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

PATCH: (#?) glob with empty path segment



This should fix the problem that things like /lib/(#l)l*/ didn't work.  It
was trying to match the empty path segment at the end by a pattern match.

--- Src/glob.c.cstr	Wed Mar 24 10:20:10 1999
+++ Src/glob.c	Tue Apr 13 14:06:14 1999
@@ -397,6 +397,7 @@
     int pbcwdsav = pathbufcwd;
     int errssofar = errsfound;
     struct dirsav ds;
+    char *str;
 
     ds.ino = ds.dev = 0;
     ds.dirname = NULL;
@@ -412,17 +413,18 @@
 	    scanner(q->next);
     }
     c = q->comp;
+    str = c->str;
     /* Now the actual matching for the current path section. */
-    if (!(c->next || c->left) && !haswilds(c->str)
+    if (!(c->next || c->left) && !haswilds(str)
 	&& (!((c->stat & (C_LCMATCHUC|C_IGNCASE)) || c->errsmax)
-	    || !strcmp(".", c->str) || !strcmp("..", c->str))) {
+	    || !*str || !strcmp(".", str) || !strcmp("..", str))) {
 	/*
 	 * We always need to match . and .. explicitly, even if we're
 	 * checking other strings for case-insensitive matches.
 	 *
 	 * It's a straight string to the end of the path section.
 	 */
-	int l = strlen(c->str);
+	int l = strlen(str);
 
 	if (l + !l + pathpos - pathbufcwd >= PATH_MAX) {
 	    int err;
@@ -442,14 +444,14 @@
 	    /* Not the last path section. Just add it to the path. */
 	    int oppos = pathpos;
 
-	    if (!errflag && !(q->closure && !strcmp(c->str, "."))) {
-		addpath(c->str);
+	    if (!errflag && !(q->closure && !strcmp(str, "."))) {
+		addpath(str);
 		if (!closure || statfullpath("", NULL, 1))
 		    scanner((q->closure) ? q : q->next);
 		pathbuf[pathpos = oppos] = '\0';
 	    }
 	} else
-	    insert(c->str, 0);
+	    insert(str, 0);
     } else {
 	/* Do pattern matching on current path section. */
 	char *fn = pathbuf[pathbufcwd] ? unmeta(pathbuf + pathbufcwd) : ".";

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       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