summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authortjg <tjg>2002-04-04 10:07:58 +0000
committerToby Goodwin <toby@paccrat.org>2015-05-16 21:23:21 +0100
commitf438af241d1a85f9d6d7b3cd214eb3f11a972e0b (patch)
treef06286def44eac88ceec223563cdf56c9f71920b /hash.c
parent5ebf72443b04d110e41c9f2f9dbc6a9796862e38 (diff)
Feature: make $version less magical, and exportable if it's changed
from its default value. Same for $prompt.
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/hash.c b/hash.c
index 9b8c901..3f65ad8 100644
--- 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;
}