XPG4.2:
* Add the -s (first identifier found only) flag. * Require at least one file operand; the standard does not permit reading from stdin in case none were given. * Recogize '\' as an additional identifier end character. * Make the exit status depend on whether any matches were found.
This commit is contained in:
parent
1cfce9cbf5
commit
c49b4850b3
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: what.1,v 1.4 1997/10/20 03:16:30 lukem Exp $
|
||||
.\" $NetBSD: what.1,v 1.5 1999/02/22 22:23:09 kleink Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
@ -33,25 +33,42 @@
|
||||
.\"
|
||||
.\" @(#)what.1 8.1 (Berkeley) 6/6/93
|
||||
.\"
|
||||
.Dd June 6, 1993
|
||||
.Dd February 22, 1999
|
||||
.Dt WHAT 1
|
||||
.Os BSD 4
|
||||
.Sh NAME
|
||||
.Nm what
|
||||
.Nd "show what versions of object modules were used to construct a file"
|
||||
.Nd search files for SCCS identifiers
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Ar name Ar ...
|
||||
.Op Fl s
|
||||
.Ar
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
reads each file
|
||||
.Ar name
|
||||
and searches for sequences of the form
|
||||
utility reads each
|
||||
.Ar file
|
||||
operand and searches 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
|
||||
.Dq \&> character.
|
||||
quote, backslash or
|
||||
.Dq \&>
|
||||
character.
|
||||
.Pp
|
||||
If the
|
||||
.Fl s
|
||||
option is specified, only the first occurence of an idenfication string in
|
||||
each file is printed.
|
||||
.Sh DIAGNOSTICS
|
||||
The
|
||||
.Nm
|
||||
utility exits 0 if any matches were found, and 1 otherwise.
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility conforms to
|
||||
.St -xpg4.2 .
|
||||
.Sh BUGS
|
||||
As
|
||||
.Bx
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: what.c,v 1.6 1997/10/20 03:16:31 lukem Exp $ */
|
||||
/* $NetBSD: what.c,v 1.7 1999/02/22 22:23:10 kleink Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1988, 1993
|
||||
@ -43,13 +43,19 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1988, 1993\n\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)what.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
__RCSID("$NetBSD: what.c,v 1.6 1997/10/20 03:16:31 lukem Exp $");
|
||||
__RCSID("$NetBSD: what.c,v 1.7 1999/02/22 22:23:10 kleink Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void search __P((void));
|
||||
int main __P((int, char **));
|
||||
static void search __P((void));
|
||||
static void usage __P((void));
|
||||
|
||||
static int matches;
|
||||
static int sflag;
|
||||
|
||||
/*
|
||||
* what
|
||||
@ -60,20 +66,39 @@ main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
if (!*++argv)
|
||||
search();
|
||||
else do {
|
||||
if (!freopen(*argv, "r", stdin)) {
|
||||
int c;
|
||||
|
||||
matches = sflag = 0;
|
||||
while ((c = getopt(argc, argv, "s")) != -1) {
|
||||
switch (c) {
|
||||
case 's':
|
||||
sflag = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc < 1) {
|
||||
usage();
|
||||
} else do {
|
||||
if (freopen(*argv, "r", stdin) == NULL) {
|
||||
perror(*argv);
|
||||
exit(1);
|
||||
exit(matches ? EXIT_SUCCESS : 1);
|
||||
}
|
||||
printf("%s\n", *argv);
|
||||
search();
|
||||
} while(*++argv);
|
||||
exit(0);
|
||||
} while (*++argv != NULL);
|
||||
|
||||
/* Note: the standard explicitly specifies an exit status of 1. */
|
||||
exit(matches ? EXIT_SUCCESS : 1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
search()
|
||||
{
|
||||
int c;
|
||||
@ -88,9 +113,20 @@ loop: if (c != '@')
|
||||
if ((c = getchar()) != ')')
|
||||
goto loop;
|
||||
putchar('\t');
|
||||
while ((c = getchar()) != EOF && c && c != '"' &&
|
||||
c != '>' && c != '\n')
|
||||
while ((c = getchar()) != EOF && c != '\0' && c != '"' &&
|
||||
c != '>' && c != '\n' && c != '\\')
|
||||
putchar(c);
|
||||
putchar('\n');
|
||||
matches++;
|
||||
if (sflag)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
|
||||
(void)fprintf(stderr, "usage: what [-s] file ...\n");
|
||||
exit(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user