[MPlayer-cvslog] r36793 - trunk/help/help_check.sh

ib subversion at mplayerhq.hu
Wed Feb 5 18:22:00 CET 2014


Author: ib
Date: Wed Feb  5 18:21:59 2014
New Revision: 36793

Log:
Improve testing of the help message header files.

Add a check for conversion specification mismatches in the translation.

Modified:
   trunk/help/help_check.sh

Modified: trunk/help/help_check.sh
==============================================================================
--- trunk/help/help_check.sh	Wed Feb  5 17:58:09 2014	(r36792)
+++ trunk/help/help_check.sh	Wed Feb  5 18:21:59 2014	(r36793)
@@ -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 @@ for h in "$@"; do
 #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


More information about the MPlayer-cvslog mailing list