#---------------------------------------------------------------------------
#    $Id: program2doxyplain 14972 2007-08-17 20:00:32Z bangerth $
#    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 "\n";


while (<>) {
    # simply print non-comment lines and let doxygen do all the work.
    # the only thing we have to make sure is that if we copy /*...*/
    # comments that doxygen doesn't get confused; do so by simply
    # adding a space
    #
    # we also need to somehow strip the $ signs out of the svn Id: string
    # to avoid trouble. The same holds for the $Name:$ tags. All other $
    # signs are simply removed.
    if ( ! m!^\s*//! ) {
        s!/\*!/ \*!g;
        s!\*/!\* /!g;

	s!\$Id:(.*)\$!Subversion Id: \1!g;
	s!\$Name:?(.*)\$!Name: \1!g;

        s!\$!!g;

	print " * $_";
    } else {
	# for comments, all we do is replace section headers, and
	# generate addressable anchors
	if ( /\@sect/ ) {
	   m!\@sect(\d)\{(.*)\}\s*$!;
	   $sect_name = $2;

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

	   print "\@endcode\n";
	   print " <a name=\"plain-$sect_name\"></a>\n";
	   print "\@code\n";
	}
    }	
}
