hacky array system

This commit is contained in:
Emma Tebibyte 2022-11-06 16:34:54 -05:00
parent 21dfb20e48
commit 36fd58b392
2 changed files with 22 additions and 2 deletions

12
test.toml Normal file
View File

@ -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" ]

12
tomcat
View File

@ -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