diff options
Diffstat (limited to 'apps/plugins/puzzles/genhelp.sh')
-rwxr-xr-x | apps/plugins/puzzles/genhelp.sh | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/apps/plugins/puzzles/genhelp.sh b/apps/plugins/puzzles/genhelp.sh new file mode 100755 index 0000000000..f243a1d5f6 --- /dev/null +++ b/apps/plugins/puzzles/genhelp.sh | |||
@@ -0,0 +1,52 @@ | |||
1 | #!/bin/bash | ||
2 | # usage: ./genhelp.sh > helpcontent.sh | ||
3 | # | ||
4 | # expects halibut to be installed in $PATH: | ||
5 | # http://www.chiark.greenend.org.uk/~sgtatham/halibut | ||
6 | |||
7 | halibut --text src/puzzles.but | ||
8 | |||
9 | # preprocess the input | ||
10 | |||
11 | # strip leading whitespace | ||
12 | cat puzzles.txt | awk '{$1=$1; print}' > puzzles.txt.tmp | ||
13 | |||
14 | # cut at "Appendix A" | ||
15 | cat puzzles.txt.tmp | awk 'BEGIN { a=1; } /Appendix A/ { a = 0; } a==1' > puzzles.txt | ||
16 | |||
17 | rm puzzles.txt.tmp | ||
18 | |||
19 | cat <<EOF | ||
20 | /* auto-generated by genhelp.sh */ | ||
21 | /* DO NOT EDIT! */ | ||
22 | const int help_chapteroffsets[] = { | ||
23 | EOF | ||
24 | |||
25 | # generate chapter offset list | ||
26 | cat puzzles.txt | awk 'BEGIN { x = -1; n = 0; } /#Chapter/ { if($0 !~ / 1:/ && $0 !~ / 2:/) { if( x == -1 ) { x = n; } print n - x","; }} {n += length($0) + 1; if(x >= 0 && $0 !~ /Chapter/ && substr($0, 1, 1) == "#") n += 1;}' | ||
27 | |||
28 | cat <<EOF | ||
29 | }; | ||
30 | |||
31 | const char help_text[] = | ||
32 | EOF | ||
33 | |||
34 | # get starting byte offset | ||
35 | start=`cat puzzles.txt | awk 'BEGIN { x = -1; n = 0; } /#Chapter/ { if($0 !~ / 1:/ && $0 !~ / 2:/) { if( x == -1 ) { x = n; print x + 1; } print n - x","; }} {n += length($0) + 1; if(x >= 0 && $0 !~ /Chapter/ && substr($0, 1, 1) == "#") n += 1;}' | head -n 1` | ||
36 | |||
37 | # generate content | ||
38 | cat puzzles.txt | tail -c +$start | awk '{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 "\"";}' | ||
39 | |||
40 | cat <<EOF | ||
41 | ; | ||
42 | |||
43 | EOF | ||
44 | |||
45 | # length of longest chapter (not including null) | ||
46 | maxlen=`cat puzzles.txt | awk 'BEGIN { x = -1; n = 0; } /#Chapter/ { if($0 !~ / 1:/ && $0 !~ / 2:/) { if( x == -1 ) { x = n; } print n - x","; }} {n += length($0) + 1; if(x >= 0 && $0 !~ /Chapter/ && substr($0, 1, 1) == "#") n += 1;}' | awk 'BEGIN { max = 0; last = 0; } { if($0 - last > max) max = $0 - last; last = $0; } END { print max }'` | ||
47 | |||
48 | # remember number of chapters | ||
49 | num=`cat puzzles.txt | awk 'BEGIN { x = -1; n = 0; } /#Chapter/ { if($0 !~ / 1:/ && $0 !~ / 2:/) { if( x == -1 ) { x = n; } print n - x","; }} {n += length($0) + 1; if(x >= 0 && $0 !~ /Chapter/ && substr($0, 1, 1) == "#") n += 1;}' | wc -l` | ||
50 | |||
51 | echo "const int help_maxlen = "$maxlen";" | ||
52 | echo "const int help_numchapters = "$num";" | ||