Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: uppercase inheritance



Norman.Azadian@xxxxxxxxxxxx wrote:
> I've tried this under version 3.1.6 (on HP-UX version 11.0):
> 
> 	= typeset -u -x aaa=bbb
> 	= echo $aaa
> 	BBB
> 	= zsh
> 	= echo $aaa
> 	bbb
> 	=
> 
> Am I missing something, or has ZSH neglected to pass on the uppercase
> property to the subshell?

The problem is that the version in the environment isn't uppercased;
actually, I'm not completely convinced that this is wrong, since the
typeset specifiers are quiet specifically for output formatting, not for
transformations on the variable itself.  The following will make that
happen, but notice that what's in the environment continues to reflect the
status when the variable was last assigned, not the state of the uppercase
flag.  I wouldn't like to alter that without major changes to the structure
of the code (which could happen if we were to introduce get/set functions
for variables).

Index: Src/builtin.c
===================================================================
RCS file: /home/pws/CVSROOT/projects/zsh/Src/builtin.c,v
retrieving revision 1.6
diff -u -r1.6 builtin.c
--- Src/builtin.c	1999/12/06 23:18:02	1.6
+++ Src/builtin.c	1999/12/10 20:03:05
@@ -645,13 +645,13 @@
     if (!(pm->flags & PM_EXPORTED) &&
 	(!pm->level || (isset(ALLEXPORT) && !pm->old))) {
 	pm->flags |= PM_EXPORTED;
-	pm->env = addenv("PWD", pwd);
+	pm->env = addenv("PWD", pwd, pm->flags);
     }
     pm = (Param) paramtab->getnode(paramtab, "OLDPWD");
     if (!(pm->flags & PM_EXPORTED) &&
 	(!pm->level || (isset(ALLEXPORT) && !pm->old))) {
 	pm->flags |= PM_EXPORTED;
-	pm->env = addenv("OLDPWD", oldpwd);
+	pm->env = addenv("OLDPWD", oldpwd, pm->flags);
     }
 }
 
@@ -1621,7 +1621,7 @@
 	if (!(pm->flags & (PM_ARRAY|PM_HASHED))) {
 	    if (pm->flags & PM_EXPORTED) {
 		if (!(pm->flags & PM_UNSET) && !pm->env && !value)
-		    pm->env = addenv(pname, getsparam(pname));
+		    pm->env = addenv(pname, getsparam(pname), pm->flags);
 	    } else if (pm->env &&
 		       (!pm->level || (isset(ALLEXPORT) && !pm->old))) {
 		delenv(pm->env);
Index: Src/exec.c
===================================================================
RCS file: /home/pws/CVSROOT/projects/zsh/Src/exec.c,v
retrieving revision 1.3
diff -u -r1.3 exec.c
--- Src/exec.c	1999/12/06 23:18:02	1.3
+++ Src/exec.c	1999/12/10 20:03:04
@@ -2217,7 +2217,7 @@
 	    } else
 		paramtab->addnode(paramtab, pm->nam, pm);
 	    if ((pm->flags & PM_EXPORTED) && ((s = getsparam(pm->nam))))
-		pm->env = addenv(pm->nam, s);
+		pm->env = addenv(pm->nam, s, pm->flags);
 	}
     }
 }
Index: Src/params.c
===================================================================
RCS file: /home/pws/CVSROOT/projects/zsh/Src/params.c,v
retrieving revision 1.2
diff -u -r1.2 params.c
--- Src/params.c	1999/12/03 19:12:10	1.2
+++ Src/params.c	1999/12/10 20:10:48
@@ -510,7 +510,8 @@
 			pm->env = *envp++ = ztrdup(*envp2);
 			*envp = NULL;
 			if (pm->flags & PM_SPECIAL)
-			    pm->env = replenv(pm->env, getsparam(pm->nam));
+			    pm->env = replenv(pm->env, getsparam(pm->nam),
+					      pm->flags);
 		    }
 		}
 		*str = '=';
