Patch from Tito to rework strings applet, and some testsuite
stuff to test it added by me.
This commit is contained in:
parent
b4a1baa312
commit
65ddf77fbd
@ -22,6 +22,7 @@
|
|||||||
* 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>
|
||||||
@ -38,83 +39,89 @@ 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;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
exitcode = fflg = oflg = 0;
|
while ((i = getopt(argc, argv, "an:of")) > 0)
|
||||||
minlen = -1;
|
switch(i)
|
||||||
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)
|
|
||||||
minlen = 4;
|
|
||||||
|
|
||||||
bfr = xmalloc(minlen);
|
|
||||||
bfr[minlen] = '\0';
|
|
||||||
file = "stdin";
|
|
||||||
do {
|
|
||||||
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;) {
|
|
||||||
foff++;
|
|
||||||
if (ISSTR(ch)) {
|
|
||||||
if (!cnt)
|
|
||||||
C = bfr;
|
|
||||||
*C++ = ch;
|
|
||||||
if (++cnt < minlen)
|
|
||||||
continue;
|
|
||||||
if (fflg)
|
|
||||||
printf("%s:", file);
|
|
||||||
if (oflg)
|
|
||||||
printf("%7lo %s", (long)(foff - minlen), (char *)bfr);
|
|
||||||
else
|
|
||||||
printf("%s", bfr);
|
|
||||||
i=0;
|
i=0;
|
||||||
while ((ch = getchar()) != EOF && ISSTR(ch))
|
|
||||||
|
if(!argc )
|
||||||
{
|
{
|
||||||
putchar((char)ch);
|
file = stdin;
|
||||||
|
goto pipe;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(a=0;a<argc;a++)
|
||||||
|
{
|
||||||
|
file=xfopen(argv[a],"r");
|
||||||
|
|
||||||
|
pipe:
|
||||||
|
|
||||||
|
count=0;
|
||||||
|
string=xmalloc(n);
|
||||||
|
string[n]='\0';
|
||||||
|
n--;
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
c=fgetc(file);
|
||||||
|
if(ISSTR(c))
|
||||||
|
{
|
||||||
|
if(i==0)
|
||||||
|
t=count;
|
||||||
|
if(i<=n)
|
||||||
|
string[i]=c;
|
||||||
|
if(i==n)
|
||||||
|
{
|
||||||
|
if(opt == 1 || opt == 3 )
|
||||||
|
printf("%s: ",(!argv[a])?"{stdin}":argv[a]);
|
||||||
|
if(opt >= 2 )
|
||||||
|
printf("%7lo ",t);
|
||||||
|
printf("%s",string);
|
||||||
|
}
|
||||||
|
if(i>n)
|
||||||
|
putchar(c);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if(i>0)
|
|
||||||
foff+=(i+1);
|
|
||||||
else
|
else
|
||||||
foff++;
|
{
|
||||||
putchar('\n');
|
if(i>n)
|
||||||
|
puts("");
|
||||||
|
i=0;
|
||||||
}
|
}
|
||||||
cnt = 0;
|
count++;
|
||||||
|
if(c==EOF)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} while (*argv);
|
if(file!=stdin)
|
||||||
exit(exitcode);
|
fclose(file);
|
||||||
|
}
|
||||||
|
free(string);
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
8
testsuite/strings/strings-works-like-GNU
Normal file
8
testsuite/strings/strings-works-like-GNU
Normal 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;
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user