aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-12-25 18:49:29 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-12-25 18:49:29 +0100
commit46a71dc30c62dde71d4e6714790b40187d378e82 (patch)
tree9f590104bd48fcdcc28cd74312bae7847d75c55f
parent6cfec7dd0269619add74ff654f724d3c5f89176b (diff)
downloadbusybox-w32-46a71dc30c62dde71d4e6714790b40187d378e82.tar.gz
busybox-w32-46a71dc30c62dde71d4e6714790b40187d378e82.tar.bz2
busybox-w32-46a71dc30c62dde71d4e6714790b40187d378e82.zip
hush: if !EDITING, do not regenerate prompt for every input char
function old new delta fgetc_interactive 261 258 -3 pseudo_exec_argv 406 399 -7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-10) Total: -10 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c
index d3444c556..3bdbe26d8 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -2640,11 +2640,14 @@ static const char *setup_prompt_string(void)
2640} 2640}
2641static int get_user_input(struct in_str *i) 2641static int get_user_input(struct in_str *i)
2642{ 2642{
2643# if ENABLE_FEATURE_EDITING
2644 /* In EDITING case, this function reads next input line,
2645 * saves it in i->p, then returns 1st char of it.
2646 */
2643 int r; 2647 int r;
2644 const char *prompt_str; 2648 const char *prompt_str;
2645 2649
2646 prompt_str = setup_prompt_string(); 2650 prompt_str = setup_prompt_string();
2647# if ENABLE_FEATURE_EDITING
2648 for (;;) { 2651 for (;;) {
2649 reinit_unicode_for_hush(); 2652 reinit_unicode_for_hush();
2650 G.flag_SIGINT = 0; 2653 G.flag_SIGINT = 0;
@@ -2674,9 +2677,15 @@ static int get_user_input(struct in_str *i)
2674 i->p = G.user_input_buf; 2677 i->p = G.user_input_buf;
2675 return (unsigned char)*i->p++; 2678 return (unsigned char)*i->p++;
2676# else 2679# else
2680 /* In !EDITING case, this function gets called for every char.
2681 * Buffering happens deeper in the call chain, in hfgetc(i->file).
2682 */
2683 int r;
2684
2677 for (;;) { 2685 for (;;) {
2678 G.flag_SIGINT = 0; 2686 G.flag_SIGINT = 0;
2679 if (i->last_char == '\0' || i->last_char == '\n') { 2687 if (i->last_char == '\0' || i->last_char == '\n') {
2688 const char *prompt_str = setup_prompt_string();
2680 /* Why check_and_run_traps here? Try this interactively: 2689 /* Why check_and_run_traps here? Try this interactively:
2681 * $ trap 'echo INT' INT; (sleep 2; kill -INT $$) & 2690 * $ trap 'echo INT' INT; (sleep 2; kill -INT $$) &
2682 * $ <[enter], repeatedly...> 2691 * $ <[enter], repeatedly...>
@@ -8171,7 +8180,6 @@ static void exec_function(char ***to_free,
8171 8180
8172 /* On MMU, funcp->body is always non-NULL */ 8181 /* On MMU, funcp->body is always non-NULL */
8173 n = run_list(funcp->body); 8182 n = run_list(funcp->body);
8174 fflush_all();
8175 _exit(n); 8183 _exit(n);
8176# else 8184# else
8177//? close_saved_fds_and_FILE_fds(); 8185//? close_saved_fds_and_FILE_fds();
@@ -8246,7 +8254,6 @@ static void exec_builtin(char ***to_free,
8246{ 8254{
8247#if BB_MMU 8255#if BB_MMU
8248 int rcode; 8256 int rcode;
8249 fflush_all();
8250//? close_saved_fds_and_FILE_fds(); 8257//? close_saved_fds_and_FILE_fds();
8251 rcode = x->b_function(argv); 8258 rcode = x->b_function(argv);
8252 fflush_all(); 8259 fflush_all();
@@ -10039,8 +10046,8 @@ int hush_main(int argc, char **argv)
10039#endif 10046#endif
10040 10047
10041 cached_getpid = getpid(); /* for tcsetpgrp() during init */ 10048 cached_getpid = getpid(); /* for tcsetpgrp() during init */
10042 G.root_pid = cached_getpid; /* for $PID (NOMMU can override via -$HEXPID:HEXPPID:...) */ 10049 G.root_pid = cached_getpid; /* for $PID (NOMMU can override via -$HEXPID:HEXPPID:...) */
10043 G.root_ppid = getppid(); /* for $$PPID (NOMMU can override) */ 10050 G.root_ppid = getppid(); /* for $PPID (NOMMU can override) */
10044 10051
10045 /* Deal with HUSH_VERSION */ 10052 /* Deal with HUSH_VERSION */
10046 debug_printf_env("unsetenv '%s'\n", "HUSH_VERSION"); 10053 debug_printf_env("unsetenv '%s'\n", "HUSH_VERSION");