* much smarter & enhanced absolute_uri() using parse_url()
[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 br, pre code br {
57 display: block;
58 }
59 </style>
60 </head>
61 <body>
62 _PREFACE;
63
64 $footer = <<<_FOOTER
65 <p><b>Generated at: %s</b></p>
66 </body>
67 </html>
68 _FOOTER;
69
70 if ($_SERVER['argc'] < 2) {
71 die("Usage: {$_SERVER['argv'][0]} <file>[ <file> ...]\n");
72 }
73
74 printf($preface, basename(getcwd()));
75
76 foreach (array_slice($_SERVER['argv'], 1) as $f) {
77 if (mf($f, $m)) {
78 printf("<h1>%s</h1>\n", basename($f));
79 foreach ($m[1] as $i => $p) {
80 printf("<h2 id=\"%s\">%s</h2>\n%s\n",
81 str_replace(', ', '_', $m[4][$i]), $p, ff($m[3][$i]));
82 }
83 print "<hr noshade>\n";
84 }
85 }
86
87 printf($footer, date('r'));
88 ?>