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>
This commit is contained in:
parent
98c46d10ee
commit
a146319173
32
shell/hush.c
32
shell/hush.c
@ -445,7 +445,6 @@ typedef struct in_str {
|
|||||||
char eof_flag; /* meaningless if ->p == NULL */
|
char eof_flag; /* meaningless if ->p == NULL */
|
||||||
char peek_buf[2];
|
char peek_buf[2];
|
||||||
#if ENABLE_HUSH_INTERACTIVE
|
#if ENABLE_HUSH_INTERACTIVE
|
||||||
smallint promptme;
|
|
||||||
smallint promptmode; /* 0: PS1, 1: PS2 */
|
smallint promptmode; /* 0: PS1, 1: PS2 */
|
||||||
#endif
|
#endif
|
||||||
FILE *file;
|
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
|
/* need to double check i->file because we might be doing something
|
||||||
* more complicated by now, like sourcing or substituting. */
|
* more complicated by now, like sourcing or substituting. */
|
||||||
#if ENABLE_HUSH_INTERACTIVE
|
#if ENABLE_HUSH_INTERACTIVE
|
||||||
if (G_interactive_fd && i->promptme && i->file == stdin) {
|
if (G_interactive_fd && i->file == stdin) {
|
||||||
do {
|
do {
|
||||||
get_user_input(i);
|
get_user_input(i);
|
||||||
} while (!*i->p); /* need non-empty line */
|
} while (!*i->p); /* need non-empty line */
|
||||||
i->promptmode = 1; /* PS2 */
|
i->promptmode = 1; /* PS2 */
|
||||||
i->promptme = 0;
|
|
||||||
goto take_cached;
|
goto take_cached;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
do ch = fgetc(i->file); while (ch == '\0');
|
do ch = fgetc(i->file); while (ch == '\0');
|
||||||
}
|
}
|
||||||
debug_printf("file_get: got '%c' %d\n", ch, ch);
|
debug_printf("file_get: got '%c' %d\n", ch, ch);
|
||||||
#if ENABLE_HUSH_INTERACTIVE
|
|
||||||
if (ch == '\n')
|
|
||||||
i->promptme = 1;
|
|
||||||
#endif
|
|
||||||
return ch;
|
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)
|
static void setup_file_in_str(struct in_str *i, FILE *f)
|
||||||
{
|
{
|
||||||
|
memset(i, 0, sizeof(*i));
|
||||||
i->peek = file_peek;
|
i->peek = file_peek;
|
||||||
i->get = file_get;
|
i->get = file_get;
|
||||||
#if ENABLE_HUSH_INTERACTIVE
|
/* i->promptmode = 0; - PS1 (memset did it) */
|
||||||
i->promptme = 1;
|
|
||||||
i->promptmode = 0; /* PS1 */
|
|
||||||
#endif
|
|
||||||
i->file = f;
|
i->file = f;
|
||||||
i->p = NULL;
|
/* i->p = NULL; */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setup_string_in_str(struct in_str *i, const char *s)
|
static void setup_string_in_str(struct in_str *i, const char *s)
|
||||||
{
|
{
|
||||||
|
memset(i, 0, sizeof(*i));
|
||||||
i->peek = static_peek;
|
i->peek = static_peek;
|
||||||
i->get = static_get;
|
i->get = static_get;
|
||||||
#if ENABLE_HUSH_INTERACTIVE
|
/* i->promptmode = 0; - PS1 (memset did it) */
|
||||||
i->promptme = 1;
|
|
||||||
i->promptmode = 0; /* PS1 */
|
|
||||||
#endif
|
|
||||||
i->p = s;
|
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 */
|
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)
|
if (MAYBE_ASSIGNMENT != 0)
|
||||||
dest.o_assignment = MAYBE_ASSIGNMENT;
|
dest.o_assignment = MAYBE_ASSIGNMENT;
|
||||||
initialize_context(&ctx);
|
initialize_context(&ctx);
|
||||||
@ -4539,7 +4526,6 @@ static struct pipe *parse_stream(char **pstring,
|
|||||||
}
|
}
|
||||||
/* Discard cached input, force prompt */
|
/* Discard cached input, force prompt */
|
||||||
input->p = NULL;
|
input->p = NULL;
|
||||||
IF_HUSH_INTERACTIVE(input->promptme = 1;)
|
|
||||||
goto reset;
|
goto reset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5539,6 +5525,10 @@ static void parse_and_run_stream(struct in_str *inp, int end_trigger)
|
|||||||
while (1) {
|
while (1) {
|
||||||
struct pipe *pipe_list;
|
struct pipe *pipe_list;
|
||||||
|
|
||||||
|
#if ENABLE_HUSH_INTERACTIVE
|
||||||
|
if (end_trigger == ';')
|
||||||
|
inp->promptmode = 0; /* PS1 */
|
||||||
|
#endif
|
||||||
pipe_list = parse_stream(NULL, inp, end_trigger);
|
pipe_list = parse_stream(NULL, inp, end_trigger);
|
||||||
if (!pipe_list) { /* EOF */
|
if (!pipe_list) { /* EOF */
|
||||||
if (empty)
|
if (empty)
|
||||||
|
Loading…
Reference in New Issue
Block a user