fix xfree() so it can be re-written as a macro
[unix-history] / usr / src / bin / csh / func.c
index 0981eb2..9011738 100644 (file)
@@ -6,23 +6,38 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)func.c     5.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)func.c     5.25 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
-#include "sh.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <locale.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#if __STDC__
+# include <stdarg.h>
+#else
+# include <varargs.h>
+#endif
+
+#include "csh.h"
+#include "extern.h"
+#include "pathnames.h"
 
 extern char **environ;
 
 static int zlast = -1;
 
 extern char **environ;
 
 static int zlast = -1;
-static void islogin();
-static void reexecute();
-static void preread();
-static void doagain();
-static int getword();
-static int keyword();
-static void Unsetenv();
-static void toend();
-static void xecho();
+static void    islogin __P((void));
+static void    reexecute __P((struct command *));
+static void    preread __P((void));
+static void    doagain __P((void));
+static int     getword __P((Char *));
+static int     keyword __P((Char *));
+static void    Unsetenv __P((Char *));
+static void    toend __P((void));
+static void    xecho __P((int, Char **));
 
 struct biltins *
 isbfunc(t)
 
 struct biltins *
 isbfunc(t)
@@ -84,8 +99,10 @@ func(t, bp)
 }
 
 void
 }
 
 void
-doonintr(v)
-    Char  **v;
+/*ARGSUSED*/
+doonintr(v, t)
+    Char **v;
+    struct command *t;
 {
     register Char *cp;
     register Char *vv = v[1];
 {
     register Char *cp;
     register Char *vv = v[1];
@@ -115,7 +132,10 @@ doonintr(v)
 }
 
 void
 }
 
 void
-donohup()
+/*ARGSUSED*/
+donohup(v, t)
+    Char **v;
+    struct command *t;
 {
     if (intty)
        stderror(ERR_NAME | ERR_TERMINAL);
 {
     if (intty)
        stderror(ERR_NAME | ERR_TERMINAL);
@@ -125,7 +145,10 @@ donohup()
 }
 
 void
 }
 
 void
-dozip()
+/*ARGSUSED*/
+dozip(v, t)
+    Char **v;
+    struct command *t;
 {
     ;
 }
 {
     ;
 }
@@ -137,8 +160,10 @@ prvars()
 }
 
 void
 }
 
 void
