#!/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: # # "

@@QQ@@": Start of a quick quiz. # "

@@QQA@@": Start of a quick-quiz answer. # "

@@QQE@@": End of a quick-quiz answer, and thus of the quick quiz. # "

@@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 "" > $fn.html echo "" >> $fn.html awk < $fn.htmlx >> $fn.html ' state == "" && $1 != "

@@QQ@@" && $1 != "

@@QQAL@@" { print $0; if ($0 ~ /^

@@QQ/) print "Bad Quick Quiz command: " NR " (expected

@@QQ@@ or

@@QQAL@@)." > "/dev/stderr" next; } state == "" && $1 == "

@@QQ@@" { qqn++; qqlineno = NR; haveqq = 1; state = "qq"; print "

Quick Quiz " qqn ":" next; } state == "qq" && $1 != "

@@QQA@@" { qq[qqn] = qq[qqn] $0 "\n"; print $0 if ($0 ~ /^

@@QQ/) print "Bad Quick Quiz command: " NR ". (expected

@@QQA@@)" > "/dev/stderr" next; } state == "qq" && $1 == "

@@QQA@@" { state = "qqa"; print "
Answer" next; } state == "qqa" && $1 != "

@@QQE@@" { qqa[qqn] = qqa[qqn] $0 "\n"; if ($0 ~ /^

@@QQ/) print "Bad Quick Quiz command: " NR " (expected

@@QQE@@)." > "/dev/stderr" next; } state == "qqa" && $1 == "

@@QQE@@" { state = ""; next; } state == "" && $1 == "

@@QQAL@@" { haveqq = ""; print "

" print "Answers to Quick Quizzes

" print ""; for (i = 1; i <= qqn; i++) { print "" print "

Quick Quiz " i ":" print qq[i]; print ""; print "

Answer:" print qqa[i]; print ""; print "

Back to Quick Quiz " i "." print ""; } next; } END { if (state != "") print "Unterminated Quick Quiz: " qqlineno "." > "/dev/stderr" else if (haveqq) print "Missing \"

@@QQAL@@\", no Quick Quiz." > "/dev/stderr" }'