aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-12-31 21:30:59 -0600
committerRob Landley <rob@landley.net>2014-12-31 21:30:59 -0600
commitf3e56f4e4ff773de95fa2c9daf979734d826fc33 (patch)
tree8a8e75b3530b504569ebe4fae09020073534c6db /scripts
parent5834ddd6df659d9c9dc7333284fc86762dea061a (diff)
downloadtoybox-f3e56f4e4ff773de95fa2c9daf979734d826fc33.tar.gz
Redo option parsing infrastructure so #define FORCE_FLAGS can unzero flag macros for a disabled command (needed when multiple commands share infrastructure with a common set of flags).
This means the flag space is no longer packed, but leaves gaps where the zeroes go. (Actual flag bit positions are the same for all configs.) Since the option parsing needs to know where the holes are, the OPTSTR values are now generated as part of flags.h with ascii 1 values for the disabled values. (So generated/oldflags.h went away.) This also means that the option string argument for OLDTOY() went away, it now uses the same arguments as the NEWTOY() it references.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/make.sh4
-rw-r--r--scripts/mkflags.c66
2 files changed, 58 insertions, 12 deletions
diff --git a/scripts/make.sh b/scripts/make.sh
index 1cbe5e0f..b91576ee 100755
--- a/scripts/make.sh
+++ b/scripts/make.sh
@@ -50,9 +50,7 @@ then
echo "USE_TOYBOX(NEWTOY(toybox, NULL, TOYFLAG_STAYROOT))" > generated/newtoys.h
sed -n -e 's/^USE_[A-Z0-9_]*(/&/p' toys/*/*.c \
| sed 's/\(.*TOY(\)\([^,]*\),\(.*\)/\2 \1\2,\3/' | sort -s -k 1,1 \
- | sed 's/[^ ]* //' >> generated/newtoys.h &&
- sed -n -e 's/.*(NEWTOY(\([^,]*\), *\(\("[^"]*"[^,]*\)*\),.*/#define OPTSTR_\1\t\2/p' \
- generated/newtoys.h > generated/oldtoys.h || exit 1
+ | sed 's/[^ ]* //' >> generated/newtoys.h || exit 1
fi
[ ! -z "$V" ] && echo "Which C files to build..."
diff --git a/scripts/mkflags.c b/scripts/mkflags.c
index 23cb83e8..454fc030 100644
--- a/scripts/mkflags.c
+++ b/scripts/mkflags.c
@@ -17,11 +17,42 @@ struct flag {
struct flag *lopt;
};
+// replace chopped out USE_BLAH() sections with low-ascii characters
+// showing how many flags got skipped
+
+char *mark_gaps(char *flags, char *all)
+{
+ char *n, *new, c;
+
+ // Shell feeds in " " for blank args, leading space not meaningful.
+ while (isspace(*flags)) flags++;
+ while (isspace(*all)) all++;
+
+ n = new = strdup(all);
+ while (*all) {
+ if (*flags == *all) {
+ *(new++) = *(all++);
+ *flags++;
+ continue;
+ }
+
+ c = *(all++);
+ if (strchr("?&^-:#|@*; ", c));
+ else if (strchr("=<>", c)) while (isdigit(*all)) all++;
+ else if (c == '(') while(*(all++) != ')');
+ else *(new++) = 1;
+ }
+ *new = 0;
+
+ return n;
+}
+
// Break down a command string into struct flag list.
struct flag *digest(char *string)
{
struct flag *list = NULL;
+ char *err = string;
while (*string) {
// Groups must be at end.
@@ -52,6 +83,10 @@ struct flag *digest(char *string)
if (strchr("?&^-:#|@*; ", *string)) string++;
else if (strchr("=<>", *string)) {
+ if (!isdigit(string[1])) {
+ fprintf(stderr, "%c without number in '%s'", *string, err);
+ exit(1);
+ }
while (isdigit(*++string)) {
if (!list) {
string++;
@@ -79,8 +114,12 @@ int main(int argc, char *argv[])
// See "intentionally crappy", above.
if (!(out = outbuf)) return 1;
+ printf("#ifdef FORCE_FLAGS\n#define FORCED_FLAG 1\n"
+ "#else\n#define FORCED_FLAG 0\n#endif\n\n");
+
for (;;) {
struct flag *flist, *aflist, *offlist;
+ char *gaps, *mgaps, c;
unsigned bit;
*command = 0;
@@ -95,6 +134,16 @@ int main(int argc, char *argv[])
bit = 0;
printf("// %s %s %s\n", command, flags, allflags);
+ mgaps = mark_gaps(flags, allflags);
+ for (gaps = mgaps; *gaps == 1; gaps++);
+ if (*gaps) c = '"';
+ else {
+ c = ' ';
+ gaps = "0";
+ }
+ printf("#undef OPTSTR_%s\n#define OPTSTR_%s %c%s%c\n",
+ command, command, c, gaps, c);
+ free(mgaps);
flist = digest(flags);
offlist = aflist = digest(allflags);
@@ -124,29 +173,28 @@ int main(int argc, char *argv[])
{
sprintf(out, "#define FLAG_%s (1<<%d)\n", flist->lopt->command, bit);
flist->lopt = flist->lopt->next;
- } else sprintf(out, "#define FLAG_%s 0\n", aflist->lopt->command);
+ } else sprintf(out, "#define FLAG_%s (FORCED_FLAG<<%d)\n",
+ aflist->lopt->command, bit);
aflist->lopt = aflist->lopt->next;
if (!aflist->command) {
aflist = aflist->next;
- if (flist) {
- flist = flist->next;
- bit++;
- }
+ bit++;
+ if (flist) flist = flist->next;
}
} else if (aflist->command) {
if (flist && (!aflist->command || *aflist->command == *flist->command))
{
if (aflist->command)
sprintf(out, "#define FLAG_%c (1<<%d)\n", *aflist->command, bit);
- bit++;
flist = flist->next;
- } else sprintf(out, "#define FLAG_%c 0\n", *aflist->command);
+ } else sprintf(out, "#define FLAG_%c (FORCED_FLAG<<%d)\n",
+ *aflist->command, bit);
+ bit++;
aflist = aflist->next;
}
out += strlen(out);
}
- sprintf(out, "#endif\n\n");
- out += strlen(out);
+ out = stpcpy(out, "#endif\n\n");
}
if (fflush(0) && ferror(stdout)) return 1;