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
This commit is contained in:
Robert Nordier 1998-05-04 22:26:56 +00:00
parent c6497bae9d
commit 1879eba7ea
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=35725
2 changed files with 54 additions and 27 deletions

View File

@ -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

View File

@ -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;
}
}