BSD 4_4_Lite2 release
[unix-history] / usr / src / bin / csh / set.c
index 5093c05..1192163 100644 (file)
@@ -1,16 +1,45 @@
 /*-
 /*-
- * Copyright (c) 1980, 1991 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1991, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)set.c      5.13 (Berkeley) %G%";
+static char sccsid[] = "@(#)set.c      8.2 (Berkeley) 3/22/95";
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <stdlib.h>
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <stdlib.h>
+#ifndef SHORT_STRINGS
+#include <string.h>
+#endif /* SHORT_STRINGS */
 #if __STDC__
 # include <stdarg.h>
 #else
 #if __STDC__
 # include <stdarg.h>
 #else
@@ -22,12 +51,12 @@ static char sccsid[] = "@(#)set.c   5.13 (Berkeley) %G%";
 
 static Char    *getinx __P((Char *, int *));
 static void     asx __P((Char *, int, Char *));
 
 static Char    *getinx __P((Char *, int *));
 static void     asx __P((Char *, int, Char *));
-static struct varent 
+static struct varent
                *getvx __P((Char *, int));
 static Char    *xset __P((Char *, Char ***));
 static Char    *operate __P((int, Char *, Char *));
 static void     putn1 __P((int));
                *getvx __P((Char *, int));
 static Char    *xset __P((Char *, Char ***));
 static Char    *operate __P((int, Char *, Char *));
 static void     putn1 __P((int));
-static struct varent 
+static struct varent
                *madrof __P((Char *, struct varent *));
 static void     unsetv1 __P((struct varent *));
 static void     exportpath __P((Char **));
                *madrof __P((Char *, struct varent *));
 static void     unsetv1 __P((struct varent *));
 static void     exportpath __P((Char **));
@@ -72,7 +101,7 @@ doset(v, t)
            hadsub++;
            p = getinx(p, &subscr);
        }
            hadsub++;
            p = getinx(p, &subscr);
        }
-       if (op = *p) {
+       if ((op = *p) != '\0') {
            *p++ = 0;
            if (*p == 0 && *v && **v == '(')
                p = *v++;
            *p++ = 0;
            if (*p == 0 && *v && **v == '(')
                p = *v++;
@@ -148,7 +177,7 @@ doset(v, t)
        else if (eq(vp, STRfilec))
            filec = 1;
 #endif
        else if (eq(vp, STRfilec))
            filec = 1;
 #endif
-    } while (p = *v++);
+    } while ((p = *v++) != NULL);
 }
 
 static Char *
 }
 
 static Char *
@@ -225,7 +254,7 @@ dolet(v, t)
        }
        if (*p == 0 && *v)
            p = *v++;
        }
        if (*p == 0 && *v)
            p = *v++;
-       if (op = *p)
+       if ((op = *p) != '\0')
            *p++ = 0;
        else
            stderror(ERR_NAME | ERR_ASSIGN);
            *p++ = 0;
        else
            stderror(ERR_NAME | ERR_ASSIGN);
@@ -276,7 +305,7 @@ dolet(v, t)
        xfree((ptr_t) vp);
        if (c != '=')
            xfree((ptr_t) p);
        xfree((ptr_t) vp);
        if (c != '=')
            xfree((ptr_t) p);
-    } while (p = *v++);
+    } while ((p = *v++) != NULL);
 }
 
 static Char *
 }
 
 static Char *
@@ -291,7 +320,7 @@ xset(cp, vp)
        xfree((ptr_t) ** vp);
        **vp = dp;
     }
        xfree((ptr_t) ** vp);
        **vp = dp;
     }
-    return (putn(exp(vp)));
+    return (putn(expr(vp)));
 }
 
 static Char *
 }
 
 static Char *
@@ -316,7 +345,7 @@ operate(op, vp, p)
     }
     *v++ = p;
     *v++ = 0;
     }
     *v++ = p;
     *v++ = 0;
-    i = exp(&vecp);
+    i = expr(&vecp);
     if (*vecp)
        stderror(ERR_NAME | ERR_EXPRESSION);
     return (putn(i));
     if (*vecp)
        stderror(ERR_NAME | ERR_EXPRESSION);
     return (putn(i));
@@ -337,7 +366,7 @@ putn(n)
        *putp++ = '-';
     }
     num = 2;                   /* confuse lint */
        *putp++ = '-';
     }
     num = 2;                   /* confuse lint */
