changeset 234:163498bf547b

Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
author Rob Landley <rob@landley.net>
date Sat, 19 Jan 2008 17:43:27 -0600
parents d4176f3f3835
children 7cde22266e65
files Makefile lib/lib.c main.c scripts/make.sh toys.h toys/basename.c toys/bzcat.c toys/catv.c toys/chroot.c toys/chvt.c toys/count.c toys/df.c toys/dirname.c toys/dmesg.c toys/echo.c toys/false.c toys/hello.c toys/help.c toys/mke2fs.c toys/mkfifo.c toys/netcat.c toys/oneit.c toys/patch.c toys/pwd.c toys/readlink.c toys/sed.c toys/sha1sum.c toys/sleep.c toys/sync.c toys/touch.c toys/toylist.h toys/toysh.c toys/true.c toys/tty.c toys/which.c toys/yes.c
diffstat 36 files changed, 89 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Sat Jan 19 17:08:39 2008 -0600
+++ b/Makefile	Sat Jan 19 17:43:27 2008 -0600
@@ -34,7 +34,7 @@
 
 clean::
 	rm -f toybox toybox_unstripped generated/config.h generated/Config.in \
-		instlist
+		generated/newtoys.h instlist
 
 distclean: clean
 	rm -f toybox_old .config* generated/help.h
--- a/lib/lib.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/lib/lib.c	Sat Jan 19 17:43:27 2008 -0600
@@ -51,7 +51,7 @@
 
 	if (CFG_HELP && toys.exithelp) {
 		*toys.optargs=*toys.argv;
-		help_main();
+		USE_HELP(help_main();)  // dear gcc: shut up.
 		fprintf(stderr,"\n");
 	}
 
--- a/main.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/main.c	Sat Jan 19 17:43:27 2008 -0600
@@ -14,7 +14,7 @@
 #define OLDTOY(name, oldname, opts, flags) {#name, oldname##_main, opts, flags},
 
 struct toy_list toy_list[] = {
-#include "toys/toylist.h"
+#include "generated/newtoys.h"
 };
 
 #define TOY_LIST_LEN (sizeof(toy_list)/sizeof(struct toy_list))
@@ -59,7 +59,7 @@
 #define NEWTOY(name, opts, flags) opts ||
 #define OLDTOY(name, oldname, opts, flags) opts ||
 static const int NEED_OPTIONS =
-#include "toys/toylist.h"
+#include "generated/newtoys.h"
 0;  // Ends the opts || opts || opts...
 
 void toy_init(struct toy_list *which, char *argv[])
--- a/scripts/make.sh	Sat Jan 19 17:08:39 2008 -0600
+++ b/scripts/make.sh	Sat Jan 19 17:43:27 2008 -0600
@@ -7,6 +7,21 @@
 echo "Extract configuration information from toys/*.c files."
 scripts/genconfig.sh
 
