/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1992-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* look for lines beginning with <prefix> in sorted a sorted file
*
* David Korn
*/
#ifndef DICT_FILE
#endif
static const char usage[] =
"[-?@(#)$Id: look (AT&T Research) 2008-02-14 $\n]"
"[+NAME?look - displays lines beginning with a given prefix]"
"[+DESCRIPTION?\blook\b displays all lines in the sorted \afile\a arguments"
" that begin with the given prefix \aprefix\a onto the standard output."
" The results are unspecified if any \afile\a is not sorted. If"
" \amax-prefix\a is specified then then records matching prefixes"
" in the inclusive range \aprefix\a..\amax-prefix\a are displayed.]"
" and enables \b--dictionary\b and \b--ignorecase\b.]"
"[d:dictionary?`Phone dictionary order': only letters, digits, and"
" white space characters are significant in string comparisons.]"
"[f:fold|ignorecase?The search is case insensitive.]"
"[h:header?Skip flat file header (all lines up to first blank line.)]"
"\n"
"\nprefix [- max-prefix] [file ...]\n"
"\n"
"[+EXIT STATUS?]{"
" [+0?The specified \aprefix\a was found in the file.]"
" [+1?The specified \aprefix\a was not found in the file.]"
" [+>1?An error occurred.]"
"}"
"[+SEE ALSO?\bgrep\b(1), \bsort\b(1)]"
;
#include <cmd.h>
#include <ctype.h>
static char*
{
register int n;
while (n = *cp++)
{
if (n == '\n')
{
*bp = 0;
break;
}
{
*bp++ = n;
break;
}
}
return buff;
}
static int
{
int n;
int len;
int found;
register char* cp;
register char* dp;
register char* buff = 0;
{
while (n = *cp++)
*dp++ = n;
*dp = 0;
if (maxprefix)
{
while (n = *cp++)
*dp++ = n;
*dp = 0;
n = len;
}
else
n = len;
}
else
return 1;
{
found = 0;
n = 0;
{
if (n <= 0)
break;
}
if (!cp)
return 1;
if (maxprefix)
{
n = 0;
}
found = !n;
while (!n)
{
break;
if (maxprefix && n > 0)
n = 0;
}
}
else
{
{
break;
else
{
if (n < 0)
else if (n > 0)
else
{
break;
}
}
}
{
return 1;
if (n <= 0)
break;
}
if (maxprefix)
{
n = 0;
}
found = !n;
while (!n)
{
break;
if (maxprefix && n > 0)
n = 0;
}
if (buff)
}
return !found;
}
int
{
register int n;
register int flags = 0;
char* ep = 0;
char* bp;
char* file;
for (;;)
{
{
case 'd':
continue;
case 'f':
continue;
case 'h':
continue;
case ':':
break;
case '?':
break;
}
break;
}
{
argv++;
{
argv++;
{
ep = 0;
}
argv++;
}
}
if (!file)
{
for (n = 0; n < elementsof(dict); n++)
{
break;
}
if (!file)
}
n = 0;
do
{
{
continue;
}
n = 1;
return n || error_info.errors;
}