]> gitweb.michael.orlitzky.com - nagios-mode.git/blob - utils/parse_object_definitions
0d164a268f62183d80b45f335d8f6aa724e5215d
[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 # Grep grabs all of the "#define XODTEMPLATE_..." lines, except for
26 # XODTEMPLATE_NONE, which ain't real.
27 #
28 # Sed removes the "XODTEMPLATE_" prefixes, then tr lowercases everything.
29 #
30 # Oh and we sort everything, add "define ", and surround each line with
31 # quotes, because we can get away with it here.
32 #
33 grep --only-matching '[[:space:]]XODTEMPLATE_[[:alnum:]_]\{1,\}' "$INFILE" \
34 | grep -v 'XODTEMPLATE_NONE' \
35 | sed 's/ XODTEMPLATE_//g' \
36 | tr '[A-Z]' '[a-z]' \
37 | sort \
38 | sed -e 's/^/\"define /g' -e 's/$/\"/g'