From d52e93c94784d59db2438383da868215b4847db1 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 30 Apr 2024 15:18:24 -0500 Subject: [PATCH] Create generated/tags.h with sed and bash instead of C. --- scripts/make.sh | 18 ++++++++++----- scripts/mktags.c | 58 ------------------------------------------------ 2 files changed, 12 insertions(+), 64 deletions(-) delete mode 100644 scripts/mktags.c diff --git a/scripts/make.sh b/scripts/make.sh index b94751dd1..ff677d5d4 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 05494b2a5..000000000 --- a/scripts/mktags.c +++ /dev/null @@ -1,58 +0,0 @@ -// Process TAGGED_ARRAY() macros to emit TAG_STRING index macros. - -#include -#include -#include -#include - -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); - } -}