about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2002-05-23 12:22:58 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2002-05-23 12:22:58 +0000
commit9b5b330799ce35d5f833092f7fe503170e4b3e02 (patch)
tree1bb7345380cb445c60f442f8f81df3f512eb5e9f /Src
parent86f38401aacfcd9b3ef6cb54faf305f7c843e60b (diff)
downloadzsh-9b5b330799ce35d5f833092f7fe503170e4b3e02.tar.gz
zsh-9b5b330799ce35d5f833092f7fe503170e4b3e02.tar.xz
zsh-9b5b330799ce35d5f833092f7fe503170e4b3e02.zip
report option arguments to _arguments in the original form (17196)
Diffstat (limited to 'Src')
-rw-r--r--Src/Zle/computil.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c
index 7254db531..412347ec9 100644
--- a/Src/Zle/computil.c
+++ b/Src/Zle/computil.c
@@ -1734,6 +1734,33 @@ freecastate(Castate s)
     zfree(s->oargs, s->d->nopts * sizeof(LinkList));
 }
 
+/* Return a copy of an option's argument, ignoring possible quoting
+ * in the option name. */
+
+static char *
+ca_opt_arg(Caopt opt, char *line)
+{
+    char *o = opt->name;
+
+    while (1) {
+        if (*o == '\\')
+            o++;
+        if (*line == '\\' || *line == '\'' || *line == '"')
+            line++;
+        if (!*o || *o != *line)
+            break;
+        o++;
+        line++;
+    }
+    if (*line && (opt->type == CAO_EQUAL || opt->type == CAO_OEQUAL)) {
+        if (*line == '\\')
+            line++;
+        if (*line == '=')
+            line++;
+    }
+    return ztrdup(line);
+}
+
 /* Parse a command line. */
 
 static int
@@ -1742,7 +1769,7 @@ ca_parse_line(Cadef d, int multi, int first)
     Caarg adef, ddef;
     Caopt ptr, wasopt = NULL, dopt;
     struct castate state;
-    char *line, *pe, **argxor = NULL;
+    char *line, *oline, *pe, **argxor = NULL;
     int cur, doff, argend, arglast, ne;
     Patprog endpat = NULL, napat = NULL;
     LinkList sopts = NULL;
@@ -1808,6 +1835,7 @@ ca_parse_line(Cadef d, int multi, int first)
 	doff = state.singles = arglast = 0;
 
         /* remove quotes */
+        oline = line;
         line = dupstring(line);
         ne = noerrs;
         noerrs = 2;
@@ -1827,7 +1855,7 @@ ca_parse_line(Cadef d, int multi, int first)
 	if (state.def) {
 	    state.arg = 0;
 	    if (state.curopt)
-		zaddlinknode(state.oargs[state.curopt->num], ztrdup(line));
+		zaddlinknode(state.oargs[state.curopt->num], ztrdup(oline));
 
 	    if ((state.opt = (state.def->type == CAA_OPT)) && state.def->opt)
 		state.oopt++;
@@ -1909,7 +1937,8 @@ ca_parse_line(Cadef d, int multi, int first)
 		    state.def->type != CAA_RREST)
 		    state.def = state.def->next;
 
-		zaddlinknode(state.oargs[state.curopt->num], ztrdup(pe));
+		zaddlinknode(state.oargs[state.curopt->num],
+                             ca_opt_arg(state.curopt, oline));
 	    }
 	    if (state.def)
 		state.opt = 0;
@@ -1962,7 +1991,8 @@ ca_parse_line(Cadef d, int multi, int first)
 		    state.def->type != CAA_RREST)
 		    state.def = state.def->next;
 
-		zaddlinknode(state.oargs[state.curopt->num], ztrdup(pe));
+		zaddlinknode(state.oargs[state.curopt->num],
+                             ca_opt_arg(state.curopt, line));
 	    }
 	    if (state.def)
 		state.opt = 0;