Patch from Tito to rework strings applet, and some testsuite

stuff to test it added by me.
This commit is contained in:
Eric Andersen 2003-01-13 23:19:31 +00:00
parent b4a1baa312
commit 65ddf77fbd
2 changed files with 78 additions and 63 deletions

View file

@ -22,99 +22,106 @@
* Original copyright notice is retained at the end of this file. * Original copyright notice is retained at the end of this file.
* *
* Modified for BusyBox by Erik Andersen <andersee@debian.org> * Modified for BusyBox by Erik Andersen <andersee@debian.org>
* Badly hacked by Tito Ragusa <farmatito@tiscali.it>
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <getopt.h> #include <getopt.h>
#include <unistd.h> #include <unistd.h>
#include <ctype.h> #include <ctype.h>
#include "busybox.h" #include "busybox.h"
#define ISSTR(ch) (isprint(ch) || ch == '\t') #define ISSTR(ch) (isprint(ch) || ch == '\t')
int strings_main(int argc, char **argv) int strings_main(int argc, char **argv)
{ {
extern char *optarg; extern char *optarg;
extern int optind; extern int optind;
int ch, cnt; int n=4, c, i, opt=0, a=0;
int exitcode; long t, count;
int oflg, fflg; FILE *file;
char *file; char *string;
size_t foff, minlen;
unsigned char *bfr, *C; while ((i = getopt(argc, argv, "an:of")) > 0)
int i; switch(i)
{
exitcode = fflg = oflg = 0;
minlen = -1;
while ((ch = getopt(argc, argv, "an:of")) > 0)
switch(ch) {
case 'a': case 'a':
break; break;
case 'f': case 'f':
fflg = 1; opt++;
break; break;
case 'n': case 'n':
minlen = atoi(optarg); n = atoi(optarg);
if(!(n/1))
show_usage();
break; break;
case 'o': case 'o':
oflg = 1; opt++;
opt++;
break; break;
default: default:
show_usage(); show_usage();
} }
argc -= optind; argc -= optind;
argv += optind; argv += optind;
if (minlen == -1) i=0;
minlen = 4;
bfr = xmalloc(minlen); if(!argc )
bfr[minlen] = '\0'; {
file = "stdin"; file = stdin;
do { goto pipe;
if (*argv) { }
fprintf(stderr, "opening '%s'\n", *argv);
file = *argv++;
if (!freopen(file, "r", stdin)) {
perror_msg("%s", file);
exitcode = EXIT_FAILURE;
continue;
}
}
foff = 0;
for (cnt = 0; (ch = getchar()) != EOF;) { for(a=0;a<argc;a++)
foff++; {
if (ISSTR(ch)) { file=xfopen(argv[a],"r");
if (!cnt)
C = bfr; pipe:
*C++ = ch;
if (++cnt < minlen) count=0;
continue; string=xmalloc(n);
if (fflg) string[n]='\0';
printf("%s:", file); n--;
if (oflg) while(1)
printf("%7lo %s", (long)(foff - minlen), (char *)bfr); {
else c=fgetc(file);
printf("%s", bfr); if(ISSTR(c))
i=0; {
while ((ch = getchar()) != EOF && ISSTR(ch)) if(i==0)
t=count;
if(i<=n)
string[i]=c;
if(i==n)
{ {
putchar((char)ch); if(opt == 1 || opt == 3 )
i++; printf("%s: ",(!argv[a])?"{stdin}":argv[a]);
if(opt >= 2 )
printf("%7lo ",t);
printf("%s",string);
} }
if(i>0) if(i>n)
foff+=(i+1); putchar(c);
else i++;
foff++;
putchar('\n');
} }
cnt = 0; else
{
if(i>n)
puts("");
i=0;
}
count++;
if(c==EOF)
break;
} }
} while (*argv); if(file!=stdin)
exit(exitcode); fclose(file);
}
free(string);
exit(EXIT_SUCCESS);
} }
/* /*
@ -130,7 +137,7 @@ int strings_main(int argc, char **argv)
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* *
* 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
* ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change> * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
* *
* 4. Neither the name of the University nor the names of its contributors * 4. Neither the name of the University nor the names of its contributors

View file

@ -0,0 +1,8 @@
rm -f foo bar
strings -af ../../busybox > foo
busybox strings -af ../../busybox > bar
test ! -f foo -a -f bar
if [ $? = 0 ] ; then
diff -q foo bar
fi;