diff options
author | Axel Beckert <abe@deuxchevaux.org> | 2017-08-10 17:16:37 +0200 |
---|---|---|
committer | Axel Beckert <abe@deuxchevaux.org> | 2017-08-10 17:16:37 +0200 |
commit | e3b67a8198c852bf6c9db3a0a1a20e87a4e1da74 (patch) | |
tree | 8486633f6232f49ea330ab8e036decb5dc3bbf74 /Src/Modules/parameter.c | |
parent | f8edeff2494bf23e2ee29d4c761361b1c878e09d (diff) | |
parent | dc475bfa0ec6cd03789dde3bf28f71e0ea9d5003 (diff) | |
download | zsh-e3b67a8198c852bf6c9db3a0a1a20e87a4e1da74.tar.gz zsh-e3b67a8198c852bf6c9db3a0a1a20e87a4e1da74.zip |
Merge tag '5.4.1' into debian
Release 5.4.1.
Diffstat (limited to 'Src/Modules/parameter.c')
-rw-r--r-- | Src/Modules/parameter.c | 132 |
1 files changed, 122 insertions, 10 deletions
diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c index 98bcaba6e..10c47d214 100644 --- a/Src/Modules/parameter.c +++ b/Src/Modules/parameter.c @@ -167,7 +167,7 @@ unsetpmcommand(Param pm, UNUSED(int exp)) /**/ static void -setpmcommands(UNUSED(Param pm), HashTable ht) +setpmcommands(Param pm, HashTable ht) { int i; HashNode hn; @@ -190,7 +190,15 @@ setpmcommands(UNUSED(Param pm), HashTable ht) cmdnamtab->addnode(cmdnamtab, ztrdup(hn->nam), &cn->node); } - deleteparamtable(ht); + /* + * On full-array assignment ht is a temporary hash with the default + * get/set functions, whereas pm->u.hash has the special $commands + * get/set functions. Do not assign ht to pm, just delete it. + * + * On append, ht and pm->u.hash are the same table, don't delete. + */ + if (ht != pm->u.hash) + deleteparamtable(ht); } static const struct gsu_scalar pmcommand_gsu = @@ -330,7 +338,7 @@ unsetpmfunction(Param pm, UNUSED(int exp)) /**/ static void -setfunctions(UNUSED(Param pm), HashTable ht, int dis) +setfunctions(Param pm, HashTable ht, int dis) { int i; HashNode hn; @@ -349,7 +357,9 @@ setfunctions(UNUSED(Param pm), HashTable ht, int dis) setfunction(hn->nam, ztrdup(getstrvalue(&v)), dis); } - deleteparamtable(ht); + /* See setpmcommands() above */ + if (ht != pm->u.hash) + deleteparamtable(ht); } /**/ @@ -515,6 +525,98 @@ scanpmdisfunctions(HashTable ht, ScanFunc func, int flags) scanfunctions(ht, func, flags, DISABLED); } +/* Functions for the functions_source special parameter. */ + +/* Retrieve the source file for a function by explicit name */ + +/**/ +static HashNode +getfunction_source(UNUSED(HashTable ht), const char *name, int dis) +{ + Shfunc shf; + Param pm = NULL; + + pm = (Param) hcalloc(sizeof(struct param)); + pm->node.nam = dupstring(name); + pm->node.flags = PM_SCALAR|PM_READONLY; + pm->gsu.s = dis ? &pmdisfunction_gsu : &pmfunction_gsu; + + if ((shf = (Shfunc) shfunctab->getnode2(shfunctab, name)) && + (dis ? (shf->node.flags & DISABLED) : !(shf->node.flags & DISABLED))) { + pm->u.str = getshfuncfile(shf); + if (!pm->u.str) + pm->u.str = dupstring(""); + } + return &pm->node; +} + +/* Retrieve the source file for functions by scanning the table */ + +/**/ +static void +scanfunctions_source(UNUSED(HashTable ht), ScanFunc func, int flags, int dis) +{ + struct param pm; + int i; + HashNode hn; + + memset((void *)&pm, 0, sizeof(struct param)); + pm.node.flags = PM_SCALAR|PM_READONLY; + pm.gsu.s = dis ? &pmdisfunction_gsu : &pmfunction_gsu; + + for (i = 0; i < shfunctab->hsize; i++) { + for (hn = shfunctab->nodes[i]; hn; hn = hn->next) { + if (dis ? (hn->flags & DISABLED) : !(hn->flags & DISABLED)) { + pm.node.nam = hn->nam; + if (func != scancountparams && + ((flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)) || + !(flags & SCANPM_WANTKEYS))) { + pm.u.str = getshfuncfile((Shfunc)hn); + if (!pm.u.str) + pm.u.str = dupstring(""); + } + func(&pm.node, flags); + } + } + } +} + +/* Param table entry for retrieving functions_source element */ + +/**/ +static HashNode +getpmfunction_source(HashTable ht, const char *name) +{ + return getfunction_source(ht, name, 0); +} + +/* Param table entry for retrieving ds_functions_source element */ + +/**/ +static HashNode +getpmdisfunction_source(HashTable ht, const char *name) +{ + return getfunction_source(ht, name, 1); +} + +/* Param table entry for scanning functions_source table */ + +/**/ +static void +scanpmfunction_source(HashTable ht, ScanFunc func, int flags) +{ + scanfunctions_source(ht, func, flags, 0); +} + +/* Param table entry for scanning dis_functions_source table */ + +/**/ +static void +scanpmdisfunction_source(HashTable ht, ScanFunc func, int flags) +{ + scanfunctions_source(ht, func, flags, 1); +} + /* Functions for the funcstack special parameter. */ /**/ @@ -845,7 +947,7 @@ unsetpmoption(Param pm, UNUSED(int exp)) /**/ static void -setpmoptions(UNUSED(Param pm), HashTable ht) +setpmoptions(Param pm, HashTable ht) { int i; HashNode hn; @@ -870,7 +972,9 @@ setpmoptions(UNUSED(Param pm), HashTable ht) (val && strcmp(val, "off")), 0, opts)) zwarn("can't change option: %s", hn->nam); } - deleteparamtable(ht); + /* See setpmcommands() above */ + if (ht != pm->u.hash) + deleteparamtable(ht); } static const struct gsu_scalar pmoption_gsu = @@ -1409,7 +1513,7 @@ unsetpmnameddir(Param pm, UNUSED(int exp)) /**/ static void -setpmnameddirs(UNUSED(Param pm), HashTable ht) +setpmnameddirs(Param pm, HashTable ht) { int i; HashNode hn, next, hd; @@ -1451,7 +1555,9 @@ setpmnameddirs(UNUSED(Param pm), HashTable ht) i = opts[INTERACTIVE]; opts[INTERACTIVE] = 0; - deleteparamtable(ht); + /* See setpmcommands() above */ + if (ht != pm->u.hash) + deleteparamtable(ht); opts[INTERACTIVE] = i; } @@ -1632,7 +1738,7 @@ unsetpmsalias(Param pm, UNUSED(int exp)) /**/ static void -setaliases(HashTable alht, UNUSED(Param pm), HashTable ht, int flags) +setaliases(HashTable alht, Param pm, HashTable ht, int flags) { int i; HashNode hn, next, hd; @@ -1668,7 +1774,9 @@ setaliases(HashTable alht, UNUSED(Param pm), HashTable ht, int flags) alht->addnode(alht, ztrdup(hn->nam), createaliasnode(ztrdup(val), flags)); } - deleteparamtable(ht); + /* See setpmcommands() above */ + if (ht != pm->u.hash) + deleteparamtable(ht); } /**/ @@ -2095,6 +2203,8 @@ static struct paramdef partab[] = { NULL, getpmdisbuiltin, scanpmdisbuiltins), SPECIALPMDEF("dis_functions", 0, &pmdisfunctions_gsu, getpmdisfunction, scanpmdisfunctions), + SPECIALPMDEF("dis_functions_source", PM_READONLY, NULL, + getpmdisfunction_source, scanpmdisfunction_source), SPECIALPMDEF("dis_galiases", 0, &pmdisgaliases_gsu, getpmdisgalias, scanpmdisgaliases), SPECIALPMDEF("dis_patchars", PM_ARRAY|PM_READONLY, @@ -2111,6 +2221,8 @@ static struct paramdef partab[] = { &funcstack_gsu, NULL, NULL), SPECIALPMDEF("functions", 0, &pmfunctions_gsu, getpmfunction, scanpmfunctions), + SPECIALPMDEF("functions_source", PM_READONLY, NULL, + getpmfunction_source, scanpmfunction_source), SPECIALPMDEF("functrace", PM_ARRAY|PM_READONLY, &functrace_gsu, NULL, NULL), SPECIALPMDEF("galiases", 0, |