4cade/bin/buildokvs.sh

27 lines
922 B
Bash
Raw Normal View History

2021-10-06 20:22:54 +00:00
#!/bin/bash
# run from project root directory
2021-10-08 16:20:42 +00:00
# make temp file with just the key/value pairs (strip blank lines, comments, eof marker)
2021-10-06 20:22:54 +00:00
records=$(mktemp)
grep -v "^$" < "$1" | grep -v "^#" | grep -v "^\[" > "$records"
2021-10-08 16:20:42 +00:00
# make temp assembly source file that represents the binary OKVS data structure
2021-10-06 20:22:54 +00:00
source=$(mktemp)
2021-10-08 16:20:42 +00:00
(echo "*=0" # dummy program counter for assembler
echo "!le16 $(wc -l <"$records"), 0" # OKVS header
2021-10-06 20:22:54 +00:00
while IFS="=" read -r key value; do
2021-10-08 16:20:42 +00:00
echo "!byte ${#key}+${#value}+3" # OKVS record length
echo "!byte ${#key}" # OKVS key length
echo "!text \"$key\"" # OKVS key
echo "!byte ${#value}" # OKVS value length
echo "!text \"$value\"" # OKVS value
2021-10-06 20:22:54 +00:00
done < "$records") > "$source"
2021-10-08 16:20:42 +00:00
# assemble temp source file to create binary OKVS data structure
2021-10-06 20:22:54 +00:00
acme -o "$2" "$source"
2021-10-08 16:20:42 +00:00
# clean up
2021-10-06 20:22:54 +00:00
rm "$source"
rm "$records"