From d292edc4dc4b35438dbbf0906a568d5eedfa1761 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 3 Jun 2011 22:06:59 +0000 Subject: 29452: allow completion of parameter flags --- Src/Zle/compcore.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'Src/Zle/compcore.c') diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index 5514e2e1d..704e125bc 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -1150,7 +1150,7 @@ check_param(char *s, int set, int test) p[1] != Inpar && p[1] != Inbrack && p[1] != Snull) { /* This is a parameter expression, not $(...), $[...], $'...'. */ char *b = p + 1, *e = b, *ie; - int n = 0, br = 1, nest = 0; + int br = 1, nest = 0; if (*b == Inbrace) { char *tb = b; @@ -1161,7 +1161,17 @@ check_param(char *s, int set, int test) /* Ignore the possible (...) flags. */ b++, br++; - n = skipparens(Inpar, Outpar, &b); + if (skipparens(Inpar, Outpar, &b) > 0) { + /* + * We are still within the parameter flags. There's no + * point trying to do anything clever here with + * parameter names. Instead, just report that we are in + * a brace parameter but let the completion function + * decide what to do about it. + */ + ispar = 2; + return NULL; + } for (tb = p - 1; tb > s && *tb != Outbrace && *tb != Inbrace; tb--); if (tb > s && *tb == Inbrace && (tb[-1] == String || *tb == Qstring)) @@ -1204,7 +1214,7 @@ check_param(char *s, int set, int test) } /* Now make sure that the cursor is inside the name. */ - if (offs <= e - s && offs >= b - s && n <= 0) { + if (offs <= e - s && offs >= b - s) { char sav; if (br) { -- cgit v1.2.3 From d7582f006f950be2622bc0d5ff26aaaa20af3b7f Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sat, 4 Jun 2011 21:32:06 +0000 Subject: 29459: Further fixes for parameter flag completion, plus drive-by fix for double-quoted parameter completion with flags --- ChangeLog | 9 ++++++++- Completion/Zsh/Context/_brace_parameter | 2 +- Src/Zle/compcore.c | 6 ++++-- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'Src/Zle/compcore.c') diff --git a/ChangeLog b/ChangeLog index 9e6efc78e..d2dab008a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-06-04 Peter Stephenson + + * Completion/Zsh/Context/_brace_parameter, Src/Zle/compcore.c + (check_param): In shell function, check for ${( not at start + of match; in C code, check for untokenized parentheses when + in double quotes. + 2011-06-03 Peter Stephenson * 29452: Completion/Zsh/Context/_brace_parameter, @@ -14951,5 +14958,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5361 $ +* $Revision: 1.5362 $ ***************************************************** diff --git a/Completion/Zsh/Context/_brace_parameter b/Completion/Zsh/Context/_brace_parameter index e6a2c4c80..c0ecf251b 100644 --- a/Completion/Zsh/Context/_brace_parameter +++ b/Completion/Zsh/Context/_brace_parameter @@ -4,7 +4,7 @@ local char delim found_percent found_m exp local -a flags integer q_last n_q -if [[ $PREFIX = '${('[^\)]# ]]; then +if [[ $PREFIX = *'${('[^\)]# ]]; then # Parameter flags. compset -p 3 diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index 704e125bc..0a1a97c3d 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -1099,7 +1099,7 @@ mod_export char * check_param(char *s, int set, int test) { char *p; - int found = 0; + int found = 0, qstring = 0; zsfree(parpre); parpre = NULL; @@ -1126,6 +1126,7 @@ check_param(char *s, int set, int test) !(*p == String && p[1] == Snull) && !(*p == Qstring && p[1] == '\'')) { found = 1; + qstring = (*p == Qstring); break; } } @@ -1161,7 +1162,8 @@ check_param(char *s, int set, int test) /* Ignore the possible (...) flags. */ b++, br++; - if (skipparens(Inpar, Outpar, &b) > 0) { + if ((qstring ? skipparens('(', ')', &b) : + skipparens(Inpar, Outpar, &b)) > 0) { /* * We are still within the parameter flags. There's no * point trying to do anything clever here with -- cgit v1.2.3 From 962624e8c343e3968fbb55160b8a14b460400bc0 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 19 Jun 2011 16:26:10 +0000 Subject: 29491: remove some variables set but not used --- ChangeLog | 7 ++++++- Src/Modules/db_gdbm.c | 10 ++++------ Src/Zle/compcore.c | 6 ++---- Src/Zle/complist.c | 8 +++----- Src/Zle/zle_refresh.c | 2 -- Src/Zle/zle_tricky.c | 4 +--- Src/glob.c | 3 +-- Src/lex.c | 9 ++++----- Src/math.c | 2 -- Src/params.c | 13 +++++++++---- Src/parse.c | 4 ++-- Src/utils.c | 4 ++-- 12 files changed, 34 insertions(+), 38 deletions(-) (limited to 'Src/Zle/compcore.c') diff --git a/ChangeLog b/ChangeLog index 387e29bcd..501c64b6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2011-06-19 Peter Stephenson + * 29491: Src/glob.c, Src/lex.c, Src/math.c, Src/params.c, + Src/parse.c, Src/utils.c, Src/Modules/db_gdbm.c, + Src/Zle/compcore.c, Src/Zle/complist.c, Src/Zle/zle_refresh.c, + Src/Zle/zle_tricky.c: remove some variables set but not used. + * 29490: Src/Builtins/rlimits.awk, Src/Builtins/rlimits.c, Src/Builtins/rlimits.mdd: add RLIMIT_RTTIME. @@ -15011,5 +15016,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5373 $ +* $Revision: 1.5374 $ ***************************************************** diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c index bdbbe19d8..9a2a7a5b9 100644 --- a/Src/Modules/db_gdbm.c +++ b/Src/Modules/db_gdbm.c @@ -39,7 +39,9 @@ #include +#if 0 /* what is this for? */ static char *backtype = "db/gdbm"; +#endif static const struct gsu_scalar gdbm_gsu = { gdbmgetfn, gdbmsetfn, gdbmunsetfn }; @@ -138,7 +140,6 @@ static void gdbmsetfn(Param pm, char *val) { datum key, content; - int ret; GDBM_FILE dbf; key.dptr = pm->node.nam; @@ -147,7 +148,7 @@ gdbmsetfn(Param pm, char *val) content.dsize = strlen(content.dptr) + 1; dbf = (GDBM_FILE)(pm->u.hash->tmpdata); - ret = gdbm_store(dbf, key, content, GDBM_REPLACE); + (void)gdbm_store(dbf, key, content, GDBM_REPLACE); } /**/ @@ -155,14 +156,13 @@ static void gdbmunsetfn(Param pm, int um) { datum key; - int ret; GDBM_FILE dbf; key.dptr = pm->node.nam; key.dsize = strlen(key.dptr) + 1; dbf = (GDBM_FILE)(pm->u.hash->tmpdata); - ret = gdbm_delete(dbf, key); + (void)gdbm_delete(dbf, key); } /**/ @@ -171,12 +171,10 @@ getgdbmnode(HashTable ht, const char *name) { int len; char *nameu; - datum key; Param pm = NULL; nameu = dupstring(name); unmetafy(nameu, &len); - key.dptr = nameu; pm = (Param) hcalloc(sizeof(struct param)); pm->node.nam = nameu; diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index 0a1a97c3d..2e2749835 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -1477,7 +1477,7 @@ set_comp_sep(void) * when stripping single quotes: 1 for RCQUOTES, 3 otherwise * (because we leave a "'" in the final string). */ - int dq = 0, odq, sq = 0, osq, qttype, sqq = 0, lsq = 0, qa = 0; + int dq = 0, odq, sq = 0, qttype, sqq = 0, lsq = 0, qa = 0; /* dolq: like sq and dq but for dollars quoting. */ int dolq = 0; /* remember some global variable values (except lp is local) */ @@ -1582,7 +1582,6 @@ set_comp_sep(void) } odq = dq; - osq = sq; inpush(dupstrspace(tmp), 0, NULL); zlemetaline = tmp; /* @@ -3306,7 +3305,7 @@ dupmatch(Cmatch m, int nbeg, int nend) mod_export int permmatches(int last) { - Cmgroup g = amatches, n, opm; + Cmgroup g = amatches, n; Cmatch *p, *q; Cexpl *ep, *eq, e, o; LinkList mlist; @@ -3320,7 +3319,6 @@ permmatches(int last) } newmatches = fi = 0; - opm = pmatches; pmatches = lmatches = NULL; nmatches = smatches = diffmatches = 0; diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c index fdca7a99f..c9c0c2dd4 100644 --- a/Src/Zle/complist.c +++ b/Src/Zle/complist.c @@ -1369,8 +1369,6 @@ compprintlist(int showall) } #endif if ((e = g->expls)) { - int l; - if (!lastused && lasttype == 1) { e = lastexpl; ml = lastml; @@ -1393,9 +1391,9 @@ compprintlist(int showall) } if (mlbeg < 0 && mfirstl < 0) mfirstl = ml; - l = compprintfmt((*e)->str, - ((*e)->always ? -1 : (*e)->count), - dolist(ml), 1, ml, &stop); + (void)compprintfmt((*e)->str, + ((*e)->always ? -1 : (*e)->count), + dolist(ml), 1, ml, &stop); if (mselect >= 0) { int mm = (mcols * ml), i; diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c index 797f86251..52797831c 100644 --- a/Src/Zle/zle_refresh.c +++ b/Src/Zle/zle_refresh.c @@ -2418,8 +2418,6 @@ singlerefresh(ZLE_STRING_T tmpline, int tmpll, int tmpcs) all_atr_off = TXT_ATTR_OFF_FROM_ON(all_atr_on); if (tmpline[t0] == ZWC('\t')) { - REFRESH_ELEMENT sp = zr_sp; - sp.atr = base_atr_on; for (*vp++ = zr_sp; (vp - vbuf) & 7; ) *vp++ = zr_sp; vp[-1].atr |= base_atr_off; diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index 8f7c2aac1..80a495317 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -529,7 +529,7 @@ parambeg(char *s) * or $'...'). */ char *b = p + 1, *e = b; - int n = 0, br = 1, nest = 0; + int n = 0, br = 1; if (*b == Inbrace) { char *tb = b; @@ -543,8 +543,6 @@ parambeg(char *s) n = skipparens(Inpar, Outpar, &b); for (tb = p - 1; tb > s && *tb != Outbrace && *tb != Inbrace; tb--); - if (tb > s && *tb == Inbrace && (tb[-1] == String || *tb == Qstring)) - nest = 1; } /* Ignore the stuff before the parameter name. */ diff --git a/Src/glob.c b/Src/glob.c index bfc7f0416..cf4a5a537 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -1801,7 +1801,7 @@ zglob(LinkList list, LinkNode np, int nountok) Eprog prog; if ((prog = parse_string(sortp->exec, 0))) { - int ef = errflag, lv = lastval, ret; + int ef = errflag, lv = lastval; /* Parsed OK, execute for each name */ for (tmpptr = matchbuf; tmpptr < matchptr; tmpptr++) { @@ -1814,7 +1814,6 @@ zglob(LinkList list, LinkNode np, int nountok) tmpptr->sortstrs[iexec] = tmpptr->name; } - ret = lastval; errflag = ef; lastval = lv; } else { diff --git a/Src/lex.c b/Src/lex.c index fdd05efff..51aaa76ef 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -1698,7 +1698,7 @@ parse_subscript(char *s, int sub, int endchar) mod_export int parse_subst_string(char *s) { - int c, l = strlen(s), err, olen, lexstop_ret; + int c, l = strlen(s), err; char *ptr; if (!*s || !strcmp(s, nulstring)) @@ -1711,13 +1711,11 @@ parse_subst_string(char *s) bptr = tokstr = s; bsiz = l + 1; c = hgetc(); - lexstop_ret = lexstop; c = gettokstr(c, 1); err = errflag; strinend(); inpop(); DPUTS(cmdsp, "BUG: parse_subst_string: cmdstack not empty."); - olen = len; lexrestore(); errflag = err; if (c == LEXERR) { @@ -1726,8 +1724,9 @@ parse_subst_string(char *s) } #ifdef DEBUG /* - * Historical note: we used to check here for olen == l, but - * that's not necessarily the case if we stripped an RCQUOTE. + * Historical note: we used to check here for olen (the value of len + * before lexrestore()) == l, but that's not necessarily the case if + * we stripped an RCQUOTE. */ if (c != STRING || (errflag && !noerrs)) { fprintf(stderr, "Oops. Bug in parse_subst_string: %s\n", diff --git a/Src/math.c b/Src/math.c index beef74525..cca521098 100644 --- a/Src/math.c +++ b/Src/math.c @@ -969,7 +969,6 @@ void op(int what) { mnumber a, b, c, *spval; - char *lv; int tp = type[what]; if (errflag) @@ -1155,7 +1154,6 @@ op(int what) } if (tp & (OP_E2|OP_E2IO)) { struct mathvalue *mvp = stack + sp + 1; - lv = stack[sp+1].lval; c = setmathvar(mvp, c); push(c, mvp->lval, 0); } else diff --git a/Src/params.c b/Src/params.c index a59c51767..8a56766f8 100644 --- a/Src/params.c +++ b/Src/params.c @@ -655,7 +655,10 @@ createparamtable(void) char **new_environ; int envsize; #endif - char **envp, **envp2, **sigptr, **t; +#ifndef USE_SET_UNSET_ENV + char **envp; +#endif + char **envp2, **sigptr, **t; char buf[50], *str, *iname, *ivalue, *hostnam; int oae = opts[ALLEXPORT]; #ifdef HAVE_UNAME @@ -721,7 +724,11 @@ createparamtable(void) /* Now incorporate environment variables we are inheriting * * into the parameter hash table. Copy them into dynamic * * memory so that we can free them if needed */ - for (envp = envp2 = environ; *envp2; envp2++) { + for ( +#ifndef USE_SET_UNSET_ENV + envp = +#endif + envp2 = environ; *envp2; envp2++) { if (split_env_string(*envp2, &iname, &ivalue)) { if (!idigit(*iname) && isident(iname) && !strchr(iname, '[')) { if ((!(pm = (Param) paramtab->getnode(paramtab, iname)) || @@ -993,9 +1000,7 @@ mod_export int isident(char *s) { char *ss; - int ne; - ne = noeval; /* save the current value of noeval */ if (!*s) /* empty string is definitely not valid */ return 0; diff --git a/Src/parse.c b/Src/parse.c index e59a882ca..4720dc3cf 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -1709,11 +1709,11 @@ par_simple(int *complex, int nr) } zshlex(); } else { - int ll, sl, pl, c = 0; + int ll, sl, c = 0; ll = ecadd(0); sl = ecadd(0); - pl = ecadd(WCB_PIPE(WC_PIPE_END, 0)); + (void)ecadd(WCB_PIPE(WC_PIPE_END, 0)); if (!par_cmd(&c)) { cmdpop(); diff --git a/Src/utils.c b/Src/utils.c index 066710e1e..d50311637 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -4689,7 +4689,7 @@ addunprintable(char *v, const char *u, const char *uend) mod_export char * quotestring(const char *s, char **e, int instring) { - const char *u, *tt; + const char *u; char *v; int alloclen; char *buf; @@ -4740,7 +4740,7 @@ quotestring(const char *s, char **e, int instring) break; } - tt = quotestart = v = buf = zshcalloc(alloclen); + quotestart = v = buf = zshcalloc(alloclen); DPUTS(instring < QT_BACKSLASH || instring == QT_BACKTICK || instring > QT_SINGLE_OPTIONAL, -- cgit v1.2.3 From 4a3ce8ab89c73f88559d9c48fdb4ed459a8aceef Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 3 Aug 2011 20:57:32 +0000 Subject: 29644: work around _describe bug, plus cosmetic tweaks --- ChangeLog | 6 +++++- Functions/Chpwd/zsh_directory_name_cdr | 2 +- Src/Zle/compcore.c | 3 ++- Src/Zle/zle_tricky.c | 13 ++++++++++++- 4 files changed, 20 insertions(+), 4 deletions(-) (limited to 'Src/Zle/compcore.c') diff --git a/ChangeLog b/ChangeLog index c6209fca0..dfc2b987e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2011-08-03 Peter Stephenson + * 29644: Functions/Chpwd/zsh_directory_name_cdr, + Src/Zle/compcore.c, Src/Zle/zle_tricky.c: Work round a bug in + _describe, plus a new comment and some more braces. + * 29633: Doc/Zsh/func.yo, Src/parse.c, Test/C04funcdef.ztst: be more careful that anonymous function syntax doesn't mess up working syntax with other functions. @@ -15195,5 +15199,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5414 $ +* $Revision: 1.5415 $ ***************************************************** diff --git a/Functions/Chpwd/zsh_directory_name_cdr b/Functions/Chpwd/zsh_directory_name_cdr index 09aa35a93..c9be7db0c 100644 --- a/Functions/Chpwd/zsh_directory_name_cdr +++ b/Functions/Chpwd/zsh_directory_name_cdr @@ -18,7 +18,7 @@ elif [[ $1 = c ]]; then values=(${${(f)"$(cdr -l)"}/ ##/:}) keys=(${values%%:*}) _describe -t dir-index 'recent directory index' \ - values keys -V unsorted -S']' + values -V unsorted -S']' return fi fi diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index 2e2749835..b1de6c6cc 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -607,7 +607,7 @@ callcompfunc(char *s, char *fn) if (rdstr) compredirect = rdstr; kset |= CP_REDIRECT; - } else + } else { switch (linwhat) { case IN_ENV: compcontext = (linarr ? "array_value" : "value"); @@ -637,6 +637,7 @@ callcompfunc(char *s, char *fn) aadd = 1; } } + } compcontext = ztrdup(compcontext); if (compwords) freearray(compwords); diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index 19787f9ff..999b2b7be 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -398,7 +398,18 @@ mod_export char *cmdstr; /**/ mod_export char *varname; -/* != 0 if we are in a subscript */ +/* + * != 0 if we are in a subscript. + * Of course, this being the completion code, you're expected to guess + * what the different numbers actually mean, but here's a cheat: + * 1: Key of an ordinary array + * 2: Key of a hash + * 3: Ummm.... this appears to be a special case of 2. After a lot + * of uncommented code looking for groups of brackets, we suddenly + * decide to set it to 2. The only upshot seems to be that compctl + * then doesn't add a matching ']' at the end, so I think it means + * there's one there already. + */ /**/ mod_export int insubscr; -- cgit v1.2.3