-    if (sizeof(int) == num && n == -32768) {
+    if (sizeof(int) == num && ((unsigned int) n) == 0x8000) {
        *putp++ = '3';
        n = 2768;
 #ifdef pdp11
        *putp++ = '3';
        n = 2768;
 #ifdef pdp11
@@ -346,7 +375,7 @@ putn(n)
     }
     else {
        num = 4;                /* confuse lint */
     }
     else {
        num = 4;                /* confuse lint */
-       if (sizeof(int) == num && n == -2147483648) {
+       if (sizeof(int) == num && ((unsigned int) n) == 0x80000000) {
            *putp++ = '2';
            n = 147483648;
        }
            *putp++ = '2';
            n = 147483648;
        }
@@ -480,7 +509,7 @@ setq(name, vec, p)
     register f;
 
     f = 0;                     /* tree hangs off the header's left link */
     register f;
 
     f = 0;                     /* tree hangs off the header's left link */
-    while (c = p->v_link[f]) {
+    while ((c = p->v_link[f]) != NULL) {
        if ((f = *name - *c->v_name) == 0 &&
            (f = Strcmp(name, c->v_name)) == 0) {
            blkfree(c->vec);
        if ((f = *name - *c->v_name) == 0 &&
            (f = Strcmp(name, c->v_name)) == 0) {
            blkfree(c->vec);
@@ -528,10 +557,10 @@ unset1(v, head)
 
     while (*++v) {
        cnt = 0;
 
     while (*++v) {
        cnt = 0;
-       while (vp = madrof(*v, head->v_left))
+       while ((vp = madrof(*v, head->v_left)) != NULL)
            unsetv1(vp), cnt++;
        if (cnt == 0)
            unsetv1(vp), cnt++;
        if (cnt == 0)
-           setname(short2str(*v));
+           setname(vis_str(*v));
     }
 }
 
     }
 }
 
@@ -568,7 +597,8 @@ unsetv1(p)
     else if (p->v_left == 0)
        c = p->v_right;
     else {
     else if (p->v_left == 0)
        c = p->v_right;
     else {
-       for (c = p->v_left; c->v_right; c = c->v_right);
+       for (c = p->v_left; c->v_right; c = c->v_right)
+           continue;
        p->v_name = c->v_name;
        p->vec = c->vec;
        p = c;
        p->v_name = c->v_name;
        p->vec = c->vec;
        p = c;
@@ -579,7 +609,7 @@ unsetv1(p)
      */
     pp = p->v_parent;
     f = pp->v_right == p;
      */
     pp = p->v_parent;
     f = pp->v_right == p;
-    if (pp->v_link[f] = c)
+    if ((pp->v_link[f] = c) != NULL)
        c->v_parent = pp;
     /*
      * Free the deleted node, and rebalance.
        c->v_parent = pp;
     /*
      * Free the deleted node, and rebalance.
@@ -632,6 +662,9 @@ exportpath(val)
                               "Warning: ridiculously long PATH truncated\n");
                break;
            }
                               "Warning: ridiculously long PATH truncated\n");
                break;
            }
+           if ((**val != '/' || **val == '\0') && (euid == 0 || uid == 0)) 
+                   (void) fprintf(csherr,
+                   "Warning: exported path contains relative components.\n");
            (void) Strcat(exppath, *val++);
            if (*val == 0 || eq(*val, STRRparen))
                break;
            (void) Strcat(exppath, *val++);
            if (*val == 0 || eq(*val, STRRparen))
                break;
@@ -697,7 +730,7 @@ balance(p, f, d)
      * is the branch of p from which we have come; ff is the branch of pp which
      * is p.
      */
      * is the branch of p from which we have come; ff is the branch of pp which
      * is p.
      */
-    for (; pp = p->v_parent; p = pp, f = ff) {
+    for (; (pp = p->v_parent) != NULL; p = pp, f = ff) {
        ff = pp->v_right == p;
        if (f ^ d) {            /* right heavy */
            switch (p->v_bal) {
        ff = pp->v_right == p;
        if (f ^ d) {            /* right heavy */
            switch (p->v_bal) {
@@ -780,9 +813,13 @@ plist(p)
 {
     register struct varent *c;
     register len;
 {
     register struct varent *c;
     register len;
+    sigset_t sigset;
 
 
-    if (setintr)
-       (void) sigsetmask(sigblock((sigset_t) 0) & ~sigmask(SIGINT));
+    if (setintr) {
+       sigemptyset(&sigset);
+       sigaddset(&sigset, SIGINT);
+       sigprocmask(SIG_UNBLOCK, &sigset, NULL);
+    }
 
     for (;;) {
        while (p->v_left)
 
     for (;;) {
        while (p->v_left)
@@ -791,8 +828,7 @@ x:
        if (p->v_parent == 0)   /* is it the header? */
            return;
        len = blklen(p->vec);
        if (p->v_parent == 0)   /* is it the header? */
            return;
        len = blklen(p->vec);
-       (void) fprintf(cshout, short2str(p->v_name));
-       (void) fputc('\t', cshout);
+       (void) fprintf(cshout, "%s\t", short2str(p->v_name));
        if (len != 1)
            (void) fputc('(', cshout);
        blkpr(cshout, p->vec);
        if (len != 1)
            (void) fputc('(', cshout);
        blkpr(cshout, p->vec);