Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Available command sync-gforge-website.
[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         $line =~ s/<h1>/<h1 align="center">/g;
176         last if (($line =~ /Reference publications about SimGrid/) 
177                 or ($line =~  /Publications about the SimGrid framework/) 
178                 or ($line =~  /Papers that use SimGrid-generated results/) 
179                 or ($line =~  /Our own papers that use SimGrid-generated results/));
180         print OUT $line;
181     }
182
183     print OUT "<div class=\"tabs\" align=\"center\">\n<ul class=\"tablist\">\n";
184     foreach my $page (@pub_titles) {
185         print OUT "         <li".($page eq $oldname? " class=\"current\"":"" )."> <a href=\"$page\"><span>".($pub_tabs{$page})."</span></a></li>\n";
186     }
187
188     print OUT "  </ul></div>\n";
189     print OUT $line;
190     while ($line = <IN>) {
191         print OUT $line;
192     }
193     close OUT;
194     close IN;
195     rename("html/$newname","html/$oldname") unless $debug{'rename'};
196 }
197 map {handle_pub($_)} @pub_titles;
198
199
200 # Operate the recursion
201 sub handle_page {
202   my $current=shift;
203   my $level=shift;
204
205   print "Handle $current->{'file'} at level $level\n" if $debug{'handle'};
206     
207   # we generate the tabs bottom up begining from where we are in the tree
208   # and display them top down, as it should in a file
209   my @tabs = ();
210   my $found_div_tabs=0;
211   
212   if (defined ($current->{'label'}) and $current->{'label'} ne 'ROOT') {
213 #    print "handle $current->{'file'}, at level $level\n";
214     # generate the tabs
215     my $iterator = $current;
216     my $lvl_it=$level;
217     while ($lvl_it >= 0) {
218       my $father = $iterator->{'up'};
219       $tabs[$lvl_it] = "<div class=\"tabs2\">\n<ul class=\"tablist\">\n";
220       foreach my $bro (@{$father->{'down'}}) {
221         $tabs[$lvl_it] .= "  <li".($bro==$iterator?" class=\"current\"":"")."> <a href=\"$bro->{'file'}\"><span>$bro->{'label'}</span></a></li>\n";      
222       }
223       $tabs[$lvl_it] .= "  </ul></div>\n";
224       $iterator = $father;
225       $lvl_it--;
226     }
227     if (defined $current->{'down'}) { # there's some kid. Display them too
228       $tabs[$level+1] = "<div class=\"tabs2\">\n  <ul class=\"tablist\">\n";
229       foreach my $kid (@{$current->{'down'}}) {
230         $tabs[$level+1] .= "  <li> <a href=\"$kid->{'file'}\"><span>$kid->{'label'}</span></a></li>\n";      
231       }
232       $tabs[$level+1] .= "  </ul></div>\n";      
233     }
234     
235     # put them in place
236     open FROM,"html/$current->{'file'}" || die;
237     my $newname="html/$current->{'file'}";
238     $newname =~ s/.html/.handlepage.html/;
239     open TO,">$newname" || die;
240 #    print "XXX Deal with html/$current->{'file'}  ->  $newname\n";
241     while (<FROM>) {
242 #      print "--Read  $_";
243       # add "current" to the module API granfather page
244       s|<li><a href="modules.html"><span>[^<]*</span></a></li>|<li class="current"><a href="modules.html"><span>Modules&nbsp;API</span></a></li>|;
245 #      print "++Write $_";
246           $found_div_tabs=1 if m/div.*class="tabs"/;    
247       print TO "$_";
248       last if ((m|</div>|)&&($found_div_tabs));
249     }
250       
251     print TO "\n<!-- POST-PROCESSED TABS -->\n";
252     foreach (@tabs) {
253 #      print "TAB: $_";
254       print TO "$_";
255     }
256     print TO "\n<!-- END OF POST-PROCESSED TABS -->\n";
257       
258     if ($current->{'file'} =~ m/^class/) {
259           while (<FROM>) {
260                 last if (m|</div>|);
261           }
262       print TO "$_";    
263     }
264     while (<FROM>) {
265       if (m/POST-PROCESSED TABS/) {
266             while (<FROM>) {
267               last if (m/END OF POST-PROCESSED TABS/);
268             }
269             next;
270       }
271
272       if (m/The documentation for/) {
273             while (<FROM>) {
274               last if (m/<p>/);
275             }
276       }
277       print TO "$_";
278     }
279     close FROM;
280     close TO;
281     rename("$newname","html/$current->{'file'}") unless $debug{'rename'};
282   } 
283   
284   # recurse on childs
285   foreach my $entry (@{$current->{'down'}}) {
286     handle_page($entry,$level+1);
287   }
288 }
289
290 ###
291 ### Launch the modules navbar reworking
292 ###
293 handle_page($top,-1);# skip roots (we have 2 roots) in level counting
294
295 ###
296 ### Add the modules navbar reworking to the modules.html file
297 ###
298 sub add_tabs_to_module_html {
299   my $found_div_tabs=0;
300   my $module_tabs = "<div class=\"tabs2\">\n<ul class=\"tablist\">\n";
301   foreach my $entry (@{$top->{'down'}}) {
302       $module_tabs .= "  <li> <a href=\"$entry->{'file'}\"><span>$entry->{'label'}</span></a></li>\n";
303   }
304   $module_tabs .= "  </ul></div>\n";      
305   
306   my $oldname = "html/modules.html";
307   open FROM,$oldname || die;
308   my $newname=$oldname;
309   $newname =~ s/.html/.handlepage.html/;
310   open TO,">$newname" || die;
311   while (<FROM>) {
312     $found_div_tabs=1 if m/div.*class="tabs"/;  
313         print TO "$_";
314         last if ((m|</div>|)&&($found_div_tabs));
315   }
316   
317   print TO "\n<!-- POST-PROCESSED TABS -->\n";
318   print TO $module_tabs;
319   print TO "\n<!-- END OF POST-PROCESSED TABS -->\n";
320
321   while (<FROM>) {
322         print TO "$_";
323   }  
324   close FROM;
325   close TO;
326   rename($newname, $oldname) unless $debug{'rename'};
327   
328   # die;
329 }   
330
331 add_tabs_to_module_html;
332
333 ###
334 ### Post-processsing common to all pages
335 ###
336 map {push @allfiles,$_} @extra_files;
337 print "All files: ".(join(", ",@allfiles))."\n" if $debug{'parse'};
338
339 my $tabs;
340
341 foreach my $file (@allfiles) {
342     $file =~ s/.html/.handlepage.html/ if $debug{'rename'}; # Take right name if debugging
343         
344     open FROM,"$file" || die;
345     my $outfile = "$file";
346     $outfile =~ s/.(html|php)$/.new.$1/;
347     open TO,">$outfile" || die;
348 #    print "POSTPROCESSING $file (tmp=$outfile)\n";
349     while (<FROM>) {
350         
351
352
353           if($tabs){
354                   if($file =~ /^html\/index\..*/){
355                         $_ =~ s/<li class="current">/<li>/g;
356                         $_ =~ s/<li><a href="index.html">/<li class="current"><a href="index.html">/g;
357                   }               
358                   $_ =~ s/<li class="current"><a href="pages.html">/<li><a href="pages.html">/g;
359                   
360                   if($file =~ /^html\/pages\..*/){
361                         $_ =~ s/<li><a href="pages.html">/<li class="current"><a href="pages.html">/g;
362                   }
363           }
364           
365           if($file =~ /^html\/publis.*/){
366                         $_ =~ s/<div class="header">/<div>/g;
367                         $_ =~ s/<div class="headertitle">/<div>/g;
368          }
369         
370           # Add the FAQ PUBLIS PEOPLE HISTORY and CONTRIB to the top navbar.
371       if( $_ =~ /<div.*class="tabs">/){
372         $tabs = 1;
373       }
374       if( $_ =~ /<\/div>/){
375         $tabs = 0;
376       }
377       if( $_ =~ /<\/ul>/ && $tabs){
378                 my $tmp_buff="";
379                 
380                         #┬áLBO : ugly way to separate doc in 2 separate stuff ...
381                         $tmp_buff .= '      <li><a href="https://gforge.inria.fr/frs/?group_id=12"><span>Download</span></a></li>'."\n";
382                         $tmp_buff .= '      <li><a href="documentation.html"><span>Online documentation</span></a></li>'."\n";
383                         $tmp_buff .= '      <li><a href="publis.html"><span>Publications</span></a></li>'."\n";
384                         $tmp_buff .= '      <li><a href="people.html"><span>People</span></a></li>'."\n";
385                         $tmp_buff .= '      <li><a href="history.html"><span>History</span></a></li>'."\n";
386                         $tmp_buff .= '      <li><a href="contrib.html"><span>Contrib</span></a></li>'."\n";
387                         $tmp_buff .= '      <li><a href="faq.html"><span>FAQ&#160;Page</span></a></li>'."\n";
388                 
389                 
390                 $tmp_buff .= '      <li><a href="http://gforge.inria.fr/projects/simgrid"><span>SimGrid&#160;Forge</span></a></li>'."\n";
391                                 
392                 
393                 $tmp_buff .= $_;
394                 $tabs = 0;
395
396               # Rework the navbar and add menu for use.html
397               # Fix the current "button" of buggy Doxygen tabs  
398               if($file =~ /^html\/use.*/
399               || $file =~ /^html\/installSimgrid.*/
400               || $file =~ /^html\/options.*/ 
401               || $file =~ /^html\/bindings.*/
402               || $file =~ /^html\/gtnets.*/
403               || $file =~ /^html\/ns3.*/
404               || $file =~ /^html\/modules.*/
405               || $file =~ /^html\/annotated.*/)
406               {
407                                 $tmp_buff .= '      <div class="tabs_group_use">'."\n";
408                                 $tmp_buff .= '          <ul class="tablist">'."\n";
409                                 $tmp_buff .= '          <li><a href="installSimgrid.html"><span>Install SimGrid</span></a></li>'."\n";
410                                 $tmp_buff .= '          <li><a href="modules.html"><span>Modules&#160;API</span></a></li>'."\n";
411                         $tmp_buff .= '          <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>'."\n";
412                                 $tmp_buff .= '          <li><a href="options.html"><span>Options & configurations</span></a></li>'."\n";
413                                 $tmp_buff .= '          <li><a href="bindings.html"><span>Bindings</span></a></li>'."\n";
414                                 $tmp_buff .= '          <li><a href="gtnets.html"><span>GTNets</span></a></li>'."\n";
415                                 $tmp_buff .= '          <li><a href="ns3.html"><span>NS3</span></a></li>'."\n";
416                                 $tmp_buff .= '          </ul></div>'."\n";
417                                 $tmp_buff .= '      </div>'."\n";
418                                 
419                                 my $filename = $file;
420                         $filename =~ s/html\///g;
421                         $filename =~ s/\.html//g;
422                         $filename =~ s/publis_.*/publis/g;
423                         $tmp_buff =~ s/<li class="current">/<li>/g;
424                         $tmp_buff =~ s/<li><a href="$filename.html">/<li class="current"><a href="$filename.html">/g;
425                         $tmp_buff =~ s/<li><a href="use.html">/<li class="current"><a href="use.html">/g; 
426                                 
427               }
428         
429               # Rework the navbar
430               # Fix the current "button" of buggy Doxygen tabs   
431               if($file =~ /^html\/publis.*/ 
432               || $file =~ /^html\/faq.*/
433               || $file =~ /^html\/people.*/ 
434               || $file =~ /^html\/history.*/ 
435               || $file =~ /^html\/contrib.*/
436               || $file =~ /^html\/pages.*/)
437               {
438                       my $filename = $file;
439                       $filename =~ s/html\///g;
440                       $filename =~ s/\.html//g;
441                       $filename =~ s/publis_.*/publis/g;
442                       $tmp_buff =~ s/<li class="current">/<li>/g;
443                       $tmp_buff =~ s/<li><a href="$filename.html">/<li class="current"><a href="$filename.html">/g;     
444               }
445               
446
447               print TO $tmp_buff;             
448               next;
449     }
450         
451       s|<li><a href="index.html"><span>Main&#160;Page</span>|<li><a href="index.php"><span>Home</span>|g;                       
452      s|<span>Main&#160;Page</span>|<span>Home</span>|g; 
453       s|<span>Modules</span>|<span>Modules&#160;API</span>|g;
454       s|<li.*><a href="pages.html"><span>Related&#160;Pages</span></a></li>\n||g;
455       s|<li><a href="modules.html"><span>Modules&#160;API</span></a></li>\n||g;
456       s|<li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>\n||g;
457       s|<li class="current"><a href="modules.html"><span>Modules&#160;API</span></a></li>\n||g;
458       s|<li class="current"><a href="annotated.html"><span>Data&#160;Structures</span></a></li>\n||g;
459       s|Related Pages<|Documentation&nbsp;Index<|g;
460       s|<div id="navrow|<div align="center" id="navrow|g;
461       s|<div class="headertitle">|<div class="headertitle" align="center">|g;   
462       print TO $_;
463     }
464     close FROM;
465     close TO;
466     rename("$outfile", "$file") unless $debug{'rename'};
467 }
468
469
470