Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
parameter "--trace" to control whether to trace masterslave examples
[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  index.php 
9                      html/GRAS_tut.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 as child of $top\n" if $debug{'parse'};
45 $current=$top;
46
47
48 while (<IN>) {
49   if (/<ul>/) {
50     print "DOWN: $current -> " if $debug{'parse'};
51     $current = $current->{'down'}[scalar @{$current->{'down'}} - 1];
52     print "$current\n" if $debug{'parse'};
53     next;
54   }
55   if (/<\/ul>/) {
56     $current = $current->{'up'};
57     print "UP\n" if $debug{'parse'};
58     next;
59   }
60   if (/<p>/) {
61     last;
62   }
63   
64   m|href="([^"]*)">([^<]*)</a>|; #"
65   
66   $entry = {};
67   $entry->{'file'} = $1;  
68   $entry->{'label'} = $2;
69   $entry->{'up'} = $current;
70   push @{$current->{'down'}},$entry;
71   print "Push $1 $2 as child of $current\n" if $debug{'parse'};
72   push @allfiles,"html/$1";
73 }
74 close IN;
75
76 # Check each file for extra information (short name, extra childs)
77 sub extra_info {
78   my $current=shift;
79
80   if (defined($current->{'file'})) {
81     open IN, "html/$current->{'file'}";
82     while (<IN>) {
83       if (/DOXYGEN_NAVBAR_LABEL/) {
84         if (/DOXYGEN_NAVBAR_LABEL="([^"]*)"/) {#"
85           print "Extra info from $current->{'file'}: label=$1, not $current->{'label'}\n" if $debug{'parse'};
86           $current->{'label'}=$1;
87         } else {
88           die "Malformated DOXYGEN_NAVBAR_LABEL line in $current->{'file'}";
89         }
90       }
91       if (/DOXYGEN_NAVBAR_CHILD/) {
92         if (/DOXYGEN_NAVBAR_CHILD *"([^"]*)"=([^ ]*)/) {#"
93           $entry = {};
94           $entry->{'label'} = $1;
95           $entry->{'file'} = $2;
96           chomp($entry->{'file'});
97           $entry->{'up'} = $current;
98           push @{$current->{'down'}},$entry;
99           print "Extra info from $current->{'file'}: New child $entry->{'label'}=$entry->{'file'}\n"  if $debug{'parse'};
100         } else {
101           die "Malformated DOXYGEN_NAVBAR_CHILD line in $current->{'file'}";
102         }
103       }
104     }
105   }
106   
107   foreach my $entry (@{$current->{'down'}}) {
108     extra_info($entry);
109   }  
110 }
111 extra_info($top);
112
113 ## debug function
114 sub display {
115   my $current=shift;
116   my $level=shift;
117   print "  " x $level;
118   print "$current: ".$current->{'label'}." ($current->{'file'})\n";
119   foreach my $entry (@{$current->{'down'}}) {
120     display($entry,$level+1);
121   }
122 }
123
124 display($top,0) if $debug{'input'};
125
126 ###
127 ### Generate the navbar
128 ###
129
130 # the root deserves some special handling
131 open IN,"html/modules.html" || die;
132 open OUT,">html/modules.new.html" || die;
133 my $line;
134 while ($line = <IN>) {
135   last if $line =~ /<h1>SimGrid Modules</;
136   print OUT $line;
137 }
138
139 print OUT "<div class=\"tabs\">\n  <ul>\n";
140 foreach $current (@{ ${$top->{'down'}}[0]->{'down'} }) {
141   print OUT "   <li><a href=\"$current->{'file'}\"><span>$current->{'label'}</span></a></li>\n";
142 }
143 print OUT "  </ul></div>\n";
144 print OUT $line;
145 while (<IN>) {
146   print OUT $_;
147 }
148
149 close OUT;
150 close IN;
151 rename("html/modules.new.html","html/modules.html") unless $debug{'rename'};
152
153 # the publication pages deserves some special handling too
154 my %pub_tabs = ("publis.html"       =>"Reference publications",
155                 "publis_core.html"  =>"Other publication about SimGrid",
156                 "publis_extern.html"=>"External papers using SimGrid",
157                 "publis_intra.html"=>"Internal papers using SimGrid");
158 # force ordering
159 my @pub_titles = ("publis.html", "publis_core.html", "publis_extern.html", "publis_intra.html");
160 sub handle_pub{
161     my $oldname = shift;
162     my $newname = $oldname;
163     $newname =~ s/\.html$/.new.html/;
164  
165 #    print "Handle_pub($oldname -> $newname)\n";
166     
167     open IN,"html/$oldname" || die "Cannot open $oldname";
168     open OUT,">html/$newname" || die "Cannot open $newname";
169     my $line;
170     while ($line = <IN>) {
171         last if $line =~ /<h1>/;
172         print OUT $line;
173     }
174
175     print OUT "<div class=\"tabs\">\n  <ul>\n";
176     foreach my $page (@pub_titles) {
177         print OUT "         <li".($page eq $oldname? " class=\"current\"":"" )."> <a href=\"$page\"><span>".($pub_tabs{$page})."</span></a></li>\n";
178     }
179
180     print OUT "  </ul></div>\n";
181     print OUT $line;
182     while ($line = <IN>) {
183         print OUT $line;
184     }
185     close OUT;
186     close IN;
187     rename("html/$newname","html/$oldname") unless $debug{'rename'};
188 }
189 map {handle_pub($_)} @pub_titles;
190
191
192 # Operate the recursion
193 sub handle_page {
194   my $current=shift;
195   my $level=shift;
196
197   print "Handle $current->{'file'} at level $level\n" if $debug{'handle'};
198     
199   # we generate the tabs bottom up begining from where we are in the tree
200   # and display them top down, as it should in a file
201   my @tabs = ();
202
203   if (defined ($current->{'label'}) and $current->{'label'} ne 'ROOT') {
204 #    print "handle $current->{'file'}, at level $level\n";
205     # generate the tabs
206     my $iterator = $current;
207     my $lvl_it=$level;
208     while ($lvl_it >= 0) {
209       my $father = $iterator->{'up'};
210       $tabs[$lvl_it] = "<div class=\"tabs\">\n  <ul>\n";
211       foreach my $bro (@{$father->{'down'}}) {
212         $tabs[$lvl_it] .= "  <li".($bro==$iterator?" class=\"current\"":"")."> <a href=\"$bro->{'file'}\"><span>$bro->{'label'}</span></a></li>\n";      
213       }
214       $tabs[$lvl_it] .= "  </ul></div>\n";
215       $iterator = $father;
216       $lvl_it--;
217     }
218     if (defined $current->{'down'}) { # there's some kid. Display them too
219       $tabs[$level+1] = "<div class=\"tabs\">\n  <ul>\n";
220       foreach my $kid (@{$current->{'down'}}) {
221         $tabs[$level+1] .= "  <li> <a href=\"$kid->{'file'}\"><span>$kid->{'label'}</span></a></li>\n";      
222       }
223       $tabs[$level+1] .= "  </ul></div>\n";      
224     }
225     
226     # put them in place
227     open FROM,"html/$current->{'file'}" || die;
228     my $newname="html/$current->{'file'}";
229     $newname =~ s/.html/.handlepage.html/;
230     open TO,">$newname" || die;
231 #    print "XXX Deal with html/$current->{'file'}  ->  $newname\n";
232     while (<FROM>) {
233 #      print "--Read  $_";
234       # add "current" to the module API granfather page
235       s|<li><a href="modules.html"><span>[^<]*</span></a></li>|<li class="current"><a href="modules.html"><span>Modules&nbsp;API</span></a></li>|;
236 #      print "++Write $_";
237       print TO "$_";
238       last if (m|</div>|);
239     }
240     foreach (@tabs) {
241 #      print "TAB: $_";
242       print TO "$_";
243     }
244     if ($current->{'file'} =~ m/^class/) {
245         while (<FROM>) {
246             last if (m|</div>|);
247         }
248       print TO "$_";    
249     }
250     while (<FROM>) {
251       if (m/The documentation for/) {
252           while (<FROM>) {
253               last if (m/<p>/);
254           }
255       }
256       print TO "$_";
257     }    
258     close FROM;
259     close TO;
260     rename("$newname","html/$current->{'file'}") unless $debug{'rename'};
261   } 
262   
263   # recurse on childs
264   foreach my $entry (@{$current->{'down'}}) {
265     handle_page($entry,$level+1);
266   }
267 }
268
269 ###
270 ### Launch the modules navbar reworking
271 ###
272 handle_page($top,-2);# skip roots (we have 2 roots) in level counting
273
274
275 ###
276 ### Post-processsing common to all pages
277 ###
278 map {push @allfiles,$_} @extra_files;
279 print "All files: ".(join(", ",@allfiles))."\n" if $debug{'parse'};
280
281 foreach my $file (@allfiles) {
282     $file =~ s/.html/.handlepage.html/ if $debug{'rename'}; # Take right name if debugging
283         
284     open FROM,"$file" || die;
285     my $outfile = "$file";
286     $outfile =~ s/.(html|php)$/.new.$1/;
287     open TO,">$outfile" || die;
288 #    print "POSTPROCESSING $file (tmp=$outfile)\n";
289     while (<FROM>) {
290       # Add the simgrid css, just in case
291       print TO '<link href="simgrid.css" rel="stylesheet" type="text/css">'."\n"
292         if (m|</head>|);
293
294       # Rework the navbar
295       if (m,<li><a href="(doc/)?index.html"><span>Main\&nbsp;Page</span></a></li>,) {
296         print TO '    <li'.($file =~ m,(doc/)?index.html, ? " class='current'" :"").'><a href="'.$1.'index.html"><span>Overview</span></a></li>'."\n";
297         print TO '    <li'.($file =~ m,(doc/)?faq.html, ? " class='current'" :"").'><a href="'.$1.'faq.html"><span>FAQ</span></a></li>'."\n";
298         next;
299       }
300       if (m,<li><a href="(doc/)?annotated.html"><span>Data\&nbsp;Structures</span></a></li>,) {
301         print TO '    <li'.($file =~ m,(doc/)?publis(_[^.]*)?.html, ? " class='current'" :"").'><a href="'.$1.'publis.html"><span>Publications</span></a></li>'."\n";
302         print TO '    <li'.($file =~ m,(doc/)?people.html, ? " class='current'" :"").'><a href="'.$1.'people.html"><span>People</span></a></li>'."\n";
303         print TO '    <li'.($file =~ m,(doc/)?history.html, ? " class='current'" :"").'><a href="'.$1.'history.html"><span>History</span></a></li>'."\n";
304         print TO '    <li'.($file =~ m,(doc/)?contrib.html, ? " class='current'" :"").'><a href="'.$1.'contrib.html"><span>Contrib</span></a></li>'."\n";
305         next;
306       }
307       s|<span>Modules</span>|<span>Modules API</span>|g;
308       s|<span>Related&nbsp;Pages</span>|<span>Site&nbsp;Plan</span>|g;
309                                                                                                  
310       print TO $_;
311     }
312     close FROM;
313     close TO;
314     rename("$outfile", "$file") unless $debug{'rename'};
315 }
316
317
318