3 # Parse the macro names out of Nagios' include/macros.h.
5 # Operates on whatever file you give it. That should probably be
6 # include/macros.h. Just sayin'.
10 EXIT_INPUT_FILE_DOESNT_EXIST
=2
13 # Securely create a temporary file under ${TMPDIR} using the
14 # template "tmpXXXXXX", and echo the result to stdout. This works
15 # around the absence of "mktemp" in the POSIX standard.
16 printf 'mkstemp(template)' | m4 -D template
="${TMPDIR:-/tmp}/tmpXXXXXX"
20 echo "Usage: $0 <input_file>"
26 TEMPFILE
="$(posix_mktemp)"
28 if [ ! -f "$INFILE" ]; then
29 echo "Error: input file $INFILE doesn't exist."
30 exit $EXIT_INPUT_FILE_DOESNT_EXIST
33 # Grabs all of the "#define MACRO..." lines, except for MACRO_X_COUNT
34 # and MACRO_ENV_VAR_PREFIX which aren't real macros, and outputs the
35 # macro name (everything after "MACRO_") enclosed in quotes and dollar
36 # signs, appropriate to be copy/pasted directly into nagios-mode.el.
37 MACRO_REGEX
='#define[[:space:]]\{1,\}MACRO_\([^[:space:]]\{1,\}\)[[:space:]]\{1,\}.*'
38 sed -n "s/${MACRO_REGEX}/\"\$\1\$\"/p" "${INFILE}" \
39 | sed '/X_COUNT\|ENV_VAR_PREFIX/d' \
42 # Add "$ARG1$", "$ARG2$",... "$ARG<max>$" to the list, where <max> is
43 # defined in macros.h.
44 MAXARG_REGEX
='#define[[:space:]]\{1,\}MAX_COMMAND_ARGUMENTS[[:space:]]\{1,\}\([1-9][0-9]*\).*'
45 MAXARG
=$(sed -n "s/${MAXARG_REGEX}/\1/p" "${INFILE}")
47 for argnum
in `seq 1 $MAXARG`; do
48 echo "\"\$ARG${argnum}\$\"" >> "${TEMPFILE}"
51 # Also the "$USER<N>$" macros, similar to the above.
52 MAXUSER_REGEX
='#define[[:space:]]\{1,\}MAX_USER_MACROS[[:space:]]\{1,\}\([1-9][0-9]*\).*'
53 MAXUSER
=$(sed -n "s/${MAXUSER_REGEX}/\1/p" "${INFILE}")
55 for argnum
in `seq 1 $MAXUSER`; do
56 echo "\"\$USER${argnum}\$\"" >> "${TEMPFILE}"
59 # Finally, sort the list and print it.