Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4f6ae11d18
Fetching contributors…

Cannot retrieve contributors at this time

file 293 lines (259 sloc) 6.273 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
#!/usr/bin/perl

if ($ARGV[0] eq "-h"){
    $dir = $ARGV[1];
    $html = 1;
    shift @ARGV;
    shift @ARGV;
}

if ($html){
    opendir (D, "$dir/sources/") || die "Can not open $dir";
    while ($n = readdir (D)){
if ($n =~ /mono-api-.*\.html$/){
open (IN, "$dir/sources/$n") || die "Can not open $n";
$files[$filecount] = $n;
while (<IN>){
@files_content[$filecount] .= $_;
if (/name="api:(.*?)"/){
$_ =~ s/.*name="api:(\w+?)".*/\1/;
$apis[$filecount] .= "$_";
}
}
$filecount++;
close IN;
}
    }
}

while (<ARGV>){
if (/\/\*\* *\n/){
&process_doc;
} else {
#print "IGNORING: $_";
}
}

if ($html){
    for ($f = 0; $f < $filecount; $f++){
$name = $files[$f];
open (OUT, "> $dir/html/$name") || die "Can not create $dir/html/$name";
print "Merging: $name\n";
print OUT<<EOF;
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <title>$name</title>
   <style type="text/css">
   h3 {
       font-size: 18px;
       padding-bottom: 4pt;
       border-bottom: 2px solid #dddddd;
   }
       
   .api {
     border: 1px solid;
     padding: 10pt;
     margin: 10pt;
   }

   .api-entry {
       border-bottom: none;
       font-size: 18px;
   }

   .prototype {
     border: 1px solid;
     background-color: #f2f2f2;
     padding: 5pt;
     margin-top: 5pt;
     margin-bottom: 5pt;
   }

   .header {
     border: 1px solid;
     padding: 0 0 5pt 5pt;
     margin: 10pt;
     white-space: pre;
       font-family: monospace;
   }
    
   .code {
     border: 1px solid;
     padding: 0 0 5pt 5pt;
     margin: 10pt;
     white-space: pre;
       font-family: monospace;
   }
   </style>
</head>
<body>
EOF
@a = split (/\n/, $files_content[$f]);

for ($ai = 0; $ai < $#a; $ai++){
$line = $a[$ai];

($api,$caption) = $line =~ /<h4><a name=\"api:(\w+)\">(\w+)<\/a><\/h4>/;
if ($api ne ""){
if ($api_shown == 1){
print OUT "</div>";
}
$api_shown = 1;
$proto = $prototype{$api};
if ($proto eq ""){
$proto = "Prototype: $api";
}

print OUT<<EOF;
 <a name="api:$api"></a>
 <div class="api">
    <div class="api-entry">$api</div>

    <div class="prototype">$proto</div>
<p>
EOF
&opt_print ("Parameters", $arguments{$api}, 1);
&opt_print ("Returns", $returns{$api}, 1);
&opt_print ("Remarks", $bodies{$api}, 0);
print OUT "\n";
} else {
if ($line =~ /@API_IDX@/){
$apis_toc = &create_toc ($apis[$f]);
$line =~ s/\@API_IDX\@/$apis_toc/;
}
if ($line =~ /^<h/){
print OUT "</div>";
$api_shown = 0;
}

print OUT "$line\n";
}
}
print OUT<<EOF;
</body>
</html>
EOF
close OUT;
system ("$ENV{runtimedir}/mono-wrapper convert.exe $dir/html/$name $dir/html/x-$name");

# clean up the mess that AgilityPack does, it CDATAs our CSS
open HACK, "$dir/html/x-$name" || die "Could not open $dir/html/x-$name";
open HACKOUT, ">$dir/deploy/$name" || die "Could not open output";

while (<HACK>){
s/^\/\/<!\[CDATA\[//;
s/^\/\/\]\]>\/\///;
print HACKOUT $_;
}
#system ("cp.exe $dir/html/$name $dir/deploy/$name");
    }
}

