7f3a8706521eaea870c6f983c13c22aa28dde2f3
[mono.git] / mono / docscripts / exdoc
1 #!/usr/bin/perl
2
3 if ($ARGV[0] eq "-h"){
4     $dir = $ARGV[1];
5     $html = 1;
6     shift @ARGV;
7     shift @ARGV;
8 }
9
10 if ($html){
11     opendir (D, "$dir/sources/") || die "Can not open $dir";
12     while ($n = readdir (D)){
13         if ($n =~ /mono-api-.*\.html$/){
14             open (IN, "$dir/sources/$n") || die "Can not open $n";
15             $files[$filecount] = $n;
16             while (<IN>){
17                 @files_content[$filecount] .= $_;
18             }
19             $filecount++;
20             close IN;
21         }
22     }
23 }
24
25 while (<ARGV>){
26         if (/\/\*\* *\n/){
27                 &process_doc;
28         } else {
29                 #print "IGNORING: $_";
30         }
31 }
32
33 if ($html){
34     for ($f = 0; $f < $filecount; $f++){
35         $name = $files[$f];
36         open (OUT, ">$dir/deploy/$name") || die "Can not create $dir/deploy/$name";
37         print "Merging: $name\n";
38         @a = split (/\n/, $files_content[$f]);
39
40         for ($ai = 0; $ai < $#a; $ai++){
41             $line = $a[$ai];
42
43             ($api) = $line =~  /<h4><a name=\"api:(\w+)\">(\w+)<\/a><\/h4>/;
44             if ($api ne ""){
45 print OUT<<EOF;
46 <blockquote>
47     <a name="api:$api">
48                 <table class="HeaderTable" width="100%" cellpadding="5">
49                         <tr bgcolor="#b0c4de"><td>
50                         <h3 class="api">$api</h3>
51                         </td></tr></table>
52     </a>
53
54     <blockquote>
55                         <table class="SignatureTable" bgcolor="#c0c0c0" cellspacing="0" width="100%">
56                         <tr><td>
57                                 <table class="InnerSignatureTalbe" cellpadding="10" cellspacing="0" width="100%">
58                                 <tr bgcolor="#f2f2f2"><td>
59     <h4>Prototype: $api</h4>
60                                 </td></tr>
61                                 </table>
62                         </td></tr>
63                         </table>
64     </blockquote>
65 <p>
66 EOF
67                     if ($arguments{$api} ne ""){
68                         print OUT "<h4>Parameters</h4>";
69                         print OUT "<blockquote><dl>";
70
71                         print OUT "$arguments{$api}\n";
72                         print OUT "</blockquote>";
73                     }
74                     if ($returns{$api} ne ""){
75                         print OUT "<h4>Returns</h4>";
76                         print OUT "<blockquote>";
77                         print OUT "$returns{$api}\n";
78                         print OUT "</blockquote>";
79                     }
80                     if ($bodies{$api} ne ""){
81                         print OUT "<h4>Remarks</h4>";
82                         print OUT "<blockquote>";
83                         print OUT "$bodies{$api}\n";
84                         print OUT "</blockquote>";
85                     }
86                     print OUT "</td></tr></table>";
87                     print OUT "\n";
88                     print OUT "</blockquote>";
89             } else {
90                 print OUT "$line\n";
91             }
92         }
93         close OUT;
94     }
95 }
96
97 sub process_doc {
98         $doc = "";
99         $func = <>;
100         chop $func;
101         $func =~ s/^ \* //;
102         $func =~ s/:$//;
103         print "Function: $func\n" if (!$html);
104         $args = "";
105         $inbody = 0;
106         $returns = "";
107         $body = "";
108         $functions[$fn++] = $func;
109
110         # Process arguments
111         while (<>){
112                 if (/^ \*\*?\//){
113                     $body =~ s/[@#](\w+)/<i>\1<\/i>/g;
114                     $returns =~ s/[@#](\w+)/<i>\1<\/i>/g;
115
116                     $args =~ s/@(\w+)/<i>\1<\/i>/g;
117                     $bodies{$func} = $body;
118                     $arguments{$func} = $args;
119                     $returns{$func} = $returns;
120                     return;
121                 }
122                 chop;
123                 s/^\ \*//;
124                 $_ = "\n<p>" if (/^\s+$/);
125                                 
126                 if ($inbody == 0){
127                     if (/\s*(\w+):(.*)/){
128                         $args .= "<dt><i>$1:</i></dt><dd>$2</dd>";
129                     } else {
130                         
131                         $body = "\t$_\n";
132                         $inbody = 1;
133                     }
134                 } elsif ($inbody == 1) {
135                     if (/Returns:/){
136                         s/Returns://;
137                         $returns = "\t$_\n";
138                         $inbody = 2;
139                     } else {
140                         $body .= "\n\t$_";
141                     }
142                 } else {
143                     $returns .= "\n\t$_";
144                 }
145                    
146         }
147 }