fix xfree() so it can be re-written as a macro
[unix-history] / usr / src / bin / csh / func.c
index 647325c..9011738 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)func.c     5.21 (Berkeley) %G%";
+static char sccsid[] = "@(#)func.c     5.25 (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;
     }
 }
 
     }
 }
 
@@ -902,7 +914,7 @@ dosetenv(v, t)
     }
     if ((lp = *v++) == 0)
        lp = STRNULL;
     }
     if ((lp = *v++) == 0)
        lp = STRNULL;
-    Setenv(vp, lp = globone(lp, G_ERROR));
+    Setenv(vp, lp = globone(lp, G_APPEND));
     if (eq(vp, STRPATH)) {
        importpath(lp);
        dohash(NULL, NULL);
     if (eq(vp, STRPATH)) {
        importpath(lp);
        dohash(NULL, NULL);
@@ -970,7 +982,8 @@ dounsetenv(v, t)
                Unsetenv(name);
                break;
            }
                Unsetenv(name);
                break;
            }
-    xfree((ptr_t) name), name = NULL;
+    xfree((ptr_t) name);
+    name = NULL;
 }
 
 void
 }
 
 void
@@ -1193,6 +1206,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));
 }
 
@@ -1408,3 +1423,21 @@ doeval(v, t)
     if (my_reenter)
        stderror(ERR_SILENT);
 }
     if (my_reenter)
        stderror(ERR_SILENT);
 }
+
+void
+/*ARGSUSED*/
+doprintf(v, t)
+    Char **v;
+    struct command *t;
+{
+    char **c;
+    extern int progprintf __P((int, char **));
+    int ret;
+    
+    ret = progprintf(blklen(v), c = short2blk(v));
+
+    blkfree((Char **) c);
+    if (ret)
+       stderror(ERR_SILENT);
+}
+