Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simgrid website documentation should be OK now. It's now separated totally from the...
[simgrid.git] / tools / doxygen / doxygen_postprocesser_website.pl
1 #! /usr/bin/perl
2
3 use strict;
4
5 # Add here the pages of the documentation generated by a @page doxygen macro
6 my @extra_files = qw(html/faq.html html/history.html html/contrib.html html/people.html
7                      html/publis.html html/publis_core.html html/publis_extern.html html/publis_intra.html);
8
9
10 my %debug;
11 $debug{'parse'} = 0; # show how we parse the module tree
12 $debug{'input'} = 0; # display the resulting tree
13 $debug{'handle'}= 0; # Be verbose on the post-processing
14 $debug{'rename'}= 0; # do not overwrite the files (allows several debuging runs without rerunning doxygen)
15
16 my @allfiles;
17 ###
18 ### Get the module definitions
19 ###
20
21 open IN, "html/modules.html" || die "Cannot parse html/modules.html. Did you really run doxygen?\n";
22
23 # pass headers
24 while (<IN>) {
25   last if /group__SimGrid__API.html/;
26 }
27
28 # Parse the tree
29 my $top;
30 my $current;
31 my $entry;
32
33 # $current->{'label'}="ROOT";
34 # push @{$top->{'down'}},$current;
35 # print "Push $current '".($current->{'label'})."' as child of $top '".($top->{'label'})."'\n" if $debug{'parse'};
36 # $current=$top;
37 $top->{'label'}="ROOT";
38 print "Create ROOT $top\n" if $debug{'parse'};
39 $current=$top;
40
41
42 # Read the whole data to postprocess it a bit
43 my $in;
44 while (<IN>) {
45     $in .= $_;
46 }
47 $in =~ s/<ul>/\n<ul>\n/sg;
48 foreach $_ (split(/\n/,$in)) {
49     next unless length($_);
50     next if ($_ =~ m|^</li>$|);
51     print "  Seen '$_'\n" if $debug{'parse'};
52   if (/<ul>/) {
53     print "DOWN: $current '$current->{'label'}' -> " if $debug{'parse'};
54     $current = $current->{'down'}[scalar @{$current->{'down'}} - 1];
55     print "$current '$current->{'label'}'\n" if $debug{'parse'};
56     next;
57   }
58   if (/<\/ul>/) {
59     $current = $current->{'up'};
60     print "UP to $current '$current->{'label'}'\n" if $debug{'parse'};
61     next;
62   }
63   if (/<p>/) {
64     last;
65   }
66   
67   m|href="([^"]*)">([^<]*)</a>|; #"
68   
69   $entry = {};
70   $entry->{'file'} = $1;  
71   $entry->{'label'} = $2;
72   $entry->{'up'} = $current;
73   push @{$current->{'down'}},$entry;
74   print "Push file:$1 label:'$2' as child of $current '$current->{'label'}'\n" if $debug{'parse'};
75   push @allfiles,"html/$1";
76 }
77 close IN;
78
79 # Check each file for extra information (short name, extra childs)
80 sub extra_info {
81   my $current=shift;
82
83   if (defined($current->{'file'})) {
84     open IN, "html/$current->{'file'}";
85     while (<IN>) {
86       if (/DOXYGEN_NAVBAR_LABEL/) {
87         if (/DOXYGEN_NAVBAR_LABEL="([^"]*)"/) {#"
88           print "Extra info from $current->{'file'}: label=$1, not $current->{'label'}\n" if $debug{'parse'};
89           $current->{'label'}=$1;
90         } else {
91           die "Malformated DOXYGEN_NAVBAR_LABEL line in $current->{'file'}";
92         }
93       }
94       if (/DOXYGEN_NAVBAR_CHILD/) {
95         if (/DOXYGEN_NAVBAR_CHILD *"([^"]*)"=([^ ]*)/) {#"
96           $entry = {};
97           $entry->{'label'} = $1;
98           $entry->{'file'} = $2;
99           chomp($entry->{'file'});
100           $entry->{'up'} = $current;
101           push @{$current->{'down'}},$entry;
102           print "Extra info from $current->{'file'}: New child $entry->{'label'}=$entry->{'file'}\n"  if $debug{'parse'};
103         } else {
104           die "Malformated DOXYGEN_NAVBAR_CHILD line in $current->{'file'}";
105         }
106       }
107     }
108   }
109   
110   foreach my $entry (@{$current->{'down'}}) {
111     extra_info($entry);
112   }  
113 }
114 extra_info($top);
115
116 ## debug function
117 sub display {
118   my $current=shift;
119   my $level=shift;
120   print "  " x $level;
121   print "$current: ".$current->{'label'}." ($current->{'file'})\n";
122   foreach my $entry (@{$current->{'down'}}) {
123     display($entry,$level+1);
124   }
125 }
126
127 display($top,0) if $debug{'input'};
128
129 ###
130 ### Generate the navbar
131 ###
132
133 # the root deserves some special handling
134 open IN,"html/modules.html" || die;
135 open OUT,">html/modules.new.html" || die;
136 my $line;
137 while ($line = <IN>) {
138   last if $line =~ /<h1>SimGrid Modules</;
139   print OUT $line;
140 }
141
142 print OUT "<div class=\"tabs\">\n  <ul class=\"tablist\">\n";
143 foreach $current (@{ ${$top->{'down'}}[0]->{'down'} }) {
144   print OUT "   <li><a href=\"$current->{'file'}\"><span>$current->{'label'}</span></a></li>\n";
145 }
146 print OUT "  </ul></div>\n";
147 print OUT $line;
148 while (<IN>) {
149   print OUT $_;
150 }
151
152 close OUT;
153 close IN;
154 rename("html/modules.new.html","html/modules.html") unless $debug{'rename'};
155
156 # the publication pages deserves some special handling too
157 my %pub_tabs = ("publis.html"       =>"Reference publications",
158                 "publis_core.html"  =>"Other publication about SimGrid",
159                 "publis_extern.html"=>"External papers using SimGrid",
160                 "publis_intra.html"=>"Internal papers using SimGrid");
161 # force ordering
162 my @pub_titles = ("publis.html", "publis_core.html", "publis_extern.html", "publis_intra.html");
163 sub handle_pub{
164     my $oldname = shift;
165     my $newname = $oldname;
166     $newname =~ s/\.html$/.new.html/;
167  
168 #    print "Handle_pub($oldname -> $newname)\n";
169     
170     open IN,"html/$oldname" || die "Cannot open $oldname";
171     open OUT,">html/$newname" || die "Cannot open $newname";
172     my $line;
173 #┬áBIG FAT WARNING : THIS HACK IS DEPENDANT OF THE DOXYGEN VERSION AND OUR TEXT (because of the string we are looking for, that is changing with doxygen version, either h1 or div class="title" ... So we're forced to use titles defined in doc files...
174     while ($line = <IN>) {
175         last if (($line =~ /Reference publications about SimGrid/) or ($line =~  /Publications about the SimGrid framework/) or ($line =~  /Papers that use SimGrid-generated results/) or ($line =~  /Our own papers that use SimGrid-generated results/));
176         print OUT $line;
177     }
178
179     print OUT "<div class=\"tabs\" align=\"center\">\n<ul class=\"tablist\">\n";
180     foreach my $page (@pub_titles) {
181         print OUT "         <li".($page eq $oldname? " class=\"current\"":"" )."> <a href=\"$page\"><span>".($pub_tabs{$page})."</span></a></li>\n";
182     }
183
184     print OUT "  </ul></div>\n";
185     print OUT $line;
186     while ($line = <IN>) {
187         print OUT $line;
188     }
189     close OUT;
190     close IN;
191     rename("html/$newname","html/$oldname") unless $debug{'rename'};
192 }
193 map {handle_pub($_)} @pub_titles;
194
195
196 # Operate the recursion
197 sub handle_page {
198   my $current=shift;
199   my $level=shift;
200
201   print "Handle $current->{'file'} at level $level\n" if $debug{'handle'};
202     
203   # we generate the tabs bottom up begining from where we are in the tree
204   # and display them top down, as it should in a file
205   my @tabs = ();
206   my $found_div_tabs=0;
207   
208   if (defined ($current->{'label'}) and $current->{'label'} ne 'ROOT') {
209 #    print "handle $current->{'file'}, at level $level\n";
210     # generate the tabs
211     my $iterator = $current;
212     my $lvl_it=$level;
213     while ($lvl_it >= 0) {
214       my $father = $iterator->{'up'};
215       $tabs[$lvl_it] = "<div class=\"tabs2\">\n<ul class=\"tablist\">\n";
216       foreach my $bro (@{$father->{'down'}}) {
217         $tabs[$lvl_it] .= "  <li".($bro==$iterator?" class=\"current\"":"")."> <a href=\"$bro->{'file'}\"><span>$bro->{'label'}</span></a></li>\n";      
218       }
219       $tabs[$lvl_it] .= "  </ul></div>\n";
220       $iterator = $father;
221       $lvl_it--;
222     }
223     if (defined $current->{'down'}) { # there's some kid. Display them too
224       $tabs[$level+1] = "<div class=\"tabs2\">\n  <ul class=\"tablist\">\n";
225       foreach my $kid (@{$current->{'down'}}) {
226         $tabs[$level+1] .= "  <li> <a href=\"$kid->{'file'}\"><span>$kid->{'label'}</span></a></li>\n";      
227       }
228       $tabs[$level+1] .= "  </ul></div>\n";      
229     }
230     
231     # put them in place
232     open FROM,"html/$current->{'file'}" || die;
233     my $newname="html/$current->{'file'}";
234     $newname =~ s/.html/.handlepage.html/;
235     open TO,">$newname" || die;
236 #    print "XXX Deal with html/$current->{'file'}  ->  $newname\n";
237     while (<FROM>) {
238 #      print "--Read  $_";
239       # add "current" to the module API granfather page
240       s|<li><a href="modules.html"><span>[^<]*</span></a></li>|<li class="current"><a href="modules.html"><span>Modules&nbsp;API</span></a></li>|;
241 #      print "++Write $_";
242           $found_div_tabs=1 if m/div.*class="tabs"/;    
243       print TO "$_";
244       last if ((m|</div>|)&&($found_div_tabs));
245     }
246       
247     print TO "\n<!-- POST-PROCESSED TABS -->\n";
248     foreach (@tabs) {
249 #      print "TAB: $_";
250       print TO "$_";
251     }
252     print TO "\n<!-- END OF POST-PROCESSED TABS -->\n";
253       
254     if ($current->{'file'} =~ m/^class/) {
255           while (<FROM>) {
256                 last if (m|</div>|);
257           }
258       print TO "$_";    
259     }
260     while (<FROM>) {
261       if (m/POST-PROCESSED TABS/) {
262             while (<FROM>) {
263               last if (m/END OF POST-PROCESSED TABS/);
264             }
265             next;
266       }
267
268       if (m/The documentation for/) {
269             while (<FROM>) {
270               last if (m/<p>/);
271             }
272       }
273       print TO "$_";
274     }
275     close FROM;
276     close TO;
277     rename("$newname","html/$current->{'file'}") unless $debug{'rename'};
278   } 
279   
280   # recurse on childs
281   foreach my $entry (@{$current->{'down'}}) {
282     handle_page($entry,$level+1);
283   }
284 }
285
286 ###
287 ### Launch the modules navbar reworking
288 ###
289 handle_page($top,-1);# skip roots (we have 2 roots) in level counting
290
291 ###
292 ### Add the modules navbar reworking to the modules.html file
293 ###
294 sub add_tabs_to_module_html {
295   my $found_div_tabs=0;
296   my $module_tabs = "<div class=\"tabs2\">\n<ul class=\"tablist\">\n";
297   foreach my $entry (@{$top->{'down'}}) {
298       $module_tabs .= "  <li> <a href=\"$entry->{'file'}\"><span>$entry->{'label'}</span></a></li>\n";
299   }
300   $module_tabs .= "  </ul></div>\n";      
301   
302   my $oldname = "html/modules.html";
303   open FROM,$oldname || die;
304   my $newname=$oldname;
305   $newname =~ s/.html/.handlepage.html/;
306   open TO,">$newname" || die;
307   while (<FROM>) {
308     $found_div_tabs=1 if m/div.*class="tabs"/;  
309         print TO "$_";
310         last if ((m|</div>|)&&($found_div_tabs));
311   }
312   
313   print TO "\n<!-- POST-PROCESSED TABS -->\n";
314   print TO $module_tabs;
315   print TO "\n<!-- END OF POST-PROCESSED TABS -->\n";
316
317   while (<FROM>) {
318         print TO "$_";
319   }  
320   close FROM;
321   close TO;
322   rename($newname, $oldname) unless $debug{'rename'};
323   
324   # die;
325 }   
326
327 add_tabs_to_module_html;
328
329 ###
330 ### Post-processsing common to all pages
331 ###
332 map {push @allfiles,$_} @extra_files;
333 print "All files: ".(join(", ",@allfiles))."\n" if $debug{'parse'};
334
335 my $tabs;
336
337 foreach my $file (@allfiles) {
338     $file =~ s/.html/.handlepage.html/ if $debug{'rename'}; # Take right name if debugging
339         
340     open FROM,"$file" || die;
341     my $outfile = "$file";
342     $outfile =~ s/.(html|php)$/.new.$1/;
343     open TO,">$outfile" || die;
344 #    print "POSTPROCESSING $file (tmp=$outfile)\n";
345     while (<FROM>) {
346         
347
348
349           if($tabs){
350                   if($file =~ /^html\/index\..*/){
351                         $_ =~ s/<li class="current">/<li>/g;
352                         $_ =~ s/<li><a href="index.html">/<li class="current"><a href="index.html">/g;
353                   }               
354                   $_ =~ s/<li class="current"><a href="pages.html">/<li><a href="pages.html">/g;
355                   
356                   if($file =~ /^html\/pages\..*/){
357                         $_ =~ s/<li><a href="pages.html">/<li class="current"><a href="pages.html">/g;
358                   }
359           }
360           
361           if($file =~ /^html\/publis.*/){
362                         $_ =~ s/<div class="header">/<div>/g;
363                         $_ =~ s/<div class="headertitle">/<div>/g;
364          }
365         
366           # Add the FAQ PUBLIS PEOPLE HISTORY and CONTRIB to the top navbar.
367       if( $_ =~ /<div.*class="tabs">/){
368         $tabs = 1;
369       }
370       if( $_ =~ /<\/div>/){
371         $tabs = 0;
372       }
373       if( $_ =~ /<\/ul>/ && $tabs){
374                 my $tmp_buff="";
375                 
376                         #┬áLBO : ugly way to separate doc in 2 separate stuff ...
377                         $tmp_buff .= '      <li><a href="https://gforge.inria.fr/frs/?group_id=12"><span>Download</span></a></li>'."\n";
378                         $tmp_buff .= '      <li><a href="documentation.php"><span>Online documentation</span></a></li>'."\n";
379                         $tmp_buff .= '      <li><a href="publis.html"><span>Publications</span></a></li>'."\n";
380                         $tmp_buff .= '      <li><a href="people.html"><span>People</span></a></li>'."\n";
381                         $tmp_buff .= '      <li><a href="history.html"><span>History</span></a></li>'."\n";
382                         $tmp_buff .= '      <li><a href="contrib.html"><span>Contrib</span></a></li>'."\n";
383                         $tmp_buff .= '      <li><a href="faq.html"><span>FAQ&#160;Page</span></a></li>'."\n";
384                 
385                 
386                 $tmp_buff .= '      <li><a href="http://gforge.inria.fr/projects/simgrid"><span>SimGrid&#160;Forge</span></a></li>'."\n";
387                                 
388                 
389                 $tmp_buff .= $_;
390                 $tabs = 0;
391
392               # Rework the navbar and add menu for use.html
393               # Fix the current "button" of buggy Doxygen tabs  
394               if($file =~ /^html\/use.*/
395               || $file =~ /^html\/installSimgrid.*/
396               || $file =~ /^html\/options.*/ 
397               || $file =~ /^html\/bindings.*/
398               || $file =~ /^html\/gtnets.*/
399               || $file =~ /^html\/ns3.*/
400               || $file =~ /^html\/modules.*/
401               || $file =~ /^html\/annotated.*/)
402               {
403                                 $tmp_buff .= '      <div class="tabs_group_use">'."\n";
404                                 $tmp_buff .= '          <ul class="tablist">'."\n";
405                                 $tmp_buff .= '          <li><a href="installSimgrid.html"><span>Install SimGrid</span></a></li>'."\n";
406                                 $tmp_buff .= '          <li><a href="modules.html"><span>Modules&#160;API</span></a></li>'."\n";
407                         $tmp_buff .= '          <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>'."\n";
408                                 $tmp_buff .= '          <li><a href="options.html"><span>Options & configurations</span></a></li>'."\n";
409                                 $tmp_buff .= '          <li><a href="bindings.html"><span>Bindings</span></a></li>'."\n";
410                                 $tmp_buff .= '          <li><a href="gtnets.html"><span>GTNets</span></a></li>'."\n";
411                                 $tmp_buff .= '          <li><a href="ns3.html"><span>NS3</span></a></li>'."\n";
412                                 $tmp_buff .= '          </ul></div>'."\n";
413                                 $tmp_buff .= '      </div>'."\n";
414                                 
415                                 my $filename = $file;
416                         $filename =~ s/html\///g;
417                         $filename =~ s/\.html//g;
418                         $filename =~ s/publis_.*/publis/g;
419                         $tmp_buff =~ s/<li class="current">/<li>/g;
420                         $tmp_buff =~ s/<li><a href="$filename.html">/<li class="current"><a href="$filename.html">/g;
421                         $tmp_buff =~ s/<li><a href="use.html">/<li class="current"><a href="use.html">/g; 
422                                 
423               }
424         
425               # Rework the navbar
426               # Fix the current "button" of buggy Doxygen tabs   
427               if($file =~ /^html\/publis.*/ 
428               || $file =~ /^html\/faq.*/
429               || $file =~ /^html\/people.*/ 
430               || $file =~ /^html\/history.*/ 
431               || $file =~ /^html\/contrib.*/
432               || $file =~ /^html\/pages.*/)
433               {
434                       my $filename = $file;
435                       $filename =~ s/html\///g;
436                       $filename =~ s/\.html//g;
437                       $filename =~ s/publis_.*/publis/g;
438                       $tmp_buff =~ s/<li class="current">/<li>/g;
439                       $tmp_buff =~ s/<li><a href="$filename.html">/<li class="current"><a href="$filename.html">/g;     
440               }
441               
442
443               print TO $tmp_buff;             
444               next;
445     }
446         
447       s|<li><a href="index.html"><span>Main&#160;Page</span>|<li><a href="index.php"><span>Home</span>|g;                       
448      s|<span>Main&#160;Page</span>|<span>Home</span>|g; 
449       s|<span>Modules</span>|<span>Modules&#160;API</span>|g;
450       s|<li.*><a href="pages.html"><span>Related&#160;Pages</span></a></li>\n||g;
451       s|<li><a href="modules.html"><span>Modules&#160;API</span></a></li>\n||g;
452       s|<li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>\n||g;
453       s|<li class="current"><a href="modules.html"><span>Modules&#160;API</span></a></li>\n||g;
454       s|<li class="current"><a href="annotated.html"><span>Data&#160;Structures</span></a></li>\n||g;
455       s|Related Pages<|Documentation&nbsp;Index<|g;
456       s|<div id="navrow|<div align="center" id="navrow|g;
457       print TO $_;
458     }
459     close FROM;
460     close TO;
461     rename("$outfile", "$file") unless $debug{'rename'};
462 }
463
464
465