From fc0fbe6788845379ee39fa9d0182c9775b335725 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 12 Feb 2022 02:16:56 -0600 Subject: [PATCH] Move lib/lib.c into main.c so make.sh doesn't have to split it out seperately. (Nothing else in lib/ has to rebuild when command list changes.) --- lib/help.c | 45 --------------------------------------------- lib/lib.h | 4 ---- main.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ scripts/make.sh | 4 ++-- toys.h | 7 +++---- 5 files changed, 49 insertions(+), 55 deletions(-) delete mode 100644 lib/help.c diff --git a/lib/help.c b/lib/help.c deleted file mode 100644 index cd023026..00000000 --- a/lib/help.c +++ /dev/null @@ -1,45 +0,0 @@ -// Function to display help text - -#include "toys.h" - -#include "generated/help.h" - -#undef NEWTOY -#undef OLDTOY -#define NEWTOY(name,opt,flags) HELP_##name "\0" -#if CFG_TOYBOX -#define OLDTOY(name,oldname,flags) "\xff" #oldname "\0" -#else -#define OLDTOY(name, oldname, flags) HELP_##oldname "\0" -#endif -static char *help_data = -#include "generated/newtoys.h" -; - -void show_help(FILE *out, int full) -{ - int i = toys.which-toy_list; - char *s, *ss; - - if (!(full&2)) - fprintf(out, "Toybox %s" USE_TOYBOX(" multicall binary") - ": https://landley.net/toybox" - USE_TOYBOX(" (see toybox --help)") "\n\n", toybox_version); - - if (CFG_TOYBOX_HELP) { - for (;;) { - s = help_data; - while (i--) s += strlen(s) + 1; - // If it's an alias, restart search for real name - if (*s != 255) break; - i = toy_find(++s)-toy_list; - } - - if (full) fprintf(out, "%s\n", s); - else { - strstart(&s, "usage: "); - for (ss = s; *ss && *ss!='\n'; ss++); - fprintf(out, "%.*s\n", (int)(ss-s), s); - } - } -} diff --git a/lib/lib.h b/lib/lib.h index b825408a..08348d05 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -104,10 +104,6 @@ struct dirtree *dirtree_flagread(char *path, int flags, int (*callback)(struct dirtree *node)); struct dirtree *dirtree_read(char *path, int (*callback)(struct dirtree *node)); -// help.c - -void show_help(FILE *out, int full); - // Tell xopen and friends to print warnings but return -1 as necessary // The largest O_BLAH flag so far is arch/alpha's O_PATH at 0x800000 so // plenty of headroom. diff --git a/main.c b/main.c index d86a6ecd..95c42fa4 100644 --- a/main.c +++ b/main.c @@ -60,6 +60,50 @@ static const int NEED_OPTIONS = #include "generated/newtoys.h" 0; // Ends the opts || opts || opts... +// Populate help text array + +#undef NEWTOY +#undef OLDTOY +#define NEWTOY(name,opt,flags) HELP_##name "\0" +#if CFG_TOYBOX +#define OLDTOY(name,oldname,flags) "\xff" #oldname "\0" +#else +#define OLDTOY(name, oldname, flags) HELP_##oldname "\0" +#endif + +#include "generated/help.h" +static char *help_data = +#include "generated/newtoys.h" +; + +void show_help(FILE *out, int full) +{ + int i = toys.which-toy_list; + char *s, *ss; + + if (!(full&2)) + fprintf(out, "Toybox %s" USE_TOYBOX(" multicall binary") + ": https://landley.net/toybox" + USE_TOYBOX(" (see toybox --help)") "\n\n", toybox_version); + + if (CFG_TOYBOX_HELP) { + for (;;) { + s = help_data; + while (i--) s += strlen(s) + 1; + // If it's an alias, restart search for real name + if (*s != 255) break; + i = toy_find(++s)-toy_list; + } + + if (full) fprintf(out, "%s\n", s); + else { + strstart(&s, "usage: "); + for (ss = s; *ss && *ss!='\n'; ss++); + fprintf(out, "%.*s\n", (int)(ss-s), s); + } + } +} + static void unknown(char *name) { toys.exitval = 127; diff --git a/scripts/make.sh b/scripts/make.sh index 51100eec..a04d3306 100755 --- a/scripts/make.sh +++ b/scripts/make.sh @@ -82,8 +82,8 @@ TOYFILES="$($SED -n 's/^CONFIG_\([^=]*\)=.*/\1/p' "$KCONFIG_CONFIG" | xargs | tr TOYFILES="$(egrep -l "TOY[(]($TOYFILES)[ ,]" toys/*/*.c)" CFLAGS="$CFLAGS $(cat generated/cflags)" BUILD="$(echo ${CROSS_COMPILE}${CC} $CFLAGS -I . $OPTIMIZE $GITHASH)" -LIBFILES="$(ls lib/*.c | grep -v lib/help.c)" -TOYFILES="lib/help.c main.c $TOYFILES" +LIBFILES="$(ls lib/*.c)" +TOYFILES="main.c $TOYFILES" if [ "${TOYFILES/pending//}" != "$TOYFILES" ] then diff --git a/toys.h b/toys.h index 60e22467..81c49552 100644 --- a/toys.h +++ b/toys.h @@ -83,9 +83,10 @@ // These live in main.c struct toy_list *toy_find(char *name); -void toy_init(struct toy_list *which, char *argv[]); +void show_help(FILE *out, int full); void check_help(char **arg); void toy_singleinit(struct toy_list *which, char *argv[]); +void toy_init(struct toy_list *which, char *argv[]); void toy_exec(char *argv[]); // Array of available commands @@ -121,9 +122,7 @@ extern struct toy_context { // Two big temporary buffers: one for use by commands, one for library functions -extern char *toybox_version, toybuf[4096], libbuf[4096]; - -extern char **environ; +extern char **environ, *toybox_version, toybuf[4096], libbuf[4096]; #define FLAG(x) (toys.optflags&FLAG_##x) -- 2.39.2