cdist/cdist/conf/type/__ini_value/files/common.awk

62 lines
1.6 KiB
Awk

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")
get_param_array("comment-sign", comment_signs)
comment_sign = comment_signs[0]
}
function trim(var) {
sub(/^[ \t]*/, "", var)
sub(/[ \t]*$/, "", var)
return var
}
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() {
spaces = ""
for(i = 0; i < indentation; i++)
spaces = (spaces " ")
printf "%s%s%s%s%s", spaces, key, delimiter, value, ORS
}
# print commented value
function v_print_commented() {
spaces = ""
for(i = 0; i < indentation; i++)
spaces = (spaces " ")
printf "%s%s%s%s%s%s", spaces, comment_sign, key, delimiter, value, ORS
}
# print comment
function c_print() {
spaces = ""
for(i = 0; i < indentation; i++)
spaces = (spaces " ")
printf "%s%s%s%s%s", spaces, comment_sign, " ", comment, ORS
}