/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1992-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* 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
/*
* David Korn
* AT&T Research
*
* strings
*/
static const char usage[] =
"[-?\n@(#)$Id: strings (AT&T Research) 2000-04-01 $\n]"
"[+NAME?strings - find and display printable strings in files]"
"[+DESCRIPTION?\bstrings\b searches for printable strings in regular files"
" and writes those strings to the standard output. A printable string"
" is any sequence of four (by default) or more printable characters"
" terminated by a newline or NUL character.]"
"[a:all?Scan the entire file. Always enabled in this implementation.]"
"[l:long-strings?Ignore \anewline\a characters as string terminators and"
" display strings using C character escape sequences. These strings"
" are suitably escaped for placement inside C \"...\" and"
" \bksh\b(1) $'...' string literals.]"
"[m:multi-byte?Scan for multibyte strings.]"
"[n:length|bytes?Set the minimum matched string length to \alength\a. For"
" compatibility -\anumber\a is equivalent to"
" \b--length\b=\anumber\a.]#[number:=4]"
"[t:radix|format?Write each string preceded by its byte offset from the"
" start of the file. The offset radix is determined by:]:[format]{"
" [+d?decimal]"
" [+o?octal]"
" [+x?hexadecimal]"
"}"
"[o:octal?Equivalent to \b--radix=o\b.]"
"\n"
"\n[ file ... ]\n"
"\n"
"[+SEE ALSO?\bgrep\b(1), \bnm\b(1), \bwhat\b(1)]"
;
#include <cmd.h>
#include <ctype.h>
static int
mapchar(register int c)
{
switch (c)
{
case '\a':
return('a');
case '\b':
return('b');
case '\f':
return('f');
case '\n':
return('n');
case '\r':
return('r');
case '\t':
return('t');
case '\v':
return('v');
case '"':
return('"');
case '\'':
return('\'');
case '\\':
return('\\');
}
return 0;
}
static int
{
register int c;
register int d;
register int n = nbytes;
while (n-- > 0)
{
c = *cp;
cp += 2;
else
cp++;
{
nbytes++;
c = d;
}
}
return nbytes + 1;
}
static int
{
register int n = 0;
register int c;
register unsigned char* inp;
register unsigned char* inend;
register int state = 0;
int sep;
if (format)
{
else
offset = 0;
offset--;
}
{
offset += c;
for (;;)
{
{
{
if (format)
{
{
return 0;
}
else
}
else
if (n < 0)
return 0;
}
if (c || !state)
n = 0;
else
state = 0;
break;
}
else if (state)
n = 0;
else
{
state = 1;
n++;
}
}
}
return 1;
}
int
{
register int n;
register int flags = 0;
register char* cp;
register char* format = 0;
argv++;
for (;;)
{
{
case 'a':
/* ignore this */
continue;
case 'l':
continue;
case 'm':
continue;
case 'n':
continue;
case 'o':
format = "07d";
continue;
case 't':
else
continue;
case ':':
continue;
case '?':
continue;
}
break;
}
if (error_info.errors)
argv++;
do
{
{
continue;
}
{
}
return error_info.errors;
}