Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: was: Re: Chatty little precompiler for _arguments
- X-seq: zsh-workers 7951
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: PATCH: was: Re: Chatty little precompiler for _arguments
- Date: Mon, 20 Sep 1999 14:15:42 +0200 (MET DST)
- In-reply-to: Sven Wischnowsky's message of Mon, 20 Sep 1999 10:43:51 +0200 (MET DST)
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
I wrote:
> Bart Schaefer wrote:
>
> > though it would be really useful if $param:q could emit quoting instead of
> > backslashes.
>
> I would be against this because its much less useful in cases where
> you stuff together string from multiple parameters. However, in its
> first life `:q' did that and we could use the doubled-flag convention
> so that `${(qq)foo}' would emit stuff in single quotes. (Tripled for
> double quotes?)
This does that. `${(qqq)foo}' looks a bit silly doesn't it?
Bye
Sven
--- os/subst.c Mon Sep 20 13:53:20 1999
+++ Src/subst.c Mon Sep 20 14:05:41 1999
@@ -721,7 +721,7 @@
int flnum = 0;
int sortit = 0, casind = 0;
int casmod = 0;
- int quotemod = 0, quoteerr = 0;
+ int quotemod = 0, quotetype = 0, quoteerr = 0;
char *sep = NULL, *spsep = NULL;
char *premul = NULL, *postmul = NULL, *preone = NULL, *postone = NULL;
char *replstr = NULL; /* replacement string for /orig/repl */
@@ -826,7 +826,7 @@
break;
case 'q':
- quotemod++;
+ quotemod++, quotetype++;
break;
case 'Q':
quotemod--;
@@ -1617,6 +1617,8 @@
opts[PROMPTPERCENT] = opp;
}
if (quotemod) {
+ if (--quotetype > 2)
+ quotetype = 2;
if (isarr) {
char **ap;
@@ -1624,10 +1626,23 @@
aval = arrdup(aval), copied = 1;
ap = aval;
- if (quotemod > 0)
- for (; *ap; ap++)
- *ap = bslashquote(*ap, NULL, 0);
- else {
+ if (quotemod > 0) {
+ if (quotetype) {
+ int sl;
+ char *tmp;
+
+ for (; *ap; ap++) {
+ tmp = bslashquote(*ap, NULL, quotetype);
+ sl = strlen(tmp);
+ *ap = (char *) zhalloc(sl + 3);
+ strcpy((*ap) + 1, tmp);
+ ap[0][0] = ap[0][sl + 1] = (quotetype == 1 ? '\'' : '"');
+ ap[0][sl + 2] = '\0';
+ }
+ } else
+ for (; *ap; ap++)
+ *ap = bslashquote(*ap, NULL, 0);
+ } else {
int one = noerrs, oef = errflag, haserr = 0;
if (!quoteerr)
@@ -1648,9 +1663,20 @@
} else {
if (!copied)
val = dupstring(val), copied = 1;
- if (quotemod > 0)
- val = bslashquote(val, NULL, 0);
- else {
+ if (quotemod > 0) {
+ if (quotetype) {
+ int sl;
+ char *tmp;
+
+ tmp = bslashquote(val, NULL, quotetype);
+ sl = strlen(tmp);
+ val = (char *) zhalloc(sl + 3);
+ strcpy(val + 1, tmp);
+ val[0] = val[sl + 1] = (quotetype == 1 ? '\'' : '"');
+ val[sl + 2] = '\0';
+ } else
+ val = bslashquote(val, NULL, 0);
+ } else {
int one = noerrs, oef = errflag, haserr;
if (!quoteerr)
diff -u od/Zsh/expn.yo Doc/Zsh/expn.yo
--- od/Zsh/expn.yo Mon Sep 20 13:06:32 1999
+++ Doc/Zsh/expn.yo Mon Sep 20 14:14:20 1999
@@ -582,7 +582,9 @@
that result from field splitting.
)
item(tt(q))(
-Quote the resulting words with backslashes.
+Quote the resulting words with backslashes. If this flag is given
+twice, the resulting words are quoted in single quotes and if it is
+given three times, the words are quoted in double quotes.
)
item(tt(Q))(
Remove one level of quotes from the resulting words.
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author