summaryrefslogtreecommitdiffstats
path: root/usr.bin/what
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
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')
-rw-r--r--usr.bin/what/what.142
-rw-r--r--usr.bin/what/what.c39
2 files changed, 54 insertions, 27 deletions
diff --git a/usr.bin/what/what.1 b/usr.bin/what/what.1
index 53930cc..7e369a9 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 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