zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Re: Beginning of line matching
       [not found] <1020326172630.ZM32331@candle.brasslantern.com>
@ 2002-04-08 17:48 ` Peter Stephenson
  0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2002-04-08 17:48 UTC (permalink / raw)
  To: Zsh hackers list

"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 <pws@csr.com>                  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.
**********************************************************************


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-04-08 17:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1020326172630.ZM32331@candle.brasslantern.com>
2002-04-08 17:48 ` PATCH: Re: Beginning of line matching Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).