From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6889 invoked from network); 5 May 2000 14:27:14 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 5 May 2000 14:27:14 -0000 Received: (qmail 22497 invoked by alias); 5 May 2000 14:26:58 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 11200 Received: (qmail 22325 invoked from network); 5 May 2000 14:26:43 -0000 Date: Fri, 05 May 2000 15:26:16 +0100 From: Peter Stephenson Subject: PATCH: substitution anchors In-reply-to: "Your message of Fri, 05 May 2000 17:32:58 +0400." <001701bfb696$6d2abbd0$21c9ca95@mow.siemens.ru> To: zsh-workers@sunsite.auc.dk (Zsh hackers list) Message-id: <0FU300484C3RBN@la-la.cambridgesiliconradio.com> Content-transfer-encoding: 7BIT > That's because I used wrong syntax in _arguments (_long_options at the > time of writing). This patch gets it right and replaces # with (#s), > that also works. Patch attached. OK, this would remove the effect of anchors in substituted parameters, and makes it a bit clearer what's going on. I don't if Bart is still keen on keeping this effect. This needs Andrej's patch (the only effect at the moment is whether `configure' shows all --enable/--disable pairs when the help text contains one of them, as is usual) and I will commit the two together or not at all. Index: Doc/Zsh/expn.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v retrieving revision 1.11 diff -u -r1.11 expn.yo --- Doc/Zsh/expn.yo 2000/05/04 06:21:18 1.11 +++ Doc/Zsh/expn.yo 2000/05/05 14:20:23 @@ -456,13 +456,21 @@ Replace the longest possible match of var(pattern) in the expansion of parameter var(name) by string var(repl). The first form replaces just the first occurrence, the second form all occurrences. +Both var(pattern) and var(repl) are subject to double-quoted substitution, +so that expressions like tt(${name/$opat/$npat}) will work, but note the +usual rule that pattern characters in tt($opat) are not treated specially +unless either the option tt(GLOB_SUBST) is set, or tt($opat) is instead +substituted as tt(${~opat}). + The var(pattern) may begin with a `tt(#)', in which case the var(pattern) must match at the start of the string, or `tt(%)', in which case it must match at the end of the string. The var(repl) may be an empty string, in which case the final `tt(/)' may also be omitted. To quote the final `tt(/)' in other cases it should be preceded by two backslashes (i.e., a quoted backslash); this is not necessary if the -`tt(/)' occurs inside a substituted parameter. +`tt(/)' occurs inside a substituted parameter. Note also that the `tt(#)' +and `tt(%)' are not active if they occur inside a substituted parameter, +even at the start. The first `tt(/)' may be preceded by a `tt(:)', in which case the match will only succeed if it matches the entire word. Note also the Index: Src/subst.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/subst.c,v retrieving revision 1.3 diff -u -r1.3 subst.c --- Src/subst.c 2000/05/03 12:21:56 1.3 +++ Src/subst.c 2000/05/05 14:20:23 @@ -1466,6 +1466,13 @@ char t = s[-1]; singsub(&s); +#if 0 + /* + * This allows # and % to be at the start of + * a parameter in the substitution, which is + * a bit nasty, and can be done (although + * less efficiently) with anchors. + */ if (t == '/' && (flags & SUB_SUBSTR)) { if ((c = *s) == '#' || c == '%') { flags &= ~SUB_SUBSTR; @@ -1476,6 +1483,7 @@ s++; } } +#endif } if (!vunset && isarr) { -- Peter Stephenson Cambridge Silicon Radio, Unit 300, Science Park, Milton Road, Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070