shell: fix compile failures in some configs

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2023-01-03 08:28:16 +01:00
parent 8ed57db65b
commit 27be0e8cfe
4 changed files with 31 additions and 15 deletions

View File

@ -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;

View File

@ -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]) {

View File

@ -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)
{

View File

@ -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
{