B.7. Get the Value for a Field

The ha_get_field() function obtains the field value from a string, where $1 is the string and $2 is the field name. The string format is a series of name-value field pairs, where a name field is followed by the value of the name, separated by whitespace. This appears as follows:

ha_get_field()
 {
     HA_STR=$1
     HA_FIELD_NAME=$2
     ha_found=0;
     ha_field=1;
 
     for ha_i in $HA_STR
     do
         if [ $ha_field -eq 1 ]; then
             ha_field=0;
             if [ $ha_i = $HA_FIELD_NAME ]; then
                 ha_found=1;
             fi
         else
             ha_field=1;
             if [ $ha_found -eq 1 ]; then
                 HA_FIELD_VALUE=$ha_i
                 return 0;
             fi
         fi
     done
 
     return 1;
 }