Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/csh Make shifting variables reflect their environment co...



details:   https://anonhg.NetBSD.org/src/rev/b76902456d4e
branches:  trunk
changeset: 785862:b76902456d4e
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Apr 03 17:32:24 2013 +0000

description:
Make shifting variables reflect their environment counterparts. Makes
"shift path" work as expected.

diffstat:

 bin/csh/set.c |  131 ++++++++++++++++++++++++++++++---------------------------
 1 files changed, 69 insertions(+), 62 deletions(-)

diffs (166 lines):

diff -r 202b9b443e2e -r b76902456d4e bin/csh/set.c
--- a/bin/csh/set.c     Wed Apr 03 17:15:07 2013 +0000
+++ b/bin/csh/set.c     Wed Apr 03 17:32:24 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: set.c,v 1.31 2013/01/23 16:39:03 christos Exp $ */
+/* $NetBSD: set.c,v 1.32 2013/04/03 17:32:24 christos Exp $ */
 
 /*-
  * Copyright (c) 1980, 1991, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)set.c      8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: set.c,v 1.31 2013/01/23 16:39:03 christos Exp $");
+__RCSID("$NetBSD: set.c,v 1.32 2013/04/03 17:32:24 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -65,6 +65,71 @@
  * C Shell
  */
 
+static void
+update_vars(Char *vp)
+{
+    if (eq(vp, STRpath)) {
+       struct varent *pt = adrof(STRpath); 
+       if (pt == NULL)
+           stderror(ERR_NAME | ERR_UNDVAR);
+       else {
+           exportpath(pt->vec);
+           dohash(NULL, NULL);
+       }
+    }
+    else if (eq(vp, STRhistchars)) {
+       Char *pn = value(STRhistchars);
+
+       HIST = *pn++;
+       HISTSUB = *pn;
+    }
+    else if (eq(vp, STRuser)) {
+       Setenv(STRUSER, value(vp));
+       Setenv(STRLOGNAME, value(vp));
+    }
+    else if (eq(vp, STRwordchars)) {
+       word_chars = value(vp);
+    }
+    else if (eq(vp, STRterm))
+       Setenv(STRTERM, value(vp));
+    else if (eq(vp, STRhome)) {
+       Char *cp;
+
+       cp = Strsave(value(vp));        /* get the old value back */
+
+       /*
+        * convert to canonical pathname (possibly resolving symlinks)
+        */
+       cp = dcanon(cp, cp);
+
+       set(vp, Strsave(cp));   /* have to save the new val */
+
+       /* and now mirror home with HOME */
+       Setenv(STRHOME, cp);
+       /* fix directory stack for new tilde home */
+       dtilde();
+       xfree((ptr_t)cp);
+    }
+#ifdef FILEC
+    else if (eq(vp, STRfilec))
+       filec = 1;
+#endif
+#ifdef EDIT
+    else if (eq(vp, STRedit)) {
+       HistEvent ev;
+       editing = 1;
+       el = el_init_fd(getprogname(), cshin, cshout, csherr,
+           SHIN, SHOUT, SHERR);
+       el_set(el, EL_EDITOR, "emacs");
+       el_set(el, EL_PROMPT, printpromptstr);
+       hi = history_init();
+       history(hi, &ev, H_SETSIZE, getn(value(STRhistory)));
+       loadhist(Histlist.Hnext);
+       el_set(el, EL_HIST, history, hi);
+    }
+#endif
+}
+
 void
 /*ARGSUSED*/
 doset(Char **v, struct command *t)
@@ -128,66 +193,7 @@
            asx(vp, subscr, Strsave(p));
        else
            set(vp, Strsave(p));
-       if (eq(vp, STRpath)) {
-           struct varent *pt = adrof(STRpath); 
-           if (pt == NULL)
-               stderror(ERR_NAME | ERR_UNDVAR);
-           else {
-               exportpath(pt->vec);
-               dohash(NULL, NULL);
-           }
-       }
-       else if (eq(vp, STRhistchars)) {
-           Char *pn = value(STRhistchars);
-
-           HIST = *pn++;
-           HISTSUB = *pn;
-       }
-       else if (eq(vp, STRuser)) {
-           Setenv(STRUSER, value(vp));
-           Setenv(STRLOGNAME, value(vp));
-       }
-       else if (eq(vp, STRwordchars)) {
-           word_chars = value(vp);
-       }
-       else if (eq(vp, STRterm))
-           Setenv(STRTERM, value(vp));
-       else if (eq(vp, STRhome)) {
-           Char *cp;
-
-           cp = Strsave(value(vp));    /* get the old value back */
-
-           /*
-            * convert to canonical pathname (possibly resolving symlinks)
-            */
-           cp = dcanon(cp, cp);
-
-           set(vp, Strsave(cp));       /* have to save the new val */
-
-           /* and now mirror home with HOME */
-           Setenv(STRHOME, cp);
-           /* fix directory stack for new tilde home */
-           dtilde();
-           xfree((ptr_t)cp);
-       }
-#ifdef FILEC
-       else if (eq(vp, STRfilec))
-           filec = 1;
-#endif
-#ifdef EDIT
-       else if (eq(vp, STRedit)) {
-           HistEvent ev;
-           editing = 1;
-           el = el_init_fd(getprogname(), cshin, cshout, csherr,
-               SHIN, SHOUT, SHERR);
-           el_set(el, EL_EDITOR, "emacs");
-           el_set(el, EL_PROMPT, printpromptstr);
-           hi = history_init();
-           history(hi, &ev, H_SETSIZE, getn(value(STRhistory)));
-           loadhist(Histlist.Hnext);
-           el_set(el, EL_HIST, history, hi);
-       }
-#endif
+       update_vars(vp);
     } while ((p = *v++) != NULL);
 }
 
@@ -621,6 +627,7 @@
     if (argv->vec[0] == 0)
        stderror(ERR_NAME | ERR_NOMORE);
     lshift(argv->vec, 1);
+    update_vars(name);
 }
 
 static void



Home | Main Index | Thread Index | Old Index