4cade/bin/buildhelp.sh

43 lines
1.5 KiB
Bash
Raw Normal View History

2021-10-06 02:20:15 +00:00
#!/bin/bash
# run from project root directory
2021-10-13 01:31:39 +00:00
# parameters
# 1 - input filename of text file containing list of games (probably GAMES.CONF)
# 2 - output filename for index file
# 3 - output filename for merged-gamehelp file
2021-10-13 17:11:42 +00:00
# 4 - input directory of gamehelp files
2021-10-13 01:31:39 +00:00
# make temp file with list of game filenames
records=$(mktemp)
grep "," < "$1" | grep -v "^#" | cut -d"," -f2 | cut -d"=" -f1 | sort > "$records"
2021-10-08 16:20:42 +00:00
# first help text is the 'TODO' placeholder screen
2021-10-13 17:11:42 +00:00
cp "$4"/STANDARD "$3"
standardsize=$(wc -c < "$3")
2021-10-13 01:31:39 +00:00
# make temp assembly source file that represents the binary OKVS data structure
source=$(mktemp)
(echo "*=0" # dummy program counter for assembler
echo "!le16 $(wc -l <"$records"), 0" # OKVS header
while read -r key; do
2021-10-13 17:11:42 +00:00
echo "!byte ${#key}+7" # OKVS record length
2021-10-13 01:31:39 +00:00
echo "!byte ${#key}" # OKVS key length
echo "!text \"$key\"" # OKVS key (effect name)
2021-10-13 17:11:42 +00:00
if [ -f "$4/$key" ]; then
2021-10-13 22:58:45 +00:00
echo "!be24 $(wc -c < "$3")" # offset into merged-gamehelp file (3-byte big-endian)
echo "!le16 $(wc -c < "$4/$key")" # size
2021-10-13 17:11:42 +00:00
cat "$4/$key" >> "$3" # add this gamehelp to the merged-gamehelp file
2021-10-13 01:31:39 +00:00
else
echo "!be24 0" # if game has no help, reuse placeholder at offset 0
2021-10-13 17:11:42 +00:00
echo "!le16 $standardsize" # and the size of the placeholder text
2021-10-13 01:31:39 +00:00
fi
done < "$records") > "$source"
# assemble temp source file to create binary OKVS data structure
acme -o "$2" "$source"
# clean up
rm "$source"
rm "$records"