BEGIN { # parameter variables section = get_param_string("section") key = get_param_string("key") delimiter = get_param_string("delimiter") value = get_param_string("value") comment = get_param_string("comment") indentation = get_param_string("indentation") delimiter_space = get_param_string("delimiter-space") get_param_array("comment-sign", comment_signs) comment_sign = comment_signs[0] if(system("test -f " (ENVIRON["__object"] "/parameter/quote")) == 0) { # quote it now that it only wins checks against quoted values value = ("\"" value "\"") } base_spaces = spaces(indentation) delimiter_spaces = spaces(delimiter_space) delimiter_w_spaces = (delimiter_spaces delimiter delimiter_spaces) } function trim(var) { sub(/^[ \t]*/, "", var) sub(/[ \t]*$/, "", var) return var } function spaces(a) { rspaces = "" for(b = 0; b < a; b++) rspaces = (rspaces " ") return rspaces } function check_spaces(part) { return match(part, /^[ \t]*$/) == 1 } function get_param_string(name) { _paramfile = (ENVIRON["__object"] "/parameter/" name) if((getline tmp < _paramfile) > 0) { close(_paramfile) return tmp } else return "" } function get_param_array(name, arr) { _paramfile = (ENVIRON["__object"] "/parameter/" name) i=0 split("", arr) # portable clear, like `delete arr` while((getline tmp < _paramfile) > 0) { arr[i++] = tmp } close(_paramfile) } # print value function v_print() { printf "%s%s%s%s%s", base_spaces, key, delimiter_w_spaces, value, ORS } # print commented value function v_print_commented() { printf "%s%s%s%s%s%s", base_spaces, comment_sign, key, delimiter_w_spaces, value, ORS } # print comment function c_print() { printf "%s%s %s%s", base_spaces, comment_sign, comment, ORS }