diff options
Diffstat (limited to 'utility.c')
-rw-r--r-- | utility.c | 27 |
1 files changed, 25 insertions, 2 deletions
@@ -40,6 +40,7 @@ | |||
40 | #define bb_need_full_version | 40 | #define bb_need_full_version |
41 | #define BB_DECLARE_EXTERN | 41 | #define BB_DECLARE_EXTERN |
42 | #include "messages.c" | 42 | #include "messages.c" |
43 | #include "usage.h" | ||
43 | 44 | ||
44 | #include <stdio.h> | 45 | #include <stdio.h> |
45 | #include <string.h> | 46 | #include <string.h> |
@@ -76,12 +77,23 @@ const char mtab_file[] = "/proc/mounts"; | |||
76 | # endif | 77 | # endif |
77 | #endif | 78 | #endif |
78 | 79 | ||
79 | extern void usage(const char *usage) | 80 | static struct BB_applet *applet_using; |
81 | |||
82 | extern void show_usage(void) | ||
80 | { | 83 | { |
81 | fprintf(stderr, "%s\n\nUsage: %s\n\n", full_version, usage); | 84 | static const char no_help[] = "No help available.\n"; |
85 | |||
86 | const char *usage_string = no_help; | ||
87 | |||
88 | if (applet_using->usage_index >= 0) { | ||
89 | usage_string = usage_messages[applet_using->usage_index]; | ||
90 | } | ||
91 | fprintf(stderr, "%s\n\nUsage: %s %s\n", full_version, | ||
92 | applet_using->name, usage_string); | ||
82 | exit(EXIT_FAILURE); | 93 | exit(EXIT_FAILURE); |
83 | } | 94 | } |
84 | 95 | ||
96 | |||
85 | static void verror_msg(const char *s, va_list p) | 97 | static void verror_msg(const char *s, va_list p) |
86 | { | 98 | { |
87 | fflush(stdout); | 99 | fflush(stdout); |
@@ -1702,6 +1714,17 @@ struct BB_applet *find_applet_by_name(const char *name) | |||
1702 | applet_name_compare); | 1714 | applet_name_compare); |
1703 | } | 1715 | } |
1704 | 1716 | ||
1717 | void run_applet_by_name(const char *name, int argc, char **argv) | ||
1718 | { | ||
1719 | /* Do a binary search to find the applet entry given the name. */ | ||
1720 | if ((applet_using = find_applet_by_name(name)) != NULL) { | ||
1721 | applet_name = applet_using->name; | ||
1722 | if (argv[1] && strcmp(argv[1], "--help") == 0) | ||
1723 | show_usage(); | ||
1724 | exit((*(applet_using->main)) (argc, argv)); | ||
1725 | } | ||
1726 | } | ||
1727 | |||
1705 | #if defined BB_DD || defined BB_TAIL | 1728 | #if defined BB_DD || defined BB_TAIL |
1706 | unsigned long parse_number(const char *numstr, | 1729 | unsigned long parse_number(const char *numstr, |
1707 | const struct suffix_mult *suffixes) | 1730 | const struct suffix_mult *suffixes) |