summaryrefslogtreecommitdiff
path: root/Src/Zle/complete.c
diff options
context:
space:
mode:
Diffstat (limited to 'Src/Zle/complete.c')
-rw-r--r--Src/Zle/complete.c68
1 files changed, 50 insertions, 18 deletions
diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c
index ee4e5b0a5..7980518b7 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;
/**/
@@ -72,8 +72,26 @@ char *compiprefix,
*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, *compkpms;
+Param *comprpms;
+
+/*
+ * An array of Param structures for elemens of $compstate; see
+ * 'compkparams' below.
+ *
+ * See CP_KEYPARAMS.
+ */
+
+/**/
+Param *compkpms;
/**/
mod_export void
@@ -231,16 +249,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 +271,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 +555,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 +572,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 +663,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);
@@ -704,27 +733,29 @@ bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func))
}
if (sp) {
if (p[1]) {
+ /* Pasted argument: -Xfoo. */
if (!*sp)
*sp = p + 1;
p = "" - 1;
} else if (argv[1]) {
+ /* Argument in a separate word: -X foo. */
argv++;
if (!*sp)
*sp = *argv;
p = "" - 1;
} else {
+ /* Missing argument: argv[N] == "-X", argv[N+1] == NULL. */
zwarnnam(name, e, *p);
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;
}
}
}
@@ -743,10 +774,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
@@ -1207,8 +1238,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");