From f438af241d1a85f9d6d7b3cd214eb3f11a972e0b Mon Sep 17 00:00:00 2001 From: tjg Date: Thu, 4 Apr 2002 10:07:58 +0000 Subject: Feature: make $version less magical, and exportable if it's changed from its default value. Same for $prompt. --- hash.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'hash.c') 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; } -- cgit v1.2.3