sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit 7bacd98b0e8da21d1ede9e269cc957e4de702a2b
parent 960bccbe9df42f830ed9dea8254694fbec61d4a6
Author: FRIGN <dev@frign.de>
Date:   Wed, 18 Mar 2015 00:20:19 +0100

Audit wc(1)

Style cleanup, Manpage refactoring.

Diffstat:
README | 2+-
wc.1 | 8++++----
wc.c | 15++++++++-------
3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/README b/README @@ -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 @@ -1,4 +1,4 @@ -.Dd February 1, 2015 +.Dd March 18, 2015 .Dt WC 1 .Os sbase .Sh NAME @@ -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 @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) { FILE *fp; - int i; + int many; int ret = 0; ARGBEGIN { @@ -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; }