Logo AND Algorithmique Numérique Distribuée

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