Created
December 18, 2019 08:11
-
-
Save jszigetvari/3bde54fbfe60ad6815089451add00251 to your computer and use it in GitHub Desktop.
remove comments from syslog-ng config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function found_single_quote(input, input_length, position) { | |
in_squote=1; | |
for (i=position; i<=input_length; i++) { | |
BUF=BUF input[i]; | |
switch (input[i]) { | |
case "\x27": | |
in_squote=0; | |
return i; | |
default: | |
break; | |
} | |
} | |
return input_length; | |
} | |
function found_double_quote(input, input_length, position) { | |
in_dquote=1 | |
nbs=0; | |
for (i=position; i<=input_length; i++) { | |
BUF=BUF input[i]; | |
switch (input[i]) { | |
case "\"": | |
if ((nbs % 2) == 1) { | |
nbs=0; | |
} | |
else { | |
in_dquote=0; | |
return i; | |
} | |
case "\\": | |
nbs++; | |
break; | |
default: | |
nbs=0; | |
break; | |
} | |
} | |
return input_length; | |
} | |
function process_line_normal(input, input_length, position) { | |
for (i=position; i<=input_length; i++) { | |
switch (input[i]) { | |
case "\x27": | |
BUF=BUF input[i]; | |
i=found_single_quote(input, input_length, i+1); | |
break; | |
case "\"": | |
BUF=BUF input[i]; | |
i=found_double_quote(input, input_length, i+1); | |
break; | |
case "#": | |
printf "%s\n", BUF; | |
BUF=""; | |
return; | |
default: | |
BUF=BUF input[i]; | |
break; | |
} | |
} | |
if ((in_dquote == 1) || (in_squote == 1)) { | |
BUF=BUF "\n"; | |
} | |
else { | |
printf "%s\n", BUF; | |
BUF=""; | |
} | |
} | |
function scan_line(input, input_length) { | |
if (in_squote==1) { | |
quote_end=found_single_quote(input, input_length, 1); | |
process_line_normal(input, input_length, quote_end+1); | |
} | |
else if (in_dquote==1) { | |
quote_end=found_double_quote(input, input_length, 1); | |
process_line_normal(input, input_length, quote_end+1); | |
} | |
else { | |
process_line_normal(input, input_length, 1); | |
} | |
} | |
BEGIN { | |
in_dquote=0; | |
in_squote=0; | |
BUF="" | |
} | |
{ | |
len=split($0, line, ""); | |
scan_line(line, len); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment