summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/genhelp.sh
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2017-05-09 22:10:59 -0400
committerFranklin Wei <git@fwei.tk>2017-05-16 16:45:39 -0400
commit001860ce7856e20b890d8adf425c899540a5d5d3 (patch)
tree61df98408207d85a05e29cfca1edb91ec6cb4d4a /apps/plugins/puzzles/genhelp.sh
parent7482b821753ac226806439fecec4f9ff504c0e90 (diff)
downloadrockbox-001860ce7856e20b890d8adf425c899540a5d5d3.tar.gz
rockbox-001860ce7856e20b890d8adf425c899540a5d5d3.zip
puzzles: full help system
- embeds the upstream halibut documentation for plugin use - currently every plugin has a copy of the help text, but in the future a centralized system using overlays might be better Change-Id: Idb6eb9accc2fa786a4c6bc2b704e7cf5fd3f78dd
Diffstat (limited to 'apps/plugins/puzzles/genhelp.sh')
-rwxr-xr-xapps/plugins/puzzles/genhelp.sh52
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
7halibut --text src/puzzles.but
8
9# preprocess the input
10
11# strip leading whitespace
12cat puzzles.txt | awk '{$1=$1; print}' > puzzles.txt.tmp
13
14# cut at "Appendix A"
15cat puzzles.txt.tmp | awk 'BEGIN { a=1; } /Appendix A/ { a = 0; } a==1' > puzzles.txt
16
17rm puzzles.txt.tmp
18
19cat <<EOF
20/* auto-generated by genhelp.sh */
21/* DO NOT EDIT! */
22const int help_chapteroffsets[] = {
23EOF
24
25# generate chapter offset list
26cat 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
28cat <<EOF
29};
30
31const char help_text[] =
32EOF
33
34# get starting byte offset
35start=`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
38cat 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
40cat <<EOF
41;
42
43EOF
44
45# length of longest chapter (not including null)
46maxlen=`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
49num=`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
51echo "const int help_maxlen = "$maxlen";"
52echo "const int help_numchapters = "$num";"