wrong source
authorMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Thu, 14 Mar 1991 11:49:31 +0000 (03:49 -0800)
committerMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Thu, 14 Mar 1991 11:49:31 +0000 (03:49 -0800)
SCCS-vsn: bin/sh/cd.c 5.2
SCCS-vsn: bin/sh/eval.c 5.2
SCCS-vsn: bin/sh/exec.c 5.2
SCCS-vsn: bin/sh/input.c 5.2
SCCS-vsn: bin/sh/main.c 5.2
SCCS-vsn: bin/sh/memalloc.c 5.2
SCCS-vsn: bin/sh/miscbltin.c 5.2
SCCS-vsn: bin/sh/mkinit.c 5.3
SCCS-vsn: bin/sh/options.c 5.2
SCCS-vsn: bin/sh/parser.c 5.2
SCCS-vsn: bin/sh/var.c 5.2
SCCS-vsn: bin/sh/bltin/echo.c 5.2

12 files changed:
usr/src/bin/sh/bltin/echo.c
usr/src/bin/sh/cd.c
usr/src/bin/sh/eval.c
usr/src/bin/sh/exec.c
usr/src/bin/sh/input.c
usr/src/bin/sh/main.c
usr/src/bin/sh/memalloc.c
usr/src/bin/sh/miscbltin.c
usr/src/bin/sh/mkinit.c
usr/src/bin/sh/options.c
usr/src/bin/sh/parser.c
usr/src/bin/sh/var.c

index 08d322b..b136881 100644 (file)
@@ -7,7 +7,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)echo.c      5.1 (Berkeley) %G%
+ *     @(#)echo.c      5.2 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
 
 #include "bltin.h"
 
 
 #include "bltin.h"
 
-#define EOF (-1)
+/* #define eflag 1 */
 
 
-main(argc, argv)  
-       char **argv; 
-{
+main(argc, argv)  char **argv; {
+       register char **ap;
        register char *p;
        register char c;
        int count;
        int nflag = 0;
        register char *p;
        register char c;
        int count;
        int nflag = 0;
+#ifndef eflag
        int eflag = 0;
        int eflag = 0;
-       extern char *optarg;
-       extern int optind, opterr;
-       int ch;
+#endif
 
 
-       opterr = 0;
-       while ((ch = getopt(argc, argv, "ne")) != EOF)
-               switch((char)ch) {
-               case 'n':
+       ap = argv;
+       if (argc)
+               ap++;
+       if ((p = *ap) != NULL) {
+               if (equal(p, "-n")) {
                        nflag++;
                        nflag++;
-                       break;
-               case 'e':
+                       ap++;
+               } else if (equal(p, "-e")) {
+#ifndef eflag
                        eflag++;
                        eflag++;
-                       break;
-               case '?':
-               default:
-                       error("usage: %s [-ne] [arg]...", *argv);
-                       return 0;
-               }
-       argc -= optind;
-       argv += optind;
-
-       if (!eflag) {
-               while (p = *argv++) {
-                       while (*p) {
-                               putchar(*p);
-                               p++;
-                       }
-                       if (*argv) putchar(' ');
+#endif
+                       ap++;
                }
                }
-       } else {
-               while (p = *argv++) {
-                       while (c = *p++) {
-                               if (c == '\\') {
-                                       switch (*p++) {
-                                       case 'b':  c = '\b';  break;
-                                       case 'c':  return 0;    /* exit */
-                                       case 'f':  c = '\f';  break;
-                                       case 'n':  c = '\n';  break;
-                                       case 'r':  c = '\r';  break;
-                                       case 't':  c = '\t';  break;
-                                       case 'v':  c = '\v';  break;
-                                       case '\\':  break;      /* c = '\\' */
-                                       case '0':       /* should be [0-7] */
-                                             c = 0;
-                                             count = 3;
-                                             while (--count >= 0 && (unsigned)(*p - '0') < 8)
-                                                   c = (c << 3) + (*p++ - '0');
-                                             break;
-                                       default:
-                                               p--;
-                                             break;
-                                       }
+       }
+       while ((p = *ap++) != NULL) {
+               while ((c = *p++) != '\0') {
+                       if (c == '\\' && eflag) {
+                               switch (*p++) {
+                               case 'b':  c = '\b';  break;
+                               case 'c':  return 0;            /* exit */
+                               case 'f':  c = '\f';  break;
+                               case 'n':  c = '\n';  break;
+                               case 'r':  c = '\r';  break;
+                               case 't':  c = '\t';  break;
+                               case 'v':  c = '\v';  break;
+                               case '\\':  break;              /* c = '\\' */
+                               case '0':
+                                       c = 0;
+                                       count = 3;
+                                       while (--count >= 0 && (unsigned)(*p - '0') < 8)
+                                               c = (c << 3) + (*p++ - '0');
+                                       break;
+                               default:
+                                       p--;
+                                       break;
                                }
                                }
-                               putchar(c);
                        }
                        }
-                       if (*argv) putchar(' ');
+                       putchar(c);
                }
                }
+               if (*ap)
+                       putchar(' ');
        }
        }
-       if (!nflag)
+       if (! nflag)
                putchar('\n');
        return 0;
 }
                putchar('\n');
        return 0;
 }
-
-#ifndef SHELL
-void
-error(f, a)
-{
-       _doprnt(f, &a, stderr);
-}
-#endif
index a9bba57..e36e1fc 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)cd.c       5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)cd.c       5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -59,7 +59,8 @@ cdcmd(argc, argv)  char **argv; {
        struct stat statb;
        char *padvance();
 
        struct stat statb;
        char *padvance();
 
-       if ((dest = argv[1]) == NULL && (dest = bltinlookup("HOME", 1)) == NULL)
+       nextopt(nullstr);
+       if ((dest = *argptr) == NULL && (dest = bltinlookup("HOME", 1)) == NULL)
                error("HOME not set");
        if (*dest == '/' || (path = bltinlookup("CDPATH", 1)) == NULL)
                path = nullstr;
                error("HOME not set");
        if (*dest == '/' || (path = bltinlookup("CDPATH", 1)) == NULL)
                path = nullstr;
index f345ed4..fbae7ca 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)eval.c     5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)eval.c     5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -102,54 +102,35 @@ SHELLPROC {
 
 
 /*
 
 
 /*
- * The eval builtin.  Do you want clean, straight-forward semantics for
- * your eval command?  If so, read on....
+ * The eval commmand.
  */
 
  */
 
-#ifdef ELIGANT
-evalcmd(argc, argv)  char **argv; {
-       char **ap;
-
-       for (ap = argv + 1 ; *ap ; ap++) {
-               evalstring(*ap);
-       }
-       return exitstatus;
-}
-#else
-
-/*
- * If, on the other hand, you prefer downright bogus semantics in the
- * name of compatibility, here it is...
- */
-
-evalcmd(argc, argv)  char **argv; {
-       char **ap;
-       char *p, *q;
-
-       if (argc <= 1) {
-               p = nullstr;
-       } else if (argc == 2) {
-               p = argv[1];
-       } else {
-               STARTSTACKSTR(p);
-               ap = argv + 1;
-               for (;;) {
-                       q = *ap++;
-                       while (*q) {
-                               STPUTC(*q++, p);
-                       }
-                       if (*ap == NULL)
-                               break;
-                       STPUTC(' ', p);
-               }
-               STPUTC('\0', p);
-               p = grabstackstr(p);
-       }
-       evalstring(p);
-       return exitstatus;
+evalcmd(argc, argv)  
+       char **argv; 
+{
+        char *p;
+        char *concat;
+        char **ap;
+
+        if (argc > 1) {
+                p = argv[1];
+                if (argc > 2) {
+                        STARTSTACKSTR(concat);
+                        ap = argv + 2;
+                        for (;;) {
+                                while (*p)
+                                        STPUTC(*p++, concat);
+                                if ((p = *ap++) == NULL)
+                                        break;
+                                STPUTC(' ', concat);
+                        }
+                        STPUTC('\0', concat);
+                        p = grabstackstr(concat);
+                }
+                evalstring(p);
+        }
+        return exitstatus;
 }
 }
-#endif
-
 
 
 /*
 
 
 /*
index 5656c11..58963a1 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)exec.c     5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)exec.c     5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -59,7 +59,7 @@ struct tblentry {
 
 
 STATIC struct tblentry *cmdtable[CMDTABLESIZE];
 
 
 STATIC struct tblentry *cmdtable[CMDTABLESIZE];
-STATIC int builtinloc;         /* index in path of %builtin, or -1 */
+STATIC int builtinloc = -1;            /* index in path of %builtin, or -1 */
 
 
 #ifdef __STDC__
 
 
 #ifdef __STDC__
@@ -296,7 +296,7 @@ hashcmd(argc, argv)  char **argv; {
                return 0;
        }
        verbose = 0;
                return 0;
        }
        verbose = 0;
