diff options
Diffstat (limited to 'apps/plugins/puzzles/genhelp.sh')
-rwxr-xr-x | apps/plugins/puzzles/genhelp.sh | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/apps/plugins/puzzles/genhelp.sh b/apps/plugins/puzzles/genhelp.sh index f243a1d5f6..293c58bd2b 100755 --- a/apps/plugins/puzzles/genhelp.sh +++ b/apps/plugins/puzzles/genhelp.sh | |||
@@ -1,5 +1,5 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # usage: ./genhelp.sh > helpcontent.sh | 2 | # usage: ./genhelp.sh |
3 | # | 3 | # |
4 | # expects halibut to be installed in $PATH: | 4 | # expects halibut to be installed in $PATH: |
5 | # http://www.chiark.greenend.org.uk/~sgtatham/halibut | 5 | # http://www.chiark.greenend.org.uk/~sgtatham/halibut |
@@ -16,37 +16,37 @@ cat puzzles.txt.tmp | awk 'BEGIN { a=1; } /Appendix A/ { a = 0; } a==1' > puzzle | |||
16 | 16 | ||
17 | rm puzzles.txt.tmp | 17 | rm puzzles.txt.tmp |
18 | 18 | ||
19 | cat <<EOF | 19 | # now split into different files |
20 | /* auto-generated by genhelp.sh */ | 20 | mkdir -p help |
21 | /* DO NOT EDIT! */ | 21 | |
22 | const int help_chapteroffsets[] = { | 22 | cat puzzles.txt | awk 'BEGIN { file = "none"; } |
23 | EOF | 23 | /#Chapter/ { |
24 | 24 | if($0 !~ / 1:/ && $0 !~ / 2:/) | |
25 | # generate chapter offset list | 25 | { |
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;}' | 26 | if(file != "none") |
27 | 27 | print ";" > file; | |
28 | cat <<EOF | 28 | file = "help/"tolower($3$4)".c"; |
29 | }; | 29 | if($3 ~ "Rectangles") |
30 | 30 | file = "help/rect.c"; | |
31 | const char help_text[] = | 31 | print "/* auto-generated by genhelp.sh */" > file; |
32 | EOF | 32 | print "/* DO NOT EDIT! */" > file; |
33 | 33 | print "const char help_text[] = " > file; } | |
34 | # get starting byte offset | 34 | } |
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` | 35 | file != "none" { |
36 | 36 | gsub(/\\/,"\\\\"); | |
37 | # generate content | 37 | if($0 !~ /Chapter/ && substr($0, 1, 1) == "#") |
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 "\"";}' | 38 | begin = "\\n"; |
39 | 39 | else begin = ""; | |
40 | cat <<EOF | 40 | last = substr($0, length($0), 1); |
41 | ; | 41 | if(length($0) == 0 || last == "|" || last == "-" || (term == "\\n" && last == "3")) |
42 | 42 | term="\\n"; | |
43 | EOF | 43 | else term = " "; |
44 | 44 | print "\"" begin $0 term "\"" > file; | |
45 | # length of longest chapter (not including null) | 45 | } |
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 }'` | 46 | END { |
47 | 47 | print ";" > file; | |
48 | # remember number of chapters | 48 | } |
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` | 49 | ' |
50 | 50 | ||
51 | echo "const int help_maxlen = "$maxlen";" | 51 | # generate quick help from gamedesc.txt |
52 | echo "const int help_numchapters = "$num";" | 52 | cat src/gamedesc.txt | awk -F ":" '{print "const char quick_help_text[] = \""$5"\";" >> "help/"$1".c" }' |