Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add pages for ns3 and gtnets.
[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/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                      html/pages.html html/modules.html html/annotated.html html/functions.html html/functions_vars.html index.php 
9                      html/GRAS_tut.html html/installSimgrid.html html/bindings.html html/options.html html/use.html html/gtnets.html
10                      html/ns3.html);
11
12 # GRAS tutorial
13 map {push @extra_files, "html/GRAS_tut_$_.html"} qw (intro 
14                                                      tour tour_install tour_setup tour_simpleexchange tour_args tour_callbacks tour_globals 
15                                                           tour_logs tour_timers tour_exceptions tour_rpc);
16
17 # GRAS examples
18 map {push @extra_files, "html/GRAS_ex_$_.html"} qw (ping mmrpc token timer);
19
20 my %debug;
21 $debug{'parse'} = 0; # show how we parse the module tree
22 $debug{'input'} = 0; # display the resulting tree
23 $debug{'handle'}= 0; # Be verbose on the post-processing
24 $debug{'rename'}= 0; # do not overwrite the files (allows several debuging runs without rerunning doxygen)
25
26 my @allfiles;
27 ###
28 ### Get the module definitions
29 ###
30
31 open IN, "html/modules.html" || die "Cannot parse html/modules.html. Did you really run doxygen?\n";
32
33 # pass headers
34 while (<IN>) {
35   last if /group__SimGrid__API.html/;
36 }
37
38 # Parse the tree
39 my $top;
40 my $current;
41 my $entry;
42
43 # $current->{'label'}="ROOT";
44 # push @{$top->{'down'}},$current;
45 # print "Push $current '".($current->{'label'})."' as child of $top '".($top->{'label'})."'\n" if $debug{'parse'};
46 # $current=$top;
47 $top->{'label'}="ROOT";
48 print "Create ROOT $top\n" if $debug{'parse'};
49 $current=$top;
50
51
52 # Read the whole data to postprocess it a bit
53 my $in;
54 while (<IN>) {
55     $in .= $_;
56 }
57 $in =~ s/<ul>/\n<ul>\n/sg;
58 foreach $_ (split(/\n/,$in)) {
59     next unless length($_);
60     next if ($_ =~ m|^</li>$|);
61     print "  Seen '$_'\n" if $debug{'parse'};
62   if (/<ul>/) {
63     print "DOWN: $current '$current->{'label'}' -> " if $debug{'parse'};
64     $current = $current->{'down'}[scalar @{$current->{'down'}} - 1];
65     print "$current '$current->{'label'}'\n" if $debug{'parse'};
66     next;
67   }
68   if (/<\/ul>/) {
69     $current = $current->{'up'};
70     print "UP to $current '$current->{'label'}'\n" if $debug{'parse'};
71     next;
72   }
73   if (/<p>/) {
74     last;
75   }
76   
77   m|href="([^"]*)">([^<]*)</a>|; #"
78   
79   $entry = {};
80   $entry->{'file'} = $1;  
81   $entry->{'label'} = $2;
82   $entry->{'up'} = $current;
83   push @{$current->{'down'}},$entry;
84   print "Push file:$1 label:'$2' as child of $current '$current->{'label'}'\n" if $debug{'parse'};
85   push @allfiles,"html/$1";
86 }
87 close IN;
88
89 # Check each file for extra information (short name, extra childs)
90 sub extra_info {
91   my $current=shift;
92
93   if (defined($current->{'file'})) {
94     open IN, "html/$current->{'file'}";
95     while (<IN>) {
96       if (/DOXYGEN_NAVBAR_LABEL/) {
97         if (/DOXYGEN_NAVBAR_LABEL="([^"]*)"/) {#"
98           print "Extra info from $current->{'file'}: label=$1, not $current->{'label'}\n" if $debug{'parse'};
99           $current->{'label'}=$1;
100         } else {
101           die "Malformated DOXYGEN_NAVBAR_LABEL line in $current->{'file'}";
102         }
103       }
104       if (/DOXYGEN_NAVBAR_CHILD/) {
105         if (/DOXYGEN_NAVBAR_CHILD *"([^"]*)"=([^ ]*)/) {#"
106           $entry = {};
107           $entry->{'label'} = $1;
108           $entry->{'file'} = $2;
109           chomp($entry->{'file'});
110           $entry->{'up'} = $current;
111           push @{$current->{'down'}},$entry;
112           print "Extra info from $current->{'file'}: New child $entry->{'label'}=$entry->{'file'}\n"  if $debug{'parse'};
113         } else {
114           die "Malformated DOXYGEN_NAVBAR_CHILD line in $current->{'file'}";
115         }
116       }
117     }
118   }
119   
120   foreach my $entry (@{$current->{'down'}}) {
121     extra_info($entry);
122   }  
123 }
124 extra_info($top);
125
126 ## debug function
127 sub display {
128   my $current=shift;
129   my $level=shift;
130   print "  " x $level;
131   print "$current: ".$current->{'label'}." ($current->{'file'})\n";
132   foreach my $entry (@{$current->{'down'}}) {
133     display($entry,$level+1);
134   }
135 }
136
137 display($top,0) if $debug{'input'};
138
139 ###
140 ### Generate the navbar
141 ###
142
143 # the root deserves some special handling
144 open IN,"html/modules.html" || die;
145 open OUT,">html/modules.new.html" || die;
146 my $line;
147 while ($line = <IN>) {
148   last if $line =~ /<h1>SimGrid Modules</;
149   print OUT $line;
150 }
151
152 print OUT "<div class=\"tabs\">\n  <ul class=\"tablist\">\n";
153 foreach $current (@{ ${$top->{'down'}}[0]->{'down'} }) {
154   print OUT "   <li><a href=\"$current->{'file'}\"><span>$current->{'label'}</span></a></li>\n";
155 }
156 print OUT "  </ul></div>\n";
157 print OUT $line;
158 while (<IN>) {
159   print OUT $_;
160 }
161
162 close OUT;
163 close IN;
164 rename("html/modules.new.html","html/modules.html") unless $debug{'rename'};
165
166 # the publication pages deserves some special handling too
167 my %pub_tabs = ("publis.html"       =>"Reference publications",
168                 "publis_core.html"  =>"Other publication about SimGrid",
169                 "publis_extern.html"=>"External papers using SimGrid",
170                 "publis_intra.html"=>"Internal papers using SimGrid");
171 # force ordering
172 my @pub_titles = ("publis.html", "publis_core.html", "publis_extern.html", "publis_intra.html");
173 sub handle_pub{
174     my $oldname = shift;
175     my $newname = $oldname;
176     $newname =~ s/\.html$/.new.html/;
177  
178 #    print "Handle_pub($oldname -> $newname)\n";
179     
180     open IN,"html/$oldname" || die "Cannot open $oldname";
181     open OUT,">html/$newname" || die "Cannot open $newname";
182     my $line;
183     while ($line = <IN>) {
184         last if $line =~ /<h1>/;
185         print OUT $line;
186     }
187
188     print OUT "<div class=\"tabs\">\n<ul class=\"tablist\">\n";
189     foreach my $page (@pub_titles) {
190         print OUT "         <li".($page eq $oldname? " class=\"current\"":"" )."> <a href=\"$page\"><span>".($pub_tabs{$page})."</span></a></li>\n";
191     }
192
193     print OUT "  </ul></div>\n";
194     print OUT $line;
195     while ($line = <IN>) {
196         print OUT $line;
197     }
198     close OUT;
199     close IN;
200     rename("html/$newname","html/$oldname") unless $debug{'rename'};
201 }
202 map {handle_pub($_)} @pub_titles;
203
204
205 # Operate the recursion
206 sub handle_page {
207   my $current=shift;
208   my $level=shift;
209
210   print "Handle $current->{'file'} at level $level\n" if $debug{'handle'};
211     
212   # we generate the tabs bottom up begining from where we are in the tree
213   # and display them top down, as it should in a file
214   my @tabs = ();
215   my $found_div_tabs=0;
216   
217   if (defined ($current->{'label'}) and $current->{'label'} ne 'ROOT') {
218 #    print "handle $current->{'file'}, at level $level\n";
219     # generate the tabs
220     my $iterator = $current;
221     my $lvl_it=$level;
222     while ($lvl_it >= 0) {
223       my $father = $iterator->{'up'};
224       $tabs[$lvl_it] = "<div class=\"tabs2\">\n<ul class=\"tablist\">\n";
225       foreach my $bro (@{$father->{'down'}}) {
226         $tabs[$lvl_it] .= "  <li".($bro==$iterator?" class=\"current\"":"")."> <a href=\"$bro->{'file'}\"><span>$bro->{'label'}</span></a></li>\n";      
227       }
228       $tabs[$lvl_it] .= "  </ul></div>\n";
229       $iterator = $father;
230       $lvl_it--;
231     }
232     if (defined $current->{'down'}) { # there's some kid. Display them too
233       $tabs[$level+1] = "<div class=\"tabs2\">\n  <ul class=\"tablist\">\n";
234       foreach my $kid (@{$current->{'down'}}) {
235         $tabs[$level+1] .= "  <li> <a href=\"$kid->{'file'}\"><span>$kid->{'label'}</span></a></li>\n";      
236       }
237       $tabs[$level+1] .= "  </ul></div>\n";      
238     }
239     
240     # put them in place
241     open FROM,"html/$current->{'file'}" || die;
242     my $newname="html/$current->{'file'}";
243     $newname =~ s/.html/.handlepage.html/;
244     open TO,">$newname" || die;
245 #    print "XXX Deal with html/$current->{'file'}  ->  $newname\n";
246     while (<FROM>) {
247 #      print "--Read  $_";
248       # add "current" to the module API granfather page
249       s|<li><a href="modules.html"><span>[^<]*</span></a></li>|<li class="current"><a href="modules.html"><span>Modules&nbsp;API</span></a></li>|;
250 #      print "++Write $_";
251           $found_div_tabs=1 if m/div.*class="tabs"/;    
252       print TO "$_";
253       last if ((m|</div>|)&&($found_div_tabs));
254     }
255       
256     print TO "\n<!-- POST-PROCESSED TABS -->\n";
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
344 my $tabs;
345
346 foreach my $file (@allfiles) {
347     $file =~ s/.html/.handlepage.html/ if $debug{'rename'}; # Take right name if debugging
348         
349     open FROM,"$file" || die;
350     my $outfile = "$file";
351     $outfile =~ s/.(html|php)$/.new.$1/;
352     open TO,">$outfile" || die;
353 #    print "POSTPROCESSING $file (tmp=$outfile)\n";
354     while (<FROM>) {
355       # Add the simgrid css, just in case
356       print TO '<link href="simgrid.css" rel="stylesheet" type="text/css">'."\n"
357         if (m|</head>|);
358
359           if($tabs){
360                   if($file =~ /^html\/index\..*/){
361                         $_ =~ s/<li class="current">/<li>/g;
362                         $_ =~ s/<li><a href="index.html">/<li class="current"><a href="index.html">/g;
363                   }               
364                   $_ =~ s/<li class="current"><a href="pages.html">/<li><a href="pages.html">/g;
365                   
366                   if($file =~ /^html\/pages\..*/){
367                         $_ =~ s/<li><a href="pages.html">/<li class="current"><a href="pages.html">/g;
368                   }
369           }
370           
371           if($file =~ /^html\/publis.*/){
372                         $_ =~ s/<div class="header">/<div>/g;
373                         $_ =~ s/<div class="headertitle">/<div>/g;
374          }
375         
376           # Add the FAQ PUBLIS PEOPLE HISTORY and CONTRIB to the top navbar.
377       if( $_ =~ /<div.*class="tabs">/){
378         $tabs = 1;
379       }
380       if( $_ =~ /<\/div>/){
381         $tabs = 0;
382       }
383       if( $_ =~ /<\/ul>/ && $tabs){
384                 my $tmp_buff="";
385                 $tmp_buff .= '      <li><a href="use.html"><span>Using SimGrid</span></a></li>'."\n";
386                 $tmp_buff .= '      <li><a href="faq.html"><span>FAQ&#160;Page</span></a></li>'."\n";
387                 $tmp_buff .= '      <li><a href="publis.html"><span>Publications</span></a></li>'."\n";
388                 $tmp_buff .= '      <li><a href="people.html"><span>People</span></a></li>'."\n";
389                 $tmp_buff .= '      <li><a href="history.html"><span>History</span></a></li>'."\n";
390                 $tmp_buff .= '      <li><a href="contrib.html"><span>Contrib</span></a></li>'."\n";
391                 $tmp_buff .= '      <li><a href="http://gforge.inria.fr/projects/simgrid"><span>Simgrid&#160;Forge</span></a></li>'."\n";
392                 $tmp_buff .= '      <li><a href="http://simgrid.gforge.inria.fr/"><span>Home</span></a></li>'."\n";
393                 $tmp_buff .= '      <li><a href="pages.html"><span>Site&nbsp;Map</span></a></li>'."\n";
394                 $tmp_buff .= $_;
395                 $tabs = 0;
396
397               # Rework the navbar and add menu for use.html
398               # Fix the current "button" of buggy Doxygen tabs  
399               if($file =~ /^html\/use.*/
400               || $file =~ /^html\/installSimgrid.*/
401               || $file =~ /^html\/options.*/ 
402               || $file =~ /^html\/bindings.*/
403               || $file =~ /^html\/gtnets.*/
404               || $file =~ /^html\/ns3.*/
405               || $file =~ /^html\/modules.*/
406               || $file =~ /^html\/annotated.*/)
407               {
408                                 $tmp_buff .= '      <div class="tabs_group_use">'."\n";
409                                 $tmp_buff .= '          <ul class="tablist">'."\n";
410                                 $tmp_buff .= '          <li><a href="installSimgrid.html"><span>Install SimGrid</span></a></li>'."\n";
411                                 $tmp_buff .= '          <li><a href="modules.html"><span>Modules&#160;API</span></a></li>'."\n";
412                         $tmp_buff .= '          <li><a href="annotated.html"><span>Data&#160;Structures</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="bindings.html"><span>Bindings</span></a></li>'."\n";
415                                 $tmp_buff .= '          <li><a href="gtnets.html"><span>GTNets</span></a></li>'."\n";
416                                 $tmp_buff .= '          <li><a href="ns3.html"><span>NS3</span></a></li>'."\n";
417                                 $tmp_buff .= '          </ul></div>'."\n";
418                                 $tmp_buff .= '      </div>'."\n";
419                                 
420                                 my $filename = $file;
421                         $filename =~ s/html\///g;
422                         $filename =~ s/\.html//g;
423                         $filename =~ s/publis_.*/publis/g;
424                         $tmp_buff =~ s/<li class="current">/<li>/g;
425                         $tmp_buff =~ s/<li><a href="$filename.html">/<li class="current"><a href="$filename.html">/g;
426                         $tmp_buff =~ s/<li><a href="use.html">/<li class="current"><a href="use.html">/g; 
427                                 
428               }
429         
430               # Rework the navbar
431               # Fix the current "button" of buggy Doxygen tabs   
432               if($file =~ /^html\/publis.*/ 
433               || $file =~ /^html\/faq.*/
434               || $file =~ /^html\/people.*/ 
435               || $file =~ /^html\/history.*/ 
436               || $file =~ /^html\/contrib.*/
437               || $file =~ /^html\/pages.*/)
438               {
439                       my $filename = $file;
440                       $filename =~ s/html\///g;
441                       $filename =~ s/\.html//g;
442                       $filename =~ s/publis_.*/publis/g;
443                       $tmp_buff =~ s/<li class="current">/<li>/g;
444                       $tmp_buff =~ s/<li><a href="$filename.html">/<li class="current"><a href="$filename.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><a href="modules.html"><span>Modules&#160;API</span></a></li>\n||g;
454       s|<li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>\n||g;
455       s|<li class="current"><a href="modules.html"><span>Modules&#160;API</span></a></li>\n||g;
456       s|<li class="current"><a href="annotated.html"><span>Data&#160;Structures</span></a></li>\n||g;
457       s|Related Pages<|Site&nbsp;Map<|g;
458                                                                                            
459       print TO $_;
460     }
461     close FROM;
462     close TO;
463     rename("$outfile", "$file") unless $debug{'rename'};
464 }
465
466
467