From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24493 invoked from network); 7 Nov 2006 22:44:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.7 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 7 Nov 2006 22:44:31 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 54818 invoked from network); 7 Nov 2006 22:44:13 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 7 Nov 2006 22:44:13 -0000 Received: (qmail 327 invoked by alias); 7 Nov 2006 22:44:11 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 22980 Received: (qmail 317 invoked from network); 7 Nov 2006 22:44:10 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 7 Nov 2006 22:44:10 -0000 Received: (qmail 54525 invoked from network); 7 Nov 2006 22:44:10 -0000 Received: from mtaout02-winn.ispmail.ntl.com (81.103.221.48) by a.mx.sunsite.dk with SMTP; 7 Nov 2006 22:44:06 -0000 Received: from aamtaout04-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com with ESMTP id <20061107224409.FXOD27023.mtaout02-winn.ispmail.ntl.com@aamtaout04-winn.ispmail.ntl.com> for ; Tue, 7 Nov 2006 22:44:09 +0000 Received: from pwslaptop.csr.com ([81.107.46.43]) by aamtaout04-winn.ispmail.ntl.com with SMTP id <20061107224405.UXGJ15733.aamtaout04-winn.ispmail.ntl.com@pwslaptop.csr.com> for ; Tue, 7 Nov 2006 22:44:05 +0000 Date: Tue, 7 Nov 2006 22:44:01 +0000 From: Peter Stephenson To: Zsh Hackers' List Subject: PATCH: more things I screwed up Message-Id: <20061107224401.8b7adf56.p.w.stephenson@ntlworld.com> X-Mailer: Sylpheed version 2.2.9 (GTK+ 2.8.20; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I've never realised that the delimiters for arguments to parameter padding flags had to be the same for each pair, although a moment's thought will show it's obvious since that's the only way you can tell if the optional arguments are present. Consequently I got this wrong when I extended the delimiters to allow multibyte characters. This means the simple form ${(l.8.)foo} with no optional arguments is broken. The next form ${(l.8..X.)foo} is semi-broken, because I didn't alter the test to be multibyte. So all in all this wasn't very competent. Index: Doc/Zsh/expn.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v retrieving revision 1.73 diff -u -r1.73 expn.yo --- Doc/Zsh/expn.yo 1 Nov 2006 12:25:22 -0000 1.73 +++ Doc/Zsh/expn.yo 7 Nov 2006 22:39:37 -0000 @@ -899,11 +899,15 @@ ) item(tt(l:)var(expr)tt(::)var(string1)tt(::)var(string2)tt(:))( Pad the resulting words on the left. Each word will be truncated if -required and placed in a field var(expr) characters wide. The space -to the left will be filled with var(string1) (concatenated as often -as needed) or spaces if var(string1) is not given. If both -var(string1) and var(string2) are given, tt(string2) is inserted -once directly to the left of each word, truncated if necessary, before +required and placed in a field var(expr) characters wide. + +The arguments tt(:)var(string1)tt(:) and tt(:)var(string2)tt(:) are +optional; neither, the first, or both may be given. Note that the same +pairs of delimiters must be used for each of the three arguments. The +space to the left will be filled with var(string1) (concatenated as +often as needed) or spaces if var(string1) is not given. If both +var(string1) and var(string2) are given, tt(string2) is inserted once +directly to the left of each word, truncated if necessary, before var(string1) is used to produce any remaining padding. If the tt(MULTIBYTE) option is in effect, the flag tt(m) may also Index: Src/subst.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/subst.c,v retrieving revision 1.66 diff -u -r1.66 subst.c --- Src/subst.c 2 Nov 2006 18:43:20 -0000 1.66 +++ Src/subst.c 7 Nov 2006 22:39:39 -0000 @@ -1224,8 +1224,9 @@ /* * Get an integer argument; update *s to the end of the - * final delimiter. *delmatchp is set to 1 if we have matching - * delimiters and there was no error in the evaluation, else 0. + * final delimiter. *delmatchp is set to the length of the + * matched delimiter if we have matching, delimiters and there was no error in + * the evaluation, else 0. */ /**/ @@ -1255,7 +1256,7 @@ return -1; if (ret < 0) ret = -ret; - *delmatchp = 1; + *delmatchp = arglen; return ret < 0 ? -ret : ret; } @@ -1602,7 +1603,8 @@ for (s++; (c = *s) != ')' && c != Outpar; s++, tt = 0) { int arglen; /* length of modifier argument */ - int delmatch; /* integer delimiters matched OK */ + int dellen; /* length of matched delimiter, 0 if not */ + char *del0; /* pointer to initial delimiter */ switch (c) { case ')': @@ -1634,7 +1636,7 @@ break; case 'I': s++; - flnum = get_intarg(&s, &delmatch); + flnum = get_intarg(&s, &dellen); if (flnum < 0) goto flagerr; s--; @@ -1734,15 +1736,21 @@ /* fall through */ case 'r': s++; - num = get_intarg(&s, &delmatch); + /* delimiter position */ + del0 = s; + num = get_intarg(&s, &dellen); if (num < 0) goto flagerr; if (tt) prenum = num; else postnum = num; - if (!delmatch) + /* must have same delimiter if more arguments */ + if (!dellen || memcmp(del0, s, dellen)) { + /* decrement since loop will increment */ + s--; break; + } t = get_strarg(s, &arglen); if (!*t) goto flagerr; @@ -1755,7 +1763,9 @@ *t = sav; sav = *s; s = t + arglen; - if (UNTOK(*s) != UNTOK(sav)) { + /* again, continue only if another start delimiter */ + if (memcmp(del0, s, dellen)) { + /* decrement since loop will increment */ s--; break; } @@ -1769,6 +1779,7 @@ else UNTOK_AND_ESCAPE(postone, s + arglen) *t = sav; + /* -1 since loop will increment */ s = t + arglen - 1; break; @@ -3310,7 +3321,7 @@ { char *ptr1, *ptr2, *ptr3, *lptr, c, *test, *sep, *t, *tt, tc, *e; char *copy, *all, *tmp, sav, sav1, *ptr1end; - int gbal, wall, rec, al, nl, charlen, delmatch; + int gbal, wall, rec, al, nl, charlen, dellen; convchar_t del; test = NULL; @@ -3436,7 +3447,7 @@ break; case 'F': (*ptr)++; - rec = get_intarg(ptr, &delmatch); + rec = get_intarg(ptr, &dellen); break; default: *ptr = lptr; Index: Test/D04parameter.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/D04parameter.ztst,v retrieving revision 1.22 diff -u -r1.22 D04parameter.ztst --- Test/D04parameter.ztst 2 Nov 2006 18:43:20 -0000 1.22 +++ Test/D04parameter.ztst 7 Nov 2006 22:39:45 -0000 @@ -361,6 +361,11 @@ >val1 val2 >key1 key2 val1 val2 + word="obfuscatory" + print !${(l.16.)word}! +${(r.16.)word}+ +0:simple padding +>! obfuscatory! +obfuscatory + + foo=(resulting words uproariously padded) print ${(pl.10..\x22..X.)foo} 0:${(pl...)...} Index: Test/D07multibyte.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/D07multibyte.ztst,v retrieving revision 1.11 diff -u -r1.11 D07multibyte.ztst --- Test/D07multibyte.ztst 2 Nov 2006 18:43:20 -0000 1.11 +++ Test/D07multibyte.ztst 7 Nov 2006 22:39:45 -0000 @@ -306,8 +306,8 @@ # TODO: if we get paired multibyte bracket delimiters to work # (as Emacs does, the smug so-and-so), the following should change. foo=bar - print ${(r£5£¥X¥)foo} - print ${(l«10«»Y»£HI£)foo} + print ${(r£5££X£)foo} + print ${(l«10««Y««HI«)foo} 0:Delimiters in parameter flags >barXX >YYYYYHIbar -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/