Logo AND Algorithmique Numérique Distribuée

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