]> granicus.if.org Git - strace/commitdiff
xlat: extend syntax
authorDmitry V. Levin <ldv@altlinux.org>
Wed, 18 Feb 2015 03:47:17 +0000 (03:47 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 19 Feb 2015 01:54:14 +0000 (01:54 +0000)
* xlat/gen.sh (gen_header): If the name of constant is specified with a
value, generate a default definition for the constant using this value.
* xlat/timerfdflags.in: Use extended syntax.

xlat/gen.sh
xlat/timerfdflags.in

index f2178405b3fc0824ea66dc1e3830ca464827a76d..1484fb59bdf1d515171c1d8d9cd96f7743c6d9f6 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/sh
 
-usage() {
+usage()
+{
        cat <<EOF
 Usage: $0 <input> <output>
 
@@ -10,7 +11,41 @@ EOF
        exit 1
 }
 
-gen_header() {
+cond_xlat()
+{
+       local line val m def xlat
+       line="$1"; shift
+
+       val="$(printf %s "${line}" | sed -n 's/^\([^[:space:]]\+\).*$/\1/p')"
+       m="${val%%|*}"
+       def="$(printf %s "${line}" |
+              sed -n 's/^[^[:space:]]\+[[:space:]]\+\([^[:space:]].*\)$/\1/p')"
+
+       if [ "${m}" = "${m#1<<}" ]; then
+               xlat="XLAT(${val}),"
+       else
+               m="${m#1<<}"
+               xlat=" { ${val}, \"${m}\" },"
+       fi
+
+       if [ -z "${def}" ]; then
+               cat <<-EOF
+               #if defined(${m}) || (defined(HAVE_DECL_${m}) && HAVE_DECL_${m})
+                ${xlat}
+               #endif
+               EOF
+       else
+               cat <<-EOF
+               #if !(defined(${m}) || (defined(HAVE_DECL_${m}) && HAVE_DECL_${m}))
+               # define ${m} ${def}
+               #endif
+                ${xlat}
+               EOF
+       fi
+}
+
+gen_header()
+{
        local input="$1" output="$2" name="$3"
        echo "generating ${output}"
        (
@@ -38,23 +73,22 @@ gen_header() {
                        unterminated=1
                        ;;
                [A-Z_]*)        # symbolic constants
-                       local m="${line%%|*}"
-                       [ -n "${unconditional}" ] ||
-                               echo "#if defined(${m}) || (defined(HAVE_DECL_${m}) && HAVE_DECL_${m})"
-                       echo "  XLAT(${line}),"
-                       [ -n "${unconditional}" ] ||
-                               echo "#endif"
+                       if [ -n "${unconditional}" ]; then
+                               echo " XLAT(${line}),"
+                       else
+                               cond_xlat "${line}"
+                       fi
                        ;;
                '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"
+                       m="${line%% *}"
+                       if [ -n "${unconditional}" ]; then
+                               echo " { ${line}, \"${line#1<<}\" },"
+                       else
+                               cond_xlat "${line}"
+                       fi
                        ;;
                [0-9]*) # numeric constants
-                       echo "  XLAT(${line}),"
+                       echo " XLAT(${line}),"
                        ;;
                *)      # verbatim lines
                        echo "${line}"
@@ -62,15 +96,16 @@ gen_header() {
                esac
        done < "${input}"
        if [ -n "${unterminated}" ]; then
-               echo "  /* this array should remain not NULL-terminated */"
+               echo " /* this array should remain not NULL-terminated */"
        else
-               echo "  XLAT_END"
+               echo " XLAT_END"
        fi
        echo "};"
        ) >"${output}"
 }
 
-gen_make() {
+gen_make()
+{
        local output="$1"
        local name
        shift
@@ -90,7 +125,8 @@ gen_make() {
        ) >"${output}"
 }
 
-gen_git() {
+gen_git()
+{
        local output="$1"
        shift
        echo "generating ${output}"
@@ -100,7 +136,8 @@ gen_git() {
        ) >"${output}"
 }
 
-main() {
+main()
+{
        case $# in
        0) set -- "${0%/*}" "${0%/*}" ;;
        2) ;;
index 7d529eba326dbb8aeea827513a7aef23fe18ef60..6c934bdc4c15d46b2a7caf2961f98631b41683fb 100644 (file)
@@ -1,21 +1,8 @@
 /* The Linux userspace headers didn't export these for a long time. */
 
-#ifndef TFD_TIMER_ABSTIME
-# define TFD_TIMER_ABSTIME (1 << 0)
+TFD_TIMER_ABSTIME (1 << 0)
+TFD_TIMER_CANCEL_ON_SET (1 << 1)
+#ifdef O_CLOEXEC
+TFD_CLOEXEC O_CLOEXEC
 #endif
-TFD_TIMER_ABSTIME
-
-#ifndef TFD_TIMER_CANCEL_ON_SET
-# define TFD_TIMER_CANCEL_ON_SET (1 << 1)
-#endif
-TFD_TIMER_CANCEL_ON_SET
-
-#if !defined TFD_CLOEXEC && defined O_CLOEXEC
-# define TFD_CLOEXEC O_CLOEXEC
-#endif
-TFD_CLOEXEC
-
-#ifndef TFD_NONBLOCK
-# define TFD_NONBLOCK O_NONBLOCK
-#endif
-TFD_NONBLOCK
+TFD_NONBLOCK O_NONBLOCK