Bump buildtools
[mono-project.git] / docs / exdoc
blob517956c3e6387b07137055ee91f9d5f64b62c09d
1 #!/usr/bin/perl
3 if ($ARGV[0] eq "-h"){
4 $sourcedir = $ARGV[1];
5 $dir = $sourcedir;
6 $html = 1;
7 shift @ARGV;
8 shift @ARGV;
10 open (FILE, "$dir/api-style.css" || die "Did not find $dir/api-style.css");
11 while (<FILE>){
12 $css = $css . $_;
15 if ($ARGV[0] eq "-t"){
16 $dir = $ARGV[1];
17 shift @ARGV;
20 if ($html){
21 opendir (D, "$sourcedir/sources/") || die "Can not open $dir";
22 while ($n = readdir (D)){
23 if ($n =~ /mono-api-.*\.html$/){
24 open (IN, "$sourcedir/sources/$n") || die "Can not open $n";
25 $files[$filecount] = $n;
26 while (<IN>){
27 @files_content[$filecount] .= $_;
28 if (/name="api:(.*?)"/){
29 $_ =~ s/.*name="api:(\w+?)".*/\1/;
30 $apis[$filecount] .= "$_";
33 $filecount++;
34 close IN;
39 while (<ARGV>){
40 if (/\/\*\* *\n/){
41 &process_doc;
42 } else {
43 #print "IGNORING: $_";
47 if ($html){
48 for ($f = 0; $f < $filecount; $f++){
49 $name = $files[$f];
50 open (OUT, "> $dir/html/$name") || die "Can not create $dir/html/$name";
51 print "Merging: $name\n";
52 print OUT<<EOF;
53 <?xml version="1.0" encoding="utf-8"?>
54 <html xmlns="http://www.w3.org/1999/xhtml">
55 <head>
56 <title>$name</title>
57 <style type="text/css">
58 $css
59 </style>
60 </head>
61 <body>
62 <div class="mapi-docs">
63 EOF
64 @a = split (/\n/, $files_content[$f]);
65 $strikeextra = "";
66 $api_shown = 0;
67 for ($ai = 0; $ai < $#a; $ai++){
68 $line = $a[$ai];
70 ($api,$caption) = $line =~ /<h4><a name=\"api:(\w+)\">(\w+)<\/a><\/h4>/;
71 if ($api ne ""){
72 if ($api_shown == 1){
73 print OUT "</div> <!-- class=mapi -->\n\n";
74 if ($deprecated{$api}){
75 $strike = "mapi-strike";
76 $strikeextra = "</div><br><div class='mapi-deprecated'><b>Deprecated:</b> " . $deprecated{$api};
77 } else {
78 $strike = "";
79 $strikeextra = "";
82 $api_shown = 1;
83 $proto = $prototype{$api};
84 if ($proto eq ""){
85 $proto = "$api";
88 print OUT<<EOF;
89 <a name="api:$api"></a>
90 <div class="mapi">
91 <div class="mapi-entry $strike"><code>$api$strikeextra</code></div>
92 <div class="mapi-height-container">
93 <div class="mapi-ptr-container"></div>
94 <div class="mapi-description">
95 <div class="mapi-ptr"></div>
97 <div class="mapi-declaration mapi-section">Syntax</div>
98 <div class="mapi-prototype">$proto</div>
99 <p>
101 $ppars = $arguments{$api};
102 if ($ppars ne "" && (!($ppars =~ /^[ \t]+$/))){
103 print OUT " <div class=\"mapi-section\">Parameters</div>\n";
104 print OUT " <table class=\"mapi-parameters\"><tbody>".${arguments{$api}}."</tbody></table>";
107 &opt_print ("Return value", $returns{$api}, 0);
108 &opt_print ("Description", $bodies{$api}, 0);
109 print OUT " </div><!--mapi-description-->\n </div><!--height container-->\n";
110 } else {
111 if ($line =~ /@API_IDX@/){
112 $apis_toc = &create_toc ($apis[$f]);
113 $line =~ s/\@API_IDX\@/$apis_toc/;
115 if ($line =~ /^<h4/){
116 print OUT "</div>\n";
117 $api_shown = 0;
119 if ($line =~ /`/){
121 print OUT "$line\n";
124 print OUT<<EOF;
125 </div>
126 </body>
127 </html>
129 close OUT;
130 system ("$ENV{runtimedir}/mono-wrapper convert.exe $dir/html/$name $dir/html/x-$name");
133 # clean up the mess that AgilityPack does, it CDATAs our CSS
134 open HACK, "$dir/html/x-$name" || die "Could not open $dir/html/x-$name";
135 open HACKOUT, ">$dir/deploy/$name" || die "Could not open output";
137 $line = 0;
138 $doprint = 0;
139 while (<HACK>){
140 print HACKOUT $last if ($doprint);
141 $line++;
142 s/^\/\/<!\[CDATA\[//;
143 s/^\/\/\]\]>\/\///;
145 # Remove the junk <span> wrapper generated by AgilityPack
146 if ($line==1){
147 s/<span>//;
149 if (/<style type/){
150 # Replace the CSS in the XHTML output with the original CSS
151 print HACKOUT $_;
152 print HACKOUT $css;
153 while (<HACK>){
154 last if (/<\/style>/);
157 $last = $_;
158 $doprint = 1;
160 if (!($last =~ /span/)){
161 print HACKOUT $last;
164 #system ("cp.exe $dir/html/$name $dir/deploy/$name");
168 sub process_doc {
169 $doc = "";
170 $func = <>;
171 chop $func;
172 $func =~ s/^ \* //;
173 $func =~ s/:$//;
174 print "Function: $func\n" if (!$html);
175 $args = "";
176 $inbody = 0;
177 $returns = "";
178 $body = "";
179 $functions[$fn++] = $func;
180 $deprecated = 0;
181 # Process arguments
182 while (<>){
183 s/NULL/<code>NULL<\/code>/g;
184 s/TRUE/<code>TRUE<\/code>/g;
185 s/FALSE/<code>FALSE<\/code>/g;
186 if (/^ \*\*?\//){
187 $body =~ s/@(\w+)/<i>\1<\/i>/g;
188 $returns =~ s/@(\w+)/<i>\1<\/i>/g;
189 $args =~ s/@(\w+)/<i>\1<\/i>/g;
191 $body =~ s/#(\w+)/<code>\1<\/code>/g;
192 $returns =~ s/#(\w+)/<code>\1<\/code>/g;
193 $args =~ s/#(\w+)/<code>\1<\/code>/g;
195 $returns =~ s/\`([:.\w\*]+)\`/<code>\1<\/code>/g;
196 $args =~ s/\`([:.\w\*]+)\`/<code>\1<\/code>/g;
197 $body =~ s/\`([:.\w\*]+)\`/<code>\1<\/code>/g;
199 $body =~ s/\n/ /;
200 $bodies{$func} = $body;
201 $arguments{$func} = $args;
202 $deprecated{$func} = $deprecated;
203 $returns{$func} = $returns;
204 $proto = "";
205 while (<>){
206 $proto .= $_;
207 last if (/\{/);
209 $proto =~ s/{//;
210 # clean it up a little, remove newlines, empty space at end
211 $proto =~ s/ +$//;
212 # Turn "Type * xxx" into "Type* xxx"
213 $proto =~ s/^(\w+)\W+\*/\1\*/;
214 $prototype{$func} = $proto;
215 return;
217 chop;
218 s/^\ \*//;
219 $_ = "<p>" if (/^\s*$/);
221 if ($inbody == 0){
222 if (/\s*(\w+):(.*)/){
223 if ($1 eq "deprecated"){
224 $deprecated = $2;
225 } else {
226 #$args .= "<dt><i>$1:</i></dt><dd>$2</dd>";
227 $args .= "<tr><td><i>$1</i><td>$2</td></td></tr>";
229 } else {
231 $body = "\t$_\n";
233 $inbody = 1;
235 } elsif ($inbody == 1) {
236 if (/Returns?:/){
237 s/Returns?://;
238 $returns = "\t$_\n";
239 $inbody = 2;
240 } else {
241 $body .= "\n\t$_";
243 } else {
244 $returns .= "\n\t$_";
250 sub create_toc {
251 my ($apis_listed) = @_;
252 my $type_size = 0;
253 my $name_size = 0;
254 my $ret, $xname, $args, $line;
255 $apis_toc = "";
258 # Try to align things, so compute type size, method size, and arguments
259 foreach $line (split /\n/, $apis_listed){
260 $p = $prototype{$line};
261 ($ret, $xname, $args) = $p =~ /(.*)\n(\w+)[ \t](.*)/;
262 $tl = length ($ret);
263 $pl = length ($xname);
265 $type_size = $tl if ($tl > $type_size);
266 $name_size = $pl if ($pl > $name_size);
269 $type_size++;
270 $name_size++;
272 foreach $line (split /\n/, $apis_listed){
273 chop;
274 $p = $prototype{$line};
275 ($ret, $xname, $args) = $p =~ /(.*)\n(\w+)[ \t](.*)/;
276 if ($xname eq ""){
277 $xname = $line;
280 $rspace = " " x ($type_size - length ($ret));
281 $nspace = " " x ($name_size - length ($xname));
282 $args = &format ($args, length ($ret . $rspace . $xname . $nspace), 60);
283 $apis_toc .= "$ret$rspace<a href=\"\#api:$line\">$xname</a>$nspace$args\n";
285 return $apis_toc;
289 # Formats the rest of the arguments in a way that will fit in N columns
291 sub format {
292 my ($args, $size, $limit) = @_;
293 my $sret = "";
295 # return $args if ((length (args) + size) < $limit);
297 $remain = $limit - $size;
298 @sa = split /,/, $args;
299 $linelen = $size;
300 foreach $arg (@sa){
301 if ($sret eq ""){
302 $sret = $arg . ", ";
303 $linelen += length ($sret);
304 } else {
305 if ($linelen + length ($arg) < $limit){
306 $sret .= "FITS" . $arg . ", ";
307 } else {
308 $newline = " " x ($size) . $arg . ", ";
309 $linelen = length ($newline);
310 $sret .= "\n" . $newline;
314 $sret =~ s/, $/;/;
315 return $sret;
318 sub opt_print {
319 my ($caption, $opttext, $quote) = @_;
321 if ($opttext ne "" && (!($opttext =~ /^[ \t]+$/))){
322 print OUT " <div class=\"mapi-section\">$caption</div>\n";
323 print OUT " <div>$opttext</div>\n";