Bugfix for loops in aliases.
authorChristos Zoulas <christos@ucbvax.Berkeley.EDU>
Sat, 31 Aug 1991 12:23:49 +0000 (04:23 -0800)
committerChristos Zoulas <christos@ucbvax.Berkeley.EDU>
Sat, 31 Aug 1991 12:23:49 +0000 (04:23 -0800)
SCCS-vsn: bin/csh/csh.c 5.29
SCCS-vsn: bin/csh/csh.h 5.19
SCCS-vsn: bin/csh/func.c 5.24
SCCS-vsn: bin/csh/lex.c 5.20
SCCS-vsn: bin/csh/extern.h 5.7

usr/src/bin/csh/csh.c
usr/src/bin/csh/csh.h
usr/src/bin/csh/extern.h
usr/src/bin/csh/func.c
usr/src/bin/csh/lex.c

index acbcdaf..15b360f 100644 (file)
@@ -12,7 +12,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)csh.c      5.28 (Berkeley) %G%";
+static char sccsid[] = "@(#)csh.c      5.29 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -938,7 +938,7 @@ process(catch)
             * read fresh stuff. Otherwise, we are rereading input and don't
             * need or want to prompt.
             */
             * read fresh stuff. Otherwise, we are rereading input and don't
             * need or want to prompt.
             */
-           if (fseekp == feobp)
+           if (aret == F_SEEK && fseekp == feobp)
                printprompt();
            (void) fflush(cshout);
        }
                printprompt();
            (void) fflush(cshout);
        }
index bcf9da8..ce09aed 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)csh.h       5.18 (Berkeley) %G%
+ *     @(#)csh.h       5.19 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -209,6 +209,23 @@ struct Bin {
     Char  **Bfbuf;             /* The array of buffer blocks */
 }       B;
 
     Char  **Bfbuf;             /* The array of buffer blocks */
 }       B;
 
+/*
+ * This structure allows us to seek inside aliases
+ */
+struct Ain {
+    int type;
+#define I_SEEK -1              /* Invalid seek */
+#define A_SEEK 0               /* Alias seek */
+#define F_SEEK 1               /* File seek */
+#define E_SEEK 2               /* Eval seek */
+    off_t f_seek;
+    Char **a_seek;
+} ;
+extern int aret;               /* What was the last character returned */
+#define SEEKEQ(a, b) ((a)->type == (b)->type && \
+                     (a)->f_seek == (b)->f_seek && \
+                     (a)->a_seek == (b)->a_seek)
+
 #define        fseekp  B.Bfseekp
 #define        fbobp   B.Bfbobp
 #define        feobp   B.Bfeobp
 #define        fseekp  B.Bfseekp
 #define        fbobp   B.Bfbobp
 #define        feobp   B.Bfeobp
@@ -220,7 +237,7 @@ struct Bin {
  * For whiles, in particular, it reseeks to the beginning of the
  * line the while was on; hence the while placement restrictions.
  */
  * For whiles, in particular, it reseeks to the beginning of the
  * line the while was on; hence the while placement restrictions.
  */
-off_t   lineloc;
+struct Ain lineloc;
 
 bool    cantell;               /* Is current source tellable ? */
 
 
 bool    cantell;               /* Is current source tellable ? */
 
@@ -353,8 +370,8 @@ extern int nsrchn;
  * input.  For foreach (fe), the word list is attached here.
  */
 struct whyle {
  * input.  For foreach (fe), the word list is attached here.
  */
 struct whyle {
-    off_t   w_start;           /* Point to restart loop */
-    off_t   w_end;             /* End of loop (0 if unknown) */
+    struct Ain   w_start;      /* Point to restart loop */
+    struct Ain   w_end;                /* End of loop (0 if unknown) */
     Char  **w_fe, **w_fe0;     /* Current/initial wordlist for fe */
     Char   *w_fename;          /* Name for fe */
     struct whyle *w_next;      /* Next (more outer) loop */
     Char  **w_fe, **w_fe0;     /* Current/initial wordlist for fe */
     Char   *w_fename;          /* Name for fe */
     struct whyle *w_next;      /* Next (more outer) loop */
index a5e2fdf..7c10d0f 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)extern.h    5.6 (Berkeley) %G%
+ *     @(#)extern.h    5.7 (Berkeley) %G%
  */
 
 #include <sys/cdefs.h>
  */
 
 #include <sys/cdefs.h>
@@ -152,7 +152,8 @@ void        savehist __P((struct wordent *));
  * lex.c
  */
 void    addla __P((Char *));
  * lex.c
  */
 void    addla __P((Char *));
-void    bseek __P((off_t));
+void    bseek __P((struct Ain *));
+void    btell __P((struct Ain *));
 void    btoeof __P((void));
 void    copylex __P((struct wordent *, struct wordent *));
 Char   *domod __P((Char *, int));
 void    btoeof __P((void));
 void    copylex __P((struct wordent *, struct wordent *));
 Char   *domod __P((Char *, int));
index 72bfd00..d3fe63d 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)func.c     5.23 (Berkeley) %G%";
+static char sccsid[] = "@(#)func.c     5.24 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -309,12 +309,12 @@ dogoto(v, t)
      */
     zlast = T_GOTO;
     for (wp = whyles; wp; wp = wp->w_next)
      */
     zlast = T_GOTO;
     for (wp = whyles; wp; wp = wp->w_next)
-       if (wp->w_end == 0) {
+       if (wp->w_end.type == I_SEEK) {
            search(T_BREAK, 0, NULL);
            search(T_BREAK, 0, NULL);
-           wp->w_end = fseekp;
+           btell(&wp->w_end);
        }
        else
        }
        else
-           bseek(wp->w_end);
+           bseek(&wp->w_end);
     search(T_GOTO, 0, lp = globone(v[1], G_ERROR));
     xfree((ptr_t) lp);
     /*
     search(T_GOTO, 0, lp = globone(v[1], G_ERROR));
     xfree((ptr_t) lp);
     /*
@@ -407,7 +407,7 @@ doforeach(v, t)
     nwp = (struct whyle *) xcalloc(1, sizeof *nwp);
     nwp->w_fe = nwp->w_fe0 = v;
     gargv = 0;
     nwp = (struct whyle *) xcalloc(1, sizeof *nwp);
     nwp->w_fe = nwp->w_fe0 = v;
     gargv = 0;
-    nwp->w_start = fseekp;
+    btell(&nwp->w_start);
     nwp->w_fename = Strsave(cp);
     nwp->w_next = whyles;
     whyles = nwp;
     nwp->w_fename = Strsave(cp);
     nwp->w_next = whyles;
     whyles = nwp;
@@ -427,7 +427,7 @@ dowhile(v, t)
     struct command *t;
 {
     register int status;
     struct command *t;
 {
     register int status;
-    register bool again = whyles != 0 && whyles->w_start == lineloc &&
+    register bool again = whyles != 0 && SEEKEQ(&whyles->w_start, &lineloc) &&
     whyles->w_fename == 0;
 
     v++;
     whyles->w_fename == 0;
 
     v++;
@@ -446,7 +446,7 @@ dowhile(v, t)
        (struct whyle *) xcalloc(1, sizeof(*nwp));
 
        nwp->w_start = lineloc;
        (struct whyle *) xcalloc(1, sizeof(*nwp));
 
        nwp->w_start = lineloc;
-       nwp->w_end = 0;
+       nwp->w_end.type = I_SEEK;
        nwp->w_next = whyles;
        whyles = nwp;
        zlast = T_WHILE;
        nwp->w_next = whyles;
        whyles = nwp;
        zlast = T_WHILE;
@@ -467,14 +467,14 @@ dowhile(v, t)
 static void
 preread()
 {
 static void
 preread()
 {
-    whyles->w_end = -1;
+    whyles->w_end.type = I_SEEK;
     if (setintr)
        (void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
 
     search(T_BREAK, 0, NULL);          /* read the expression in */
     if (setintr)
        (void) sigblock(sigmask(SIGINT));
     if (setintr)
        (void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
 
     search(T_BREAK, 0, NULL);          /* read the expression in */
     if (setintr)
        (void) sigblock(sigmask(SIGINT));
-    whyles->w_end = fseekp;
+    btell(&whyles->w_end);
 }
 
 void
 }
 
 void
@@ -485,7 +485,7 @@ doend(v, t)
 {
     if (!whyles)
        stderror(ERR_NAME | ERR_NOTWHILE);
 {
     if (!whyles)
        stderror(ERR_NAME | ERR_NOTWHILE);
-    whyles->w_end = fseekp;
+    btell(&whyles->w_end);
     doagain();
 }
 
     doagain();
 }
 
@@ -505,7 +505,7 @@ doagain()
 {
     /* Repeating a while is simple */
     if (whyles->w_fename == 0) {
 {
     /* Repeating a while is simple */
     if (whyles->w_fename == 0) {
-       bseek(whyles->w_start);
+       bseek(&whyles->w_start);
        return;
     }
     /*
        return;
     }
     /*
@@ -518,7 +518,7 @@ doagain()
        return;
     }
     set(whyles->w_fename, Strsave(*whyles->w_fe++));
        return;
     }
     set(whyles->w_fename, Strsave(*whyles->w_fe++));
-    bseek(whyles->w_start);
+    bseek(&whyles->w_start);
 }
 
 void
 }
 
 void
@@ -593,10 +593,14 @@ search(type, level, goal)
 
     Stype = type;
     Sgoal = goal;
 
     Stype = type;
     Sgoal = goal;
-    if (type == T_GOTO)
-       bseek((off_t) 0);
+    if (type == T_GOTO) {
+       struct Ain a;
+       a.type = F_SEEK;
+       a.f_seek = 0;
+       bseek(&a);
+    }
     do {
     do {
-       if (intty && fseekp == feobp)
+       if (intty && fseekp == feobp && aret == F_SEEK)
            (void) fprintf(cshout, "? "), (void) fflush(cshout);
        aword[0] = 0;
        (void) getword(aword);
            (void) fprintf(cshout, "? "), (void) fflush(cshout);
        aword[0] = 0;
        (void) getword(aword);
@@ -790,32 +794,40 @@ keyword(wp)
 static void
 toend()
 {
 static void
 toend()
 {
-    if (whyles->w_end == 0) {
+    if (whyles->w_end.type == I_SEEK) {
        search(T_BREAK, 0, NULL);
        search(T_BREAK, 0, NULL);
-       whyles->w_end = fseekp - 1;
+       btell(&whyles->w_end);
+       whyles->w_end.f_seek--;
     }
     else
     }
     else
-       bseek(whyles->w_end);
+       bseek(&whyles->w_end);
     wfree();
 }
 
 void
 wfree()
 {
     wfree();
 }
 
 void
 wfree()
 {
-    long    o = fseekp;
+    struct Ain    o;
+    struct whyle *nwp;
+    btell(&o);
+
+    if (o.type != F_SEEK) 
+       return;
 
 
-    while (whyles) {
+    for (; whyles; whyles = nwp) {
        register struct whyle *wp = whyles;
        register struct whyle *wp = whyles;
-       register struct whyle *nwp = wp->w_next;
+       nwp = wp->w_next;
+       if (wp->w_start.type != F_SEEK || wp->w_end.type != F_SEEK)
+           continue;
 
 
-       if (o >= wp->w_start && (wp->w_end == 0 || o < wp->w_end))
+       if (o.f_seek >= wp->w_start.f_seek && 
+           (wp->w_end.f_seek == 0 || o.f_seek < wp->w_end.f_seek))
            break;
        if (wp->w_fe0)
            blkfree(wp->w_fe0);
        if (wp->w_fename)
            xfree((ptr_t) wp->w_fename);
        xfree((ptr_t) wp);
            break;
        if (wp->w_fe0)
            blkfree(wp->w_fe0);
        if (wp->w_fename)
            xfree((ptr_t) wp->w_fename);
        xfree((ptr_t) wp);
-       whyles = nwp;
     }
 }
 
     }
 }
 
@@ -1193,6 +1205,8 @@ getval(lp, v)
 badscal:
        stderror(ERR_NAME | ERR_SCALEF);
     }
 badscal:
        stderror(ERR_NAME | ERR_SCALEF);
     }
+    if ((f + 0.5) >= (float) 0x7fffffff || (f + 0.5) < (float) 0x80000000)
+       stderror(ERR_NAME | ERR_SCALEF);
     return ((RLIM_TYPE) (f + 0.5));
 }
 
     return ((RLIM_TYPE) (f + 0.5));
 }
 
index 50a97fd..dcc9d43 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)lex.c      5.19 (Berkeley) %G%";
+static char sccsid[] = "@(#)lex.c      5.20 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -81,6 +81,7 @@ static int exclc = 0;
 
 /* "Globp" for alias resubstitution */
 static Char *alvecp = NULL;
 
 /* "Globp" for alias resubstitution */
 static Char *alvecp = NULL;
+int aret = F_SEEK;
 
 /*
  * Labuf implements a general buffer for lookahead during lexical operations.
 
 /*
  * Labuf implements a general buffer for lookahead during lexical operations.
@@ -118,10 +119,10 @@ lex(hp)
     register struct wordent *wdp;
     int     c;
 
     register struct wordent *wdp;
     int     c;
 
-    lineloc = fseekp;
+    btell(&lineloc);
     hp->next = hp->prev = hp;
     hp->word = STRNULL;
     hp->next = hp->prev = hp;
     hp->word = STRNULL;
-    alvecp = 0, hadhist = 0;
+    hadhist = 0;
     do
        c = readc(0);
     while (c == ' ' || c == '\t');
     do
        c = readc(0);
     while (c == ' ' || c == '\t');
@@ -1090,7 +1091,7 @@ gethent(sc)
            }
            np = lhsb;
            event = 0;
            }
            np = lhsb;
            event = 0;
-           while (!any(": \t\\\n}'\"", c)) {
+           while (!cmap(c, _META | _Q | _Q1) && !any("{}:", c)) {
                if (event != -1 && Isdigit(c))
                    event = event * 10 + c - '0';
                else
                if (event != -1 && Isdigit(c))
                    event = event * 10 + c - '0';
                else
@@ -1231,17 +1232,25 @@ readc(wanteof)
     register int c;
     static  sincereal;
 
     register int c;
     static  sincereal;
 
+    aret = F_SEEK;
     if (c = peekread) {
        peekread = 0;
        return (c);
     }
 top:
     if (c = peekread) {
        peekread = 0;
        return (c);
     }
 top:
+    aret = F_SEEK;
     if (alvecp) {
     if (alvecp) {
-       if (c = *alvecp++)
+       aret = A_SEEK;
+       if (c = *alvecp++) 
            return (c);
        if (alvec && *alvec) {
            return (c);
        if (alvec && *alvec) {
-           alvecp = *alvec++;
-           return (' ');
+               alvecp = *alvec++;
+               return (' ');
+       }
+       else {
+           aret = F_SEEK;
+           alvecp = NULL;
+           return('\n');
        }
     }
     if (alvec) {
        }
     }
     if (alvec) {
@@ -1253,12 +1262,14 @@ top:
        return ('\n');
     }
     if (evalp) {
        return ('\n');
     }
     if (evalp) {
+       aret = E_SEEK;
        if (c = *evalp++)
            return (c);
        if (c = *evalp++)
            return (c);
-       if (*evalvec) {
+       if (evalvec && *evalvec) {
            evalp = *evalvec++;
            return (' ');
        }
            evalp = *evalvec++;
            return (' ');
        }
+       aret = F_SEEK;
        evalp = 0;
     }
     if (evalvec) {
        evalp = 0;
     }
     if (evalvec) {
@@ -1461,29 +1472,46 @@ bfree()
 
 void
 bseek(l)
 
 void
 bseek(l)
-    off_t   l;
-
+    struct Ain   *l;
 {
 {
+    switch (aret = l->type) {
+    case E_SEEK:
+       evalvec = l->a_seek;
+       evalp = (Char *) l->f_seek;
+       return;
+    case A_SEEK:
+       alvec = l->a_seek;
+       alvecp = (Char *) l->f_seek;
+       return;
+    case F_SEEK:       
+       fseekp = l->f_seek;
+       return;
+    default:
+       (void) fprintf(csherr, "Bad seek type %d\n", aret);
+       abort();
+    }
+}
 
 
-    fseekp = l;
-    if (!cantell) {
-#ifdef notdef
-       register struct whyle *wp;
-#endif
-
-       if (!whyles)
-           return;
-#ifdef notdef
-       /*
-        * Christos: I don't understand this? both wp and l are local. What is
-        * this used for? I suspect the author meant fseek = wp->w_start
-        * This seek/tell stuff needs to be re-written...
-        */
-       for (wp = whyles; wp->w_next; wp = wp->w_next)
-           continue;
-       if (wp->w_start > l)
-           l = wp->w_start;
-#endif
+void
+btell(l)
+    struct Ain *l;
+{
+    switch (l->type = aret) {
+    case E_SEEK:
+       l->a_seek = evalvec;
+       l->f_seek = (off_t) evalp;
+       return;
+    case A_SEEK:
+       l->a_seek = alvec;
+       l->f_seek = (off_t) alvecp;
+       return;
+    case F_SEEK:
+       l->f_seek = fseekp;
+       l->a_seek = NULL;
+       return;
+    default:
+       (void) fprintf(csherr, "Bad seek type %d\n", aret);
+       abort();
     }
 }
 
     }
 }