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>
This commit is contained in:
parent
d0cdacafa9
commit
cd7a38a87d
@ -14,6 +14,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#undef ARRAY_SIZE
|
#undef ARRAY_SIZE
|
||||||
#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
|
#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
|
||||||
@ -49,6 +50,16 @@ static int cmp_name(const void *a, const void *b)
|
|||||||
return strcmp(aa->name, bb->name);
|
return strcmp(aa->name, bb->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int str_isalnum_(const char *s)
|
||||||
|
{
|
||||||
|
while (*s) {
|
||||||
|
if (!isalnum(*s) && *s != '_')
|
||||||
|
return 0;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -94,6 +105,12 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
printf(";\n\n");
|
printf(";\n\n");
|
||||||
|
|
||||||
|
for (i = 0; i < NUM_APPLETS; i++) {
|
||||||
|
if (str_isalnum_(applets[i].name))
|
||||||
|
printf("#define APPLET_NO_%s %d\n", applets[i].name, i);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
printf("#ifndef SKIP_applet_main\n");
|
printf("#ifndef SKIP_applet_main\n");
|
||||||
printf("int (*const applet_main[])(int argc, char **argv) = {\n");
|
printf("int (*const applet_main[])(int argc, char **argv) = {\n");
|
||||||
for (i = 0; i < NUM_APPLETS; i++) {
|
for (i = 0; i < NUM_APPLETS; i++) {
|
||||||
|
@ -745,15 +745,25 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
|
|||||||
|
|
||||||
/* Reinit some shared global data */
|
/* Reinit some shared global data */
|
||||||
xfunc_error_retval = EXIT_FAILURE;
|
xfunc_error_retval = EXIT_FAILURE;
|
||||||
|
|
||||||
applet_name = APPLET_NAME(applet_no);
|
applet_name = APPLET_NAME(applet_no);
|
||||||
if (argc == 2 && strcmp(argv[1], "--help") == 0) {
|
|
||||||
|
#if defined APPLET_NO_test
|
||||||
/* Special case. POSIX says "test --help"
|
/* Special case. POSIX says "test --help"
|
||||||
* should be no different from e.g. "test --foo". */
|
* should be no different from e.g. "test --foo".
|
||||||
//TODO: just compare applet_no with APPLET_NO_test
|
* Thus for "test", we skip --help check.
|
||||||
if (!ENABLE_TEST || strcmp(applet_name, "test") != 0) {
|
*/
|
||||||
/* If you want "foo --help" to return 0: */
|
if (applet_no != APPLET_NO_test)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
if (argc == 2 && strcmp(argv[1], "--help") == 0) {
|
||||||
|
#if defined APPLET_NO_false
|
||||||
|
/* Someone insisted that "false --help" must exit 1. Sigh */
|
||||||
|
if (applet_no != APPLET_NO_false)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
/* Make "foo --help" exit with 0: */
|
||||||
xfunc_error_retval = 0;
|
xfunc_error_retval = 0;
|
||||||
|
}
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user