zsh-workers
 help / color / mirror / code / Atom feed
From: Sven Wischnowsky <wischnow@berkom.de>
To: zsh-workers@sunsite.dk
Subject: Re: _call_program (and possibly other hooks) or opt_args quoting prob lem.
Date: Tue, 21 May 2002 10:14:56 +0200	[thread overview]
Message-ID: <15594.512.412597.296070@wischnow.berkom.de> (raw)
In-Reply-To: <1021916607.3408.10.camel@localhost.localdomain>


Borsenkow Andrej wrote:

> ...
> 
> What happens currently is, zsh removes quoting when it stores values in
> opt_args array but it does not expand it. After this is done there is no
> way to recover original string as entered by user. So in cases when you
> may want it (see above example _foo) you have no means to get real
> value.

It's the code affected by the patch below (which I'm not going to
commit right now, only if I get replies). We need the de-quoting
because options may be partly quoted (Bart once send a message about
this and as a consequence I added the de-quoting code).

I'm not sure if we should commit this patch, because, as was already
pointed out, ${(e)...} on a string as it is reported now should give
one the needed expansion. With the patch that would become ${(Qe)...}.

Any opinions?


Bye
  Sven

P.S.: The patch may be offset, never mind.

diff -ur -r ../oz/Src/Zle/computil.c ./Src/Zle/computil.c
--- ../oz/Src/Zle/computil.c	Sat May 18 20:31:04 2002
+++ ./Src/Zle/computil.c	Sat May 18 23:28:25 2002
@@ -1693,6 +1695,33 @@
     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
@@ -1701,7 +1730,7 @@
     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;
@@ -1767,6 +1796,7 @@
 	doff = state.singles = arglast = 0;
 
         /* remove quotes */
+        oline = line;
         line = dupstring(line);
         ne = noerrs;
         noerrs = 2;
@@ -1786,7 +1816,7 @@
 	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++;
@@ -1868,7 +1898,8 @@
 		    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;
@@ -1921,7 +1952,8 @@
 		    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;

-- 
Sven Wischnowsky                          wischnow@berkom.de


  reply	other threads:[~2002-05-21  8:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-16 16:32 Borsenkow Andrej
2002-05-17 18:39 ` Bart Schaefer
2002-05-18 11:24   ` Borsenkow Andrej
2002-05-20 16:40     ` Bart Schaefer
2002-05-20 17:43       ` Borsenkow Andrej
2002-05-21  8:14         ` Sven Wischnowsky [this message]
2002-05-21 16:17           ` Bart Schaefer
2002-05-23 12:20             ` Sven Wischnowsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15594.512.412597.296070@wischnow.berkom.de \
    --to=wischnow@berkom.de \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).