- ws
[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 = str_replace("<br />\n<br />\n", "</p>\n<p>", 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 $t = str_replace("</span><br />\n</code>", "</span></code>", $t);
21 return sprintf('<p>%s</p>', ltrim($t, ' *'));
22 }
23 function e($s)
24 {
25 $a = func_get_args();
26 array_unshift($a, STDERR);
27 call_user_func_array('fprintf', $a);
28 }
29
30 $preface = <<<_PREFACE
31 <html>
32 <head>
33 <title>Function Summary of ext/%s</title>
34 <style>
35 body {
36 font-size: 80%%;
37 font-family: sans-serif;
38 }
39 h2, h3 {
40 color: #339;
41 clear: both;
42 font-size: 1.2em;
43 background: #ffc;
44 padding: .2em;
45 }
46 h2.o {
47 color: #66b;
48 clear: both;
49 font-size: 1.3em;
50 background: #f0f0f0;
51 padding: .2em;
52 }
53 p {
54 margin-left: 1em;
55 }
56 pre {
57 font-size: 1.2em;
58 }
59 br {
60 display: none;
61 }
62 blockquote {
63 margin-bottom: 3em;
64 border: 1px solid #ccc;
65 background: #f0f0f0;
66 padding: 0em 1em;
67 width: auto;
68 float: left;
69 }
70 p, pre {
71 clear: both;
72 }
73 p br, pre code br {
74 display: block;
75 }
76 .toc {
77 position: absolute;
78 top: 10px;
79 right: 10px;
80 width: 300px;
81 height: 95%%;
82 overflow: scroll;
83 font-size: .9em;
84 }
85 body>div.toc {
86 position: fixed;
87 }
88 .toc ul {
89 padding-left: 15px;
90 margin-left: 0;
91 }
92 .toc li {
93 padding: 0;
94 margin: 0;
95 }
96 .tocfile {
97 font-weight: bold;
98 }
99 </style>
100 </head>
101 <body>
102 _PREFACE;
103
104 $footer = <<<_FOOTER
105 <p><b>Generated at: %s</b></p>
106 </body>
107 </html>
108
109 _FOOTER;
110
111 if ($_SERVER['argc'] < 2) {
112 die("Usage: {$_SERVER['argv'][0]} <file>[ <file> ...]\n");
113 }
114
115 $TOC = array();
116
117 printf($preface, basename(getcwd()));
118
119 $seen = array();
120 foreach (array_slice($_SERVER['argv'], 1) as $fp) {
121 foreach (glob($fp) as $f) {
122 if (isset($seen[$f])) {
123 continue;
124 } else {
125 $seen[$f] = true;
126 }
127 if (mf($f, $m)) {
128 $c = null;
129 e("\nAnalyzing %s\n", basename($f));
130 printf("<h1 id=\"%s\">%s</h1>\n", basename($f), basename($f));
131 foreach ($m[1] as $i => $p) {
132 e("Documenting $p\n");
133 if ($o = preg_match('/^(.*), (.*)$/', $m[4][$i], $n)) {
134 if ($n[1] != $c) {
135 $c = $n[1];
136 printf("<h2 id=\"%s\" class=\"o\">%s</h2>\n", $n[1], $n[1]);
137 }
138 $TOC[basename($f)][$n[1]][$n[2]] = $n[1].'::'.$n[2].'()';
139 printf("<h%d id=\"%s\">%s</h%d>\n", 3, $n[1].'_'.$n[2], $p, 3);
140 } else {
141 $TOC[basename($f)][$m[4][$i]] = $m[4][$i].'()';
142 printf("<h%d id=\"%s\">%s</h%d>\n", 2, $m[4][$i], $p, 2);
143 }
144 print ff($m[3][$i]) ."\n";
145 }
146 print "<hr noshade>\n";
147 }
148 }
149 }
150 printf("<div class=\"toc\"><strong>Table of Contents</strong>\n<ul>\n");
151 foreach ($TOC as $file => $f) {
152 printf("<li><a class=\"tocfile\" href=\"#%s\">%s</a>\n<ul>\n", $file, $file);
153 foreach ($f as $cof => $met) {
154 if (is_array($met)) {
155 foreach ($met as $id => $m) {
156 printf("<li><a href=\"#%s_%s\">%s</a></li>\n", $cof, $id, $m);
157 }
158 } else {
159 printf("<li><a href=\"#%s\">%s</a>\n", $cof, $cof);
160 }
161 printf("</li>\n");
162 }
163 printf("</ul>\n</li>\n");
164 }
165 printf("</ul>\n</div>\n");
166
167 printf($footer, date('r'));
168 e("\nDone\n");
169 ?>
170