From e6a5137690fb94f6379499f76a4a07811922a379 Mon Sep 17 00:00:00 2001 From: davidovski Date: Sun, 5 Jun 2022 14:09:43 +0100 Subject: fixed comments not working when preceeded by whitespace --- Makefile | 2 +- src/parseconf.sh | 6 ++++-- test/parseconf.sh | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d5a2718..f616fc6 100755 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ DIST=dist .DEFAULT_GOAL := build -install: install-hbar install-colors install-parseconf install-shtests install-glyphs install-xitui install-xilib +install: build install-hbar install-colors install-parseconf install-shtests install-glyphs install-xitui install-xilib check: check-parseconf build: make-dist hbar shtests parseconf colors diff --git a/src/parseconf.sh b/src/parseconf.sh index abc6b36..d215a99 100644 --- a/src/parseconf.sh +++ b/src/parseconf.sh @@ -16,12 +16,14 @@ EOF # parse a single config file line # parse_line() { - [ $# = "0" ] && return + [ "$#" = 0 ] && return local line="$@" local key=$1 + shift local value="$@" + value=${value%#*} case $key in "include") @@ -108,6 +110,6 @@ $print_keys && pattern="s/^$pattern:(.+)/\1/p;${count}" # strip whitespace -sed "s/^#.*$\|\s(\s\+)\|^\s\|\s^\|;*$//g" $CONF_FILE | +sed "s/^\s*#.*$\|\s(\s\+)\|^\s\|\s^\|;*$//g" $CONF_FILE | parse $@ | sed -rn $pattern diff --git a/test/parseconf.sh b/test/parseconf.sh index ab28721..1cd668f 100755 --- a/test/parseconf.sh +++ b/test/parseconf.sh @@ -50,6 +50,20 @@ key4 value4 [ "$retval" = "key2:value2" ] } +test_comments_parsing() { + config=" +#key1 value1 + #key2 value2 +# this is a comment +#key4 value4 +dict { + #nothing here +} + " + retval=$(printf "$config" | ${PARSECONF} ) + [ "x$retval" = "x" ] +} + test_list_parsing() { config=" -- cgit v1.2.1