-#ifdef BB_SH
- /* Add in a special case hack -- whenever **argv == '-'
- * (i.e. '-su' or '-sh') always invoke the shell */
- if (**argv == '-' && *(*argv+1)!= '-') {
- exit(((*(shell_main)) (argc, argv)));
- }
-#endif
-
- /* Do a binary search to find the applet entry given the name. */
- search_applet.name = applet_name;
- applet = bsearch(&search_applet, applets, NUM_APPLETS,
- sizeof(struct BB_applet), applet_name_compare);
- if (applet != NULL) {
- if (applet->usage && argv[1] && strcmp(argv[1], "--help") == 0)
- usage(applet->usage);
- exit((*(applet->main)) (argc, argv));
- }
-
- return(busybox_main(argc, argv));
-}
-
-
-int busybox_main(int argc, char **argv)
-{
- int col = 0;
-
- argc--;
- argv++;
-
- if (been_there_done_that == 1 || argc < 1) {
- const struct BB_applet *a = applets;
-
- fprintf(stderr, "%s\n\n"
- "Usage: busybox [function] [arguments]...\n"
- " or: [function] [arguments]...\n\n"
- "\tBusyBox is a multi-call binary that combines many common Unix\n"
- "\tutilities into a single executable. Most people will create a\n"
- "\tlink to busybox for each function they wish to use, and BusyBox\n"
- "\twill act like whatever it was invoked as.\n"
- "\nCurrently defined functions:\n", full_version);
-
- while (a->name != 0) {
- col +=
- fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
- (a++)->name);
- if (col > 60 && a->name != 0) {
- fprintf(stderr, ",\n");
- col = 0;
+ /* Deal with --help. (Also print help when called with no arguments) */
+
+ if (argc==1 || !strcmp(argv[1],"--help") ) {
+ if (argc>2) {
+ run_applet_by_name(bb_applet_name=argv[2], 2, argv);
+ } else {
+ const struct BB_applet *a;
+ int col, output_width;
+
+ if (ENABLE_FEATURE_AUTOWIDTH) {
+ /* Obtain the terminal width. */
+ get_terminal_width_height(0, &output_width, NULL);
+ /* leading tab and room to wrap */
+ output_width -= 20;
+ } else output_width = 60;
+
+ printf("%s\n\n"
+ "Usage: busybox [function] [arguments]...\n"
+ " or: [function] [arguments]...\n\n"
+ "\tBusyBox is a multi-call binary that combines many common Unix\n"
+ "\tutilities into a single executable. Most people will create a\n"
+ "\tlink to busybox for each function they wish to use and BusyBox\n"
+ "\twill act like whatever it was invoked as!\n"
+ "\nCurrently defined functions:\n", bb_msg_full_version);
+
+ col=0;
+ for(a = applets; a->name;) {
+ col += printf("%s%s", (col ? ", " : "\t"), (a++)->name);
+ if (col > output_width && a->name) {
+ printf(",\n");
+ col = 0;
+ }