rockbox/apps/plugins/puzzles/genhelp.sh
Franklin Wei 552a271c6f puzzles: remove redundant help content
It used to be that each puzzle had a complete copy of the entire
puzzles manual and the "quick help" text for every single puzzle. This
was obviously a waste, so now each puzzle only has the sections of the
manual that apply to it, saving about 100KB or so per puzzle. This
also has the added benefit of shrinking binary size enough to allow
full help support on the c200v2, which has been enabled.

Change-Id: I76c799635de058e4a48e0c18b79537857af7cf85
2017-06-03 13:45:07 -04:00

52 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
# usage: ./genhelp.sh
#
# expects halibut to be installed in $PATH:
# http://www.chiark.greenend.org.uk/~sgtatham/halibut
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
# now split into different files
mkdir -p help
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 */" > file;
print "/* DO NOT EDIT! */" > file;
print "const char help_text[] = " > file; }
}
file != "none" {
gsub(/\\/,"\\\\");
if($0 !~ /Chapter/ && substr($0, 1, 1) == "#")
begin = "\\n";
else begin = "";
last = substr($0, length($0), 1);
if(length($0) == 0 || last == "|" || last == "-" || (term == "\\n" && last == "3"))
term="\\n";
else term = " ";
print "\"" begin $0 term "\"" > file;
}
END {
print ";" > file;
}
'
# generate quick help from gamedesc.txt
cat src/gamedesc.txt | awk -F ":" '{print "const char quick_help_text[] = \""$5"\";" >> "help/"$1".c" }'