Logo AND Algorithmique Numérique Distribuée

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