nl(1) should handle up to 1 file

This commit is contained in:
sin 2014-12-04 12:04:41 +00:00
parent 86c88d8b3a
commit 761599ae61
2 changed files with 9 additions and 11 deletions

2
nl.1
View File

@ -9,7 +9,7 @@ nl \- number lines
.IR increment ] .IR increment ]
.RB [ \-s .RB [ \-s
.IR separator ] .IR separator ]
.RI [ file ...] .RI [ file ]
.SH DESCRIPTION .SH DESCRIPTION
.B nl .B nl
reads each file in sequence and writes it to stdout with non\-empty lines reads each file in sequence and writes it to stdout with non\-empty lines

18
nl.c
View File

@ -18,8 +18,7 @@ static regex_t preg;
static void static void
usage(void) usage(void)
{ {
eprintf("usage: %s [-b style] [-i increment] [-s sep] [FILE...]\n", eprintf("usage: %s [-b style] [-i increment] [-s sep] [file]\n", argv0);
argv0);
} }
int int
@ -27,7 +26,6 @@ main(int argc, char *argv[])
{ {
FILE *fp; FILE *fp;
char *r; char *r;
int ret = 0;
ARGBEGIN { ARGBEGIN {
case 'b': case 'b':
@ -48,18 +46,18 @@ main(int argc, char *argv[])
usage(); usage();
} ARGEND; } ARGEND;
if (argc > 1)
usage();
if (argc == 0) { if (argc == 0) {
nl("<stdin>", stdin); nl("<stdin>", stdin);
} else for (; argc > 0; argc--, argv++) { } else {
if (!(fp = fopen(argv[0], "r"))) { if (!(fp = fopen(argv[0], "r")))
weprintf("fopen %s:", argv[0]); eprintf("fopen %s:", argv[0]);
ret = 1;
continue;
}
nl(argv[0], fp); nl(argv[0], fp);
fclose(fp); fclose(fp);
} }
return ret; return 0;
} }
void void