zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: PATCH: Re: Beginning of line matching
Date: Mon, 08 Apr 2002 18:48:08 +0100	[thread overview]
Message-ID: <28554.1018288088@csr.com> (raw)
In-Reply-To: ""Bart Schaefer""'s message of "Tue, 26 Mar 2002 17:26:29 GMT." <1020326172630.ZM32331@candle.brasslantern.com>

"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.
**********************************************************************


           reply	other threads:[~2002-04-08 17:48 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <1020326172630.ZM32331@candle.brasslantern.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=28554.1018288088@csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).