Logo AND Algorithmique Numérique Distribuée

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