[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-kdoc
Subject:    update for kdocLyx.pm (kdoc 1) fixes a few missing layout resets
From:       Gerald Guglielmo <gug () fnal ! gov>
Date:       1999-03-25 22:03:45
[Download RAW message or body]

-- 
-Jerry->
gug@fnal.gov
Pepe's Theory of everything: "Under the right circumstances, things
happen."
["kdocLyx.pm" (text/plain)]

#    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, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
package kdocLyx;

require Ast;

## LaTeX Output.
# Peeks in main: quiet, version, classSource

BEGIN {
	$modname = "kdocLyx";
}

sub dumpDoc {
	my( $name, $node, $outputdir ) = @_;

	print "Generating Lyx documentation.\n" unless $main::quiet;

	open(LYX,"> $outputdir/$name.lyx") 
		|| die "Couldn't create $outputdir/".$name.".lyx.\n";

	print LYX<<EOF;
\\lyxformat 2.15
\\textclass article
\\begin_preamble
\\def\\D0{D\\O}  \\def\\d0{D\\O}
\\def\\mtl{{\\tt\\~\\relax}}
\\usepackage{a4}
\\usepackage{makeidx}
\\makeindex
\\end_preamble
\\language default
\\inputencoding default
\\fontscheme default
\\graphics default
\\paperfontsize 12
\\spacing single
\\papersize Default
\\paperpackage a4
\\use_geometry 0
\\use_amsmath 0
\\paperorientation portrait
\\secnumdepth 5
\\tocdepth 5     
\\paragraph_separation indent
\\defskip medskip
\\quotes_language english
\\quotes_times 2
\\papercolumns 1
\\papersides 1
\\paperpagestyle headings
\\layout Title

$name Library Index
\\layout Author
 Generated with KDOC $main::version
\\layout Standard
\\latex latex

\\backslash
clearpage
\\latex default
\\layout Standard    
\\begin_inset LatexCommand \\tableofcontents

\\end_inset
\\latex latex
\\backslash
clearpage
\\latex default
\\layout Standard    
EOF

	$node->Visit($modname);

	foreach $class ( @{$classes} )  {

		$class->Visit($modname);

		$inPre = 0;
		$doc = "";

		foreach $line ( split /\n/, $Description ) {
			if( $line =~ /<(pre|PRE)>/ ) {
				$inPre = 1;
				$doc .= "\\begin{verbatim}\n";
				next;
			}
			if( $line =~ m#</(pre|PRE)># ) {
				$inPre = 0;
				$doc .= "\\end{verbatim}\n";
				next;
			}
			if( !$inPre ) {
				$line =~ s/\@ref(\s*(#|::))?//g;
#				$line =~ s/([~#\$\\\&%#_\{\}])/\\$1/g;
				$line =~ s/([~#\$\\\&%#\{\}])/\\$1/g;
                                $line =~ s/<(code|pre)>/\\family typewriter\n/g;
                                $line =~ s/<\/(code|pre)>/\\family default\n/g;      
				$line =~ s/([<>])/\\family typewriter\n $1\\family default\n /g;
				$line =~ s/~/\\family typewriter\n~\\family default\n \\relax /g;
			}

			$doc .= $line."\n";
		}

		$ClassName = escapeLyx( $astNodeName );
		$ClassName2 = escape( $astNodeName );
		$Header =  escapeLyx( $Header );
		$ClassSee = escapeLyx( $ClassSee );

		print LYX<<EOF;
\\layout Section

\\emph on $ClassName \n
\\emph toggle class reference  
\\begin_inset LatexCommand \\index\{$ClassName2\}\n
\\end_inset \n
\\layout Standard\n
\\latex latex\n
\\vspace{-0.6cm}
\\hrulefill
\\latex default\n\n
\\layout Standard\n
Generated from the file 
\\size small \\family sans  $Header. \n
\\family default \\size default\n
EOF

		if( $class->{ "TmplArgs" } ne "" ) {
			print LYX "\\layout Description\n", 
				"template \\protected_separator form: ",
				"template <", escapeLyx( $class->{ "TmplArgs" } ),
				"> ",
				 $ClassName, "\n";

		}

		if( defined $class->{ "Ancestors" } ){
			print LYX "\\layout Description\n",
			"inherits: ";

			foreach $ancestor ( @{$Ancestors} ) {
				$ancName = $ancestor->{"astNodeName"};

				$str = " ".$ancName;

				if( defined $main::classSource{ $ancName } ) {
					$str .="(".$main::classSource{$ancName}.
							")";
				}

				print LYX escapeLyx( $str ),"\n";
			}

		}


		if( $Author ne "" || $Version ne "" || $ClassShort ne "" 
				|| $ClassSee ne "" ) {
			print LYX "\\layout Description\n";

			print LYX "Description: ", escapeLyx( $ClassShort ),"\n"
				if $ClassShort ne "";

			print LYX "\\layout Description\n","Version: ", escapeLyx( $Version ),"\n"
				if $Version ne "";

			print LYX "\\layout Description\n", "Author: ", escapeLyx( $Author ),"\n"
				if $Author ne "";		

			print LYX "\\layout Description\n", "See\\protected_separator Also: ", escapeLyx( \
$ClassSee ),"\n"  if $ClassSee ne "";		

		}

		print LYX "\n \\layout Standard\n$doc\n\n" if $Description ne "";

		dumpMembers( "public members", $public ) 
			if defined $class->{"public"};
		dumpMembers( "public slots", $public_slots )
			if defined $class->{"public_slots"};
		dumpMembers( "protected members", $protected )
			if defined $class->{"protected"};
		dumpMembers( "protected slots", $protected_slots )
			if defined $class->{"protected_slots"};
		dumpMembers( "signals", $signals )
			if defined $class->{"signals"};

		if( $main::dontDoPrivate == 0 ) {
			dumpMembers( "private members", $private )
				if defined $class->{"private"};
			dumpMembers( "private slots", $private_slots )
				if defined $class->{"private_slots"};
		}

		Ast::UnVisit();
	}

	Ast::UnVisit();



print LYX "\\begin_inset LatexCommand \\printindex\n","\\end_inset\n","\\the_end\n";

}

sub dumpMembers
{
	my( $access, $nodes ) = @_;

	print LYX "\\layout Subsection\n","$access\n";

# what am i going to do here?? texttt??? verbatim???  
	foreach $member ( @{$nodes} ) {

		$member->Visit($modname);
		
		$inPre = 0;
		$doc = "";

		foreach $line ( split /\n/, $Description ) {
			if( $line =~ /<(pre|PRE)>/ ) {
				$inPre = 1;
				$doc .= "\\begin{verbatim}\n";
				next;
			}
			if( $line =~ /<\/(pre|PRE)>/ ) {
				$inPre = 0;
				$doc .= "\\end{verbatim}\n";
				next;
			}
			if( !$inPre ) {
				$line =~ s/\@ref(\s*(#|::))?//g;
#				$line =~ s/([~#\$\\\&%#_\{\}])/\\$1/g;
				$line =~ s/([~#\$\\\&%#\{\}])/\\$1/g;
                                $line =~ s/<(code|pre)>/\\family typewriter\n/g;
                                $line =~ s/<\/(code|pre)>/\\family default\n/g;      
				$line =~ s/([<>])/\\family typewriter\n $1\\family default\n /g;
				$line =~ s/~/\\family typewriter\n~\\family default\n \\relax /g;
			}

			$doc .= $line."\n";
		}

		$astNodeName = escapeLyx( $astNodeName );
		$astNodeName2 = escape( $astNodeName );


		print LYX<<EOF;
\\layout Subsubsection*\n

$ClassName\:\:$astNodeName\n
\\begin_inset LatexCommand \\index{$ClassName2!$astNodeName2}\n
\\end_inset\n
\\begin_inset LatexCommand \\index{$astNodeName2!$ClassName2}\n
\\end_inset\n
\\layout Standard\n
\\latex latex\n
\\vspace{-0.65cm}
\\hrulefill
\\latex default\n
\\layout Standard
\\align left\n
EOF

		if( $Keyword eq "method" ) {
			$ReturnType = escapeLyx( $ReturnType );
			$Parameters = escapeLyx( $Parameters );
			$Parameters =~ s/\n+/ /g;
                        if($ReturnType eq "") {
                          if($Const eq "") {
 			    print LYX "\\family typewriter\n$astNodeName(",
			    "$Parameters);\\family default\n";
			  } else {
 			    print LYX "\\family typewriter\n$astNodeName(",
			    "$Parameters) $Const;\\family default\n";
			  }
                        }
			else {
                          if($Const eq "") {
   			    print LYX "\\family typewriter\n$ReturnType \
$astNodeName(","$Parameters);\\family default\n";  } else {
   			    print LYX "\\family typewriter\n$ReturnType $astNodeName(","$Parameters) \
$Const;\\family default\n";  }
			}
                        print LYX "\n\\layout Standard\n";
		}
		elsif ( $Keyword eq "property" ) {
			$Type =~ s/\ +//; # strip off any leading spaces
			$Type = escapeLyx( $Type );
			print LYX "\\family typewriter\n$Type $astNodeName;\\family default\n";
		}
		elsif ( $Keyword eq "typedef" ) {
			$Type = escapeLyx( $Type );
			print LYX "\\family typewriter\n$Type $astNodeName;\\family default\n";
		}
		elsif ( $Keyword eq "enum" ) {
			$Constants = escapeLyx( $Constants );
			$Constants =~ s/\n+/ /g;

			print LYX<<EOF
\\family typewriter 
enum $astNodeName
\\family default
$Constants;

EOF
		}

		print LYX<<EOF;
$doc

EOF
		if ( $Keyword eq "method" && 
			($Returns ne "" || $Exceptions ne "" || $#{$ParamDoc} != -1) ) {
                        if( $#{$ParamDoc} != -1 ) {
                                print LYX "\\layout Description\n",
                                        "Parameters:\\protected_separator\n", 
                                        "\n\\begin_deeper\n";
                                foreach $parameter ( @{$ParamDoc} ) {
                                        print LYX "\\layout Description\n";
                                        print LYX $parameter->{"astNodeName"},
                                        " ", $parameter->{"Description"},
                                        "\\protected_separator\n";
                                }      
                                print LYX "\\end_deeper\n";
			}
			if ( $Returns ne "" ) {
				$Returns = escapeLyx( $Returns );
				print LYX<<EOF;

                        
\\layout Description
Returns: 
\\protected_separator    
\\begin_deeper   
\\layout Standard
$Returns  
\\end_deeper
EOF
			}

			if ( $Exceptions ne "" ) {
				$Exceptions = escapeLyx( $Exceptions );
				print LYX<<EOF;
\\layout Description

Throws:
\\protected_separator    
\\begin_deeper   
\\layout Standard
$Exceptions   
\\end_deeper
EOF
			}

		}
		Ast::UnVisit();
	}
}

sub escapeLyx
{
	my( $str ) = @_;

	$str =~ s/\@ref\s+//g;
#	$str =~ s/([#\$\\\&%#_\{\}])/\\$1/g;
	$str =~ s/\\/\\$1/g;
# strip off multiple spaces
	$str =~ s/\ +/\ /g;
#	$str =~ s/([<>]+)/\\family typewriter\n $1\n \\family default/g;
#	$str =~ s/~/\\mtl /g;

	return $str;
}

sub escape
{
	my( $str ) = @_;

	$str =~ s/\@ref\s+//g;
	$str =~ s/([#\$\\\&%#_\{\}])/\\$1/g;
        $str =~ s/([<>]+)/\\texttt\{$1\}/g;
# 	$str =~ s/([<>]+)/\\family typewriter\n $1 \n \\family default/g;
	$str =~ s/~/\\mtl /g;

	return $str;
}

1;



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic