2 # Copyright (C) 2006 Andre Noll
3 # Licensed under the LGPL, version 3. See COPYING and COPYING.LESSER.
5 # Syntactically check the gsu_options array for errors and parse the config
9 local i conf="${gsu_config_file:=${HOME:-}/.$gsu_name.rc}" val orig_val
10 local name option_type default_value required description help_text
12 for ((i=0; i < ${#gsu_options[@]}; i++)); do
13 eval "${gsu_options[$i]}"
14 eval val='"'\${${name}:-}'"'
15 eval orig_${gsu_config_var_prefix}_$name='"'${val}'"'
18 [[ -r "$conf" ]] && source "$conf"
20 for ((i=0; i < ${#gsu_options[@]}; i++)); do
28 eval "${gsu_options[$i]}"
30 # Check name. It must be non-empty and consist of [a-zA-Z_0-9]
31 # only. Moreover it must start with [a-zA-Z].
32 ret=-$E_GSU_BAD_CONFIG_VAR
33 result="name: '$name'"
34 [[ "$name" =~ ^[a-zA-Z][a-zA-Z_0123456789]*$ ]] || return
36 eval orig_val='"'\$orig_${gsu_config_var_prefix}_$name'"'
37 if [[ -z "$orig_val" ]]; then
38 eval val='"'\${$name:-}'"'
44 ret=-$E_GSU_NEED_VALUE
46 [[ -z "$val" ]] && return
52 result="required: $required, name: $name, val: $val"
56 eval ${gsu_config_var_prefix}_$name='"'\${val:="$default_value"}'"'
57 # Check option type. ATM, only num and string are supported
58 # Other types may be added without breaking compatibility
59 case "$option_type" in
63 gsu_is_a_number "$val"
67 ret=-$E_GSU_BAD_OPTION_TYPE
68 result="$name/$option_type"
75 # Call gsu_check_options(), die on errors.
76 gsu_check_options_or_die()
85 if [[ "$(type -t _gsu_setup)" != "function" ]]; then
86 gsu_dir=${gsu_dir:-${BASH_SOURCE[0]%/*}}
87 . "$gsu_dir/common" || exit 1