From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20966 invoked from network); 8 Apr 2002 17:48:46 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 8 Apr 2002 17:48:46 -0000 Received: (qmail 23230 invoked by alias); 8 Apr 2002 17:48:38 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 16942 Received: (qmail 23216 invoked from network); 8 Apr 2002 17:48:37 -0000 To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: Re: Beginning of line matching In-reply-to: ""Bart Schaefer""'s message of "Tue, 26 Mar 2002 17:26:29 GMT." <1020326172630.ZM32331@candle.brasslantern.com> Date: Mon, 08 Apr 2002 18:48:08 +0100 Message-ID: <28554.1018288088@csr.com> From: Peter Stephenson "Bart Schaefer" wrote: > On Mar 26, 12:31pm, Ian Lynagh wrote: > } > } I would have expected ${FOO/(#s)/X} and ${${FOO/(#m)(#s)?/X$MATCH}:-X} > } to be equivalent, but it seems that only the second one has the desired > } effect when FOO is not empty. Is there a reason the first doesn't behave > } as I expected? > > AFAICT, it's because "start of string" is considered to begin with the > first real character, thus after the implicit intial empty substring. > > This should probably be considered a bug. > > Compare ${FOO/()/X}, and also ${FOO//()/X} ... It seems to be this simple to fix all these problems. I think the test for a non-zero-length match was to try and avoid possible problems caused by infinite loops, but I don't see anything that would cause infinite loops. The parameter tests still pass (other forms of pattern matching aren't affected). This could probably go in 4.0, I suppose. Index: Src/glob.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/glob.c,v retrieving revision 1.25 diff -u -r1.25 glob.c --- Src/glob.c 22 Feb 2002 17:28:06 -0000 1.25 +++ Src/glob.c 8 Apr 2002 17:38:39 -0000 @@ -2291,7 +2291,7 @@ for (; t < s + l; t++, patoffset++) { /* Find the longest match from this position. */ set_pat_start(p, t-s); - if (pattry(p, t) && patinput > t) { + if (pattry(p, t)) { char *mpos = patinput; if (!(fl & SUB_LONG) && !(p->flags & PAT_PURES)) { char *ptr; @@ -2371,7 +2371,7 @@ if (t > s && t[-1] == Meta) t--; set_pat_start(p, t-s); - if (pattry(p, t) && patinput > t && !--n) { + if (pattry(p, t) && !--n) { /* Found the longest match */ char *mpos = patinput; if (!(fl & SUB_LONG) && !(p->flags & PAT_PURES)) { -- Peter Stephenson Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070 ********************************************************************** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. **********************************************************************