changeset 36697:fe87abe38ef3

Improve testing of the help message header files. Add a check for conversion specification mismatches in the translation.
author ib
date Wed, 05 Feb 2014 17:21:59 +0000
parents 3bf334d01c59
children 6014c22afcd1
files help/help_check.sh
diffstat 1 files changed, 53 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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 <<EOF > ${CHECK}.c
 #include <inttypes.h>
 #include <string.h>
@@ -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