Fixed nested loop bug
authorChristos Zoulas <christos@ucbvax.Berkeley.EDU>
Sun, 20 Oct 1991 09:26:42 +0000 (01:26 -0800)
committerChristos Zoulas <christos@ucbvax.Berkeley.EDU>
Sun, 20 Oct 1991 09:26:42 +0000 (01:26 -0800)
SCCS-vsn: bin/csh/func.c 5.27

usr/src/bin/csh/func.c

index 9d0bb0c..bfc7255 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)func.c     5.26 (Berkeley) %G%";
+static char sccsid[] = "@(#)func.c     5.27 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -309,7 +309,7 @@ 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.type == I_SEEK) {
+       if (wp->w_end.type == F_SEEK && wp->w_end.f_seek == 0) {
            search(T_BREAK, 0, NULL);
            btell(&wp->w_end);
        }
            search(T_BREAK, 0, NULL);
            btell(&wp->w_end);
        }
@@ -410,6 +410,7 @@ doforeach(v, t)
     btell(&nwp->w_start);
     nwp->w_fename = Strsave(cp);
     nwp->w_next = whyles;
     btell(&nwp->w_start);
     nwp->w_fename = Strsave(cp);
     nwp->w_next = whyles;
+    nwp->w_end.type = F_SEEK;
     whyles = nwp;
     /*
      * Pre-read the loop so as to be more comprehensible to a terminal user.
     whyles = nwp;
     /*
      * Pre-read the loop so as to be more comprehensible to a terminal user.
@@ -446,7 +447,8 @@ 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.type = I_SEEK;
+       nwp->w_end.type = F_SEEK;
+       nwp->w_end.f_seek = 0;
        nwp->w_next = whyles;
        whyles = nwp;
        zlast = T_WHILE;
        nwp->w_next = whyles;
        whyles = nwp;
        zlast = T_WHILE;
@@ -794,7 +796,7 @@ keyword(wp)
 static void
 toend()
 {
 static void
 toend()
 {
-    if (whyles->w_end.type == I_SEEK) {
+    if (whyles->w_end.type == F_SEEK && whyles->w_end.f_seek == 0) {
        search(T_BREAK, 0, NULL);
        btell(&whyles->w_end);
        whyles->w_end.f_seek--;
        search(T_BREAK, 0, NULL);
        btell(&whyles->w_end);
        whyles->w_end.f_seek--;
@@ -817,9 +819,8 @@ wfree()
     for (; whyles; whyles = nwp) {
        register struct whyle *wp = whyles;
        nwp = wp->w_next;
     for (; whyles; whyles = nwp) {
        register struct whyle *wp = whyles;
        nwp = wp->w_next;
-       if (wp->w_start.type != F_SEEK || wp->w_end.type != F_SEEK)
-           continue;
-
+       if (wp->w_start.type != F_SEEK || wp->w_end.type != F_SEEK) 
+           break;
        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 (o.f_seek >= wp->w_start.f_seek && 
            (wp->w_end.f_seek == 0 || o.f_seek < wp->w_end.f_seek))
            break;