Logo AND Algorithmique Numérique Distribuée

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