- even better use a object struct member for that crap
[m6w6/ext-http] / funcsummary.php
1 <?php
2
3 function hl($m)
4 {
5 return sprintf("<blockquote>%s</blockquote>\n", highlight_string($m[1], true));
6 }
7 function mf($f, &$m)
8 {
9 return preg_match_all(
10 '/\/\* *\{\{\{ *proto (.*?)(\n|$)(.*?)PHP_(?:FUNCTION|METHOD)\((.*?)\)/s',
11 file_get_contents($f), $m);
12 }
13 function ff($t)
14 {
15 $t = preg_replace('/^ \* /m', '', trim($t, "*/ \n"));
16 $t = preg_replace_callback('/(\<\?php.*?\?\>)/s', 'hl', $t);
17 $t = nl2br(preg_replace('/\n *\* */', "\n", $t));
18 $t = preg_replace('/(\<br \/\>\n)+\<pre\>(\<br \/\>\n)+/', '</p><pre>', $t);
19 $t = preg_replace('/(\<br \/\>\n)+\<\/pre\>(\<br \/\>\n)+/', '</pre><p>', $t);
20 return sprintf('<p>%s</p>', ltrim($t, ' *'));
21 }
22
23 $preface = <<<_PREFACE
24 <html>
25 <head>
26 <title>Function Summary of ext/%s</title>
27 <style>
28 body {
29 font-size: 80%%;
30 font-family: sans-serif;
31 }
32 h2 {
33 color: #339;
34 clear: both;
35 font-size: 1.2em;
36 background: #ffc;
37 padding: .2em;
38 }
39 p {
40 margin-left: 1em;
41 }
42 pre {
43 font-size: 1.2em;
44 }
45 br {
46 display: none;
47 }
48 blockquote {
49 margin-bottom: 3em;
50 border: 1px solid #ccc;
51 background: #f0f0f0;
52 padding: 0em 1em;
53 width: auto;
54 float: left;
55 }
56 p, pre {
57 clear: both;
58 }
59 p br, pre code br {
60 display: block;
61 }
62 </style>
63 </head>
64 <body>
65 _PREFACE;
66
67 $footer = <<<_FOOTER
68 <p><b>Generated at: %s</b></p>
69 </body>
70 </html>
71
72 _FOOTER;
73
74 if ($_SERVER['argc'] < 2) {
75 die("Usage: {$_SERVER['argv'][0]} <file>[ <file> ...]\n");
76 }
77
78 printf($preface, basename(getcwd()));
79
80 foreach (array_slice($_SERVER['argv'], 1) as $f) {
81 if (mf($f, $m)) {
82 printf("<h1>%s</h1>\n", basename($f));
83 foreach ($m[1] as $i => $p) {
84 printf("<h2 id=\"%s\">%s</h2>\n%s\n",
85 str_replace(', ', '_', $m[4][$i]), $p, ff($m[3][$i]));
86 }
87 print "<hr noshade>\n";
88 }
89 }
90
91 printf($footer, date('r'));
92 ?>
93