3 # Parse directive names out of Nagios' xdata/xodtemplate.c.
6 EXIT_INPUT_FILE_DOESNT_EXIST
=2
9 # Securely create a temporary file under ${TMPDIR} using the
10 # template "tmpXXXXXX", and echo the result to stdout. This works
11 # around the absence of "mktemp" in the POSIX standard.
12 printf 'mkstemp(template)' | m4 -D template
="${TMPDIR:-/tmp}/tmpXXXXXX"
16 echo "Usage: $0 <path-to-xodtemplate.c>"
22 TEMPFILE
="$(posix_mktemp)"
24 if [ ! -f "$INFILE" ]; then
25 echo "Error: input file $INFILE doesn't exist."
26 exit $EXIT_INPUT_FILE_DOESNT_EXIST
29 # The list of weekday names, taken from xdata/xodtemplate.c. The
30 # Nagios strcmp parser doesn't look for them individually. Since
31 # they're unlikely to change, appending them manually sounds
42 # This grabs all of the variable names that are explicitly checked for
43 # with strcmp in xdata/xodtemplate.c. We include these because some
44 # valid variable names (e.g. "hostgroups") are implicitly mapped to
45 # "real" variables whose names differ.
47 # The "name", "register", and "use" directives are special (literally,
48 # they get the "special" font in nagios-mode.el), so we drop them from
51 # Before we parse the names, though, we move each !strcmp to its own
52 # line, which greatly simplifies the parsing.
53 VARCMP_REGEX
='.*!strcmp(variable,[[:space:]]*"\([A-Za-z_]\{1,\}\)").*'
54 sed "s/\!strcmp(/\n\!strcmp(/g" < "${INFILE}" \
55 | sed -n "s/${VARCMP_REGEX}/\"\1\"/p" \
56 | sed '/^"name\|use\|register"$/d' \
59 # Finally, sort the list and print it.
60 sort < "${TEMPFILE}" | uniq