about summary refs log tree commit diff
path: root/Src/parse.c
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>2000-03-11 00:11:02 +0000
committerTanaka Akira <akr@users.sourceforge.net>2000-03-11 00:11:02 +0000
commitd1688ca54177882828624cb5abcb3e2d727ad39f (patch)
tree487a19f44b44b278bbea83c7e62aabc15d80924d /Src/parse.c
parentc2943574773ad1584f1d868a1a2d38266af7dde4 (diff)
downloadzsh-d1688ca54177882828624cb5abcb3e2d727ad39f.tar.gz
zsh-d1688ca54177882828624cb5abcb3e2d727ad39f.tar.xz
zsh-d1688ca54177882828624cb5abcb3e2d727ad39f.zip
zsh-workers/10059
Diffstat (limited to 'Src/parse.c')
-rw-r--r--Src/parse.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/Src/parse.c b/Src/parse.c
index d4bde90e9..73ed40e2f 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -233,6 +233,18 @@ Eccstr ecstrs;
 /**/
 int ecsoffs, ecssub, ecnfunc;
 
+/* Adjust pointers in here-doc structs. */
+
+static void
+ecadjusthere(int p, int d)
+{
+    struct heredocs *h;
+
+    for (h = hdocs; h; h = h->next)
+	if (h->pc >= p)
+	    h->pc += d;
+}
+
 /* Insert n free code-slots at position p. */
 
 static void
@@ -250,6 +262,7 @@ ecispace(int p, int n)
     if ((m = ecused - p) > 0)
 	memmove(ecbuf + p + n, ecbuf + p, m * sizeof(wordcode));
     ecused += n;
+    ecadjusthere(p, n);
 }
 
 /* Add one wordcode. */
@@ -278,6 +291,7 @@ ecdel(int p)
     if (n > 0)
 	memmove(ecbuf + p, ecbuf + p + 1, n * sizeof(wordcode));
     ecused--;
+    ecadjusthere(p, -1);
 }
 
 /* Build the wordcode for a string. */
@@ -682,7 +696,6 @@ par_pline(int *complex)
 	for (r = p + 1; wc_code(ecbuf[r]) == WC_REDIR; r += 3);
 
 	ecispace(r, 3);
-	p += 3;
 	ecbuf[r] = WCB_REDIR(MERGEOUT);
 	ecbuf[r + 1] = 2;
 	ecbuf[r + 2] = ecstrcode("1");
@@ -690,6 +703,8 @@ par_pline(int *complex)
 	*complex = 1;
 	cmdpush(CS_ERRPIPE);
 	yylex();
+	while (tok == SEPER)
+	    yylex();
 	ecbuf[p] = WCB_PIPE(WC_PIPE_MID, (line >= 0 ? line + 1 : 0));
 	ecispace(p + 1, 1);
 	ecbuf[p + 1] = ecused - 1 - p;
@@ -1577,12 +1592,6 @@ par_redir(int *rp)
 	/* <<[-] name */
 	struct heredocs **hd;
 
-	for (hd = &hdocs; *hd; hd = &(*hd)->next);
-	*hd = zalloc(sizeof(struct heredocs));
-	(*hd)->next = NULL;
-	(*hd)->pc = ecbuf + r;
-	(*hd)->str = tokstr;
-
 	/* If we ever need more than three codes (or less), we have to change
 	 * the factors in par_cmd() and par_simple(), too. */
 	ecispace(r, 3);
@@ -1590,6 +1599,13 @@ par_redir(int *rp)
 	ecbuf[r] = WCB_REDIR(type);
 	ecbuf[r + 1] = fd1;
 
+	for (hd = &hdocs; *hd; hd = &(*hd)->next);
+	*hd = zalloc(sizeof(struct heredocs));
+	(*hd)->next = NULL;
+	(*hd)->type = type;
+	(*hd)->pc = r;
+	(*hd)->str = tokstr;
+
 	yylex();
 	return;
     }
@@ -1626,10 +1642,10 @@ par_redir(int *rp)
 
 /**/
 void
-setheredoc(Wordcode pc, int type, char *str)
+setheredoc(int pc, int type, char *str)
 {
-    pc[0] = WCB_REDIR(type);
-    pc[2] = ecstrcode(str);
+    ecbuf[pc] = WCB_REDIR(type);
+    ecbuf[pc + 2] = ecstrcode(str);
 }
 
 /*