From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1987 invoked from network); 20 Sep 1999 12:15:56 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 20 Sep 1999 12:15:56 -0000 Received: (qmail 9712 invoked by alias); 20 Sep 1999 12:15:48 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7951 Received: (qmail 9705 invoked from network); 20 Sep 1999 12:15:48 -0000 Date: Mon, 20 Sep 1999 14:15:42 +0200 (MET DST) Message-Id: <199909201215.OAA07256@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk In-reply-to: Sven Wischnowsky's message of Mon, 20 Sep 1999 10:43:51 +0200 (MET DST) Subject: PATCH: was: Re: Chatty little precompiler for _arguments 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@informatik.hu-berlin.de