6 static int been_there_done_that = 0;
8 static const struct Applet applets[] = {
10 #ifdef BB_BUSYBOX //bin
11 {"busybox", busybox_main},
13 #ifdef BB_BLOCK_DEVICE //sbin
14 {"block_device", block_device_main},
17 {"cat", cat_more_main},
19 #ifdef BB_CHMOD_CHOWN_CHGRP //bin
20 {"chmod", chmod_chown_chgrp_main},
21 {"chown", chmod_chown_chgrp_main},
22 {"chgrp", chmod_chown_chgrp_main},
24 #ifdef BB_CHROOT //sbin
25 {"chroot", chroot_main},
27 #ifdef BB_CLEAR //usr/bin
28 {"clear", clear_main},
43 {"dmesg", dmesg_main},
45 #ifdef BB_DUTMP //usr/sbin
46 {"dutmp", cat_more_main},
48 #ifdef BB_FDFLUSH //bin
49 {"fdflush", fdflush_main},
51 #ifdef BB_FIND //usr/bin
66 #ifdef BB_LENGTH //usr/bin
67 {"length", length_main},
72 #ifdef BB_LOADFONT //usr/bin
73 {"loadfont", loadfont_main},
75 #ifdef BB_LOADKMAP //sbin
76 {"loadkmap", loadkmap_main},
81 #ifdef BB_MAKEDEVS //sbin
82 {"makedevs", makedevs_main},
84 #ifdef BB_MATH //usr/bin
88 {"mkdir", mkdir_main},
91 {"mknod", mknod_main},
93 #ifdef BB_MKSWAP //sbin
94 {"mkswap", mkswap_main},
96 #ifdef BB_MNC //usr/bin
102 #ifdef BB_MOUNT //bin
103 {"mount", mount_main},
111 #ifdef BB_PRINTF //usr/bin
112 {"printf", printf_main},
117 #ifdef BB_REBOOT //sbin
118 {"reboot", reboot_main},
123 #ifdef BB_RMDIR //bin
124 {"rmdir", rmdir_main},
126 #ifdef BB_SLEEP //bin
127 {"sleep", sleep_main},
132 #ifdef BB_SWAPONOFF //sbin
133 {"swapon", swap_on_off_main},
134 {"swapoff", swap_on_off_main},
139 #ifdef BB_TOUCH //usr/bin
140 {"touch", touch_main},
142 #ifdef BB_TRUE_FALSE //bin
144 {"false", false_main},
146 #ifdef BB_UMOUNT //bin
147 {"umount", umount_main},
149 #ifdef BB_UPDATE //sbin
150 {"update", update_main},
154 {"gunzip", zcat_main},
162 int main(int argc, char **argv)
165 char *name = argv[0];
166 const struct Applet *a = applets;
173 while (a->name != 0) {
174 if (strcmp(name, a->name) == 0) {
177 status = ((*(a->main)) (argc, argv));
179 fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
181 fprintf(stderr, "\n");
186 exit (busybox_main(argc, argv));
190 int busybox_main(int argc, char **argv)
196 if (been_there_done_that == 1 || argc < 1) {
197 const struct Applet *a = applets;
198 fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n",
200 fprintf(stderr, "\nUsage:\t[function] [arguments]...\n");
201 fprintf(stderr, "\tbusybox [function] [arguments]...\n");
203 "\n\tMost people will create a symlink to busybox for each\n"
204 "\tfunction name, and busybox will act like whatever you invoke it as.\n");
205 fprintf(stderr, "\nCurrently defined functions:\n");
207 while (a->name != 0) {
208 col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), (a++)->name);
210 fprintf(stderr, ",\n");
214 fprintf(stderr, "\n\n");
217 /* If we've already been here once, exit now */
218 been_there_done_that = 1;
219 return (main(argc, argv));