about summary refs log tree commit diff
path: root/Src/pattern.c
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>2000-02-23 15:18:43 +0000
committerTanaka Akira <akr@users.sourceforge.net>2000-02-23 15:18:43 +0000
commit1054071bd60937ae8a9fbc16c1407211c6198a55 (patch)
treed91747424173fe809ec204864df49009874b6282 /Src/pattern.c
parent2b37049c221501c6ae77e0308634aebcdb10060d (diff)
downloadzsh-1054071bd60937ae8a9fbc16c1407211c6198a55.tar.gz
zsh-1054071bd60937ae8a9fbc16c1407211c6198a55.tar.xz
zsh-1054071bd60937ae8a9fbc16c1407211c6198a55.zip
zsh-workers/9839
Diffstat (limited to 'Src/pattern.c')
-rw-r--r--Src/pattern.c88
1 files changed, 34 insertions, 54 deletions
diff --git a/Src/pattern.c b/Src/pattern.c
index 1c4abbfb4..4cfdc1336 100644
--- a/Src/pattern.c
+++ b/Src/pattern.c
@@ -1357,9 +1357,7 @@ pattryrefs(Patprog prog, char *string, int *nump, int *begp, int *endp)
 		char *str;
 		int mlen = ztrsub(patinput, patinstart);
 
-		PERMALLOC {
-		    str = dupstrpfx(patinstart, patinput - patinstart);
-		} LASTALLOC;
+		str = ztrduppfx(patinstart, patinput - patinstart);
 		setsparam("MATCH", str);
 		setiparam("MBEGIN", (zlong)(patoffset + !isset(KSHARRAYS)));
 		setiparam("MEND",
@@ -1406,42 +1404,40 @@ pattryrefs(Patprog prog, char *string, int *nump, int *begp, int *endp)
 		sp = patbeginp;
 		ep = patendp;
 
-		PERMALLOC {
-		    for (i = 0; i < prog->patnpar; i++) {
-			if (parsfound & (1 << i)) {
-			    matcharr[i] = dupstrpfx(*sp, *ep - *sp);
-			    /*
-			     * mbegin and mend give indexes into the string
-			     * in the standard notation, i.e. respecting
-			     * KSHARRAYS, and with the end index giving
-			     * the last character, not one beyond.
-			     * For example, foo=foo; [[ $foo = (f)oo ]] gives
-			     * (without KSHARRAYS) indexes 1 and 1, which
-			     * corresponds to indexing as ${foo[1,1]}.
-			     */
-			    sprintf(numbuf, "%ld",
-				    (long)(ztrsub(*sp, patinstart) + 
-					   patoffset +
-					   !isset(KSHARRAYS)));
-			    mbeginarr[i] = ztrdup(numbuf);
-			    sprintf(numbuf, "%ld",
-				    (long)(ztrsub(*ep, patinstart) + 
-					   patoffset +
-					   !isset(KSHARRAYS) - 1));
-			    mendarr[i] = ztrdup(numbuf);
-			} else {
-			    /* Pattern wasn't set: either it was in an
-			     * unmatched branch, or a hashed parenthesis
-			     * that didn't match at all.
-			     */
-			    matcharr[i] = ztrdup("");
-			    mbeginarr[i] = ztrdup("-1");
-			    mendarr[i] = ztrdup("-1");
-			}
-			sp++;
-			ep++;
+		for (i = 0; i < prog->patnpar; i++) {
+		    if (parsfound & (1 << i)) {
+			matcharr[i] = ztrduppfx(*sp, *ep - *sp);
+			/*
+			 * mbegin and mend give indexes into the string
+			 * in the standard notation, i.e. respecting
+			 * KSHARRAYS, and with the end index giving
+			 * the last character, not one beyond.
+			 * For example, foo=foo; [[ $foo = (f)oo ]] gives
+			 * (without KSHARRAYS) indexes 1 and 1, which
+			 * corresponds to indexing as ${foo[1,1]}.
+			 */
+			sprintf(numbuf, "%ld",
+				(long)(ztrsub(*sp, patinstart) + 
+				       patoffset +
+				       !isset(KSHARRAYS)));
+			mbeginarr[i] = ztrdup(numbuf);
+			sprintf(numbuf, "%ld",
+				(long)(ztrsub(*ep, patinstart) + 
+				       patoffset +
+				       !isset(KSHARRAYS) - 1));
+			mendarr[i] = ztrdup(numbuf);
+		    } else {
+			/* Pattern wasn't set: either it was in an
+			 * unmatched branch, or a hashed parenthesis
+			 * that didn't match at all.
+			 */
+			matcharr[i] = ztrdup("");
+			mbeginarr[i] = ztrdup("-1");
+			mendarr[i] = ztrdup("-1");
 		    }
-		} LASTALLOC;
+		    sp++;
+		    ep++;
+		}
 		setaparam("match", matcharr);
 		setaparam("mbegin", mbeginarr);
 		setaparam("mend", mendarr);
@@ -2245,22 +2241,6 @@ static int patrepeat(Upat p)
     return count;
 }
 
-/* Duplicate a patprog. */
-
-/**/
-Patprog
-duppatprog(Patprog prog)
-{
-    if (prog && prog != dummy_patprog1 && prog != dummy_patprog2) {
-	Patprog ret = (Patprog) alloc(prog->size);
-
-	memcpy(ret, prog, prog->size);
-
-	return ret;
-    }
-    return prog;
-}
-
 /* Free a patprog. */
 
 /**/