Allow strings(1) to operate on more than one file

This commit is contained in:
sin 2013-10-10 16:04:15 +01:00
parent 484d5b4340
commit 12ad81fa24
2 changed files with 10 additions and 8 deletions

View File

@ -3,7 +3,7 @@
strings \- print the strings of printable characters in files strings \- print the strings of printable characters in files
.SH SYNOPSIS .SH SYNOPSIS
.B strings .B strings
.IR [file...] .IR file...
.SH DESCRIPTION .SH DESCRIPTION
.B strings .B strings
prints the printable character sequences that are at least 6 characters prints the printable character sequences that are at least 6 characters

View File

@ -9,7 +9,7 @@ static void dostrings(FILE *fp, const char *fname);
static void static void
usage(void) usage(void)
{ {
eprintf("usage: %s file\n", argv0); eprintf("usage: %s file...\n", argv0);
} }
int int
@ -22,13 +22,15 @@ main(int argc, char *argv[])
usage(); usage();
} ARGEND; } ARGEND;
if (argc > 0) { if (argc == 0) {
if (!(fp = fopen(argv[0], "r")))
eprintf("open %s:", argv[0]);
dostrings(fp, argv[0]);
fclose(fp);
} else {
dostrings(stdin, "<stdin>"); dostrings(stdin, "<stdin>");
} else {
for (; argc > 0; argc--, argv++) {
if (!(fp = fopen(argv[0], "r")))
eprintf("open %s:", argv[0]);
dostrings(fp, argv[0]);
fclose(fp);
}
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;