]> gitweb.michael.orlitzky.com - nagios-mode.git/commitdiff
utils/parse_object_definitions: make POSIX-compatible.
authorMichael Orlitzky <michael@orlitzky.com>
Fri, 11 Nov 2022 21:18:15 +0000 (16:18 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Fri, 11 Nov 2022 21:19:54 +0000 (16:19 -0500)
This script now uses an ugly sed script instead of relying on the
non-portable "--only-matching" flag of grep.

utils/parse_object_definitions

index 0d164a268f62183d80b45f335d8f6aa724e5215d..aaa6c314e3a154199f1ac9f6abf90dc9a8886bfe 100755 (executable)
@@ -22,17 +22,15 @@ if [ ! -f "$INFILE" ]; then
     exit $EXIT_INPUT_FILE_DOESNT_EXIST
 fi
 
-# 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:]_]\{1,\}' "$INFILE" \
-    | grep -v 'XODTEMPLATE_NONE'                                           \
-    | sed 's/ XODTEMPLATE_//g'                                             \
-    | tr '[A-Z]' '[a-z]'                                                   \
-    | sort                                                                 \
-    | sed -e 's/^/\"define /g' -e 's/$/\"/g'
+# 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                                            \