Author: sparky
Date: Thu Mar 16 14:16:10 2006
New Revision: 7182

Modified:
   ppcrcd/trunk/doc/gendoc.pl
Log:
- almost finished


Modified: ppcrcd/trunk/doc/gendoc.pl
==============================================================================
--- ppcrcd/trunk/doc/gendoc.pl  (original)
+++ ppcrcd/trunk/doc/gendoc.pl  Thu Mar 16 14:16:10 2006
@@ -5,23 +5,14 @@
 use File::Find;
 
 my %options;
+my $loaded = 0;
 
-sub html {
-       $_ = $_[0];
-       s/&/&/g;
-       s/</&lt;/g;
-       s/>/&gt;/g;
-       s#&lt;_&lt;(.*?)&gt;_&gt;#<u>$1</u>#gs;
-       s#&lt;\*&lt;(.*?)&gt;\*&gt;#<b>$1</b>#gs;
-       s#&lt;/&lt;(.*?)&gt;/&gt;#<i>$1</i>#gs;
-       return $_;
-}
-
-find(\&addoption, qw(initrd.dir conf.dir));
 sub addoption {
-       return if (!-f || -l || /^\./ || /~$/);
-       my $file = $_;
-       open F_IN, $_ or warn "$File::Find::name: $!\n" and return;
+       return if (!-f || -l || /^\./ || /~$/ || /.svn/);
+       unless ( open F_IN, $_ ) {
+               warn "$File::Find::name: $!\n";
+               return;
+       }
        file: while ( <F_IN> ) {
                if ( s/^\s*?#@([a-z]*)@\s+(.*?)\s*:\s+// ) {
                        $options{$1} = {} unless exists $options{$1};
@@ -40,6 +31,20 @@
        close F_IN;
 }
 
+sub html {
+       $_ = $_[0];
+       s/&/&amp;/g;
+       s/</&lt;/g;
+       s/>/&gt;/g;
+       s#&lt;_&lt;(.*?)&gt;_&gt;#<u>$1</u>#gs;
+       s#&lt;\*&lt;(.*?)&gt;\*&gt;#<b>$1</b>#gs;
+       s#&lt;/&lt;(.*?)&gt;/&gt;#<i>$1</i>#gs;
+       s#^===(.*)===$#<h1>$1</h1>#gm;
+       s#^==(.*)==$#<h2>$1</h2>#gm;
+       s#^=(.*)=$#<h3>$1</h3>#gm;
+       return $_;
+}
+
 sub htmlize {
        my $pre = 0;
        my $out = "";
@@ -52,22 +57,72 @@
                } else {
                        if ( $pre ) {
                                $pre = 0;
+                               chomp $out;
                                $out .= "</pre>\n";
                        }
                }
                $out .= $line . "\n";
        }
+       if ($pre) {
+               chomp $out;
+               $out .= "</pre>\n";
+       }
        return $out;
 }
 
-foreach my $opt (keys %options) {
-       print "<h1> $opt </h1>\n";
+my $title="";
+sub adddoc {
+       $_ = $_[0];
+       return if (!-f || -l || /^\./ || /~$/ || /.svn/);
+       open F_IN, $_ or warn "$_: $!\n" and return;
+       my $file;
+       {
+               local $/ = undef;
+               $file = <F_IN>;
+       }
+       close F_IN;
+       $file = htmlize($file);
+       $file =~ m#^.*?<h1>(.*?)</h1>#o;
+       $title = $1;
+       while ( $file =~ /&lt;options "([a-z]*)"&gt;/ ) {
+               my $opt = $1;
+               my $options = "";
+               unless ( $loaded ) {
+                       find(\&addoption, qw(initrd.dir conf.dir));
+                       $loaded = 1;
+               }
        
-       foreach my $var (sort keys %{$options{$opt}}) {
-               print "<div>\n<h3>";
-               print html($var).":</h3>\n";
-               print htmlize($options{$opt}->{$var});
-               print "</div>\n";
+               foreach my $var (sort keys %{$options{$opt}}) {
+                       $options .= "<div>\n<h3>";
+                       $options .= html($var).":</h3>\n";
+                       $options .= htmlize($options{$opt}->{$var});
+                       $options .= "</div>\n";
+               }
+               
+               $file =~ s/&lt;options "$opt"&gt;/$options/;
        }
+       return $file;
 }
+
+my $content = adddoc(shift @ARGV);
+print <<EOF;
+<html>
+       <head>
+               <title>$title</title>
+               <style>
+                       pre     {
+                               padding: 5px;
+                               border: 1px dashed #909090;
+                       }
+                       div {
+                               padding: 5px;
+                       }
+               </style>
+       </head>
+       <body>
+$content
+       </body>
+</html>
+EOF
+
 # vim: ts=4:sw=4
_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to