# HG changeset patch # User ib # Date 1391620919 0 # Node ID fe87abe38ef328d70b5e3ffb5bd6825bee04341c # Parent 3bf334d01c597728e587ba128e72a8c987e46668 Improve testing of the help message header files. Add a check for conversion specification mismatches in the translation. diff -r 3bf334d01c59 -r fe87abe38ef3 help/help_check.sh --- a/help/help_check.sh Wed Feb 05 16:58:09 2014 +0000 +++ b/help/help_check.sh Wed Feb 05 17:21:59 2014 +0000 @@ -1,14 +1,37 @@ #!/bin/sh -# Check help message header files. +# Check help message header files for conversion specifications and +# valid string constant definitions. CHECK=checkhelp +SYMCONST_REGEX="[A-Za-z0-9_]\\+" +CONVSPEC_REGEX="%[^diouxXeEfFgGaAcspn%]*[diouxXeEfFgGaAcspn%][0-9]*" +# the [0-9]* is for inttypes' printf specifier macros and hopefully won't hurt otherwise + trap "rm -f ${CHECK}.c ${CHECK}.o" EXIT CC=$1 shift +# gather definitions containing conversion specifications from master file + +while read line; do + + DEFINE=$(echo "$line" | sed -n "s:^[ \t]*#define[ \t]\+\($SYMCONST_REGEX\)[ \t]\+\(.*\):\1=\2:; s:'::g; s:=:=':p") + + case "$DEFINE" in + *%*) eval "$DEFINE'";; + esac + +done < help/help_mp-en.h + +# create statements from definitions in the translated header file for a test +# compilation and compare conversion specifications from the translated header +# file with those of the master file (if any specification in any of the two +# files) + for h in "$@"; do + cat < ${CHECK}.c #include #include @@ -16,7 +39,35 @@ #include "$h" void $CHECK () { EOF - sed -n "s:^[ \t]*#define[ \t]\+\([0-9A-Za-z_]\+\).*:strdup(\1);:p" "$h" >> ${CHECK}.c + + while read line; do + + DEFINE=$(echo "$line" | sed -n "s:^[ \t]*#define[ \t]\+\($SYMCONST_REGEX\)[ \t]\+\(.*\):NAME=\1;STRING=\2:; s:'::g; s:STRING=:STRING=':p") + + if [ "$DEFINE" ]; then + eval "$DEFINE'" + echo "strdup($NAME);" >> ${CHECK}.c + ANY_CONVSPEC="$(eval "echo \$${NAME} \${STRING}")" + else + ANY_CONVSPEC="" + fi + + case "$ANY_CONVSPEC" in + *%*) ;; + *) continue;; + esac + + CONVSPECS=$(echo $STRING | sed -n "s:[^%]*\($CONVSPEC_REGEX\)[^%]*: \1:gp") + MCONVSPECS=$(eval echo \$${NAME} | sed -n "s:[^%]*\($CONVSPEC_REGEX\)[^%]*: \1:gp") + + if [ "$CONVSPECS" != "$MCONVSPECS" ]; then + echo "$h: $NAME conversion specification mismatch:${MCONVSPECS:- (none)} has been translated${CONVSPECS:- (none)}" + exit 2 + fi + + done < "$h" + echo "}" >> ${CHECK}.c $CC -Werror -c -o ${CHECK}.o ${CHECK}.c || exit + done