about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>2000-03-14 23:57:23 +0000
committerTanaka Akira <akr@users.sourceforge.net>2000-03-14 23:57:23 +0000
commit53f0102525def32c358ed52e0a92ee976c1e393c (patch)
treed45f8eb45c5c54878999a2dff9a2e85a30c946b3
parentbbf8d8baf0389b4bb20dfbdd48c62bc789e1a5fc (diff)
downloadzsh-53f0102525def32c358ed52e0a92ee976c1e393c.tar.gz
zsh-53f0102525def32c358ed52e0a92ee976c1e393c.tar.xz
zsh-53f0102525def32c358ed52e0a92ee976c1e393c.zip
zsh-workers/10135
-rw-r--r--Doc/Zsh/compsys.yo21
-rw-r--r--Src/Zle/computil.c36
2 files changed, 44 insertions, 13 deletions
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 13eebe7b1..9c38c3e27 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -2339,15 +2339,6 @@ quoted with a backslash.
 If the option may be given more than once, a star
 (`tt(*)') has to be added in front of the var(opt-spec).
 
-An var(opt-spec) may also contain a list of other option names with
-which the option described is mutually exclusive. Such a list is given 
-in parentheses at the beginning, as in `tt((-two -three)-one:...)'. In 
-this example, the options `tt(-two)' and `tt(-three)' will not be
-offered as possible completions if the option `tt(-one)' is on the
-line. Also, the list may contain a single colon as one of its elements 
-to specify that the descriptions for normal (non-option-) arguments
-should not be used if the option described is on the line.
-
 Finally, the var(opt-spec) may contain a explanation string. This is
 given in brackets at the end, as in `tt(-q[query operation])'. The
 tt(verbose) style is used to decide if these
@@ -2360,6 +2351,18 @@ first argument.
 )
 enditem()
 
+Every var(spec) may also contain a list of option names and argument
+numbers with which the option or argument described is mutually
+exclusive. Such a list is given in parentheses at the beginning, as in
+`tt((-two -three 1)-one:...)' or `tt((-foo):...)'. In the first
+example, the options `tt(-two)' and `tt(-three)' and the first
+argument will not be offered as possible completions if the option
+`tt(-one)' is on the line. Also, the list may contain a single star as
+one of its elements to specify that the description for the rest
+arguments should not be used and it may contain a colon to specify
+that the descriptions for all normal (non-option-) arguments should
+not be used.
+
 In each of the cases above, the var(action) says how the possible
 completions should be generated. In cases where only one of a fixed
 set of strings can be completed, these strings can directly be given as 
diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c
index 38996193b..d407a97f3 100644
--- a/Src/Zle/computil.c
+++ b/Src/Zle/computil.c
@@ -329,11 +329,13 @@ struct caopt {
 struct caarg {
     Caarg next;
     char *descr;		/* description */
+    char **xor;			/* if this, then not ... */
     char *action;		/* what to do for it */
     int type;			/* CAA_* below */
     char *end;			/* end-pattern for ::<pat>:... */
     char *opt;			/* option name if for an option */
     int num;			/* it's the num'th argument */
+    int active;			/* still allowed on command line */
 };
 
 #define CAA_NORMAL 1
@@ -375,6 +377,8 @@ freecaargs(Caarg a)
     for (; a; a = n) {
 	n = a->next;
 	zsfree(a->descr);
+	if (a->xor)
+	    freearray(a->xor);
 	zsfree(a->action);
 	zsfree(a->end);
 	zsfree(a->opt);
@@ -457,6 +461,7 @@ parse_caarg(int mult, int type, int num, char *oname, char **def)
 
     ret->next = NULL;
     ret->descr = ret->action = ret->end = NULL;
+    ret->xor = NULL;
     ret->num = num;
     ret->type = type;
     ret->opt = ztrdup(oname);
@@ -806,6 +811,7 @@ parse_cadef(char *nam, char **args)
 		    type = CAA_RARGS;
 	    }
 	    ret->rest = parse_caarg(0, type, -1, NULL, &p);
+	    ret->rest->xor = xor;
 	} else {
 	    /* It's a normal argument definition. */
 
@@ -835,6 +841,7 @@ parse_cadef(char *nam, char **args)
 		p++;
 	    }
 	    arg = parse_caarg(0, type, anum - 1, NULL, &p);
+	    arg->xor = xor;
 
 	    /* Sort the new definition into the existing list. */
 
@@ -970,10 +977,10 @@ ca_get_arg(Cadef d, int n)
 	while (a && a->num < n)
 	    a = a->next;
 
-	if (a && a->num == n)
+	if (a && a->num == n && a->active)
 	    return a;
 
-	return d->rest;
+	return (d->rest && d->rest->active ? d->rest : NULL);
     }
     return NULL;
 }
@@ -989,7 +996,19 @@ ca_inactive(Cadef d, char **xor)
 	for (; *xor; xor++) {
 	    if (xor[0][0] == ':' && !xor[0][1])
 		d->argsactive = 0;
-	    else if ((opt = ca_get_opt(d, *xor, 1, NULL)))
+	    else if (xor[0][0] == '*' && !xor[0][1]) {
+		if (d->rest)
+		    d->rest->active = 0;
+	    } else if (xor[0][0] >= '0' && xor[0][0] <= '9') {
+		int n = atoi(xor[0]);
+		Caarg a = d->args;
+
+		while (a && a->num < n)
+		    a = a->next;
+
+		if (a && a->num == n)
+		    a->active = 0;
+	    } else if ((opt = ca_get_opt(d, *xor, 1, NULL)))
 		opt->active = 0;
 	}
     }
@@ -1019,7 +1038,7 @@ ca_parse_line(Cadef d)
     Caarg adef, ddef;
     Caopt ptr, wasopt;
     struct castate state;
-    char *line, *pe;
+    char *line, *pe, **argxor = NULL;
     int cur, doff;
     Patprog endpat = NULL;
 
@@ -1041,6 +1060,10 @@ ca_parse_line(Cadef d)
     for (ptr = d->opts; ptr; ptr = ptr->next)
 	ptr->active = 1;
     d->argsactive = 1;
+    if (d->rest)
+	d->rest->active = 1;
+    for (adef = d->args; adef; adef = adef->next)
+	adef->active = 1;
 
     /* Default values for the state. */
 
@@ -1072,6 +1095,8 @@ ca_parse_line(Cadef d)
 	ddef = adef = NULL;
 	doff = state.singles = 0;
 
+	ca_inactive(d, argxor);
+
 	/* We've a definition for an argument, skip to the next. */
 
 	if (state.def) {
@@ -1202,6 +1227,9 @@ ca_parse_line(Cadef d)
 	    }
 	    zaddlinknode(state.args, ztrdup(line));
 
+	    if (state.def)
+		argxor = state.def->xor;
+
 	    if (state.def && state.def->type != CAA_NORMAL &&
 		state.def->type != CAA_OPT && state.inarg) {
 		state.restbeg = cur;