aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-04-07 17:01:31 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-04-07 17:01:31 +0200
commit8d6eab3225330fddf0c32ae10f1eb87803c5c325 (patch)
treed545d7f06c24939dba68e11441bafddb7f3f1fcd /shell
parent17058a06c4333fc0c492c168c8a971ebd0fd5a5a (diff)
downloadbusybox-w32-8d6eab3225330fddf0c32ae10f1eb87803c5c325.tar.gz
busybox-w32-8d6eab3225330fddf0c32ae10f1eb87803c5c325.tar.bz2
busybox-w32-8d6eab3225330fddf0c32ae10f1eb87803c5c325.zip
hush: fix prompt in multi-line $(())
Now shows PS2 in this case: /path/to/dir $ a=b; echo $(( > _ Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 34d905397..d5ea3b21f 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -440,6 +440,7 @@
440#define debug_printf_redir(...) do {} while (0) 440#define debug_printf_redir(...) do {} while (0)
441#define debug_printf_list(...) do {} while (0) 441#define debug_printf_list(...) do {} while (0)
442#define debug_printf_subst(...) do {} while (0) 442#define debug_printf_subst(...) do {} while (0)
443#define debug_printf_prompt(...) do {} while (0)
443#define debug_printf_clean(...) do {} while (0) 444#define debug_printf_clean(...) do {} while (0)
444 445
445#define ERR_PTR ((void*)(long)1) 446#define ERR_PTR ((void*)(long)1)
@@ -551,9 +552,6 @@ static const char *const assignment_flag[] = {
551 552
552typedef struct in_str { 553typedef struct in_str {
553 const char *p; 554 const char *p;
554#if ENABLE_HUSH_INTERACTIVE
555 smallint promptmode; /* 0: PS1, 1: PS2 */
556#endif
557 int peek_buf[2]; 555 int peek_buf[2];
558 int last_char; 556 int last_char;
559 FILE *file; 557 FILE *file;
@@ -876,6 +874,9 @@ struct globals {
876#else 874#else
877# define G_x_mode 0 875# define G_x_mode 0
878#endif 876#endif
877#if ENABLE_HUSH_INTERACTIVE
878 smallint promptmode; /* 0: PS1, 1: PS2 */
879#endif
879 smallint flag_SIGINT; 880 smallint flag_SIGINT;
880#if ENABLE_HUSH_LOOPS 881#if ENABLE_HUSH_LOOPS
881 smallint flag_break_continue; 882 smallint flag_break_continue;
@@ -1248,6 +1249,10 @@ static const struct built_in_command bltins2[] = {
1248# define debug_printf_subst(...) (indent(), fdprintf(2, __VA_ARGS__)) 1249# define debug_printf_subst(...) (indent(), fdprintf(2, __VA_ARGS__))
1249#endif 1250#endif
1250 1251
1252#ifndef debug_printf_prompt
1253# define debug_printf_prompt(...) (indent(), fdprintf(2, __VA_ARGS__))
1254#endif
1255
1251#ifndef debug_printf_clean 1256#ifndef debug_printf_clean
1252# define debug_printf_clean(...) (indent(), fdprintf(2, __VA_ARGS__)) 1257# define debug_printf_clean(...) (indent(), fdprintf(2, __VA_ARGS__))
1253# define DEBUG_CLEAN 1 1258# define DEBUG_CLEAN 1
@@ -2470,15 +2475,15 @@ static void cmdedit_update_prompt(void)
2470 G.PS2 = ""; 2475 G.PS2 = "";
2471} 2476}
2472# endif 2477# endif
2473static const char *setup_prompt_string(int promptmode) 2478static const char *setup_prompt_string(void)
2474{ 2479{
2475 const char *prompt_str; 2480 const char *prompt_str;
2476 2481
2477 debug_printf("setup_prompt_string %d ", promptmode); 2482 debug_printf_prompt("%s promptmode:%d\n", __func__, G.promptmode);
2478 2483
2479 IF_FEATURE_EDITING_FANCY_PROMPT( prompt_str = G.PS2;) 2484 IF_FEATURE_EDITING_FANCY_PROMPT( prompt_str = G.PS2;)
2480 IF_NOT_FEATURE_EDITING_FANCY_PROMPT(prompt_str = "> ";) 2485 IF_NOT_FEATURE_EDITING_FANCY_PROMPT(prompt_str = "> ";)
2481 if (promptmode == 0) { /* PS1 */ 2486 if (G.promptmode == 0) { /* PS1 */
2482 if (!ENABLE_FEATURE_EDITING_FANCY_PROMPT) { 2487 if (!ENABLE_FEATURE_EDITING_FANCY_PROMPT) {
2483 /* No fancy prompts supported, (re)generate "CURDIR $ " by hand */ 2488 /* No fancy prompts supported, (re)generate "CURDIR $ " by hand */
2484 free((char*)G.PS1); 2489 free((char*)G.PS1);
@@ -2497,7 +2502,7 @@ static int get_user_input(struct in_str *i)
2497 int r; 2502 int r;
2498 const char *prompt_str; 2503 const char *prompt_str;
2499 2504
2500 prompt_str = setup_prompt_string(i->promptmode); 2505 prompt_str = setup_prompt_string();
2501# if ENABLE_FEATURE_EDITING 2506# if ENABLE_FEATURE_EDITING
2502 for (;;) { 2507 for (;;) {
2503 reinit_unicode_for_hush(); 2508 reinit_unicode_for_hush();
@@ -2567,7 +2572,8 @@ static int fgetc_interactive(struct in_str *i)
2567 if (G_interactive_fd && i->file == stdin) { 2572 if (G_interactive_fd && i->file == stdin) {
2568 /* Returns first char (or EOF), the rest is in i->p[] */ 2573 /* Returns first char (or EOF), the rest is in i->p[] */
2569 ch = get_user_input(i); 2574 ch = get_user_input(i);
2570 i->promptmode = 1; /* PS2 */ 2575 G.promptmode = 1; /* PS2 */
2576 debug_printf_prompt("%s promptmode=%d\n", __func__, G.promptmode);
2571 } else { 2577 } else {
2572 /* Not stdin: script file, sourced file, etc */ 2578 /* Not stdin: script file, sourced file, etc */
2573 do ch = fgetc(i->file); while (ch == '\0'); 2579 do ch = fgetc(i->file); while (ch == '\0');
@@ -2740,7 +2746,6 @@ static int i_peek_and_eat_bkslash_nl(struct in_str *input)
2740static void setup_file_in_str(struct in_str *i, FILE *f) 2746static void setup_file_in_str(struct in_str *i, FILE *f)
2741{ 2747{
2742 memset(i, 0, sizeof(*i)); 2748 memset(i, 0, sizeof(*i));
2743 /* i->promptmode = 0; - PS1 (memset did it) */
2744 i->file = f; 2749 i->file = f;
2745 /* i->p = NULL; */ 2750 /* i->p = NULL; */
2746} 2751}
@@ -2748,7 +2753,6 @@ static void setup_file_in_str(struct in_str *i, FILE *f)
2748static void setup_string_in_str(struct in_str *i, const char *s) 2753static void setup_string_in_str(struct in_str *i, const char *s)
2749{ 2754{
2750 memset(i, 0, sizeof(*i)); 2755 memset(i, 0, sizeof(*i));
2751 /* i->promptmode = 0; - PS1 (memset did it) */
2752 /*i->file = NULL */; 2756 /*i->file = NULL */;
2753 i->p = s; 2757 i->p = s;
2754} 2758}
@@ -4549,6 +4553,9 @@ static int add_till_closing_bracket(o_string *dest, struct in_str *input, unsign
4549# endif 4553# endif
4550 end_ch &= (DOUBLE_CLOSE_CHAR_FLAG - 1); 4554 end_ch &= (DOUBLE_CLOSE_CHAR_FLAG - 1);
4551 4555
4556 G.promptmode = 1; /* PS2 */
4557 debug_printf_prompt("%s promptmode=%d\n", __func__, G.promptmode);
4558
4552 while (1) { 4559 while (1) {
4553 ch = i_getch(input); 4560 ch = i_getch(input);
4554 if (ch == EOF) { 4561 if (ch == EOF) {
@@ -4614,6 +4621,7 @@ static int add_till_closing_bracket(o_string *dest, struct in_str *input, unsign
4614 continue; 4621 continue;
4615 } 4622 }
4616 } 4623 }
4624 debug_printf_parse("%s return '%s' ch:'%c'\n", __func__, dest->data, ch);
4617 return ch; 4625 return ch;
4618} 4626}
4619#endif /* ENABLE_HUSH_TICK || ENABLE_FEATURE_SH_MATH || ENABLE_HUSH_DOLLAR_OPS */ 4627#endif /* ENABLE_HUSH_TICK || ENABLE_FEATURE_SH_MATH || ENABLE_HUSH_DOLLAR_OPS */
@@ -6670,8 +6678,10 @@ static void parse_and_run_stream(struct in_str *inp, int end_trigger)
6670 struct pipe *pipe_list; 6678 struct pipe *pipe_list;
6671 6679
6672#if ENABLE_HUSH_INTERACTIVE 6680#if ENABLE_HUSH_INTERACTIVE
6673 if (end_trigger == ';') 6681 if (end_trigger == ';') {
6674 inp->promptmode = 0; /* PS1 */ 6682 G.promptmode = 0; /* PS1 */
6683 debug_printf_prompt("%s promptmode=%d\n", __func__, G.promptmode);
6684 }
6675#endif 6685#endif
6676 pipe_list = parse_stream(NULL, inp, end_trigger); 6686 pipe_list = parse_stream(NULL, inp, end_trigger);
6677 if (!pipe_list || pipe_list == ERR_PTR) { /* EOF/error */ 6687 if (!pipe_list || pipe_list == ERR_PTR) { /* EOF/error */