about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2004-10-22 15:36:35 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2004-10-22 15:36:35 +0000
commitfeca88ede6dec816878832f2129fe85b211770e4 (patch)
tree7679a3c1425af4829b539f58b99daadbdd6f5207
parent658f46a8094663e4a1d3dfbf37a951cbd9e1a345 (diff)
downloadzsh-feca88ede6dec816878832f2129fe85b211770e4.tar.gz
zsh-feca88ede6dec816878832f2129fe85b211770e4.tar.xz
zsh-feca88ede6dec816878832f2129fe85b211770e4.zip
20513: fix tests of zero-length patterns
trivial optimisation in jobs.c (unposted)
-rw-r--r--ChangeLog7
-rw-r--r--Src/jobs.c4
-rw-r--r--Src/pattern.c15
-rw-r--r--Test/D02glob.ztst4
4 files changed, 27 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 4328903c3..a29beb1f9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2004-10-22  Peter Stephenson  <pws@csr.com>
+
+	* 20513: Src/pattern.c, Test/D02glob.ztst: tests of zero length
+	patterns didn't work after 20500.
+
+	* unposted: Src/jobs.c: trivial optimisation.
+
 2004-10-20  Wayne Davison  <wayned@users.sourceforge.net>
 
 	* 20505: Src/utils.c, Src/builtin.c, Src/exec.c, Src/hist.c,
diff --git a/Src/jobs.c b/Src/jobs.c
index 9bb8bbbd7..ed97d2cef 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -565,9 +565,9 @@ printtime(struct timeval *real, child_times_t *ti, char *desc)
 #ifdef HAVE_GETRUSAGE
     user_time = ti->ru_utime.tv_sec + ti->ru_utime.tv_usec / 1000000.0;
     system_time = ti->ru_stime.tv_sec + ti->ru_stime.tv_usec / 1000000.0;
-    percent = 100.0 * (user_time + system_time)
-	/ (real->tv_sec + real->tv_usec / 1000000.0);
     total_time = user_time + system_time;
+    percent = 100.0 * total_time
+	/ (real->tv_sec + real->tv_usec / 1000000.0);
 #else
     set_clktck();
     user_time    = ti->ut / (double) clktck;
diff --git a/Src/pattern.c b/Src/pattern.c
index 04452187d..528c48d5e 100644
--- a/Src/pattern.c
+++ b/Src/pattern.c
@@ -399,7 +399,7 @@ patcompile(char *exp, int inflags, char **endexp)
 	patendstr++;
 	patendseglen--;
 	patendstrlen--;
-	remnulargs(exp);
+	remnulargs(patparse);
 	patglobflags = 0;
     }
     /*
@@ -419,10 +419,20 @@ patcompile(char *exp, int inflags, char **endexp)
 	    || (!(patglobflags & ~GF_IGNCASE) && (patflags & PAT_FILE))
 #endif
 	    )
+	{
+	    /*
+	     * Waah!  I wish I understood this.
+	     * Empty metafied strings have an initial Nularg.
+	     * This never corresponds to a real character in
+	     * a glob pattern or string, so skip it.
+	     */
+	    if (*exp == Nularg)
+		exp++;
 	    for (strp = exp; *strp &&
 		     (!(patflags & PAT_FILE) || *strp != '/') && !itok(*strp);
 		 strp++)
 		;
+	}
 	if (!strp || (*strp && *strp != '/')) {
 	    /* No, do normal compilation. */
 	    strp = NULL;
@@ -1010,6 +1020,9 @@ patcomppiece(int *flagp)
 
 	/* Get length of string without metafication. */
 	nmeta = 0;
+	/* inherited from domatch, but why, exactly? */
+	if (*str0 == Nularg)
+	    str0++;
 	for (ptr = str0; ptr < patparse; ptr++) {
 	    if (*ptr == Meta) {
 		nmeta++;
diff --git a/Test/D02glob.ztst b/Test/D02glob.ztst
index a500f443a..c7976225d 100644
--- a/Test/D02glob.ztst
+++ b/Test/D02glob.ztst
@@ -308,3 +308,7 @@
  print glob.tmp/**/*~*/dir3(/*|(#e))(/)
 0:Exclusions with complicated path specifications
 >glob.tmp/dir1 glob.tmp/dir2 glob.tmp/dir4
+
+ [[ "" = "" ]] && echo OK
+0:Empty strings
+>OK