about summary refs log tree commit diff
path: root/Src/Zle/computil.c
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 /Src/Zle/computil.c
parentbbf8d8baf0389b4bb20dfbdd48c62bc789e1a5fc (diff)
downloadzsh-53f0102525def32c358ed52e0a92ee976c1e393c.tar.gz
zsh-53f0102525def32c358ed52e0a92ee976c1e393c.tar.xz
zsh-53f0102525def32c358ed52e0a92ee976c1e393c.zip
zsh-workers/10135
Diffstat (limited to 'Src/Zle/computil.c')
-rw-r--r--Src/Zle/computil.c36
1 files changed, 32 insertions, 4 deletions
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;