2017-05-10 02:10:59 +00:00
|
|
|
#!/bin/bash
|
2017-06-03 17:45:07 +00:00
|
|
|
# usage: ./genhelp.sh
|
2017-05-10 02:10:59 +00:00
|
|
|
#
|
|
|
|
# expects halibut to be installed in $PATH:
|
|
|
|
# http://www.chiark.greenend.org.uk/~sgtatham/halibut
|
2017-08-16 15:32:28 +00:00
|
|
|
#
|
|
|
|
# also requires host CC and lz4 library to be available
|
2017-05-10 02:10:59 +00:00
|
|
|
|
|
|
|
halibut --text src/puzzles.but
|
|
|
|
|
|
|
|
# preprocess the input
|
|
|
|
|
|
|
|
# strip leading whitespace
|
|
|
|
cat puzzles.txt | awk '{$1=$1; print}' > puzzles.txt.tmp
|
|
|
|
|
|
|
|
# cut at "Appendix A"
|
|
|
|
cat puzzles.txt.tmp | awk 'BEGIN { a=1; } /Appendix A/ { a = 0; } a==1' > puzzles.txt
|
|
|
|
|
|
|
|
rm puzzles.txt.tmp
|
|
|
|
|
2017-06-03 17:45:07 +00:00
|
|
|
# now split into different files
|
|
|
|
mkdir -p help
|
|
|
|
|
2018-03-18 02:54:07 +00:00
|
|
|
cat puzzles.txt | awk '
|
|
|
|
BEGIN {
|
|
|
|
file = "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
/#Chapter/ {
|
|
|
|
if($0 !~ / 1:/ && $0 !~ / 2:/)
|
|
|
|
{
|
|
|
|
if(file != "none")
|
|
|
|
print ";" > file;
|
|
|
|
file = "help/"tolower($3$4)".c";
|
|
|
|
|
|
|
|
if($3 ~ "Rectangles")
|
|
|
|
file = "help/rect.c";
|
|
|
|
|
|
|
|
print "/* auto-generated by genhelp.sh (intermediate file) */" > file;
|
|
|
|
print "/* DO NOT EDIT! */" > file;
|
|
|
|
print "const char help_text[] = " > file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file != "none" {
|
|
|
|
/* escape backslashes */
|
|
|
|
gsub(/\\/,"\\\\");
|
|
|
|
|
|
|
|
if($0 ~ /\$/)
|
|
|
|
print("WARNING: text contains dollar sign: change special character!" $0);
|
|
|
|
|
|
|
|
/* replace underscores with dollar signs (not used in any of the puzzles docs) */
|
|
|
|
if($0 ~ /http/)
|
|
|
|
gsub(/_/,"$");
|
|
|
|
|
|
|
|
begin = "";
|
|
|
|
|
|
|
|
last = substr($0, length($0), 1);
|
|
|
|
|
|
|
|
/* hack for chapter titles */
|
|
|
|
if(substr($0, 1, 1) == "#" || length($0) == 0)
|
|
|
|
term=" \\n";
|
|
|
|
else
|
|
|
|
term = " ";
|
|
|
|
|
|
|
|
/* custom code markup (halibut modification required) */
|
|
|
|
if(substr($0, 1, 2) == ">>")
|
|
|
|
{
|
|
|
|
gsub(/>> /,"");
|
|
|
|
term = " \\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
print "\"" begin $0 term "\"" > file;
|
|
|
|
}
|
|
|
|
|
|
|
|
END {
|
|
|
|
print ";" > file;
|
|
|
|
}
|
2017-06-03 17:45:07 +00:00
|
|
|
'
|
|
|
|
|
2017-08-16 15:32:28 +00:00
|
|
|
# now compress
|
2018-03-18 02:54:07 +00:00
|
|
|
for f in help/*.c
|
2017-08-16 15:32:28 +00:00
|
|
|
do
|
|
|
|
echo "Compressing: "$f
|
|
|
|
gcc compress.c $f -llz4 -o compress -O0
|
|
|
|
./compress > $f.tmp
|
|
|
|
mv $f.tmp $f
|
|
|
|
done
|
|
|
|
|
2020-06-25 18:37:55 +00:00
|
|
|
# generate quick help from all the .R files
|
|
|
|
cat src/*.R | awk 'print_next { print_next = 0; print; } /!begin/ && />/ && /gamedesc.txt/ { print_next = 1; }' | awk -F ":" '{print "const char quick_help_text[] = \""$5"\";" >> "help/"$1".c" }'
|
2018-04-24 23:03:33 +00:00
|
|
|
|
|
|
|
rm puzzles.txt
|
|
|
|
rm compress
|