[PATCH 1/2] busybox: list applets and custom scripts separately
Ron Yorston
rmy at pobox.com
Sun Nov 18 15:02:02 UTC 2018
Make 'busybox --help' distinguish between applets (including
scripted applets) and custom scripts.
If no custom scripts are present the size of the binary is unchanged.
Otherwise:
function old new delta
run_applet_and_exit 728 779 +51
.rodata 168667 168686 +19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 70/0) Total: 70 bytes
Signed-off-by: Ron Yorston <rmy at pobox.com>
---
libbb/appletlib.c | 83 ++++++++++++++++++++++++++++++++--------
scripts/embedded_scripts | 2 +
2 files changed, 68 insertions(+), 17 deletions(-)
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index e0a402031..9e17b84ac 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -55,8 +55,13 @@
# include "embedded_scripts.h"
#else
# define NUM_SCRIPTS 0
+# define NUM_CUSTOM_SCRIPTS 0
+# define NUM_APPLET_SCRIPTS 0
# define HAS_PROFILE 0
#endif
+
+#define SEPARATE_CUSTOM_SCRIPTS (NUM_CUSTOM_SCRIPTS > 0 || HAS_PROFILE)
+
#if NUM_SCRIPTS > 0 || HAS_PROFILE
# include "bb_archive.h"
static const char packed_scripts[] ALIGN1 = { PACKED_SCRIPTS };
@@ -758,6 +763,18 @@ static void install_links(const char *busybox UNUSED_PARAM,
static void run_applet_and_exit(const char *name, char **argv) NORETURN;
# if ENABLE_BUSYBOX
+# if SEPARATE_CUSTOM_SCRIPTS
+static int is_custom(int applet_no)
+{
+ int i;
+
+ for (i = 0; i < NUM_CUSTOM_SCRIPTS; ++i)
+ if (applet_numbers[i] == applet_no)
+ return 1;
+ return 0;
+}
+# endif
+
# if ENABLE_FEATURE_SH_STANDALONE && ENABLE_FEATURE_TAB_COMPLETION
/*
* Insert "busybox" into applet table as well.
@@ -776,6 +793,9 @@ static
# endif
int busybox_main(int argc UNUSED_PARAM, char **argv)
{
+# if SEPARATE_CUSTOM_SCRIPTS
+ int j, applet_no;
+# endif
if (!argv[1]) {
/* Called without arguments */
const char *a;
@@ -815,25 +835,54 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
"\n"
"Currently defined functions:\n"
);
- col = 0;
- /* prevent last comma to be in the very last pos */
- output_width--;
- a = applet_names;
- while (*a) {
- int len2 = strlen(a) + 2;
- if (col >= (int)output_width - len2) {
- full_write2_str(",\n");
- col = 0;
+# if SEPARATE_CUSTOM_SCRIPTS
+ for (j = 0; j < 2; j++)
+# endif
+ {
+ col = 0;
+# if SEPARATE_CUSTOM_SCRIPTS
+ if (j == 1) {
+ full_write2_str("\n\nCustom scripts:\n");
+ if (HAS_PROFILE) {
+ full_write2_str("\t.profile");
+ col = 14;
+ }
}
- if (col == 0) {
- col = 6;
- full_write2_str("\t");
- } else {
- full_write2_str(", ");
+ applet_no = 0;
+# endif
+ /* prevent last comma to be in the very last pos */
+ output_width--;
+ a = applet_names;
+ while (*a) {
+ int len2 = strlen(a) + 2;
+# if SEPARATE_CUSTOM_SCRIPTS
+ if (is_custom(applet_no)) {
+ if (j == 0)
+ goto skip;
+ }
+ else {
+ if (j == 1)
+ goto skip;
+ }
+# endif
+ if (col >= (int)output_width - len2) {
+ full_write2_str(",\n");
+ col = 0;
+ }
+ if (col == 0) {
+ col = 6;
+ full_write2_str("\t");
+ } else {
+ full_write2_str(", ");
+ }
+ full_write2_str(a);
+ col += len2;
+# if SEPARATE_CUSTOM_SCRIPTS
+ skip:
+ ++applet_no;
+# endif
+ a += len2 - 1;
}
- full_write2_str(a);
- col += len2;
- a += len2 - 1;
}
full_write2_str("\n");
return 0;
diff --git a/scripts/embedded_scripts b/scripts/embedded_scripts
index 9e137ca1d..e030f6ae7 100755
--- a/scripts/embedded_scripts
+++ b/scripts/embedded_scripts
@@ -109,6 +109,8 @@ fi
printf "\n"
printf '#define NUM_SCRIPTS %d\n' $n
+printf '#define NUM_CUSTOM_SCRIPTS %d\n' $(echo $custom_scripts | wc -w)
+printf '#define NUM_APPLET_SCRIPTS %d\n' $(echo $applet_scripts | wc -w)
if [ -f $custom_loc/.profile ]
then
# order is important: .profile must be first
--
2.19.1
More information about the busybox
mailing list