Use getopt() to reject options (asa has none), and to the "--" end of options

marker. Exit non-zero if we cannot open one of the input files. Update
standards conformance and exit status statements in manual page.

PR:		36130
Approved by:	mike
This commit is contained in:
Tim J. Robbins 2002-05-15 03:17:01 +00:00
parent 8a99cbd53d
commit 66562e1aac
2 changed files with 38 additions and 21 deletions

View File

@ -30,7 +30,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd September 23, 1993
.Dd May 9, 2002
.Dt ASA 1
.Os
.Sh NAME
@ -63,10 +63,8 @@ before printing the rest of the line.
.Pp
Lines beginning with characters other than the above are treated as if they
begin with \*[Lt]space\*[Gt].
.Sh EXIT STATUS
The
.Nm
utility exit 0 on success, and \*[Gt]0 if an error occurs.
.Sh DIAGNOSTICS
.Ex -std
.Sh EXAMPLES
To view a file containing the output of a
.Tn FORTRAN
@ -83,8 +81,6 @@ program and redirect it to a line-printer:
The
.Nm
utility conforms to
.St -p1003.2-92
and to
.St -xcu5 .
.St -p1003.1-2001 .
.Sh AUTHORS
J.T. Conklin, Winning Strategies, Inc.

View File

@ -43,29 +43,50 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
static void asa(FILE *);
static void usage(void);
int
main(int argc, char *argv[])
{
int ch, exval;
FILE *fp;
const char *fn;
/* skip progname */
argv++;
while ((ch = getopt(argc, argv, "")) != -1) {
switch (ch) {
case '?':
default:
usage();
/*NOTREACHED*/
}
}
argc -= optind;
argv += optind;
fp = stdin;
do {
if (*argv != NULL) {
if ((fp = fopen(*argv, "r")) == NULL) {
warn("%s", *argv);
exval = 0;
if (argc == 0)
asa(stdin);
else {
while ((fn = *argv++) != NULL) {
if ((fp = fopen(fn, "r")) == NULL) {
warn("%s", fn);
exval = 1;
continue;
}
}
asa(fp);
if (fp != stdin)
(void)fclose(fp);
} while (*argv++ != NULL);
asa(fp);
fclose(fp);
}
}
exit(0);
exit(exval);
}
static void
usage(void)
{
fprintf(stderr, "usage: asa [file...]\n");
exit(1);
}
static void