# along with this program; if not, write to the Free Software
# Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
-# Usage: opts.sh outfile.c outfile.h file1.opt [file2.opt, ...]
+# Usage: opts.sh moveifchange srcdir outfile.c outfile.h file1.opt [ ...]
# Always operate in the C locale.
LANG=C
SORT=sort # Could be /bin/sort or /usr/bin/sort
+MOVEIFCHANGE=$1; shift
C_FILE=$1; shift
H_FILE=$1; shift
+TMP_C_FILE=tmp-${C_FILE}
+TMP_H_FILE=tmp-${H_FILE}
${AWK} '
# Ignore comments and blank lines
/^[ \t]*(;|$)/ { next }
# Note that RS="" falls foul of gawk 3.1.2 bugs
- /^[^ \t]/ { getline tmp; print $0 "\034" tmp}
+ /^[^ \t]/ { record = $0
+ do { getline tmp;
+ if (!(tmp ~ "^[ \t]*(;|$)"))
+ record = record "\034" tmp
+ } while (tmp != "")
+ print record
+ }
' "$@" | ${SORT} | ${AWK} '
function switch_flags (flags, result)
{
if (flags ~ " Separate ") result = result " | CL_SEPARATE"
if (flags ~ " RejectNegative ") result = result " | CL_REJECT_NEGATIVE"
if (flags ~ " UInteger ") result = result " | CL_UINTEGER"
+ if (flags ~ " Undocumented ") result = result " | CL_UNDOCUMENTED"
sub( "^0 \\| ", "", result )
return result
}
} else {
opts[n_opts] = $1
flags[n_opts] = $2
+ help[n_opts] = $3
n_opts++;
}
}
# Dump out an enumeration into a .h file, and an array of options into a
# C file. Combine the flags of duplicate options.
END {
- c_file = "'${C_FILE}'"
- h_file = "'${H_FILE}'"
+ c_file = "'${TMP_C_FILE}'"
+ h_file = "'${TMP_H_FILE}'"
+ realh_file = "'${H_FILE}'"
comma = ","
print "/* This file is auto-generated by opts.sh. */\n" > c_file
- print "#include \"" h_file "\"" >> c_file
+ print "#include <intl.h>" >> c_file
+ print "#include \"" realh_file "\"" >> c_file
print "#include \"opts.h\"\n" >> c_file
print "const char * const lang_names[] =\n{" >> c_file
if (i + 1 == n_opts)
comma = ""
+ if (help[i] == "")
+ hlp = "0"
+ else
+ hlp = "N_(\"" help[i] "\")";
+
printf(" %s,%s/* -%s */\n", enum, s, opts[i]) >> h_file
- printf(" { \"%s\", (unsigned short) %s, %u,\n\t%s }%s\n",
- opts[i], back_chain[i], len, switch_flags(flags[i]),
- comma) >> c_file
+ printf(" { \"-%s\",\n %s,\n %s, %u, %s }%s\n",
+ opts[i], hlp, back_chain[i], len,
+ switch_flags(flags[i]), comma) >> c_file
}
print " N_OPTS\n};" >> h_file
print "};" >> c_file
}
'
+
+# Copy the newly generated files back to the correct names only if different.
+# This is to prevent a cascade of file rebuilds when not necessary.
+${MOVEIFCHANGE} ${TMP_H_FILE} ${H_FILE}
+${MOVEIFCHANGE} ${TMP_C_FILE} ${C_FILE}