-       while ((c = nextopt("rv")) >= 0) {
+       while ((c = nextopt("rv")) != '\0') {
                if (c == 'r') {
                        clearcmdentry(0);
                } else if (c == 'v') {
                if (c == 'r') {
                        clearcmdentry(0);
                } else if (c == 'v') {
index e8f7330..296e8b1 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)input.c    5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)input.c    5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -155,10 +155,23 @@ retry:
        p = parsenextc = parsefile->buf;
        i = read(parsefile->fd, p, BUFSIZ);
        if (i <= 0) {
        p = parsenextc = parsefile->buf;
        i = read(parsefile->fd, p, BUFSIZ);
        if (i <= 0) {
-               if (i < 0 && errno == EINTR)
-                       goto retry;
-               parsenleft = EOF_NLEFT;
-               return PEOF;
+                if (i < 0) {
+                        if (errno == EINTR)
+                                goto retry;
+                        if (parsefile->fd == 0 && errno == EWOULDBLOCK) {
+                                int flags = fcntl(0, F_GETFL, 0);
+                                if (flags >= 0 && flags & FNDELAY) {
+                                        flags &=~ FNDELAY;
+                                        if (fcntl(0, F_SETFL, flags) >= 0) {
+                                                out2str("sh: turning off NDELAY
+ mode\n");
+                                                goto retry;
+                                        }
+                                }
+                        }
+                }
+                parsenleft = EOF_NLEFT;
+                return PEOF;
        }
        parsenleft = i - 1;
 
        }
        parsenleft = i - 1;
 
index 40cdc97..2f1ba64 100644 (file)
@@ -15,7 +15,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <signal.h>
 #endif /* not lint */
 
 #include <signal.h>
@@ -173,7 +173,7 @@ cmdloop(top) {
                }
                n = parsecmd(inter);
 #ifdef DEBUG
                }
                n = parsecmd(inter);
 #ifdef DEBUG
-               /* BROKEN - FIX showtree(n); */
+               /* showtree(n); */
 #endif
                if (n == NEOF) {
                        if (Iflag == 0 || numeof >= 50)
 #endif
                if (n == NEOF) {
                        if (Iflag == 0 || numeof >= 50)
index 9fe373f..6f4ff99 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)memalloc.c 5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)memalloc.c 5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "shell.h"
 #endif /* not lint */
 
 #include "shell.h"
@@ -179,7 +179,7 @@ growstackblock() {
        int oldlen = stacknleft;
        struct stack_block *sp;
 
        int oldlen = stacknleft;
        struct stack_block *sp;
 
-       if (stacknxt == stackp->space) {
+       if (stacknxt == stackp->space && stackp != &stackbase) {
                INTOFF;
                sp = stackp;
                stackp = sp->prev;
                INTOFF;
                sp = stackp;
                stackp = sp->prev;
@@ -230,7 +230,7 @@ grabstackblock(len) {
 char *
 growstackstr() {
        int len = stackblocksize();
 char *
 growstackstr() {
        int len = stackblocksize();
-       if (herefd && len >= 1024) {
+       if (herefd >= 0 && len >= 1024) {
                xwrite(herefd, stackblock(), len);
                sstrnleft = len - 1;
                return stackblock();
                xwrite(herefd, stackblock(), len);
                sstrnleft = len - 1;
                return stackblock();
index b8d48f5..6483cf9 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)miscbltin.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)miscbltin.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -50,7 +50,7 @@ readcmd(argc, argv)  char **argv; {
 
        eflag = 0;
        prompt = NULL;
 
        eflag = 0;
        prompt = NULL;
-       while ((i = nextopt("ep:")) >= 0) {
+       while ((i = nextopt("ep:")) != '\0') {
                if (i == 'p')
                        prompt = optarg;
                else
                if (i == 'p')
                        prompt = optarg;
                else
index e8d73ba..2cd41a4 100644 (file)
@@ -15,23 +15,24 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)mkinit.c   5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)mkinit.c   5.3 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
- * Usage:  mkinit command sourcefile...
- *
  * This program scans all the source files for code to handle various
  * special events and combines this code into one file.  This (allegedly)
  * improves the structure of the program since there is no need for
  * anyone outside of a module to know that that module performs special
  * operations on particular events.  The command is executed iff init.c
  * is actually changed.
  * This program scans all the source files for code to handle various
  * special events and combines this code into one file.  This (allegedly)
  * improves the structure of the program since there is no need for
  * anyone outside of a module to know that that module performs special
  * operations on particular events.  The command is executed iff init.c
  * is actually changed.
+ *
+ * Usage:  mkinit command sourcefile...
  */
 
 
 #include <sys/cdefs.h>
 #include <stdio.h>
  */
 
 
 #include <sys/cdefs.h>
 #include <stdio.h>
+#include <fcntl.h>
 
 
 /*
 
 
 /*
@@ -133,6 +134,8 @@ main(argc, argv)
        char **argv;
        {
        char **ap;
        char **argv;
        {
        char **ap;
+       int fd;
+       char c;
 
        if (argc < 2)
                error("Usage:  mkinit command file...");
 
        if (argc < 2)
                error("Usage:  mkinit command file...");
@@ -145,13 +148,14 @@ main(argc, argv)
                unlink(OUTFILE);
                link(OUTTEMP, OUTFILE);
                unlink(OUTTEMP);
                unlink(OUTFILE);
                link(OUTTEMP, OUTFILE);
                unlink(OUTTEMP);
-               printf("%s\n", argv[1]);
-               execl("/bin/sh", "sh", "-c", argv[1], (char *)0);
-               error("Can't exec shell");
        } else {
                unlink(OUTTEMP);
        } else {
                unlink(OUTTEMP);
-               exit(0);
+               if (touch(OUTOBJ))
+                       exit(0);                /* no compilation necessary */
        }
        }
+       printf("%s\n", argv[1]);
+       execl("/bin/sh", "sh", "-c", argv[1], (char *)0);
+       error("Can't exec shell");
 }
 
 
 }
 
 
@@ -370,8 +374,6 @@ output() {
 
 /*
  * Return true if the new output file is different from the old one.
 
 /*
  * Return true if the new output file is different from the old one.
- * Also return true if init.o has been deleted since we want to force
- * a recompilation in this case.
  */
 
 int
  */
 
 int
@@ -379,9 +381,6 @@ file_changed() {
        register FILE *f1, *f2;
        register int c;
 
        register FILE *f1, *f2;
        register int c;
 
-       if ((c = open(OUTOBJ, 0)) < 0)
-               return 1;
-       close(c);
        if ((f1 = fopen(OUTFILE, "r")) == NULL
         || (f2 = fopen(OUTTEMP, "r")) == NULL)
                return 1;
        if ((f1 = fopen(OUTFILE, "r")) == NULL
         || (f2 = fopen(OUTTEMP, "r")) == NULL)
                return 1;
@@ -393,6 +392,30 @@ file_changed() {
 }
 
 
 }
 
 
+/*
+ * Touch a file.  Returns 0 on failure, 1 on success.
+ */
+
+int
+touch(file)
+       char *file;
+       {
+       int fd;
+       char c;
+
+       if ((fd = open(file, O_RDWR)) < 0)
+               return 0;
+       if (read(fd, &c, 1) != 1) {
+               close(fd);
+               return 0;
+       }
+       lseek(fd, 0L, 0);
+       write(fd, &c, 1);
+       close(fd);
+       return 1;
+}
+
+
 
 /*
  * A text structure is simply a block of text that is kept in memory.
 
 /*
  * A text structure is simply a block of text that is kept in memory.
@@ -433,11 +456,9 @@ addchar(c, text)
        *text->nextc++ = c;
 }
 
        *text->nextc++ = c;
 }
 
-
 /*
  * Write the contents of a text structure to a file.
  */
 /*
  * Write the contents of a text structure to a file.
  */
-
 void
 writetext(text, fp)
        struct text *text;
 void
 writetext(text, fp)
        struct text *text;
@@ -452,8 +473,6 @@ writetext(text, fp)
        }
 }
 
        }
 }
 
-
-
 FILE *
 ckfopen(file, mode)
        char *file;
 FILE *
 ckfopen(file, mode)
        char *file;
@@ -468,8 +487,6 @@ ckfopen(file, mode)
        return fp;
 }
 
        return fp;
 }
 
