aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2024-04-30 15:18:24 -0500
committerRob Landley <rob@landley.net>2024-04-30 15:18:24 -0500
commitd52e93c94784d59db2438383da868215b4847db1 (patch)
tree03a1b473936c6b863deb9870728213b52971d7a0
parent41e7186b012e864c6252e5c5a415fb4379503bfd (diff)
downloadtoybox-d52e93c94784d59db2438383da868215b4847db1.tar.gz
Create generated/tags.h with sed and bash instead of C.
-rwxr-xr-xscripts/make.sh18
-rw-r--r--scripts/mktags.c58
2 files changed, 12 insertions, 64 deletions
diff --git a/scripts/make.sh b/scripts/make.sh
index b94751dd..ff677d5d 100755
--- a/scripts/make.sh
+++ b/scripts/make.sh
@@ -212,12 +212,18 @@ fi
echo "} this;"
} > "$GENDIR"/globals.h || exit 1
-hostcomp mktags
-if isnewer tags.h toys
-then
- $SED -n '/TAGGED_ARRAY(/,/^)/{s/.*TAGGED_ARRAY[(]\([^,]*\),/\1/;p}' \
- toys/*/*.c lib/*.c | "$UNSTRIPPED"/mktags > "$GENDIR"/tags.h
-fi
+# Recreate tags.h
+$SED -ne '/TAGGED_ARRAY(/,/^)/{s/.*TAGGED_ARRAY[(]\([^,]*\),/\1/p' \
+ -e 's/[^{]*{"\([^"]*\)"[^{]*/ _\1/gp}' toys/*/*.c | tr '[:punct:]' _ | \
+while read i; do
+ [ "$i" = "${i#_}" ] && { HEAD="$i"; X=0; LL=; continue;}
+ for j in $i; do
+ [ $X -eq 32 ] && LL=LL
+ NAME="$HEAD$j"
+ printf "#define $NAME %*s%s\n#define _$NAME %*s%s\n" \
+ $((32-${#NAME})) "" "$X" $((31-${#NAME})) "" "(1$LL<<$((X++)))" || exit 1
+ done
+done > "$GENDIR"/tags.h || exit 1
# Create help.h, and zhelp.h if zcat enabled
hostcomp config2help
diff --git a/scripts/mktags.c b/scripts/mktags.c
deleted file mode 100644
index 05494b2a..00000000
--- a/scripts/mktags.c
+++ /dev/null
@@ -1,58 +0,0 @@
-// Process TAGGED_ARRAY() macros to emit TAG_STRING index macros.
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-
-int main(int argc, char *argv[])
-{
- char *tag = 0;
- int idx = 0;
-
- for (;;) {
- char *line = 0, *s;
- ssize_t len;
-
- len = getline(&line, (void *)&len, stdin);
- if (len<0) break;
- while (len && isspace(line[len-1])) line[--len]=0;
-
- // Very simple parser: If we haven't got a TAG then first line is TAG.
- // Then look for { followed by "str" (must be on same line, may have
- // more than one per line), for each one emit #define. Current TAG ended
- // by ) at start of line.
-
- if (!tag) {
- if (!isalpha(*line)) {
- fprintf(stderr, "bad tag %s\n", line);
- exit(1);
- }
- tag = strdup(line);
- idx = 0;
-
- continue;
- }
-
- for (s = line; isspace(*s); s++);
- if (*s == ')') tag = 0;
- else for (;;) {
- char *start;
-
- while (*s && *s != '{') s++;
- while (*s && *s != '"') s++;
- if (!*s) break;
-
- start = ++s;
- while (*s && *s != '"') {
- if (!isalpha(*s) && !isdigit(*s)) *s = '_';
- s++;
- }
- printf("#define %s_%*.*s %d\n", tag, -40, (int)(s-start), start, idx);
- printf("#define _%s_%*.*s (1%s<<%d)\n", tag, -39, (int)(s-start), start,
- idx>31 ? "LL": "", idx);
- idx++;
- }
- free(line);
- }
-}