1.1 --- a/makesd-common Tue May 28 00:30:18 2019 +0200
1.2 +++ b/makesd-common Mon Jun 10 01:37:46 2019 +0200
1.3 @@ -36,11 +36,101 @@
1.4 fi
1.5 }
1.6
1.7 -# Process partition field values in summary tables.
1.8 +# filter <type> [ <property> ... ]
1.9 +#
1.10 +# Filter input, preserving only sections with the given type, preserving only
1.11 +# the given properties if indicated.
1.12 +
1.13 +filter()
1.14 +{
1.15 + local FIELD LINE PROPERTY SECTION TYPE
1.16 +
1.17 + TYPE=$1
1.18 + SECTION=
1.19 +
1.20 + shift 1
1.21 +
1.22 + while read LINE ; do
1.23 +
1.24 + # Start a new section if appropriate.
1.25 +
1.26 + if [ "$LINE" ] && [ ! "$SECTION" ] ; then
1.27 + SECTION=`echo "$LINE" | cut -d' ' -f1`
1.28 +
1.29 + # Produce suitable section headers.
1.30 +
1.31 + if [ "$SECTION" = "$TYPE" ] ; then
1.32 + echo "$LINE"
1.33 + fi
1.34 +
1.35 + continue
1.36 + fi
1.37 +
1.38 + # Produce lines from any suitable section including any blank line.
1.39 +
1.40 + if [ "$SECTION" = "$TYPE" ] ; then
1.41 +
1.42 + # Select appropriate properties if indicated.
1.43 +
1.44 + if [ "$LINE" ] && [ "$1" ] ; then
1.45 + FIELD=`echo "$LINE" | cut -d: -f1`
1.46 +
1.47 + for PROPERTY in $* ; do
1.48 + if [ "$PROPERTY" = "$FIELD" ] ; then
1.49 + echo "$LINE"
1.50 + break
1.51 + fi
1.52 + done
1.53 +
1.54 + # Otherwise, select all properties.
1.55
1.56 -read_fields()
1.57 + else
1.58 + echo "$LINE"
1.59 + fi
1.60 + fi
1.61 +
1.62 + # End sections on blank lines.
1.63 +
1.64 + if [ ! "$LINE" ] ; then
1.65 + SECTION=
1.66 + fi
1.67 + done
1.68 +}
1.69 +
1.70 +# get_field <string>
1.71 +#
1.72 +# Emit the field name of a property definition.
1.73 +
1.74 +get_field()
1.75 {
1.76 - IFS=`echo -n '\t'` read START SIZE TYPE
1.77 + echo "$1" | cut -d: -f1
1.78 +}
1.79 +
1.80 +# get_value <string>
1.81 +#
1.82 +# Emit the value of a property definition.
1.83 +
1.84 +get_value()
1.85 +{
1.86 + echo "$1" | cut -d: -f2 | sed 's/^\s*//'
1.87 +}
1.88 +
1.89 +# search <string> <file>
1.90 +#
1.91 +# Search for the given string in the input, returning the line number.
1.92 +
1.93 +search()
1.94 +{
1.95 + grep -h -n "$1" "$2" | cut -d: -f1
1.96 +}
1.97 +
1.98 +# set_value <name> <value>
1.99 +#
1.100 +# Set the parameter of the given name to value.
1.101 +
1.102 +set_value()
1.103 +{
1.104 + eval "$1=\"\$2\""
1.105 }
1.106
1.107 # test_align_cylinder <args>
1.108 @@ -58,6 +148,8 @@
1.109 fi
1.110 }
1.111
1.112 +# Common messages.
1.113 +
1.114 align_cylinder_description()
1.115 {
1.116 cat <<EOF
1.117 @@ -66,3 +158,11 @@
1.118 and sectors.
1.119 EOF
1.120 }
1.121 +
1.122 +show_definitions_description()
1.123 +{
1.124 + cat <<EOF
1.125 +If the -a, --all or --defs options are specified, all hardware definitions are
1.126 +emitted and no further actions are taken.
1.127 +EOF
1.128 +}