# HG changeset patch # User Paul Boddie # Date 1560167552 -7200 # Node ID a0ae8d201d1eec0d695aad9af7770d0340b14035 # Parent eeb7bcd53897dab399e54ce2a4a96c823514a068 Permit certain properties to be duplicated, such as the "expand" property. diff -r eeb7bcd53897 -r a0ae8d201d1e makesd-common --- a/makesd-common Mon Jun 10 01:37:46 2019 +0200 +++ b/makesd-common Mon Jun 10 13:52:32 2019 +0200 @@ -75,12 +75,9 @@ if [ "$LINE" ] && [ "$1" ] ; then FIELD=`echo "$LINE" | cut -d: -f1` - for PROPERTY in $* ; do - if [ "$PROPERTY" = "$FIELD" ] ; then - echo "$LINE" - break - fi - done + if is_in "$FIELD" $* ; then + echo "$LINE" + fi # Otherwise, select all properties. @@ -115,6 +112,27 @@ echo "$1" | cut -d: -f2 | sed 's/^\s*//' } +# is_in [ ... ] +# +# Test whether the given string is present amongst the given members. + +is_in() +{ + local STRING + + STRING=$1 + + shift 1 + + for MEMBER in $* ; do + if [ "$STRING" = "$MEMBER" ] ; then + return 0 + fi + done + + return 1 +} + # search # # Search for the given string in the input, returning the line number. diff -r eeb7bcd53897 -r a0ae8d201d1e makesd-expand-def --- a/makesd-expand-def Mon Jun 10 01:37:46 2019 +0200 +++ b/makesd-expand-def Mon Jun 10 13:52:32 2019 +0200 @@ -64,13 +64,19 @@ # consolidate # -# Eliminate duplicate properties, preserving only the final definition. +# Eliminate duplicate properties, preserving only the final definition, except +# for certain properties. consolidate() { - sort -k1,1 -t: -s | show_last + sort -k1,1 -t: -s | show_last 'expand' } +# show_last [ ... ] +# +# Show only the last property of any given name, preserving duplicate entries +# only for any given properties. + show_last() { local FIELD LAST LASTLINE @@ -85,9 +91,9 @@ FIELD=`get_field "$LINE"` # With a differing property from any previous one, emit the previous - # one. + # one. With a preserved property, also emit the previous line. - if [ "$LAST" ] && [ "$FIELD" != "$LAST" ] ; then + if [ "$LAST" ] && [ "$FIELD" != "$LAST" ] || is_in "$FIELD" $* ; then echo "$LASTLINE" fi