Using assignments as truth values seems to have been a favoured
authornealcrook <neal@pippaluk.org.uk>
Tue, 22 Nov 2016 08:39:07 +0000 (08:39 +0000)
committernealcrook <neal@pippaluk.org.uk>
Tue, 22 Nov 2016 08:39:07 +0000 (08:39 +0000)
programming style of Mr Bourne. gcc moans about it though:

"suggest parentheses around assignment used as truth value"

so in the interests of fewer compile warnings I have complied with the
suggestion.

Applications/V7/cmd/sh/args.c
Applications/V7/cmd/sh/cmd.c
Applications/V7/cmd/sh/error.c
Applications/V7/cmd/sh/expand.c
Applications/V7/cmd/sh/fault.c
Applications/V7/cmd/sh/io.c
Applications/V7/cmd/sh/macro.c
Applications/V7/cmd/sh/name.c
Applications/V7/cmd/sh/print.c
Applications/V7/cmd/sh/service.c
Applications/V7/cmd/sh/string.c

index f0f6c6d..bc677d7 100644 (file)
@@ -94,7 +94,7 @@ DOLPTR freeargs(DOLPTR blk)
        register DOLPTR argr = 0;
        register DOLPTR argblk;
 
-       if (argblk = blk) {
+       if ( (argblk = blk) ) {
                argr = argblk->dolnxt;
                if ((--argblk->doluse) == 0) {
                        for (argp = (char **) argblk->dolarg;
@@ -128,7 +128,7 @@ static const char **copyargs(const char *from[], int n)
 void clearup(void)
 {
        /* force `for' $* lists to go away */
-       while (argfor = freeargs(argfor));
+       while ( (argfor = freeargs(argfor)) );
 
        /* clean up io files */
        while (pop());
index 4e01828..6abc7fc 100644 (file)
@@ -89,7 +89,7 @@ TREPTR cmd(register int sym, int flg)
                        synbad();
 
        case ';':
-               if (e = cmd(sym, flg | MTFLG))
+               if ( (e = cmd(sym, flg | MTFLG)) )
                        i = makelist(TLST, i, e);
                break;
 
@@ -307,7 +307,7 @@ static TREPTR item(BOOL flag)
        }
        reserv++;
        word();
-       if (io = inout(io)) {
+       if ( (io = inout(io)) ) {
                t = makefork(0, t);
                t->treio = io;
        }
index 8e8cd79..d59e622 100644 (file)
@@ -69,8 +69,7 @@ void exitsh(int xno)
 void done(void)
 {
        register STRING t;
-       if (t = trapcom[0]
-           ) {
+       if ( (t = trapcom[0]) ) {
                trapcom[0] = 0; /*should free but not long */
                execexp(t, 0);
                ;
index c2128ca..acbb09d 100644 (file)
@@ -164,7 +164,7 @@ int expand(char *as, int rflg)
        {
                register char c;
                s = as;
-               while (c = *s)
+               while ( (c = *s) )
                        *s++ = (c & STRIP ? c : '/');
        }
        return count;
@@ -175,7 +175,7 @@ int gmatch(register char *s, register char *p)
        register int scc;
        char c;
 
-       if (scc = *s++) {
+       if ( (scc = *s++) ) {
                if ((scc &= STRIP) == 0) {
                        scc = 0200;
                }
@@ -187,7 +187,7 @@ int gmatch(register char *s, register char *p)
                        int lc;
                        ok = 0;
                        lc = 077777;
-                       while (c = *p++) {
+                       while ( (c = *p++) ) {
                                if (c == ']') {
                                        return (ok ? gmatch(s, p) : 0);
                                } else if (c == MINUS) {
@@ -234,7 +234,7 @@ static void addg(const char *as1, char *as2, const char *as3)
        s2 = locstak() + BYTESPERWORD;
 
        s1 = as1;
-       while (c = *s1++) {
+       while ( (c = *s1++) ) {
                if ((c &= STRIP) == 0) {
                        *s2++ = '/';
                        break;
@@ -243,12 +243,12 @@ static void addg(const char *as1, char *as2, const char *as3)
                *s2++ = c;
        }
        s1 = as2;
-       while (*s2 = *s1++) {
+       while ( (*s2 = *s1++) ) {
                s2++;
        }
-       if (s1 = as3) {
+       if ( (s1 = as3) ) {
                *s2++ = '/';
-               while (*s2++ = *++s1);
+               while ( (*s2++ = *++s1) );
        }
        makearg(endstak(s2));
 }
index d3f4386..dd5c452 100644 (file)
@@ -98,7 +98,7 @@ void chktrap(void)
        while (--i) {
                if (trapflg[i] & TRAPSET) {
                        trapflg[i] &= ~TRAPSET;
-                       if (t = trapcom[i]) {
+                       if ( (t = trapcom[i]) ) {
                                int savxit = exitval;
                                execexp(t, 0);
                                exitval = savxit;
index 7276cfe..f407cf1 100644 (file)
@@ -115,7 +115,7 @@ void copy(IOPTR ioparg)
        int fd;
        register IOPTR iop;
 
-       if (iop = ioparg) {
+       if ( (iop = ioparg) ) {
                copy(iop->iolst);
                ends = mactrim(iop->ioname);
 
index 2619940..534a87a 100644 (file)
@@ -77,7 +77,7 @@ retry:
                        CHAR idb[2];
                        char *id = idb;
 
-                       if (bra = (c == BRACE))
+                       if ( (bra = (c == BRACE)) )
                                c = readc();
 
                        if (letter(c)) {
@@ -141,7 +141,7 @@ retry:
                        if (v) {
                                if (c != '+') {
                                        for (;;) {
-                                               while (c = *v++)
+                                               while ( (c = *v++) )
                                                        pushstak(c | quote);
 
                                                if (dolg == 0 || (++dolg > dolc))
@@ -239,7 +239,7 @@ static void comsubst(void)
        tdystak(savptr);
        staktop = movstr(savptr, stakbot);
 
-       while (d = readc())
+       while ( (d = readc()) )
                pushstak(d | quote);
 
        await(0);
@@ -264,7 +264,7 @@ void subst(int in, int ot)
        push(&fb);
        initf(in);
        /* DQUOTE used to stop it from quoting */
-       while (c = (getch(DQUOTE) & STRIP)) {
+       while ( (c = (getch(DQUOTE) & STRIP)) ) {
                pushstak(c);
                if (--count == 0) {
                        flush(ot);
index dff927a..7bd9a9f 100644 (file)
@@ -38,7 +38,7 @@ int syslook(char *w, SYSTAB syswds)
        syscan = syswds;
        first = *w;
 
-       while (s = syscan->sysnam) {
+       while ( (s = syscan->sysnam) ) {
                if (first == *s && eq(w, s))
                        return (syscan->sysval);
                syscan++;
@@ -236,7 +236,7 @@ void printnam(NAMPTR n)
        register const char *s;
 
        sigchk();
-       if (s = n->namval) {
+       if ( (s = n->namval) ) {
                prs(n->namid);
                prc('=');
                prs(s);
index a51f98a..1ee9ae4 100644 (file)
@@ -38,7 +38,7 @@ void prs(const char *as)
 {
        register const char *s;
 
-       if (s = as)
+       if ( (s = as) )
                write(output, s, length(s) - 1);
 }
 
@@ -57,7 +57,7 @@ void prt(clock_t t)
        sec = t % 60;
        t /= 60;
        min = t % 60;
-       if (hr = t / 60) {
+       if ( (hr = t / 60) ) {
                prn(hr);
                prc('h');
        }
index fc51695..01ae0b9 100644 (file)
@@ -133,7 +133,7 @@ void execa(const char **at)
                path = getpath(*t);
                namscan(exname);
                xecenv = sh_setenv();
-               while (path = execs(path, t));
+               while ( (path = execs(path, t)) );
                failed(*t, xecmsg);
        }
 }
@@ -149,7 +149,7 @@ static const char *execs(const char *ap, const char *t[])
        sigchk();
        execve(p, (char**) &t[0], (char **)xecenv);
        switch (errno) {
-       case ENOEXEC:
+       case ENOEXEC:           /* could be a shell script */
                flags = 0;
                comdiv = 0;
                ioset = 0;
@@ -240,7 +240,7 @@ void await(int i)
 
                w_hi = (w >> 8) & LOBYTE;
 
-               if (sig = w & 0177) {
+               if ( (sig = w & 0177) ) {
                        if (sig == 0177) {      /* ptrace! return */
                                prs("ptrace: ");
                                sig = w_hi;
@@ -277,8 +277,8 @@ void trim(char *at)
        register char c;
        register char q = 0;
 
-       if (p = at) {
-               while (c = *p) {
+       if ( (p = at) ) {
+               while ( (c = *p) ) {
                        *p++ = c & STRIP;
                        q |= c;
                }
@@ -304,7 +304,7 @@ char **scan(int argn)
 
        while (argp) {
                *--comargn = argp->argval;
-               if (argp = argp->argnxt)
+               if ( (argp = argp->argnxt) )
                        trim(*comargn);
                if (argp == 0 || ((intptr_t)(argp)) & ARGMK) {
                        gsort(comargn, comargm);
@@ -352,7 +352,7 @@ int getarg(COMPTR ac)
        register int count = 0;
        register COMPTR c;
 
-       if (c = ac) {
+       if ( (c = ac) ) {
                argp = c->comarg;
                while (argp) {
                        count += split(macro(argp->argval));
@@ -386,7 +386,7 @@ static int split(register const char *s)
                } else if (c == 0) {
                        s--;
                }
-               if (c = expand(((ARGPTR) (argp = endstak(argp)))->argval, 0)) {
+               if ( (c = expand(((ARGPTR) (argp = endstak(argp)))->argval, 0)) ) {
                        count += c;
                } else {        /* assign(&fngnod, argp->argval); */
                        makearg(argp);
index 0d893ff..8e21d15 100644 (file)
@@ -17,7 +17,7 @@
 
 char *movstr(register const char *a, register char *b)
 {
-       while (*b++ = *a++);
+       while ( (*b++ = *a++) );
        return (--b);
 }
 
@@ -25,7 +25,7 @@ int any(char c, const char *s)
 {
        register char d;
 
-       while (d = *s++) {
+       while ( (d = *s++) ) {
                if (d == c) {
                        return (TRUE);
                        ;
@@ -49,7 +49,7 @@ int length(const char *as)
 {
        register const char *s;
 
-       if (s = as) {
+       if ( (s = as) ) {
                while (*s++);;
        }
        return (s - as);