diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-01-18 17:55:04 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-01-18 17:55:04 +0100 |
commit | a14631917363aa96943e46090773c15ac1b0f995 (patch) | |
tree | 62f04b0019996982ab45c63106cf2e185baa82ee | |
parent | 98c46d10ee81f206f274da312086a3f0533582af (diff) | |
download | busybox-w32-a14631917363aa96943e46090773c15ac1b0f995.tar.gz busybox-w32-a14631917363aa96943e46090773c15ac1b0f995.tar.bz2 busybox-w32-a14631917363aa96943e46090773c15ac1b0f995.zip |
hush: improve prompt in nested {}s, remove unused in_str->promptme member
function old new delta
setup_string_in_str 29 38 +9
parse_and_run_stream 79 88 +9
setup_file_in_str 32 39 +7
parse_stream 2430 2422 -8
file_get 262 235 -27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/2 up/down: 25/-35) Total: -10 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/hush.c | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/shell/hush.c b/shell/hush.c index 3581ba119..1709fd9d1 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -445,7 +445,6 @@ typedef struct in_str { | |||
445 | char eof_flag; /* meaningless if ->p == NULL */ | 445 | char eof_flag; /* meaningless if ->p == NULL */ |
446 | char peek_buf[2]; | 446 | char peek_buf[2]; |
447 | #if ENABLE_HUSH_INTERACTIVE | 447 | #if ENABLE_HUSH_INTERACTIVE |
448 | smallint promptme; | ||
449 | smallint promptmode; /* 0: PS1, 1: PS2 */ | 448 | smallint promptmode; /* 0: PS1, 1: PS2 */ |
450 | #endif | 449 | #endif |
451 | FILE *file; | 450 | FILE *file; |
@@ -1946,22 +1945,17 @@ static int FAST_FUNC file_get(struct in_str *i) | |||
1946 | /* need to double check i->file because we might be doing something | 1945 | /* need to double check i->file because we might be doing something |
1947 | * more complicated by now, like sourcing or substituting. */ | 1946 | * more complicated by now, like sourcing or substituting. */ |
1948 | #if ENABLE_HUSH_INTERACTIVE | 1947 | #if ENABLE_HUSH_INTERACTIVE |
1949 | if (G_interactive_fd && i->promptme && i->file == stdin) { | 1948 | if (G_interactive_fd && i->file == stdin) { |
1950 | do { | 1949 | do { |
1951 | get_user_input(i); | 1950 | get_user_input(i); |
1952 | } while (!*i->p); /* need non-empty line */ | 1951 | } while (!*i->p); /* need non-empty line */ |
1953 | i->promptmode = 1; /* PS2 */ | 1952 | i->promptmode = 1; /* PS2 */ |
1954 | i->promptme = 0; | ||
1955 | goto take_cached; | 1953 | goto take_cached; |
1956 | } | 1954 | } |
1957 | #endif | 1955 | #endif |
1958 | do ch = fgetc(i->file); while (ch == '\0'); | 1956 | do ch = fgetc(i->file); while (ch == '\0'); |
1959 | } | 1957 | } |
1960 | debug_printf("file_get: got '%c' %d\n", ch, ch); | 1958 | debug_printf("file_get: got '%c' %d\n", ch, ch); |
1961 | #if ENABLE_HUSH_INTERACTIVE | ||
1962 | if (ch == '\n') | ||
1963 | i->promptme = 1; | ||
1964 | #endif | ||
1965 | return ch; | 1959 | return ch; |
1966 | } | 1960 | } |
1967 | 1961 | ||
@@ -1988,26 +1982,22 @@ static int FAST_FUNC file_peek(struct in_str *i) | |||
1988 | 1982 | ||
1989 | static void setup_file_in_str(struct in_str *i, FILE *f) | 1983 | static void setup_file_in_str(struct in_str *i, FILE *f) |
1990 | { | 1984 | { |
1985 | memset(i, 0, sizeof(*i)); | ||
1991 | i->peek = file_peek; | 1986 | i->peek = file_peek; |
1992 | i->get = file_get; | 1987 | i->get = file_get; |
1993 | #if ENABLE_HUSH_INTERACTIVE | 1988 | /* i->promptmode = 0; - PS1 (memset did it) */ |
1994 | i->promptme = 1; | ||
1995 | i->promptmode = 0; /* PS1 */ | ||
1996 | #endif | ||
1997 | i->file = f; | 1989 | i->file = f; |
1998 | i->p = NULL; | 1990 | /* i->p = NULL; */ |
1999 | } | 1991 | } |
2000 | 1992 | ||
2001 | static void setup_string_in_str(struct in_str *i, const char *s) | 1993 | static void setup_string_in_str(struct in_str *i, const char *s) |
2002 | { | 1994 | { |
1995 | memset(i, 0, sizeof(*i)); | ||
2003 | i->peek = static_peek; | 1996 | i->peek = static_peek; |
2004 | i->get = static_get; | 1997 | i->get = static_get; |
2005 | #if ENABLE_HUSH_INTERACTIVE | 1998 | /* i->promptmode = 0; - PS1 (memset did it) */ |
2006 | i->promptme = 1; | ||
2007 | i->promptmode = 0; /* PS1 */ | ||
2008 | #endif | ||
2009 | i->p = s; | 1999 | i->p = s; |
2010 | i->eof_flag = 0; | 2000 | /* i->eof_flag = 0; */ |
2011 | } | 2001 | } |
2012 | 2002 | ||
2013 | 2003 | ||
@@ -4031,9 +4021,6 @@ static struct pipe *parse_stream(char **pstring, | |||
4031 | 4021 | ||
4032 | reset: /* we come back here only on syntax errors in interactive shell */ | 4022 | reset: /* we come back here only on syntax errors in interactive shell */ |
4033 | 4023 | ||
4034 | #if ENABLE_HUSH_INTERACTIVE | ||
4035 | input->promptmode = 0; /* PS1 */ | ||
4036 | #endif | ||
4037 | if (MAYBE_ASSIGNMENT != 0) | 4024 | if (MAYBE_ASSIGNMENT != 0) |
4038 | dest.o_assignment = MAYBE_ASSIGNMENT; | 4025 | dest.o_assignment = MAYBE_ASSIGNMENT; |
4039 | initialize_context(&ctx); | 4026 | initialize_context(&ctx); |
@@ -4539,7 +4526,6 @@ static struct pipe *parse_stream(char **pstring, | |||
4539 | } | 4526 | } |
4540 | /* Discard cached input, force prompt */ | 4527 | /* Discard cached input, force prompt */ |
4541 | input->p = NULL; | 4528 | input->p = NULL; |
4542 | IF_HUSH_INTERACTIVE(input->promptme = 1;) | ||
4543 | goto reset; | 4529 | goto reset; |
4544 | } | 4530 | } |
4545 | } | 4531 | } |
@@ -5539,6 +5525,10 @@ static void parse_and_run_stream(struct in_str *inp, int end_trigger) | |||
5539 | while (1) { | 5525 | while (1) { |
5540 | struct pipe *pipe_list; | 5526 | struct pipe *pipe_list; |
5541 | 5527 | ||
5528 | #if ENABLE_HUSH_INTERACTIVE | ||
5529 | if (end_trigger == ';') | ||
5530 | inp->promptmode = 0; /* PS1 */ | ||
5531 | #endif | ||
5542 | pipe_list = parse_stream(NULL, inp, end_trigger); | 5532 | pipe_list = parse_stream(NULL, inp, end_trigger); |
5543 | if (!pipe_list) { /* EOF */ | 5533 | if (!pipe_list) { /* EOF */ |
5544 | if (empty) | 5534 | if (empty) |