summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/genhelp.sh
blob: 293c58bd2b8dd2810cb5e5f14f5374f52ed143f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/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" }'