From 122354a0dcc071b0b21eea644b37a988383aaec7 Mon Sep 17 00:00:00 2001 From: Matthias Stecher Date: Wed, 29 Sep 2021 20:23:01 +0200 Subject: [PATCH] __ini_value: draft of comment handling work in progress for a long time and I didn't touched it again till just to commit it ... I have to work on it. --- cdist/conf/type/__ini_value/files/comment.awk | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 cdist/conf/type/__ini_value/files/comment.awk diff --git a/cdist/conf/type/__ini_value/files/comment.awk b/cdist/conf/type/__ini_value/files/comment.awk new file mode 100644 index 00000000..1d3c04b7 --- /dev/null +++ b/cdist/conf/type/__ini_value/files/comment.awk @@ -0,0 +1,57 @@ +# We try to find a comment block -- how? +# check how much paragraphs it has +# check if +# +# this code is crap - at least not well written + +# Check the buffer if the comment was found +function check_comments() { + _lastline = bufindex - (buflen - 1) + _comm_size = length(comments) + + lastfreeline = 0 + lastfreecommline = 0 + comm_index = 0 + + # go through all lines + for(i = bufindex; i < _lastline; i++) { + _line = trim(linebuf[i]) + + # empty line? + if(_line == "") { + lastfreeline = i + continue + } + + # line start matched + if(_line == trim(comments[comm_index])) { + # end? else continue + if(comm_index < _comm_size) { + continue + } + else { + + } + } + # reset again cause not matched + else comm_index = 0 + + # empty comment line + if(is_comment(_line)) { + _comment = trim(substr(_line, 2)) + + # check if empty comment + if(_comment == "") { + lastfreecommline = i + } + } + + # check if comments fit in or is too big + if((_lastline - bufindex) < _comm_size) { + # too short + } + else { + #if() + } + } +}