-doalias(v)
-    register Char **v;
+/*ARGSUSED*/
+doalias(v, t)
+    Char **v;
+    struct command *t;
 {
     register struct varent *vp;
     register Char *p;
 {
     register struct varent *vp;
     register Char *p;
@@ -149,8 +174,10 @@ doalias(v)
        plist(&aliases);
     else if (*v == 0) {
        vp = adrof1(strip(p), &aliases);
        plist(&aliases);
     else if (*v == 0) {
        vp = adrof1(strip(p), &aliases);
-       if (vp)
-           blkpr(vp->vec), xprintf("\n");
+       if (vp) {
+           blkpr(cshout, vp->vec);
+           fputc('\n', cshout);
+       }
     }
     else {
        if (eq(p, STRalias) || eq(p, STRunalias)) {
     }
     else {
        if (eq(p, STRalias) || eq(p, STRunalias)) {
@@ -162,27 +189,34 @@ doalias(v)
 }
 
 void
 }
 
 void
-unalias(v)
-    Char  **v;
+/*ARGSUSED*/
+unalias(v, t)
+    Char **v;
+    struct command *t;
 {
     unset1(v, &aliases);
 }
 
 void
 {
     unset1(v, &aliases);
 }
 
 void
-dologout()
+/*ARGSUSED*/
+dologout(v, t)
+    Char **v;
+    struct command *t;
 {
     islogin();
     goodbye();
 }
 
 void
 {
     islogin();
     goodbye();
 }
 
 void
-dologin(v)
-    Char  **v;
+/*ARGSUSED*/
+dologin(v, t)
+    Char **v;
+    struct command *t;
 {
     islogin();
     rechist();
     (void) signal(SIGTERM, parterm);
 {
     islogin();
     rechist();
     (void) signal(SIGTERM, parterm);
-    (void) execl(_PATH_LOGIN, "login", short2str(v[1]), (Char *) 0);
+    (void) execl(_PATH_LOGIN, "login", short2str(v[1]), NULL);
     untty();
     xexit(1);
 }
     untty();
     xexit(1);
 }
@@ -219,7 +253,7 @@ doif(v, kp)
         * following code.
         */
        if (!i)
         * following code.
         */
        if (!i)
-           search(T_IF, 0);
+           search(T_IF, 0, NULL);
        return;
     }
     /*
        return;
     }
     /*
@@ -248,18 +282,23 @@ reexecute(kp)
      * pgrp's as the jobs would then have no way to get the tty (we can't give
      * it to them, and our parent wouldn't know their pgrp, etc.
      */
      * pgrp's as the jobs would then have no way to get the tty (we can't give
      * it to them, and our parent wouldn't know their pgrp, etc.
      */
-    execute(kp, (tpgrp > 0 ? tpgrp : -1), (int *) 0, (int *) 0);
+    execute(kp, (tpgrp > 0 ? tpgrp : -1), NULL, NULL);
 }
 
 void
 }
 
 void
-doelse()
+/*ARGSUSED*/
+doelse(v, t)
+    Char **v;
+    struct command *t;
 {
 {
-    search(T_ELSE, 0);
+    search(T_ELSE, 0, NULL);
 }
 
 void
 }
 
 void
-dogoto(v)
-    Char  **v;
+/*ARGSUSED*/
+dogoto(v, t)
+    Char **v;
+    struct command *t;
 {
     register struct whyle *wp;
     Char   *lp;
 {
     register struct whyle *wp;
     Char   *lp;
@@ -270,12 +309,12 @@ dogoto(v)
      */
     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) {
-           search(T_BREAK, 0);
-           wp->w_end = btell();
+       if (wp->w_end.type == I_SEEK) {
+           search(T_BREAK, 0, NULL);
+           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);
     /*
@@ -285,8 +324,10 @@ dogoto(v)
 }
 
 void
 }
 
 void
-doswitch(v)
-    register Char **v;
+/*ARGSUSED*/
+doswitch(v, t)
+    Char **v;
+    struct command *t;
 {
     register Char *cp, *lp;
 
 {
     register Char *cp, *lp;
 
@@ -303,7 +344,10 @@ doswitch(v)
 }
 
 void
 }
 
 void
-dobreak()
+/*ARGSUSED*/
+dobreak(v, t)
+    Char **v;
+    struct command *t;
 {
     if (whyles)
        toend();
 {
     if (whyles)
        toend();
@@ -312,8 +356,10 @@ dobreak()
 }
 
 void
 }
 
 void
-doexit(v)
-    Char  **v;
+/*ARGSUSED*/
+doexit(v, t)
+    Char **v;
+    struct command *t;
 {
     if (chkstop == 0 && (intty || intact) && evalvec == 0)
        panystop(0);
 {
     if (chkstop == 0 && (intty || intact) && evalvec == 0)
        panystop(0);
@@ -332,8 +378,10 @@ doexit(v)
 }
 
 void
 }
 
 void
-doforeach(v)
-    register Char **v;
+/*ARGSUSED*/
+doforeach(v, t)
+    Char **v;
+    struct command *t;
 {
     register Char *cp, *sp;
     register struct whyle *nwp;
 {
     register Char *cp, *sp;
     register struct whyle *nwp;
@@ -359,7 +407,7 @@ doforeach(v)
     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 = btell();
+    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;
@@ -373,11 +421,13 @@ doforeach(v)
 }
 
 void
 }
 
 void
-dowhile(v)
-    Char  **v;
+/*ARGSUSED*/
+dowhile(v, t)
+    Char **v;
+    struct command *t;
 {
     register int status;
 {
     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++;
@@ -396,7 +446,7 @@ dowhile(v)
        (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;
@@ -417,27 +467,33 @@ dowhile(v)
 static void
 preread()
 {
 static void
 preread()
 {
-    whyles->w_end = -1;
+    whyles->w_end.type = I_SEEK;
     if (setintr)
     if (setintr)
-       (void) sigsetmask(sigblock((sigmask_t) 0) & ~sigmask(SIGINT));
+       (void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
 
 
-    search(T_BREAK, 0);                /* read the expression in */
+    search(T_BREAK, 0, NULL);          /* read the expression in */
     if (setintr)
        (void) sigblock(sigmask(SIGINT));
     if (setintr)
        (void) sigblock(sigmask(SIGINT));
-    whyles->w_end = btell();
+    btell(&whyles->w_end);
 }
 
 void
 }
 
 void
-doend()
+/*ARGSUSED*/
+doend(v, t)
+    Char **v;
+    struct command *t;
 {
     if (!whyles)
        stderror(ERR_NAME | ERR_NOTWHILE);
 {
     if (!whyles)
        stderror(ERR_NAME | ERR_NOTWHILE);
-    whyles->w_end = btell();
+    btell(&whyles->w_end);
     doagain();
 }
 
 void
     doagain();
 }
 
 void
-docontin()
+/*ARGSUSED*/
+docontin(v, t)
+    Char **v;
+    struct command *t;
 {
     if (!whyles)
        stderror(ERR_NAME | ERR_NOTWHILE);
 {
     if (!whyles)
        stderror(ERR_NAME | ERR_NOTWHILE);
@@ -449,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;
     }
     /*
@@ -458,11 +514,11 @@ doagain()
      * is 0.
      */
     if (!whyles->w_fe[1]) {
      * is 0.
      */
     if (!whyles->w_fe[1]) {
-       dobreak();
+       dobreak(NULL, NULL);
        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
@@ -471,7 +527,7 @@ dorepeat(v, kp)
     struct command *kp;
 {
     register int i;
     struct command *kp;
 {
     register int i;
-    register sigmask_t omask = 0;
+    register sigset_t omask = 0;
 
     i = getn(v[1]);
     if (setintr)
 
     i = getn(v[1]);
     if (setintr)
@@ -489,9 +545,12 @@ dorepeat(v, kp)
 }
 
 void
 }
 
 void
-doswbrk()
+/*ARGSUSED*/
+doswbrk(v, t)
+    Char **v;
+    struct command *t;
 {
 {
-    search(T_BRKSW, 0);
+    search(T_BRKSW, 0, NULL);
 }
 
 int
 }
 
 int
@@ -534,11 +593,15 @@ 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)
-           xprintf("? "), flush();
+       if (intty && fseekp == feobp && aret == F_SEEK)
+           (void) fprintf(cshout, "? "), (void) fflush(cshout);
        aword[0] = 0;
        (void) getword(aword);
        switch (srchx(aword)) {
        aword[0] = 0;
        (void) getword(aword);
        switch (srchx(aword)) {
@@ -627,7 +690,6 @@ getword(wp)
     register int c, d;
     int     kwd = 0;
     Char   *owp = wp;
     register int c, d;
     int     kwd = 0;
     Char   *owp = wp;
-    static int keyword();
 
     c = readc(1);
     d = 0;
 
     c = readc(1);
     d = 0;
@@ -732,60 +794,72 @@ 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 = btell() - 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 = btell();
+    struct Ain    o;
+    struct whyle *nwp;
+    btell(&o);
 
 
-    while (whyles) {
+    if (o.type != F_SEEK) 
+       return;
+
+    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;
     }
 }
 
 void
     }
 }
 
 void
-doecho(v)
-    Char  **v;
+/*ARGSUSED*/
+doecho(v, t)
+    Char **v;
+    struct command *t;
 {
     xecho(' ', v);
 }
 
 void
 {
     xecho(' ', v);
 }
 
 void
-doglob(v)
-    Char  **v;
+/*ARGSUSED*/
+doglob(v, t)
+    Char **v;
+    struct command *t;
 {
     xecho(0, v);
 {
     xecho(0, v);
-    flush();
+    (void) fflush(cshout);
 }
 
 static void
 xecho(sep, v)
 }
 
 static void
 xecho(sep, v)
-    Char    sep;
+    int    sep;
     register Char **v;
 {
     register Char *cp;
     int     nonl = 0;
 
     if (setintr)
     register Char **v;
 {
     register Char *cp;
     int     nonl = 0;
 
     if (setintr)
-       (void) sigsetmask(sigblock((sigmask_t) 0) & ~sigmask(SIGINT));
+       (void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
     v++;
     if (*v == 0)
        return;
     v++;
     if (*v == 0)
        return;
@@ -805,27 +879,26 @@ xecho(sep, v)
        register int c;
 
        while (c = *cp++)
        register int c;
 
        while (c = *cp++)
-           xputchar(c | QUOTE);
+           (void) fputc(c | QUOTE, cshout);
 
        if (*v)
 
        if (*v)
-           xputchar(sep | QUOTE);
+           (void) fputc(sep | QUOTE, cshout);
     }
     if (sep && nonl == 0)
     }
     if (sep && nonl == 0)
-       xputchar('\n');
+       (void) fputc('\n', cshout);
     else
     else
-       flush();
+       (void) fflush(cshout);
     if (setintr)
        (void) sigblock(sigmask(SIGINT));
     if (gargv)
        blkfree(gargv), gargv = 0;
 }
 
     if (setintr)
        (void) sigblock(sigmask(SIGINT));
     if (gargv)
        blkfree(gargv), gargv = 0;
 }
 
-/* from "Karl Berry." <karl%mote.umb.edu@relay.cs.net> -- for NeXT things
-   (and anything else with a modern compiler) */
-
 void
 void
-dosetenv(v)
-    register Char **v;
+/*ARGSUSED*/
+dosetenv(v, t)
+    Char **v;
+    struct command *t;
 {
     Char   *vp, *lp;
 
 {
     Char   *vp, *lp;
 
@@ -834,17 +907,17 @@ dosetenv(v)
        register Char **ep;
 
        if (setintr)
        register Char **ep;
 
        if (setintr)
-           (void) sigsetmask(sigblock((sigmask_t) 0) & ~sigmask(SIGINT));
+           (void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
        for (ep = STR_environ; *ep; ep++)
        for (ep = STR_environ; *ep; ep++)
-           xprintf("%s\n", short2str(*ep));
+           (void) fprintf(cshout, "%s\n", short2str(*ep));
        return;
     }
     if ((lp = *v++) == 0)
        lp = STRNULL;
        return;
     }
     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);
     if (eq(vp, STRPATH)) {
        importpath(lp);
-       dohash();
+       dohash(NULL, NULL);
     }
     else if (eq(vp, STRLANG) || eq(vp, STRLC_CTYPE)) {
 #ifdef NLS
     }
     else if (eq(vp, STRLANG) || eq(vp, STRLC_CTYPE)) {
 #ifdef NLS
@@ -861,8 +934,10 @@ dosetenv(v)
 }
 
 void
 }
 
 void
-dounsetenv(v)
-    register Char **v;
+/*ARGSUSED*/
+dounsetenv(v, t)
+    Char **v;
+    struct command *t;
 {
     Char  **ep, *p, *n;
     int     i, maxi;
 {
     Char  **ep, *p, *n;
     int     i, maxi;
@@ -881,34 +956,34 @@ dounsetenv(v)
 
     name = (Char *) xmalloc((size_t) (maxi + 1) * sizeof(Char));
 
 
     name = (Char *) xmalloc((size_t) (maxi + 1) * sizeof(Char));
 
-    v++;
-    maxi = 1;
-    while (maxi)
-       for (maxi = 0, ep = STR_environ; *ep; ep++) {
-           for (n = name, p = *ep; *p && *p != '='; *n++ = *p++);
-           *n = '\0';
-           if (!Gmatch(name, *v))
-               continue;
-           maxi = 1;
-           if (eq(name, STRLANG) || eq(name, STRLC_CTYPE)) {
+    while (++v && *v)
+       for (maxi = 1; maxi;)
+           for (maxi = 0, ep = STR_environ; *ep; ep++) {
+               for (n = name, p = *ep; *p && *p != '='; *n++ = *p++);
+               *n = '\0';
+               if (!Gmatch(name, *v))
+                   continue;
+               maxi = 1;
+               if (eq(name, STRLANG) || eq(name, STRLC_CTYPE)) {
 #ifdef NLS
 #ifdef NLS
-               int     k;
+                   int     k;
 
 
-               (void) setlocale(LC_ALL, "");
-               for (k = 0200; k <= 0377 && !Isprint(k); k++);
-               AsciiOnly = k > 0377;
+                   (void) setlocale(LC_ALL, "");
+                   for (k = 0200; k <= 0377 && !Isprint(k); k++);
+                   AsciiOnly = k > 0377;
 #else
 #else
-               AsciiOnly = getenv("LANG") == NULL &&
-                   getenv("LC_CTYPE") == NULL;
+                   AsciiOnly = getenv("LANG") == NULL &&
+                       getenv("LC_CTYPE") == NULL;
 #endif                         /* NLS */
 #endif                         /* NLS */
+               }
+               /*
+                * Delete name, and start again cause the environment changes
+                */
+               Unsetenv(name);
+               break;
            }
            }
-           /*
-            * Delete name, and start again cause the environment changes
-            */
-           Unsetenv(name);
-           break;
-       }
-    xfree((ptr_t) name), name = NULL;
+    xfree((ptr_t) name);
+    name = NULL;
 }
 
 void
 }
 
 void
@@ -969,8 +1044,10 @@ Unsetenv(name)
 }
 
 void
 }
 
 void
-doumask(v)
-    register Char **v;
+/*ARGSUSED*/
+doumask(v, t)
+    Char **v;
+    struct command *t;
 {
     register Char *cp = v[1];
     register int i;
 {
     register Char *cp = v[1];
     register int i;
@@ -978,7 +1055,7 @@ doumask(v)
     if (cp == 0) {
        i = umask(0);
        (void) umask(i);
     if (cp == 0) {
        i = umask(0);
        (void) umask(i);
-       xprintf("%o\n", i);
+       (void) fprintf(cshout, "%o\n", i);
        return;
     }
     i = 0;
        return;
     }
     i = 0;
@@ -1003,7 +1080,10 @@ static struct limits {
     RLIMIT_STACK,      "stacksize",    1024,   "kbytes",
     RLIMIT_CORE,       "coredumpsize", 1024,   "kbytes",
     RLIMIT_RSS,                "memoryuse",    1024,   "kbytes",
     RLIMIT_STACK,      "stacksize",    1024,   "kbytes",
     RLIMIT_CORE,       "coredumpsize", 1024,   "kbytes",
     RLIMIT_RSS,                "memoryuse",    1024,   "kbytes",
-    -1,                (char *) 0,     0,      (char *) 0
+    RLIMIT_MEMLOCK,    "memorylocked", 1024,   "kbytes",
+    RLIMIT_NPROC,      "maxproc",      1,      "",
+    RLIMIT_OFILE,      "openfiles",    1,      "",
+    -1,                NULL,           0,      NULL
 };
 
 static struct limits *findlim();
 };
 
 static struct limits *findlim();
@@ -1033,8 +1113,10 @@ findlim(cp)
 }
 
 void
 }
 
 void
-dolimit(v)
-    register Char **v;
+/*ARGSUSED*/
+dolimit(v, t)
+    Char **v;
+    struct command *t;
 {
     register struct limits *lp;
     register RLIM_TYPE limit;
 {
     register struct limits *lp;
     register RLIM_TYPE limit;
@@ -1124,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));
 }
 
@@ -1148,23 +1232,26 @@ plim(lp, hard)
     struct rlimit rlim;
     RLIM_TYPE limit;
 
     struct rlimit rlim;
     RLIM_TYPE limit;
 
-    xprintf("%s \t", lp->limname);
+    (void) fprintf(cshout, "%s \t", lp->limname);
 
     (void) getrlimit(lp->limconst, &rlim);
     limit = hard ? rlim.rlim_max : rlim.rlim_cur;
 
     if (limit == RLIM_INFINITY)
 
     (void) getrlimit(lp->limconst, &rlim);
     limit = hard ? rlim.rlim_max : rlim.rlim_cur;
 
     if (limit == RLIM_INFINITY)
-       xprintf("unlimited");
+       (void) fprintf(cshout, "unlimited");
     else if (lp->limconst == RLIMIT_CPU)
        psecs((long) limit);
     else
     else if (lp->limconst == RLIMIT_CPU)
        psecs((long) limit);
     else
-       xprintf("%ld %s", (long) (limit / lp->limdiv), lp->limscale);
-    xprintf("\n");
+       (void) fprintf(cshout, "%ld %s", (long) (limit / lp->limdiv), 
+                      lp->limscale);
+    (void) fputc('\n', cshout);
 }
 
 void
 }
 
 void
