hush: improve prompt in nested {}s, remove unused in_str->promptme member
No binary (build failed)
—
(log yok)
| @@ -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) | |