commit abf068492e16ef52b262cf903e8b39ac10c2bb59
Author:     Michael Forney <[email protected]>
AuthorDate: Sat Nov 2 12:59:02 2019 -0700
Commit:     Michael Forney <[email protected]>
CommitDate: Sat Nov 2 14:03:10 2019 -0700

    wc: Set flag defaults if none were specified

diff --git a/wc.c b/wc.c
index 56f2fda..05ddfa6 100644
--- a/wc.c
+++ b/wc.c
@@ -12,20 +12,19 @@ static size_t tc = 0, tl = 0, tw = 0;
 static void
 output(const char *str, size_t nc, size_t nl, size_t nw)
 {
-       int noflags = !cmode && !lflag && !wflag;
        int first = 1;
 
-       if (lflag || noflags) {
+       if (lflag) {
                if (!first)
                        putchar(' ');
                printf("%*.1zu", first ? (first = 0) : 6, nl);
        }
-       if (wflag || noflags) {
+       if (wflag) {
                if (!first)
                        putchar(' ');
                printf("%*.1zu", first ? (first = 0) : 6, nw);
        }
-       if (cmode || noflags) {
+       if (cmode) {
                if (!first)
                        putchar(' ');
                printf("%*.1zu", first ? (first = 0) : 6, nc);
@@ -43,7 +42,7 @@ wc(FILE *fp, const char *str)
        size_t nc = 0, nl = 0, nw = 0;
 
        while ((rlen = efgetrune(&c, fp, str))) {
-               nc += (cmode == 'c' || !cmode) ? rlen : (c != Runeerror);
+               nc += (cmode == 'c') ? rlen : (c != Runeerror);
                if (c == '\n')
                        nl++;
                if (!isspacerune(c))
@@ -91,6 +90,12 @@ main(int argc, char *argv[])
                usage();
        } ARGEND
 
+       if (!lflag && !wflag && !cmode) {
+               cmode = 'c';
+               lflag = 1;
+               wflag = 1;
+       }
+
        if (!argc) {
                wc(stdin, NULL);
        } else {

Reply via email to