diff options
author | Rob Landley <rob@landley.net> | 2005-09-04 11:10:37 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2005-09-04 11:10:37 +0000 |
commit | b766c394569cce356fceb63d83da79581c0997b9 (patch) | |
tree | a1c4cd18cede88c2e18a6e22f0b59924d5838682 /applets/applets.c | |
parent | 9754b91c16288fd0f4d6301fd6d01aa8b3c3b1d9 (diff) | |
download | busybox-w32-b766c394569cce356fceb63d83da79581c0997b9.tar.gz busybox-w32-b766c394569cce356fceb63d83da79581c0997b9.tar.bz2 busybox-w32-b766c394569cce356fceb63d83da79581c0997b9.zip |
General cleanup of command line parsing to allow "busybox" to work as a prefix.
(I.E. any argv[0] that starts with "busybox" winds up in busybox_main().)
Added testing/busybox.tests which tests the following permutations:
./busybox
./busybox-suffix
./busybox cat
./busybox-suffix cat
./busybox --help
./busybox-suffix --help
./busybox --help cat
./busybox-suffix --help cat
./busybox --help unknown
./busybox-suffix --help unknown
./unknown
Also repair the test suite so ./runtest calls the ".tests" scripts properly.
Note: you can now go "busybox busybox busbox ls -l" and it'll take it. The
new code is pretty generic. I can block that if anybody can come up with a
good reason to...
Diffstat (limited to 'applets/applets.c')
-rw-r--r-- | applets/applets.c | 52 |
1 files changed, 14 insertions, 38 deletions
diff --git a/applets/applets.c b/applets/applets.c index ce9ecbbc5..21b0c3dbc 100644 --- a/applets/applets.c +++ b/applets/applets.c | |||
@@ -90,8 +90,7 @@ static int suid_cfg_readable; | |||
90 | 90 | ||
91 | 91 | ||
92 | 92 | ||
93 | extern void | 93 | extern void bb_show_usage (void) |
94 | bb_show_usage (void) | ||
95 | { | 94 | { |
96 | const char *format_string; | 95 | const char *format_string; |
97 | const char *usage_string = usage_messages; | 96 | const char *usage_string = usage_messages; |
@@ -112,8 +111,7 @@ bb_show_usage (void) | |||
112 | exit (EXIT_FAILURE); | 111 | exit (EXIT_FAILURE); |
113 | } | 112 | } |
114 | 113 | ||
115 | static int | 114 | static int applet_name_compare (const void *x, const void *y) |
116 | applet_name_compare (const void *x, const void *y) | ||
117 | { | 115 | { |
118 | const char *name = x; | 116 | const char *name = x; |
119 | const struct BB_applet *applet = y; | 117 | const struct BB_applet *applet = y; |
@@ -123,47 +121,25 @@ applet_name_compare (const void *x, const void *y) | |||
123 | 121 | ||
124 | extern const size_t NUM_APPLETS; | 122 | extern const size_t NUM_APPLETS; |
125 | 123 | ||
126 | struct BB_applet * | 124 | struct BB_applet *find_applet_by_name (const char *name) |
127 | find_applet_by_name (const char *name) | ||
128 | { | 125 | { |
129 | return bsearch (name, applets, NUM_APPLETS, sizeof (struct BB_applet), | 126 | return bsearch (name, applets, NUM_APPLETS, sizeof (struct BB_applet), |
130 | applet_name_compare); | 127 | applet_name_compare); |
131 | } | 128 | } |
132 | 129 | ||
133 | void | 130 | void run_applet_by_name (const char *name, int argc, char **argv) |
134 | run_applet_by_name (const char *name, int argc, char **argv) | ||
135 | { | 131 | { |
136 | static int recurse_level = 0; | 132 | if(ENABLE_FEATURE_SUID_CONFIG) parse_config_file (); |
137 | extern int been_there_done_that; /* From busybox.c */ | 133 | |
138 | 134 | if(!strncmp(name, "busybox", 7)) busybox_main(argc, argv); | |
139 | #ifdef CONFIG_FEATURE_SUID_CONFIG | 135 | /* Do a binary search to find the applet entry given the name. */ |
140 | if (recurse_level == 0) | 136 | applet_using = find_applet_by_name(name); |
141 | parse_config_file (); | 137 | if(applet_using) { |
142 | #endif | 138 | bb_applet_name = applet_using->name; |
143 | 139 | if(argc==2 && !strcmp(argv[1], "--help")) bb_show_usage (); | |
144 | recurse_level++; | 140 | if(ENABLE_FEATURE_SUID) check_suid (applet_using); |
145 | /* Do a binary search to find the applet entry given the name. */ | 141 | exit ((*(applet_using->main)) (argc, argv)); |
146 | if ((applet_using = find_applet_by_name (name)) != NULL) { | ||
147 | bb_applet_name = applet_using->name; | ||
148 | if (argv[1] && strcmp (argv[1], "--help") == 0) { | ||
149 | if (strcmp (applet_using->name, "busybox") == 0) { | ||
150 | if (argv[2]) | ||
151 | applet_using = find_applet_by_name (argv[2]); | ||
152 | else | ||
153 | applet_using = NULL; | ||
154 | } | ||
155 | if (applet_using) | ||
156 | bb_show_usage (); | ||
157 | been_there_done_that = 1; | ||
158 | busybox_main (0, NULL); | ||
159 | } | 142 | } |
160 | #ifdef CONFIG_FEATURE_SUID | ||
161 | check_suid (applet_using); | ||
162 | #endif | ||
163 | |||
164 | exit ((*(applet_using->main)) (argc, argv)); | ||
165 | } | ||
166 | recurse_level--; | ||
167 | } | 143 | } |
168 | 144 | ||
169 | 145 | ||