aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Whitley <markw@lineo.com>2000-10-25 00:28:27 +0000
committerMark Whitley <markw@lineo.com>2000-10-25 00:28:27 +0000
commit130005cd89514ba6b8a4b29569279c3da44739c4 (patch)
tree730dc8d26fb8cf12dd06fa2cb83ce68c0c883fa8
parent207061ac0d400f663dc411c132d7fc07dca7d496 (diff)
downloadbusybox-w32-130005cd89514ba6b8a4b29569279c3da44739c4.tar.gz
busybox-w32-130005cd89514ba6b8a4b29569279c3da44739c4.tar.bz2
busybox-w32-130005cd89514ba6b8a4b29569279c3da44739c4.zip
Applied patch from Gaute B Strokkenes <gs234@cam.ac.uk> to use a binary search
to locate applets, rather than a linear search. Also, broke out the listing of applets into it's own file: applets.h.
-rw-r--r--applets.h375
-rw-r--r--applets/busybox.c393
-rw-r--r--busybox.c393
-rw-r--r--include/applets.h375
4 files changed, 804 insertions, 732 deletions
diff --git a/applets.h b/applets.h
new file mode 100644
index 000000000..a2d73bc59
--- /dev/null
+++ b/applets.h
@@ -0,0 +1,375 @@
1/*
2 * applets.h - a listing of all busybox applets.
3 *
4 * If you write a new applet, you need to add an entry to this list to make
5 * busybox aware of it.
6 *
7 * It is CRUCIAL that this listing be kept in ascii order, otherwise the binary
8 * search lookup contributed by Gaute B Strokkenes stops working. If you value
9 * your kneecaps, you'll be sure to *make sure* that any changes made to this
10 * file result in the listing remaining in ascii order. You have been warned.
11 */
12
13const struct BB_applet applets[] = {
14
15#ifdef BB_TEST
16 {"[", test_main, _BB_DIR_USR_BIN, test_usage},
17#endif
18#ifdef BB_AR
19 {"ar", ar_main, _BB_DIR_USR_BIN, ar_usage},
20#endif
21#ifdef BB_BASENAME
22 {"basename", basename_main, _BB_DIR_USR_BIN, basename_usage},
23#endif
24 {"busybox", busybox_main, _BB_DIR_BIN, NULL},
25#ifdef BB_CAT
26 {"cat", cat_main, _BB_DIR_BIN, cat_usage},
27#endif
28#ifdef BB_CHMOD_CHOWN_CHGRP
29 {"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN, chgrp_usage},
30#endif
31#ifdef BB_CHMOD_CHOWN_CHGRP
32 {"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN, chmod_usage},
33#endif
34#ifdef BB_CHMOD_CHOWN_CHGRP
35 {"chown", chmod_chown_chgrp_main, _BB_DIR_BIN, chown_usage},
36#endif
37#ifdef BB_CHROOT
38 {"chroot", chroot_main, _BB_DIR_USR_SBIN, chroot_usage},
39#endif
40#ifdef BB_CHVT
41 {"chvt", chvt_main, _BB_DIR_USR_BIN, chvt_usage},
42#endif
43#ifdef BB_CLEAR
44 {"clear", clear_main, _BB_DIR_USR_BIN, clear_usage},
45#endif
46#ifdef BB_CMP
47 {"cmp", cmp_main, _BB_DIR_USR_BIN, cmp_usage},
48#endif
49#ifdef BB_CP_MV
50 {"cp", cp_mv_main, _BB_DIR_BIN, cp_usage},
51#endif
52#ifdef BB_CUT
53 {"cut", cut_main, _BB_DIR_USR_BIN, cut_usage},
54#endif
55#ifdef BB_DATE
56 {"date", date_main, _BB_DIR_BIN, date_usage},
57#endif
58#ifdef BB_DC
59 {"dc", dc_main, _BB_DIR_USR_BIN, dc_usage},
60#endif
61#ifdef BB_DD
62 {"dd", dd_main, _BB_DIR_BIN, dd_usage},
63#endif
64#ifdef BB_DEALLOCVT
65 {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN, deallocvt_usage},
66#endif
67#ifdef BB_DF
68 {"df", df_main, _BB_DIR_BIN, df_usage},
69#endif
70#ifdef BB_DIRNAME
71 {"dirname", dirname_main, _BB_DIR_USR_BIN, dirname_usage},
72#endif
73#ifdef BB_DMESG
74 {"dmesg", dmesg_main, _BB_DIR_BIN, dmesg_usage},
75#endif
76#ifdef BB_DOS2UNIX
77 {"dos2unix", dos2unix_main, _BB_DIR_USR_BIN, dos2unix_usage},
78#endif
79#ifdef BB_DU
80 {"du", du_main, _BB_DIR_USR_BIN, du_usage},
81#endif
82#ifdef BB_DUMPKMAP
83 {"dumpkmap", dumpkmap_main, _BB_DIR_BIN, dumpkmap_usage},
84#endif
85#ifdef BB_DUTMP
86 {"dutmp", dutmp_main, _BB_DIR_USR_SBIN, dutmp_usage},
87#endif
88#ifdef BB_ECHO
89 {"echo", echo_main, _BB_DIR_BIN, echo_usage},
90#endif
91#ifdef BB_EXPR
92 {"expr", expr_main, _BB_DIR_USR_BIN, expr_usage},
93#endif
94#ifdef BB_TRUE_FALSE
95 {"false", false_main, _BB_DIR_BIN, false_usage},
96#endif
97#ifdef BB_FBSET
98 {"fbset", fbset_main, _BB_DIR_USR_SBIN, NULL},
99#endif
100#ifdef BB_FDFLUSH
101 {"fdflush", fdflush_main, _BB_DIR_BIN, fdflush_usage},
102#endif
103#ifdef BB_FIND
104 {"find", find_main, _BB_DIR_USR_BIN, find_usage},
105#endif
106#ifdef BB_FREE
107 {"free", free_main, _BB_DIR_USR_BIN, free_usage},
108#endif
109#ifdef BB_FREERAMDISK
110 {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN, freeramdisk_usage},
111#endif
112#ifdef BB_FSCK_MINIX
113 {"fsck.minix", fsck_minix_main, _BB_DIR_SBIN, fsck_minix_usage},
114#endif
115#ifdef BB_GETOPT
116 {"getopt", getopt_main, _BB_DIR_BIN, getopt_usage},
117#endif
118#ifdef BB_GREP
119 {"grep", grep_main, _BB_DIR_BIN, grep_usage},
120#endif
121#ifdef BB_GUNZIP
122 {"gunzip", gunzip_main, _BB_DIR_BIN, gunzip_usage},
123#endif
124#ifdef BB_GZIP
125 {"gzip", gzip_main, _BB_DIR_BIN, gzip_usage},
126#endif
127#ifdef BB_HALT
128 {"halt", halt_main, _BB_DIR_SBIN, halt_usage},
129#endif
130#ifdef BB_HEAD
131 {"head", head_main, _BB_DIR_USR_BIN, head_usage},
132#endif
133#ifdef BB_HOSTID
134 {"hostid", hostid_main, _BB_DIR_USR_BIN, hostid_usage},
135#endif
136#ifdef BB_HOSTNAME
137 {"hostname", hostname_main, _BB_DIR_BIN, hostname_usage},
138#endif
139#ifdef BB_ID
140 {"id", id_main, _BB_DIR_USR_BIN, id_usage},
141#endif
142#ifdef BB_INIT
143 {"init", init_main, _BB_DIR_SBIN, NULL},
144#endif
145#ifdef BB_INSMOD
146 {"insmod", insmod_main, _BB_DIR_SBIN, insmod_usage},
147#endif
148#ifdef BB_KILL
149 {"kill", kill_main, _BB_DIR_BIN, kill_usage},
150#endif
151#ifdef BB_KILLALL
152 {"killall", kill_main, _BB_DIR_USR_BIN, kill_usage},
153#endif
154#ifdef BB_LENGTH
155 {"length", length_main, _BB_DIR_USR_BIN, length_usage},
156#endif
157#ifdef BB_LINUXRC
158 {"linuxrc", init_main, _BB_DIR_ROOT, NULL},
159#endif
160#ifdef BB_LN
161 {"ln", ln_main, _BB_DIR_BIN, ln_usage},
162#endif
163#ifdef BB_LOADACM
164 {"loadacm", loadacm_main, _BB_DIR_USR_BIN, loadacm_usage},
165#endif
166#ifdef BB_LOADFONT
167 {"loadfont", loadfont_main, _BB_DIR_USR_BIN, loadfont_usage},
168#endif
169#ifdef BB_LOADKMAP
170 {"loadkmap", loadkmap_main, _BB_DIR_SBIN, loadkmap_usage},
171#endif
172#ifdef BB_LOGGER
173 {"logger", logger_main, _BB_DIR_USR_BIN, logger_usage},
174#endif
175#ifdef BB_LOGNAME
176 {"logname", logname_main, _BB_DIR_USR_BIN, logname_usage},
177#endif
178#ifdef BB_LS
179 {"ls", ls_main, _BB_DIR_BIN, ls_usage},
180#endif
181#ifdef BB_LSMOD
182 {"lsmod", lsmod_main, _BB_DIR_SBIN, lsmod_usage},
183#endif
184#ifdef BB_MAKEDEVS
185 {"makedevs", makedevs_main, _BB_DIR_SBIN, makedevs_usage},
186#endif
187#ifdef BB_MD5SUM
188 {"md5sum", md5sum_main, _BB_DIR_USR_BIN, md5sum_usage},
189#endif
190#ifdef BB_MKDIR
191 {"mkdir", mkdir_main, _BB_DIR_BIN, mkdir_usage},
192#endif
193#ifdef BB_MKFIFO
194 {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN, mkfifo_usage},
195#endif
196#ifdef BB_MKFS_MINIX
197 {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, mkfs_minix_usage},
198#endif
199#ifdef BB_MKNOD
200 {"mknod", mknod_main, _BB_DIR_BIN, mknod_usage},
201#endif
202#ifdef BB_MKSWAP
203 {"mkswap", mkswap_main, _BB_DIR_SBIN, mkswap_usage},
204#endif
205#ifdef BB_MKTEMP
206 {"mktemp", mktemp_main, _BB_DIR_BIN, mktemp_usage},
207#endif
208#ifdef BB_MORE
209 {"more", more_main, _BB_DIR_BIN, more_usage},
210#endif
211#ifdef BB_MOUNT
212 {"mount", mount_main, _BB_DIR_BIN, mount_usage},
213#endif
214#ifdef BB_MT
215 {"mt", mt_main, _BB_DIR_BIN, mt_usage},
216#endif
217#ifdef BB_CP_MV
218 {"mv", cp_mv_main, _BB_DIR_BIN, mv_usage},
219#endif
220#ifdef BB_NC
221 {"nc", nc_main, _BB_DIR_USR_BIN, nc_usage},
222#endif
223#ifdef BB_NSLOOKUP
224 {"nslookup", nslookup_main, _BB_DIR_USR_BIN, nslookup_usage},
225#endif
226#ifdef BB_PING
227 {"ping", ping_main, _BB_DIR_BIN, ping_usage},
228#endif
229#ifdef BB_POWEROFF
230 {"poweroff", poweroff_main, _BB_DIR_SBIN, poweroff_usage},
231#endif
232#ifdef BB_PRINTF
233 {"printf", printf_main, _BB_DIR_USR_BIN, printf_usage},
234#endif
235#ifdef BB_PS
236 {"ps", ps_main, _BB_DIR_BIN, ps_usage},
237#endif
238#ifdef BB_PWD
239 {"pwd", pwd_main, _BB_DIR_BIN, pwd_usage},
240#endif
241#ifdef BB_RDATE
242 {"rdate", rdate_main, _BB_DIR_USR_BIN, rdate_usage},
243#endif
244#ifdef BB_READLINK
245 {"readlink", readlink_main, _BB_DIR_USR_BIN, readlink_usage},
246#endif
247#ifdef BB_REBOOT
248 {"reboot", reboot_main, _BB_DIR_SBIN, reboot_usage},
249#endif
250#ifdef BB_RENICE
251 {"renice", renice_main, _BB_DIR_USR_BIN, renice_usage},
252#endif
253#ifdef BB_RESET
254 {"reset", reset_main, _BB_DIR_USR_BIN, reset_usage},
255#endif
256#ifdef BB_RM
257 {"rm", rm_main, _BB_DIR_BIN, rm_usage},
258#endif
259#ifdef BB_RMDIR
260 {"rmdir", rmdir_main, _BB_DIR_BIN, rmdir_usage},
261#endif
262#ifdef BB_RMMOD
263 {"rmmod", rmmod_main, _BB_DIR_SBIN, rmmod_usage},
264#endif
265#ifdef BB_SED
266 {"sed", sed_main, _BB_DIR_BIN, sed_usage},
267#endif
268#ifdef BB_SETKEYCODES
269 {"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN, setkeycodes_usage},
270#endif
271#ifdef BB_SH
272 {"sh", shell_main, _BB_DIR_BIN, shell_usage},
273#endif
274#ifdef BB_SLEEP
275 {"sleep", sleep_main, _BB_DIR_BIN, sleep_usage},
276#endif
277#ifdef BB_SORT
278 {"sort", sort_main, _BB_DIR_USR_BIN, sort_usage},
279#endif
280#ifdef BB_SWAPONOFF
281 {"swapoff", swap_on_off_main, _BB_DIR_SBIN, swapoff_usage},
282#endif
283#ifdef BB_SWAPONOFF
284 {"swapon", swap_on_off_main, _BB_DIR_SBIN, swapon_usage},
285#endif
286#ifdef BB_SYNC
287 {"sync", sync_main, _BB_DIR_BIN, sync_usage},
288#endif
289#ifdef BB_SYSLOGD
290 {"syslogd", syslogd_main, _BB_DIR_SBIN, syslogd_usage},
291#endif
292#ifdef BB_TAIL
293 {"tail", tail_main, _BB_DIR_USR_BIN, tail_usage},
294#endif
295#ifdef BB_TAR
296 {"tar", tar_main, _BB_DIR_BIN, tar_usage},
297#endif
298#ifdef BB_TEE
299 {"tee", tee_main, _BB_DIR_USR_BIN, tee_usage},
300#endif
301#ifdef BB_TELNET
302 {"telnet", telnet_main, _BB_DIR_USR_BIN, telnet_usage},
303#endif
304#ifdef BB_TEST
305 {"test", test_main, _BB_DIR_USR_BIN, test_usage},
306#endif
307#ifdef BB_TOUCH
308 {"touch", touch_main, _BB_DIR_BIN, touch_usage},
309#endif
310#ifdef BB_TR
311 {"tr", tr_main, _BB_DIR_USR_BIN, tr_usage},
312#endif
313#ifdef BB_TRUE_FALSE
314 {"true", true_main, _BB_DIR_BIN, true_usage},
315#endif
316#ifdef BB_TTY
317 {"tty", tty_main, _BB_DIR_USR_BIN, tty_usage},
318#endif
319#ifdef BB_UMOUNT
320 {"umount", umount_main, _BB_DIR_BIN, umount_usage},
321#endif
322#ifdef BB_UNAME
323 {"uname", uname_main, _BB_DIR_BIN, uname_usage},
324#endif
325#ifdef BB_UNIQ
326 {"uniq", uniq_main, _BB_DIR_USR_BIN, uniq_usage},
327#endif
328#ifdef BB_UNIX2DOS
329 {"unix2dos", unix2dos_main, _BB_DIR_USR_BIN, unix2dos_usage},
330#endif
331#ifdef BB_UNRPM
332 {"unrpm", unrpm_main, _BB_DIR_USR_BIN, unrpm_usage},
333#endif
334#ifdef BB_UPDATE
335 {"update", update_main, _BB_DIR_SBIN, update_usage},
336#endif
337#ifdef BB_UPTIME
338 {"uptime", uptime_main, _BB_DIR_USR_BIN, uptime_usage},
339#endif
340#ifdef BB_USLEEP
341 {"usleep", usleep_main, _BB_DIR_BIN, usleep_usage},
342#endif
343#ifdef BB_UUDECODE
344 {"uudecode", uudecode_main, _BB_DIR_USR_BIN, uudecode_usage},
345#endif
346#ifdef BB_UUENCODE
347 {"uuencode", uuencode_main, _BB_DIR_USR_BIN, uuencode_usage},
348#endif
349#ifdef BB_WC
350 {"wc", wc_main, _BB_DIR_USR_BIN, wc_usage},
351#endif
352#ifdef BB_WGET
353 {"wget", wget_main, _BB_DIR_USR_BIN, wget_usage},
354#endif
355#ifdef BB_WHICH
356 {"which", which_main, _BB_DIR_USR_BIN, which_usage},
357#endif
358#ifdef BB_WHOAMI
359 {"whoami", whoami_main, _BB_DIR_USR_BIN, whoami_usage},
360#endif
361#ifdef BB_XARGS
362 {"xargs", xargs_main, _BB_DIR_USR_BIN, xargs_usage},
363#endif
364#ifdef BB_YES
365 {"yes", yes_main, _BB_DIR_USR_BIN, yes_usage},
366#endif
367#ifdef BB_GUNZIP
368 {"zcat", gunzip_main, _BB_DIR_BIN, gunzip_usage},
369#endif
370 {0,NULL,0,NULL}
371};
372
373/* The -1 arises because of the {0,NULL,0,NULL} entry above. */
374#define NUM_APPLETS (sizeof (applets) / sizeof (struct BB_applet) - 1)
375
diff --git a/applets/busybox.c b/applets/busybox.c
index 21b8a110e..696dd4262 100644
--- a/applets/busybox.c
+++ b/applets/busybox.c
@@ -3,6 +3,7 @@
3#include <stdio.h> 3#include <stdio.h>
4#include <string.h> 4#include <string.h>
5#include <errno.h> 5#include <errno.h>
6#include "applets.h"
6 7
7#define bb_need_full_version 8#define bb_need_full_version
8#define BB_DECLARE_EXTERN 9#define BB_DECLARE_EXTERN
@@ -10,365 +11,6 @@
10 11
11static int been_there_done_that = 0; 12static int been_there_done_that = 0;
12 13
13const struct BB_applet applets[] = {
14
15#ifdef BB_AR
16 {"ar", ar_main, _BB_DIR_USR_BIN, ar_usage},
17#endif
18#ifdef BB_BASENAME
19 {"basename", basename_main, _BB_DIR_USR_BIN, basename_usage},
20#endif
21 {"busybox", busybox_main, _BB_DIR_BIN, NULL},
22#ifdef BB_CAT
23 {"cat", cat_main, _BB_DIR_BIN, cat_usage},
24#endif
25#ifdef BB_CHMOD_CHOWN_CHGRP
26 {"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN, chgrp_usage},
27#endif
28#ifdef BB_CHMOD_CHOWN_CHGRP
29 {"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN, chmod_usage},
30#endif
31#ifdef BB_CHMOD_CHOWN_CHGRP
32 {"chown", chmod_chown_chgrp_main, _BB_DIR_BIN, chown_usage},
33#endif
34#ifdef BB_CHROOT
35 {"chroot", chroot_main, _BB_DIR_USR_SBIN, chroot_usage},
36#endif
37#ifdef BB_CLEAR
38 {"clear", clear_main, _BB_DIR_USR_BIN, clear_usage},
39#endif
40#ifdef BB_CHVT
41 {"chvt", chvt_main, _BB_DIR_USR_BIN, chvt_usage},
42#endif
43#ifdef BB_CMP
44 {"cmp", cmp_main, _BB_DIR_USR_BIN, cmp_usage},
45#endif
46#ifdef BB_CP_MV
47 {"cp", cp_mv_main, _BB_DIR_BIN, cp_usage},
48#endif
49#ifdef BB_CUT
50 {"cut", cut_main, _BB_DIR_USR_BIN, cut_usage},
51#endif
52#ifdef BB_DATE
53 {"date", date_main, _BB_DIR_BIN, date_usage},
54#endif
55#ifdef BB_DC
56 {"dc", dc_main, _BB_DIR_USR_BIN, dc_usage},
57#endif
58#ifdef BB_DD
59 {"dd", dd_main, _BB_DIR_BIN, dd_usage},
60#endif
61#ifdef BB_DF
62 {"df", df_main, _BB_DIR_BIN, df_usage},
63#endif
64#ifdef BB_DIRNAME
65 {"dirname", dirname_main, _BB_DIR_USR_BIN, dirname_usage},
66#endif
67#ifdef BB_DMESG
68 {"dmesg", dmesg_main, _BB_DIR_BIN, dmesg_usage},
69#endif
70#ifdef BB_DOS2UNIX
71 {"dos2unix", dos2unix_main, _BB_DIR_USR_BIN, dos2unix_usage},
72#endif
73#ifdef BB_DU
74 {"du", du_main, _BB_DIR_USR_BIN, du_usage},
75#endif
76#ifdef BB_DUMPKMAP
77 {"dumpkmap", dumpkmap_main, _BB_DIR_BIN, dumpkmap_usage},
78#endif
79#ifdef BB_DUTMP
80 {"dutmp", dutmp_main, _BB_DIR_USR_SBIN, dutmp_usage},
81#endif
82#ifdef BB_ECHO
83 {"echo", echo_main, _BB_DIR_BIN, echo_usage},
84#endif
85#ifdef BB_EXPR
86 {"expr", expr_main, _BB_DIR_USR_BIN, expr_usage},
87#endif
88#ifdef BB_TRUE_FALSE
89 {"false", false_main, _BB_DIR_BIN, false_usage},
90#endif
91#ifdef BB_FBSET
92 {"fbset", fbset_main, _BB_DIR_USR_SBIN, NULL},
93#endif
94#ifdef BB_FDFLUSH
95 {"fdflush", fdflush_main, _BB_DIR_BIN, fdflush_usage},
96#endif
97#ifdef BB_FIND
98 {"find", find_main, _BB_DIR_USR_BIN, find_usage},
99#endif
100#ifdef BB_FREE
101 {"free", free_main, _BB_DIR_USR_BIN, free_usage},
102#endif
103#ifdef BB_FREERAMDISK
104 {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN, freeramdisk_usage},
105#endif
106#ifdef BB_DEALLOCVT
107 {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN, deallocvt_usage},
108#endif
109#ifdef BB_FSCK_MINIX
110 {"fsck.minix", fsck_minix_main, _BB_DIR_SBIN, fsck_minix_usage},
111#endif
112#ifdef BB_GETOPT
113 {"getopt", getopt_main, _BB_DIR_BIN, getopt_usage},
114#endif
115#ifdef BB_GREP
116 {"grep", grep_main, _BB_DIR_BIN, grep_usage},
117#endif
118#ifdef BB_GUNZIP
119 {"gunzip", gunzip_main, _BB_DIR_BIN, gunzip_usage},
120#endif
121#ifdef BB_GZIP
122 {"gzip", gzip_main, _BB_DIR_BIN, gzip_usage},
123#endif
124#ifdef BB_HALT
125 {"halt", halt_main, _BB_DIR_SBIN, halt_usage},
126#endif
127#ifdef BB_HEAD
128 {"head", head_main, _BB_DIR_USR_BIN, head_usage},
129#endif
130#ifdef BB_HOSTID
131 {"hostid", hostid_main, _BB_DIR_USR_BIN, hostid_usage},
132#endif
133#ifdef BB_HOSTNAME
134 {"hostname", hostname_main, _BB_DIR_BIN, hostname_usage},
135#endif
136#ifdef BB_ID
137 {"id", id_main, _BB_DIR_USR_BIN, id_usage},
138#endif
139#ifdef BB_INIT
140 {"init", init_main, _BB_DIR_SBIN, NULL},
141#endif
142#ifdef BB_INSMOD
143 {"insmod", insmod_main, _BB_DIR_SBIN, insmod_usage},
144#endif
145#ifdef BB_KILL
146 {"kill", kill_main, _BB_DIR_BIN, kill_usage},
147#endif
148#ifdef BB_KILLALL
149 {"killall", kill_main, _BB_DIR_USR_BIN, kill_usage},
150#endif
151#ifdef BB_LENGTH
152 {"length", length_main, _BB_DIR_USR_BIN, length_usage},
153#endif
154#ifdef BB_LINUXRC
155 {"linuxrc", init_main, _BB_DIR_ROOT, NULL},
156#endif
157#ifdef BB_LN
158 {"ln", ln_main, _BB_DIR_BIN, ln_usage},
159#endif
160#ifdef BB_LOADACM
161 {"loadacm", loadacm_main, _BB_DIR_USR_BIN, loadacm_usage},
162#endif
163#ifdef BB_LOADFONT
164 {"loadfont", loadfont_main, _BB_DIR_USR_BIN, loadfont_usage},
165#endif
166#ifdef BB_LOADKMAP
167 {"loadkmap", loadkmap_main, _BB_DIR_SBIN, loadkmap_usage},
168#endif
169#ifdef BB_LOGGER
170 {"logger", logger_main, _BB_DIR_USR_BIN, logger_usage},
171#endif
172#ifdef BB_LOGNAME
173 {"logname", logname_main, _BB_DIR_USR_BIN, logname_usage},
174#endif
175#ifdef BB_LS
176 {"ls", ls_main, _BB_DIR_BIN, ls_usage},
177#endif
178#ifdef BB_LSMOD
179 {"lsmod", lsmod_main, _BB_DIR_SBIN, lsmod_usage},
180#endif
181#ifdef BB_MAKEDEVS
182 {"makedevs", makedevs_main, _BB_DIR_SBIN, makedevs_usage},
183#endif
184#ifdef BB_MD5SUM
185 {"md5sum", md5sum_main, _BB_DIR_USR_BIN, md5sum_usage},
186#endif
187#ifdef BB_MKDIR
188 {"mkdir", mkdir_main, _BB_DIR_BIN, mkdir_usage},
189#endif
190#ifdef BB_MKFIFO
191 {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN, mkfifo_usage},
192#endif
193#ifdef BB_MKFS_MINIX
194 {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, mkfs_minix_usage},
195#endif
196#ifdef BB_MKNOD
197 {"mknod", mknod_main, _BB_DIR_BIN, mknod_usage},
198#endif
199#ifdef BB_MKSWAP
200 {"mkswap", mkswap_main, _BB_DIR_SBIN, mkswap_usage},
201#endif
202#ifdef BB_MKTEMP
203 {"mktemp", mktemp_main, _BB_DIR_BIN, mktemp_usage},
204#endif
205#ifdef BB_NC
206 {"nc", nc_main, _BB_DIR_USR_BIN, nc_usage},
207#endif
208#ifdef BB_MORE
209 {"more", more_main, _BB_DIR_BIN, more_usage},
210#endif
211#ifdef BB_MOUNT
212 {"mount", mount_main, _BB_DIR_BIN, mount_usage},
213#endif
214#ifdef BB_MT
215 {"mt", mt_main, _BB_DIR_BIN, mt_usage},
216#endif
217#ifdef BB_CP_MV
218 {"mv", cp_mv_main, _BB_DIR_BIN, mv_usage},
219#endif
220#ifdef BB_NSLOOKUP
221 {"nslookup", nslookup_main, _BB_DIR_USR_BIN, nslookup_usage},
222#endif
223#ifdef BB_PING
224 {"ping", ping_main, _BB_DIR_BIN, ping_usage},
225#endif
226#ifdef BB_POWEROFF
227 {"poweroff", poweroff_main, _BB_DIR_SBIN, poweroff_usage},
228#endif
229#ifdef BB_PRINTF
230 {"printf", printf_main, _BB_DIR_USR_BIN, printf_usage},
231#endif
232#ifdef BB_PS
233 {"ps", ps_main, _BB_DIR_BIN, ps_usage},
234#endif
235#ifdef BB_PWD
236 {"pwd", pwd_main, _BB_DIR_BIN, pwd_usage},
237#endif
238#ifdef BB_RDATE
239 {"rdate", rdate_main, _BB_DIR_USR_BIN, rdate_usage},
240#endif
241#ifdef BB_READLINK
242 {"readlink", readlink_main, _BB_DIR_USR_BIN, readlink_usage},
243#endif
244#ifdef BB_REBOOT
245 {"reboot", reboot_main, _BB_DIR_SBIN, reboot_usage},
246#endif
247#ifdef BB_RENICE
248 {"renice", renice_main, _BB_DIR_USR_BIN, renice_usage},
249#endif
250#ifdef BB_RESET
251 {"reset", reset_main, _BB_DIR_USR_BIN, reset_usage},
252#endif
253#ifdef BB_RM
254 {"rm", rm_main, _BB_DIR_BIN, rm_usage},
255#endif
256#ifdef BB_RMDIR
257 {"rmdir", rmdir_main, _BB_DIR_BIN, rmdir_usage},
258#endif
259#ifdef BB_RMMOD
260 {"rmmod", rmmod_main, _BB_DIR_SBIN, rmmod_usage},
261#endif
262#ifdef BB_SED
263 {"sed", sed_main, _BB_DIR_BIN, sed_usage},
264#endif
265#ifdef BB_SETKEYCODES
266 {"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN, setkeycodes_usage},
267#endif
268#ifdef BB_SH
269 {"sh", shell_main, _BB_DIR_BIN, shell_usage},
270#endif
271#ifdef BB_SLEEP
272 {"sleep", sleep_main, _BB_DIR_BIN, sleep_usage},
273#endif
274#ifdef BB_SORT
275 {"sort", sort_main, _BB_DIR_USR_BIN, sort_usage},
276#endif
277#ifdef BB_SYNC
278 {"sync", sync_main, _BB_DIR_BIN, sync_usage},
279#endif
280#ifdef BB_SYSLOGD
281 {"syslogd", syslogd_main, _BB_DIR_SBIN, syslogd_usage},
282#endif
283#ifdef BB_SWAPONOFF
284 {"swapon", swap_on_off_main, _BB_DIR_SBIN, swapon_usage},
285#endif
286#ifdef BB_SWAPONOFF
287 {"swapoff", swap_on_off_main, _BB_DIR_SBIN, swapoff_usage},
288#endif
289#ifdef BB_TAIL
290 {"tail", tail_main, _BB_DIR_USR_BIN, tail_usage},
291#endif
292#ifdef BB_TAR
293 {"tar", tar_main, _BB_DIR_BIN, tar_usage},
294#endif
295#ifdef BB_TELNET
296 {"telnet", telnet_main, _BB_DIR_USR_BIN, telnet_usage},
297#endif
298#ifdef BB_TEST
299 {"test", test_main, _BB_DIR_USR_BIN, test_usage},
300#endif
301#ifdef BB_TEE
302 {"tee", tee_main, _BB_DIR_USR_BIN, tee_usage},
303#endif
304#ifdef BB_TOUCH
305 {"touch", touch_main, _BB_DIR_BIN, touch_usage},
306#endif
307#ifdef BB_TR
308 {"tr", tr_main, _BB_DIR_USR_BIN, tr_usage},
309#endif
310#ifdef BB_TRUE_FALSE
311 {"true", true_main, _BB_DIR_BIN, true_usage},
312#endif
313#ifdef BB_TTY
314 {"tty", tty_main, _BB_DIR_USR_BIN, tty_usage},
315#endif
316#ifdef BB_UMOUNT
317 {"umount", umount_main, _BB_DIR_BIN, umount_usage},
318#endif
319#ifdef BB_UNAME
320 {"uname", uname_main, _BB_DIR_BIN, uname_usage},
321#endif
322#ifdef BB_UNIQ
323 {"uniq", uniq_main, _BB_DIR_USR_BIN, uniq_usage},
324#endif
325#ifdef BB_UNIX2DOS
326 {"unix2dos", unix2dos_main, _BB_DIR_USR_BIN, unix2dos_usage},
327#endif
328#ifdef BB_UNRPM
329 {"unrpm", unrpm_main, _BB_DIR_USR_BIN, unrpm_usage},
330#endif
331#ifdef BB_UPDATE
332 {"update", update_main, _BB_DIR_SBIN, update_usage},
333#endif
334#ifdef BB_UPTIME
335 {"uptime", uptime_main, _BB_DIR_USR_BIN, uptime_usage},
336#endif
337#ifdef BB_UUENCODE
338 {"uuencode", uuencode_main, _BB_DIR_USR_BIN, uuencode_usage},
339#endif
340#ifdef BB_UUDECODE
341 {"uudecode", uudecode_main, _BB_DIR_USR_BIN, uudecode_usage},
342#endif
343#ifdef BB_USLEEP
344 {"usleep", usleep_main, _BB_DIR_BIN, usleep_usage},
345#endif
346#ifdef BB_WC
347 {"wc", wc_main, _BB_DIR_USR_BIN, wc_usage},
348#endif
349#ifdef BB_WGET
350 {"wget", wget_main, _BB_DIR_USR_BIN, wget_usage},
351#endif
352#ifdef BB_WHICH
353 {"which", which_main, _BB_DIR_USR_BIN, which_usage},
354#endif
355#ifdef BB_WHOAMI
356 {"whoami", whoami_main, _BB_DIR_USR_BIN, whoami_usage},
357#endif
358#ifdef BB_XARGS
359 {"xargs", xargs_main, _BB_DIR_USR_BIN, xargs_usage},
360#endif
361#ifdef BB_YES
362 {"yes", yes_main, _BB_DIR_USR_BIN, yes_usage},
363#endif
364#ifdef BB_GUNZIP
365 {"zcat", gunzip_main, _BB_DIR_BIN, gunzip_usage},
366#endif
367#ifdef BB_TEST
368 {"[", test_main, _BB_DIR_USR_BIN, test_usage},
369#endif
370 {0,NULL,0,NULL}
371};
372 14
373const char *applet_name; 15const char *applet_name;
374 16
@@ -443,7 +85,7 @@ static void install_links(const char *busybox, int use_symbolic_links)
443int main(int argc, char **argv) 85int main(int argc, char **argv)
444{ 86{
445 const char *s; 87 const char *s;
446 const struct BB_applet *a = applets; 88 int u, l; /* Lower and upper bounds for the binary search. */
447 applet_name = "busybox"; 89 applet_name = "busybox";
448 90
449#ifdef BB_FEATURE_INSTALLER 91#ifdef BB_FEATURE_INSTALLER
@@ -491,14 +133,33 @@ int main(int argc, char **argv)
491 } 133 }
492#endif 134#endif
493 135
494 while (a->name != 0) { 136 /* Do a binary search to find the applet entry given the name. */
495 if (strcmp(applet_name, a->name) == 0) { 137
496 if (a->usage && argv[1] && strcmp(argv[1], "--help") == 0) 138 u = NUM_APPLETS - 1;
497 usage(a->usage); 139 l = 0;
498 exit(((*(a->main)) (argc, argv))); 140
141 for (;;) {
142 int i = l + (u - l) / 2;
143 int j = strcmp(applet_name, applets[i].name);
144
145 if (j == 0) {
146 if (applets[i].usage && argv[1] && strcmp(argv[1], "--help") == 0)
147 usage(applets[i].usage);
148 exit(((*(applets[i].main)) (argc, argv)));
499 } 149 }
500 a++; 150
151 if (u == l)
152 break;
153
154 if (j < 0)
155 u = i - 1;
156 else
157 l = i + 1;
158
159 if (u < l)
160 break;
501 } 161 }
162
502 return(busybox_main(argc, argv)); 163 return(busybox_main(argc, argv));
503} 164}
504 165
diff --git a/busybox.c b/busybox.c
index 21b8a110e..696dd4262 100644
--- a/busybox.c
+++ b/busybox.c
@@ -3,6 +3,7 @@
3#include <stdio.h> 3#include <stdio.h>
4#include <string.h> 4#include <string.h>
5#include <errno.h> 5#include <errno.h>
6#include "applets.h"
6 7
7#define bb_need_full_version 8#define bb_need_full_version
8#define BB_DECLARE_EXTERN 9#define BB_DECLARE_EXTERN
@@ -10,365 +11,6 @@
10 11
11static int been_there_done_that = 0; 12static int been_there_done_that = 0;
12 13
13const struct BB_applet applets[] = {
14
15#ifdef BB_AR
16 {"ar", ar_main, _BB_DIR_USR_BIN, ar_usage},
17#endif
18#ifdef BB_BASENAME
19 {"basename", basename_main, _BB_DIR_USR_BIN, basename_usage},
20#endif
21 {"busybox", busybox_main, _BB_DIR_BIN, NULL},
22#ifdef BB_CAT
23 {"cat", cat_main, _BB_DIR_BIN, cat_usage},
24#endif
25#ifdef BB_CHMOD_CHOWN_CHGRP
26 {"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN, chgrp_usage},
27#endif
28#ifdef BB_CHMOD_CHOWN_CHGRP
29 {"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN, chmod_usage},
30#endif
31#ifdef BB_CHMOD_CHOWN_CHGRP
32 {"chown", chmod_chown_chgrp_main, _BB_DIR_BIN, chown_usage},
33#endif
34#ifdef BB_CHROOT
35 {"chroot", chroot_main, _BB_DIR_USR_SBIN, chroot_usage},
36#endif
37#ifdef BB_CLEAR
38 {"clear", clear_main, _BB_DIR_USR_BIN, clear_usage},
39#endif
40#ifdef BB_CHVT
41 {"chvt", chvt_main, _BB_DIR_USR_BIN, chvt_usage},
42#endif
43#ifdef BB_CMP
44 {"cmp", cmp_main, _BB_DIR_USR_BIN, cmp_usage},
45#endif
46#ifdef BB_CP_MV
47 {"cp", cp_mv_main, _BB_DIR_BIN, cp_usage},
48#endif
49#ifdef BB_CUT
50 {"cut", cut_main, _BB_DIR_USR_BIN, cut_usage},
51#endif
52#ifdef BB_DATE
53 {"date", date_main, _BB_DIR_BIN, date_usage},
54#endif
55#ifdef BB_DC
56 {"dc", dc_main, _BB_DIR_USR_BIN, dc_usage},
57#endif
58#ifdef BB_DD
59 {"dd", dd_main, _BB_DIR_BIN, dd_usage},
60#endif
61#ifdef BB_DF
62 {"df", df_main, _BB_DIR_BIN, df_usage},
63#endif
64#ifdef BB_DIRNAME
65 {"dirname", dirname_main, _BB_DIR_USR_BIN, dirname_usage},
66#endif
67#ifdef BB_DMESG
68 {"dmesg", dmesg_main, _BB_DIR_BIN, dmesg_usage},
69#endif
70#ifdef BB_DOS2UNIX
71 {"dos2unix", dos2unix_main, _BB_DIR_USR_BIN, dos2unix_usage},
72#endif
73#ifdef BB_DU
74 {"du", du_main, _BB_DIR_USR_BIN, du_usage},
75#endif
76#ifdef BB_DUMPKMAP
77 {"dumpkmap", dumpkmap_main, _BB_DIR_BIN, dumpkmap_usage},
78#endif
79#ifdef BB_DUTMP
80 {"dutmp", dutmp_main, _BB_DIR_USR_SBIN, dutmp_usage},
81#endif
82#ifdef BB_ECHO
83 {"echo", echo_main, _BB_DIR_BIN, echo_usage},
84#endif
85#ifdef BB_EXPR
86 {"expr", expr_main, _BB_DIR_USR_BIN, expr_usage},
87#endif
88#ifdef BB_TRUE_FALSE
89 {"false", false_main, _BB_DIR_BIN, false_usage},
90#endif
91#ifdef BB_FBSET
92 {"fbset", fbset_main, _BB_DIR_USR_SBIN, NULL},
93#endif
94#ifdef BB_FDFLUSH
95 {"fdflush", fdflush_main, _BB_DIR_BIN, fdflush_usage},
96#endif
97#ifdef BB_FIND
98 {"find", find_main, _BB_DIR_USR_BIN, find_usage},
99#endif
100#ifdef BB_FREE
101 {"free", free_main, _BB_DIR_USR_BIN, free_usage},
102#endif
103#ifdef BB_FREERAMDISK
104 {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN, freeramdisk_usage},
105#endif
106#ifdef BB_DEALLOCVT
107 {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN, deallocvt_usage},
108#endif
109#ifdef BB_FSCK_MINIX
110 {"fsck.minix", fsck_minix_main, _BB_DIR_SBIN, fsck_minix_usage},
111#endif
112#ifdef BB_GETOPT
113 {"getopt", getopt_main, _BB_DIR_BIN, getopt_usage},
114#endif
115#ifdef BB_GREP
116 {"grep", grep_main, _BB_DIR_BIN, grep_usage},
117#endif
118#ifdef BB_GUNZIP
119 {"gunzip", gunzip_main, _BB_DIR_BIN, gunzip_usage},
120#endif
121#ifdef BB_GZIP
122 {"gzip", gzip_main, _BB_DIR_BIN, gzip_usage},
123#endif
124#ifdef BB_HALT
125 {"halt", halt_main, _BB_DIR_SBIN, halt_usage},
126#endif
127#ifdef BB_HEAD
128 {"head", head_main, _BB_DIR_USR_BIN, head_usage},
129#endif
130#ifdef BB_HOSTID
131 {"hostid", hostid_main, _BB_DIR_USR_BIN, hostid_usage},
132#endif
133#ifdef BB_HOSTNAME
134 {"hostname", hostname_main, _BB_DIR_BIN, hostname_usage},
135#endif
136#ifdef BB_ID
137 {"id", id_main, _BB_DIR_USR_BIN, id_usage},
138#endif
139#ifdef BB_INIT
140 {"init", init_main, _BB_DIR_SBIN, NULL},
141#endif
142#ifdef BB_INSMOD
143 {"insmod", insmod_main, _BB_DIR_SBIN, insmod_usage},
144#endif
145#ifdef BB_KILL
146 {"kill", kill_main, _BB_DIR_BIN, kill_usage},
147#endif
148#ifdef BB_KILLALL
149 {"killall", kill_main, _BB_DIR_USR_BIN, kill_usage},
150#endif
151#ifdef BB_LENGTH
152 {"length", length_main, _BB_DIR_USR_BIN, length_usage},
153#endif
154#ifdef BB_LINUXRC
155 {"linuxrc", init_main, _BB_DIR_ROOT, NULL},
156#endif
157#ifdef BB_LN
158 {"ln", ln_main, _BB_DIR_BIN, ln_usage},
159#endif
160#ifdef BB_LOADACM
161 {"loadacm", loadacm_main, _BB_DIR_USR_BIN, loadacm_usage},
162#endif
163#ifdef BB_LOADFONT
164 {"loadfont", loadfont_main, _BB_DIR_USR_BIN, loadfont_usage},
165#endif
166#ifdef BB_LOADKMAP
167 {"loadkmap", loadkmap_main, _BB_DIR_SBIN, loadkmap_usage},
168#endif
169#ifdef BB_LOGGER
170 {"logger", logger_main, _BB_DIR_USR_BIN, logger_usage},
171#endif
172#ifdef BB_LOGNAME
173 {"logname", logname_main, _BB_DIR_USR_BIN, logname_usage},
174#endif
175#ifdef BB_LS
176 {"ls", ls_main, _BB_DIR_BIN, ls_usage},
177#endif
178#ifdef BB_LSMOD
179 {"lsmod", lsmod_main, _BB_DIR_SBIN, lsmod_usage},
180#endif
181#ifdef BB_MAKEDEVS
182 {"makedevs", makedevs_main, _BB_DIR_SBIN, makedevs_usage},
183#endif
184#ifdef BB_MD5SUM
185 {"md5sum", md5sum_main, _BB_DIR_USR_BIN, md5sum_usage},
186#endif
187#ifdef BB_MKDIR
188 {"mkdir", mkdir_main, _BB_DIR_BIN, mkdir_usage},
189#endif
190#ifdef BB_MKFIFO
191 {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN, mkfifo_usage},
192#endif
193#ifdef BB_MKFS_MINIX
194 {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, mkfs_minix_usage},
195#endif
196#ifdef BB_MKNOD
197 {"mknod", mknod_main, _BB_DIR_BIN, mknod_usage},
198#endif
199#ifdef BB_MKSWAP
200 {"mkswap", mkswap_main, _BB_DIR_SBIN, mkswap_usage},
201#endif
202#ifdef BB_MKTEMP
203 {"mktemp", mktemp_main, _BB_DIR_BIN, mktemp_usage},
204#endif
205#ifdef BB_NC
206 {"nc", nc_main, _BB_DIR_USR_BIN, nc_usage},
207#endif
208#ifdef BB_MORE
209 {"more", more_main, _BB_DIR_BIN, more_usage},
210#endif
211#ifdef BB_MOUNT
212 {"mount", mount_main, _BB_DIR_BIN, mount_usage},
213#endif
214#ifdef BB_MT
215 {"mt", mt_main, _BB_DIR_BIN, mt_usage},
216#endif
217#ifdef BB_CP_MV
218 {"mv", cp_mv_main, _BB_DIR_BIN, mv_usage},
219#endif
220#ifdef BB_NSLOOKUP
221 {"nslookup", nslookup_main, _BB_DIR_USR_BIN, nslookup_usage},
222#endif
223#ifdef BB_PING
224 {"ping", ping_main, _BB_DIR_BIN, ping_usage},
225#endif
226#ifdef BB_POWEROFF
227 {"poweroff", poweroff_main, _BB_DIR_SBIN, poweroff_usage},
228#endif
229#ifdef BB_PRINTF
230 {"printf", printf_main, _BB_DIR_USR_BIN, printf_usage},
231#endif
232#ifdef BB_PS
233 {"ps", ps_main, _BB_DIR_BIN, ps_usage},
234#endif
235#ifdef BB_PWD
236 {"pwd", pwd_main, _BB_DIR_BIN, pwd_usage},
237#endif
238#ifdef BB_RDATE
239 {"rdate", rdate_main, _BB_DIR_USR_BIN, rdate_usage},
240#endif
241#ifdef BB_READLINK
242 {"readlink", readlink_main, _BB_DIR_USR_BIN, readlink_usage},
243#endif
244#ifdef BB_REBOOT
245 {"reboot", reboot_main, _BB_DIR_SBIN, reboot_usage},
246#endif
247#ifdef BB_RENICE
248 {"renice", renice_main, _BB_DIR_USR_BIN, renice_usage},
249#endif
250#ifdef BB_RESET
251 {"reset", reset_main, _BB_DIR_USR_BIN, reset_usage},
252#endif
253#ifdef BB_RM
254 {"rm", rm_main, _BB_DIR_BIN, rm_usage},
255#endif
256#ifdef BB_RMDIR
257 {"rmdir", rmdir_main, _BB_DIR_BIN, rmdir_usage},
258#endif
259#ifdef BB_RMMOD
260 {"rmmod", rmmod_main, _BB_DIR_SBIN, rmmod_usage},
261#endif
262#ifdef BB_SED
263 {"sed", sed_main, _BB_DIR_BIN, sed_usage},
264#endif
265#ifdef BB_SETKEYCODES
266 {"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN, setkeycodes_usage},
267#endif
268#ifdef BB_SH
269 {"sh", shell_main, _BB_DIR_BIN, shell_usage},
270#endif
271#ifdef BB_SLEEP
272 {"sleep", sleep_main, _BB_DIR_BIN, sleep_usage},
273#endif
274#ifdef BB_SORT
275 {"sort", sort_main, _BB_DIR_USR_BIN, sort_usage},
276#endif
277#ifdef BB_SYNC
278 {"sync", sync_main, _BB_DIR_BIN, sync_usage},
279#endif
280#ifdef BB_SYSLOGD
281 {"syslogd", syslogd_main, _BB_DIR_SBIN, syslogd_usage},
282#endif
283#ifdef BB_SWAPONOFF
284 {"swapon", swap_on_off_main, _BB_DIR_SBIN, swapon_usage},
285#endif
286#ifdef BB_SWAPONOFF
287 {"swapoff", swap_on_off_main, _BB_DIR_SBIN, swapoff_usage},
288#endif
289#ifdef BB_TAIL
290 {"tail", tail_main, _BB_DIR_USR_BIN, tail_usage},
291#endif
292#ifdef BB_TAR
293 {"tar", tar_main, _BB_DIR_BIN, tar_usage},
294#endif
295#ifdef BB_TELNET
296 {"telnet", telnet_main, _BB_DIR_USR_BIN, telnet_usage},
297#endif
298#ifdef BB_TEST
299 {"test", test_main, _BB_DIR_USR_BIN, test_usage},
300#endif
301#ifdef BB_TEE
302 {"tee", tee_main, _BB_DIR_USR_BIN, tee_usage},
303#endif
304#ifdef BB_TOUCH
305 {"touch", touch_main, _BB_DIR_BIN, touch_usage},
306#endif
307#ifdef BB_TR
308 {"tr", tr_main, _BB_DIR_USR_BIN, tr_usage},
309#endif
310#ifdef BB_TRUE_FALSE
311 {"true", true_main, _BB_DIR_BIN, true_usage},
312#endif
313#ifdef BB_TTY
314 {"tty", tty_main, _BB_DIR_USR_BIN, tty_usage},
315#endif
316#ifdef BB_UMOUNT
317 {"umount", umount_main, _BB_DIR_BIN, umount_usage},
318#endif
319#ifdef BB_UNAME
320 {"uname", uname_main, _BB_DIR_BIN, uname_usage},
321#endif
322#ifdef BB_UNIQ
323 {"uniq", uniq_main, _BB_DIR_USR_BIN, uniq_usage},
324#endif
325#ifdef BB_UNIX2DOS
326 {"unix2dos", unix2dos_main, _BB_DIR_USR_BIN, unix2dos_usage},
327#endif
328#ifdef BB_UNRPM
329 {"unrpm", unrpm_main, _BB_DIR_USR_BIN, unrpm_usage},
330#endif
331#ifdef BB_UPDATE
332 {"update", update_main, _BB_DIR_SBIN, update_usage},
333#endif
334#ifdef BB_UPTIME
335 {"uptime", uptime_main, _BB_DIR_USR_BIN, uptime_usage},
336#endif
337#ifdef BB_UUENCODE
338 {"uuencode", uuencode_main, _BB_DIR_USR_BIN, uuencode_usage},
339#endif
340#ifdef BB_UUDECODE
341 {"uudecode", uudecode_main, _BB_DIR_USR_BIN, uudecode_usage},
342#endif
343#ifdef BB_USLEEP
344 {"usleep", usleep_main, _BB_DIR_BIN, usleep_usage},
345#endif
346#ifdef BB_WC
347 {"wc", wc_main, _BB_DIR_USR_BIN, wc_usage},
348#endif
349#ifdef BB_WGET
350 {"wget", wget_main, _BB_DIR_USR_BIN, wget_usage},
351#endif
352#ifdef BB_WHICH
353 {"which", which_main, _BB_DIR_USR_BIN, which_usage},
354#endif
355#ifdef BB_WHOAMI
356 {"whoami", whoami_main, _BB_DIR_USR_BIN, whoami_usage},
357#endif
358#ifdef BB_XARGS
359 {"xargs", xargs_main, _BB_DIR_USR_BIN, xargs_usage},
360#endif
361#ifdef BB_YES
362 {"yes", yes_main, _BB_DIR_USR_BIN, yes_usage},
363#endif
364#ifdef BB_GUNZIP
365 {"zcat", gunzip_main, _BB_DIR_BIN, gunzip_usage},
366#endif
367#ifdef BB_TEST
368 {"[", test_main, _BB_DIR_USR_BIN, test_usage},
369#endif
370 {0,NULL,0,NULL}
371};
372 14
373const char *applet_name; 15const char *applet_name;
374 16
@@ -443,7 +85,7 @@ static void install_links(const char *busybox, int use_symbolic_links)
443int main(int argc, char **argv) 85int main(int argc, char **argv)
444{ 86{
445 const char *s; 87 const char *s;
446 const struct BB_applet *a = applets; 88 int u, l; /* Lower and upper bounds for the binary search. */
447 applet_name = "busybox"; 89 applet_name = "busybox";
448 90
449#ifdef BB_FEATURE_INSTALLER 91#ifdef BB_FEATURE_INSTALLER
@@ -491,14 +133,33 @@ int main(int argc, char **argv)
491 } 133 }
492#endif 134#endif
493 135
494 while (a->name != 0) { 136 /* Do a binary search to find the applet entry given the name. */
495 if (strcmp(applet_name, a->name) == 0) { 137
496 if (a->usage && argv[1] && strcmp(argv[1], "--help") == 0) 138 u = NUM_APPLETS - 1;
497 usage(a->usage); 139 l = 0;
498 exit(((*(a->main)) (argc, argv))); 140
141 for (;;) {
142 int i = l + (u - l) / 2;
143 int j = strcmp(applet_name, applets[i].name);
144
145 if (j == 0) {
146 if (applets[i].usage && argv[1] && strcmp(argv[1], "--help") == 0)
147 usage(applets[i].usage);
148 exit(((*(applets[i].main)) (argc, argv)));
499 } 149 }
500 a++; 150
151 if (u == l)
152 break;
153
154 if (j < 0)
155 u = i - 1;
156 else
157 l = i + 1;
158
159 if (u < l)
160 break;
501 } 161 }
162
502 return(busybox_main(argc, argv)); 163 return(busybox_main(argc, argv));
503} 164}
504 165
diff --git a/include/applets.h b/include/applets.h
new file mode 100644
index 000000000..a2d73bc59
--- /dev/null
+++ b/include/applets.h
@@ -0,0 +1,375 @@
1/*
2 * applets.h - a listing of all busybox applets.
3 *
4 * If you write a new applet, you need to add an entry to this list to make
5 * busybox aware of it.
6 *
7 * It is CRUCIAL that this listing be kept in ascii order, otherwise the binary
8 * search lookup contributed by Gaute B Strokkenes stops working. If you value
9 * your kneecaps, you'll be sure to *make sure* that any changes made to this
10 * file result in the listing remaining in ascii order. You have been warned.
11 */
12
13const struct BB_applet applets[] = {
14
15#ifdef BB_TEST
16 {"[", test_main, _BB_DIR_USR_BIN, test_usage},
17#endif
18#ifdef BB_AR
19 {"ar", ar_main, _BB_DIR_USR_BIN, ar_usage},
20#endif
21#ifdef BB_BASENAME
22 {"basename", basename_main, _BB_DIR_USR_BIN, basename_usage},
23#endif
24 {"busybox", busybox_main, _BB_DIR_BIN, NULL},
25#ifdef BB_CAT
26 {"cat", cat_main, _BB_DIR_BIN, cat_usage},
27#endif
28#ifdef BB_CHMOD_CHOWN_CHGRP
29 {"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN, chgrp_usage},
30#endif
31#ifdef BB_CHMOD_CHOWN_CHGRP
32 {"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN, chmod_usage},
33#endif
34#ifdef BB_CHMOD_CHOWN_CHGRP
35 {"chown", chmod_chown_chgrp_main, _BB_DIR_BIN, chown_usage},
36#endif
37#ifdef BB_CHROOT
38 {"chroot", chroot_main, _BB_DIR_USR_SBIN, chroot_usage},
39#endif
40#ifdef BB_CHVT
41 {"chvt", chvt_main, _BB_DIR_USR_BIN, chvt_usage},
42#endif
43#ifdef BB_CLEAR
44 {"clear", clear_main, _BB_DIR_USR_BIN, clear_usage},
45#endif
46#ifdef BB_CMP
47 {"cmp", cmp_main, _BB_DIR_USR_BIN, cmp_usage},
48#endif
49#ifdef BB_CP_MV
50 {"cp", cp_mv_main, _BB_DIR_BIN, cp_usage},
51#endif
52#ifdef BB_CUT
53 {"cut", cut_main, _BB_DIR_USR_BIN, cut_usage},
54#endif
55#ifdef BB_DATE
56 {"date", date_main, _BB_DIR_BIN, date_usage},
57#endif
58#ifdef BB_DC
59 {"dc", dc_main, _BB_DIR_USR_BIN, dc_usage},
60#endif
61#ifdef BB_DD
62 {"dd", dd_main, _BB_DIR_BIN, dd_usage},
63#endif
64#ifdef BB_DEALLOCVT
65 {"deallocvt", deallocvt_main, _BB_DIR_USR_BIN, deallocvt_usage},
66#endif
67#ifdef BB_DF
68 {"df", df_main, _BB_DIR_BIN, df_usage},
69#endif
70#ifdef BB_DIRNAME
71 {"dirname", dirname_main, _BB_DIR_USR_BIN, dirname_usage},
72#endif
73#ifdef BB_DMESG
74 {"dmesg", dmesg_main, _BB_DIR_BIN, dmesg_usage},
75#endif
76#ifdef BB_DOS2UNIX
77 {"dos2unix", dos2unix_main, _BB_DIR_USR_BIN, dos2unix_usage},
78#endif
79#ifdef BB_DU
80 {"du", du_main, _BB_DIR_USR_BIN, du_usage},
81#endif
82#ifdef BB_DUMPKMAP
83 {"dumpkmap", dumpkmap_main, _BB_DIR_BIN, dumpkmap_usage},
84#endif
85#ifdef BB_DUTMP
86 {"dutmp", dutmp_main, _BB_DIR_USR_SBIN, dutmp_usage},
87#endif
88#ifdef BB_ECHO
89 {"echo", echo_main, _BB_DIR_BIN, echo_usage},
90#endif
91#ifdef BB_EXPR
92 {"expr", expr_main, _BB_DIR_USR_BIN, expr_usage},
93#endif
94#ifdef BB_TRUE_FALSE
95 {"false", false_main, _BB_DIR_BIN, false_usage},
96#endif
97#ifdef BB_FBSET
98 {"fbset", fbset_main, _BB_DIR_USR_SBIN, NULL},
99#endif
100#ifdef BB_FDFLUSH
101 {"fdflush", fdflush_main, _BB_DIR_BIN, fdflush_usage},
102#endif
103#ifdef BB_FIND
104 {"find", find_main, _BB_DIR_USR_BIN, find_usage},
105#endif
106#ifdef BB_FREE
107 {"free", free_main, _BB_DIR_USR_BIN, free_usage},
108#endif
109#ifdef BB_FREERAMDISK
110 {"freeramdisk", freeramdisk_main, _BB_DIR_SBIN, freeramdisk_usage},
111#endif
112#ifdef BB_FSCK_MINIX
113 {"fsck.minix", fsck_minix_main, _BB_DIR_SBIN, fsck_minix_usage},
114#endif
115#ifdef BB_GETOPT
116 {"getopt", getopt_main, _BB_DIR_BIN, getopt_usage},
117#endif
118#ifdef BB_GREP
119 {"grep", grep_main, _BB_DIR_BIN, grep_usage},
120#endif
121#ifdef BB_GUNZIP
122 {"gunzip", gunzip_main, _BB_DIR_BIN, gunzip_usage},
123#endif
124#ifdef BB_GZIP
125 {"gzip", gzip_main, _BB_DIR_BIN, gzip_usage},
126#endif
127#ifdef BB_HALT
128 {"halt", halt_main, _BB_DIR_SBIN, halt_usage},
129#endif
130#ifdef BB_HEAD
131 {"head", head_main, _BB_DIR_USR_BIN, head_usage},
132#endif
133#ifdef BB_HOSTID
134 {"hostid", hostid_main, _BB_DIR_USR_BIN, hostid_usage},
135#endif
136#ifdef BB_HOSTNAME
137 {"hostname", hostname_main, _BB_DIR_BIN, hostname_usage},
138#endif
139#ifdef BB_ID
140 {"id", id_main, _BB_DIR_USR_BIN, id_usage},
141#endif
142#ifdef BB_INIT
143 {"init", init_main, _BB_DIR_SBIN, NULL},
144#endif
145#ifdef BB_INSMOD
146 {"insmod", insmod_main, _BB_DIR_SBIN, insmod_usage},
147#endif
148#ifdef BB_KILL
149 {"kill", kill_main, _BB_DIR_BIN, kill_usage},
150#endif
151#ifdef BB_KILLALL
152 {"killall", kill_main, _BB_DIR_USR_BIN, kill_usage},
153#endif
154#ifdef BB_LENGTH
155 {"length", length_main, _BB_DIR_USR_BIN, length_usage},
156#endif
157#ifdef BB_LINUXRC
158 {"linuxrc", init_main, _BB_DIR_ROOT, NULL},
159#endif
160#ifdef BB_LN
161 {"ln", ln_main, _BB_DIR_BIN, ln_usage},
162#endif
163#ifdef BB_LOADACM
164 {"loadacm", loadacm_main, _BB_DIR_USR_BIN, loadacm_usage},
165#endif
166#ifdef BB_LOADFONT
167 {"loadfont", loadfont_main, _BB_DIR_USR_BIN, loadfont_usage},
168#endif
169#ifdef BB_LOADKMAP
170 {"loadkmap", loadkmap_main, _BB_DIR_SBIN, loadkmap_usage},
171#endif
172#ifdef BB_LOGGER
173 {"logger", logger_main, _BB_DIR_USR_BIN, logger_usage},
174#endif
175#ifdef BB_LOGNAME
176 {"logname", logname_main, _BB_DIR_USR_BIN, logname_usage},
177#endif
178#ifdef BB_LS
179 {"ls", ls_main, _BB_DIR_BIN, ls_usage},
180#endif
181#ifdef BB_LSMOD
182 {"lsmod", lsmod_main, _BB_DIR_SBIN, lsmod_usage},
183#endif
184#ifdef BB_MAKEDEVS
185 {"makedevs", makedevs_main, _BB_DIR_SBIN, makedevs_usage},
186#endif
187#ifdef BB_MD5SUM
188 {"md5sum", md5sum_main, _BB_DIR_USR_BIN, md5sum_usage},
189#endif
190#ifdef BB_MKDIR
191 {"mkdir", mkdir_main, _BB_DIR_BIN, mkdir_usage},
192#endif
193#ifdef BB_MKFIFO
194 {"mkfifo", mkfifo_main, _BB_DIR_USR_BIN, mkfifo_usage},
195#endif
196#ifdef BB_MKFS_MINIX
197 {"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, mkfs_minix_usage},
198#endif
199#ifdef BB_MKNOD
200 {"mknod", mknod_main, _BB_DIR_BIN, mknod_usage},
201#endif
202#ifdef BB_MKSWAP
203 {"mkswap", mkswap_main, _BB_DIR_SBIN, mkswap_usage},
204#endif
205#ifdef BB_MKTEMP
206 {"mktemp", mktemp_main, _BB_DIR_BIN, mktemp_usage},
207#endif
208#ifdef BB_MORE
209 {"more", more_main, _BB_DIR_BIN, more_usage},
210#endif
211#ifdef BB_MOUNT
212 {"mount", mount_main, _BB_DIR_BIN, mount_usage},
213#endif
214#ifdef BB_MT
215 {"mt", mt_main, _BB_DIR_BIN, mt_usage},
216#endif
217#ifdef BB_CP_MV
218 {"mv", cp_mv_main, _BB_DIR_BIN, mv_usage},
219#endif
220#ifdef BB_NC
221 {"nc", nc_main, _BB_DIR_USR_BIN, nc_usage},
222#endif
223#ifdef BB_NSLOOKUP
224 {"nslookup", nslookup_main, _BB_DIR_USR_BIN, nslookup_usage},
225#endif
226#ifdef BB_PING
227 {"ping", ping_main, _BB_DIR_BIN, ping_usage},
228#endif
229#ifdef BB_POWEROFF
230 {"poweroff", poweroff_main, _BB_DIR_SBIN, poweroff_usage},
231#endif
232#ifdef BB_PRINTF
233 {"printf", printf_main, _BB_DIR_USR_BIN, printf_usage},
234#endif
235#ifdef BB_PS
236 {"ps", ps_main, _BB_DIR_BIN, ps_usage},
237#endif
238#ifdef BB_PWD
239 {"pwd", pwd_main, _BB_DIR_BIN, pwd_usage},
240#endif
241#ifdef BB_RDATE
242 {"rdate", rdate_main, _BB_DIR_USR_BIN, rdate_usage},
243#endif
244#ifdef BB_READLINK
245 {"readlink", readlink_main, _BB_DIR_USR_BIN, readlink_usage},
246#endif
247#ifdef BB_REBOOT
248 {"reboot", reboot_main, _BB_DIR_SBIN, reboot_usage},
249#endif
250#ifdef BB_RENICE
251 {"renice", renice_main, _BB_DIR_USR_BIN, renice_usage},
252#endif
253#ifdef BB_RESET
254 {"reset", reset_main, _BB_DIR_USR_BIN, reset_usage},
255#endif
256#ifdef BB_RM
257 {"rm", rm_main, _BB_DIR_BIN, rm_usage},
258#endif
259#ifdef BB_RMDIR
260 {"rmdir", rmdir_main, _BB_DIR_BIN, rmdir_usage},
261#endif
262#ifdef BB_RMMOD
263 {"rmmod", rmmod_main, _BB_DIR_SBIN, rmmod_usage},
264#endif
265#ifdef BB_SED
266 {"sed", sed_main, _BB_DIR_BIN, sed_usage},
267#endif
268#ifdef BB_SETKEYCODES
269 {"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN, setkeycodes_usage},
270#endif
271#ifdef BB_SH
272 {"sh", shell_main, _BB_DIR_BIN, shell_usage},
273#endif
274#ifdef BB_SLEEP
275 {"sleep", sleep_main, _BB_DIR_BIN, sleep_usage},
276#endif
277#ifdef BB_SORT
278 {"sort", sort_main, _BB_DIR_USR_BIN, sort_usage},
279#endif
280#ifdef BB_SWAPONOFF
281 {"swapoff", swap_on_off_main, _BB_DIR_SBIN, swapoff_usage},
282#endif
283#ifdef BB_SWAPONOFF
284 {"swapon", swap_on_off_main, _BB_DIR_SBIN, swapon_usage},
285#endif
286#ifdef BB_SYNC
287 {"sync", sync_main, _BB_DIR_BIN, sync_usage},
288#endif
289#ifdef BB_SYSLOGD
290 {"syslogd", syslogd_main, _BB_DIR_SBIN, syslogd_usage},
291#endif
292#ifdef BB_TAIL
293 {"tail", tail_main, _BB_DIR_USR_BIN, tail_usage},
294#endif
295#ifdef BB_TAR
296 {"tar", tar_main, _BB_DIR_BIN, tar_usage},
297#endif
298#ifdef BB_TEE
299 {"tee", tee_main, _BB_DIR_USR_BIN, tee_usage},
300#endif
301#ifdef BB_TELNET
302 {"telnet", telnet_main, _BB_DIR_USR_BIN, telnet_usage},
303#endif
304#ifdef BB_TEST
305 {"test", test_main, _BB_DIR_USR_BIN, test_usage},
306#endif
307#ifdef BB_TOUCH
308 {"touch", touch_main, _BB_DIR_BIN, touch_usage},
309#endif
310#ifdef BB_TR
311 {"tr", tr_main, _BB_DIR_USR_BIN, tr_usage},
312#endif
313#ifdef BB_TRUE_FALSE
314 {"true", true_main, _BB_DIR_BIN, true_usage},
315#endif
316#ifdef BB_TTY
317 {"tty", tty_main, _BB_DIR_USR_BIN, tty_usage},
318#endif
319#ifdef BB_UMOUNT
320 {"umount", umount_main, _BB_DIR_BIN, umount_usage},
321#endif
322#ifdef BB_UNAME
323 {"uname", uname_main, _BB_DIR_BIN, uname_usage},
324#endif
325#ifdef BB_UNIQ
326 {"uniq", uniq_main, _BB_DIR_USR_BIN, uniq_usage},
327#endif
328#ifdef BB_UNIX2DOS
329 {"unix2dos", unix2dos_main, _BB_DIR_USR_BIN, unix2dos_usage},
330#endif
331#ifdef BB_UNRPM
332 {"unrpm", unrpm_main, _BB_DIR_USR_BIN, unrpm_usage},
333#endif
334#ifdef BB_UPDATE
335 {"update", update_main, _BB_DIR_SBIN, update_usage},
336#endif
337#ifdef BB_UPTIME
338 {"uptime", uptime_main, _BB_DIR_USR_BIN, uptime_usage},
339#endif
340#ifdef BB_USLEEP
341 {"usleep", usleep_main, _BB_DIR_BIN, usleep_usage},
342#endif
343#ifdef BB_UUDECODE
344 {"uudecode", uudecode_main, _BB_DIR_USR_BIN, uudecode_usage},
345#endif
346#ifdef BB_UUENCODE
347 {"uuencode", uuencode_main, _BB_DIR_USR_BIN, uuencode_usage},
348#endif
349#ifdef BB_WC
350 {"wc", wc_main, _BB_DIR_USR_BIN, wc_usage},
351#endif
352#ifdef BB_WGET
353 {"wget", wget_main, _BB_DIR_USR_BIN, wget_usage},
354#endif
355#ifdef BB_WHICH
356 {"which", which_main, _BB_DIR_USR_BIN, which_usage},
357#endif
358#ifdef BB_WHOAMI
359 {"whoami", whoami_main, _BB_DIR_USR_BIN, whoami_usage},
360#endif
361#ifdef BB_XARGS
362 {"xargs", xargs_main, _BB_DIR_USR_BIN, xargs_usage},
363#endif
364#ifdef BB_YES
365 {"yes", yes_main, _BB_DIR_USR_BIN, yes_usage},
366#endif
367#ifdef BB_GUNZIP
368 {"zcat", gunzip_main, _BB_DIR_BIN, gunzip_usage},
369#endif
370 {0,NULL,0,NULL}
371};
372
373/* The -1 arises because of the {0,NULL,0,NULL} entry above. */
374#define NUM_APPLETS (sizeof (applets) / sizeof (struct BB_applet) - 1)
375