- last mhash algo was missed
[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 function e($s)
23 {
24 $a = func_get_args();
25 array_unshift($a, STDERR);
26 call_user_func_array('fprintf', $a);
27 }
28
29 $preface = <<<_PREFACE
30 <html>
31 <head>
32 <title>Function Summary of ext/%s</title>
33 <style>
34 body {
35 font-size: 80%%;
36 font-family: sans-serif;
37 }
38 h2, h3 {
39 color: #339;
40 clear: both;
41 font-size: 1.2em;
42 background: #ffc;
43 padding: .2em;
44 }
45 h2.o {
46 color: #66b;
47 clear: both;
48 font-size: 1.3em;
49 background: #f0f0f0;
50 padding: .2em;
51 }
52 p {
53 margin-left: 1em;
54 }
55 pre {
56 font-size: 1.2em;
57 }
58 br {
59 display: none;
60 }
61 blockquote {
62 margin-bottom: 3em;
63 border: 1px solid #ccc;
64 background: #f0f0f0;
65 padding: 0em 1em;
66 width: auto;
67 float: left;
68 }
69 p, pre {
70 clear: both;
71 }
72 p br, pre code br {
73 display: block;
74 }
75 </style>
76 </head>
77 <body>
78 _PREFACE;
79
80 $footer = <<<_FOOTER
81 <p><b>Generated at: %s</b></p>
82 </body>
83 </html>
84
85 _FOOTER;
86
87 if ($_SERVER['argc'] < 2) {
88 die("Usage: {$_SERVER['argv'][0]} <file>[ <file> ...]\n");
89 }
90
91 printf($preface, basename(getcwd()));
92
93 foreach (array_slice($_SERVER['argv'], 1) as $fp) {
94 foreach (glob($fp) as $f) {
95
96 if (mf($f, $m)) {
97 e("\nAnalyzing %s\n", basename($f));
98 printf("<h1>%s</h1>\n", basename($f));
99 foreach ($m[1] as $i => $p) {
100 e("Documenting $p\n");
101 if ($o = preg_match('/^(.*), (.*)$/', $m[4][$i], $n)) {
102 if ($n[2] == '__construct') {
103 printf("<h2 id=\"%s\" class=\"o\">%s</h2>\n", $n[1], $n[1]);
104 }
105 }
106 printf("<h%d id=\"%s\">%s</h%d>\n%s\n",
107 $o?3:2, $o?$n[1].'_'.$n[2]:$m[4][$i], $p, $o?3:2, ff($m[3][$i]));
108 }
109 print "<hr noshade>\n";
110 }
111 }
112 }
113
114 printf($footer, date('r'));
115 e("\nDone\n");
116 ?>
117