Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: #c flag wrong behaviour
- X-seq: zsh-workers 24780
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh-workers <zsh-workers@xxxxxxxxxx>
- Subject: Re: #c flag wrong behaviour
- Date: Sun, 30 Mar 2008 22:10:05 +0100
- In-reply-to: <20080329161300.GA19193@okita>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20080329161300.GA19193@okita>
On Sat, 29 Mar 2008 17:18:24 +0100
Anthony Charles <antho.charles@xxxxxxxxx> 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@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author