From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20417 invoked by alias); 11 May 2011 13:03:08 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 29218 Received: (qmail 15746 invoked from network); 11 May 2011 13:03:06 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, T_TO_NO_BRKTS_FREEMAIL autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.214.43 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:subject:date:message-id:x-mailer; bh=lJzHvFRitiJStNBEP9VRXXaGmFkQocNGW7YAxX8RifM=; b=Tn/1yZaEY1NnV3dd9ERiwgfu14DeoT+Q/dv0L4bKnEdgWprlMAM//I386cVzw3XH04 P3JhlqU3ZFzjSyKZs2JTJv66ZpifhxRY4+ozUVzEP0dqoezld/McxdaqZD9nk9qU73H6 rv3AzWXZ5eDnOMJLQd7hRPNWyAWBZSYx3CXXY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer; b=eoFW4fiigSZmdIqMEU1W1MtrxNp/vs9mmxNnOsqP0fyoU/GRsDJYxP9VautZ0TjTJP S0x84oTFqoVFO2S0Bv6+14G3XIT5FRTPxNdHSk2U2Wkqc6kfvCUKCSLFIenIqq7QfMyP eBx04gtvS+IipBIbEQps4EW1makoQuSRO1u5I= From: Mikael Magnusson To: zsh-workers@zsh.org Subject: PATCH: expanding parameters like echo/print builtins Date: Wed, 11 May 2011 15:02:51 +0200 Message-Id: <1305118971-25617-1-git-send-email-mikachu@gmail.com> X-Mailer: git-send-email 1.7.4-rc1 Is this already possible? I had an array with a lot of \u1234 escapes in it, and couldn't find a way to do it easily. I came up with this: ${arr:gs/(#b)'\\\\u(????)/${(#):-$(( 16#$match[1] ))}'} but it's a bit awkward to type. The following patch adds the (g::) parameter flag which calls the getkeystring function, and allows setting the _EMACS, _OCTAL_ESC and _CTRL flags. --- Doc/Zsh/expn.yo | 8 ++++++++ Src/subst.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 0 deletions(-) diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index 2c3a571..2beebd7 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -863,6 +863,14 @@ item(tt(F))( Join the words of arrays together using newline as a separator. This is a shorthand for `tt(pj:\n:)'. ) +item(tt(g:opts:))( +Expand words like the echo builtin. With the tt(o) option, octal escapes +don't take a leading zero. With the tt(c) option, sequences like `tt(^X)' +are interpreted. With the tt(e) option, interprets `tt(\M-t)' and similar +sequences like the print builtin. With both tt(o) and tt(e) options, behaves +like the print builtin with the exception of the next sentence. In none +of these modes is `tt(\c)' interpreted. +) item(tt(i))( Sort case-insensitively. May be combined with `tt(n)' or `tt(O)'. ) diff --git a/Src/subst.c b/Src/subst.c index 617986c..a2af01b 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -1607,6 +1607,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub) */ int presc = 0; /* + * The (g) flag. Expand words with various GETKEY_ flags. + */ + int getkeys = -1; + /* * The (@) flag; interacts obscurely with qt and isarr. * This is one of the things that decides whether multsub * will produce an array, but in an extremely indirect fashion. @@ -1932,6 +1936,36 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub) presc++; break; + case 'z': + t = get_strarg(++s, &arglen); + if (getkeys < 0) + getkeys = 0; + if (*t) { + sav = *t; + *t = 0; + while (*++s) { + switch (*s) { + case 'e': + getkeys |= GETKEY_EMACS; + break; + case 'o': + getkeys |= GETKEY_OCTAL_ESC; + break; + case 'c': + getkeys |= GETKEY_CTRL; + break; + + default: + *t = sav; + goto flagerr; + } + } + *t = sav; + s = t + arglen - 1; + } else + goto flagerr; + break; + case 'z': shsplit = LEXFLAGS_ACTIVE; break; @@ -3141,6 +3175,27 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub) opts[PROMPTPERCENT] = opp; } /* + * Perform GETKEY expansion + */ + if (getkeys >= 0) { + if (isarr) { + char **ap; + + if (!copied) + aval = arrdup(aval), copied = 1; + ap = aval; + for (; *ap; ap++) { + int len; + *ap = getkeystring(*ap, &len, getkeys, NULL); + } + } else { + int len; + if (!copied) + val = dupstring(val), copied = 1; + val = getkeystring(val, &len, getkeys, NULL); + } + } + /* * One of the possible set of quotes to apply, depending on * the repetitions of the (q) flag. */ -- 1.7.4-rc1