]> gitweb.michael.orlitzky.com - nagios-mode.git/blob - utils/parse_object_definitions
utils/parse_object_definitions: make POSIX-compatible.
[nagios-mode.git] / utils / parse_object_definitions
1 #!/bin/sh
2 #
3 # Parse the object names out of Nagios' xdata/xodtemplate.h, and
4 # convert them to their definition format.
5 #
6 # Operates on whatever file you give it, like the other utilities.
7 #
8
9 EXIT_USAGE=1
10 EXIT_INPUT_FILE_DOESNT_EXIST=2
11
12 if [ $# -lt 1 ]; then
13 echo "Usage: $0 <input_file>"
14 exit $EXIT_USAGE
15 fi
16
17
18 INFILE="$1"
19
20 if [ ! -f "$INFILE" ]; then
21 echo "Error: input file $INFILE doesn't exist."
22 exit $EXIT_INPUT_FILE_DOESNT_EXIST
23 fi
24
25 # Sed grabs all of the "#define XODTEMPLATE_FOO" lines, pulls out the
26 # FOO part, and then prints "define FOO", surrounded in
27 # quotes. Afterwards we prune the two lines corresponding to
28 # XODTEMPLATE_NULL and XODTEMPLATE_NONE which do not correspond to
29 # real object types. Finally we lowercase everything with tr, and sort
30 # the result.
31 XOD_REGEX='#define[[:space:]]\{1,\}XODTEMPLATE_\([^[:space:]]\{1,\}\)[[:space:]]\{1,\}.*'
32
33 sed -n "s/${XOD_REGEX}/\"define \1\"/p" "${INFILE}" \
34 | sed '/define NULL\|NONE/d' \
35 | tr '[A-Z]' '[a-z]' \
36 | sort \