diff options
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r-- | libbb/appletlib.c | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 1ff7fe6c8..27ce8a6e8 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -144,17 +144,19 @@ static const char packed_usage[] ALIGN1 = { PACKED_USAGE }; | |||
144 | void FAST_FUNC bb_show_usage(void) | 144 | void FAST_FUNC bb_show_usage(void) |
145 | { | 145 | { |
146 | if (ENABLE_SHOW_USAGE) { | 146 | if (ENABLE_SHOW_USAGE) { |
147 | ssize_t FAST_FUNC (*full_write_fn)(const char *) = | ||
148 | xfunc_error_retval ? full_write2_str : full_write1_str; | ||
147 | #ifdef SINGLE_APPLET_STR | 149 | #ifdef SINGLE_APPLET_STR |
148 | /* Imagine that this applet is "true". Dont link in printf! */ | 150 | /* Imagine that this applet is "true". Dont link in printf! */ |
149 | const char *usage_string = unpack_usage_messages(); | 151 | const char *usage_string = unpack_usage_messages(); |
150 | 152 | ||
151 | if (usage_string) { | 153 | if (usage_string) { |
152 | if (*usage_string == '\b') { | 154 | if (*usage_string == '\b') { |
153 | full_write2_str("No help available\n"); | 155 | full_write_fn("No help available\n"); |
154 | } else { | 156 | } else { |
155 | full_write2_str("Usage: "SINGLE_APPLET_STR" "); | 157 | full_write_fn("Usage: "SINGLE_APPLET_STR" "); |
156 | full_write2_str(usage_string); | 158 | full_write_fn(usage_string); |
157 | full_write2_str("\n"); | 159 | full_write_fn("\n"); |
158 | } | 160 | } |
159 | if (ENABLE_FEATURE_CLEAN_UP) | 161 | if (ENABLE_FEATURE_CLEAN_UP) |
160 | dealloc_usage_messages((char*)usage_string); | 162 | dealloc_usage_messages((char*)usage_string); |
@@ -170,23 +172,23 @@ void FAST_FUNC bb_show_usage(void) | |||
170 | while (*p++) continue; | 172 | while (*p++) continue; |
171 | ap--; | 173 | ap--; |
172 | } | 174 | } |
173 | full_write2_str(bb_banner); | 175 | full_write_fn(bb_banner); |
174 | #if ENABLE_PLATFORM_MINGW32 | 176 | #if ENABLE_PLATFORM_MINGW32 |
175 | full_write2_str("\n"); | 177 | full_write_fn("\n"); |
176 | #else | 178 | #else |
177 | full_write2_str(" multi-call binary.\n"); /* common string */ | 179 | full_write_fn(" multi-call binary.\n"); /* common string */ |
178 | #endif | 180 | #endif |
179 | if (*p == '\b') | 181 | if (*p == '\b') |
180 | full_write2_str("\nNo help available\n"); | 182 | full_write_fn("\nNo help available\n"); |
181 | else { | 183 | else { |
182 | full_write2_str("\nUsage: "); | 184 | full_write_fn("\nUsage: "); |
183 | full_write2_str(applet_name); | 185 | full_write_fn(applet_name); |
184 | if (p[0]) { | 186 | if (p[0]) { |
185 | if (p[0] != '\n') | 187 | if (p[0] != '\n') |
186 | full_write2_str(" "); | 188 | full_write_fn(" "); |
187 | full_write2_str(p); | 189 | full_write_fn(p); |
188 | } | 190 | } |
189 | full_write2_str("\n"); | 191 | full_write_fn("\n"); |
190 | } | 192 | } |
191 | if (ENABLE_FEATURE_CLEAN_UP) | 193 | if (ENABLE_FEATURE_CLEAN_UP) |
192 | dealloc_usage_messages((char*)usage_string); | 194 | dealloc_usage_messages((char*)usage_string); |
@@ -371,8 +373,10 @@ void lbb_prepare(const char *applet | |||
371 | && !(ENABLE_TRUE && strcmp(applet_name, "true") == 0) | 373 | && !(ENABLE_TRUE && strcmp(applet_name, "true") == 0) |
372 | && !(ENABLE_FALSE && strcmp(applet_name, "false") == 0) | 374 | && !(ENABLE_FALSE && strcmp(applet_name, "false") == 0) |
373 | && !(ENABLE_ECHO && strcmp(applet_name, "echo") == 0) | 375 | && !(ENABLE_ECHO && strcmp(applet_name, "echo") == 0) |
374 | ) | 376 | ) { |
377 | xfunc_error_retval = 0; | ||
375 | bb_show_usage(); | 378 | bb_show_usage(); |
379 | } | ||
376 | } | 380 | } |
377 | #endif | 381 | #endif |
378 | } | 382 | } |
@@ -912,24 +916,23 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
912 | help: | 916 | help: |
913 | output_width = get_terminal_width(2); | 917 | output_width = get_terminal_width(2); |
914 | 918 | ||
915 | dup2(1, 2); | 919 | full_write1_str(bb_banner); /* reuse const string */ |
916 | full_write2_str(bb_banner); /* reuse const string */ | ||
917 | # if ENABLE_PLATFORM_MINGW32 | 920 | # if ENABLE_PLATFORM_MINGW32 |
918 | full_write2_str("\n("); | 921 | full_write1_str("\n("); |
919 | # if defined(MINGW_VER) | 922 | # if defined(MINGW_VER) |
920 | if (sizeof(MINGW_VER) > 5) { | 923 | if (sizeof(MINGW_VER) > 5) { |
921 | full_write2_str(MINGW_VER "; "); | 924 | full_write1_str(MINGW_VER "; "); |
922 | } | 925 | } |
923 | # endif | 926 | # endif |
924 | full_write2_str(ENABLE_GLOBBING ? "glob" : "noglob"); | 927 | full_write1_str(ENABLE_GLOBBING ? "glob" : "noglob"); |
925 | # if ENABLE_FEATURE_UTF8_MANIFEST | 928 | # if ENABLE_FEATURE_UTF8_MANIFEST |
926 | full_write2_str("; Unicode"); | 929 | full_write1_str("; Unicode"); |
927 | # endif | 930 | # endif |
928 | full_write2_str(")\n\n"); | 931 | full_write1_str(")\n\n"); |
929 | # else | 932 | # else |
930 | full_write2_str(" multi-call binary.\n"); /* reuse */ | 933 | full_write1_str(" multi-call binary.\n"); /* reuse */ |
931 | #endif | 934 | #endif |
932 | full_write2_str( | 935 | full_write1_str( |
933 | "BusyBox is copyrighted by many authors between 1998-2024.\n" | 936 | "BusyBox is copyrighted by many authors between 1998-2024.\n" |
934 | "Licensed under GPLv2. See source distribution for detailed\n" | 937 | "Licensed under GPLv2. See source distribution for detailed\n" |
935 | "copyright notices.\n" | 938 | "copyright notices.\n" |
@@ -973,20 +976,20 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
973 | while (*a) { | 976 | while (*a) { |
974 | int len2 = strlen(a) + 2; | 977 | int len2 = strlen(a) + 2; |
975 | if (col >= (int)output_width - len2) { | 978 | if (col >= (int)output_width - len2) { |
976 | full_write2_str(",\n"); | 979 | full_write1_str(",\n"); |
977 | col = 0; | 980 | col = 0; |
978 | } | 981 | } |
979 | if (col == 0) { | 982 | if (col == 0) { |
980 | col = 6; | 983 | col = 6; |
981 | full_write2_str("\t"); | 984 | full_write1_str("\t"); |
982 | } else { | 985 | } else { |
983 | full_write2_str(", "); | 986 | full_write1_str(", "); |
984 | } | 987 | } |
985 | full_write2_str(a); | 988 | full_write1_str(a); |
986 | col += len2; | 989 | col += len2; |
987 | a += len2 - 1; | 990 | a += len2 - 1; |
988 | } | 991 | } |
989 | full_write2_str("\n"); | 992 | full_write1_str("\n"); |
990 | return 0; | 993 | return 0; |
991 | } | 994 | } |
992 | 995 | ||
@@ -1006,11 +1009,10 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
1006 | if (is_prefixed_with(argv[1], "--list")) { | 1009 | if (is_prefixed_with(argv[1], "--list")) { |
1007 | unsigned i = 0; | 1010 | unsigned i = 0; |
1008 | const char *a = applet_names; | 1011 | const char *a = applet_names; |
1009 | dup2(1, 2); | ||
1010 | while (*a) { | 1012 | while (*a) { |
1011 | # if ENABLE_FEATURE_INSTALLER && !ENABLE_PLATFORM_MINGW32 | 1013 | # if ENABLE_FEATURE_INSTALLER && !ENABLE_PLATFORM_MINGW32 |
1012 | if (argv[1][6]) /* --list-full? */ | 1014 | if (argv[1][6]) /* --list-full? */ |
1013 | full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); | 1015 | full_write1_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); |
1014 | # elif ENABLE_PLATFORM_MINGW32 && (ENABLE_FEATURE_PREFER_APPLETS \ | 1016 | # elif ENABLE_PLATFORM_MINGW32 && (ENABLE_FEATURE_PREFER_APPLETS \ |
1015 | || ENABLE_FEATURE_SH_STANDALONE \ | 1017 | || ENABLE_FEATURE_SH_STANDALONE \ |
1016 | || ENABLE_FEATURE_SH_NOFORK) | 1018 | || ENABLE_FEATURE_SH_NOFORK) |
@@ -1027,12 +1029,12 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) | |||
1027 | # endif | 1029 | # endif |
1028 | else | 1030 | else |
1029 | str = " "; | 1031 | str = " "; |
1030 | full_write2_str(str); | 1032 | full_write1_str(str); |
1031 | full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); | 1033 | full_write1_str(install_dir[APPLET_INSTALL_LOC(i)] + 1); |
1032 | } | 1034 | } |
1033 | # endif | 1035 | # endif |
1034 | full_write2_str(a); | 1036 | full_write1_str(a); |
1035 | full_write2_str("\n"); | 1037 | full_write1_str("\n"); |
1036 | i++; | 1038 | i++; |
1037 | while (*a++ != '\0') | 1039 | while (*a++ != '\0') |
1038 | continue; | 1040 | continue; |