#! /usr/bin/awk -f # # Copyright 1998-2003 John D. Polstra # All rights reserved. # $Id: faqgen.awk,v 1.9 2003/03/04 19:26:14 jdp Exp $ BEGIN { secH = "H3"; } # A comment line beginning with "!#" /^!#/ { next; } # Id line /^![Ii]/ { id = gensub(/^[^ ]+[ ]+/, "", 1); next; } # Section /^![Ss]/ { inQuestion = 0; ++secCount; secName[secCount] = gensub(/^[^ ]+[ ]+/, "", 1); secFirst[secCount] = qCount + 1; next; } # Question (normal or new) /^![QqNn]/ { inQuestion = 1; ++qCount; if (NF >= 2) labels[qCount] = $2; else labels[qCount] = qCount; if ($1 ~ /![Nn]/) new[qCount] = 1; next; } # A line of the question inQuestion && /[^ ]/ { if (qCount in questions) questions[qCount] = questions[qCount] "\n" $0; else questions[qCount] = $0; next; } # Blank line terminating question inQuestion && /^[ ]*$/ { inQuestion = 0; next; } # A line of the answer { answers[qCount] = answers[qCount] $0 "\n"; next; } END { secFirst[secCount+1] = qCount + 1; # Emit the table of contents. for (sec = 1; sec <= secCount; sec++) { printf "<%s>%s%s>\n", secH, secName[sec], secH; printf "
\n%s
\n", answers[q]; } printf "