summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/appletlib.c72
-rw-r--r--libbb/lineedit.c20
2 files changed, 36 insertions, 56 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 6dfaf1f..a0ebaca 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -51,7 +51,7 @@
#include "usage_compressed.h"
#if ENABLE_ASH_EMBEDDED_SCRIPTS
-# define DEFINE_script_names 1
+# define DEFINE_SCRIPT_DATA 1
# include "embedded_scripts.h"
#else
# define NUM_SCRIPTS 0
@@ -818,27 +818,21 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
/* prevent last comma to be in the very last pos */
output_width--;
a = applet_names;
- {
-# if NUM_SCRIPTS > 0
- int i;
- for (i = 0; i < 2; i++, a = script_names)
-# endif
- while (*a) {
- int len2 = strlen(a) + 2;
- 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;
- a += len2 - 1;
+ while (*a) {
+ int len2 = strlen(a) + 2;
+ 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;
+ a += len2 - 1;
}
full_write2_str("\n");
return 0;
@@ -946,20 +940,25 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **ar
# endif /* NUM_APPLETS > 0 */
# if NUM_SCRIPTS > 0
-int FAST_FUNC
-find_script_by_name(const char *name)
+static int find_script_by_name(const char *name)
{
- const char *s = script_names;
- int i = 0;
+ int i;
+ int applet = find_applet_by_name(name);
- while (*s) {
- if (strcmp(name, s) == 0)
- return i;
- i++;
- while (*s++ != '\0')
- continue;
+ if (applet >= 0) {
+ for (i = 0; i < NUM_SCRIPTS; ++i)
+ if (applet_numbers[i] == applet)
+ return i;
}
- return -0x10000; /* make it so that NUM_APPLETS + <error> is still < 0 */
+ return -1;
+}
+
+int scripted_main(int argc UNUSED_PARAM, char **argv)
+{
+ int script = find_script_by_name(applet_name);
+ if (script >= 0)
+ exit(ash_main(-script - 1, argv));
+ return 0;
}
char* FAST_FUNC
@@ -978,7 +977,7 @@ get_script_content(unsigned n)
}
# endif /* NUM_SCRIPTS > 0 */
-# if ENABLE_BUSYBOX || NUM_APPLETS > 0 || NUM_SCRIPTS > 0
+# if ENABLE_BUSYBOX || NUM_APPLETS > 0
static NORETURN void run_applet_and_exit(const char *name, char **argv)
{
# if ENABLE_BUSYBOX
@@ -993,13 +992,6 @@ static NORETURN void run_applet_and_exit(const char *name, char **argv)
run_applet_no_and_exit(applet, name, argv);
}
# endif
-# if NUM_SCRIPTS > 0
- {
- int script = find_script_by_name(name);
- if (script >= 0)
- exit(ash_main(-script - 1, argv));
- }
-# endif
/*bb_error_msg_and_die("applet not found"); - links in printf */
full_write2_str(applet_name);
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 618e7c2..b1e971f 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -41,12 +41,6 @@
#include "busybox.h"
#include "NUM_APPLETS.h"
#include "unicode.h"
-#if ENABLE_ASH_EMBEDDED_SCRIPTS
-# include "embedded_scripts.h"
-#else
-# define NUM_SCRIPTS 0
-#endif
-
#ifndef _POSIX_VDISABLE
# define _POSIX_VDISABLE '\0'
#endif
@@ -812,20 +806,14 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type)
}
pf_len = strlen(pfind);
-# if ENABLE_FEATURE_SH_STANDALONE && (NUM_APPLETS != 1 || NUM_SCRIPTS > 0)
+# if ENABLE_FEATURE_SH_STANDALONE && NUM_APPLETS != 1
if (type == FIND_EXE_ONLY && !dirbuf) {
- const char *p;
-# if NUM_APPLETS != 1 && NUM_SCRIPTS > 0
- for (i = 0, p = applet_names; i < 2; i++, p = script_names)
-# elif NUM_APPLETS != 1 /* and NUM_SCRIPTS == 0 */
- p = applet_names;
-# else /* NUM_APPLETS == 1 && NUM_SCRIPTS > 0 */
- p = script_names;
-# endif
+ const char *p = applet_names;
+
while (*p) {
if (strncmp(pfind, p, pf_len) == 0)
add_match(xstrdup(p));
- while (*p++)
+ while (*p++ != '\0')
continue;
}
}