]> gitweb.michael.orlitzky.com - nagios-mode.git/blob - utils/parse_object_definitions
If the point is left of indent-column after nagios-indent-to, move it to indent-column.
[nagios-mode.git] / utils / parse_object_definitions
1 #!/bin/bash
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 EXIT_OUTPUT_FILE_EXISTS=3
12
13 if [ $# -lt 2 ]; then
14 echo "Usage: $0 <input_file> <output_file>"
15 exit $EXIT_USAGE
16 fi
17
18
19 INFILE="$1"
20 OUTFILE="$2"
21
22 if [ ! -f "$INFILE" ]; then
23 echo "Error: input file $INFILE doesn't exist."
24 exit $EXIT_INPUT_FILE_DOESNT_EXIST
25 fi
26
27 if [ -f "$OUTFILE" ]; then
28 echo "Error: output file $OUTFILE already exists."
29 exit $EXIT_OUTPUT_FILE_EXISTS
30 fi
31
32 # Common options. Color screws up the output.
33 GREP="grep --extended-regexp --color=never"
34
35 # Grep grabs all of the "#define XODTEMPLATE_..." lines, except for
36 # XODTEMPLATE_NONE, which ain't real.
37 #
38 # Sed removes the "XODTEMPLATE_" prefixes, then tr lowercases everything.
39 #
40 # Oh and we sort everything, add "define ", and surround each line with
41 # quotes, because we can get away with it here.
42 #
43 $GREP --only-matching '[[:space:]]XODTEMPLATE_[[:alnum:]_]+' "$INFILE" \
44 | $GREP -v 'XODTEMPLATE_NONE' \
45 | sed 's/ XODTEMPLATE_//g' \
46 | tr '[A-Z]' '[a-z]' \
47 | sort \
48 | sed -e 's/^/\"define /g' -e 's/$/\"/g' >> "$OUTFILE"