aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-01-18 17:55:04 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-01-18 17:55:04 +0100
commita14631917363aa96943e46090773c15ac1b0f995 (patch)
tree62f04b0019996982ab45c63106cf2e185baa82ee /shell
parent98c46d10ee81f206f274da312086a3f0533582af (diff)
downloadbusybox-a14631917363aa96943e46090773c15ac1b0f995.tar.gz
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>
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c32
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 {
char eof_flag; /* meaningless if ->p == NULL */
char peek_buf[2];
#if ENABLE_HUSH_INTERACTIVE
- smallint promptme;
smallint promptmode; /* 0: PS1, 1: PS2 */
#endif
FILE *file;
@@ -1946,22 +1945,17 @@ static int FAST_FUNC file_get(struct in_str *i)
/* need to double check i->file because we might be doing something
* more complicated by now, like sourcing or substituting. */
#if ENABLE_HUSH_INTERACTIVE
- if (G_interactive_fd && i->promptme && i->file == stdin) {
+ if (G_interactive_fd && i->file == stdin) {
do {
get_user_input(i);
} while (!*i->p); /* need non-empty line */
i->promptmode = 1; /* PS2 */
- i->promptme = 0;
goto take_cached;
}
#endif
do ch = fgetc(i->file); while (ch == '\0');
}
debug_printf("file_get: got '%c' %d\n", ch, ch);
-#if ENABLE_HUSH_INTERACTIVE
- if (ch == '\n')
- i->promptme = 1;
-#endif
return ch;
}
@@ -1988,26 +1982,22 @@ static int FAST_FUNC file_peek(struct in_str *i)
static void setup_file_in_str(struct in_str *i, FILE *f)
{
+ memset(i, 0, sizeof(*i));
i->peek = file_peek;
i->get = file_get;
-#if ENABLE_HUSH_INTERACTIVE
- i->promptme = 1;
- i->promptmode = 0; /* PS1 */
-#endif
+ /* i->promptmode = 0; - PS1 (memset did it) */
i->file = f;
- i->p = NULL;
+ /* i->p = NULL; */
}
static void setup_string_in_str(struct in_str *i, const char *s)
{
+ memset(i, 0, sizeof(*i));
i->peek = static_peek;
i->get = static_get;
-#if ENABLE_HUSH_INTERACTIVE
- i->promptme = 1;
- i->promptmode = 0; /* PS1 */
-#endif
+ /* i->promptmode = 0; - PS1 (memset did it) */
i->p = s;
- i->eof_flag = 0;
+ /* i->eof_flag = 0; */
}
@@ -4031,9 +4021,6 @@ static struct pipe *parse_stream(char **pstring,
reset: /* we come back here only on syntax errors in interactive shell */
-#if ENABLE_HUSH_INTERACTIVE
- input->promptmode = 0; /* PS1 */
-#endif
if (MAYBE_ASSIGNMENT != 0)
dest.o_assignment = MAYBE_ASSIGNMENT;
initialize_context(&ctx);
@@ -4539,7 +4526,6 @@ static struct pipe *parse_stream(char **pstring,
}
/* Discard cached input, force prompt */
input->p = NULL;
- IF_HUSH_INTERACTIVE(input->promptme = 1;)
goto reset;
}
}
@@ -5539,6 +5525,10 @@ static void parse_and_run_stream(struct in_str *inp, int end_trigger)
while (1) {
struct pipe *pipe_list;
+#if ENABLE_HUSH_INTERACTIVE
+ if (end_trigger == ';')
+ inp->promptmode = 0; /* PS1 */
+#endif
pipe_list = parse_stream(NULL, inp, end_trigger);
if (!pipe_list) { /* EOF */
if (empty)