Rework the code that finds the list of variables in a template.
authorMartin Schwenke <martin@meltin.net>
Tue, 29 Jun 2010 02:33:26 +0000 (12:33 +1000)
committerMartin Schwenke <martin@meltin.net>
Tue, 29 Jun 2010 02:33:26 +0000 (12:33 +1000)
This version seems cleaner and clearer than the previous version, so
is more likely to be correct.

Signed-off-by: Martin Schwenke <martin@meltin.net>
autocluster

index 8cbf96ea29763c8f8a890fa3b88610da5a96f3ca..4495b969685c01409e29fed651e995991830fb43 100755 (executable)
@@ -880,12 +880,13 @@ _substitute_vars() {(
        instring="$1"
        delimiter="${2:-@@}"
 
-       # get the list of variables used in the template
-       VARS=`echo "$instring" |
-             tr -cs "A-Z0-9_$delimiter" '\012' | 
-              sort -u |
-             sed -e "s#@@*[^@]*@@*#&\n#" |
-             sed -n -e "s#^[^@]*${delimiter}\(.*\)${delimiter}[^@]*\\$#\1#p"`
+       # Get the list of variables used in the template.  The grep
+       # gets rid of any blank lines and lines with extraneous '@'s
+       # next to template substitutions.
+       VARS=$(echo "$instring" |
+           sed -n -e "s#[^@]*${delimiter}\([A-Z0-9_][A-Z0-9_]*\)${delimiter}[^@]*#\1\n#gp" |
+           grep '^[A-Z0-9_][A-Z0-9_]*$' |
+           sort -u)
 
        tmp=$(mktemp)
        for v in $VARS; do