4cade/bin/buildokvs.sh

28 lines
914 B
Bash
Raw Normal View History

2021-10-06 20:22:54 +00:00
#!/bin/bash
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)
2024-05-24 20:24:55 +00:00
tr -d "\r" | awk '!/^$|^#/' > "$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
2021-10-23 05:36:04 +00:00
# assemble temp source file into binary OKVS data structure, then output that
out=$(mktemp)
acme -o "$out" "$source"
cat "$out"
2021-10-08 16:20:42 +00:00
# clean up
2021-10-23 05:36:04 +00:00
rm "$out"
2021-10-06 20:22:54 +00:00
rm "$source"
rm "$records"