From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: parameter and quoting (was: Re: Completion problems.)
Date: Thu, 5 Aug 1999 14:19:00 +0200 (MET DST) [thread overview]
Message-ID: <199908051219.OAA16988@beta.informatik.hu-berlin.de> (raw)
In-Reply-To: "Bart Schaefer"'s message of Wed, 4 Aug 1999 17:00:44 +0000
Bart Schaefer wrote:
> On Aug 4, 11:37am, Sven Wischnowsky wrote:
> } Subject: Re: Completion problems.
> }
> } Tanaka Akira wrote:
> }
> } > In following examples, unquoted forms are not known until runtime.
> } >
> } > % if some-complex-command; then var=xxx; else var=yyy; fi; tst $var/<TAB>
> } > % tst $(some-complex-command)/<TAB>
> }
> } I see two ways to go: 1) completely change the completion code to
> } report strings in unquoted form or 2) add a parameter expansion
> } modifier which does something like the opposite of `:q'.
>
> I think (2) would be quite useful in other contexts anyway. Perhaps (Q)?
> (And we could add (q) which means the same as :q, just for completeness.)
The patch below tries to do that in the simplest way I could think of.
This is the solution that makes errors be ignored, because I have to
ask first: we could easily add another flag that turns on error-
checking. OR should error-reporting be the normal case and we should
have a flag to turn it off? For modifiers we could have a new modifier
that can be combined with `Q' a la `g' and `f', e.g. `$a:EQ' or
something like that. And with respect to the flag: this could be made
to work for things like `${...%...}', too. Btw. something like `${foo%(}'
currently gives me a non-zero return status but no error message --
even though there seems to be some extra code for it -- I haven't
investigated any firther yet, but this seems wrong, doesn't it?
Ok. Which way should we go?
Bye
Sven
diff -u os/subst.c Src/subst.c
--- os/subst.c Mon Aug 2 11:44:47 1999
+++ Src/subst.c Thu Aug 5 14:00:43 1999
@@ -721,6 +721,7 @@
int flnum = 0;
int sortit = 0, casind = 0;
int casmod = 0;
+ int quotemod = 0;
char *sep = NULL, *spsep = NULL;
char *premul = NULL, *postmul = NULL, *preone = NULL, *postone = NULL;
char *replstr = NULL; /* replacement string for /orig/repl */
@@ -822,6 +823,14 @@
case 'i':
casind = 1;
break;
+
+ case 'q':
+ quotemod = 1;
+ break;
+ case 'Q':
+ quotemod = -1;
+ break;
+
case 'e':
eval = 1;
break;
@@ -1546,6 +1555,46 @@
makecapitals(&val);
}
}
+ if (quotemod) {
+ if (isarr) {
+ char **ap;
+
+ if (!copied)
+ aval = arrdup(aval), copied = 1;
+ ap = aval;
+
+ if (quotemod > 0)
+ for (; *ap; ap++)
+ *ap = bslashquote(*ap, NULL, 0);
+ else {
+ int one = noerrs, oef = errflag;
+
+ noerrs = 1;
+ for (; *ap; ap++) {
+ parse_subst_string(*ap);
+ remnulargs(*ap);
+ untokenize(*ap);
+ }
+ noerrs = one;
+ errflag = oef;
+ }
+ } else {
+ if (!copied)
+ val = dupstring(val), copied = 1;
+ if (quotemod > 0)
+ val = bslashquote(val, NULL, 0);
+ else {
+ int one = noerrs, oef = errflag;
+
+ noerrs = 1;
+ parse_subst_string(val);
+ noerrs = one;
+ errflag = oef;
+ remnulargs(val);
+ untokenize(val);
+ }
+ }
+ }
if (isarr) {
char *x;
char *y;
@@ -1747,6 +1796,7 @@
case 'l':
case 'u':
case 'q':
+ case 'Q':
c = **ptr;
break;
@@ -1868,6 +1918,18 @@
case 'q':
copy = bslashquote(copy, NULL, 0);
break;
+ case 'Q':
+ {
+ int one = noerrs, oef = errflag;
+
+ noerrs = 1;
+ parse_subst_string(copy);
+ noerrs = one;
+ errflag = oef;
+ remnulargs(copy);
+ untokenize(copy);
+ }
+ break;
}
tc = *tt;
*tt = '\0';
@@ -1921,6 +1983,18 @@
break;
case 'q':
*str = bslashquote(*str, NULL, 0);
+ break;
+ case 'Q':
+ {
+ int one = noerrs, oef = errflag;
+
+ noerrs = 1;
+ parse_subst_string(*str);
+ noerrs = one;
+ errflag = oef;
+ remnulargs(*str);
+ untokenize(*str);
+ }
break;
}
}
diff -u od/Zsh/expn.yo Doc/Zsh/expn.yo
--- od/Zsh/expn.yo Mon Aug 2 11:45:23 1999
+++ Doc/Zsh/expn.yo Thu Aug 5 14:12:26 1999
@@ -166,6 +166,9 @@
case it is only useful if the resulting text is to be re-evaluated
such as by tt(eval).
)
+item(tt(Q))(
+Remove one level of quotes from the substituted words.
+)
item(tt(x))(
Like tt(q), but break into words at each blank.
)
@@ -577,6 +580,12 @@
Capitalize the resulting words. `Words' in this case refers to sequences
of alphanumeric characters separated by non-alphanumerics, em(not) to words
that result from field splitting.
+)
+item(tt(q))(
+Quote the resulting words with backslashes.
+)
+item(tt(Q))(
+Remove one level of quotes from the resulting words.
)
item(tt(c))(
With tt(${#)var(name)tt(}), count the total number of characters in an array,
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
next reply other threads:[~1999-08-05 12:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-08-05 12:19 Sven Wischnowsky [this message]
1999-08-05 12:05 ` Peter Stephenson
1999-08-05 16:20 ` Bart Schaefer
1999-08-05 12:53 Sven Wischnowsky
1999-08-05 13:18 ` Peter Stephenson
1999-08-05 14:22 ` Andrej Borsenkow
1999-08-05 14:26 Sven Wischnowsky
1999-08-05 14:41 ` Andrej Borsenkow
1999-08-05 16:24 ` Bart Schaefer
1999-08-06 7:14 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=199908051219.OAA16988@beta.informatik.hu-berlin.de \
--to=wischnow@informatik.hu-berlin.de \
--cc=zsh-workers@sunsite.auc.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).