exdoc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. #!/usr/bin/perl
  2. if ($ARGV[0] eq "-h"){
  3. $dir = $ARGV[1];
  4. $html = 1;
  5. shift @ARGV;
  6. shift @ARGV;
  7. }
  8. if ($html){
  9. opendir (D, "$dir/sources/") || die "Can not open $dir";
  10. while ($n = readdir (D)){
  11. if ($n =~ /mono-api-.*\.html$/){
  12. open (IN, "$dir/sources/$n") || die "Can not open $n";
  13. $files[$filecount] = $n;
  14. while (<IN>){
  15. @files_content[$filecount] .= $_;
  16. if (/name="api:(.*?)"/){
  17. $_ =~ s/.*name="api:(\w+?)".*/\1/;
  18. $apis[$filecount] .= "$_";
  19. }
  20. }
  21. $filecount++;
  22. close IN;
  23. }
  24. }
  25. }
  26. while (<ARGV>){
  27. if (/\/\*\* *\n/){
  28. &process_doc;
  29. } else {
  30. #print "IGNORING: $_";
  31. }
  32. }
  33. if ($html){
  34. for ($f = 0; $f < $filecount; $f++){
  35. $name = $files[$f];
  36. open (OUT, "> $dir/html/$name") || die "Can not create $dir/html/$name";
  37. print "Merging: $name\n";
  38. print OUT<<EOF;
  39. <?xml version="1.0" encoding="utf-8"?>
  40. <html xmlns="http://www.w3.org/1999/xhtml">
  41. <head>
  42. <title>$name</title>
  43. <style type="text/css">
  44. h3 {
  45. font-size: 18px;
  46. padding-bottom: 4pt;
  47. border-bottom: 2px solid #dddddd;
  48. }
  49. .api {
  50. border: 1px solid;
  51. padding: 10pt;
  52. margin: 10pt;
  53. }
  54. .api-entry {
  55. border-bottom: none;
  56. font-size: 18px;
  57. }
  58. .prototype {
  59. border: 1px solid;
  60. background-color: #f2f2f2;
  61. padding: 5pt;
  62. margin-top: 5pt;
  63. margin-bottom: 5pt;
  64. }
  65. .header {
  66. border: 1px solid;
  67. padding: 0 0 5pt 5pt;
  68. margin: 10pt;
  69. white-space: pre;
  70. font-family: monospace;
  71. }
  72. .code {
  73. border: 1px solid;
  74. padding: 0 0 5pt 5pt;
  75. margin: 10pt;
  76. white-space: pre;
  77. font-family: monospace;
  78. }
  79. </style>
  80. </head>
  81. <body>
  82. EOF
  83. @a = split (/\n/, $files_content[$f]);
  84. for ($ai = 0; $ai < $#a; $ai++){
  85. $line = $a[$ai];
  86. ($api,$caption) = $line =~ /<h4><a name=\"api:(\w+)\">(\w+)<\/a><\/h4>/;
  87. if ($api ne ""){
  88. if ($api_shown == 1){
  89. print OUT "</div>";
  90. }
  91. $api_shown = 1;
  92. $proto = $prototype{$api};
  93. if ($proto eq ""){
  94. $proto = "Prototype: $api";
  95. }
  96. print OUT<<EOF;
  97. <a name="api:$api"></a>
  98. <div class="api">
  99. <div class="api-entry">$api</div>
  100. <div class="prototype">$proto</div>
  101. <p>
  102. EOF
  103. &opt_print ("Parameters", $arguments{$api}, 1);
  104. &opt_print ("Returns", $returns{$api}, 1);
  105. &opt_print ("Remarks", $bodies{$api}, 0);
  106. print OUT "\n";
  107. } else {
  108. if ($line =~ /@API_IDX@/){
  109. $apis_toc = &create_toc ($apis[$f]);
  110. $line =~ s/\@API_IDX\@/$apis_toc/;
  111. }
  112. if ($line =~ /^<h/){
  113. print OUT "</div>";
  114. $api_shown = 0;
  115. }
  116. print OUT "$line\n";
  117. }
  118. }
  119. print OUT<<EOF;
  120. </body>
  121. </html>
  122. EOF
  123. close OUT;
  124. system ("$ENV{runtimedir}/mono-wrapper convert.exe $dir/html/$name $dir/html/x-$name");
  125. # clean up the mess that AgilityPack does, it CDATAs our CSS
  126. open HACK, "$dir/html/x-$name" || die "Could not open $dir/html/x-$name";
  127. open HACKOUT, ">$dir/deploy/$name" || die "Could not open output";
  128. while (<HACK>){
  129. s/^\/\/<!\[CDATA\[//;
  130. s/^\/\/\]\]>\/\///;
  131. print HACKOUT $_;
  132. }
  133. #system ("cp.exe $dir/html/$name $dir/deploy/$name");
  134. }
  135. }
  136. sub process_doc {
  137. $doc = "";
  138. $func = <>;
  139. chop $func;
  140. $func =~ s/^ \* //;
  141. $func =~ s/:$//;
  142. print "Function: $func\n" if (!$html);
  143. $args = "";
  144. $inbody = 0;
  145. $returns = "";
  146. $body = "";
  147. $functions[$fn++] = $func;
  148. # Process arguments
  149. while (<>){
  150. if (/^ \*\*?\//){
  151. $body =~ s/[@#](\w+)/<i>\1<\/i>/g;
  152. $returns =~ s/[@#](\w+)/<i>\1<\/i>/g;
  153. $args =~ s/@(\w+)/<i>\1<\/i>/g;
  154. $body =~ s/\n/ /;
  155. $bodies{$func} = $body;
  156. $arguments{$func} = $args;
  157. $returns{$func} = $returns;
  158. $proto = "";
  159. while (<>){
  160. $proto .= $_;
  161. last if (/\{/);
  162. }
  163. $proto =~ s/{//;
  164. # clean it up a little, remove newlines, empty space at end
  165. $proto =~ s/ +$//;
  166. # Turn "Type * xxx" into "Type* xxx"
  167. $proto =~ s/^(\w+)\W+\*/\1\*/;
  168. $prototype{$func} = $proto;
  169. return;
  170. }
  171. chop;
  172. s/^\ \*//;
  173. $_ = "\n<p>" if (/^\s+$/);
  174. if ($inbody == 0){
  175. if (/\s*(\w+):(.*)/){
  176. $args .= "<dt><i>$1:</i></dt><dd>$2</dd>";
  177. } else {
  178. $body = "\t$_\n";
  179. $inbody = 1;
  180. }
  181. } elsif ($inbody == 1) {
  182. if (/Returns?:/){
  183. s/Returns?://;
  184. $returns = "\t$_\n";
  185. $inbody = 2;
  186. } else {
  187. $body .= "\n\t$_";
  188. }
  189. } else {
  190. $returns .= "\n\t$_";
  191. }
  192. }
  193. }
  194. sub create_toc {
  195. my ($apis_listed) = @_;
  196. my $type_size = 0;
  197. my $name_size = 0;
  198. my $ret, $xname, $args, $line;
  199. $apis_toc = "";
  200. # Try to align things, so compute type size, method size, and arguments
  201. foreach $line (split /\n/, $apis_listed){
  202. $p = $prototype{$line};
  203. ($ret, $xname, $args) = $p =~ /(.*)\n(\w+)[ \t](.*)/;
  204. $tl = length ($ret);
  205. $pl = length ($xname);
  206. $type_size = $tl if ($tl > $type_size);
  207. $name_size = $pl if ($pl > $name_size);
  208. }
  209. $type_size++;
  210. $name_size++;
  211. foreach $line (split /\n/, $apis_listed){
  212. chop;
  213. $p = $prototype{$line};
  214. ($ret, $xname, $args) = $p =~ /(.*)\n(\w+)[ \t](.*)/;
  215. $rspace = " " x ($type_size - length ($ret));
  216. $nspace = " " x ($name_size - length ($xname));
  217. $args = &format ($args, length ($ret . $rspace . $xname . $nspace), 60);
  218. $apis_toc .= "$ret$rspace<a href=\"\#api:$line\">$xname</a>$nspace$args\n";
  219. }
  220. return $apis_toc;
  221. }
  222. #
  223. # Formats the rest of the arguments in a way that will fit in N columns
  224. #
  225. sub format {
  226. my ($args, $size, $limit) = @_;
  227. my $sret = "";
  228. # return $args if ((length (args) + size) < $limit);
  229. $remain = $limit - $size;
  230. @sa = split /,/, $args;
  231. $linelen = $size;
  232. foreach $arg (@sa){
  233. if ($sret eq ""){
  234. $sret = $arg . ", ";
  235. $linelen += length ($sret);
  236. } else {
  237. if ($linelen + length ($arg) < $limit){
  238. $sret .= "FITS" . $arg . ", ";
  239. } else {
  240. $newline = " " x ($size) . $arg . ", ";
  241. $linelen = length ($newline);
  242. $sret .= "\n" . $newline;
  243. }
  244. }
  245. }
  246. $sret =~ s/, $/;/;
  247. return $sret;
  248. }
  249. sub opt_print {
  250. my ($caption, $opttext, $quote) = @_;
  251. if ($opttext ne "" && (!($opttext =~ /^[ \t]+$/))){
  252. print OUT "<b>$caption</b>\n";
  253. if ($quote == 1){
  254. print OUT "<blockquote>$opttext</blockquote>\n";
  255. } else {
  256. print OUT "<p>$opttext\n";
  257. }
  258. }
  259. }