From 27be0e8cfeb6f0f7a66bbfb2a6ca23d5a064e6ab Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 3 Jan 2023 08:28:16 +0100 Subject: [PATCH] shell: fix compile failures in some configs Signed-off-by: Denys Vlasenko --- include/libbb.h | 8 +++++++- libbb/lineedit.c | 24 +++++++++++++----------- shell/ash.c | 8 ++++++-- shell/hush.c | 6 +++++- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 19ed9ec09..cca33a177 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1939,9 +1939,15 @@ typedef struct line_input_t { # if ENABLE_SHELL_ASH || ENABLE_SHELL_HUSH /* function to fetch additional application-specific names to match */ get_exe_name_t *get_exe_name; +# endif +# endif +# if (ENABLE_FEATURE_USERNAME_COMPLETION || ENABLE_FEATURE_EDITING_FANCY_PROMPT) \ + && (ENABLE_SHELL_ASH || ENABLE_SHELL_HUSH) /* function to fetch value of shell variable */ sh_get_var_t *sh_get_var; -# endif +# define EDITING_HAS_sh_get_var 1 +# else +# define EDITING_HAS_sh_get_var 0 # endif # if MAX_HISTORY int cnt_history; diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 697f2a577..d6b2e76ff 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -249,14 +249,6 @@ static void get_user_strings(void) } } -static const char *get_username_str(void) -{ - if (!got_user_strings) - get_user_strings(); - return user_buf ? user_buf : ""; - /* btw, bash uses "I have no name!" string if uid has no entry */ -} - static NOINLINE const char *get_homedir_or_NULL(void) { const char *home; @@ -275,6 +267,16 @@ static NOINLINE const char *get_homedir_or_NULL(void) } #endif +#if ENABLE_FEATURE_EDITING_FANCY_PROMPT +static const char *get_username_str(void) +{ + if (!got_user_strings) + get_user_strings(); + return user_buf ? user_buf : ""; + /* btw, bash uses "I have no name!" string if uid has no entry */ +} +#endif + #if ENABLE_UNICODE_SUPPORT static size_t load_string(const char *src) { @@ -2035,13 +2037,13 @@ static void parse_and_put_prompt(const char *prmt_ptr) case 'W': /* basename of cur dir */ if (!cwd_buf) { const char *home; -#if ENABLE_SHELL_ASH +# if EDITING_HAS_sh_get_var cwd_buf = state->sh_get_var ? xstrdup(state->sh_get_var("PWD")) : xrealloc_getcwd_or_warn(NULL); -#else +# else cwd_buf = xrealloc_getcwd_or_warn(NULL); -#endif +# endif if (!cwd_buf) cwd_buf = (char *)bb_msg_unknown; else if ((home = get_homedir_or_NULL()) != NULL && home[0]) { diff --git a/shell/ash.c b/shell/ash.c index 326f8b2a9..99fdbce7b 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -9736,7 +9736,7 @@ evalpipe(union node *n, int flags) } /* setinteractive needs this forward reference */ -#if ENABLE_FEATURE_EDITING +#if ENABLE_FEATURE_TAB_COMPLETION static const char *get_builtin_name(int i) FAST_FUNC; #endif @@ -9773,8 +9773,12 @@ setinteractive(int on) #if ENABLE_FEATURE_EDITING if (!line_input_state) { line_input_state = new_line_input_t(FOR_SHELL | WITH_PATH_LOOKUP); +# if ENABLE_FEATURE_TAB_COMPLETION line_input_state->get_exe_name = get_builtin_name; +# endif +# if EDITING_HAS_sh_get_var line_input_state->sh_get_var = lookupvar; +# endif } #endif } @@ -10283,7 +10287,7 @@ find_builtin(const char *name) return bp; } -#if ENABLE_FEATURE_EDITING +#if ENABLE_FEATURE_TAB_COMPLETION static const char * FAST_FUNC get_builtin_name(int i) { diff --git a/shell/hush.c b/shell/hush.c index 051b123e7..693099209 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -8188,7 +8188,7 @@ static const struct built_in_command *find_builtin(const char *name) return find_builtin_helper(name, bltins2, &bltins2[ARRAY_SIZE(bltins2)]); } -#if ENABLE_HUSH_JOB && ENABLE_FEATURE_EDITING +#if ENABLE_HUSH_JOB && ENABLE_FEATURE_TAB_COMPLETION static const char * FAST_FUNC get_builtin_name(int i) { if (/*i >= 0 && */ i < ARRAY_SIZE(bltins1)) { @@ -10668,8 +10668,12 @@ int hush_main(int argc, char **argv) # if ENABLE_FEATURE_EDITING G.line_input_state = new_line_input_t(FOR_SHELL); +# if ENABLE_FEATURE_TAB_COMPLETION G.line_input_state->get_exe_name = get_builtin_name; +# endif +# if EDITING_HAS_sh_get_var G.line_input_state->sh_get_var = get_local_var_value; +# endif # endif # if ENABLE_HUSH_SAVEHISTORY && MAX_HISTORY > 0 {