X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=utils%2Fparse_object_definitions;h=aaa6c314e3a154199f1ac9f6abf90dc9a8886bfe;hb=HEAD;hp=dd303683ff7140a3f160ab47692649eee60a6a41;hpb=50a11ca38c7c80a17e86d9095df3a513ab4acb5e;p=nagios-mode.git diff --git a/utils/parse_object_definitions b/utils/parse_object_definitions index dd30368..aaa6c31 100755 --- a/utils/parse_object_definitions +++ b/utils/parse_object_definitions @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # Parse the object names out of Nagios' xdata/xodtemplate.h, and # convert them to their definition format. @@ -8,41 +8,29 @@ EXIT_USAGE=1 EXIT_INPUT_FILE_DOESNT_EXIST=2 -EXIT_OUTPUT_FILE_EXISTS=3 -if [ $# -lt 2 ]; then - echo "Usage: $0 " +if [ $# -lt 1 ]; then + echo "Usage: $0 " exit $EXIT_USAGE fi INFILE="$1" -OUTFILE="$2" if [ ! -f "$INFILE" ]; then echo "Error: input file $INFILE doesn't exist." exit $EXIT_INPUT_FILE_DOESNT_EXIST fi -if [ -f "$OUTFILE" ]; then - echo "Error: output file $OUTFILE already exists." - exit $EXIT_OUTPUT_FILE_EXISTS -fi - -# Common options. Color screws up the output. -GREP="grep --extended-regexp --color=never" - -# Grep grabs all of the "#define XODTEMPLATE_..." lines, except for -# XODTEMPLATE_NONE, which ain't real. -# -# Sed removes the "XODTEMPLATE_" prefixes, then tr lowercases everything. -# -# Oh and we sort everything, add "define ", and surround each line with -# quotes, because we can get away with it here. -# -$GREP --only-matching '[[:space:]]XODTEMPLATE_[[:alnum:]_]+' "$INFILE" \ - | $GREP -v 'XODTEMPLATE_NONE' \ - | sed 's/ XODTEMPLATE_//g' \ - | tr '[A-Z]' '[a-z]' \ - | sort \ - | sed -e 's/^/\"define /g' -e 's/$/\"/g' >> "$OUTFILE" +# Sed grabs all of the "#define XODTEMPLATE_FOO" lines, pulls out the +# FOO part, and then prints "define FOO", surrounded in +# quotes. Afterwards we prune the two lines corresponding to +# XODTEMPLATE_NULL and XODTEMPLATE_NONE which do not correspond to +# real object types. Finally we lowercase everything with tr, and sort +# the result. +XOD_REGEX='#define[[:space:]]\{1,\}XODTEMPLATE_\([^[:space:]]\{1,\}\)[[:space:]]\{1,\}.*' + +sed -n "s/${XOD_REGEX}/\"define \1\"/p" "${INFILE}" \ + | sed '/define NULL\|NONE/d' \ + | tr '[A-Z]' '[a-z]' \ + | sort \