zsh-workers
 help / color / mirror / code / Atom feed
* #c flag wrong behaviour
@ 2008-03-29 16:18 Anthony Charles
  2008-03-29 17:50 ` Bart Schaefer
  2008-03-30 21:10 ` Peter Stephenson
  0 siblings, 2 replies; 3+ messages in thread
From: Anthony Charles @ 2008-03-29 16:18 UTC (permalink / raw)
  To: zsh-workers

Hi,

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?

-- 
Anthony CHARLES


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: #c flag wrong behaviour
  2008-03-29 16:18 #c flag wrong behaviour Anthony Charles
@ 2008-03-29 17:50 ` Bart Schaefer
  2008-03-30 21:10 ` Peter Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2008-03-29 17:50 UTC (permalink / raw)
  To: zsh-workers

On Mar 29,  5:18pm, Anthony Charles wrote:
}
} 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?

Those results do appear incorrect to me.  Unfortunately I can't tell if
the problem is in the compilation of the pattern, or the execution.  I
suspect the compilation because it doesn't parallel ## in the way I'd
expect, but I'm not very familiar with that part of the code.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: #c flag wrong behaviour
  2008-03-29 16:18 #c flag wrong behaviour Anthony Charles
  2008-03-29 17:50 ` Bart Schaefer
@ 2008-03-30 21:10 ` Peter Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2008-03-30 21:10 UTC (permalink / raw)
  To: zsh-workers

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/


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-03-30 22:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-29 16:18 #c flag wrong behaviour Anthony Charles
2008-03-29 17:50 ` Bart Schaefer
2008-03-30 21:10 ` 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).