aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Config.in5
-rw-r--r--libbb/appletlib.c92
2 files changed, 59 insertions, 38 deletions
diff --git a/Config.in b/Config.in
index ae21f52ef..01680af1f 100644
--- a/Config.in
+++ b/Config.in
@@ -178,6 +178,11 @@ config BUSYBOX
178 178
179 Running "busybox APPLET [ARGS...]" will still work, of course. 179 Running "busybox APPLET [ARGS...]" will still work, of course.
180 180
181config FEATURE_SHOW_SCRIPT
182 bool "Support --show SCRIPT"
183 default y
184 depends on BUSYBOX
185
181config FEATURE_INSTALLER 186config FEATURE_INSTALLER
182 bool "Support --install [-s] to install applet links at runtime" 187 bool "Support --install [-s] to install applet links at runtime"
183 default y 188 default y
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index a0ebaca29..a79a37efb 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -756,6 +756,44 @@ static void install_links(const char *busybox UNUSED_PARAM,
756 756
757static void run_applet_and_exit(const char *name, char **argv) NORETURN; 757static void run_applet_and_exit(const char *name, char **argv) NORETURN;
758 758
759# if NUM_SCRIPTS > 0
760static int find_script_by_name(const char *name)
761{
762 int i;
763 int applet = find_applet_by_name(name);
764
765 if (applet >= 0) {
766 for (i = 0; i < NUM_SCRIPTS; ++i)
767 if (applet_numbers[i] == applet)
768 return i;
769 }
770 return -1;
771}
772
773int scripted_main(int argc UNUSED_PARAM, char **argv)
774{
775 int script = find_script_by_name(applet_name);
776 if (script >= 0)
777 exit(ash_main(-script - 1, argv));
778 return 0;
779}
780
781char* FAST_FUNC
782get_script_content(unsigned n)
783{
784 char *t = unpack_bz2_data(packed_scripts, sizeof(packed_scripts),
785 UNPACKED_SCRIPTS_LENGTH);
786 if (t) {
787 while (n != 0) {
788 while (*t++ != '\0')
789 continue;
790 n--;
791 }
792 }
793 return t;
794}
795# endif /* NUM_SCRIPTS > 0 */
796
759# if ENABLE_BUSYBOX 797# if ENABLE_BUSYBOX
760# if ENABLE_FEATURE_SH_STANDALONE && ENABLE_FEATURE_TAB_COMPLETION 798# if ENABLE_FEATURE_SH_STANDALONE && ENABLE_FEATURE_TAB_COMPLETION
761 /* 799 /*
@@ -793,6 +831,9 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
793 "\n" 831 "\n"
794 "Usage: busybox [function [arguments]...]\n" 832 "Usage: busybox [function [arguments]...]\n"
795 " or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n" 833 " or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n"
834# if ENABLE_FEATURE_SHOW_SCRIPT && NUM_SCRIPTS > 0
835 " or: busybox --show SCRIPT\n"
836# endif
796 IF_FEATURE_INSTALLER( 837 IF_FEATURE_INSTALLER(
797 " or: busybox --install [-s] [DIR]\n" 838 " or: busybox --install [-s] [DIR]\n"
798 ) 839 )
@@ -838,6 +879,19 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
838 return 0; 879 return 0;
839 } 880 }
840 881
882# if ENABLE_FEATURE_SHOW_SCRIPT && NUM_SCRIPTS > 0
883 if (strcmp(argv[1], "--show") == 0) {
884 int n;
885 if (!argv[2])
886 bb_error_msg_and_die(bb_msg_requires_arg, "--show");
887 n = find_script_by_name(argv[2]);
888 if (n < 0)
889 bb_error_msg_and_die("script '%s' not found", argv[2]);
890 full_write1_str(get_script_content(n));
891 return 0;
892 }
893# endif
894
841 if (is_prefixed_with(argv[1], "--list")) { 895 if (is_prefixed_with(argv[1], "--list")) {
842 unsigned i = 0; 896 unsigned i = 0;
843 const char *a = applet_names; 897 const char *a = applet_names;
@@ -939,44 +993,6 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **ar
939} 993}
940# endif /* NUM_APPLETS > 0 */ 994# endif /* NUM_APPLETS > 0 */
941 995
942# if NUM_SCRIPTS > 0
943static int find_script_by_name(const char *name)
944{
945 int i;
946 int applet = find_applet_by_name(name);
947
948 if (applet >= 0) {
949 for (i = 0; i < NUM_SCRIPTS; ++i)
950 if (applet_numbers[i] == applet)
951 return i;
952 }
953 return -1;
954}
955
956int scripted_main(int argc UNUSED_PARAM, char **argv)
957{
958 int script = find_script_by_name(applet_name);
959 if (script >= 0)
960 exit(ash_main(-script - 1, argv));
961 return 0;
962}
963
964char* FAST_FUNC
965get_script_content(unsigned n)
966{
967 char *t = unpack_bz2_data(packed_scripts, sizeof(packed_scripts),
968 UNPACKED_SCRIPTS_LENGTH);
969 if (t) {
970 while (n != 0) {
971 while (*t++ != '\0')
972 continue;
973 n--;
974 }
975 }
976 return t;
977}
978# endif /* NUM_SCRIPTS > 0 */
979
980# if ENABLE_BUSYBOX || NUM_APPLETS > 0 996# if ENABLE_BUSYBOX || NUM_APPLETS > 0
981static NORETURN void run_applet_and_exit(const char *name, char **argv) 997static NORETURN void run_applet_and_exit(const char *name, char **argv)
982{ 998{