#---------------------------------------------------------------------------
#    $Id: program2toc 14782 2007-06-15 16:37:12Z kanschat $
#    Version: $Name$
#
#    Copyright (C) 2006, 2007 by the deal.II authors
#
#    This file is subject to QPL and may not be  distributed
#    without copyright and license information. Please refer
#    to the file deal.II/doc/license.html for the  text  and
#    further information on this license.
#
#---------------------------------------------------------------------------

print "    <ul>\n";

$level = 3;
while (<>) {
    if ( /\@sect(.)\{(.*)\}/ ) {
	$newlevel = $1;
	$text = $2;
	
	# only allow header levels 3 through 6, since higher ones are
	# reserved for top-level document headers
	if (! ($newlevel =~ /[3456]/)) {
	    print STDERR "Only header levels 3 through 6 are allowed.\n";
	    print STDERR "You had $newlevel.\n";
	    die;
	}

	if ($newlevel > $level) {
	    for ($i=$level; $i<$newlevel; ++$i) {
	        print "      <ul>\n";
            }
	} elsif ($newlevel < $level) {
	    for ($i=$newlevel; $i<$level; ++$i) {
	        print "      </ul>\n";
            }
	}

	$reftext = $text;

	# for the anchor, use the name of the section but discard
	# everything except for letters, numbers, and underscores
	$reftext =~ s/[^a-zA-Z0-9_]//g;

	# replace quotation marks by the appropriate HTML quotation marks
	$text =~ s!``!&#8220;!g;
	$text =~ s!''!&#8221;!g;

        # replace double dashes in comments by &mdash;
	$text =~ s!--!&mdash;!g;

	print "        <li><a href=\"#$reftext\">$text</a>\n";

	$level = $newlevel;
    } 
}

for (; $level>=3; --$level) {
    print "      </ul>\n";
}
