diff --git a/src/pkgconf-funcs.sh b/src/pkgconf-funcs.sh index d06b68b..fd144c8 100644 --- a/src/pkgconf-funcs.sh +++ b/src/pkgconf-funcs.sh @@ -1,119 +1,119 @@ #### start of pkgconf-funcs # # Bourne shell functions for config file in pkg-config style, so that # we can share such a config file between pkg-config and script # # # get_var: Get the variable value of NAME # # Variables are recorded in the shell variables named "VAR_" # get_var () { local name=$1 eval echo \$VAR_$name } # # get_attr: Get the attribute value of KEY # # Attributes are recorded in the shell variables named "ATTR_" # get_attr () { local name=$1 eval echo \$ATTR_$name } # Remove ${varname} part in the beginning of a string. remove_var_expr () { local varname=$1 shift eval echo \"\${@#\\\$\\\{$varname\\\}}\" } # Given a string, substitute variables. substitute_vars () { local string="$1" local line local varname local result while [ -n "$string" ]; do case "$string" in \$\$*) result="$result\$" string="${string#\$\$}" ;; \${*}*) varname="${string#\$\{}" varname="${varname%%\}*}" result="$result$(get_var ${varname})" string=$(remove_var_expr ${varname} ${string}) ;; *) result="${result}$(printf %c "$string")" string="${string#$(printf %c "$string")}" ;; esac done echo "$result" } # # Read a config file # # Variables: # For VAR=VALUE, value is stored in the shell variable VAR_*. # # Attributes: # For KEY: VALUE, value is stored in the shell variable ATTR_*. # read_config_file () { local line local varname local value local key while read line; do case "$line" in *=*) varname="${line%%=*}" value="${line#*=}" VAR_list="$VAR_list VAR_$varname" read VAR_$varname <