From 6a9a7caa59370e03a9db3da89280e51febe75149 Mon Sep 17 00:00:00 2001 From: davidovski Date: Wed, 30 Mar 2022 23:43:15 +0100 Subject: fixed parseconf --- src/parseconf.sh | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/parseconf.sh b/src/parseconf.sh index 929ce05..abc6b36 100755 --- a/src/parseconf.sh +++ b/src/parseconf.sh @@ -23,22 +23,38 @@ parse_line() { shift local value="$@" - [ "$key" = "include" ] && cat $value | parse && return - [ "$key" = "]" ] && unset list=${list%.*} && printf "\n" && return - [ "$key" = "}" ] && unset level=${level%.*} && return + case $key in + "include") + cat $value | parse + return + ;; + "]") + IFS=. + set -- $list + list="${*%${!#}}" + IFS=" " + printf "\n" + return + ;; + "}") + [ "$level" = "${level%.*}" ] && + level="" || level=${level%.*} + return + ;; + esac case ${value##* } in "{") - level="${level}${key}." + level="${level}${level:+.}${key}" ;; "[") list="${list}${list:+.}${key}" - printf "$level$key:" + printf "$level${level:+.}$key:" ;; *) [ "${#list}" = "0" ] && - printf "$level$key:$value\n" || + printf "$level${level:+.}$key:$value\n" || printf "$line " ;; esac -- cgit v1.2.1