2021-10-08 15:54:25 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-10-13 01:31:39 +00:00
|
|
|
# run from project root directory
|
|
|
|
|
|
|
|
# parameters
|
|
|
|
# 1 - input filename of text file containing list of effects (probably FX.CONF or DFX.CONF)
|
|
|
|
# 2 - output filename for index file
|
|
|
|
# 3 - output filename for merged-effects file
|
|
|
|
# 4 - input directory of (previously assembled) effects files
|
|
|
|
|
2021-10-08 16:20:42 +00:00
|
|
|
# create or truncate merged-effects file
|
2021-10-08 15:54:25 +00:00
|
|
|
:>| "$3"
|
2021-10-08 16:20:42 +00:00
|
|
|
|
|
|
|
# make temp file with list of effect names
|
2021-10-08 15:54:25 +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-08 15:54:25 +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-08 15:54:25 +00:00
|
|
|
while read -r key; do
|
2021-10-13 16:03:42 +00:00
|
|
|
echo "!byte ${#key}+7" # OKVS record length
|
2021-10-08 16:20:42 +00:00
|
|
|
echo "!byte ${#key}" # OKVS key length
|
|
|
|
echo "!text \"$key\"" # OKVS key (effect name)
|
2021-10-13 16:03:42 +00:00
|
|
|
offset=$(wc -c < "$3")
|
|
|
|
size=$(wc -c < "$4/$key")
|
|
|
|
echo "!be24 $offset" # offset into merged-effects file
|
|
|
|
echo -n "!le16 "
|
|
|
|
# If offset+size does not cross a block boundary, use the size.
|
|
|
|
# Otherwise, round up size to the next block boundary.
|
|
|
|
# This padding does not get added to the file; it is just an
|
|
|
|
# optimization to avoid a partial copy on the last block read.
|
|
|
|
if [ $(($offset / 512)) -eq $((($offset + $size) / 512)) ]; then
|
|
|
|
echo "$size"
|
|
|
|
else
|
|
|
|
echo "$(((($offset + $size + 511) & -512) - $offset))"
|
|
|
|
fi
|
2021-10-13 01:31:39 +00:00
|
|
|
cat "$4/$key" >> "$3" # add effect code into merged-effects file
|
2021-10-08 16:20:42 +00:00
|
|
|
# (all effects were previously assembled)
|
2021-10-08 15:54:25 +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-08 15:54:25 +00:00
|
|
|
acme -o "$2" "$source"
|
2021-10-08 16:20:42 +00:00
|
|
|
|
|
|
|
# clean up
|
2021-10-08 15:54:25 +00:00
|
|
|
rm "$source"
|
|
|
|
rm "$records"
|