got rid of tabs ;-;

This commit is contained in:
Emma Tebibyte 2022-11-21 23:59:32 -05:00
parent 1e6d0f2154
commit 60eba51303
1 changed files with 30 additions and 30 deletions

60
tomcat
View File

@ -8,23 +8,23 @@ argv2="$2"
# check usage # check usage
if ! test -n "$1"; then if ! test -n "$1"; then
printf "Usage: %s [OPTIONS] [TABLE.KEY[INDEX]] [FILE]\n" "$0" 1>&2 printf "Usage: %s [OPTIONS] [TABLE.KEY[INDEX]] [FILE]\n" "$0" 1>&2
exit 64 # sysexits(3) EX_USAGE exit 64 # sysexits(3) EX_USAGE
fi fi
# test if input has a period # test if input has a period
if test -n "$(printf "%s\n" "$argv1" | sed -n '/.*\..*/p')"; then if test -n "$(printf "%s\n" "$argv1" | sed -n '/.*\..*/p')"; then
# cut out everything beyond the first period for TABLE # cut out everything beyond the first period for TABLE
TABLE=$(printf "%s\n" "$argv1" | sed -n 's/\..*//p') TABLE=$(printf "%s\n" "$argv1" | sed -n 's/\..*//p')
# cut out everything before the first period for KEY # cut out everything before the first period for KEY
KEY=$(printf "%s\n" "$argv1" | sed -n 's/^[^.]*\.//p') KEY=$(printf "%s\n" "$argv1" | sed -n 's/^[^.]*\.//p')
! test -n "$KEY" &&\ ! test -n "$KEY" &&\
printf "%s: No key specified\n" "$argv0" &&\ printf "%s: No key specified\n" "$argv0" &&\
exit 65 # sysexits(3) EX_DATAERR exit 65 # sysexits(3) EX_DATAERR
else else
printf "%s: No key specified\n" "$argv0" printf "%s: No key specified\n" "$argv0"
exit 65 # sysexits(3) EX_DATAERR exit 65 # sysexits(3) EX_DATAERR
fi fi
# remove array index from KEY # remove array index from KEY
@ -34,40 +34,40 @@ ARR=$(printf "%s\n" "$argv1" | sed -n 's/.\+\[//p' | tr -d ']')
# test if argument 2 is a file or not # test if argument 2 is a file or not
if test -e "$argv2"; then if test -e "$argv2"; then
# set TOML to the text from the file # set TOML to the text from the file
TOML=$(sed 's/[^"#]#\+.*//g' <"$argv2" | sed 's/^#.*//g' ) TOML=$(sed 's/[^"#]#\+.*//g' <"$argv2" | sed 's/^#.*//g' )
else else
# set TOML to the text from stdin # set TOML to the text from stdin
TOML=$(printf "%s\n" "$argv2" | sed 's/[^"#]#\+.*//g') TOML=$(printf "%s\n" "$argv2" | sed 's/[^"#]#\+.*//g')
fi fi
if test -n "$TABLE"; then if test -n "$TABLE"; then
KEYS=$(printf "%s\n" "$TOML" |\ KEYS=$(printf "%s\n" "$TOML" |\
# output only lines between TABLE and the next table # output only lines between TABLE and the next table
awk "/^\[$TABLE\]/{flag=1; next} /^\[/{flag=0} flag" - ) awk "/^\[$TABLE\]/{flag=1; next} /^\[/{flag=0} flag" - )
else else
KEYS=$(printf "%s\n" "$TOML" |\ KEYS=$(printf "%s\n" "$TOML" |\
# output only lines before the first table # output only lines before the first table
awk '1;/^\[/{exit}' - | sed -n '/^[^[]/p') awk '1;/^\[/{exit}' - | sed -n '/^[^[]/p')
fi fi
# set VAL to the parsed KEYS list # set VAL to the parsed KEYS list
VAL=$(printf "%s\n" "$KEYS" |\ VAL=$(printf "%s\n" "$KEYS" |\
# remove the key from the string and delineate arrays, removing # remove the key from the string and delineate arrays, removing
# brackets, trailing commas, and leading spaces # brackets, trailing commas, and leading spaces
sed -n "s/$KEY *= *//p" | sed 's/", "/ /g' | tr -d '[]"' |\ sed -n "s/$KEY *= *//p" | sed 's/", "/ /g' | tr -d '[]"' |\
sed 's/, *$//g' | sed 's/^ \+//g' | sed 's/ \+$//g') sed 's/, *$//g' | sed 's/^ \+//g' | sed 's/ \+$//g')
# test if ARR is set; if it is, then we have an array index to grab # test if ARR is set; if it is, then we have an array index to grab
if test -n "$ARR"; then if test -n "$ARR"; then
# change the line delineator to newlines for parsing and output the result # change the line delineator to newlines for parsing and output the result
printf "%s\n" "$VAL" | sed 's/ /\n/g' | head -n "$ARR" |\ printf "%s\n" "$VAL" | sed 's/ /\n/g' | head -n "$ARR" |\
tail -n 1 tail -n 1
elif ! test -n "$VAL"; then elif ! test -n "$VAL"; then
printf "%s: %s: No such key or table\n" "$argv0" "$argv1" printf "%s: %s: No such key or table\n" "$argv0" "$argv1"
exit 65 # sysexits(3) EX_DATAERR exit 65 # sysexits(3) EX_DATAERR
else else
printf "%s\n" "$VAL" printf "%s\n" "$VAL"
fi fi
exit 0 exit 0