]> granicus.if.org Git - strace/commitdiff
Enhance xlat generator
authorDmitry V. Levin <ldv@altlinux.org>
Fri, 25 Apr 2014 23:04:13 +0000 (23:04 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 30 May 2014 21:33:02 +0000 (21:33 +0000)
* xlat/gen.sh: Define all xlat structs not declared in defs.h as static.
Some symbolic constants are not macros, extend #ifdef check to cover
symbolic constants checked by AC_CHECK_DECLS.
Handle complex symbolic constants in SYMBOL|... form.
Handle symbolic constants in 1<<SYMBOL form.
Handle numeric constants.
Implement #unconditional directive that turns off preprocessor checks.
Implement #unterminated directive that turns off adding XLAT_END.

xlat/gen.sh

index 23d5b8d8f0c6d9d80e1831f2238838f475da3639..f2178405b3fc0824ea66dc1e3830ca464827a76d 100755 (executable)
@@ -12,24 +12,60 @@ EOF
 
 gen_header() {
        local input="$1" output="$2" name="$3"
-       local line
        echo "generating ${output}"
        (
-       echo "/* Generated by $0 from $1; do not edit. */"
-       echo "const struct xlat ${name}[] = {"
-       while read line ; do
+       local defs="${0%/*}/../defs.h"
+       local prefix
+       if grep -x "extern const struct xlat ${name}\\[\\];" "${defs}" > /dev/null; then
+               prefix=
+       else
+               prefix='static '
+       fi
+
+       cat <<-EOF
+               /* Generated by $0 from $1; do not edit. */
+
+               ${prefix}const struct xlat ${name}[] = {
+       EOF
+       local unconditional= unterminated= line
+       while read line; do
+               LC_COLLATE=C
                case ${line} in
-               /*|\#*|'')
-                       echo "${line}"
+               '#unconditional')
+                       unconditional=1
+                       ;;
+               '#unterminated')
+                       unterminated=1
                        ;;
-               *)
-                       echo "#ifdef ${line}"
+               [A-Z_]*)        # symbolic constants
+                       local m="${line%%|*}"
+                       [ -n "${unconditional}" ] ||
+                               echo "#if defined(${m}) || (defined(HAVE_DECL_${m}) && HAVE_DECL_${m})"
                        echo "  XLAT(${line}),"
-                       echo "#endif"
+                       [ -n "${unconditional}" ] ||
+                               echo "#endif"
+                       ;;
+               '1<<'[A-Z_]*)   # symbolic constants with shift
+                       local m="${line#1<<}"
+                       [ -n "${unconditional}" ] ||
+                               echo "#if defined(${m}) || (defined(HAVE_DECL_${m}) && HAVE_DECL_${m})"
+                       echo "  { ${line}, \"${m}\" },"
+                       [ -n "${unconditional}" ] ||
+                               echo "#endif"
+                       ;;
+               [0-9]*) # numeric constants
+                       echo "  XLAT(${line}),"
+                       ;;
+               *)      # verbatim lines
+                       echo "${line}"
                        ;;
                esac
        done < "${input}"
-       echo "  XLAT_END"
+       if [ -n "${unterminated}" ]; then
+               echo "  /* this array should remain not NULL-terminated */"
+       else
+               echo "  XLAT_END"
+       fi
        echo "};"
        ) >"${output}"
 }
@@ -76,8 +112,9 @@ main() {
        local name
 
        if [ -d "${input}" ]; then
-               local f name names
+               local f names=
                for f in "${input}"/*.in; do
+                       [ -f "${f}" ] || continue
                        name=${f##*/}
                        name=${name%.in}
                        gen_header "${f}" "${output}/${name}.h" "${name}" &