+# Create a list of all the applets toybox can provide.  Note that the first
+# entry is out of order on purpose (the toybox multiplexer applet must be the
+# first element of the array).  The rest must be sorted in alphabetical order
+# for fast binary search.
+
+function newtoys()
+{
+  for i in toys/*.c
+  do
+    sed -n -e '1,/^config [A-Z]/s/^USE_/&/p' $i || exit 1
+  done
+}
+echo "NEWTOY(toybox, NULL, 0)" > generated/newtoys.h
+newtoys | sort >> generated/newtoys.h
+
 # Only recreate generated/help.h if python is installed
 if [ ! -z "$(which python)" ] && [ ! -z "$(grep 'CONFIG_HELP=y' .config)" ]
 then
--- a/toys.h	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys.h	Sat Jan 19 17:43:27 2008 -0600
@@ -41,6 +41,12 @@
 #include "toys/e2fs.h"
 #include "toys/toylist.h"
 
+// Get list of function prototypes for all enabled command_main() functions.
+
+#define NEWTOY(name, opts, flags) void name##_main(void);
+#define OLDTOY(name, oldname, opts, flags)
+#include "generated/newtoys.h"
+
 // These live in main.c
 
 struct toy_list *toy_find(char *name);
--- a/toys/basename.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/basename.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * See http://www.opengroup.org/onlinepubs/009695399/utilities/basename.html
 
+USE_BASENAME(NEWTOY(basename, "<1>2", TOYFLAG_BIN))
+
 config BASENAME
 	bool "basename"
 	default y
--- a/toys/bzcat.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/bzcat.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * Not in SUSv3.
 
+USE_BZCAT(NEWTOY(bzcat, NULL, TOYFLAG_USR|TOYFLAG_BIN))
+
 config BZCAT
 	bool "bzcat"
 	default n
--- a/toys/catv.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/catv.c	Sat Jan 19 17:43:27 2008 -0600
@@ -7,6 +7,8 @@
  * Not in SUSv3, but see "Cat -v considered harmful" at
  *   http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz
 
+USE_CATV(NEWTOY(catv, "vte", TOYFLAG_USR|TOYFLAG_BIN))
+
 config CATV
 	bool "catv"
 	default y
--- a/toys/chroot.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/chroot.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * Not in SUSv3.
 
+USE_CHROOT(NEWTOY(chroot, "<1", TOYFLAG_USR|TOYFLAG_SBIN))
+
 config CHROOT
 	bool "chroot"
 	default y
--- a/toys/chvt.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/chvt.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * Not in SUSv3.
 
+USE_CHVT(NEWTOY(chvt, "<1", TOYFLAG_USR|TOYFLAG_SBIN))
+
 config CHVT
 	bool "chvt"
 	default y
--- a/toys/count.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/count.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * Not in SUSv3.
 
+USE_COUNT(NEWTOY(count, NULL, TOYFLAG_USR|TOYFLAG_BIN))
+
 config COUNT
 	bool "count"
 	default y
--- a/toys/df.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/df.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * See http://www.opengroup.org/onlinepubs/009695399/utilities/df.html
 
+USE_DF(NEWTOY(df, "Pkt*a", TOYFLAG_USR|TOYFLAG_SBIN))
+
 config DF
 	bool "df (disk free)"
 	default y
--- a/toys/dirname.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/dirname.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * See http://www.opengroup.org/onlinepubs/009695399/utilities/dirname.html
 
+USE_DIRNAME(NEWTOY(dirname, "<1>1", TOYFLAG_BIN))
+
 config DIRNAME
 	bool "dirname"
 	default y
--- a/toys/dmesg.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/dmesg.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * Not in SUSv3.
 
+USE_DMESG(NEWTOY(dmesg, "s#n#c", TOYFLAG_BIN))
+
 config DMESG
 	bool "dmesg"
 	default y
--- a/toys/echo.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/echo.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * See http://www.opengroup.org/onlinepubs/009695399/utilities/echo.html
 
+USE_ECHO(NEWTOY(echo, "+en", TOYFLAG_BIN))
+
 config ECHO
 	bool "echo"
 	default y
--- a/toys/false.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/false.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,7 @@
  *
  * See http://www.opengroup.org/onlinepubs/009695399/utilities/false.html
 
+USE_FALSE(NEWTOY(false, NULL, TOYFLAG_BIN))
 
 config FALSE
 	bool "false"
--- a/toys/hello.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/hello.c	Sat Jan 19 17:43:27 2008 -0600
@@ -7,6 +7,8 @@
  * Not in SUSv3.
  * See http://www.opengroup.org/onlinepubs/009695399/utilities/
 
+USE_HELLO(NEWTOY(hello, NULL, TOYFLAG_USR|TOYFLAG_BIN))
+
 config HELLO
 	bool "hello"
 	default y
--- a/toys/help.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/help.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * Not in SUSv3, but exists as a bash builtin.
 
+USE_HELP(NEWTOY(help, "<1", TOYFLAG_BIN))
+
 config HELP
 	bool "help"
 	default y
@@ -31,7 +33,7 @@
 #define NEWTOY(name,opt,flags) help_##name "\0"
 #define OLDTOY(name,oldname,opts,flags) "\xff" #oldname "\0"
 static char *help_data =
-#include "toys/toylist.h"
+#include "generated/newtoys.h"
 ;
 
 void help_main(void)
--- a/toys/mke2fs.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/mke2fs.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * Not in SUSv3.
 
+USE_MKE2FS(NEWTOY(mke2fs, MKE2FS_OPTSTRING, TOYFLAG_SBIN))
+
 config MKE2FS
 	bool "mke2fs"
 	default n
--- a/toys/mkfifo.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/mkfifo.c	Sat Jan 19 17:43:27 2008 -0600
@@ -4,6 +4,8 @@
  *
  * See http://www.opengroup.org/onlinepubs/009695399/utilities/mkfifo.html
 
+USE_MKFIFO(NEWTOY(mkfifo, "<1m:", TOYFLAG_BIN))
+
 config MKFIFO
 	bool "mkfifo"
 	default y
--- a/toys/netcat.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/netcat.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,9 @@
  *
  * Not in SUSv3.
 
+USE_NETCAT(OLDTOY(nc, netcat, "i#w#l@p#s:q#f:e", TOYFLAG_BIN))
+USE_NETCAT(NEWTOY(netcat, "i#w#l@p#s:q#f:e", TOYFLAG_BIN))
+
 config NETCAT
 	bool "netcat"
 	default n
--- a/toys/oneit.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/oneit.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * Not in SUSv3.
 
+USE_ONEIT(NEWTOY(oneit, "+<1c:p", TOYFLAG_SBIN))
+
 config ONEIT
 	bool "oneit"
 	default y
--- a/toys/patch.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/patch.c	Sat Jan 19 17:43:27 2008 -0600
@@ -21,6 +21,8 @@
  * -F fuzz (number, default 2)
  * [file] which file to patch
 
+USE_PATCH(NEWTOY(patch, "up#i:R", TOYFLAG_USR|TOYFLAG_BIN))
+
 config PATCH
 	bool "patch"
 	default y
--- a/toys/pwd.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/pwd.c	Sat Jan 19 17:43:27 2008 -0600
@@ -8,6 +8,8 @@
  *
  * TODO: add -L -P
 
+USE_PWD(NEWTOY(pwd, NULL, TOYFLAG_BIN))
+
 config PWD
 	bool "pwd"
 	default y
--- a/toys/readlink.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/readlink.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * Not in SUSv3.
 
+USE_READLINK(NEWTOY(readlink, "<1f", TOYFLAG_BIN))
+
 config READLINK
 	bool "readlink"
 	default n
--- a/toys/sed.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/sed.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * See http://www.opengroup.org/onlinepubs/009695399/utilities/sed.c
 
+USE_SED(NEWTOY(sed, "irne*", TOYFLAG_BIN))
+
 config SED
 	bool "sed"
 	default n
--- a/toys/sha1sum.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/sha1sum.c	Sat Jan 19 17:43:27 2008 -0600
@@ -9,6 +9,8 @@
  *
  * Not in SUSv3.
 
+USE_SHA1SUM(NEWTOY(sha1sum, NULL, TOYFLAG_USR|TOYFLAG_BIN))
+
 config SHA1SUM
 	bool "sha1sum"
 	default y
--- a/toys/sleep.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/sleep.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * See http://www.opengroup.org/onlinepubs/009695399/utilities/sleep.html
 
+USE_SLEEP(NEWTOY(sleep, "<1", TOYFLAG_BIN))
+
 config SLEEP
 	bool "sleep"
 	default y
--- a/toys/sync.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/sync.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * Not in SUSv3.
 
+USE_SYNC(NEWTOY(sync, NULL, TOYFLAG_BIN))
+
 config SYNC
 	bool "sync"
 	default y
--- a/toys/touch.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/touch.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * See http://www.opengroup.org/onlinepubs/009695399/utilities/touch.html
 
+USE_TOUCH(NEWTOY(touch, "l#t:r:mca", TOYFLAG_BIN))
+
 config TOUCH
 	bool "touch"
 	default y
--- a/toys/toylist.h	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/toylist.h	Sat Jan 19 17:43:27 2008 -0600
@@ -5,13 +5,6 @@
  */
 
 
-// Provide function declarations and structs.  Note that main.c #includes this
-// file twice (with different macros) to populate toy_list[].
-
-#ifndef NEWTOY
-#define NEWTOY(name, opts, flags) void name##_main(void);
-#define OLDTOY(name, oldname, opts, flags)
-
 struct df_data {
 	struct arg_list *fstype;
 
@@ -126,48 +119,3 @@
 	char *options;
 	int flags;
 } toy_list[];
-
-#endif
-
-// List of all the applets toybox can provide.
-
-// This one is out of order on purpose: it's the first element in the array.
-
-NEWTOY(toybox, NULL, 0)
-
-// The rest of these are alphabetical, for binary search.
-
-USE_BASENAME(NEWTOY(basename, "<1>2", TOYFLAG_BIN))
-USE_BZCAT(NEWTOY(bzcat, NULL, TOYFLAG_USR|TOYFLAG_BIN))
-USE_CATV(NEWTOY(catv, "vte", TOYFLAG_USR|TOYFLAG_BIN))
-USE_CHROOT(NEWTOY(chroot, "<1", TOYFLAG_USR|TOYFLAG_SBIN))
-USE_CHVT(NEWTOY(chvt, "<1", TOYFLAG_USR|TOYFLAG_SBIN))
-USE_COUNT(NEWTOY(count, NULL, TOYFLAG_USR|TOYFLAG_BIN))
-USE_TOYSH(NEWTOY(cd, NULL, TOYFLAG_NOFORK))
-USE_DF(NEWTOY(df, "Pkt*a", TOYFLAG_USR|TOYFLAG_SBIN))
-USE_DIRNAME(NEWTOY(dirname, "<1>1", TOYFLAG_BIN))
-USE_DMESG(NEWTOY(dmesg, "s#n#c", TOYFLAG_BIN))
-USE_ECHO(NEWTOY(echo, "+en", TOYFLAG_BIN))
-USE_TOYSH(NEWTOY(exit, NULL, TOYFLAG_NOFORK))
-USE_FALSE(NEWTOY(false, NULL, TOYFLAG_BIN))
-USE_HELLO(NEWTOY(hello, NULL, TOYFLAG_USR|TOYFLAG_BIN))
-USE_HELP(NEWTOY(help, "<1", TOYFLAG_BIN))
-USE_MKE2FS(NEWTOY(mke2fs, MKE2FS_OPTSTRING, TOYFLAG_SBIN))
-USE_MKFIFO(NEWTOY(mkfifo, "<1m:", TOYFLAG_BIN))
-USE_NETCAT(OLDTOY(nc, netcat, "i#w#l@p#s:q#f:e", TOYFLAG_BIN))
-USE_NETCAT(NEWTOY(netcat, "i#w#l@p#s:q#f:e", TOYFLAG_BIN))
-USE_ONEIT(NEWTOY(oneit, "+<1c:p", TOYFLAG_SBIN))
-USE_PATCH(NEWTOY(patch, "up#i:R", TOYFLAG_USR|TOYFLAG_BIN))
-USE_PWD(NEWTOY(pwd, NULL, TOYFLAG_BIN))
-USE_READLINK(NEWTOY(readlink, "<1f", TOYFLAG_BIN))
-USE_SED(NEWTOY(sed, "irne*", TOYFLAG_BIN))
-USE_TOYSH(OLDTOY(sh, toysh, "c:i", TOYFLAG_BIN))
-USE_SHA1SUM(NEWTOY(sha1sum, NULL, TOYFLAG_USR|TOYFLAG_BIN))
-USE_SLEEP(NEWTOY(sleep, "<1", TOYFLAG_BIN))
-USE_SYNC(NEWTOY(sync, NULL, TOYFLAG_BIN))
-USE_TOUCH(NEWTOY(touch, "l#t:r:mca", TOYFLAG_BIN))
-USE_TOYSH(NEWTOY(toysh, "c:i", TOYFLAG_BIN))
-USE_TRUE(NEWTOY(true, NULL, TOYFLAG_BIN))
-USE_TTY(NEWTOY(tty, "s", TOYFLAG_BIN))
-USE_WHICH(NEWTOY(which, "a", TOYFLAG_USR|TOYFLAG_BIN))
-USE_YES(NEWTOY(yes, NULL, TOYFLAG_USR|TOYFLAG_BIN))
--- a/toys/toysh.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/toysh.c	Sat Jan 19 17:43:27 2008 -0600
@@ -16,6 +16,11 @@
  *
  * TODO: // Handle embedded NUL bytes in the command line.
 
+USE_TOYSH(NEWTOY(cd, NULL, TOYFLAG_NOFORK))
+USE_TOYSH(NEWTOY(exit, NULL, TOYFLAG_NOFORK))
+USE_TOYSH(OLDTOY(sh, toysh, "c:i", TOYFLAG_BIN))
+USE_TOYSH(NEWTOY(toysh, "c:i", TOYFLAG_BIN))
+
 config TOYSH
 	bool "sh (toysh)"
 	default y
--- a/toys/true.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/true.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * See http://www.opengroup.org/onlinepubs/009695399/utilities/true.html
 
+USE_TRUE(NEWTOY(true, NULL, TOYFLAG_BIN))
+
 config TRUE
 	bool "true"
 	default y
--- a/toys/tty.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/tty.c	Sat Jan 19 17:43:27 2008 -0600
@@ -5,6 +5,8 @@
  *
  * See http://www.opengroup.org/onlinepubs/009695399/utilities/tty.html
 
+USE_TTY(NEWTOY(tty, "s", TOYFLAG_BIN))
+
 config TTY
 	bool "tty"
 	default y
--- a/toys/which.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/which.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * Not in SUSv3.
 
+USE_WHICH(NEWTOY(which, "a", TOYFLAG_USR|TOYFLAG_BIN))
+
 config WHICH
 	bool "which"
 	default y
--- a/toys/yes.c	Sat Jan 19 17:08:39 2008 -0600
+++ b/toys/yes.c	Sat Jan 19 17:43:27 2008 -0600
@@ -6,6 +6,8 @@
  *
  * Not in SUSv3.
 
+USE_YES(NEWTOY(yes, NULL, TOYFLAG_USR|TOYFLAG_BIN))
+
 config YES
 	bool "yes"
 	default y