1.1 --- a/makesd-common Mon Jun 10 01:37:46 2019 +0200
1.2 +++ b/makesd-common Mon Jun 10 13:52:32 2019 +0200
1.3 @@ -75,12 +75,9 @@
1.4 if [ "$LINE" ] && [ "$1" ] ; then
1.5 FIELD=`echo "$LINE" | cut -d: -f1`
1.6
1.7 - for PROPERTY in $* ; do
1.8 - if [ "$PROPERTY" = "$FIELD" ] ; then
1.9 - echo "$LINE"
1.10 - break
1.11 - fi
1.12 - done
1.13 + if is_in "$FIELD" $* ; then
1.14 + echo "$LINE"
1.15 + fi
1.16
1.17 # Otherwise, select all properties.
1.18
1.19 @@ -115,6 +112,27 @@
1.20 echo "$1" | cut -d: -f2 | sed 's/^\s*//'
1.21 }
1.22
1.23 +# is_in <string> [ <member> ... ]
1.24 +#
1.25 +# Test whether the given string is present amongst the given members.
1.26 +
1.27 +is_in()
1.28 +{
1.29 + local STRING
1.30 +
1.31 + STRING=$1
1.32 +
1.33 + shift 1
1.34 +
1.35 + for MEMBER in $* ; do
1.36 + if [ "$STRING" = "$MEMBER" ] ; then
1.37 + return 0
1.38 + fi
1.39 + done
1.40 +
1.41 + return 1
1.42 +}
1.43 +
1.44 # search <string> <file>
1.45 #
1.46 # Search for the given string in the input, returning the line number.
2.1 --- a/makesd-expand-def Mon Jun 10 01:37:46 2019 +0200
2.2 +++ b/makesd-expand-def Mon Jun 10 13:52:32 2019 +0200
2.3 @@ -64,13 +64,19 @@
2.4
2.5 # consolidate
2.6 #
2.7 -# Eliminate duplicate properties, preserving only the final definition.
2.8 +# Eliminate duplicate properties, preserving only the final definition, except
2.9 +# for certain properties.
2.10
2.11 consolidate()
2.12 {
2.13 - sort -k1,1 -t: -s | show_last
2.14 + sort -k1,1 -t: -s | show_last 'expand'
2.15 }
2.16
2.17 +# show_last [ <property> ... ]
2.18 +#
2.19 +# Show only the last property of any given name, preserving duplicate entries
2.20 +# only for any given properties.
2.21 +
2.22 show_last()
2.23 {
2.24 local FIELD LAST LASTLINE
2.25 @@ -85,9 +91,9 @@
2.26 FIELD=`get_field "$LINE"`
2.27
2.28 # With a differing property from any previous one, emit the previous
2.29 - # one.
2.30 + # one. With a preserved property, also emit the previous line.
2.31
2.32 - if [ "$LAST" ] && [ "$FIELD" != "$LAST" ] ; then
2.33 + if [ "$LAST" ] && [ "$FIELD" != "$LAST" ] || is_in "$FIELD" $* ; then
2.34 echo "$LASTLINE"
2.35 fi
2.36