#!/bin/sh
-usage() {
+usage()
+{
cat <<EOF
Usage: $0 <input> <output>
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}"
(
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}"
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
) >"${output}"
}
-gen_git() {
+gen_git()
+{
local output="$1"
shift
echo "generating ${output}"
) >"${output}"
}
-main() {
+main()
+{
case $# in
0) set -- "${0%/*}" "${0%/*}" ;;
2) ;;
/* 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