Pārlūkot izejas kodu

shell: fix compile failures in some configs

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko 1 gadu atpakaļ
vecāks
revīzija
27be0e8cfe
4 mainītis faili ar 31 papildinājumiem un 15 dzēšanām
  1. 7 1
      include/libbb.h
  2. 13 11
      libbb/lineedit.c
  3. 6 2
      shell/ash.c
  4. 5 1
      shell/hush.c

+ 7 - 1
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;

+ 13 - 11
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]) {

+ 6 - 2
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)
 {

+ 5 - 1
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
 		{