]> gitweb.michael.orlitzky.com - nagios-mode.git/commitdiff
utils/parse_object_definitions: miscellaneous cleanups.
authorMichael Orlitzky <michael@orlitzky.com>
Fri, 11 Nov 2022 20:03:13 +0000 (15:03 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Fri, 11 Nov 2022 21:19:54 +0000 (16:19 -0500)
  1. Use /bin/sh instead of /bin/bash
  2. Use basic (non-extended) regular expressions with grep
  3. Use plain "grep" instead of "grep --extended-regexp --color=never"
  4. Write the result to stdout; drop the second CLI argument

utils/parse_object_definitions

index dd303683ff7140a3f160ab47692649eee60a6a41..0d164a268f62183d80b45f335d8f6aa724e5215d 100755 (executable)
@@ -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,30 +8,20 @@
 
 EXIT_USAGE=1
 EXIT_INPUT_FILE_DOESNT_EXIST=2
-EXIT_OUTPUT_FILE_EXISTS=3
 
-if [ $# -lt 2 ]; then
-    echo "Usage: $0 <input_file> <output_file>"
+if [ $# -lt 1 ]; then
+    echo "Usage: $0 <input_file>"
     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.
 #
@@ -40,9 +30,9 @@ GREP="grep --extended-regexp --color=never"
 # 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"
+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'