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