From 36fd58b39208684164afc2c0a8d568d083541d91 Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 6 Nov 2022 16:34:54 -0500 Subject: [PATCH] hacky array system --- test.toml | 12 ++++++++++++ tomcat | 12 ++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test.toml diff --git a/test.toml b/test.toml new file mode 100644 index 0000000..542a9ca --- /dev/null +++ b/test.toml @@ -0,0 +1,12 @@ +# full-line comment + +[main] # appended comment +key = "val" +keyc = "val" # comment appended to key/value line +"keyq" = "val" +keycom = "# value with hash" + +[fancy] +arr = [ "val1", "val2", "val3" ] +arrc = [ "val1", "val2", "val3", ] # comment appended to array line +arrcom = [ "# one", "##two", "###three" ] diff --git a/tomcat b/tomcat index 83bdf08..f92e7db 100755 --- a/tomcat +++ b/tomcat @@ -18,8 +18,16 @@ TOML=$(sed 's/[^"#]#\+.*//g' <"$1") set -- $(printf "%s\n" "$2" | cut -d "." --output-delimiter=" " -f 1-) PAIRS=$(printf "%s\n" "$TOML" | awk "/^\[$1\]/{flag=1; next} /^\[/{flag=0} flag" - ) -VAL=$(printf "%s\n" "$PAIRS" | sed -n "s/$2 *= *//p" | tr -d '"[],') +ARR=$(printf "%s\n" "$2" | sed -n 's/.\+\[//p') -printf "%s\n" "$VAL" +VAL=$(printf "%s\n" "$PAIRS" | sed -n "s/$2 *= *//p" | sed 's/, /,/g' | tr -d '[]') + +if test -n "$ARR"; then + set -- $(printf "%s\n" "$VAL" | cut -d "," --output-delimiter=" " -f 1-) + POS=$(printf "%s\n" "$ARR" |tr -d ']') + +else + printf "%s\n" "$VAL" +fi exit 0