#define bb_need_full_version
#define BB_DECLARE_EXTERN
#include "messages.c"
+#include "usage.h"
#include <stdio.h>
#include <string.h>
# 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;
+ int i;
+
+ if (applet_using->usage_index >= 0) {
+ usage_string = usage_messages;
+ for (i=applet_using->usage_index ; i>0 ; ) {
+ if (!*usage_string++) {
+ --i;
+ }
+ }
+ }
+ fprintf(stderr, "%s\n\nUsage: %s %s\n\n", full_version,
+ applet_using->name, usage_string);
exit(EXIT_FAILURE);
}
+
static void verror_msg(const char *s, va_list p)
{
fflush(stdout);
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)