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