commit f438af241d1a85f9d6d7b3cd214eb3f11a972e0b
parent 5ebf72443b04d110e41c9f2f9dbc6a9796862e38
Author: tjg <tjg>
Date: Thu, 4 Apr 2002 10:07:58 +0000
Feature: make $version less magical, and exportable if it's changed
from its default value. Same for $prompt.
Diffstat:
6 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -771,6 +771,7 @@ Changes since rc-1.5b2
2002-04-03
- Feature: make $version less magical, and exportable.
+ Feature: make $version less magical, and exportable if it's changed
+ from its default value. Same for $prompt.
Bug: make $bqstatus and $status not exportable.
diff --git a/configure.ac b/configure.ac
@@ -8,7 +8,7 @@ dnl Automake stuff.
dnl Use this one for snapshots...
dnl AM_INIT_AUTOMAKE(rc, 1.6s`echo $RELDATE |sed 's/-//g'`)
dnl ...and this one for releases
-AM_INIT_AUTOMAKE(rc, 1.6c6)
+AM_INIT_AUTOMAKE(rc, 1.6c7)
AM_CONFIG_HEADER(config.h)
diff --git a/hash.c b/hash.c
@@ -228,14 +228,37 @@ extern void initenv(char **envp) {
}
}
+static char *neverexport[] = {
+ "apid", "apids", "bqstatus", "cdpath", "home",
+ "ifs", "path", "pid", "status", "*"
+};
+
+/* for a few variables that have default values, we export them only
+if they've been explicitly set; maybeexport[n].flag is TRUE if this
+has occurred. */
+struct nameflag {
+ char *name;
+ bool flag;
+};
+static struct nameflag maybeexport[] = {
+ { "prompt", FALSE },
+ { "version", FALSE }
+};
+
+void set_exportable(char *s, bool b) {
+ int i;
+ for (i = 0; i < arraysize(maybeexport); ++i)
+ if (maybeexport[i].flag != b && streq(s, maybeexport[i].name))
+ maybeexport[i].flag = b;
+}
+
static bool var_exportable(char *s) {
- static char *notforexport[] = {
- "apid", "apids", "bqstatus", "cdpath", "home", "ifs",
- "path", "pid", "status", "*"
- };
int i;
- for (i = 0; i < arraysize(notforexport); i++)
- if (streq(s, notforexport[i]))
+ for (i = 0; i < arraysize(neverexport); i++)
+ if (streq(s, neverexport[i]))
+ return FALSE;
+ for (i = 0; i < arraysize(maybeexport); i++)
+ if (maybeexport[i].flag == FALSE && streq(s, maybeexport[i].name))
return FALSE;
return TRUE;
}
diff --git a/main.c b/main.c
@@ -113,6 +113,7 @@ static void assigndefault(char *name,...) {
for (l = NULL; (v = va_arg(ap, char *)) != NULL;)
l = append(l, word(v, NULL));
varassign(name, l, FALSE);
+ set_exportable(name, FALSE);
if (streq(name, "path"))
alias(name, l, FALSE);
va_end(ap);
diff --git a/rc.h b/rc.h
@@ -251,6 +251,7 @@ extern void fnassign_string(char *);
extern void fnrm(char *);
extern void initenv(char **);
extern void inithash(void);
+extern void set_exportable(char *, bool);
extern void setsigdefaults(bool);
extern void inithandler(void);
extern void varassign(char *, List *, bool);
diff --git a/var.c b/var.c
@@ -18,6 +18,7 @@ extern void varassign(char *name, List *def, bool stack) {
new = get_var_place(name, stack);
new->def = newdef;
new->extdef = NULL;
+ set_exportable(name, TRUE);
#if READLINE
if (interactive && (streq(name, "TERM") || streq(name, "TERMCAP")))
rl_reset_terminal(NULL);