From 4ed5e37d4b6569b16758ae736084d96f6f19a0ac Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Tue, 1 May 2001 01:49:50 +0000 Subject: Another hush update from Larry: Minor improvements. Something is still broken with running scripts via "hush filename". All the following are now handled acceptably (matches ash, not bash). if true; then echo foo1; fi if true; then echo foo2; fi if true; false; then echo bar; else echo foo3; fi if true || false; then echo foo4; fi - Larry --- hush.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'hush.c') diff --git a/hush.c b/hush.c index 4753bd7ab..8ef1e2731 100644 --- a/hush.c +++ b/hush.c @@ -102,7 +102,7 @@ #include /* #include */ -#define DEBUG_SHELL +/* #define DEBUG_SHELL */ #ifdef BB_VER #include "busybox.h" @@ -814,7 +814,12 @@ static int file_get(struct in_str *i) if (i->__promptme && interactive && i->file == stdin) { get_user_input(i); i->promptmode=2; + } else { + static char buffer; + buffer = fgetc(i->file); + i->p = &buffer; } + i->__promptme = 0; if (i->p && *i->p) { @@ -1152,15 +1157,17 @@ static int run_list_real(struct pipe *pi) { int rcode=0; int if_code=0, next_if_code=0; /* need double-buffer to handle elif */ - reserved_style rmode=RES_NONE; + reserved_style rmode, skip_more_in_this_rmode=RES_XXXX; for (;pi;pi=pi->next) { rmode = pi->r_mode; - debug_printf("rmode=%d if_code=%d next_if_code=%d\n", rmode, if_code, next_if_code); + debug_printf("rmode=%d if_code=%d next_if_code=%d skip_more=%d\n", rmode, if_code, next_if_code, skip_more_in_this_rmode); + if (rmode == skip_more_in_this_rmode) continue; + skip_more_in_this_rmode = RES_XXXX; if (rmode == RES_THEN || rmode == RES_ELSE) if_code = next_if_code; if (rmode == RES_THEN && if_code) continue; if (rmode == RES_ELSE && !if_code) continue; if (rmode == RES_ELIF && !if_code) continue; - if (pi->num_progs == 0) break; + if (pi->num_progs == 0) continue; rcode = run_pipe_real(pi); if (rcode!=-1) { /* We only ran a builtin: rcode was set by the return value @@ -1194,7 +1201,8 @@ static int run_list_real(struct pipe *pi) next_if_code=rcode; /* can be overwritten a number of times */ if ( (rcode==EXIT_SUCCESS && pi->followup==PIPE_OR) || (rcode!=EXIT_SUCCESS && pi->followup==PIPE_AND) ) - return rcode; /* XXX broken if list is part of if/then/else */ + skip_more_in_this_rmode=rmode; + /* return rcode; */ /* XXX broken if list is part of if/then/else */ } return rcode; } -- cgit v1.2.3