Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 1 | #include "internal.h" |
| 2 | #include <stdio.h> |
| 3 | #include <string.h> |
| 4 | #include <errno.h> |
| 5 | |
| 6 | static int been_there_done_that = 0; |
| 7 | |
| 8 | static const struct Applet applets[] = { |
| 9 | |
| 10 | #ifdef BB_BUSYBOX //bin |
| 11 | {"busybox", busybox_main}, |
| 12 | #endif |
| 13 | #ifdef BB_BLOCK_DEVICE //sbin |
| 14 | {"block_device", block_device_main}, |
| 15 | #endif |
| 16 | #ifdef BB_CAT //bin |
Eric Andersen | e77ae3a | 1999-10-19 20:03:34 +0000 | [diff] [blame] | 17 | {"cat", cat_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 18 | #endif |
Eric Andersen | 1b61f41 | 1999-10-13 18:56:42 +0000 | [diff] [blame] | 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}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 23 | #endif |
| 24 | #ifdef BB_CHROOT //sbin |
| 25 | {"chroot", chroot_main}, |
| 26 | #endif |
| 27 | #ifdef BB_CLEAR //usr/bin |
| 28 | {"clear", clear_main}, |
| 29 | #endif |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 30 | #ifdef BB_CHVT //usr/bin |
| 31 | {"chvt", chvt_main}, |
| 32 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 33 | #ifdef BB_CP //bin |
Eric Andersen | f811e07 | 1999-10-09 00:25:00 +0000 | [diff] [blame] | 34 | {"cp", cp_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 35 | #endif |
| 36 | #ifdef BB_DATE //bin |
| 37 | {"date", date_main}, |
| 38 | #endif |
| 39 | #ifdef BB_DD //bin |
| 40 | {"dd", dd_main}, |
| 41 | #endif |
| 42 | #ifdef BB_DF //bin |
| 43 | {"df", df_main}, |
| 44 | #endif |
| 45 | #ifdef BB_DMESG //bin |
| 46 | {"dmesg", dmesg_main}, |
| 47 | #endif |
John Beppu | 7a98606 | 1999-12-09 18:29:29 +0000 | [diff] [blame] | 48 | #ifdef BB_DU //bin |
| 49 | {"du", du_main}, |
| 50 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 51 | #ifdef BB_DUTMP //usr/sbin |
Eric Andersen | e77ae3a | 1999-10-19 20:03:34 +0000 | [diff] [blame] | 52 | {"dutmp", dutmp_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 53 | #endif |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 54 | #ifdef BB_FBSET //usr/sbin |
| 55 | {"fbset", fbset_main}, |
| 56 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 57 | #ifdef BB_FDFLUSH //bin |
Eric Andersen | f6be944 | 1999-10-13 21:12:06 +0000 | [diff] [blame] | 58 | {"fdflush", fdflush_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 59 | #endif |
| 60 | #ifdef BB_FIND //usr/bin |
| 61 | {"find", find_main}, |
| 62 | #endif |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 63 | #ifdef BB_FREE //usr/bin |
| 64 | {"free", free_main}, |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 65 | #endif |
| 66 | #ifdef BB_DEALLOCVT //usr/bin |
| 67 | {"deallocvt", deallocvt_main}, |
| 68 | #endif |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 69 | #ifdef BB_FSCK_MINIX //sbin |
| 70 | {"fsck.minix", fsck_minix_main}, |
| 71 | #endif |
| 72 | #ifdef BB_MKFS_MINIX //sbin |
| 73 | {"mkfs.minix", mkfs_minix_main}, |
| 74 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 75 | #ifdef BB_GREP //bin |
| 76 | {"grep", grep_main}, |
| 77 | #endif |
| 78 | #ifdef BB_HALT //sbin |
| 79 | {"halt", halt_main}, |
| 80 | #endif |
John Beppu | 3157b1f | 1999-12-10 07:42:50 +0000 | [diff] [blame] | 81 | #ifdef BB_HEAD //bin |
| 82 | {"head", head_main}, |
| 83 | #endif |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 84 | #ifdef BB_HOSTNAME //bin |
| 85 | {"hostname", hostname_main}, |
| 86 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 87 | #ifdef BB_INIT //sbin |
| 88 | {"init", init_main}, |
| 89 | #endif |
Erik Andersen | 6da0ae8 | 1999-12-17 01:08:27 +0000 | [diff] [blame] | 90 | #ifdef BB_INSMOD //sbin |
| 91 | {"insmod", insmod_main}, |
| 92 | #endif |
Eric Andersen | 6a76e65 | 1999-11-19 05:31:45 +0000 | [diff] [blame] | 93 | #ifdef BB_FEATURE_LINUXRC // |
| 94 | {"linuxrc", init_main}, |
| 95 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 96 | #ifdef BB_KILL //bin |
| 97 | {"kill", kill_main}, |
| 98 | #endif |
| 99 | #ifdef BB_LENGTH //usr/bin |
| 100 | {"length", length_main}, |
| 101 | #endif |
| 102 | #ifdef BB_LN //bin |
Eric Andersen | f6be944 | 1999-10-13 21:12:06 +0000 | [diff] [blame] | 103 | {"ln", ln_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 104 | #endif |
Erik Andersen | 7dc1607 | 2000-01-04 01:10:25 +0000 | [diff] [blame] | 105 | #ifdef BB_LOADACM //usr/bin |
| 106 | {"loadacm", loadacm_main}, |
| 107 | #endif |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 108 | #ifdef BB_LOADFONT //usr/bin |
| 109 | {"loadfont", loadfont_main}, |
| 110 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 111 | #ifdef BB_LOADKMAP //sbin |
| 112 | {"loadkmap", loadkmap_main}, |
| 113 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 114 | #ifdef BB_LS //bin |
| 115 | {"ls", ls_main}, |
| 116 | #endif |
Erik Andersen | 6f23cec | 1999-12-15 22:14:12 +0000 | [diff] [blame] | 117 | #ifdef BB_LSMOD //sbin |
| 118 | {"lsmod", lsmod_main}, |
| 119 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 120 | #ifdef BB_MAKEDEVS //sbin |
| 121 | {"makedevs", makedevs_main}, |
| 122 | #endif |
| 123 | #ifdef BB_MATH //usr/bin |
| 124 | {"math", math_main}, |
| 125 | #endif |
| 126 | #ifdef BB_MKDIR //bin |
Eric Andersen | f6be944 | 1999-10-13 21:12:06 +0000 | [diff] [blame] | 127 | {"mkdir", mkdir_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 128 | #endif |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 129 | #ifdef BB_MKFIFO //usr/bin |
| 130 | {"mkfifo", mkfifo_main}, |
| 131 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 132 | #ifdef BB_MKNOD //bin |
| 133 | {"mknod", mknod_main}, |
| 134 | #endif |
| 135 | #ifdef BB_MKSWAP //sbin |
| 136 | {"mkswap", mkswap_main}, |
| 137 | #endif |
| 138 | #ifdef BB_MNC //usr/bin |
| 139 | {"mnc", mnc_main}, |
| 140 | #endif |
| 141 | #ifdef BB_MORE //bin |
Eric Andersen | 4bea32a | 1999-10-06 00:30:51 +0000 | [diff] [blame] | 142 | {"more", more_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 143 | #endif |
| 144 | #ifdef BB_MOUNT //bin |
| 145 | {"mount", mount_main}, |
| 146 | #endif |
| 147 | #ifdef BB_MT //bin |
| 148 | {"mt", mt_main}, |
| 149 | #endif |
| 150 | #ifdef BB_MV //bin |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 151 | {"mv", mv_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 152 | #endif |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 153 | #ifdef BB_PING //bin |
| 154 | {"ping", ping_main}, |
| 155 | #endif |
Eric Andersen | 2cb5507 | 1999-12-10 08:25:07 +0000 | [diff] [blame] | 156 | #ifdef BB_POWEROFF //sbin |
| 157 | {"poweroff", poweroff_main}, |
| 158 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 159 | #ifdef BB_PRINTF //usr/bin |
| 160 | {"printf", printf_main}, |
| 161 | #endif |
Eric Andersen | ef8b6c7 | 1999-10-20 08:05:35 +0000 | [diff] [blame] | 162 | #ifdef BB_PS //bin |
| 163 | {"ps", ps_main}, |
| 164 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 165 | #ifdef BB_PWD //bin |
| 166 | {"pwd", pwd_main}, |
| 167 | #endif |
| 168 | #ifdef BB_REBOOT //sbin |
| 169 | {"reboot", reboot_main}, |
| 170 | #endif |
| 171 | #ifdef BB_RM //bin |
| 172 | {"rm", rm_main}, |
| 173 | #endif |
| 174 | #ifdef BB_RMDIR //bin |
Eric Andersen | f6be944 | 1999-10-13 21:12:06 +0000 | [diff] [blame] | 175 | {"rmdir", rmdir_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 176 | #endif |
Erik Andersen | 3d7e341 | 1999-12-16 23:04:20 +0000 | [diff] [blame] | 177 | #ifdef BB_RMMOD //sbin |
| 178 | {"rmmod", rmmod_main}, |
| 179 | #endif |
Eric Andersen | e77ae3a | 1999-10-19 20:03:34 +0000 | [diff] [blame] | 180 | #ifdef BB_SFDISK //sbin |
| 181 | {"fdisk", sfdisk_main}, |
| 182 | {"sfdisk", sfdisk_main}, |
| 183 | #endif |
Eric Andersen | c1525e8 | 1999-10-29 00:07:31 +0000 | [diff] [blame] | 184 | #ifdef BB_SED //bin |
| 185 | {"sed", sed_main}, |
| 186 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 187 | #ifdef BB_SLEEP //bin |
| 188 | {"sleep", sleep_main}, |
| 189 | #endif |
John Beppu | 019513a | 1999-12-22 17:57:31 +0000 | [diff] [blame] | 190 | #ifdef BB_SORT //bin |
| 191 | {"sort", sort_main}, |
| 192 | #endif |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 193 | #ifdef BB_SYNC //bin |
| 194 | {"sync", sync_main}, |
| 195 | #endif |
| 196 | #ifdef BB_SYSLOGD //sbin |
| 197 | {"syslogd", syslogd_main}, |
| 198 | #endif |
| 199 | #ifdef BB_LOGGER //usr/bin |
| 200 | {"logger", logger_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 201 | #endif |
Eric Andersen | 8759006 | 1999-10-18 21:22:59 +0000 | [diff] [blame] | 202 | #ifdef BB_SWAPONOFF //sbin |
| 203 | {"swapon", swap_on_off_main}, |
| 204 | {"swapoff", swap_on_off_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 205 | #endif |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 206 | #ifdef BB_TAIL //usr/bin |
| 207 | {"tail", tail_main}, |
| 208 | #endif |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 209 | #ifdef BB_TAR //bin |
| 210 | {"tar", tar_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 211 | #endif |
John Beppu | 059f152 | 1999-12-10 05:27:16 +0000 | [diff] [blame] | 212 | #ifdef BB_TEE //bin |
| 213 | {"tee", tee_main}, |
| 214 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 215 | #ifdef BB_TOUCH //usr/bin |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 216 | {"touch", touch_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 217 | #endif |
Eric Andersen | a3f0907 | 1999-10-19 16:39:10 +0000 | [diff] [blame] | 218 | #ifdef BB_TRUE_FALSE //bin |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 219 | {"true", true_main}, |
Eric Andersen | a3f0907 | 1999-10-19 16:39:10 +0000 | [diff] [blame] | 220 | {"false", false_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 221 | #endif |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 222 | #ifdef BB_UNAME //bin |
| 223 | {"uname", uname_main}, |
| 224 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 225 | #ifdef BB_UMOUNT //bin |
Eric Andersen | 8759006 | 1999-10-18 21:22:59 +0000 | [diff] [blame] | 226 | {"umount", umount_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 227 | #endif |
John Beppu | abb4772 | 2000-01-06 00:48:21 +0000 | [diff] [blame^] | 228 | #ifdef BB_UNIQ //bin |
| 229 | {"uniq", uniq_main}, |
| 230 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 231 | #ifdef BB_UPDATE //sbin |
| 232 | {"update", update_main}, |
| 233 | #endif |
Eric Andersen | d80e851 | 1999-11-16 00:46:00 +0000 | [diff] [blame] | 234 | #ifdef BB_GUNZIP //bin |
| 235 | {"zcat", gunzip_main}, |
| 236 | {"gunzip", gunzip_main}, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 237 | #endif |
| 238 | #ifdef BB_GZIP //bin |
| 239 | {"gzip", gzip_main}, |
| 240 | #endif |
| 241 | {0} |
| 242 | }; |
| 243 | |
| 244 | int main(int argc, char **argv) |
| 245 | { |
| 246 | char *s = argv[0]; |
| 247 | char *name = argv[0]; |
| 248 | const struct Applet *a = applets; |
| 249 | |
| 250 | while (*s != '\0') { |
| 251 | if (*s++ == '/') |
| 252 | name = s; |
| 253 | } |
| 254 | |
| 255 | while (a->name != 0) { |
| 256 | if (strcmp(name, a->name) == 0) { |
| 257 | int status; |
| 258 | |
| 259 | status = ((*(a->main)) (argc, argv)); |
| 260 | if (status < 0) { |
| 261 | fprintf(stderr, "%s: %s\n", a->name, strerror(errno)); |
| 262 | } |
| 263 | fprintf(stderr, "\n"); |
| 264 | exit(status); |
| 265 | } |
| 266 | a++; |
| 267 | } |
Eric Andersen | 2ce1edc | 1999-10-12 15:42:48 +0000 | [diff] [blame] | 268 | exit (busybox_main(argc, argv)); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | |
| 272 | int busybox_main(int argc, char **argv) |
| 273 | { |
Eric Andersen | 17d49ef | 1999-10-06 20:25:32 +0000 | [diff] [blame] | 274 | int col=0; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 275 | argc--; |
| 276 | argv++; |
| 277 | |
Eric Andersen | c6cb79d | 1999-10-13 18:01:10 +0000 | [diff] [blame] | 278 | if (been_there_done_that == 1 || argc < 1) { |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 279 | const struct Applet *a = applets; |
Eric Andersen | d73dc5b | 1999-11-10 23:13:02 +0000 | [diff] [blame] | 280 | fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 281 | BB_VER, BB_BT); |
Eric Andersen | d73dc5b | 1999-11-10 23:13:02 +0000 | [diff] [blame] | 282 | fprintf(stderr, "Usage: busybox [function] [arguments]...\n"); |
| 283 | fprintf(stderr, " or: [function] [arguments]...\n\n"); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 284 | fprintf(stderr, |
Eric Andersen | d73dc5b | 1999-11-10 23:13:02 +0000 | [diff] [blame] | 285 | "\tMost people will create a symlink to busybox for each\n" |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 286 | "\tfunction name, and busybox will act like whatever you invoke it as.\n"); |
| 287 | fprintf(stderr, "\nCurrently defined functions:\n"); |
| 288 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 289 | while (a->name != 0) { |
Eric Andersen | 2ce1edc | 1999-10-12 15:42:48 +0000 | [diff] [blame] | 290 | col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), (a++)->name); |
Eric Andersen | 17d49ef | 1999-10-06 20:25:32 +0000 | [diff] [blame] | 291 | if (col>60) { |
| 292 | fprintf(stderr, ",\n"); |
| 293 | col=0; |
| 294 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 295 | } |
| 296 | fprintf(stderr, "\n\n"); |
| 297 | exit(-1); |
Eric Andersen | c6cb79d | 1999-10-13 18:01:10 +0000 | [diff] [blame] | 298 | } else { |
| 299 | /* If we've already been here once, exit now */ |
| 300 | been_there_done_that = 1; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 301 | return (main(argc, argv)); |
Eric Andersen | c6cb79d | 1999-10-13 18:01:10 +0000 | [diff] [blame] | 302 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 303 | } |