📄 makedoc.perl
字号:
#! /usr/local/bin/perl### <scriptdef>### <name> makedoc.perl </name>### <collection> MakLib Code Library </collection>### <overview> <eng>Generate HTML documents for source files</eng> ### <jpn>僜乕僗僼傽僀儖偐傜 HTML 僪僉儏儊儞僩偺惗惉</jpn> </overview>### <desc>### <p>### This script creates a collection of HTML documents from specified ### files. The lines started with /// or ### is extracted and formatted.### </p>### </desc>### <remark>### <p> Generated HTML files are placed in the html directory. </p>### </remark>### </scriptdef>$docdir = "html/";@order = ("typedef", "subclass", "enum", "const", "member", "ctor", "dtor", "func", "operator", "staticmember", "staticfunc", "class");%collections = ( "Maximum Entropy Estimator", "<jpn>嵟戝僄儞僩儘僺乕儌僨儖悇掕婍</jpn><eng>Maximum Entropy Model Estimator</eng>", "Library", "Private Library", "Other", "<jpn>偦偺懠</jpn><eng>Miscellaneous</eng>");$linkstr{"TopIndex"} = "<jpn>憤崌嶕堷</jpn><eng>Index</eng>";$link{"TopIndex"} = "index.html";for( $pass = 1; $pass <= 2; $pass++ ){ $membercount = 1; print STDERR "Pass $pass...\n"; foreach $f (@ARGV) {# $inbuf = "<name>$f</name>"; $inbuf = ""; $namespace = ""; if( $f =~ /\.sgml/ ) { open(IN, "<$f"); while( <IN> ) { $inbuf = $inbuf . $_; } close(IN); } elsif( $f =~ /\.perl/ ) { open(IN, "<$f"); while( <IN> ) { chop; if( /\s*###\s(.*)$/ ) { $inbuf = $inbuf . $1 . "\n"; } } close(IN); } elsif( $f =~ /\.h/ ) { open(IN, "<$f"); while( <IN> ) { chop; if( /namespace (\w[\w0-9]*)\s*($|{)/ ) ## } { $namespace = $1; } if( m#^\s*///\s(.*)$# ) { $l = $1; if( $l =~ /<(class|func)def>/ ) { $l = $l . "<namespace>$namespace</namespace>"; } $inbuf = $inbuf . $l . "\n"; } elsif( m#^(.*[^/])///\s(.*)$# ) { ($a,$b) = ($1, $2); $a = &encode(&escape($a)); $inbuf = $inbuf . "<!-- " . $a . " -->" . $b . "\n"; } elsif( m#\S# ) # non-space char { s#//.*##; $a = &encode(&escape($_)); $inbuf = $inbuf . "<!-- " . $a . " -->\n"; } else { # $inbuf = $inbuf . "\n"; } } close(IN); } else { next; } if( $inbuf =~ s#<collection>(.*?)</collection>##si ) { $collection = $1; } else { $collection = "" }; $col = "other"; foreach $i (keys %collections) { if( $collection =~ /$i/i ) { $col = $i; last; } } $linkstr{"Index"} = $collections{$col} . " <jpn>嶕堷</jpn><eng>Index</eng>"; $link{"Index"} = "index-$col.html"; @outm = @outn = @outc = @outf = @outv = @outk = (); while( $inbuf =~ s#<manualdef>(.*?)</manualdef>##si ) { push( @outm, &manualdef($1, $f, $collections{$col}) ); } while( $inbuf =~ s#<notiondef>(.*?)</notiondef>##si ) { push( @outn, ¬iondef($1, $f, $collections{$col}) ); } while( $inbuf =~ s#<classdef>(.*?)</classdef>##si ) { push( @outc, &classdef($1, $f, $collections{$col})) ; } while( $inbuf =~ s#<funcdef>(.*?)</funcdef>##si ) { push( @outf, &funcdef($1, $f, $collections{$col}) ); } while( $inbuf =~ s#<vardef>(.*?)</vardef>##si ) { push( @outv, &vardef($1, $f, $collections{$col}) ); } while( $inbuf =~ s#<constdef>(.*?)</constdef>##si ) { push( @outk, &constdef($1, $f, $collections{$col}) ); } if( $inbuf =~ s#<name>\s*(\S*?)\s*</name>##si ) { $name = $1; } else { $name = $f; } if( $inbuf =~ s#<remark>(.*?)</remark>##si ) { $remark = $1; } else { $remark = "" }; if( $inbuf =~ s#<overview>(.*?)</overview>##si ) { $overview = " - $1"; } else { $overview = "" }; if( $inbuf =~ s#<see>(.*?)</see>##si ) { $see = &makeref("Index, $1"); } else { $see = "<ref>Index</ref>" }; if( $inbuf =~ s#<usage>(.*?)</usage>##si ) { $usage = $1; } else { $usage = "" }; if( $inbuf =~ s#<desc>(.*?)</desc>##si ) { $desc = $1; } else { $desc = "" }; $link{$f} = $link{$name} = &make_filename("$name.html"); if( $pass == 2 ) { $out = ""; $out = $out . "<H2><jpn>巊梡朄</jpn><eng>Usage</eng></H2>\n$usage\n" if $usage ne ""; $out = $out . "<H2><jpn>愢柧</jpn><eng>Description</eng></H2>\n$desc\n" if $desc ne ""; if( @outn != 0 ) { $out = $out . "<H2><jpn>夝愢</jpn><eng>Descriptions</eng></H2>\n<ul>" . join("\n", @outn) . "</ul>"; } if( @outc != 0 ) { $out = $out . "<H2><jpn>僋儔僗</jpn><eng>Classes</eng></H2>\n<ul>" . join("\n", @outc) . "</ul>"; } if( @outf != 0 ) { $out = $out . "<H2><jpn>娭悢</jpn><eng>Functions</eng></H2>\n<ul>" . join("\n", @outf) . "</ul>"; } if( @outk != 0 ) { $out = $out . "<H2><jpn>僌儘乕僶儖掕悢</jpn><eng>Global Constants</eng></H2>\n<ul>" . join("\n", @outk) . "</ul>"; } if( @outv != 0 ) { $out = $out . "<H2><jpn>僌儘乕僶儖曄悢</jpn><eng>Global Variables</eng></H2>\n<ul>" . join("\n", @outv) . "</ul>"; } $out = $out . "<H2><jpn>拲庍</jpn><eng>Remarks</eng></H2>\n$remark\n" if $remark ne ""; if( $out ne "" ) { $out = "<H1><jpn>僼傽僀儖</jpn><eng>File</eng> $f $overview</H1>" . $out; $out = $out . "<H2><jpn>嶲徠</jpn><eng>See also</eng></H2>\n$see\n"; &sendfile( $link{$name}, "File $name: $collection", $out); push( @{$allouth{$col}}, "<li><ref>$f</ref>$overview" ); push( @{$alloutn{$col}}, @outn ); push( @{$alloutc{$col}}, @outc ); push( @{$alloutf{$col}}, @outf ); push( @{$alloutv{$col}}, @outv ); push( @{$alloutk{$col}}, @outk ); } push( @{$alloutm{$col}}, @outm ); } }}print STDERR "Finish...\n";$aout = "<H1> <jpn>憤崌嶕堷</jpn><eng>Index</eng></H1>\n";$aout = $aout . "<eng><a href=\"j-index.html\">Index in Japanese</eng></a><jpn><a href=\"index.html\">Index in English</a></jpn>";$aout = $aout . "<ul>";foreach $col (keys %collections){ $out = ""; $out = $out . "<H2><jpn>儅僯儏傾儖</jpn><eng>Manuals</eng></H2>\n<ul>" . join("\n", sort @{$alloutm{$col}}) . "</ul>\n" if @{$alloutm{$col}}; $out = $out . "<H2><jpn>夝愢</jpn><eng>Descriptions</eng></H2>\n<ul>" . join("\n", sort @{$alloutn{$col}}) . "</ul>\n" if @{$alloutn{$col}}; $out = $out . "<H2><jpn>僼傽僀儖</jpn><eng>Files</eng></H2>\n<ul>" . join("\n", sort @{$allouth{$col}}) . "</ul>\n" if @{$allouth{$col}}; $out = $out . "<H2><jpn>僋儔僗</jpn><eng>Classes</eng></H2>\n<ul>" . join("\n", sort @{$alloutc{$col}}) . "</ul>\n" if @{$alloutc{$col}}; $out = $out . "<H2><jpn>娭悢</jpn><eng>Functions</eng></H2>\n<ul>" . join("\n", sort @{$alloutf{$col}}) . "</ul>\n" if @{$alloutf{$col}}; $out = $out . "<H2><jpn>僌儘乕僶儖掕悢</jpn><eng>Global Constants</eng></H2>\n<ul>" . join("\n", sort @{$alloutk{$col}}) . "</ul>\n" if @{$alloutk{$col}}; $out = $out . "<H2><jpn>僌儘乕僶儖曄悢</jpn><eng>Global Variables</eng></H2>\n<ul>" . join("\n", sort @{$alloutv{$col}}) . "</ul>\n" if @{$alloutv{$col}}; if( $out ne "" ) { $out = "<H1>" . $collections{$col} . " <jpn>嶕堷</jpn><eng>Index</eng></H1>\n" . "<eng><a href=\"j-index-$col.html\">Index in Japanese</eng></a><jpn><a href=\"index-$col.html\">Index in English</a></jpn>" . $out; $out = $out . "\n<ref>TopIndex</ref>\n"; $linkstr{"Index-$col"} = $collections{$col} . " <jpn>嶕堷</jpn><eng>Index</eng>"; $link{"Index-$col"} = "index-$col.html"; $aout = $aout . "<li> <ref>Index-$col</ref>\n"; &sendfile( "index-$col.html", $linkstr{"Index-$col"}, $out); }}$aout = $aout . "</ul>\n";&sendfile( "index.html", "Index", $aout);&write_cssfile( "cssdef.css" );sub manualdef{ local($str, $file) = @_; local($name, $desc, $see, $decl, $i, $chapout, $body, $out, $lin, $delim, $mode, $overview ); local(@name, @title, @overview); if( $str =~ s#<name>(.*?)</name>##si ) { $name = $1; $name =~ s/\s//g; } else { die "no <name> in manualdef in file $file" }; if( $str =~ s#<title>(.*?)</title>##si ) { $title = $1; } else { die "no <title> in manualdef $name in file $file" }; if( $str =~ s#<overview>(.*?)</overview>##si ) { $overview = " - $1"; } else { $overview = "" }; $nchap = 0; while( $str =~ s#<chapter>(.*?)</chapter>##si ) { $nchap++; $body = $1; if( $body =~ s#<name>(.*?)</name>##si ) { $name[$nchap] = $1; $name[$nchap] =~ s/\s//g; } else { die "no <name> in manualdef in file $file" }; if( $body =~ s#<title>(.*?)</title>##si ) { $title[$nchap] = $1; } else { die "no <title> in chapter $name in file $file" }; if( $body =~ s#<overview>(.*?)</overview>##si ) { $overview[$nchap] = " - $1"; } else { $overview[$nchap] = ""; }; $body[$nchap] = $body; } if( $pass == 1 ) { $link{$name} = &make_filename("$name.html"); $linkstr{$name} = $title; for( $i=1; $i<=$nchap; $i++ ) { $link{$name[$i]} = &make_filename($name[$i] . ".html"); $linkstr{$name[$i]} = $title[$i]; } } else { $out = "<H1>$title</H1>\n<ol>"; for( $i=1; $i<=$nchap; $i++ ) { $out = $out . "<li><ref>$name[$i]</ref>$overview[$i]\n"; $chapout = "<H1>$title[$i]</H1>\n"; $chapout = $chapout . $body[$i]; &sendfile($link{$name[$i]}, $title[$i], $chapout); } $out = $out . "\n</ol>\n"; $out = $out . "<ref>Index</ref>\n"; $out =~ s#\n\n\n+#\n\n#g;# print $out; &sendfile($link{$name}, "$title", $out); } return "<li><ref>$name</ref>$overview";}sub notiondef{ local($str, $file) = @_; local($name, $desc, $see, $decl, $namespace, $classhead, $body, $out, $lin, $delim, $mode ); if( $str =~ s#<name>(.*?)</name>##si ) { $name = $1; $name =~ s/\s//g; } else { die "no <name> in notiondef in file $file" }; if( $str =~ s#<title>(.*?)</title>##si ) { $title = $1; } else { die "no <title> in notiondef $name in file $file" }; if( $str =~ s#<desc>(.*?)</desc>##si ) { $desc = $1; } else { die "no <desc> in notiondef $name in file $file" }; if( $str =~ s#<see>(.*?)</see>##si ) { $see = &makeref($1); } else { $see = "" }; if( $pass == 1 ) { $link{$name} = &make_filename("$name.html"); $linkstr{$name} = $title; } else { $out = "<H1>$title</H1>\n"; $out = $out . "$desc\n"; $out = $out . "<H2><jpn>嶲徠</jpn><eng>See also</eng></H2>\n$see\n" if $see ne "";# 嵟廔張棟 $out =~ s#\n\n\n+#\n\n#g;# print $out; &sendfile(&make_filename("$name.html"), "Function $name: $title", $out); } return "<li><ref>$name</ref>";}sub classdef{ local($str, $file, $title) = @_; local($name, $desc, $see, $decl, $namespace, $classhead, $body, $out, $lin, $delim, $mode ); if( $str =~ s#<name>(.*?)</name>##si ) { $name = $1; $name =~ s/\s//g; } else { die "no <name> in classdef" }; if( $str =~ s#<desc>(.*?)</desc>##si ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -