summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@altlinux.org>2014-04-25 23:04:13 +0000
committerDmitry V. Levin <ldv@altlinux.org>2014-05-30 21:33:02 +0000
commit5153b5cd681a4091d378883d06291b5bcb963e69 (patch)
treef91414fa6886d41c7fc81666749a77f227e99efe
parent3e69bdf41a1c272028d9347bc55d7f73e3c4de46 (diff)
downloadstrace-5153b5cd681a4091d378883d06291b5bcb963e69.tar.gz
Enhance xlat generator
* 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.
-rwxr-xr-xxlat/gen.sh59
1 files changed, 48 insertions, 11 deletions
diff --git a/xlat/gen.sh b/xlat/gen.sh
index 23d5b8d8f..f2178405b 100755
--- a/xlat/gen.sh
+++ b/xlat/gen.sh
@@ -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}" &