Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh General KNF and source code cleanups, avoid scatterin...



details:   https://anonhg.NetBSD.org/src/rev/5260b43aa65a
branches:  trunk
changeset: 344410:5260b43aa65a
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Mar 27 14:34:46 2016 +0000

description:
General KNF and source code cleanups, avoid scattering the
magic string " \t\n" all over the place, slightly improved
syntax error messages, restructured some of the code for
clarity, don't allow IFS to be imported through the environment,
and remove the (never) conditionally compiled ATTY option.
Apart from one or two syntax error messages, and ignoring IFS
if present in the environment, this is intended to have no
user visible changes. (from kre@)

diffstat:

 bin/sh/expand.c       |   14 +---
 bin/sh/input.c        |    5 +-
 bin/sh/main.c         |   10 +--
 bin/sh/mkinit.sh      |    4 +-
 bin/sh/mknodenames.sh |    2 +-
 bin/sh/parser.c       |  147 +++++++++++++++++++++++--------------------------
 bin/sh/var.c          |   16 ++---
 bin/sh/var.h          |   11 +--
 8 files changed, 93 insertions(+), 116 deletions(-)

diffs (truncated from 648 to 300 lines):

diff -r 8dd60676f9f0 -r 5260b43aa65a bin/sh/expand.c
--- a/bin/sh/expand.c   Sun Mar 27 10:46:41 2016 +0000
+++ b/bin/sh/expand.c   Sun Mar 27 14:34:46 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: expand.c,v 1.97 2016/03/16 15:44:35 christos Exp $     */
+/*     $NetBSD: expand.c,v 1.98 2016/03/27 14:34:46 christos Exp $     */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)expand.c   8.5 (Berkeley) 5/15/95";
 #else
-__RCSID("$NetBSD: expand.c,v 1.97 2016/03/16 15:44:35 christos Exp $");
+__RCSID("$NetBSD: expand.c,v 1.98 2016/03/27 14:34:46 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -193,7 +193,7 @@
        int ifs_split = EXP_IFS_SPLIT;
 
        if (flag & EXP_IFS_SPLIT)
-               ifs = ifsset() ? ifsval() : " \t\n";
+               ifs = ifsval();
 
        if (*p == '~' && (flag & (EXP_TILDE | EXP_VARTILDE)))
                p = exptilde(p, flag);
@@ -705,7 +705,6 @@
                                                STPUTC(CTLESC, expdest);
                                        STPUTC(*val++, expdest);
                                }
-
                        }
                }
        }
@@ -924,10 +923,7 @@
                }
                /* fall through */
        case '*':
-               if (ifsset() != 0)
-                       sep = ifsval()[0];
-               else
-                       sep = ' ';
+               sep = ifsval()[0];
                for (ap = shellparam.p ; (p = *ap++) != NULL ; ) {
                        STRTODEST(p);
                        if (*ap && sep)
@@ -1011,7 +1007,7 @@
                return;
        }
 
-       ifs = ifsset() ? ifsval() : " \t\n";
+       ifs = ifsval();
 
        for (ifsp = &ifsfirst; ifsp != NULL; ifsp = ifsp->next) {
                p = string + ifsp->begoff;
diff -r 8dd60676f9f0 -r 5260b43aa65a bin/sh/input.c
--- a/bin/sh/input.c    Sun Mar 27 10:46:41 2016 +0000
+++ b/bin/sh/input.c    Sun Mar 27 14:34:46 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: input.c,v 1.47 2016/01/04 03:00:24 christos Exp $      */
+/*     $NetBSD: input.c,v 1.48 2016/03/27 14:34:46 christos Exp $      */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)input.c    8.3 (Berkeley) 6/9/95";
 #else
