zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers <zsh-workers@sunsite.dk>
Subject: Re: #c flag wrong behaviour
Date: Sun, 30 Mar 2008 22:10:05 +0100	[thread overview]
Message-ID: <20080330221005.6d5551b3@pws-pc> (raw)
In-Reply-To: <20080329161300.GA19193@okita>

On Sat, 29 Mar 2008 17:18:24 +0100
Anthony Charles <antho.charles@gmail.com> wrote:
> I think there is a problem with the new #c flag:
> 
> zsh -f
> Saito% setopt extendedglob
> Saito% touch test.{zsh,ksh,bash}
> Saito% print *.?(#c1)sh
> test.ksh test.zsh
> Saito% print *.?(#c2)sh
> test.bash
> Saito% print *.?(#c1,2)sh 
> test.bash
> Saito% print *.?(#c1,)sh    
> zsh: no matches found: *.?(#c1,)sh
> Saito% print *.?(#c1,)
> test.bash test.ksh test.zsh
> Saito%
> 
> It seems that #c flag is too greedy. Am I wrong?

You're right:  I missed out a save/restore of the test string because I
didn't have the right tests.  The effect was that although #c correctly
tried to match greedily first, it didn't backtrack along the test string
on a failure.

Index: Misc/globtests
===================================================================
RCS file: /cvsroot/zsh/zsh/Misc/globtests,v
retrieving revision 1.6
diff -u -r1.6 globtests
--- Misc/globtests	27 Jul 2007 21:51:33 -0000	1.6
+++ Misc/globtests	30 Mar 2008 22:03:07 -0000
@@ -192,5 +192,20 @@
 t froofroo         (fro(#c2))(#c2)
 f froofroofroo     (fro(#c2))(#c2)
 f froofro          (fro(#c2))(#c2)
+t ax               ?(#c1,2)x
+t ax               ?(#c1,)x
+t ax               ?(#c0,1)x
+f ax               ?(#c0,0)x
+f ax               ?(#c2,)x
+t aa               a(#c1,2)a
+t aa               a(#c1,)a
+t aa               a(#c0,1)a
+f aa               a(#c0,0)a
+f aa               a(#c2,)a
+t test.zsh         *.?(#c1)sh
+t test.bash        *.?(#c2)sh
+t test.bash        *.?(#c1,2)sh
+t test.bash        *.?(#c1,)sh
+t test.zsh         *.?(#c1,)sh
 EOT
 print "$failed tests failed."
Index: Src/pattern.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/pattern.c,v
retrieving revision 1.42
diff -u -r1.42 pattern.c
--- Src/pattern.c	25 Mar 2008 17:47:11 -0000	1.42
+++ Src/pattern.c	30 Mar 2008 22:03:08 -0000
@@ -2969,9 +2969,11 @@
 		scan[P_CT_PTR].p = (unsigned char *)patinput;
 
 		if (max < 0 || cur < max) {
+		    char *patinput_thistime = patinput;
 		    scan[P_CT_CURRENT].l = cur + 1;
 		    if (patmatch(scan + P_CT_OPERAND))
 			return 1;
+		    patinput = patinput_thistime;
 		}
 		if (cur < min)
 		    return 0;
Index: Test/D02glob.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D02glob.ztst,v
retrieving revision 1.13
diff -u -r1.13 D02glob.ztst
--- Test/D02glob.ztst	27 Jul 2007 21:51:33 -0000	1.13
+++ Test/D02glob.ztst	30 Mar 2008 22:03:12 -0000
@@ -187,6 +187,21 @@
 >0:  [[ froofroo = (fro(#c2))(#c2) ]]
 >1:  [[ froofroofroo = (fro(#c2))(#c2) ]]
 >1:  [[ froofro = (fro(#c2))(#c2) ]]
+>0:  [[ ax = ?(#c1,2)x ]]
+>0:  [[ ax = ?(#c1,)x ]]
+>0:  [[ ax = ?(#c0,1)x ]]
+>1:  [[ ax = ?(#c0,0)x ]]
+>1:  [[ ax = ?(#c2,)x ]]
+>0:  [[ aa = a(#c1,2)a ]]
+>0:  [[ aa = a(#c1,)a ]]
+>0:  [[ aa = a(#c0,1)a ]]
+>1:  [[ aa = a(#c0,0)a ]]
+>1:  [[ aa = a(#c2,)a ]]
+>0:  [[ test.zsh = *.?(#c1)sh ]]
+>0:  [[ test.bash = *.?(#c2)sh ]]
+>0:  [[ test.bash = *.?(#c1,2)sh ]]
+>0:  [[ test.bash = *.?(#c1,)sh ]]
+>0:  [[ test.zsh = *.?(#c1,)sh ]]
 >0 tests failed.
 
   globtest globtests.ksh


-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


      parent reply	other threads:[~2008-03-30 22:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-29 16:18 Anthony Charles
2008-03-29 17:50 ` Bart Schaefer
2008-03-30 21:10 ` Peter Stephenson [this message]

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=20080330221005.6d5551b3@pws-pc \
    --to=p.w.stephenson@ntlworld.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).