sub process_doc {
$doc = "";
$func = <>;
chop $func;
$func =~ s/^ \* //;
$func =~ s/:$//;
print "Function: $func\n" if (!$html);
$args = "";
$inbody = 0;
$returns = "";
$body = "";
$functions[$fn++] = $func;

# Process arguments
while (<>){
if (/^ \*\*?\//){
$body =~ s/[@#](\w+)/<i>\1<\/i>/g;
$returns =~ s/[@#](\w+)/<i>\1<\/i>/g;

$args =~ s/@(\w+)/<i>\1<\/i>/g;
$body =~ s/\n/ /;
$bodies{$func} = $body;
$arguments{$func} = $args;
$returns{$func} = $returns;
$proto = "";
while (<>){
$proto .= $_;
last if (/\{/);
}
$proto =~ s/{//;
# clean it up a little, remove newlines, empty space at end
$proto =~ s/ +$//;
# Turn "Type * xxx" into "Type* xxx"
$proto =~ s/^(\w+)\W+\*/\1\*/;
$prototype{$func} = $proto;
return;
}
chop;
s/^\ \*//;
$_ = "\n<p>" if (/^\s+$/);

if ($inbody == 0){
if (/\s*(\w+):(.*)/){
$args .= "<dt><i>$1:</i></dt><dd>$2</dd>";
} else {

$body = "\t$_\n";
$inbody = 1;
}
} elsif ($inbody == 1) {
if (/Returns?:/){
s/Returns?://;
$returns = "\t$_\n";
$inbody = 2;
} else {
$body .= "\n\t$_";
}
} else {
$returns .= "\n\t$_";
}

}
}

sub create_toc {
    my ($apis_listed) = @_;
    my $type_size = 0;
    my $name_size = 0;
    my $ret, $xname, $args, $line;
    $apis_toc = "";


    # Try to align things, so compute type size, method size, and arguments
    foreach $line (split /\n/, $apis_listed){
$p = $prototype{$line};
($ret, $xname, $args) = $p =~ /(.*)\n(\w+)[ \t](.*)/;
$tl = length ($ret);
$pl = length ($xname);

$type_size = $tl if ($tl > $type_size);
$name_size = $pl if ($pl > $name_size);
    }

    $type_size++;
    $name_size++;

    foreach $line (split /\n/, $apis_listed){
chop;
$p = $prototype{$line};
($ret, $xname, $args) = $p =~ /(.*)\n(\w+)[ \t](.*)/;

$rspace = " " x ($type_size - length ($ret));
$nspace = " " x ($name_size - length ($xname));
$args = &format ($args, length ($ret . $rspace . $xname . $nspace), 60);
$apis_toc .= "$ret$rspace<a href=\"\#api:$line\">$xname</a>$nspace$args\n";
    }
    return $apis_toc;
}

#
# Formats the rest of the arguments in a way that will fit in N columns
#
sub format {
    my ($args, $size, $limit) = @_;
    my $sret = "";

# return $args if ((length (args) + size) < $limit);
    
    $remain = $limit - $size;
    @sa = split /,/, $args;
    $linelen = $size;
    foreach $arg (@sa){
if ($sret eq ""){
$sret = $arg . ", ";
$linelen += length ($sret);
} else {
if ($linelen + length ($arg) < $limit){
$sret .= "FITS" . $arg . ", ";
} else {
$newline = " " x ($size) . $arg . ", ";
$linelen = length ($newline);
$sret .= "\n" . $newline;
}
}
    }
    $sret =~ s/, $/;/;
    return $sret;
}

sub opt_print {
    my ($caption, $opttext, $quote) = @_;

    if ($opttext ne "" && (!($opttext =~ /^[ \t]+$/))){
print OUT "<b>$caption</b>\n";
if ($quote == 1){
print OUT "<blockquote>$opttext</blockquote>\n";
} else {
print OUT "<p>$opttext\n";
}
    }
}
Something went wrong with that request. Please try again.