a909123a53be3e190c828c76d8e4b2ca6cddc023
[clinton/guile-figl.git] / upstream-man-pages / man4 / xhtml / makeindex.pl
1 #!/usr/bin/perl
2
3 sub Usage {
4 print
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 <link rel="stylesheet" type="text/css" href="../../mancommon/opengl-man.css" />
18 <title>OpenGL Documentation</title>
19 </head>
20 <body>
21 <a name="top"></a>
22 <center><h1>OpenGL 4 Reference Pages</h1></center>
23 <br/><br/>
24
25 ';
26 }
27
28 sub PrintFooter {
29 print '
30 </body>
31 </html>
32 ';
33 }
34
35 sub TableElementForFilename {
36 my $name = shift;
37
38 my $strippedname = $name;
39 $strippedname =~ s/\.xml//;
40 print "\t";
41 print '<tr><td><a target="pagedisp" href="' , $name , '">';
42 print "$strippedname";
43 print "</a></td></tr>\n";
44 }
45
46 sub BeginTable {
47 my $letter = shift;
48 print "<a name=\"$letter\"></a><br/><br/>\n";
49 print '<table width="200" class="sample">';
50 print "\t<th>";
51 print "$letter</th>\n";
52 }
53
54 sub EndTable {
55 print "\t";
56 print '<tr><td align="right"><a href="#top">Top</a></td></tr>';
57 print "\n</table>\n\n";
58 }
59
60
61
62 ##############
63 # main
64 ##############
65
66 if (@ARGV != 2)
67 {
68 Usage();
69 die;
70 }
71
72 # grab list of generated XHTML files
73 opendir(DIR,$ARGV[0]) or die "couldn't open directory";
74
75 @files = readdir(DIR);
76 close(DIR);
77 @files = sort @files;
78
79 PrintHeader();
80
81 my @glX;
82 my @glut;
83 my @glu;
84 my @gl;
85
86 my @realEntrypoints;
87 my @pageNames;
88
89 #pre-create list of all true entrypoint names
90
91 foreach (@files)
92 {
93 if (/xml/)
94 {
95 $parentName = $ARGV[1] . '/' . $_;
96 if (open(PARENT, $parentName))
97 {
98 @funcs = <PARENT>;
99 @funcs = grep(/<funcdef>/, @funcs);
100 foreach (@funcs)
101 {
102 $func = $_;
103 $func =~ s/.*<function>//;
104 $func =~ s/<\/function>.*\n//;
105
106 push (@realEntrypoints, $func);
107 }
108 close(PARENT);
109 }
110 }
111 }
112
113 #pre-create list of page names
114
115 foreach (@files)
116 {
117 if (/xml/)
118 {
119 $parentName = $ARGV[1] . '/' . $_;
120 if (open(PARENT, $parentName))
121 {
122 my $entrypoint = $_;
123 $entrypoint =~ s/\.xml//;
124
125 push (@pageNames, $entrypoint);
126
127 close(PARENT);
128 }
129 }
130 }
131
132 #sort the files into gl, glut, glu, and glX
133
134 foreach (@files)
135 {
136 if (/xml/)
137 {
138 # filter out entrypoint variations that don't have their own man pages
139 my $needIndexEntry = 0;
140
141 # continue only if parent page exists (e.g. glColor) OR
142 # different parent page exists with matching entrypoint (e.g. glEnd)
143 my $entrypoint = $_;
144 $entrypoint =~ s/\.xml//;
145
146 foreach (@pageNames)
147 {
148 if ($_ eq $entrypoint)
149 {
150 # it has its own man page
151 $needIndexEntry = 1;
152 }
153 }
154
155 if ($needIndexEntry == 0)
156 {
157 foreach (@realEntrypoints)
158 {
159 if ($_ eq $entrypoint)
160 {
161 # it's a real entrypoint, but make sure not a variation
162 $needIndexEntry = 1;
163
164 foreach (@pageNames)
165 {
166 my $alteredEntrypoint = $entrypoint;
167 $alteredEntrypoint =~ s/$_//;
168
169 if (!($alteredEntrypoint eq $entrypoint))
170 {
171 $needIndexEntry = 0;
172 }
173 }
174 }
175 }
176 }
177
178 if ($needIndexEntry)
179 {
180 if (/^glX/)
181 {
182 push (@glX, $_);
183 }
184 elsif (/^glut/)
185 {
186 push (@glut, $_);
187 }
188 elsif (/^glu/)
189 {
190 push (@glu, $_);
191 }
192 elsif (/^gl/)
193 {
194 push (@gl, $_);
195 }
196 }
197 }
198 }
199
200
201 #output the table of contents
202
203 my @toc;
204
205 if ($#gl > 0)
206 {
207 $currentletter = "";
208 $opentable = 0;
209
210 foreach (@gl)
211 {
212 $name = $_;
213 $name =~ s/^gl//;
214 $firstletter = substr($name, 0, 1);
215 if ($firstletter ne $currentletter)
216 {
217 push (@toc, $firstletter);
218 $currentletter = $firstletter;
219 }
220 }
221 if ($#glu > 0) { push (@toc, "glu"); }
222 if ($#glut > 0) { push (@toc, "glut"); }
223 if ($#glX > 0) { push (@toc, "glX"); }
224 }
225
226
227 print '<center>';
228 print '<div id="container">';
229 foreach (@toc)
230 {
231 print '<b><a href="#';
232 print $_;
233 print '" style="text-decoration:none"> ';
234 print $_;
235 print " </a></b> &nbsp; ";
236 }
237 print "</div>\n\n\n";
238 print '</center>';
239
240 # output the tables
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 if ($opentable == 1)
255 {
256 EndTable();
257 }
258 BeginTable($firstletter);
259 $opentable =1;
260 $currentletter = $firstletter;
261 }
262 TableElementForFilename($_);
263 }
264 if ($opentable)
265 {
266 EndTable();
267 }
268 }
269
270 if ($#glu > 0)
271 {
272 BeginTable("glu");
273 foreach (@glu)
274 {
275 TableElementForFilename($_);
276 }
277 EndTable();
278 }
279
280 if ($#glut > 0)
281 {
282 BeginTable("glut");
283 foreach (@glut)
284 {
285 TableElementForFilename($_);
286 }
287 EndTable();
288 }
289
290 if ($#glX > 0)
291 {
292 BeginTable("glX");
293 foreach (@glX)
294 {
295 TableElementForFilename($_);
296 }
297 EndTable();
298 }
299
300 PrintFooter();