Logo AND Algorithmique Numérique Distribuée

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