3 # Usage: sh htmlqqz.sh file
5 # Extracts and converts quick quizzes in a proto-HTML document file.htmlx.
6 # Commands, all of which must be on a line by themselves:
8 # "<p>@@QQ@@": Start of a quick quiz.
9 # "<p>@@QQA@@": Start of a quick-quiz answer.
10 # "<p>@@QQE@@": End of a quick-quiz answer, and thus of the quick quiz.
11 # "<p>@@QQAL@@": Place to put quick-quiz answer list.
13 # Places the result in file.html.
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 2 of the License, or
18 # (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, you can access it online at
27 # http://www.gnu.org/licenses/gpl-2.0.html.
29 # Copyright (c) 2013 Paul E. McKenney, IBM Corporation.
32 if test ! -r $fn.htmlx
34 echo "Error: $fn.htmlx unreadable."
38 echo "<!-- DO NOT HAND EDIT. -->" > $fn.html
39 echo "<!-- Instead, edit $fn.htmlx and run 'sh htmlqqz.sh $fn' -->" >> $fn.html
40 awk < $fn.htmlx >> $fn.html '
42 state == "" && $1 != "<p>@@QQ@@" && $1 != "<p>@@QQAL@@" {
45 print "Bad Quick Quiz command: " NR " (expected <p>@@QQ@@ or <p>@@QQAL@@)." > "/dev/stderr"
49 state == "" && $1 == "<p>@@QQ@@" {
54 print "<p><a name=\"Quick Quiz " qqn "\"><b>Quick Quiz " qqn "</b>:</a>"
58 state == "qq" && $1 != "<p>@@QQA@@" {
59 qq[qqn] = qq[qqn] $0 "\n";
62 print "Bad Quick Quiz command: " NR ". (expected <p>@@QQA@@)" > "/dev/stderr"
66 state == "qq" && $1 == "<p>@@QQA@@" {
68 print "<br><a href=\"#qq" qqn "answer\">Answer</a>"
72 state == "qqa" && $1 != "<p>@@QQE@@" {
73 qqa[qqn] = qqa[qqn] $0 "\n";
75 print "Bad Quick Quiz command: " NR " (expected <p>@@QQE@@)." > "/dev/stderr"
79 state == "qqa" && $1 == "<p>@@QQE@@" {
84 state == "" && $1 == "<p>@@QQAL@@" {
86 print "<h3><a name=\"Answers to Quick Quizzes\">"
87 print "Answers to Quick Quizzes</a></h3>"
89 for (i = 1; i <= qqn; i++) {
90 print "<a name=\"qq" i "answer\"></a>"
91 print "<p><b>Quick Quiz " i "</b>:"
94 print "</p><p><b>Answer</b>:"
97 print "</p><p><a href=\"#Quick%20Quiz%20" i "\"><b>Back to Quick Quiz " i "</b>.</a>"
105 print "Unterminated Quick Quiz: " qqlineno "." > "/dev/stderr"
107 print "Missing \"<p>@@QQAL@@\", no Quick Quiz." > "/dev/stderr"