From e55c16708320aee327fe192d543a25e05343fae5 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Tue, 16 Jun 2015 01:36:50 +0200 Subject: 35476: Allow setting $0 when POSIX_ARGZERO is not set --- Src/params.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'Src/params.c') diff --git a/Src/params.c b/Src/params.c index 98541a6da..3b757359b 100644 --- a/Src/params.c +++ b/Src/params.c @@ -196,7 +196,7 @@ static const struct gsu_integer ttyidle_gsu = { ttyidlegetfn, nullintsetfn, stdunsetfn }; static const struct gsu_scalar argzero_gsu = -{ argzerogetfn, nullstrsetfn, nullunsetfn }; +{ argzerogetfn, argzerosetfn, nullunsetfn }; static const struct gsu_scalar username_gsu = { usernamegetfn, usernamesetfn, stdunsetfn }; static const struct gsu_scalar dash_gsu = @@ -4044,6 +4044,21 @@ lcsetfn(Param pm, char *x) } #endif /* USE_LOCALE */ +/* Function to set value for special parameter `0' */ + +/**/ +static void +argzerosetfn(UNUSED(Param pm), char *x) +{ + if (x) { + if (!isset(POSIXARGZERO)) { + zsfree(argzero); + argzero = ztrdup(x); + } + zsfree(x); + } +} + /* Function to get value for special parameter `0' */ /**/ -- cgit v1.2.3 From a0862f6381979b165e864e9c5b97d12432d35d48 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Wed, 15 Jul 2015 17:51:41 -0700 Subject: 35799: with NO_EXEC, parse parameter subscript expressions --- ChangeLog | 6 ++++++ Src/params.c | 22 +++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'Src/params.c') diff --git a/ChangeLog b/ChangeLog index 6ee125d8a..7f3ecfbd2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2015-07-15 Barton E. Schaefer + + * 35799: Src/params.c: with NO_EXEC, parse parameter subscript + expressions to correctly balance enclosing braces, but do not + perform the subscripting + 2015-07-15 Mikael Magnusson * unposted: Completion/Zsh/Type/_ps1234: unposted: _ps1234: diff --git a/Src/params.c b/Src/params.c index 3b757359b..7d0c8525e 100644 --- a/Src/params.c +++ b/Src/params.c @@ -1116,14 +1116,12 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w, Patprog pprog = NULL; /* - * If in NO_EXEC mode, the parameters won't be set up - * properly, so there's no point even doing any sanity checking. - * Just return 0 now. + * If in NO_EXEC mode, the parameters won't be set up properly, + * so just pretend everything is a hash for subscript parsing */ - if (unset(EXECOPT)) - return 0; - ishash = (v->pm && PM_TYPE(v->pm->node.flags) == PM_HASHED); + ishash = (unset(EXECOPT) || + (v->pm && PM_TYPE(v->pm->node.flags) == PM_HASHED)); if (prevcharlen) *prevcharlen = 1; if (nextcharlen) @@ -1278,8 +1276,18 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w, } if (!c) return 0; - s = dupstrpfx(s, t - s); *str = tt = t; + + /* + * If in NO_EXEC mode, the parameters won't be set up properly, + * so there's no additional sanity checking we can do. + * Just return 0 now. + */ + if (unset(EXECOPT)) + return 0; + + s = dupstrpfx(s, t - s); + /* If we're NOT reverse subscripting, strip the inull()s so brackets * * are not backslashed after parsestr(). Otherwise leave them alone * * so that the brackets will be escaped when we patcompile() or when * -- cgit v1.2.3 From f3e8f4cf7a68a1e0e4356fc0f7e419ada338a3e0 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Wed, 22 Jul 2015 12:43:09 -0700 Subject: 35581, 35582: output array assignments with spaces inside the parens --- ChangeLog | 7 +++++++ Src/params.c | 12 +++++++++--- Test/A06assign.ztst | 2 +- Test/B02typeset.ztst | 6 +++--- 4 files changed, 20 insertions(+), 7 deletions(-) (limited to 'Src/params.c') diff --git a/ChangeLog b/ChangeLog index ad2d53198..7e21be806 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2015-07-22 Barton E. Schaefer + + * 35582: Test/A06assign.ztst, Test/B02typeset.ztst: test for 35581 + + * 35581: Src/params.c: output array assignments with spaces inside + the parens + 2015-07-16 Barton E. Schaefer * 35805: Test/E01options.ztst: tests for 35799 diff --git a/Src/params.c b/Src/params.c index 7d0c8525e..312fa9ae1 100644 --- a/Src/params.c +++ b/Src/params.c @@ -5099,8 +5099,10 @@ printparamvalue(Param p, int printflags) break; case PM_ARRAY: /* array */ - if (!(printflags & PRINT_KV_PAIR)) + if (!(printflags & PRINT_KV_PAIR)) { putchar('('); + putchar(' '); + } u = p->gsu.a->getfn(p); if(*u) { quotedzputs(*u++, stdout); @@ -5109,13 +5111,17 @@ printparamvalue(Param p, int printflags) quotedzputs(*u++, stdout); } } - if (!(printflags & PRINT_KV_PAIR)) + if (!(printflags & PRINT_KV_PAIR)) { + putchar(' '); putchar(')'); + } break; case PM_HASHED: /* association */ - if (!(printflags & PRINT_KV_PAIR)) + if (!(printflags & PRINT_KV_PAIR)) { putchar('('); + putchar(' '); + } { HashTable ht = p->gsu.h->getfn(p); if (ht) diff --git a/Test/A06assign.ztst b/Test/A06assign.ztst index a4401cb67..302659c7e 100644 --- a/Test/A06assign.ztst +++ b/Test/A06assign.ztst @@ -430,7 +430,7 @@ 0:GLOB_ASSIGN with numeric types >typeset -i i=0 >typeset -a n ->n=(tmpfile1 tmpfile2) +>n=( tmpfile1 tmpfile2 ) >typeset x=tmpfile2 >typeset -E f=4.000000000e+00 diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst index 4c033cce7..05b3c16ea 100644 --- a/Test/B02typeset.ztst +++ b/Test/B02typeset.ztst @@ -453,7 +453,7 @@ fn 1:declare -p shouldn't create scoped values >typeset -a array ->array=(foo bar) +>array=( foo bar ) ?fn:typeset: no such variable: nonexistent unsetopt typesetsilent @@ -504,10 +504,10 @@ typeset -pm 'r[12]' 0:readonly -p output >typeset -a a1 ->a1=(one two) +>a1=( one two ) >typeset -ar a1 >typeset -a a2 ->a2=(three four) +>a2=( three four ) >typeset -r r1=yes >typeset -r r2=no -- cgit v1.2.3 From a1f8d4ffc73293e0461c01ff005194a474854376 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Wed, 22 Jul 2015 12:52:24 -0700 Subject: 35826: add getsparam_u() to return unmetafied string, use it for a number of references to non-special params --- ChangeLog | 5 +++++ Src/Modules/newuser.c | 2 +- Src/Modules/zftp.c | 6 +++--- Src/Zle/complist.c | 4 ++-- Src/Zle/zle_misc.c | 4 ++-- Src/init.c | 2 +- Src/params.c | 23 ++++++++++++++++------- Src/utils.c | 10 +++++++--- Src/watch.c | 2 +- 9 files changed, 38 insertions(+), 20 deletions(-) (limited to 'Src/params.c') diff --git a/ChangeLog b/ChangeLog index 90babd20e..0b631c1a2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2015-07-22 Barton E. Schaefer + * 35826: Src/Modules/newuser.c, Src/Modules/zftp.c, + Src/Zle/complist.c, Src/Zle/zle_misc.c, Src/init.c, Src/params.c, + Src/utils.c, Src/watch.c: add getsparam_u() to return unmetafied + string, use it for a number of references to non-special params + * 35823: Functions/Zle/narrow-to-region: fix handling of MARK and CURSOR, clean up documentary comment diff --git a/Src/Modules/newuser.c b/Src/Modules/newuser.c index 71902da7d..efdb2abba 100644 --- a/Src/Modules/newuser.c +++ b/Src/Modules/newuser.c @@ -67,7 +67,7 @@ check_dotfile(const char *dotdir, const char *fname) int boot_(UNUSED(Module m)) { - const char *dotdir = getsparam("ZDOTDIR"); + const char *dotdir = getsparam_u("ZDOTDIR"); const char *spaths[] = { #ifdef SITESCRIPT_DIR SITESCRIPT_DIR, diff --git a/Src/Modules/zftp.c b/Src/Modules/zftp.c index 09d4bd703..30f517658 100644 --- a/Src/Modules/zftp.c +++ b/Src/Modules/zftp.c @@ -731,7 +731,7 @@ zfgetmsg(void) stopit = (*ptr++ != '-'); queue_signals(); - if (!(verbose = getsparam("ZFTP_VERBOSE"))) + if (!(verbose = getsparam_u("ZFTP_VERBOSE"))) verbose = ""; if (strchr(verbose, lastcodestr[0])) { /* print the whole thing verbatim */ @@ -1785,7 +1785,7 @@ zftp_open(char *name, char **args, int flags) char *hname; alarm(0); queue_signals(); - if ((hname = getsparam("ZFTP_HOST")) && *hname) + if ((hname = getsparam_u("ZFTP_HOST")) && *hname) zwarnnam(name, "timeout connecting to %s", hname); else zwarnnam(name, "timeout on host name lookup"); @@ -3077,7 +3077,7 @@ bin_zftp(char *name, char **args, UNUSED(Options ops), UNUSED(int func)) } queue_signals(); - if ((prefs = getsparam("ZFTP_PREFS"))) { + if ((prefs = getsparam_u("ZFTP_PREFS"))) { zfprefs = 0; for (ptr = prefs; *ptr; ptr++) { switch (toupper(STOUC(*ptr))) { diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c index f37a43231..fd90ccb31 100644 --- a/Src/Zle/complist.c +++ b/Src/Zle/complist.c @@ -507,8 +507,8 @@ getcols() max_caplen = lr_caplen = 0; mcolors.flags = 0; queue_signals(); - if (!(s = getsparam("ZLS_COLORS")) && - !(s = getsparam("ZLS_COLOURS"))) { + if (!(s = getsparam_u("ZLS_COLORS")) && + !(s = getsparam_u("ZLS_COLOURS"))) { for (i = 0; i < NUM_COLS; i++) mcolors.files[i] = filecol(""); mcolors.pats = NULL; diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index d350688a7..556ce5ba6 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -1552,13 +1552,13 @@ makesuffix(int n) { char *suffixchars; - if (!(suffixchars = getsparam("ZLE_REMOVE_SUFFIX_CHARS"))) + if (!(suffixchars = getsparam_u("ZLE_REMOVE_SUFFIX_CHARS"))) suffixchars = " \t\n;&|"; addsuffixstring(SUFTYP_POSSTR, 0, suffixchars, n); /* Do this second so it takes precedence */ - if ((suffixchars = getsparam("ZLE_SPACE_SUFFIX_CHARS")) && *suffixchars) + if ((suffixchars = getsparam_u("ZLE_SPACE_SUFFIX_CHARS")) && *suffixchars) addsuffixstring(SUFTYP_POSSTR, SUFFLAGS_SPACE, suffixchars, n); suffixlen = n; diff --git a/Src/init.c b/Src/init.c index 0fe4d758c..2ef90992d 100644 --- a/Src/init.c +++ b/Src/init.c @@ -1426,7 +1426,7 @@ sourcehome(char *s) char *h; queue_signals(); - if (EMULATION(EMULATE_SH|EMULATE_KSH) || !(h = getsparam("ZDOTDIR"))) { + if (EMULATION(EMULATE_SH|EMULATE_KSH) || !(h = getsparam_u("ZDOTDIR"))) { h = home; if (!h) return; diff --git a/Src/params.c b/Src/params.c index 312fa9ae1..00f43e47d 100644 --- a/Src/params.c +++ b/Src/params.c @@ -2639,6 +2639,15 @@ getsparam(char *s) return getstrvalue(v); } +/**/ +mod_export char * +getsparam_u(char *s) +{ + if ((s = getsparam(s))) + return unmetafy(s, NULL); + return s; +} + /* Retrieve an array parameter */ /**/ @@ -3971,7 +3980,7 @@ setlang(char *x) struct localename *ln; char *x2; - if ((x2 = getsparam("LC_ALL")) && *x2) + if ((x2 = getsparam_u("LC_ALL")) && *x2) return; /* @@ -3985,10 +3994,10 @@ setlang(char *x) * from this is meaningless. So just all $LANG to show through in * that case. */ - setlocale(LC_ALL, x ? x : ""); + setlocale(LC_ALL, x ? unmeta(x) : ""); queue_signals(); for (ln = lc_names; ln->name; ln++) - if ((x = getsparam(ln->name)) && *x) + if ((x = getsparam_u(ln->name)) && *x) setlocale(ln->category, x); unqueue_signals(); } @@ -4004,7 +4013,7 @@ lc_allsetfn(Param pm, char *x) * that with any LC_* that are set. */ if (!x || !*x) { - x = getsparam("LANG"); + x = getsparam_u("LANG"); if (x && *x) { queue_signals(); setlang(x); @@ -4012,7 +4021,7 @@ lc_allsetfn(Param pm, char *x) } } else - setlocale(LC_ALL, x); + setlocale(LC_ALL, unmeta(x)); } /**/ @@ -4020,7 +4029,7 @@ void langsetfn(Param pm, char *x) { strsetfn(pm, x); - setlang(x); + setlang(unmeta(x)); } /**/ @@ -4046,7 +4055,7 @@ lcsetfn(Param pm, char *x) if (x && *x) { for (ln = lc_names; ln->name; ln++) if (!strcmp(ln->name, pm->node.nam)) - setlocale(ln->category, x); + setlocale(ln->category, unmeta(x)); } unqueue_signals(); } diff --git a/Src/utils.c b/Src/utils.c index 8ff575fd9..ba9056459 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -248,7 +248,7 @@ VA_DCL VA_START(ap, message); VA_GET_ARG(ap, message, const char *); - if ((filename = getsparam("ZSH_DEBUG_LOG")) != NULL && + if ((filename = getsparam_u("ZSH_DEBUG_LOG")) != NULL && (file = fopen(filename, "a")) != NULL) { zerrmsg(file, message, ap); fclose(file); @@ -1949,7 +1949,8 @@ extern char *_mktemp(char *); /* Get a unique filename for use as a temporary file. If "prefix" is * NULL, the name is relative to $TMPPREFIX; If it is non-NULL, the * unique suffix includes a prefixed '.' for improved readability. If - * "use_heap" is true, we allocate the returned name on the heap. */ + * "use_heap" is true, we allocate the returned name on the heap. + * The string passed as "prefix" is expected to be metafied. */ /**/ mod_export char * @@ -1976,6 +1977,9 @@ gettempname(const char *prefix, int use_heap) return ret; } +/* The gettempfile() "prefix" is expected to be metafied, see hist.c + * and gettempname(). */ + /**/ mod_export int gettempfile(const char *prefix, int use_heap, char **tempname) @@ -3585,7 +3589,7 @@ zbeep(void) { char *vb; queue_signals(); - if ((vb = getsparam("ZBEEP"))) { + if ((vb = getsparam_u("ZBEEP"))) { int len; vb = getkeystring(vb, &len, GETKEYS_BINDKEY, NULL); write_loop(SHTTY, vb, len); diff --git a/Src/watch.c b/Src/watch.c index fe409f91a..e1bdaa4a0 100644 --- a/Src/watch.c +++ b/Src/watch.c @@ -566,7 +566,7 @@ dowatch(void) return; } queue_signals(); - if (!(fmt = getsparam("WATCHFMT"))) + if (!(fmt = getsparam_u("WATCHFMT"))) fmt = DEFAULT_WATCHFMT; while ((uct || wct) && !errflag) if (!uct || (wct && ucmp(uptr, wptr) > 0)) -- cgit v1.2.3