-dounlimit(v)
-    register Char **v;
+/*ARGSUSED*/
+dounlimit(v, t)
+    Char **v;
+    struct command *t;
 {
     register struct limits *lp;
     int     lerr = 0;
 {
     register struct limits *lp;
     int     lerr = 0;
@@ -1208,16 +1295,19 @@ setlim(lp, hard, limit)
        rlim.rlim_cur = limit;
 
     if (setrlimit(lp->limconst, &rlim) < 0) {
        rlim.rlim_cur = limit;
 
     if (setrlimit(lp->limconst, &rlim) < 0) {
-       xprintf("%s: %s: Can't %s%s limit\n", bname, lp->limname,
-               limit == RLIM_INFINITY ? "remove" : "set",
-               hard ? " hard" : "");
+       (void) fprintf(csherr, "%s: %s: Can't %s%s limit\n", bname, lp->limname,
+                      limit == RLIM_INFINITY ? "remove" : "set",
+                      hard ? " hard" : "");
        return (-1);
     }
     return (0);
 }
 
 void
        return (-1);
     }
     return (0);
 }
 
 void
-dosuspend()
+/*ARGSUSED*/
+dosuspend(v, t)
+    Char **v;
+    struct command *t;
 {
     int     ctpgrp;
 
 {
     int     ctpgrp;
 
@@ -1233,13 +1323,11 @@ dosuspend()
     (void) signal(SIGTSTP, old);
 
     if (tpgrp != -1) {
     (void) signal(SIGTSTP, old);
 
     if (tpgrp != -1) {
-retry:
        ctpgrp = tcgetpgrp(FSHTTY);
        ctpgrp = tcgetpgrp(FSHTTY);
-       if (ctpgrp != opgrp) {
+       while  (ctpgrp != opgrp) {
            old = signal(SIGTTIN, SIG_DFL);
            (void) kill(0, SIGTTIN);
            (void) signal(SIGTTIN, old);
            old = signal(SIGTTIN, SIG_DFL);
            (void) kill(0, SIGTTIN);
            (void) signal(SIGTTIN, old);
-           goto retry;
        }
        (void) setpgid(0, shpgrp);
        (void) tcsetpgrp(FSHTTY, shpgrp);
        }
        (void) setpgid(0, shpgrp);
        (void) tcsetpgrp(FSHTTY, shpgrp);
@@ -1258,29 +1346,32 @@ retry:
  *   Otherwise, under stty tostop, processes will stop in the wrong
  *   pgrp, with no way for the shell to get them going again.  -IAN!
  */
  *   Otherwise, under stty tostop, processes will stop in the wrong
  *   pgrp, with no way for the shell to get them going again.  -IAN!
  */
+static Char **gv = NULL;
 void
 void
-doeval(v)
-    Char  **v;
+/*ARGSUSED*/
+doeval(v, t)
+    Char **v;
+    struct command *t;
 {
     Char  **oevalvec;
     Char   *oevalp;
     int     odidfds;
     jmp_buf osetexit;
     int     my_reenter;
 {
     Char  **oevalvec;
     Char   *oevalp;
     int     odidfds;
     jmp_buf osetexit;
     int     my_reenter;
-    Char  **gv;
+    Char  **savegv = gv;
     int     saveIN;
     int     saveOUT;
     int     saveIN;
     int     saveOUT;
-    int     saveDIAG;
+    int     saveERR;
     int     oSHIN;
     int     oSHOUT;
     int     oSHIN;
     int     oSHOUT;
-    int     oSHDIAG;
+    int     oSHERR;
 
     oevalvec = evalvec;
     oevalp = evalp;
     odidfds = didfds;
     oSHIN = SHIN;
     oSHOUT = SHOUT;
 
     oevalvec = evalvec;
     oevalp = evalp;
     odidfds = didfds;
     oSHIN = SHIN;
     oSHOUT = SHOUT;
-    oSHDIAG = SHDIAG;
+    oSHERR = SHERR;
 
     v++;
     if (*v == 0)
 
     v++;
     if (*v == 0)
@@ -1294,14 +1385,14 @@ doeval(v)
        v = copyblk(v);
     }
     else {
        v = copyblk(v);
     }
     else {
-       gv = (Char **) 0;
+       gv = NULL;
        v = copyblk(v);
        trim(v);
     }
 
     saveIN = dcopy(SHIN, -1);
     saveOUT = dcopy(SHOUT, -1);
        v = copyblk(v);
        trim(v);
     }
 
     saveIN = dcopy(SHIN, -1);
     saveOUT = dcopy(SHOUT, -1);
-    saveDIAG = dcopy(SHDIAG, -1);
+    saveERR = dcopy(SHERR, -1);
 
     getexit(osetexit);
 
 
     getexit(osetexit);
 
@@ -1310,7 +1401,7 @@ doeval(v)
        evalp = 0;
        SHIN = dcopy(0, -1);
        SHOUT = dcopy(1, -1);
        evalp = 0;
        SHIN = dcopy(0, -1);
        SHOUT = dcopy(1, -1);
-       SHDIAG = dcopy(2, -1);
+       SHERR = dcopy(2, -1);
        didfds = 0;
        process(0);
     }
        didfds = 0;
        process(0);
     }
@@ -1321,14 +1412,32 @@ doeval(v)
     didfds = odidfds;
     (void) close(SHIN);
     (void) close(SHOUT);
     didfds = odidfds;
     (void) close(SHIN);
     (void) close(SHOUT);
-    (void) close(SHDIAG);
+    (void) close(SHERR);
     SHIN = dmove(saveIN, oSHIN);
     SHOUT = dmove(saveOUT, oSHOUT);
     SHIN = dmove(saveIN, oSHIN);
     SHOUT = dmove(saveOUT, oSHOUT);
-    SHDIAG = dmove(saveDIAG, oSHDIAG);
-
+    SHERR = dmove(saveERR, oSHERR);
     if (gv)
     if (gv)
-       blkfree(gv);
+       blkfree(gv), gv = NULL;
     resexit(osetexit);
     resexit(osetexit);
+    gv = savegv;
     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);
+}
+