aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/RCU/Design/htmlqqz.sh
blob: d354f069559b8f9c186f87786d608c9fa773fe8e (plain) (blame)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/sh
#
# Usage: sh htmlqqz.sh file
#
# Extracts and converts quick quizzes in a proto-HTML document file.htmlx.
# Commands, all of which must be on a line by themselves:
#
#	"<p>@@QQ@@": Start of a quick quiz.
#	"<p>@@QQA@@": Start of a quick-quiz answer.
#	"<p>@@QQE@@": End of a quick-quiz answer, and thus of the quick quiz.
#	"<p>@@QQAL@@": Place to put quick-quiz answer list.
#
# Places the result in file.html.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, you can access it online at
# http://www.gnu.org/licenses/gpl-2.0.html.
#
# Copyright (c) 2013 Paul E. McKenney, IBM Corporation.

fn=$1
if test ! -r $fn.htmlx
then
	echo "Error: $fn.htmlx unreadable."
	exit 1
fi

echo "<!-- DO NOT HAND EDIT. -->" > $fn.html
echo "<!-- Instead, edit $fn.htmlx and run 'sh htmlqqz.sh $fn' -->" >> $fn.html
awk < $fn.htmlx >> $fn.html '

state == "" && $1 != "<p>@@QQ@@" && $1 != "<p>@@QQAL@@" {
	print $0;
	if ($0 ~ /^<p>@@QQ/)
		print "Bad Quick Quiz command: " NR " (expected <p>@@QQ@@ or <p>@@QQAL@@)." > "/dev/stderr"
	next;
}

state == "" && $1 == "<p>@@QQ@@" {
	qqn++;
	qqlineno = NR;
	haveqq = 1;
	state = "qq";
	print "<p><a name=\"Quick Quiz " qqn "\"><b>Quick Quiz " qqn "</b>:</a>"
	next;
}

state == "qq" && $1 != "<p>@@QQA@@" {
	qq[qqn] = qq[qqn] $0 "\n";
	print $0
	if ($0 ~ /^<p>@@QQ/)
		print "Bad Quick Quiz command: " NR ". (expected <p>@@QQA@@)" > "/dev/stderr"
	next;
}

state == "qq" && $1 == "<p>@@QQA@@" {
	state = "qqa";
	print "<br><a href=\"#qq" qqn "answer\">Answer</a>"
	next;
}

state == "qqa" && $1 != "<p>@@QQE@@" {
	qqa[qqn] = qqa[qqn] $0 "\n";
	if ($0 ~ /^<p>@@QQ/)
		print "Bad Quick Quiz command: " NR " (expected <p>@@QQE@@)." > "/dev/stderr"
	next;
}

state == "qqa" && $1 == "<p>@@QQE@@" {
	state = "";
	next;
}

state == "" && $1 == "<p>@@QQAL@@" {
	haveqq = "";
	print "<h3><a name=\"Answers to Quick Quizzes\">"
	print "Answers to Quick Quizzes</a></h3>"
	print "";
	for (i = 1; i <= qqn; i++) {
		print "<a name=\"qq" i "answer\"></a>"
		print "<p><b>Quick Quiz " i "</b>:"
		print qq[i];
		print "";
		print "</p><p><b>Answer</b>:"
		print qqa[i];
		print "";
		print "</p><p><a href=\"#Quick%20Quiz%20" i "\"><b>Back to Quick Quiz " i "</b>.</a>"
		print "";
	}
	next;
}

END {
	if (state != "")
		print "Unterminated Quick Quiz: " qqlineno "." > "/dev/stderr"
	else if (haveqq)
		print "Missing \"<p>@@QQAL@@\", no Quick Quiz." > "/dev/stderr"
}'