diff --git a/usr.bin/what/what.1 b/usr.bin/what/what.1 index 53930cc44555..7e369a9a0c1b 100644 --- a/usr.bin/what/what.1 +++ b/usr.bin/what/what.1 @@ -31,7 +31,7 @@ .\" .\" @(#)what.1 8.1 (Berkeley) 6/6/93 .\" -.\" $Id: what.1,v 1.7 1997/08/26 07:04:20 charnier Exp $ +.\" $Id: what.1,v 1.8 1998/04/14 06:31:23 phk Exp $ .\" .Dd June 6, 1993 .Dt WHAT 1 @@ -40,30 +40,34 @@ .Nm what .Nd "show what versions of object modules were used to construct a file" .Sh SYNOPSIS -.Nm what -.Ar name Ar ... +.Nm +.Op Fl s +.Ar file Ar ... .Sh DESCRIPTION -.Nm What -reads each file -.Ar name -and searches for sequences of the form +The +.Nm +utility searches each specified +.Ar file +for sequences of the form .Dq \&@(#) as inserted by the source code control system. It prints the remainder -of the string following this marker, up to a null character, newline, double -quote, or +of the string following this marker, up to a NUL character, newline, double +quote, .Dq \&> -character. +character, or backslash. +.Pp +The following option is available: +.Bl -tag -width Ds +.It Fl s +Stop searching each file after the first match. +.El +.Pp +Exit status is 0 if any matches were found, otherwise 1. .Sh BUGS -As -.Bx -is not licensed to distribute +This is a rewrite of the .Tn SCCS -this is a rewrite of the -.Nm -command which is part of -.Tn SCCS , -and may not behave exactly the same as that -command does. +command of the same name, +and behavior may not be identical. .Sh SEE ALSO .Xr ident 1 , .Xr strings 1 diff --git a/usr.bin/what/what.c b/usr.bin/what/what.c index 91f114d9278c..ebc4d1107e9b 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 #include +#include +#include + +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; } }