@@ -522,18 +523,18 @@
 	pm = (Param) paramtab->getnode(paramtab, "HOME");
 	if (!(pm->flags & PM_EXPORTED)) {
 	    pm->flags |= PM_EXPORTED;
-	    pm->env = addenv("HOME", home);
+	    pm->env = addenv("HOME", home, pm->flags);
 	}
 	pm = (Param) paramtab->getnode(paramtab, "LOGNAME");
 	if (!(pm->flags & PM_EXPORTED)) {
 	    pm->flags |= PM_EXPORTED;
-	    pm->env = addenv("LOGNAME", pm->u.str);
+	    pm->env = addenv("LOGNAME", pm->u.str, pm->flags);
 	}
 	pm = (Param) paramtab->getnode(paramtab, "SHLVL");
 	if (!(pm->flags & PM_EXPORTED))
 	    pm->flags |= PM_EXPORTED;
 	sprintf(buf, "%d", (int)++shlvl);
-	pm->env = addenv("SHLVL", buf);
+	pm->env = addenv("SHLVL", buf, pm->flags);
 
 	/* Add the standard non-special parameters */
 	set_pwd_env();
@@ -1506,10 +1507,10 @@
     else
 	val = v->pm->gets.cfn(v->pm);
     if (v->pm->env)
-	v->pm->env = replenv(v->pm->env, val);
+	v->pm->env = replenv(v->pm->env, val, v->pm->flags);
     else {
 	v->pm->flags |= PM_EXPORTED;
-	v->pm->env = addenv(v->pm->nam, val);
+	v->pm->env = addenv(v->pm->nam, val, v->pm->flags);
     }
 }
 
@@ -2683,13 +2684,13 @@
     len_s = strlen(s);
     for (ep = environ; *ep; ep++)
 	if (!strncmp(*ep, s, len_s) && (*ep)[len_s] == '=') {
-	    pm->env = replenv(*ep, u);
+	    pm->env = replenv(*ep, u, pm->flags);
 	    return;
 	}
     if (isset(ALLEXPORT))
 	pm->flags |= PM_EXPORTED;
     if (pm->flags & PM_EXPORTED)
-	pm->env = addenv(s, u);
+	pm->env = addenv(s, u, pm->flags);
 }
 
 /* Given *name = "foo", it searchs the environment for string *
@@ -2709,11 +2710,25 @@
     return NULL;
 }
 
+/**/
+static void
+copyenvstr(char *s, char *value, int flags)
+{
+    while (*s++) {
+	if ((*s = *value++) == Meta)
+	    *s = *value++ ^ 32;
+	if (flags & PM_LOWER)
+	    *s = tulower(*s);
+	else if (flags & PM_UPPER)
+	    *s = tuupper(*s);
+    }
+}
+
 /* Change the value of an existing environment variable */
 
 /**/
 char *
-replenv(char *e, char *value)
+replenv(char *e, char *value, int flags)
 {
     char **ep, *s;
     int len_value;
@@ -2726,9 +2741,7 @@
 	    while (*s++ != '=');
 	    *ep = (char *) zrealloc(e, s - e + len_value + 1);
 	    s = s - e + *ep - 1;
-	    while (*s++)
-		if ((*s = *value++) == Meta)
-		    *s = *value++ ^ 32;
+	    copyenvstr(s, value, flags);
 	    return *ep;
 	}
     return NULL;
@@ -2739,7 +2752,7 @@
 
 /**/
 static char *
-mkenvstr(char *name, char *value)
+mkenvstr(char *name, char *value, int flags)
 {
     char *str, *s;
     int len_name, len_value;
@@ -2751,9 +2764,7 @@
     strcpy(s, name);
     s += len_name;
     *s = '=';
-    while (*s++)
-	if ((*s = *value++) == Meta)
-	    *s = *value++ ^ 32;
+    copyenvstr(s, value, flags);
     return str;
 }
 
@@ -2764,7 +2775,7 @@
 
 /**/
 char *
-addenv(char *name, char *value)
+addenv(char *name, char *value, int flags)
 {
     char **ep, *s, *t;
     int num_env;
@@ -2775,7 +2786,7 @@
 	for (s = *ep, t = name; *s && *s == *t; s++, t++);
 	if (*s == '=' && !*t) {
 	    zsfree(*ep);
-	    return *ep = mkenvstr(name, value);
+	    return *ep = mkenvstr(name, value, flags);
 	}
     }
 
@@ -2785,7 +2796,7 @@
 
     /* Now add it at the end */
     ep = environ + num_env;
-    *ep = mkenvstr(name, value);
+    *ep = mkenvstr(name, value, flags);
     *(ep + 1) = NULL;
     return *ep;
 }

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>



Messages sorted by: Reverse Date, Date, Thread, Author