[hackers] [sbase] Audit wc(1) || FRIGN

From: <git_AT_suckless.org>
Date: Thu, 19 Mar 2015 11:13:25 +0100 (CET)

commit 77ab42908e0d3a990b11183d751021de604b63b5
Author: FRIGN <dev_AT_frign.de>
Date: Wed Mar 18 00:20:19 2015 +0100

    Audit wc(1)
    
    Style cleanup, Manpage refactoring.

diff --git a/README b/README
index ad9586f..5c9a5df 100644
--- a/README
+++ b/README
_AT_@ -86,7 +86,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
 =*| unlink yes none
 =*| uudecode yes none
 =*| uuencode yes none
-#* wc yes none
+#*| wc yes none
 = xargs no -I, -L, -p, -s, -t, -x
 =*| yes non-posix none
 
diff --git a/wc.1 b/wc.1
index c18b210..7251382 100644
--- a/wc.1
+++ b/wc.1
_AT_@ -1,4 +1,4 @@
-.Dd February 1, 2015
+.Dd March 18, 2015
 .Dt WC 1
 .Os sbase
 .Sh NAME
_AT_@ -11,9 +11,9 @@
 .Op Ar file ...
 .Sh DESCRIPTION
 .Nm
-prints the number of lines, words and bytes in each
-.Ar file ,
-unless set differently with flags.
+writes the number of lines, words and bytes in each
+.Ar file
+to stdout.
 If no
 .Ar file
 is given
diff --git a/wc.c b/wc.c
index f3064a9..0ff3b8d 100644
--- a/wc.c
+++ b/wc.c
_AT_@ -61,7 +61,7 @@ int
 main(int argc, char *argv[])
 {
         FILE *fp;
- int i;
+ int many;
         int ret = 0;
 
         ARGBEGIN {
_AT_@ -81,20 +81,21 @@ main(int argc, char *argv[])
                 usage();
         } ARGEND;
 
- if (argc == 0) {
+ if (!argc) {
                 wc(stdin, NULL);
         } else {
- for (i = 0; i < argc; i++) {
- if (!(fp = fopen(argv[i], "r"))) {
- weprintf("fopen %s:", argv[i]);
+ for (many = (argc > 1); *argv; argc--, argv++) {
+ if (!(fp = fopen(*argv, "r"))) {
+ weprintf("fopen %s:", *argv);
                                 ret = 1;
                                 continue;
                         }
- wc(fp, argv[i]);
+ wc(fp, *argv);
                         fclose(fp);
                 }
- if (argc > 1)
+ if (many)
                         output("total", tc, tl, tw);
         }
+
         return ret;
 }
Received on Thu Mar 19 2015 - 11:13:25 CET

This archive was generated by hypermail 2.3.0 : Thu Mar 19 2015 - 11:24:41 CET