From ca3bc0d95d7deab4f5381f12b15047de748c0814 Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Sat, 30 Jan 2016 00:25:53 +0900 Subject: 37838: use UNUSED() consistently --- Src/Zle/computil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Src/Zle/computil.c') diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index 60fb096be..e8f0a6fe7 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -4994,7 +4994,7 @@ enables_(Module m, int **enables) /**/ int -boot_(Module m) +boot_(UNUSED(Module m)) { return 0; } -- cgit v1.2.3 From 81409caee707df19f0a3680aac50f1fa43755465 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 4 Aug 2016 15:54:25 +0000 Subject: workers/38995 (in part): compfiles: Add reverse-engineered documentation breadcrumbs. --- ChangeLog | 3 +++ Src/Zle/computil.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+) (limited to 'Src/Zle/computil.c') diff --git a/ChangeLog b/ChangeLog index 5ab0f3b7b..e3a2066f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-08-05 Daniel Shahaf + * workers/38995 (in part): Src/Zle/computil.c: compfiles: + Add reverse-engineered documentation breadcrumbs. + * 38996: Completion/Unix/Command/_man: Support _correct_word. * 38994: Completion/Unix/Command/_man: Fix two bugs when diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index e8f0a6fe7..0028ac1ca 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -4480,6 +4480,10 @@ cfp_matcher_pats(char *matcher, char *add) return add; } +/* + * ### This function call is skipped by _approximate, so "opt" probably means "optimize". + */ + static void cfp_opt_pats(char **pats, char *matcher) { @@ -4811,6 +4815,17 @@ cf_remove_other(char **names, char *pre, int *amb) return NULL; } +/* + * SYNOPSIS: + * 1. compfiles -p parnam1 parnam2 skipped matcher sdirs parnam3 varargs [..varargs] + * 2. compfiles -p- parnam1 parnam2 skipped matcher sdirs parnam3 varargs [..varargs] + * 3. compfiles -P parnam1 parnam2 skipped matcher sdirs parnam3 + * + * 1. Set parnam1 to an array of patterns.... + * 2. Like #1 but without calling cfp_opt_pats(). (This is only used by _approximate.) + * 3. Like #1 but varargs is implicitly set to char *varargs[2] = { "*(-/)", NULL };. + */ + static int bin_compfiles(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) { -- cgit v1.2.3 From f760bd6064d429a851ec5a57a2c1b7896a1c0e51 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Sat, 13 Aug 2016 01:32:31 +0200 Subject: 39026: pattern specified with _arguments' -A option shouldn't be checked against words after the cursor --- ChangeLog | 5 +++++ Src/Zle/computil.c | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'Src/Zle/computil.c') diff --git a/ChangeLog b/ChangeLog index ffe21020b..3a375a4b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-08-13 Oliver Kiddle + + * 39026: Src/Zle/computil.c: pattern specified with _arguments' + -A option shouldn't be checked against words after the cursor + 2016-08-12 Barton E. Schaefer * 39035: Src/subst.c, Test/D04parameter.ztst: ${(A)name=word} diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index 0028ac1ca..ecfa2bc34 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -2167,9 +2167,11 @@ ca_parse_line(Cadef d, int multi, int first) #endif ) return 1; - else if (state.arg && (!napat || !pattry(napat, line))) { + else if (state.arg && + (!napat || cur <= compcurrent || !pattry(napat, line))) { /* Otherwise it's a normal argument. */ - if (napat && ca_inactive(d, NULL, cur + 1, 1, NULL)) + if (napat && cur <= compcurrent && + ca_inactive(d, NULL, cur + 1, 1, NULL)) return 1; arglast = 1; -- cgit v1.2.3 From 73c0e8d4e679ed681acc4883234324c7676cc676 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 4 Sep 2016 18:26:32 +0000 Subject: 39173: _arguments: Escape colons and backslashes in $opt_args unambiguously. --- ChangeLog | 4 ++++ Doc/Zsh/compsys.yo | 6 ++++-- README | 9 +++++++++ Src/Zle/computil.c | 12 +++++++++--- 4 files changed, 26 insertions(+), 5 deletions(-) (limited to 'Src/Zle/computil.c') diff --git a/ChangeLog b/ChangeLog index be821de99..4643eda77 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2016-09-06 Daniel Shahaf + * 39173: Doc/Zsh/compsys.yo, README, Src/Zle/computil.c: + _arguments: Escape colons and backslashes in $opt_args + unambiguously. + * 39171: Completion/Unix/Command/_libvirt: Apply $opt_args-unescaping. diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 8c7ef0f5a..b2cc39268 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -3948,8 +3948,10 @@ command line after the command name excluding all options and their arguments. Options are stored in the associative array `tt(opt_args)' with option names as keys and their arguments as the values. For options that have more than one argument these are -given as one string, separated by colons. All colons in the original -arguments are preceded with backslashes. +given as one string, separated by colons. All colons and backslashes +in the original arguments are preceded with backslashes. (Note: +Zsh 5.2 and older did not escape backslashes in the original string; +see the tt(NEWS) file for details.) The parameter `tt(context)' is set when returning to the calling function to perform an action of the form `tt(->)var(string)'. It is set to an diff --git a/README b/README index 9de5eb4a9..019294e4b 100644 --- a/README +++ b/README @@ -87,6 +87,15 @@ The "f" qualifier has for many years been the documented way of testing file modes; it allows the "and" test ("*(f+1)" is the documented equivalent of "*(1)") as well as many other forms. +5) The completion helper function _arguments now escapes both backslashes +and colons in the values of option arguments when populating the $opt_args +associative array. Previously, colons were escaped with a backslash but +backslashes were not themselves escaped with a backslash, which lead to +ambiguity: if the -x option took two arguments (as in + _arguments : -x:foo:${action}:bar:$action +), it would be impossible to tell from $opt_args whether the command-line +was '-x foo\:bar' or '-x foo\\ bar'. + Incompatibilities between 5.0.8 and 5.2 --------------------------------------- diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index ecfa2bc34..1c90a543a 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -2310,7 +2310,10 @@ ca_parse_line(Cadef d, int multi, int first) return 0; } -/* Build a colon-list from a list. */ +/* Build a colon-list from a list. + * + * This is only used to populate values of $opt_args. + */ static char * ca_colonlist(LinkList l) @@ -2320,16 +2323,19 @@ ca_colonlist(LinkList l) int len = 0; char *p, *ret, *q; + /* Compute the length to be allocated. */ for (n = firstnode(l); n; incnode(n)) { len++; for (p = (char *) getdata(n); *p; p++) - len += (*p == ':' ? 2 : 1); + len += (*p == ':' || *p == '\\') ? 2 : 1; } ret = q = (char *) zalloc(len); + /* Join L into RET, joining with colons and escaping colons and + * backslashes. */ for (n = firstnode(l); n;) { for (p = (char *) getdata(n); *p; p++) { - if (*p == ':') + if (*p == ':' || *p == '\\') *q++ = '\\'; *q++ = *p; } -- cgit v1.2.3 From f368720b8b9b481f82cef2e84a7e035864dff5f1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 9 Sep 2016 09:38:06 +0000 Subject: 39252: internal: quotestring: Drop the 'e' parameter, which no caller uses. --- ChangeLog | 7 +++++++ Src/Zle/compcore.c | 2 +- Src/Zle/compctl.c | 20 ++++++++++---------- Src/Zle/computil.c | 6 +++--- Src/Zle/zle_misc.c | 2 +- Src/Zle/zle_tricky.c | 24 ++++++++++++------------ Src/builtin.c | 2 +- Src/subst.c | 12 ++++++------ Src/text.c | 4 ++-- Src/utils.c | 27 ++++----------------------- 10 files changed, 47 insertions(+), 59 deletions(-) (limited to 'Src/Zle/computil.c') diff --git a/ChangeLog b/ChangeLog index a0e643615..7fba3550c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-09-11 Daniel Shahaf + + * 39252: Src/Zle/compcore.c, Src/Zle/compctl.c, + Src/Zle/computil.c, Src/Zle/zle_misc.c, Src/Zle/zle_tricky.c, + Src/builtin.c, Src/subst.c, Src/text.c, Src/utils.c: internal: + quotestring: Drop the 'e' parameter, which no caller uses. + 2016-09-09 Daniel Shahaf * unposted: Test/D04parameter.ztst: Add tests for ${(q)} being diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index ae7068fc9..2f9fb3308 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -1055,7 +1055,7 @@ multiquote(char *s, int ign) p += ign; while (*p) { if (ign >= 0 || p[1]) - s = quotestring(s, NULL, *p); + s = quotestring(s, *p); p++; } } diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c index ce4576297..c2da2977f 100644 --- a/Src/Zle/compctl.c +++ b/Src/Zle/compctl.c @@ -1400,7 +1400,7 @@ printcompctl(char *s, Compctl cc, int printflags, int ispat) untokenize(p); quotedzputs(p, stdout); } else - quotedzputs(quotestring(s, NULL, QT_BACKSLASH), stdout); + quotedzputs(quotestring(s, QT_BACKSLASH), stdout); } /* loop through flags w/o args that are set, printing them if so */ @@ -1536,7 +1536,7 @@ printcompctl(char *s, Compctl cc, int printflags, int ispat) char *p = dupstring(s); untokenize(p); - quotedzputs(quotestring(p, NULL, QT_BACKSLASH), stdout); + quotedzputs(quotestring(p, QT_BACKSLASH), stdout); } } putchar('\n'); @@ -1740,8 +1740,8 @@ static int addwhat; * This uses the instring variable exported from zle_tricky.c. */ -#define quotename(s, e) \ -quotestring(s, e, instring == QT_NONE ? QT_BACKSLASH : instring) +#define quotename(s) \ +quotestring(s, instring == QT_NONE ? QT_BACKSLASH : instring) /* Hook functions */ @@ -3153,10 +3153,10 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) lpre = zhalloc(lpl + 1); memcpy(lpre, s, lpl); lpre[lpl] = '\0'; - qlpre = quotename(lpre, NULL); + qlpre = quotename(lpre); lsuf = dupstring(s + offs); lsl = strlen(lsuf); - qlsuf = quotename(lsuf, NULL); + qlsuf = quotename(lsuf); /* First check for ~.../... */ if (ic == Tilde) { @@ -3175,11 +3175,11 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) rpre = (*p || *lpre == Tilde || *lpre == Equals) ? (noreal = 0, getreal(tt)) : dupstring(tt); - qrpre = quotename(rpre, NULL); + qrpre = quotename(rpre); for (p = lsuf; *p && *p != String && *p != Tick; p++); rsuf = *p ? (noreal = 0, getreal(lsuf)) : dupstring(lsuf); - qrsuf = quotename(rsuf, NULL); + qrsuf = quotename(rsuf); /* Check if word is a pattern. */ @@ -3315,10 +3315,10 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) /* And get the file prefix. */ fpre = dupstring(((s1 == s || s1 == rpre || ic) && (*s != '/' || zlemetacs == wb)) ? s1 : s1 + 1); - qfpre = quotename(fpre, NULL); + qfpre = quotename(fpre); /* And the suffix. */ fsuf = dupstrpfx(rsuf, s2 - rsuf); - qfsuf = quotename(fsuf, NULL); + qfsuf = quotename(fsuf); if (comppatmatch && *comppatmatch && (ispattern & 2)) { int t2; diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index 1c90a543a..16b681cda 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -3554,7 +3554,7 @@ comp_quote(char *str, int prefix) if ((x = (prefix && *str == '='))) *str = 'x'; - ret = quotestring(str, NULL, *compqstack); + ret = quotestring(str, *compqstack); if (x) *str = *ret = '='; @@ -4744,7 +4744,7 @@ cf_ignore(char **names, LinkList ign, char *style, char *path) for (; (n = *names); names++) { if (!ztat(n, &nst, 1) && S_ISDIR(nst.st_mode)) { if (tpwd && nst.st_dev == est.st_dev && nst.st_ino == est.st_ino) { - addlinknode(ign, quotestring(n, NULL, QT_BACKSLASH)); + addlinknode(ign, quotestring(n, QT_BACKSLASH)); continue; } if (tpar && !strncmp((c = dupstring(n)), path, pl)) { @@ -4760,7 +4760,7 @@ cf_ignore(char **names, LinkList ign, char *style, char *path) if (found || ((e = strrchr(c, '/')) && e > c + pl && !ztat(c, &st, 1) && st.st_dev == nst.st_dev && st.st_ino == nst.st_ino)) - addlinknode(ign, quotestring(n, NULL, QT_BACKSLASH)); + addlinknode(ign, quotestring(n, QT_BACKSLASH)); } } } diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index a040ca0df..fbd40cd03 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -780,7 +780,7 @@ bracketedpaste(char **args) int n; ZLE_STRING_T wpaste; wpaste = stringaszleline((zmult == 1) ? pbuf : - quotestring(pbuf, NULL, QT_SINGLE_OPTIONAL), 0, &n, NULL, NULL); + quotestring(pbuf, QT_SINGLE_OPTIONAL), 0, &n, NULL, NULL); cuttext(wpaste, n, CUT_REPLACE); if (!(zmod.flags & MOD_VIBUF)) { kct = -1; diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index 1d4e1d284..958e79ffb 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -424,8 +424,8 @@ mod_export int instring, inbackt; * This uses the instring variable above. */ -#define quotename(s, e) \ -quotestring(s, e, instring == QT_NONE ? QT_BACKSLASH : instring) +#define quotename(s) \ +quotestring(s, instring == QT_NONE ? QT_BACKSLASH : instring) /* Check if the given string is the name of a parameter and if this * * parameter is one worth expanding. */ @@ -2004,11 +2004,11 @@ get_comp_string(void) new->next = NULL; new->str = dupstrpfx(bbeg, len); - new->str = ztrdup(quotename(new->str, NULL)); + new->str = ztrdup(quotename(new->str)); untokenize(new->str); new->pos = begi; *dbeg = '\0'; - new->qpos = strlen(quotename(predup, NULL)); + new->qpos = strlen(quotename(predup)); *dbeg = '{'; i -= len; boffs -= len; @@ -2067,11 +2067,11 @@ get_comp_string(void) lastbrbeg = new; new->str = dupstrpfx(bbeg, len); - new->str = ztrdup(quotename(new->str, NULL)); + new->str = ztrdup(quotename(new->str)); untokenize(new->str); new->pos = begi; *dbeg = '\0'; - new->qpos = strlen(quotename(predup, NULL)); + new->qpos = strlen(quotename(predup)); *dbeg = '{'; i -= len; boffs -= len; @@ -2117,7 +2117,7 @@ get_comp_string(void) brend = new; new->str = dupstrpfx(bbeg, len); - new->str = ztrdup(quotename(new->str, NULL)); + new->str = ztrdup(quotename(new->str)); untokenize(new->str); new->pos = dp - predup - len + 1; new->qpos = len; @@ -2146,11 +2146,11 @@ get_comp_string(void) lastbrbeg = new; new->str = dupstrpfx(bbeg, len); - new->str = ztrdup(quotename(new->str, NULL)); + new->str = ztrdup(quotename(new->str)); untokenize(new->str); new->pos = begi; *dbeg = '\0'; - new->qpos = strlen(quotename(predup, NULL)); + new->qpos = strlen(quotename(predup)); *dbeg = '{'; boffs -= len; memmove(dbeg, dbeg + len, 1+strlen(dbeg+len)); @@ -2165,7 +2165,7 @@ get_comp_string(void) p = bp->pos; l = bp->qpos; bp->pos = strlen(predup + p + l); - bp->qpos = strlen(quotename(predup + p + l, NULL)); + bp->qpos = strlen(quotename(predup + p + l)); memmove(predup + p, predup + p + l, 1+bp->pos); } } @@ -2288,7 +2288,7 @@ doexpansion(char *s, int lst, int olst, int explincmd) foredel(we - wb, CUT_RAW); while ((ss = (char *)ugetnode(vl))) { ret = 0; - ss = quotename(ss, NULL); + ss = quotename(ss); untokenize(ss); inststr(ss); if (nonempty(vl) || !first) { @@ -2997,7 +2997,7 @@ processcmd(UNUSED(char **args)) inststr(" "); untokenize(s); - inststr(quotename(s, NULL)); + inststr(quotename(s)); zsfree(s); done = 1; diff --git a/Src/builtin.c b/Src/builtin.c index 3b82c9e7f..248f929d7 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -4844,7 +4844,7 @@ bin_print(char *name, char **args, Options ops, int func) break; case 'q': stringval = curarg ? - quotestring(curarg, NULL, QT_BACKSLASH_SHOWNULL) : &nullstr; + quotestring(curarg, QT_BACKSLASH_SHOWNULL) : &nullstr; *d = 's'; print_val(stringval); break; diff --git a/Src/subst.c b/Src/subst.c index 4641b4ba5..1c2027f32 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -3615,7 +3615,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, char *tmp; for (; *ap; ap++) { - tmp = quotestring(*ap, NULL, quotetype); + tmp = quotestring(*ap, quotetype); sl = strlen(tmp); *ap = (char *) zhalloc(pre + sl + post + 1); strcpy((*ap) + pre, tmp); @@ -3628,7 +3628,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, } } else for (; *ap; ap++) - *ap = quotestring(*ap, NULL, QT_BACKSLASH_SHOWNULL); + *ap = quotestring(*ap, QT_BACKSLASH_SHOWNULL); } else { int one = noerrs, oef = errflag, haserr = 0; @@ -3658,7 +3658,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, } else if (quotetype > QT_BACKSLASH) { int sl; char *tmp; - tmp = quotestring(val, NULL, quotetype); + tmp = quotestring(val, quotetype); sl = strlen(tmp); val = (char *) zhalloc(pre + sl + 2); strcpy(val + pre, tmp); @@ -3669,7 +3669,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, if (quotetype == QT_DOLLARS) val[0] = '$'; } else - val = quotestring(val, NULL, QT_BACKSLASH_SHOWNULL); + val = quotestring(val, QT_BACKSLASH_SHOWNULL); } else { int one = noerrs, oef = errflag, haserr; @@ -4274,7 +4274,7 @@ modify(char **str, char **ptr) subst(©, hsubl, hsubr, gbal); break; case 'q': - copy = quotestring(copy, NULL, QT_BACKSLASH_SHOWNULL); + copy = quotestring(copy, QT_BACKSLASH_SHOWNULL); break; case 'Q': { @@ -4356,7 +4356,7 @@ modify(char **str, char **ptr) subst(str, hsubl, hsubr, gbal); break; case 'q': - *str = quotestring(*str, NULL, QT_BACKSLASH); + *str = quotestring(*str, QT_BACKSLASH); break; case 'Q': { diff --git a/Src/text.c b/Src/text.c index cf6d3eb42..d387d361a 100644 --- a/Src/text.c +++ b/Src/text.c @@ -1068,11 +1068,11 @@ getredirs(LinkList redirs) */ if (!has_token(f->name)) { taddchr('\''); - taddstr(quotestring(f->name, NULL, QT_SINGLE)); + taddstr(quotestring(f->name, QT_SINGLE)); taddchr('\''); } else { taddchr('"'); - taddstr(quotestring(f->name, NULL, QT_DOUBLE)); + taddstr(quotestring(f->name, QT_DOUBLE)); taddchr('"'); } if (sav) diff --git a/Src/utils.c b/Src/utils.c index d209078f4..b434821e5 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -1047,9 +1047,9 @@ substnamedir(char *s) Nameddir d = finddir(s); if (!d) - return quotestring(s, NULL, QT_BACKSLASH); + return quotestring(s, QT_BACKSLASH); return zhtricat("~", d->node.nam, quotestring(s + strlen(d->dir), - NULL, QT_BACKSLASH)); + QT_BACKSLASH)); } @@ -5649,10 +5649,6 @@ addunprintable(char *v, const char *u, const char *uend) /* * Quote the string s and return the result as a string from the heap. * - * If e is non-zero, the - * pointer it points to may point to a position in s and in e the position - * of the corresponding character in the quoted string is returned. - * * The last argument is a QT_ value defined in zsh.h other than QT_NONE. * * Most quote styles other than backslash assume the quotes are to @@ -5665,13 +5661,13 @@ addunprintable(char *v, const char *u, const char *uend) /**/ mod_export char * -quotestring(const char *s, char **e, int instring) +quotestring(const char *s, int instring) { const char *u; char *v; int alloclen; char *buf; - int sf = 0, shownull = 0; + int shownull = 0; /* * quotesub is used with QT_SINGLE_OPTIONAL. * quotesub = 0: mechanism not active @@ -5742,10 +5738,6 @@ quotestring(const char *s, char **e, int instring) while (*u) { uend = u + MB_METACHARLENCONV(u, &cc); - if (e && !sf && *e <= u) { - *e = v; - sf = 1; - } if ( #ifdef MULTIBYTE_SUPPORT cc != WEOF && @@ -5772,11 +5764,6 @@ quotestring(const char *s, char **e, int instring) } } else if (instring == QT_BACKSLASH_PATTERN) { while (*u) { - if (e && !sf && *e == u) { - *e = v; - sf = 1; - } - if (ipattern(*u)) *v++ = '\\'; *v++ = *u++; @@ -5795,8 +5782,6 @@ quotestring(const char *s, char **e, int instring) */ while (*u) { int dobackslash = 0; - if (e && *e == u) - *e = v, sf = 1; if (*u == Tick || *u == Qtick) { char c = *u++; @@ -5984,10 +5969,6 @@ quotestring(const char *s, char **e, int instring) *v++ = '\''; *v = '\0'; - if (e && *e == u) - *e = v, sf = 1; - DPUTS(e && !sf, "BUG: Wild pointer *e in quotestring()"); - v = dupstring(buf); zfree(buf, alloclen); return v; -- cgit v1.2.3 From 0e01942c07f51f2eb9896625adfec246289851b8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 22 Sep 2016 14:42:50 +0000 Subject: 39412: Fix directory completion when $PWD:h contains parentheses, which are interpreted as globbing metacharacters. --- ChangeLog | 6 ++++++ Src/Zle/computil.c | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'Src/Zle/computil.c') diff --git a/ChangeLog b/ChangeLog index 260047969..608a296e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2016-09-23 Daniel Shahaf + + * 39412: Src/Zle/computil.c: Fix directory completion when + $PWD:h contains parentheses, which are interpreted as globbing + metacharacters. + 2016-09-22 Daniel Shahaf * 39410: Completion/Darwin/Type/_retrieve_mac_apps, diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index 16b681cda..27b78cd61 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -4830,8 +4830,11 @@ cf_remove_other(char **names, char *pre, int *amb) * 3. compfiles -P parnam1 parnam2 skipped matcher sdirs parnam3 * * 1. Set parnam1 to an array of patterns.... + * ${(P)parnam1} is an in/out parameter. * 2. Like #1 but without calling cfp_opt_pats(). (This is only used by _approximate.) * 3. Like #1 but varargs is implicitly set to char *varargs[2] = { "*(-/)", NULL };. + * + * parnam2 has to do with the accept-exact style (see cfp_test_exact()). */ static int @@ -4866,7 +4869,7 @@ bin_compfiles(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) return 0; } for (l = newlinklist(); *tmp; tmp++) - addlinknode(l, *tmp); + addlinknode(l, quotestring(*tmp, QT_BACKSLASH_PATTERN)); set_list_array(args[1], cf_pats((args[0][1] == 'P'), !!args[0][2], l, getaparam(args[2]), args[3], args[4], args[5], -- cgit v1.2.3 From 4ab3fcc90d928d200f9e70c81189079c3316b42d Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 3 Oct 2016 13:43:20 +0100 Subject: 39545: Add some missing unqueue_signals(). All of these are added simply to fit existing logic in other branches. --- ChangeLog | 5 +++++ Src/Zle/computil.c | 1 + Src/Zle/zle_main.c | 1 + Src/builtin.c | 3 +++ Src/exec.c | 3 +++ Src/hist.c | 1 + Src/init.c | 4 +++- Src/mem.c | 8 ++++++-- Src/module.c | 1 + Src/params.c | 2 ++ Src/prompt.c | 4 +++- 11 files changed, 29 insertions(+), 4 deletions(-) (limited to 'Src/Zle/computil.c') diff --git a/ChangeLog b/ChangeLog index a1c4e60e3..a68dfaf59 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2016-10-03 Peter Stephenson + * 39545: Src/builtin.c, Src/exec.c, Src/hist.c, Src/init.c, + Src/mem.c, Src/module.c, Src/params.c, Src/prompt.c, + Src/Zle/computil.c, Src/Zle/zle_main.c: Add some missing + unqueue_signals(). + * 39521: Src/exec.c, Src/zsh.h, Test/A01grammar.ztst: Refactor start of execcmd(). This allows execpline2() easier access to the state at the start of execuation. diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index 27b78cd61..e9bad1cab 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -4865,6 +4865,7 @@ bin_compfiles(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) } queue_signals(); if (!(tmp = getaparam(args[1]))) { + unqueue_signals(); zwarnnam(nam, "unknown parameter: %s", args[1]); return 0; } diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 0bdd82ba4..0b3b1fcf4 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -1631,6 +1631,7 @@ bin_vared(char *name, char **args, Options ops, UNUSED(int func)) return 1; } else if (v) { if (*s) { + unqueue_signals(); zwarnnam(name, "not an identifier: `%s'", args[0]); return 1; } diff --git a/Src/builtin.c b/Src/builtin.c index 60dc07f25..a274ff791 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -1489,6 +1489,7 @@ bin_fc(char *nam, char **argv, Options ops, int func) } if (zleactive) { + unqueue_signals(); zwarnnam(nam, "no interactive history within ZLE"); return 1; } @@ -2808,6 +2809,7 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func) return 0; } if (off & PM_TIED) { + unqueue_signals(); zerrnam(name, "use unset to remove tied variables"); return 1; } @@ -3138,6 +3140,7 @@ bin_functions(char *name, char **argv, Options ops, int func) queue_signals(); for (q = mathfuncs; q; q = q->next) { if (!strcmp(q->name, funcname)) { + unqueue_signals(); zwarnnam(name, "-M %s: function already exists", funcname); zsfree(p->name); diff --git a/Src/exec.c b/Src/exec.c index a4294288b..9890286b2 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -1795,6 +1795,8 @@ execpline(Estate state, wordcode slcode, int how, int last1) deletejob(jn, 0); thisjob = pj; } + else + unqueue_signals(); if ((slflags & WC_SUBLIST_NOT) && !errflag) lastval = !lastval; } @@ -5556,6 +5558,7 @@ runshfunc(Eprog prog, FuncWrap wrap, char *name) if (!cont) { if (ou) zfree(ou, ouu); + unqueue_signals(); return; } wrap = wrap->next; diff --git a/Src/hist.c b/Src/hist.c index 5fc40bd67..eebd7dcde 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -653,6 +653,7 @@ histsubchar(int c) (c == '}' || c == ';' || c == '\'' || c == '"' || c == '`')) { /* Neither event nor word designator, no expansion */ safeinungetc(c); + unqueue_signals(); return bangchar; } *ptr = 0; diff --git a/Src/init.c b/Src/init.c index 3dea179b9..c12043b88 100644 --- a/Src/init.c +++ b/Src/init.c @@ -1442,8 +1442,10 @@ sourcehome(char *s) queue_signals(); if (EMULATION(EMULATE_SH|EMULATE_KSH) || !(h = getsparam_u("ZDOTDIR"))) { h = home; - if (!h) + if (!h) { + unqueue_signals(); return; + } } { diff --git a/Src/mem.c b/Src/mem.c index 021dad573..db311efbd 100644 --- a/Src/mem.c +++ b/Src/mem.c @@ -903,11 +903,15 @@ memory_validate(Heapid heap_id) queue_signals(); for (h = heaps; h; h = h->next) { - if (h->heap_id == heap_id) + if (h->heap_id == heap_id) { + unqueue_signals(); return 0; + } for (hs = heaps->sp; hs; hs = hs->next) { - if (hs->heap_id == heap_id) + if (hs->heap_id == heap_id) { + unqueue_signals(); return 0; + } } } diff --git a/Src/module.c b/Src/module.c index 46a7d7746..41f142adb 100644 --- a/Src/module.c +++ b/Src/module.c @@ -2242,6 +2242,7 @@ load_module(char const *name, Feature_enables enablesarr, int silent) return 0; } if (m->node.flags & MOD_BUSY) { + unqueue_signals(); zerr("circular dependencies for module ;%s", name); return 1; } diff --git a/Src/params.c b/Src/params.c index e11510246..1418021aa 100644 --- a/Src/params.c +++ b/Src/params.c @@ -2803,6 +2803,7 @@ assignsparam(char *s, char *val, int flags) zerr("read-only variable: %s", v->pm->node.nam); *ss = '['; zsfree(val); + unqueue_signals(); return NULL; } flags &= ~ASSPM_WARN_CREATE; @@ -3117,6 +3118,7 @@ setnparam(char *s, mnumber val) if (!(v = getvalue(&vbuf, &t, 1))) { DPUTS(!v, "BUG: value not found for new parameter"); /* errflag |= ERRFLAG_ERROR; */ + unqueue_signals(); return NULL; } if (!was_unset && isset(WARNCREATEGLOBAL) && locallevel > forklevel) diff --git a/Src/prompt.c b/Src/prompt.c index d4f389809..ee77c8bc8 100644 --- a/Src/prompt.c +++ b/Src/prompt.c @@ -491,8 +491,10 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep) if (!arg) arg++; queue_signals(); - if (!(hostnam = getsparam("HOST"))) + if (!(hostnam = getsparam("HOST"))) { + unqueue_signals(); break; + } if (arg < 0) { for (ss = hostnam + strlen(hostnam); ss > hostnam; ss--) if (ss[-1] == '.' && !++arg) -- cgit v1.2.3 From 7b3ec54ebe05e9f5d415f95ed9c5c3f39a1e60a2 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Thu, 13 Oct 2016 10:03:13 +0200 Subject: 39611: with _arguments sets completion stopped if one of the rest arguments starts with a dash --- ChangeLog | 3 +++ Src/Zle/computil.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'Src/Zle/computil.c') diff --git a/ChangeLog b/ChangeLog index 1afd5e654..95f2529c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-10-13 Oliver Kiddle + * 39611: Src/Zle/computil.c: with _arguments sets completion + stopped if one of the rest arguments starts with a dash + * 39533: Matthew Martin: Completion/Unix/Command/_doas: add the new -L option, sort options and add some exclusions diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index e9bad1cab..cb3c32f1f 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -2158,7 +2158,8 @@ ca_parse_line(Cadef d, int multi, int first) state.opt = 0; else state.curopt = NULL; - } else if (multi && (*line == '-' || *line == '+') && cur != compcurrent + } else if (multi && (*line == '-' || *line == '+') && cur != compcurrent && + ca_get_opt(d, line, 0, NULL) #if 0 /**** Ouch. Using this will disable the mutual exclusion of different sets. Not using it will make the -A -- cgit v1.2.3 From a8754b63fc505817a49b4e2de4c3b2f70382a52c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 29 Sep 2016 14:11:39 +0000 Subject: 39500: compdescribe: perform on-screen-width computation using the "nice" length, since the matches are rendered by nice*() functions by compadd Remove two "###" question comments relative to the patch posted, since the answer to them is (clearly) negative. --- ChangeLog | 6 ++++++ Src/Zle/computil.c | 19 ++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) (limited to 'Src/Zle/computil.c') diff --git a/ChangeLog b/ChangeLog index 97d3bc097..2d638dfdb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2016-10-16 Daniel Shahaf + + * 39500: Src/Zle/computil.c: compdescribe: perform + on-screen-width computation using the "nice" length, since the + matches are rendered by nice*() functions by compadd + 2016-10-13 Oliver Kiddle * 39624: Completion/Unix/Command/_yafc: remove space before diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index cb3c32f1f..0025dc37c 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -199,11 +199,11 @@ cd_calc(void) set->count++; if ((l = strlen(str->str)) > cd_state.pre) cd_state.pre = l; - if ((l = MB_METASTRWIDTH(str->str)) > cd_state.premaxw) + if ((l = ZMB_nicewidth(str->str)) > cd_state.premaxw) cd_state.premaxw = l; if (str->desc) { set->desc++; - if ((l = strlen(str->desc)) > cd_state.suf) + if ((l = strlen(str->desc)) > cd_state.suf) /* ### strlen() assumes no \n */ cd_state.suf = l; } } @@ -490,7 +490,7 @@ cd_init(char *nam, char *hide, char *mlen, char *sep, setp = &(cd_state.sets); cd_state.sep = ztrdup(sep); cd_state.slen = strlen(sep); - cd_state.swidth = MB_METASTRWIDTH(sep); + cd_state.swidth = ZMB_nicewidth(sep); cd_state.sets = NULL; cd_state.showd = disp; cd_state.maxg = cd_state.groups = cd_state.descs = 0; @@ -526,7 +526,8 @@ cd_init(char *nam, char *hide, char *mlen, char *sep, str->other = NULL; str->set = set; - for (tmp = *ap; *tmp && *tmp != ':'; tmp++) + /* Advance tmp to the first unescaped colon. */ + for (tmp = *ap; *tmp && *tmp != ':'; tmp++) if (*tmp == '\\' && tmp[1]) tmp++; @@ -537,7 +538,7 @@ cd_init(char *nam, char *hide, char *mlen, char *sep, *tmp = '\0'; str->str = str->match = ztrdup(rembslash(*ap)); str->len = strlen(str->str); - str->width = MB_METASTRWIDTH(str->str); + str->width = ZMB_nicewidth(str->str); str->sortstr = NULL; } if (str) @@ -692,7 +693,7 @@ cd_get(char **params) * end of screen as safety margin */ d = str->desc; - w = MB_METASTRWIDTH(d); + w = ZMB_nicewidth(d); if (w <= remw) strcpy(p, d); else { @@ -701,7 +702,7 @@ cd_get(char **params) l = MB_METACHARLEN(d); memcpy(pp, d, l); pp[l] = '\0'; - w = MB_METASTRWIDTH(pp); + w = ZMB_nicewidth(pp); if (w > remw) { *pp = '\0'; break; @@ -792,7 +793,7 @@ cd_get(char **params) cd_state.swidth - CM_SPACE; p = pp = dbuf + cd_state.slen; d = str->desc; - w = MB_METASTRWIDTH(d); + w = ZMB_nicewidth(d); if (w <= remw) { strcpy(p, d); remw -= w; @@ -802,7 +803,7 @@ cd_get(char **params) l = MB_METACHARLEN(d); memcpy(pp, d, l); pp[l] = '\0'; - w = MB_METASTRWIDTH(pp); + w = ZMB_nicewidth(pp); if (w > remw) { *pp = '\0'; break; -- cgit v1.2.3 From e8df1c70560a504e325146d5c239689c7782ce2c Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 30 Nov 2016 16:19:21 +0000 Subject: 40043: fix computil.c indentation (cosmetic) --- ChangeLog | 5 +++++ Src/Zle/computil.c | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'Src/Zle/computil.c') diff --git a/ChangeLog b/ChangeLog index 44fa6580b..0da1aafc1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-11-30 Peter Stephenson + + * 40043: Src/Zle/computil.c: fix indentation (recent gcc warns + about this). + 2016-11-30 Daniel Shahaf * 40036: Completion/Debian/Command/_bts: Complete removal diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index 0025dc37c..c78167329 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -1694,10 +1694,10 @@ ca_get_opt(Cadef d, char *line, int full, char **end) for (p = d->opts; p; p = p->next) if (p->active && ((!p->args || p->type == CAO_NEXT) ? !strcmp(p->name, line) : strpfx(p->name, line))) { - int l = strlen(p->name); - if ((p->type == CAO_OEQUAL || p->type == CAO_EQUAL) && - line[l] && line[l] != '=') - continue; + int l = strlen(p->name); + if ((p->type == CAO_OEQUAL || p->type == CAO_EQUAL) && + line[l] && line[l] != '=') + continue; if (end) { /* Return a pointer to the end of the option. */ -- cgit v1.2.3