summaryrefslogtreecommitdiffstats
path: root/usr.bin/what/what.c
diff options
context:
space:
mode:
authorrnordier <rnordier@FreeBSD.org>1998-05-04 22:26:56 +0000
committerrnordier <rnordier@FreeBSD.org>1998-05-04 22:26:56 +0000
commitbb6e1ba0c0c992a86f3ea0695bfa3370104b6da4 (patch)
tree2dacb75b187f84aca81f4dad022364775d130f0f /usr.bin/what/what.c
parent9de382a93cb08d8b73268daf2bf5e37dc3464353 (diff)
downloadFreeBSD-src-bb6e1ba0c0c992a86f3ea0695bfa3370104b6da4.zip
FreeBSD-src-bb6e1ba0c0c992a86f3ea0695bfa3370104b6da4.tar.gz
Make compatible with standard what command:
Implement -s option Keep going if a file is not found Append ':' to printed filenames Include backslash in terminal characters Make exit status dependent on a match having been found Revise manpage accordingly
Diffstat (limited to 'usr.bin/what/what.c')
-rw-r--r--usr.bin/what/what.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/usr.bin/what/what.c b/usr.bin/what/what.c
index 91f114d..ebc4d11 100644
--- a/usr.bin/what/what.c
+++ b/usr.bin/what/what.c
@@ -42,32 +42,52 @@ static const char copyright[] =
static char sccsid[] = "@(#)what.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
- "$Id$";
+ "$Id: what.c,v 1.3 1997/08/25 06:49:45 charnier Exp $";
#endif /* not lint */
#include <err.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static int sflag;
+static int found;
void search __P((void));
/*
* what
*/
-/* ARGSUSED */
int
main(argc, argv)
int argc;
char **argv;
{
- if (!*++argv)
+ int c;
+
+ while ((c = getopt(argc, argv, "s")) != -1)
+ switch (c) {
+ case 's':
+ sflag = 1;
+ break;
+ default:
+ (void)fprintf(stderr,
+ "usage: what [-s] file ...\n");
+ exit(1);
+ }
+ argv += optind;
+
+ if (!*argv)
search();
else do {
if (!freopen(*argv, "r", stdin))
- err(1, "%s", *argv);
- printf("%s\n", *argv);
- search();
+ warn("%s", *argv);
+ else {
+ printf("%s:\n", *argv);
+ search();
+ }
} while(*++argv);
- exit(0);
+ exit(!found);
}
void
@@ -86,8 +106,11 @@ loop: if (c != '@')
goto loop;
putchar('\t');
while ((c = getchar()) != EOF && c && c != '"' &&
- c != '>' && c != '\n')
+ c != '>' && c != '\\' && c != '\n')
putchar(c);
putchar('\n');
+ found = 1;
+ if (sflag)
+ return;
}
}
OpenPOWER on IntegriCloud