diff options
Diffstat (limited to 'apps/plugins/puzzles/genhelp.sh')
-rwxr-xr-x | apps/plugins/puzzles/genhelp.sh | 84 |
1 files changed, 56 insertions, 28 deletions
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 | |||
21 | # now split into different files | 21 | # now split into different files |
22 | mkdir -p help | 22 | mkdir -p help |
23 | 23 | ||
24 | cat puzzles.txt | awk 'BEGIN { file = "none"; } | 24 | cat puzzles.txt | awk ' |
25 | /#Chapter/ { | 25 | BEGIN { |
26 | if($0 !~ / 1:/ && $0 !~ / 2:/) | 26 | file = "none"; |
27 | { | 27 | } |
28 | if(file != "none") | 28 | |
29 | print ";" > file; | 29 | /#Chapter/ { |
30 | file = "help/"tolower($3$4)".c"; | 30 | if($0 !~ / 1:/ && $0 !~ / 2:/) |
31 | if($3 ~ "Rectangles") | 31 | { |
32 | file = "help/rect.c"; | 32 | if(file != "none") |
33 | print "/* auto-generated by genhelp.sh */" > file; | 33 | print ";" > file; |
34 | print "/* DO NOT EDIT! */" > file; | 34 | file = "help/"tolower($3$4)".c"; |
35 | print "const char help_text[] = " > file; } | 35 | |
36 | } | 36 | if($3 ~ "Rectangles") |
37 | file != "none" { | 37 | file = "help/rect.c"; |
38 | gsub(/\\/,"\\\\"); | 38 | |
39 | if($0 !~ /Chapter/ && substr($0, 1, 1) == "#") | 39 | print "/* auto-generated by genhelp.sh (intermediate file) */" > file; |
40 | begin = "\\n"; | 40 | print "/* DO NOT EDIT! */" > file; |
41 | else begin = ""; | 41 | print "const char help_text[] = " > file; |
42 | last = substr($0, length($0), 1); | 42 | } |
43 | if(length($0) == 0 || last == "|" || last == "-" || (term == "\\n" && last == "3")) | 43 | } |
44 | term="\\n"; | 44 | |
45 | else term = " "; | 45 | file != "none" { |
46 | print "\"" begin $0 term "\"" > file; | 46 | /* escape backslashes */ |
47 | } | 47 | gsub(/\\/,"\\\\"); |
48 | END { | 48 | |
49 | print ";" > file; | 49 | if($0 ~ /\$/) |
50 | } | 50 | print("WARNING: text contains dollar sign: change special character!" $0); |
51 | |||
52 | /* replace underscores with dollar signs (not used in any of the puzzles docs) */ | ||
53 | if($0 ~ /http/) | ||
54 | gsub(/_/,"$"); | ||
55 | |||
56 | begin = ""; | ||
57 | |||
58 | last = substr($0, length($0), 1); | ||
59 | |||
60 | /* hack for chapter titles */ | ||
61 | if(substr($0, 1, 1) == "#" || length($0) == 0) | ||
62 | term=" \\n"; | ||
63 | else | ||
64 | term = " "; | ||
65 | |||
66 | /* custom code markup (halibut modification required) */ | ||
67 | if(substr($0, 1, 2) == ">>") | ||
68 | { | ||
69 | gsub(/>> /,""); | ||
70 | term = " \\n"; | ||
71 | } | ||
72 | |||
73 | print "\"" begin $0 term "\"" > file; | ||
74 | } | ||
75 | |||
76 | END { | ||
77 | print ";" > file; | ||
78 | } | ||
51 | ' | 79 | ' |
52 | 80 | ||
53 | # now compress | 81 | # now compress |
54 | for f in help/* | 82 | for f in help/*.c |
55 | do | 83 | do |
56 | echo "Compressing: "$f | 84 | echo "Compressing: "$f |
57 | gcc compress.c $f -llz4 -o compress -O0 | 85 | gcc compress.c $f -llz4 -o compress -O0 |