From 77641d59a7ece60554da6cc1337d885786e5fc3f Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Sat, 17 Mar 2018 22:54:07 -0400 Subject: puzzles: add formatting to help viewer The help text is now processed to generate a style array to pass to the display_text library in addition to the text itself. The help text is still compressed using LZ4, and still fits on the c200v2. Change-Id: I7a3a664f90f67a1a018956c72d2b62d92b8ffd17 --- apps/plugins/puzzles/genhelp.sh | 84 +++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 28 deletions(-) (limited to 'apps/plugins/puzzles/genhelp.sh') diff --git a/apps/plugins/puzzles/genhelp.sh b/apps/plugins/puzzles/genhelp.sh index 1d4dac794b..007cdafd21 100755 --- a/apps/plugins/puzzles/genhelp.sh +++ b/apps/plugins/puzzles/genhelp.sh @@ -21,37 +21,65 @@ 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; - } +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; +} ' # now compress -for f in help/* +for f in help/*.c do echo "Compressing: "$f gcc compress.c $f -llz4 -o compress -O0 -- cgit v1.2.3