/***********************************************************************
* *
* 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
/*
* Glenn Fowler
* AT&T Research
*
* what
* my what is faster than yours.
* your who is what?
* no, they're different.
*/
static const char usage[] =
"[-?\n@(#)$Id: what (AT&T Research) 2012-02-11 $\n]"
"[+NAME?what - display binary identification strings]"
"[+DESCRIPTION?\bwhat\b searches the given files for all occurrences of"
" the identification pattern \b@(#)\b or \b$Id:\b and writes a line to"
" the standard output containing the text that follows until the first"
" occurrence of one of the following: \b\" < > \\ $ newline NUL\b. If no"
" \bfile\b is given or if a \bfile\b is \b-\b then the standard input is"
" read. The name of each input file, followed by a \b:\b, is also"
" written as a separate line to the standard output.]"
"[m:matched?Only list the names of files that match the identification"
" pattern.]"
"[s:first|single?Find only the first occurrence of the pattern in each file.]"
"\n"
"\n[ file ... ]\n"
"\n"
"[+EXIT STATUS]{"
" [+0?Some matches were found.]"
" [+1?Otherwise.]"
" [+2?Option error.]"
"}"
"[+SEE ALSO?\bident\b(1), \bgrep\b(1), \bstrings\b(1)]"
;
#include <cmd.h>
#include <ctype.h>
static struct
{
int hit;
int match;
int single;
} state;
static void
{
register unsigned char* buf;
register unsigned char* s;
register unsigned char* e;
int intro;
unsigned char* b;
char* t;
{
goto next;
for (;;)
{
{
next:
s[0] = s[1] = s[2] = 0;
switch (mid)
{
default:
/*FALLTHROUGH*/
case 2:
/*FALLTHROUGH*/
case 1:
/*FALLTHROUGH*/
case 0:
break;
}
goto done;
goto next;
{
case HIT:
if (buf[0] == ')' && s[2] == '#' && s[1] == '(' && s[0] == '@' || buf[0] == ':' && s[2] == 'd' && s[1] == 'I' && s[0] == '$')
{
index = 0;
s = buf + 1;
goto hit;
}
break;
case 1:
if (buf[1] == ')' && buf[0] == '#' && s[2] == '(' && s[1] == '@' || buf[1] == ':' && buf[0] == 'd' && s[2] == 'I' && s[1] == '$')
{
index = 1;
s = buf + 2;
goto hit;
}
break;
case 2:
if (buf[2] == ')' && buf[1] == '#' && buf[0] == '(' && s[2] == '@' || buf[2] == ':' && buf[1] == 'd' && buf[0] == 'I' && s[2] == '$')
{
index = 2;
s = buf + 3;
goto hit;
}
break;
}
}
else
{
if (s[0] == ')' && s[-1] == '#' && s[-2] == '(' && s[-3] == '@' || s[0] == ':' && s[-1] == 'd' && s[-2] == 'I' && s[-3] == '$')
{
s++;
hit:
while (s < e)
{
while (s < e && (*s == ' ' || *s == '\t'))
s++;
if ((e - s) < 4)
break;
else if (s[0] == '@' && s[1] == '(' && s[2] == '#' && s[3] == ')')
s += 4;
else if (s[0] == '$' && s[1] == 'I' && s[2] == 'd' && s[3] == ':')
s += 4;
else
break;
}
b = s;
t = "\t";
if (!intro)
{
intro = 1;
}
for (;;)
{
if (s >= e)
{
t = "";
goto list;
}
else
{
switch (*s)
{
case 0:
case '<':
case '>':
case '"':
case '\\':
case '\n':
list:
if ((s - b) > 2 && *(s - 1) == '$' && *(s - 2) == ' ')
s -= 2;
if (s > b || !*t)
{
return;
if (!buf)
goto done;
}
break;
default:
s++;
continue;
}
break;
}
}
}
goto next;
}
}
}
done:
}
int
{
register int n;
register char* s;
for (n = 0; n <= UCHAR_MAX; n++)
for (;;)
{
{
case 'm':
continue;
case 's':
continue;
case ':':
continue;
case '?':
continue;
}
break;
}
if (error_info.errors)
if (s = *argv)
argv++;
do
{
if (!s || streq(s, "-"))
{
}
{
continue;
}
} while (s = *argv++);
}