__ini_value: unify present + commented state awk scripts

Because the difference between the both states is just the comment sign
before it, it was now merged into one folder + symlink to avoid
redundancy. To acomplish the difference, a further parser step was
introduced to execute different print function based on the state (it is
a bit of hard-coded but ok).
This commit is contained in:
matze 2021-03-06 23:12:25 +01:00
parent 3e67cdbf9b
commit ea7ac72f9a
6 changed files with 18 additions and 22 deletions

View file

@ -34,11 +34,23 @@ SHELL
# generate the script and strip # generate the script and strip
awk -v state="$state" ' awk -v state="$state" '
function parse(line) {
if(match(line, /^[ \t]*# %code_print%$/) > 0) {
if(state == "present")
print "v_print()"
else if(state == "commented")
print "v_print_commented()"
else
print "print \"script compile error! cdist state " state " unkown!\" > /dev/stderr"
}
else print line
}
{ {
if(match($0, /^[ \t]*# %codeblock_([^%]+)%$/, result) > 0) { if(match($0, /^[ \t]*# %codeblock_([^%]+)%$/) > 0) {
file = (ENVIRON["__type"] "/files/parts/" state "/" result[1] ".awk") split($2, result, "_"); type = substr(result[2], 1, length(result[2]) - 1)
file = (ENVIRON["__type"] "/files/parts/" state "/" type ".awk")
while((getline line < file) > 0) while((getline line < file) > 0)
print line parse(line)
close(file) close(file)
} }
else print else print

View file

@ -0,0 +1 @@
present

View file

@ -1,8 +0,0 @@
# check if last line was the comment
was_com_there = was_comment(lastline(), comment)
# print + comment if not there
flush_buffer()
if(comment && !was_com_there) c_print()
v_print_commented()

View file

@ -1,9 +0,0 @@
was_com_there = was_comment(lastline(), comment)
# print before and comment
flush_buffer()
if(comment && !was_com_there) c_print()
# print value + seperator line at the end
v_print_commented()
print ""

View file

@ -5,4 +5,4 @@ was_com_there = was_comment(lastline(), comment)
flush_buffer() flush_buffer()
if(comment && !was_com_there) c_print() if(comment && !was_com_there) c_print()
v_print() # %code_print%

View file

@ -50,7 +50,7 @@ flush_lines(insertpoint - firstline_index)
# print before and comment # print before and comment
if(insert_line_before) print "" if(insert_line_before) print ""
if(comment && !no_insert_comment) c_print() if(comment && !no_insert_comment) c_print()
v_print() # %code_print%
if(insert_line_after) print "" if(insert_line_after) print ""
flush_buffer() flush_buffer()