[U-Boot] [PATCH 1/2] hush: Treat trailing || and && as incomplete statements
Joe Hershberger
joe.hershberger at ni.com
Thu Nov 8 21:15:55 CET 2012
A || or && at the end of a command should behave just like an if
statment that is not complete.
Signed-off-by: Joe Hershberger <joe.hershberger at ni.com>
---
common/hush.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/common/hush.c b/common/hush.c
index 4c84c2f..43edcfa 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -214,6 +214,7 @@ struct p_context {
int old_flag; /* for figuring out valid reserved words */
struct p_context *stack;
int type; /* define type of parser : ";$" common or special symbol */
+ pipe_style last_followup; /* PIPE_BG, PIPE_SEQ, PIPE_OR, PIPE_AND */
/* How about quoting status? */
};
@@ -2534,7 +2535,7 @@ static int done_command(struct p_context *ctx)
) {
#endif
debug_printf("done_command: skipping null command\n");
- return 0;
+ return 1;
} else if (prog) {
pi->num_progs++;
debug_printf("done_command: num_progs incremented to %d\n",pi->num_progs);
@@ -2567,9 +2568,15 @@ static int done_command(struct p_context *ctx)
static int done_pipe(struct p_context *ctx, pipe_style type)
{
struct pipe *new_p;
- done_command(ctx); /* implicit closure of previous command */
+ int ret;
+
+ ret = done_command(ctx); /* implicit closure of previous command */
+ /* The current command is null so don't allocate a new one */
+ if (ret && type == PIPE_SEQ)
+ return ret;
debug_printf("done_pipe, type %d\n", type);
ctx->pipe->followup = type;
+ ctx->last_followup = type;
ctx->pipe->r_mode = ctx->w;
new_p=new_pipe();
ctx->pipe->next = new_p;
@@ -2962,7 +2969,10 @@ int parse_stream(o_string *dest, struct p_context *ctx,
if (end_trigger != '\0' && ch=='\n')
done_pipe(ctx,PIPE_SEQ);
}
- if (ch == end_trigger && !dest->quote && ctx->w==RES_NONE) {
+ if (ch == end_trigger && !dest->quote &&
+ ctx->w == RES_NONE &&
+ ctx->last_followup != PIPE_AND &&
+ ctx->last_followup != PIPE_OR) {
debug_printf("leaving parse_stream (triggered)\n");
return 0;
}
--
1.7.11.5
More information about the U-Boot
mailing list