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

PATCH: piped loops (was: Re: `make' completion in zsh-3.1.9)



Bart Schaefer wrote:

> ...
> 
> Why does it work when the while-construct is wrapped with { } ?
> 
> Why can't we "pretend" -- in the wordcode compiler, if necessary -- that
> every complex command is wrapped with { } ?

I thought something similar yesterday but then didn't have the time to 
look.

Now I had.

The first thing I noticed was that while

  % { while read -e; do :; done < foo } | less

worked, this:

  % { while read -e; do :; done } < foo | less

didn't.

>From there it was simple.  execpline2() looks at the code for the
command for exactly the case that there is a current-shell-thing in a
pipeline.  It then fork()s directly (so that it doesn't have to be
done in execcmd()).

BUT.  With

  % { while read -e; do :; done } < foo | less

or

  % while read -e; do :; done < foo | less

the command (the `while') is preceded by the codes for the
redirections and execpline2() didn't skip them when looking for the
command code.

So we only have to make it do that.


I feel much better now.


Bye
 Sven

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.24
diff -u -r1.24 exec.c
--- Src/exec.c	2001/01/16 13:44:20	1.24
+++ Src/exec.c	2001/03/22 12:10:41
@@ -1189,11 +1189,11 @@
 	execcmd(state, input, output, how, last1 ? 1 : 2);
     else {
 	int old_list_pipe = list_pipe;
-	Wordcode next = state->pc + (*state->pc);
+	Wordcode next = state->pc + (*state->pc), pc;
 	wordcode code;
 
 	state->pc++;
-	code = *state->pc;
+	for (pc = state->pc; wc_code(code = *pc) == WC_REDIR; pc += 3);
 
 	mpipe(pipes);
 

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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