diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2014-09-18 00:47:05 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-09-18 00:47:05 +0200 |
commit | cd7a38a87d54f5421b379870ff866676f31923b2 (patch) | |
tree | ddc2a3e74dcbf1cd0486e01c4f0e6c48bb445988 | |
parent | d0cdacafa98ec0e73e58c2e5a8ba9dded18006df (diff) | |
download | busybox-w32-cd7a38a87d54f5421b379870ff866676f31923b2.tar.gz busybox-w32-cd7a38a87d54f5421b379870ff866676f31923b2.tar.bz2 busybox-w32-cd7a38a87d54f5421b379870ff866676f31923b2.zip |
false: make "false --help" exit with 1
function old new delta
run_applet_no_and_exit 447 445 -2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | applets/applet_tables.c | 17 | ||||
-rw-r--r-- | libbb/appletlib.c | 26 |
2 files changed, 35 insertions, 8 deletions
diff --git a/applets/applet_tables.c b/applets/applet_tables.c index 94b974e09..92bf1e447 100644 --- a/applets/applet_tables.c +++ b/applets/applet_tables.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <string.h> | 14 | #include <string.h> |
15 | #include <stdio.h> | 15 | #include <stdio.h> |
16 | #include <unistd.h> | 16 | #include <unistd.h> |
17 | #include <ctype.h> | ||
17 | 18 | ||
18 | #undef ARRAY_SIZE | 19 | #undef ARRAY_SIZE |
19 | #define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0]))) | 20 | #define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0]))) |
@@ -49,6 +50,16 @@ static int cmp_name(const void *a, const void *b) | |||
49 | return strcmp(aa->name, bb->name); | 50 | return strcmp(aa->name, bb->name); |
50 | } | 51 | } |
51 | 52 | ||
53 | static int str_isalnum_(const char *s) | ||
54 | { | ||
55 | while (*s) { | ||
56 | if (!isalnum(*s) && *s != '_') | ||
57 | return 0; | ||
58 | s++; | ||
59 | } | ||
60 | return 1; | ||
61 | } | ||
62 | |||
52 | int main(int argc, char **argv) | 63 | int main(int argc, char **argv) |
53 | { | 64 | { |
54 | int i; | 65 | int i; |
@@ -94,6 +105,12 @@ int main(int argc, char **argv) | |||
94 | } | 105 | } |
95 | printf(";\n\n"); | 106 | printf(";\n\n"); |
96 | 107 | ||
108 | for (i = 0; i < NUM_APPLETS; i++) { | ||
109 | if (str_isalnum_(applets[i].name)) | ||
110 | printf("#define APPLET_NO_%s %d\n", applets[i].name, i); | ||
111 | } | ||
112 | printf("\n"); | ||
113 | |||
97 | printf("#ifndef SKIP_applet_main\n"); | 114 | printf("#ifndef SKIP_applet_main\n"); |
98 | printf("int (*const applet_main[])(int argc, char **argv) = {\n"); | 115 | printf("int (*const applet_main[])(int argc, char **argv) = {\n"); |
99 | for (i = 0; i < NUM_APPLETS; i++) { | 116 | for (i = 0; i < NUM_APPLETS; i++) { |
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index a0150854a..cb16e310f 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -745,15 +745,25 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) | |||
745 | 745 | ||
746 | /* Reinit some shared global data */ | 746 | /* Reinit some shared global data */ |
747 | xfunc_error_retval = EXIT_FAILURE; | 747 | xfunc_error_retval = EXIT_FAILURE; |
748 | |||
749 | applet_name = APPLET_NAME(applet_no); | 748 | applet_name = APPLET_NAME(applet_no); |
750 | if (argc == 2 && strcmp(argv[1], "--help") == 0) { | 749 | |
751 | /* Special case. POSIX says "test --help" | 750 | #if defined APPLET_NO_test |
752 | * should be no different from e.g. "test --foo". */ | 751 | /* Special case. POSIX says "test --help" |
753 | //TODO: just compare applet_no with APPLET_NO_test | 752 | * should be no different from e.g. "test --foo". |
754 | if (!ENABLE_TEST || strcmp(applet_name, "test") != 0) { | 753 | * Thus for "test", we skip --help check. |
755 | /* If you want "foo --help" to return 0: */ | 754 | */ |
756 | xfunc_error_retval = 0; | 755 | if (applet_no != APPLET_NO_test) |
756 | #endif | ||
757 | { | ||
758 | if (argc == 2 && strcmp(argv[1], "--help") == 0) { | ||
759 | #if defined APPLET_NO_false | ||
760 | /* Someone insisted that "false --help" must exit 1. Sigh */ | ||
761 | if (applet_no != APPLET_NO_false) | ||
762 | #endif | ||
763 | { | ||
764 | /* Make "foo --help" exit with 0: */ | ||
765 | xfunc_error_retval = 0; | ||
766 | } | ||
757 | bb_show_usage(); | 767 | bb_show_usage(); |
758 | } | 768 | } |
759 | } | 769 | } |