-
-
 void *
 ckmalloc(nbytes) {
        register char *p;
 void *
 ckmalloc(nbytes) {
        register char *p;
@@ -480,7 +497,6 @@ ckmalloc(nbytes) {
        return p;
 }
 
        return p;
 }
 
-
 char *
 savestr(s)
        char *s;
 char *
 savestr(s)
        char *s;
@@ -492,8 +508,6 @@ savestr(s)
        return p;
 }
 
        return p;
 }
 
-
-
 void
 error(msg)
        char *msg;
 void
 error(msg)
        char *msg;
index 189d0aa..eb080d4 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)options.c  5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)options.c  5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "shell.h"
 #endif /* not lint */
 
 #include "shell.h"
@@ -99,13 +99,23 @@ options(cmdline) {
        int val;
        int c;
 
        int val;
        int c;
 
-       minusc = NULL;
+       if (cmdline)
+               minusc = NULL;
        while ((p = *argptr) != NULL) {
                argptr++;
                if ((c = *p++) == '-') {
                        val = 1;
        while ((p = *argptr) != NULL) {
                argptr++;
                if ((c = *p++) == '-') {
                        val = 1;
-                       if (p[0] == '\0' || p[0] == '-' && p[1] == '\0')
+                        if (p[0] == '\0' || p[0] == '-' && p[1] == '\0') {
+                                if (!cmdline) {
+                                        /* "-" means turn off -x and -v */
+                                        if (p[0] == '\0')
+                                                xflag = vflag = 0;
+                                        /* "--" means reset params */
+                                        else if (*argptr == NULL)
+                                                setparam(argptr);
+                                }
                                break;    /* "-" or  "--" terminates options */
                                break;    /* "-" or  "--" terminates options */
+                       }
                } else if (c == '+') {
                        val = 0;
                } else {
                } else if (c == '+') {
                        val = 0;
                } else {
@@ -115,7 +125,7 @@ options(cmdline) {
                while ((c = *p++) != '\0') {
                        if (c == 'c' && cmdline) {
                                char *q;
                while ((c = *p++) != '\0') {
                        if (c == 'c' && cmdline) {
                                char *q;
-#ifdef NOHACK
+#ifdef NOHACK  /* removing this code allows sh -ce 'foo' for compat */
                                if (*p == '\0')
 #endif
                                        q = *argptr++;
                                if (*p == '\0')
 #endif
                                        q = *argptr++;
@@ -312,13 +322,11 @@ out:
        return 0;
 }
 
        return 0;
 }
 
-
 /*
  * Standard option processing (a la getopt) for builtin routines.  The
  * only argument that is passed to nextopt is the option string; the
 /*
  * Standard option processing (a la getopt) for builtin routines.  The
  * only argument that is passed to nextopt is the option string; the
- * other arguments are unnecessary.  It return the character, or -1 on
- * end of input.  This routine assumes that all characters in optstring
- * are positive.
+ * other arguments are unnecessary.  It return the character, or '\0' on
+ * end of input.
  */
 
 int
  */
 
 int
@@ -331,10 +339,10 @@ nextopt(optstring)
        if ((p = optptr) == NULL || *p == '\0') {
                p = *argptr;
                if (p == NULL || *p != '-' || *++p == '\0')
        if ((p = optptr) == NULL || *p == '\0') {
                p = *argptr;
                if (p == NULL || *p != '-' || *++p == '\0')
-                       return -1;
+                       return '\0';
                argptr++;
                if (p[0] == '-' && p[1] == '\0')        /* check for "--" */
                argptr++;
                if (p[0] == '-' && p[1] == '\0')        /* check for "--" */
-                       return -1;
+                       return '\0';
        }
        c = *p++;
        for (q = optstring ; *q != c ; ) {
        }
        c = *p++;
        for (q = optstring ; *q != c ; ) {
index e496459..0d2c09e 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)parser.c   5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)parser.c   5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "shell.h"
 #endif /* not lint */
 
 #include "shell.h"
@@ -285,6 +285,7 @@ command() {
                }
                if (readtoken() != TFI)
                        synexpect(TFI);
                }
                if (readtoken() != TFI)
                        synexpect(TFI);
+               checkkwd();
                break;
        case TWHILE:
        case TUNTIL:
                break;
        case TWHILE:
        case TUNTIL:
@@ -296,6 +297,7 @@ command() {
                n1->nbinary.ch2 = list(0);
                if (readtoken() != TDONE)
                        synexpect(TDONE);
                n1->nbinary.ch2 = list(0);
                if (readtoken() != TDONE)
                        synexpect(TDONE);
+               checkkwd();
                break;
        case TFOR:
                if (readtoken() != TWORD || quoteflag || ! goodname(wordtext))
                break;
        case TFOR:
                if (readtoken() != TWORD || quoteflag || ! goodname(wordtext))
@@ -339,6 +341,7 @@ command() {
                n1->nfor.body = list(0);
                if (readtoken() != t)
                        synexpect(t);
                n1->nfor.body = list(0);
                if (readtoken() != t)
                        synexpect(t);
+               checkkwd();
                break;
        case TCASE:
                n1 = (union node *)stalloc(sizeof (struct ncase));
                break;
        case TCASE:
                n1 = (union node *)stalloc(sizeof (struct ncase));
@@ -382,6 +385,7 @@ command() {
                *cpp = NULL;
                if (lasttoken != TESAC)
                        synexpect(TESAC);
                *cpp = NULL;
                if (lasttoken != TESAC)
                        synexpect(TESAC);
+               checkkwd();
                break;
        case TLP:
                n1 = (union node *)stalloc(sizeof (struct nredir));
                break;
        case TLP:
                n1 = (union node *)stalloc(sizeof (struct nredir));
@@ -390,11 +394,13 @@ command() {
                n1->nredir.redirect = NULL;
                if (readtoken() != TRP)
                        synexpect(TRP);
                n1->nredir.redirect = NULL;
                if (readtoken() != TRP)
                        synexpect(TRP);
+               checkkwd();
                break;
        case TBEGIN:
                n1 = list(0);
                if (readtoken() != TEND)
                        synexpect(TEND);
                break;
        case TBEGIN:
                n1 = list(0);
                if (readtoken() != TEND)
                        synexpect(TEND);
+               checkkwd();
                break;
        case TWORD:
        case TREDIR:
                break;
        case TWORD:
        case TREDIR:
@@ -452,8 +458,10 @@ simplecmd() {
                        /* We have a function */
                        if (readtoken() != TRP)
                                synexpect(TRP);
                        /* We have a function */
                        if (readtoken() != TRP)
                                synexpect(TRP);
+#ifdef notdef
                        if (! goodname(n->narg.text))
                                synerror("Bad function name");
                        if (! goodname(n->narg.text))
                                synerror("Bad function name");
+#endif
                        n->type = NDEFUN;
                        n->narg.next = command();
                        return n;
                        n->type = NDEFUN;
                        n->narg.next = command();
                        return n;
@@ -565,7 +573,8 @@ checkkwd() {
        register char *const *pp;
        int t;
 
        register char *const *pp;
        int t;
 
-       while ((t = readtoken()) == TNL);
+       while ((t = readtoken()) == TNL)
+               parseheredoc();
        if (t == TWORD && quoteflag == 0) {
                for (pp = parsekwd ; *pp ; pp++) {
                        if (**pp == *wordtext && equal(*pp, wordtext)) {
        if (t == TWORD && quoteflag == 0) {
                for (pp = parsekwd ; *pp ; pp++) {
                        if (**pp == *wordtext && equal(*pp, wordtext)) {
@@ -590,9 +599,6 @@ readtoken() {
        } else {
                t = xxreadtoken();
                TRACE(("token %s %s\n", tokname[t], t == TWORD ? wordtext : ""));
        } else {
                t = xxreadtoken();
                TRACE(("token %s %s\n", tokname[t], t == TWORD ? wordtext : ""));
-               if (vflag)
-                       outfmt(out2, "%s %s\n", tokname[t], 
-                               t == TWORD ? wordtext : "");
                return t;
        }
 }
                return t;
        }
 }
@@ -957,11 +963,7 @@ parsesub: {
 #endif
 
        c = pgetc();
 #endif
 
        c = pgetc();
-       if (c == ' ' || c == '\t' || c == '\n' || c == PEOF
-#ifndef STRICT_VARCHECKING     /* make this an option? */
-           || (c != '(' && c != '{' && !is_name(c) && !is_special(c))
-#endif
-       ) {
+       if (c != '(' && c != '{' && !is_name(c) && !is_special(c)) {
                USTPUTC('$', out);
                pungetc();
        } else if (c == '(') {  /* $(command) */
                USTPUTC('$', out);
                pungetc();
        } else if (c == '(') {  /* $(command) */
@@ -982,7 +984,7 @@ parsesub: {
                        } while (is_in_name(c));
                } else {
                        if (! is_special(c))
                        } while (is_in_name(c));
                } else {
                        if (! is_special(c))
-badsub:                        synerror("Bad substitution");
+badsub:                                synerror("Bad substitution");
                        USTPUTC(c, out);
                        c = pgetc();
                }
                        USTPUTC(c, out);
                        c = pgetc();
                }
index 502634b..fa138f8 100644 (file)
@@ -9,14 +9,13 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)var.c      5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)var.c      5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
  * Shell variables.
  */
 
 #endif /* not lint */
 
 /*
  * Shell variables.
  */
 
-
 #include "shell.h"
 #include "output.h"
 #include "expand.h"
 #include "shell.h"
 #include "output.h"
 #include "expand.h"
@@ -66,7 +65,6 @@ const struct varinit varinit[] = {
        {&vpath,        VSTRFIXED|VTEXTFIXED,           "PATH=:/bin:/usr/bin"},
        {&vps1, VSTRFIXED|VTEXTFIXED,           "PS1=$ "},
        {&vps2, VSTRFIXED|VTEXTFIXED,           "PS2=> "},
        {&vpath,        VSTRFIXED|VTEXTFIXED,           "PATH=:/bin:/usr/bin"},
        {&vps1, VSTRFIXED|VTEXTFIXED,           "PS1=$ "},
        {&vps2, VSTRFIXED|VTEXTFIXED,           "PS2=> "},
-       {&vvers,        VSTRFIXED|VTEXTFIXED,           "SHELLVERS=ash 0.2"},
 #if ATTY
        {&vterm,        VSTRFIXED|VTEXTFIXED|VUNSET,    "TERM="},
 #endif
 #if ATTY
        {&vterm,        VSTRFIXED|VTEXTFIXED|VUNSET,    "TERM="},
 #endif
@@ -120,6 +118,9 @@ initvar() {
 
        for (ip = varinit ; (vp = ip->var) != NULL ; ip++) {
                if ((vp->flags & VEXPORT) == 0) {
 
        for (ip = varinit ; (vp = ip->var) != NULL ; ip++) {
                if ((vp->flags & VEXPORT) == 0) {
+                       if ((strncmp(ip->text, "PS1=", 4) == 0) &&
+                           getuid() == 0)
+                               ip->text = "PS1=# ";
                        vpp = hashvar(ip->text);
                        vp->next = *vpp;
                        *vpp = vp;
                        vpp = hashvar(ip->text);
                        vp->next = *vpp;
                        *vpp = vp;
@@ -127,9 +128,8 @@ initvar() {
                        vp->flags = ip->flags;
                }
        }
                        vp->flags = ip->flags;
                }
        }
-}
-
 
 
+}
 
 /*
  * Set the value of a variable.  The flags argument is ored with the
 
 /*
  * Set the value of a variable.  The flags argument is ored with the