diff options
Diffstat (limited to 'Src/Zle/complete.c')
-rw-r--r-- | Src/Zle/complete.c | 81 |
1 files changed, 59 insertions, 22 deletions
diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c index 30fab541a..68bdf2332 100644 --- a/Src/Zle/complete.c +++ b/Src/Zle/complete.c @@ -52,7 +52,7 @@ char **compwords, *compqiprefix, *compqisuffix, *compquote, - *compqstack, + *compqstack, /* compstate[all_quotes] */ *comppatmatch, *complastprompt; /**/ @@ -67,13 +67,31 @@ char *compiprefix, *compexact, *compexactstr, *comppatinsert, - *comptoend, + *comptoend, /* compstate[to_end]; populates 'movetoend' */ *compoldlist, *compoldins, *compvared; +/* + * An array of Param structures for compsys special parameters; + * see 'comprparams' below. An entry for $compstate is added + * by makecompparams(). + * + * See CP_REALPARAMS. + */ + +/**/ +Param *comprpms; + +/* + * An array of Param structures for elemens of $compstate; see + * 'compkparams' below. + * + * See CP_KEYPARAMS. + */ + /**/ -Param *comprpms, *compkpms; +Param *compkpms; /**/ mod_export void @@ -209,7 +227,15 @@ cpcpattern(Cpattern o) return r; } -/* Parse a string for matcher control, containing multiple matchers. */ +/* + * Parse a string for matcher control, containing multiple matchers. + * + * 's' is the string to be parsed. + * + * 'name' is the name of the builtin from which this is called, for errors. + * + * Return 'pcm_err' on error; a NULL return value means ... + */ /**/ mod_export Cmatcher @@ -231,16 +257,17 @@ parse_cmatcher(char *name, char *s) if (!*s) break; switch (*s) { - case 'b': fl2 = CMF_INTER; + case 'b': fl2 = CMF_INTER; /* FALLTHROUGH */ case 'l': fl = CMF_LEFT; break; - case 'e': fl2 = CMF_INTER; + case 'e': fl2 = CMF_INTER; /* FALLTHROUGH */ case 'r': fl = CMF_RIGHT; break; case 'm': fl = 0; break; - case 'B': fl2 = CMF_INTER; + case 'B': fl2 = CMF_INTER; /* FALLTHROUGH */ case 'L': fl = CMF_LEFT | CMF_LINE; break; - case 'E': fl2 = CMF_INTER; + case 'E': fl2 = CMF_INTER; /* FALLTHROUGH */ case 'R': fl = CMF_RIGHT | CMF_LINE; break; case 'M': fl = CMF_LINE; break; + case 'x': break; default: if (name) zwarnnam(name, "unknown match specification character `%c'", @@ -252,6 +279,15 @@ parse_cmatcher(char *name, char *s) zwarnnam(name, "missing `:'"); return pcm_err; } + if (*s == 'x') { + if (s[2] && !inblank(s[2])) { + if (name) + zwarnnam(name, + "unexpected pattern following x: specification"); + return pcm_err; + } + return ret; + } s += 2; if (!*s) { if (name) @@ -527,8 +563,8 @@ static int bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func)) { struct cadata dat; - char *p, **sp, *e, *m = NULL, *mstr = NULL; - int dm; + char *mstr = NULL; /* argument of -M options, accumulated */ + int added; /* return value */ Cmatcher match = NULL; if (incompfunc != 1) { @@ -544,14 +580,16 @@ bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func)) dat.dummies = -1; for (; *argv && **argv == '-'; argv++) { + char *p; /* loop variable, points into argv */ if (!(*argv)[1]) { argv++; break; } for (p = *argv + 1; *p; p++) { - sp = NULL; - e = NULL; - dm = 0; + char *m = NULL; /* argument of -M option (this one only) */ + char **sp = NULL; /* the argument to an option should be copied + to *sp. */ + const char *e; /* error message */ switch (*p) { case 'q': dat.flags |= CMF_REMOVE; @@ -633,7 +671,6 @@ bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func)) case 'M': sp = &m; e = "matching specification expected after -%c"; - dm = 1; break; case 'X': sp = &(dat.exp); @@ -720,14 +757,13 @@ bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func)) zsfree(mstr); return 1; } - if (dm) { + if (m) { if (mstr) { char *tmp = tricat(mstr, " ", m); zsfree(mstr); mstr = tmp; } else mstr = ztrdup(m); - m = NULL; } } } @@ -746,10 +782,10 @@ bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func)) return 1; dat.match = match = cpcmatcher(match); - dm = addmatches(&dat, argv); + added = addmatches(&dat, argv); freecmatcher(match); - return dm; + return added; } #define CVT_RANGENUM 0 @@ -865,7 +901,7 @@ do_comp_vars(int test, int na, char *sa, int nb, char *sb, int mod) return 0; singsub(&sa); - pp = patcompile(sa, PAT_STATIC, NULL); + pp = patcompile(sa, PAT_HEAPDUP, NULL); for (i--, p = compwords + i; i >= 0; p--, i--) { if (pattry(pp, *p)) { @@ -919,7 +955,7 @@ do_comp_vars(int test, int na, char *sa, int nb, char *sb, int mod) if (!na) return 0; - if (!(pp = patcompile(sa, PAT_STATIC, 0))) + if (!(pp = patcompile(sa, PAT_HEAPDUP, 0))) return 0; if (test == CVT_PREPAT) { @@ -1210,8 +1246,9 @@ makecompparams(void) addcompparams(comprparams, comprpms); - if (!(cpm = createparam(COMPSTATENAME, - PM_SPECIAL|PM_REMOVABLE|PM_LOCAL|PM_HASHED))) + if (!(cpm = createparam( + COMPSTATENAME, + PM_SPECIAL|PM_REMOVABLE|PM_SINGLE|PM_LOCAL|PM_HASHED))) cpm = (Param) paramtab->getnode(paramtab, COMPSTATENAME); DPUTS(!cpm, "param not set in makecompparams"); |