Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
integrate the history to the build infrastructure
[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/publis.html html/pages.html html/modules.html html/contrib.html index.php html/GRAS_tut.html);
7
8 # GRAS tutorial
9 map {push @extra_files, "html/GRAS_tut_$_.html"} qw (intro 
10                                                      tour tour_install tour_setup tour_simpleexchange tour_args tour_callbacks tour_globals 
11                                                           tour_logs tour_timers tour_exceptions tour_rpc);
12
13 # GRAS examples
14 map {push @extra_files, "html/GRAS_ex_$_.html"} qw (ping mmrpc token timer);
15
16 my %debug;
17 $debug{'parse'} = 0; # show how we parse the module tree
18 $debug{'input'} = 0; # display the resulting tree
19 $debug{'handle'}= 0; # Be verbose on the post-processing
20 $debug{'rename'}= 0; # do not overwrite the files (allows several debuging runs without rerunning doxygen)
21
22 my @allfiles;
23 ###
24 ### Get the module definitions
25 ###
26
27 open IN, "html/modules.html" || die "Cannot parse html/modules.html. Did you really run doxygen?\n";
28
29 # pass headers
30 while (<IN>) {
31   last if /group__SimGrid__API.html/;
32 }
33
34 # Parse the tree
35 my $top;
36 my $current;
37 my $entry;
38
39 $current->{'label'}="ROOT";
40 push @{$top->{'down'}},$current;
41 print "Push $current as child of $top\n" if $debug{'parse'};
42 $current=$top;
43
44
45 while (<IN>) {
46   if (/<ul>/) {
47     print "DOWN: $current -> " if $debug{'parse'};
48     $current = $current->{'down'}[scalar @{$current->{'down'}} - 1];
49     print "$current\n" if $debug{'parse'};
50     next;
51   }
52   if (/<\/ul>/) {
53     $current = $current->{'up'};
54     print "UP\n" if $debug{'parse'};
55     next;
56   }
57   if (/<p>/) {
58     last;
59   }
60   
61   m|href="([^"]*)">([^<]*)</a>|; #"
62   
63   $entry = {};
64   $entry->{'file'} = $1;  
65   $entry->{'label'} = $2;
66   $entry->{'up'} = $current;
67   push @{$current->{'down'}},$entry;
68   print "Push $1 $2 as child of $current\n" if $debug{'parse'};
69   push @allfiles,"html/$1";
70 }
71 close IN;
72
73 # Check each file for extra information (short name, extra childs)
74 sub extra_info {
75   my $current=shift;
76
77   if (defined($current->{'file'})) {
78     open IN, "html/$current->{'file'}";
79     while (<IN>) {
80       if (/DOXYGEN_NAVBAR_LABEL/) {
81         if (/DOXYGEN_NAVBAR_LABEL="([^"]*)"/) {#"
82           print "Extra info from $current->{'file'}: label=$1, not $current->{'label'}\n" if $debug{'parse'};
83           $current->{'label'}=$1;
84         } else {
85           die "Malformated DOXYGEN_NAVBAR_LABEL line in $current->{'file'}";
86         }
87       }
88       if (/DOXYGEN_NAVBAR_CHILD/) {
89         if (/DOXYGEN_NAVBAR_CHILD *"([^"]*)"=([^ ]*)/) {#"
90           $entry = {};
91           $entry->{'label'} = $1;
92           $entry->{'file'} = $2;
93           chomp($entry->{'file'});
94           $entry->{'up'} = $current;
95           push @{$current->{'down'}},$entry;
96           print "Extra info from $current->{'file'}: New child $entry->{'label'}=$entry->{'file'}\n"  if $debug{'parse'};
97         } else {
98           die "Malformated DOXYGEN_NAVBAR_CHILD line in $current->{'file'}";
99         }
100       }
101     }
102   }
103   
104   foreach my $entry (@{$current->{'down'}}) {
105     extra_info($entry);
106   }  
107 }
108 extra_info($top);
109
110 ## debug function
111 sub display {
112   my $current=shift;
113   my $level=shift;
114   print "  " x $level;
115   print "$current: ".$current->{'label'}." ($current->{'file'})\n";
116   foreach my $entry (@{$current->{'down'}}) {
117     display($entry,$level+1);
118   }
119 }
120
121 display($top,0) if $debug{'input'};
122
123 ###
124 ### Generate the navbar
125 ###
126
127 # the root deserves some special handling
128 open IN,"html/modules.html" || die;
129 open OUT,">html/modules.new.html" || die;
130 my $line;
131 while ($line = <IN>) {
132   last if $line =~ /<h1>SimGrid Modules</;
133   print OUT $line;
134 }
135
136 print OUT "<div class=\"tabs\">\n  <ul>\n";
137 foreach $current (@{ ${$top->{'down'}}[0]->{'down'} }) {
138   print OUT "   <li><a href=\"$current->{'file'}\"><span>$current->{'label'}</span></a></li>\n";
139 }
140 print OUT "  </ul></div>\n";
141 print OUT $line;
142 while (<IN>) {
143   print OUT $_;
144 }
145
146 close OUT;
147 close IN;
148 rename("html/modules.new.html","html/modules.html") unless $debug{'rename'};
149
150 # Operate the recursion
151 sub handle_page {
152   my $current=shift;
153   my $level=shift;
154
155   print "Handle $current->{'file'} at level $level\n" if $debug{'handle'};
156     
157   # we generate the tabs bottom up begining from where we are in the tree
158   # and display them top down, as it should in a file
159   my @tabs = ();
160
161   if (defined ($current->{'label'}) and $current->{'label'} ne 'ROOT') {
162 #    print "handle $current->{'file'}, at level $level\n";
163     # generate the tabs
164     my $iterator = $current;
165     my $lvl_it=$level;
166     while ($lvl_it >= 0) {
167       my $father = $iterator->{'up'};
168       $tabs[$lvl_it] = "<div class=\"tabs\">\n  <ul>\n";
169       foreach my $bro (@{$father->{'down'}}) {
170         $tabs[$lvl_it] .= "  <li".($bro==$iterator?" class=\"current\"":"")."> <a href=\"$bro->{'file'}\"><span>$bro->{'label'}</span></a></li>\n";      
171       }
172       $tabs[$lvl_it] .= "  </ul></div>\n";
173       $iterator = $father;
174       $lvl_it--;
175     }
176     if (defined $current->{'down'}) { # there's some kid. Display them too
177       $tabs[$level+1] = "<div class=\"tabs\">\n  <ul>\n";
178       foreach my $kid (@{$current->{'down'}}) {
179         $tabs[$level+1] .= "  <li> <a href=\"$kid->{'file'}\"><span>$kid->{'label'}</span></a></li>\n";      
180       }
181       $tabs[$level+1] .= "  </ul></div>\n";      
182     }
183     
184     # put them in place
185     open FROM,"html/$current->{'file'}" || die;
186     my $newname="html/$current->{'file'}";
187     $newname =~ s/.html/.handlepage.html/;
188     open TO,">$newname" || die;
189 #    print "XXX Deal with html/$current->{'file'}  ->  $newname\n";
190     while (<FROM>) {
191 #      print "--Read  $_";
192       # add "current" to the module API granfather page
193       s|<li><a href="modules.html"><span>[^<]*</span></a></li>|<li class="current"><a href="modules.html"><span>Modules&nbsp;API</span></a></li>|;
194 #      print "++Write $_";
195       print TO "$_";
196       last if (m|</div>|);
197     }
198     foreach (@tabs) {
199 #      print "TAB: $_";
200       print TO "$_";
201     }
202     while (<FROM>) {
203       print TO "$_";
204     }    
205     close FROM;
206     close TO;
207     rename("$newname","html/$current->{'file'}") unless $debug{'rename'};
208   } 
209   
210   # recurse on childs
211   foreach my $entry (@{$current->{'down'}}) {
212     handle_page($entry,$level+1);
213   }
214 }
215
216 ###
217 ### Launch the modules navbar reworking
218 ###
219 handle_page($top,-2);# skip roots (we have 2 roots) in level counting
220
221
222 ###
223 ### Post-processsing common to all pages
224 ###
225 map {push @allfiles,$_} @extra_files;
226
227 foreach my $file (@allfiles) {
228     $file =~ s/.html/.handlepage.html/ if $debug{'rename'}; # Take right name if debugging
229         
230     open FROM,"$file" || die;
231     my $outfile = "$file";
232     $outfile =~ s/.(html|php)$/.new.$1/;
233     open TO,">$outfile" || die;
234 #    print "POSTPROCESSING $file (tmp=$outfile)\n";
235     while (<FROM>) {
236       # Add the simgrid css, just in case
237       print TO '<link href="simgrid.css" rel="stylesheet" type="text/css">'."\n"
238         if (m|</head>|);
239
240       # Rework the navbar
241       if (m,<li><a href="(doc/)?index.html"><span>Main\&nbsp;Page</span></a></li>,) {
242         print TO '    <li'.($file =~ m,(doc/)?index.html, ? " class='current'" :"").'><a href="'.$1.'index.html"><span>Overview</span></a></li>'."\n";
243         print TO '    <li'.($file =~ m,(doc/)?faq.html, ? " class='current'" :"").'><a href="'.$1.'faq.html"><span>FAQ</span></a></li>'."\n";
244         next;
245       }
246       if (m,<li><a href="(doc/)?annotated.html"><span>Data\&nbsp;Structures</span></a></li>,) {
247         print TO '    <li'.($file =~ m,(doc/)?publis.html, ? " class='current'" :"").'><a href="'.$1.'publis.html"><span>Publications</span></a></li>'."\n";
248         print TO '    <li'.($file =~ m,(doc/)?history.html, ? " class='current'" :"").'><a href="'.$1.'history.html"><span>History</span></a></li>'."\n";
249         next;
250       }
251       s|<span>Modules</span>|<span>Modules API</span>|g;
252 #      s|<li><a href="(doc/)?dirs.html"><span>Directories</span></a></li>||g;
253                                                                                                  
254       print TO $_;
255     }
256     close FROM;
257     close TO;
258     rename("$outfile", "$file") unless $debug{'rename'};
259 }
260
261
262