[hackers] [sbase] nl(1) should handle up to 1 file || sin

From: <git_AT_suckless.org>
Date: Thu, 04 Dec 2014 13:05:13 +0100

commit 761599ae61b8c9dfc1af047e502f62cbb7e55e53
Author: sin <sin_AT_2f30.org>
Date: Thu Dec 4 12:04:41 2014 +0000

    nl(1) should handle up to 1 file

diff --git a/nl.1 b/nl.1
index c6e2ed5..61159b4 100644
--- a/nl.1
+++ b/nl.1
_AT_@ -9,7 +9,7 @@ nl \- number lines
 .IR increment ]
 .RB [ \-s
 .IR separator ]
-.RI [ file ...]
+.RI [ file ]
 .SH DESCRIPTION
 .B nl
 reads each file in sequence and writes it to stdout with non\-empty lines
diff --git a/nl.c b/nl.c
index f21e133..44772ad 100644
--- a/nl.c
+++ b/nl.c
_AT_@ -18,8 +18,7 @@ static regex_t preg;
 static void
 usage(void)
 {
- eprintf("usage: %s [-b style] [-i increment] [-s sep] [FILE...]\n",
- argv0);
+ eprintf("usage: %s [-b style] [-i increment] [-s sep] [file]\n", argv0);
 }
 
 int
_AT_@ -27,7 +26,6 @@ main(int argc, char *argv[])
 {
         FILE *fp;
         char *r;
- int ret = 0;
 
         ARGBEGIN {
         case 'b':
_AT_@ -48,18 +46,18 @@ main(int argc, char *argv[])
                 usage();
         } ARGEND;
 
+ if (argc > 1)
+ usage();
+
         if (argc == 0) {
                 nl("<stdin>", stdin);
- } else for (; argc > 0; argc--, argv++) {
- if (!(fp = fopen(argv[0], "r"))) {
- weprintf("fopen %s:", argv[0]);
- ret = 1;
- continue;
- }
+ } else {
+ if (!(fp = fopen(argv[0], "r")))
+ eprintf("fopen %s:", argv[0]);
                 nl(argv[0], fp);
                 fclose(fp);
         }
- return ret;
+ return 0;
 }
 
 void
Received on Thu Dec 04 2014 - 13:05:13 CET

This archive was generated by hypermail 2.3.0 : Thu Dec 04 2014 - 13:12:24 CET