From 46638f0839cff327b00c914fe3d626d8e16791f6 Mon Sep 17 00:00:00 2001 From: Matthias Stecher Date: Wed, 17 Mar 2021 18:17:21 +0100 Subject: [PATCH] __ini_value: change empty value check Change the short-circuit check for an empty value to a more structual approach. This might be better for the code or not .. --- cdist/conf/type/__ini_value/files/base.awk | 79 +++++++++++----------- 1 file changed, 38 insertions(+), 41 deletions(-) diff --git a/cdist/conf/type/__ini_value/files/base.awk b/cdist/conf/type/__ini_value/files/base.awk index 57535964..ddc52949 100644 --- a/cdist/conf/type/__ini_value/files/base.awk +++ b/cdist/conf/type/__ini_value/files/base.awk @@ -66,56 +66,53 @@ found {print; next} # main loop (til the line was found) !found { line = trim($0) - # short curcit on empty lines - if(line == "") { - push_line() - next - } + # process if the line is not empty (or only contains spaces) + if(line != "") { + # check for a ini section + if(substr(line, 1, 1) == "[" && substr(line, length(line), 1) == "]") { + is_section = 1 + curr_section = line - # check for a ini section - if(substr(line, 1, 1) == "[" && substr(line, length(line), 1) == "]") { - is_section = 1 - curr_section = line + if(curr_section == section) { + found_section = 1 + is_curr_section = 1 + } + else { + # if nothing found, print it in the valid section before the next one + if(is_curr_section) { + if(!found) { + # set found as it is there now + found=1 - if(curr_section == section) { - found_section = 1 - is_curr_section = 1 + # %codeblock_insert% + + # print line as it would else only be populated below + print + next + } + is_curr_section = 0 + } + } } else { - # if nothing found, print it in the valid section before the next one + # only current session is interessting if(is_curr_section) { - if(!found) { - # set found as it is there now - found=1 - - # %codeblock_insert% - - # print line as it would else only be populated below - print - next + # check for a comment + is_com = is_comment(line) + if(is_com) { + line = trim(substr(line, 2)) } - is_curr_section = 0 - } - } - } - else { - # only current session is interessting - if(is_curr_section) { - # check for a comment - is_com = is_comment(line) - if(is_com) { - line = trim(substr(line, 2)) - } - # check for a delimiter and a key (must be at first position due to trimming) - if((idel = index(line, delimiter)) && (ikey = index(line, key)) == 1) { - # check there are only spaces between the key and delimiter - if(check_spaces(substr(line, ikey + length(key), idel - (length(key) + 1)))) { - found = 1 + # check for a delimiter and a key (must be at first position due to trimming) + if((idel = index(line, delimiter)) && (ikey = index(line, key)) == 1) { + # check there are only spaces between the key and delimiter + if(check_spaces(substr(line, ikey + length(key), idel - (length(key) + 1)))) { + found = 1 - # %codeblock_found% + # %codeblock_found% - next + next + } } } }