-__RCSID("$NetBSD: input.c,v 1.47 2016/01/04 03:00:24 christos Exp $");
+__RCSID("$NetBSD: input.c,v 1.48 2016/03/27 14:34:46 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -453,6 +453,7 @@
 void
 setinputstring(char *string, int push)
 {
+
        INTOFF;
        if (push)
                pushfile();
diff -r 8dd60676f9f0 -r 5260b43aa65a bin/sh/main.c
--- a/bin/sh/main.c     Sun Mar 27 10:46:41 2016 +0000
+++ b/bin/sh/main.c     Sun Mar 27 14:34:46 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.62 2016/03/01 21:10:40 martin Exp $ */
+/*     $NetBSD: main.c,v 1.63 2016/03/27 14:34:46 christos Exp $       */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.7 (Berkeley) 7/19/95";
 #else
-__RCSID("$NetBSD: main.c,v 1.62 2016/03/01 21:10:40 martin Exp $");
+__RCSID("$NetBSD: main.c,v 1.63 2016/03/27 14:34:46 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -150,11 +150,7 @@
                                exitshell(exitstatus);
                }
                reset();
-               if (exception == EXINT
-#if ATTY
-                && (! attyset() || equal(termval(), "emacs"))
-#endif
-                ) {
+               if (exception == EXINT) {
                        out2c('\n');
                        flushout(&errout);
                }
diff -r 8dd60676f9f0 -r 5260b43aa65a bin/sh/mkinit.sh
--- a/bin/sh/mkinit.sh  Sun Mar 27 10:46:41 2016 +0000
+++ b/bin/sh/mkinit.sh  Sun Mar 27 14:34:46 2016 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-#      $NetBSD: mkinit.sh,v 1.6 2016/03/08 23:23:31 christos Exp $
+#      $NetBSD: mkinit.sh,v 1.7 2016/03/27 14:34:46 christos Exp $
 
 # Copyright (c) 2003 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -55,7 +55,7 @@
                        IFS='   '
                        set -- $line
                        # ignore duplicates
-                       [ "${includes}" != "${includes%* $2 *}" ] && continue
+                       [ "${includes}" != "${includes% $2 *}" ] && continue
                        includes="$includes$2 "
                        continue
                        ;;
diff -r 8dd60676f9f0 -r 5260b43aa65a bin/sh/mknodenames.sh
--- a/bin/sh/mknodenames.sh     Sun Mar 27 10:46:41 2016 +0000
+++ b/bin/sh/mknodenames.sh     Sun Mar 27 14:34:46 2016 +0000
@@ -7,7 +7,7 @@
 
 NODES=$1
 
-test -t 1 && exec > nodenames.h
+test -t 1 && -z "$2" && exec > nodenames.h
 
 echo "#ifdef DEBUG"
 echo '
diff -r 8dd60676f9f0 -r 5260b43aa65a bin/sh/parser.c
--- a/bin/sh/parser.c   Sun Mar 27 10:46:41 2016 +0000
+++ b/bin/sh/parser.c   Sun Mar 27 14:34:46 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parser.c,v 1.107 2016/03/21 02:37:26 christos Exp $    */
+/*     $NetBSD: parser.c,v 1.108 2016/03/27 14:34:46 christos Exp $    */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)parser.c   8.7 (Berkeley) 5/16/95";
 #else
-__RCSID("$NetBSD: parser.c,v 1.107 2016/03/21 02:37:26 christos Exp $");
+__RCSID("$NetBSD: parser.c,v 1.108 2016/03/27 14:34:46 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -117,13 +117,14 @@
 STATIC int xxreadtoken(void);
 STATIC int readtoken1(int, char const *, char *, int);
 STATIC int noexpand(char *);
-STATIC void synexpect(int) __dead;
+STATIC void synexpect(int, const char *) __dead;
 STATIC void synerror(const char *) __dead;
 STATIC void setprompt(int);
 
 
 static const char EOFhere[] = "EOF reading here (<<) document";
 
+
 /*
  * Read and parse a command.  Returns NEOF on end of file.  (NULL is a
  * valid parse tree indicating a blank line.)
@@ -156,7 +157,7 @@
 {
        union node *n1, *n2, *n3;
        int tok;
-       TRACE(("list: entered\n"));
+       TRACE(("list(%d,%d): entered\n", nlflag, erflag));
 
        checkkwd = 2;
        if (nlflag == 0 && tokendlist[peektoken()])
@@ -192,7 +193,7 @@
                case TBACKGND:
                case TSEMI:
                        tok = readtoken();
-                       /* fall through */
+                       /* FALLTHROUGH */
                case TNL:
                        if (tok == TNL) {
                                parseheredoc();
@@ -209,19 +210,17 @@
                        if (heredoclist)
                                parseheredoc();
                        else
-                               pungetc();              /* push back EOF on input */
+                               pungetc();      /* push back EOF on input */
                        return n1;
                default:
                        if (nlflag || erflag)
-                               synexpect(-1);
+                               synexpect(-1, 0);
                        tokpushback++;
                        return n1;
                }
        }
 }
 
-
-
 STATIC union node *
 andor(void)
 {
@@ -248,8 +247,6 @@
        }
 }
 
-
-
 STATIC union node *
 pipeline(void)
 {
@@ -332,7 +329,7 @@
                n1->type = NIF;
                n1->nif.test = list(0, 0);
                if (readtoken() != TTHEN)
-                       synexpect(TTHEN);
+                       synexpect(TTHEN, 0);
                n1->nif.ifpart = list(0, 0);
                n2 = n1;
                while (readtoken() == TELIF) {
@@ -341,7 +338,7 @@
                        n2->type = NIF;
                        n2->nif.test = list(0, 0);
                        if (readtoken() != TTHEN)
-                               synexpect(TTHEN);
+                               synexpect(TTHEN, 0);
                        n2->nif.ifpart = list(0, 0);
                }
                if (lasttoken == TELSE)
@@ -351,7 +348,7 @@
                        tokpushback++;
                }
                if (readtoken() != TFI)
-                       synexpect(TFI);
+                       synexpect(TFI, 0);
                checkkwd = 1;
                break;
        case TWHILE:
@@ -362,11 +359,11 @@
                n1->nbinary.ch1 = list(0, 0);
                if ((got=readtoken()) != TDO) {
 TRACE(("expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : ""));
-                       synexpect(TDO);
+                       synexpect(TDO, 0);
                }
                n1->nbinary.ch2 = list(0, 0);
                if (readtoken() != TDONE)
-                       synexpect(TDONE);
+                       synexpect(TDONE, 0);
                checkkwd = 1;
                break;
        }
@@ -389,7 +386,7 @@
                        *app = NULL;
                        n1->nfor.args = ap;
                        if (lasttoken != TNL && lasttoken != TSEMI)
-                               synexpect(-1);
+                               synexpect(-1, 0);
                } else {
                        static char argvars[5] = {
                            CTLVAR, VSNORMAL|VSQUOTE, '@', '=', '\0'
@@ -413,17 +410,17 @@
                else if (t == TBEGIN)
                        t = TEND;
                else
-                       synexpect(-1);
+                       synexpect(-1, 0);
                n1->nfor.body = list(0, 0);
                if (readtoken() != t)
-                       synexpect(t);
+                       synexpect(t, 0);
                checkkwd = 1;
                break;
        case TCASE:
                n1 = stalloc(sizeof(struct ncase));
                n1->type = NCASE;
                if (readtoken() != TWORD)
-                       synexpect(TWORD);
+                       synexpect(TWORD, 0);
                n1->ncase.expr = n2 = stalloc(sizeof(struct narg));
                n2->type = NARG;
                n2->narg.text = wordtext;
@@ -431,7 +428,7 @@
                n2->narg.next = NULL;



Home | Main Index | Thread Index | Old Index