$(example-htmls):
@echo ================== Assembling $@
@TOC=`cat $D/examples/$(@:.html=)/$(@:.html=.cc) \
- | grep "@sect" \
- | perl -pi -e 's/.*\{(.*)\}.*/\1/; $$n=$$1; $$nn=$$1; \
- $$nn=~s/\s/_/g; $$_="<li><a href=\"#$$nn\">$$n</a></li>\n";' \
+ | perl program2toc \
| perl -pi -e 's/\"/\\\"/g;'` ; \
cat head.html \
| perl -pi -e '$$step="$@"; \
<ol>
<li> <a href="#Intro">Introduction</a>
<li> <a href="#CommProg">The commented program</a>
- <ul>
- TOC
- </ul>
+TOC
<li> <a href="#Results">Results</a>
<li> <a href="#PlainProg">The plain program</a>
</ol>
--- /dev/null
+print " <ul>\n";
+
+$level = 3;
+while (<>) {
+ if ( /\@sect(.)\{(.*)\}/ ) {
+ $newlevel = $1;
+ $text = $2;
+
+ # only allow header levels 3 and 4, since higher ones are
+ # reserved for top-level document headers
+ if (! ($newlevel =~ /[34]/)) {
+ print STDERR "Only header levels 3 and 4 are allowed.\n";
+ print STDERR "You had $newlevel.\n";
+ die;
+ }
+
+ if ($newlevel > $level) {
+ print " <ul>\n";
+ } elsif ($newlevel < $level) {
+ print " </ul>\n";
+ }
+
+ $reftext = $text;
+ $reftext =~ s/\s/_/g;
+ print " <li><a href=\"#$reftext\">$text</a>\n";
+
+ $level = $newlevel;
+ }
+}
+
+if ( $level == 4) {
+ print " </ul>\n";
+}
+print " </ul>\n";
In the beginning the Universe was created. This has made a lot of
people very angry and has been widely regarded as a bad move.
Douglas Adams