hush: stop generating extra empty pipes in parse stage.

This commit is contained in:
Denis Vlasenko 2007-05-05 15:11:40 +00:00
parent a6c467f6d1
commit dd4cb2b31e

View File

@ -2685,8 +2685,8 @@ static int done_command(struct p_context *ctx)
&& child->argv == NULL && child->argv == NULL
&& child->redirects == NULL && child->redirects == NULL
) { ) {
debug_printf_parse("done_command: skipping null command\n"); debug_printf_parse("done_command: skipping null cmd, num_progs=%d\n", pi->num_progs);
return 0; return pi->num_progs;
} }
pi->num_progs++; pi->num_progs++;
debug_printf_parse("done_command: ++num_progs=%d\n", pi->num_progs); debug_printf_parse("done_command: ++num_progs=%d\n", pi->num_progs);
@ -2712,26 +2712,28 @@ static int done_command(struct p_context *ctx)
ctx->child = child; ctx->child = child;
/* but ctx->pipe and ctx->list_head remain unchanged */ /* but ctx->pipe and ctx->list_head remain unchanged */
return 0; return pi->num_progs; /* used only for 0/nonzero check */
} }
static int done_pipe(struct p_context *ctx, pipe_style type) static int done_pipe(struct p_context *ctx, pipe_style type)
{ {
struct pipe *new_p; struct pipe *new_p;
int not_null;
debug_printf_parse("done_pipe entered, followup %d\n", type); debug_printf_parse("done_pipe entered, followup %d\n", type);
done_command(ctx); /* implicit closure of previous command */ not_null = done_command(ctx); /* implicit closure of previous command */
ctx->pipe->followup = type; ctx->pipe->followup = type;
ctx->pipe->r_mode = ctx->res_w; ctx->pipe->r_mode = ctx->res_w;
new_p = new_pipe(); /* Without this check, even just <enter> on command line generates
ctx->pipe->next = new_p; * tree of three NOPs (!). Which is harmless but annoying.
ctx->pipe = new_p; * IOW: it is safe to do it unconditionally. */
ctx->child = NULL; if (not_null) {
// TODO: even just <enter> on command line basically generates new_p = new_pipe();
// tree of three NOPs (!). ctx->pipe->next = new_p;
// Can we detect that previous done_command have seen "skipping null command" ctx->pipe = new_p;
// condition and NOT create new pipe here? ctx->child = NULL;
done_command(ctx); /* set up new pipe to accept commands */ done_command(ctx); /* set up new pipe to accept commands */
}
debug_printf_parse("done_pipe return 0\n"); debug_printf_parse("done_pipe return 0\n");
return 0; return 0;
} }