summaryrefslogtreecommitdiff
path: root/utility.c
diff options
context:
space:
mode:
authorEric Andersen2001-02-14 21:23:06 +0000
committerEric Andersen2001-02-14 21:23:06 +0000
commit67991cf824f8df27e74c92d754fb507681c69ce6 (patch)
treea0b652f3dc794d1050c1a8de3afb014a621238fa /utility.c
parent68be2ab914e1e20fe666bbd22a89a18714be2789 (diff)
downloadbusybox-67991cf824f8df27e74c92d754fb507681c69ce6.zip
busybox-67991cf824f8df27e74c92d754fb507681c69ce6.tar.gz
This patch, put together by Manuel Novoa III, is a merge of work
done by Evin Robertson (bug#1105) and work from Manuel to make usage messages occupy less space and simplify how usage messages are displayed.
Diffstat (limited to 'utility.c')
-rw-r--r--utility.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/utility.c b/utility.c
index 368dfc5..818523c 100644
--- a/utility.c
+++ b/utility.c
@@ -40,6 +40,7 @@
#define bb_need_full_version
#define BB_DECLARE_EXTERN
#include "messages.c"
+#include "usage.h"
#include <stdio.h>
#include <string.h>
@@ -76,12 +77,23 @@ const char mtab_file[] = "/proc/mounts";
# endif
#endif
-extern void usage(const char *usage)
+static struct BB_applet *applet_using;
+
+extern void show_usage(void)
{
- fprintf(stderr, "%s\n\nUsage: %s\n\n", full_version, usage);
+ static const char no_help[] = "No help available.\n";
+
+ const char *usage_string = no_help;
+
+ if (applet_using->usage_index >= 0) {
+ usage_string = usage_messages[applet_using->usage_index];
+ }
+ fprintf(stderr, "%s\n\nUsage: %s %s\n", full_version,
+ applet_using->name, usage_string);
exit(EXIT_FAILURE);
}
+
static void verror_msg(const char *s, va_list p)
{
fflush(stdout);
@@ -1702,6 +1714,17 @@ struct BB_applet *find_applet_by_name(const char *name)
applet_name_compare);
}
+void run_applet_by_name(const char *name, int argc, char **argv)
+{
+ /* Do a binary search to find the applet entry given the name. */
+ if ((applet_using = find_applet_by_name(name)) != NULL) {
+ applet_name = applet_using->name;
+ if (argv[1] && strcmp(argv[1], "--help") == 0)
+ show_usage();
+ exit((*(applet_using->main)) (argc, argv));
+ }
+}
+
#if defined BB_DD || defined BB_TAIL
unsigned long parse_number(const char *numstr,
const struct suffix_mult *suffixes)