Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: 3.1.6-pws-2: globbing documentation



"Bart Schaefer" wrote:
> } +As a shorthand, `tt(**/)' is equivalent to `tt((*/)#)'; note that this
> } +therefore matches files in the current directory as well as
> } +subdirectories.
> 
> Wait, we just said that (*/)# was not a legal pattern!  How can **/ be a
> shorthand for it?  What we really mean (now) is that ** is a _replacement_
> (or "alternative" or some such word) for (*/)#, right?

I'd forgotten that (<pat>/)# is a special case, dating all the way back to
pfalstad; it's handled in the globbing code, not the pattern matching code,
so it's not affected by the patches.  However, I noticed a bug: something
like (foo*/)# produces a null string alongside the correct set of matches.
This is because the test for an existing file adds a "." if the current
segment is empty.  That's fine if there is already a path, turning foo/
into foo/. for the test to bypass system foolishness, but if there's
nothing there already it shouldn't do that.  I hope.

--- Doc/Zsh/expn.yo.glob	Fri Sep  3 15:52:48 1999
+++ Doc/Zsh/expn.yo	Fri Sep  3 16:52:38 1999
@@ -1092,9 +1092,13 @@
 the `tt(LPAR())' is treated specially, as detailed below. The option
 tt(SH_GLOB) prevents bare parentheses from being used in this way, though
 the tt(KSH_GLOB) option is still available.
+
 Note that grouping cannot extend over multiple directories: it is an error
-to have a `tt(/)' within a group (this only applies for patterns which
-match filenames).
+to have a `tt(/)' within a group (this only applies for patterns used in
+filename generation).  There is one exception:  a group of the form
+tt(LPAR())var(pat)tt(/RPAR()#) appearing as a complete path segment can
+match a sequence of directories.  For example, tt(foo/(a*/)#bar) matches
+tt(foo/bar), tt(foo/any/bar), tt(foo/any/anyother/bar), and so on).
 )
 item(var(x)tt(|)var(y))(
 Matches either var(x) or var(y).
--- Src/glob.c.glob	Mon Aug 30 16:25:13 1999
+++ Src/glob.c	Fri Sep  3 16:48:15 1999
@@ -243,7 +243,11 @@
 	  "BUG: statfullpath(): pathname too long");
     strcpy(buf, pathbuf + pathbufcwd);
     strcpy(buf + pathpos - pathbufcwd, s);
-    if (!*s) {
+    if (!*s && *buf) {
+	/*
+	 * Don't add the '.' if the path so far is empty, since
+	 * then we get bogus empty strings inserted as files.
+	 */
 	buf[pathpos - pathbufcwd] = '.';
 	buf[pathpos - pathbufcwd + 1] = '\0';
 	l = 0;

-- 
Peter Stephenson <pws@xxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



Messages sorted by: Reverse Date, Date, Thread, Author