Commit | Line | Data |
---|---|---|
7faf1d71 AW |
1 | #!/usr/bin/perl |
2 | ||
3 | sub Usage { | |
4 | ||
5 | "Usage: makeindex xhtmldir xmldir | |
6 | where xhtmldir contains a directory full of OpenGL .xml XHTML man pages -AND- | |
7 | where xmldir contains a directory full of OpenGL .xml source XML man pages | |
8 | ||
9 | probably want to redirect output into a file like | |
10 | ./makeindex.pl . .. > ./index.html | |
11 | " | |
12 | } | |
13 | ||
14 | sub PrintHeader { | |
15 | print '<html> | |
16 | <head> | |
17 | <title>OpenGL Documentation</title> | |
18 | <style type="text/css"> | |
19 | ||
20 | html, body, table | |
21 | { color: #000; | |
22 | padding: 4px 4px; | |
23 | margin: 0px 0 0 0; | |
24 | text-align: center; | |
25 | font-family: Arial, Lucida, sans-serif; | |
26 | font-size: 10pt; | |
27 | ||
28 | } | |
29 | ||
30 | #container { | |
31 | margin: 10px; | |
32 | font-size: 14pt; | |
33 | text-decoration:none; | |
34 | } | |
35 | ||
36 | table.sample { | |
37 | border-width: 1px; | |
38 | border-spacing: 5px; | |
39 | border-style: dotted; | |
40 | border-color: black; | |
41 | border-collapse: separate; | |
42 | background-color: #F0F0F0; | |
43 | } | |
44 | table.sample th { | |
45 | border-width: 1px; | |
46 | padding: 5px; | |
47 | border-style: none; | |
48 | } | |
49 | table.sample td { | |
50 | border-width: 1px; | |
51 | padding: 1px; | |
52 | border-style: none; | |
53 | } | |
54 | </style> | |
55 | ||
56 | </head> | |
57 | <body> | |
58 | <a name="top"></a> | |
59 | <h1>OpenGL 2.1 Reference Pages</h1> | |
60 | <br/><br/> | |
61 | ||
62 | '; | |
63 | } | |
64 | ||
65 | sub PrintFooter { | |
66 | print ' | |
67 | </body> | |
68 | </html> | |
69 | '; | |
70 | } | |
71 | ||
72 | sub TableElementForFilename { | |
73 | my $name = shift; | |
74 | ||
75 | my $strippedname = $name; | |
76 | $strippedname =~ s/\.xml//; | |
77 | print "\t"; | |
78 | print '<tr><td><a target="pagedisp" href="' , $name , '">'; | |
79 | print "$strippedname"; | |
80 | print "</a></td></tr>\n"; | |
81 | } | |
82 | ||
83 | sub BeginTable { | |
84 | my $letter = shift; | |
85 | print "<a name=\"$letter\"></a><br/><br/>\n"; | |
86 | print '<table width="200" align="center" class="sample">'; | |
87 | print "\t<th>"; | |
88 | print "$letter</th>\n"; | |
89 | } | |
90 | ||
91 | sub EndTable { | |
92 | print "\t"; | |
93 | print '<tr><td><center><a href="#top">Top</a></center></td></tr>'; | |
94 | print "\n</table>\n\n"; | |
95 | } | |
96 | ||
97 | ||
98 | ||
99 | ############## | |
100 | # main | |
101 | ############## | |
102 | ||
103 | if (@ARGV != 2) | |
104 | { | |
105 | Usage(); | |
106 | die; | |
107 | } | |
108 | ||
109 | # grab list of generated XHTML files | |
110 | opendir(DIR,$ARGV[0]) or die "couldn't open directory"; | |
111 | ||
112 | @files = readdir(DIR); | |
113 | close(DIR); | |
114 | @files = sort @files; | |
115 | ||
116 | PrintHeader(); | |
117 | ||
118 | my @glX; | |
119 | my @glut; | |
120 | my @glu; | |
121 | my @gl; | |
122 | ||
123 | my @realEntrypoints; | |
124 | my @pageNames; | |
125 | ||
126 | #pre-create list of all true entrypoint names | |
127 | ||
128 | foreach (@files) | |
129 | { | |
130 | if (/xml/) | |
131 | { | |
132 | $parentName = $ARGV[1] . '/' . $_; | |
133 | if (open(PARENT, $parentName)) | |
134 | { | |
135 | @funcs = <PARENT>; | |
136 | @funcs = grep(/<funcdef>/, @funcs); | |
137 | foreach (@funcs) | |
138 | { | |
139 | $func = $_; | |
140 | $func =~ s/.*<function>//; | |
141 | $func =~ s/<\/function>.*\n//; | |
142 | ||
143 | push (@realEntrypoints, $func); | |
144 | } | |
145 | close(PARENT); | |
146 | } | |
147 | } | |
148 | } | |
149 | ||
150 | #pre-create list of page names | |
151 | ||
152 | foreach (@files) | |
153 | { | |
154 | if (/xml/) | |
155 | { | |
156 | $parentName = $ARGV[1] . '/' . $_; | |
157 | if (open(PARENT, $parentName)) | |
158 | { | |
159 | my $entrypoint = $_; | |
160 | $entrypoint =~ s/\.xml//; | |
161 | ||
162 | push (@pageNames, $entrypoint); | |
163 | ||
164 | close(PARENT); | |
165 | } | |
166 | } | |
167 | } | |
168 | ||
169 | #sort the files into gl, glut, glu, and glX | |
170 | ||
171 | foreach (@files) | |
172 | { | |
173 | if (/xml/) | |
174 | { | |
175 | # filter out entrypoint variations that don't have their own man pages | |
176 | my $needIndexEntry = 0; | |
177 | ||
178 | # continue only if parent page exists (e.g. glColor) OR | |
179 | # different parent page exists with matching entrypoint (e.g. glEnd) | |
180 | my $entrypoint = $_; | |
181 | $entrypoint =~ s/\.xml//; | |
182 | ||
183 | foreach (@pageNames) | |
184 | { | |
185 | if ($_ eq $entrypoint) | |
186 | { | |
187 | # it has its own man page | |
188 | $needIndexEntry = 1; | |
189 | } | |
190 | } | |
191 | ||
192 | if ($needIndexEntry == 0) | |
193 | { | |
194 | foreach (@realEntrypoints) | |
195 | { | |
196 | if ($_ eq $entrypoint) | |
197 | { | |
198 | # it's a real entrypoint, but make sure not a variation | |
199 | $needIndexEntry = 1; | |
200 | ||
201 | foreach (@pageNames) | |
202 | { | |
203 | my $alteredEntrypoint = $entrypoint; | |
204 | $alteredEntrypoint =~ s/$_//; | |
205 | ||
206 | if (!($alteredEntrypoint eq $entrypoint)) | |
207 | { | |
208 | $needIndexEntry = 0; | |
209 | } | |
210 | } | |
211 | } | |
212 | } | |
213 | } | |
214 | ||
215 | if ($needIndexEntry) | |
216 | { | |
217 | if (/^glX/) | |
218 | { | |
219 | push (@glX, $_); | |
220 | } | |
221 | elsif (/^glut/) | |
222 | { | |
223 | push (@glut, $_); | |
224 | } | |
225 | elsif (/^glu/) | |
226 | { | |
227 | push (@glu, $_); | |
228 | } | |
229 | elsif (/^gl/) | |
230 | { | |
231 | push (@gl, $_); | |
232 | } | |
233 | } | |
234 | } | |
235 | } | |
236 | ||
237 | ||
238 | #output the table of contents | |
239 | ||
240 | my @toc; | |
241 | ||
242 | if ($#gl > 0) | |
243 | { | |
244 | $currentletter = ""; | |
245 | $opentable = 0; | |
246 | ||
247 | foreach (@gl) | |
248 | { | |
249 | $name = $_; | |
250 | $name =~ s/^gl//; | |
251 | $firstletter = substr($name, 0, 1); | |
252 | if ($firstletter ne $currentletter) | |
253 | { | |
254 | push (@toc, $firstletter); | |
255 | $currentletter = $firstletter; | |
256 | } | |
257 | } | |
258 | if ($#glu > 0) { push (@toc, "glu"); } | |
259 | if ($#glut > 0) { push (@toc, "glut"); } | |
260 | if ($#glX > 0) { push (@toc, "glX"); } | |
261 | } | |
262 | ||
263 | ||
264 | print '<div id="container">'; | |
265 | foreach (@toc) | |
266 | { | |
267 | print '<b><a href="#'; | |
268 | print $_; | |
269 | print '" style="text-decoration:none"> '; | |
270 | print $_; | |
271 | print " </a></b> "; | |
272 | } | |
273 | print "</div>\n\n\n"; | |
274 | ||
275 | # output the tables | |
276 | ||
277 | if ($#gl > 0) | |
278 | { | |
279 | $currentletter = ""; | |
280 | $opentable = 0; | |
281 | ||
282 | foreach (@gl) | |
283 | { | |
284 | $name = $_; | |
285 | $name =~ s/^gl//; | |
286 | $firstletter = substr($name, 0, 1); | |
287 | if ($firstletter ne $currentletter) | |
288 | { | |
289 | if ($opentable == 1) | |
290 | { | |
291 | EndTable(); | |
292 | } | |
293 | BeginTable($firstletter); | |
294 | $opentable =1; | |
295 | $currentletter = $firstletter; | |
296 | } | |
297 | TableElementForFilename($_); | |
298 | } | |
299 | if ($opentable) | |
300 | { | |
301 | EndTable(); | |
302 | } | |
303 | } | |
304 | ||
305 | if ($#glu > 0) | |
306 | { | |
307 | BeginTable("glu"); | |
308 | foreach (@glu) | |
309 | { | |
310 | TableElementForFilename($_); | |
311 | } | |
312 | EndTable(); | |
313 | } | |
314 | ||
315 | if ($#glut > 0) | |
316 | { | |
317 | BeginTable("glut"); | |
318 | foreach (@glut) | |
319 | { | |
320 | TableElementForFilename($_); | |
321 | } | |
322 | EndTable(); | |
323 | } | |
324 | ||
325 | if ($#glX > 0) | |
326 | { | |
327 | BeginTable("glX"); | |
328 | foreach (@glX) | |
329 | { | |
330 | TableElementForFilename($_); | |
331 | } | |
332 | EndTable(); | |
333 | } | |
334 | ||
335 | PrintFooter(); |