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

Re: Recursive globbing



Bart Schaefer wrote:
> ... <general anathematic malaise> ...

(Moved to zsh-workers.)

Or how about this alternative?

Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.49
diff -u -r1.49 expn.yo
--- Doc/Zsh/expn.yo	6 Apr 2004 09:26:50 -0000	1.49
+++ Doc/Zsh/expn.yo	14 May 2004 17:07:25 -0000
@@ -1593,6 +1593,11 @@
 otherwise identical.  Neither of these can be combined with other forms of
 globbing within the same path segment; in that case, the `tt(*)'
 operators revert to their usual effect.
+
+If the option TT(EXTENDED_GLOB) is set, then tt(*#) is treated as a
+shorthand for tt(**/*), and tt(**#) and tt(*##) are treated as shorthands
+for tt(***/*).  Hence tt(*#.c) matches any file ending in tt(.c) in or
+below the current directory, not following symbolic links.
 subsect(Glob Qualifiers)
 cindex(globbing, qualifiers)
 cindex(qualifiers, globbing)
Index: Src/glob.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/glob.c,v
retrieving revision 1.33
diff -u -r1.33 glob.c
--- Src/glob.c	6 Apr 2004 17:45:47 -0000	1.33
+++ Src/glob.c	14 May 2004 17:07:29 -0000
@@ -638,15 +638,55 @@
     Complist l1;
     char *str;
     int compflags = gf_noglobdots ? (PAT_FILE|PAT_NOGLD) : PAT_FILE;
+    int recurse = 0, follow = 0;
 
-    if (instr[0] == Star && instr[1] == Star &&
-        (instr[2] == '/' || (instr[2] == Star && instr[3] == '/'))) {
-	/* Match any number of directories. */
-	int follow;
+    if (instr[0] == Star)
+    {
+	if (instr[1] == Star)
+	{
+	    if (instr[2] == '/')
+	    {
+		instr += 3;
+		recurse = 1;
+	    }
+	    else if (instr[2] == Star && instr[3] == '/')
+	    {
+		/* with three stars, follow symbolic links */
+		instr += 4;
+		follow = 1;
+		recurse = 1;
+	    }
+	    else if (isset(EXTENDEDGLOB) && instr[2] == Pound)
+	    {
+		/* with two stars and a pound, treat as ***[/]* */
+		instr += 2;
+		*instr = Star;
+		recurse = 1;
+	    }
+	}
+	else if (isset(EXTENDEDGLOB) && instr[1] == Pound)
+	{
+	    if (instr[2] == Pound)
+	    {
+		/*
+		 * with a star and two pounds, treat as ***[/]*
+		 * (same as **#).
+		 */
+		instr += 2;
+		follow = 1;
+	    }
+	    else
+	    {
+		/* with a star and a pound, treat as **[/]* */
+		instr++;
+	    }
+	    *instr = Star;
+	    recurse = 1;
+	}
+    }
 
-	/* with three stars, follow symbolic links */
-	follow = (instr[2] == Star);
-	instr += (3 + follow);
+    if (recurse) {
+	/* Match any number of directories. */
 
 	/* Now get the next path component if there is one. */
 	l1 = (Complist) zhalloc(sizeof *l1);

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



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