From 6cf0a115451d6d5ead94860f0731040dc2293db0 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 26 Nov 2012 14:14:29 -0600 Subject: Cleanup i18n support (#ifdefectomy, move global init to process launch). Teach make.sh to emit "#define FLAG_x 0" for options inside disabled USE macros so we can unconditionally refer to them. --- scripts/make.sh | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'scripts/make.sh') diff --git a/scripts/make.sh b/scripts/make.sh index f9fa0a40..921d1994 100755 --- a/scripts/make.sh +++ b/scripts/make.sh @@ -54,11 +54,27 @@ sed -n -e 's/^USE_[A-Z0-9_]*(/&/p' toys/*/*.c \ | sed 's/\(.*TOY(\)\([^,]*\),\(.*\)/\2 \1\2,\3/' | sort -k 1,1 \ | sed 's/[^ ]* //' >> generated/newtoys.h +# Extract list of command letters from processed header file + +function getflags() +{ + sed -n -e "s/.*TOY($1"',[ \t]*"\([^"]*\)"[ \t]*,.*)/\1/' \ + -e 't keep;d;:keep' -e 's/^[<>=][0-9]//' -e 's/[?&^]//' \ + -e 't keep' -e 's/[><=][0-9][0-9]*//g' -e 's/+.//g' \ + -e 's/([^)]*)//g' -e 's/\[[^]]*\]//g' -e 's/[-?^:&#|@*]//g' -e 'p' +} + # Extract global structure definitions and flag definitions from toys/*/*.c function getglobals() { + # Run newtoys.h through the compiler's preprocessor to resolve USE macros + # against current config. NEWTOYS="$(cat generated/config.h generated/newtoys.h | gcc -E - | sed 's/" *"//g')" + + # Grab allyesconfig for comparison + ALLTOYS="$((sed '/USE_.*([^)]*)$/s/$/ __VA_ARGS__/' generated/config.h && cat generated/newtoys.h) | gcc -E - | sed 's/" *"//g')" + for i in toys/*/*.c do NAME="$(echo $i | sed 's@.*/\(.*\)\.c@\1@')" @@ -68,13 +84,9 @@ function getglobals() -e 's/^GLOBALS(/struct '"$NAME"'_data {/' \ -e 's/^)/};/' -e 'p' $i - # And get flag definitions - FLAGS="$(echo "$NEWTOYS" | sed -n \ - -e "s/.*TOY($NAME"',[ \t]*"\([^"]*\)"[ \t]*,.*)/\1/' \ - -e 't keep;d;:keep' -e 's/^[<>=][0-9]//' -e 's/[?&^]//' \ - -e 't keep' -e 's/[><=][0-9][0-9]*//g' -e 's/+.//g' \ - -e 's/([^)]*)//g' -e 's/\[[^]]*\]//g' -e 's/[-?^:&#|@*]//g' \ - -e 'p')" + FLAGS="$(echo "$NEWTOYS" | getflags "$NAME")" + ZFLAGS="$(echo "$ALLTOYS" | getflags "$NAME" | sed 's/[-'"$FLAGS"']//g')" + echo "#ifdef FOR_${NAME}" X=0 while [ $X -lt ${#FLAGS} ] @@ -83,6 +95,12 @@ function getglobals() X=$(($X+1)) echo "(1<<$((${#FLAGS}-$X)))" done + X=0 + while [ $X -lt ${#ZFLAGS} ] + do + echo "#define FLAG_${ZFLAGS:$X:1} 0" + X=$(($X+1)) + done echo "#define TT this.${NAME}" echo "#endif" done -- cgit v1.2.3