aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-18 21:00:21 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-18 21:00:21 +0000
commit2ace1e3f07c819743554b317f4219e21eff06d6b (patch)
treef1e55284426f2a445aa381be6d04c9a18322b0c2
parent55b2de71d73d2d62fdc8a920b12644ff3c3fc0ef (diff)
downloadbusybox-w32-2ace1e3f07c819743554b317f4219e21eff06d6b.tar.gz
busybox-w32-2ace1e3f07c819743554b317f4219e21eff06d6b.tar.bz2
busybox-w32-2ace1e3f07c819743554b317f4219e21eff06d6b.zip
make "busybox" w/o args work again, and save 10 bytes in the process.
-rw-r--r--applets/applets.c102
1 files changed, 52 insertions, 50 deletions
diff --git a/applets/applets.c b/applets/applets.c
index d7e63eb1e..66bcc42de 100644
--- a/applets/applets.c
+++ b/applets/applets.c
@@ -525,7 +525,46 @@ static void install_links(const char *busybox, int use_symbolic_links)
525/* If we were called as "busybox..." */ 525/* If we were called as "busybox..." */
526static int busybox_main(char **argv) 526static int busybox_main(char **argv)
527{ 527{
528 if (ENABLE_FEATURE_INSTALLER && argv[1] && !strcmp(argv[1], "--install")) { 528 if (!argv[1]) {
529 /* Called without arguments */
530 const struct bb_applet *a;
531 int col, output_width;
532 help:
533 output_width = 80;
534 if (ENABLE_FEATURE_AUTOWIDTH) {
535 /* Obtain the terminal width. */
536 get_terminal_width_height(0, &output_width, NULL);
537 }
538 /* leading tab and room to wrap */
539 output_width -= sizeof("start-stop-daemon, ") + 8;
540
541 printf("%s\n"
542 "Copyright (C) 1998-2006  Erik Andersen, Rob Landley, and others.\n"
543 "Licensed under GPLv2.  See source distribution for full notice.\n"
544 "\n"
545 "Usage: busybox [function] [arguments]...\n"
546 " or: [function] [arguments]...\n"
547 "\n"
548 "\tBusyBox is a multi-call binary that combines many common Unix\n"
549 "\tutilities into a single executable. Most people will create a\n"
550 "\tlink to busybox for each function they wish to use and BusyBox\n"
551 "\twill act like whatever it was invoked as!\n"
552 "\nCurrently defined functions:\n", bb_msg_full_version);
553 col = 0;
554 a = applets;
555 while (a->name) {
556 if (col > output_width) {
557 puts(",");
558 col = 0;
559 }
560 col += printf("%s%s", (col ? ", " : "\t"), a->name);
561 a++;
562 }
563 puts("\n");
564 return 0;
565 }
566
567 if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) {
529 int use_symbolic_links = 0; 568 int use_symbolic_links = 0;
530 char *busybox; 569 char *busybox;
531 570
@@ -544,57 +583,20 @@ static int busybox_main(char **argv)
544 return 0; 583 return 0;
545 } 584 }
546 585
547 /* Deal with --help. Also print help when called with no arguments */ 586 if (strcmp(argv[1], "--help") == 0) {
548 587 /* "busybox --help [<applet>]" */
549 if (!argv[1] || !strcmp(argv[1], "--help") ) { 588 if (!argv[2])
550 if (argv[2]) { 589 goto help;
551 /* set name for proper "<name>: applet not found" */ 590 /* convert to "<applet> --help" */
552 applet_name = argv[2]; 591 argv[0] = argv[2];
553 argv[2] = NULL; 592 argv[2] = NULL;
554 run_applet_and_exit(applet_name, argv);
555 } else {
556 const struct bb_applet *a;
557 int col, output_width;
558
559 output_width = 80 - sizeof("start-stop-daemon, ") - 8;
560 if (ENABLE_FEATURE_AUTOWIDTH) {
561 /* Obtain the terminal width. */
562 get_terminal_width_height(0, &output_width, NULL);
563 /* leading tab and room to wrap */
564 output_width -= sizeof("start-stop-daemon, ") + 8;
565 }
566
567 printf("%s\n"
568 "Copyright (C) 1998-2006  Erik Andersen, Rob Landley, and others.\n"
569 "Licensed under GPLv2.  See source distribution for full notice.\n"
570 "\n"
571 "Usage: busybox [function] [arguments]...\n"
572 " or: [function] [arguments]...\n"
573 "\n"
574 "\tBusyBox is a multi-call binary that combines many common Unix\n"
575 "\tutilities into a single executable. Most people will create a\n"
576 "\tlink to busybox for each function they wish to use and BusyBox\n"
577 "\twill act like whatever it was invoked as!\n"
578 "\nCurrently defined functions:\n", bb_msg_full_version);
579 col = 0;
580 a = applets;
581 while (a->name) {
582 col += printf("%s%s", (col ? ", " : "\t"), a->name);
583 a++;
584 if (col > output_width && a->name) {
585 puts(",");
586 col = 0;
587 }
588 }
589 puts("\n");
590 return 0;
591 }
592 } else { 593 } else {
593 /* we want "<argv[1]>: applet not found", not "busybox: ..." */ 594 /* "busybox <applet> arg1 arg2 ..." */
594 applet_name = argv[1]; 595 argv++;
595 run_applet_and_exit(argv[1], argv + 1);
596 } 596 }
597 597 /* we want "<argv[0]>: applet not found", not "busybox: ..." */
598 applet_name = argv[0];
599 run_applet_and_exit(argv[0], argv);
598 bb_error_msg_and_die("applet not found"); 600 bb_error_msg_and_die("applet not found");
599} 601}
600 602