Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
the borland project file for stub_generator
[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 # 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 $current=$top;
42
43 print "Push $current as child of $top\n" if $debug{'parse'};
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           $current->{'label'}=$1;
83         } else {
84           die "Malformated DOXYGEN_NAVBAR_LABEL line in $current->{'file'}";
85         }
86       }
87       if (/DOXYGEN_NAVBAR_CHILD/) {
88         if (/DOXYGEN_NAVBAR_CHILD *"([^"]*)"=([^ ]*)/) {#"
89           $entry = {};
90           $entry->{'label'} = $1;
91           $entry->{'file'} = $2;
92           chomp($entry->{'file'});
93           $entry->{'up'} = $current;
94           push @{$current->{'down'}},$entry;
95         } else {
96           die "Malformated DOXYGEN_NAVBAR_CHILD line in $current->{'file'}";
97         }
98       }
99     }
100   }
101   
102   foreach my $entry (@{$current->{'down'}}) {
103     extra_info($entry);
104   }  
105 }
106 extra_info($top);
107
108 ## debug function
109 sub display {
110   my $current=shift;
111   my $level=shift;
112   print "  " x $level;
113   print "$current: ".$current->{'label'}." ($current->{'file'})\n";
114   foreach my $entry (@{$current->{'down'}}) {
115     display($entry,$level+1);
116   }
117 }
118
119 display($top,0) if $debug{'input'};
120
121 ###
122 ### Generate the navbar
123 ###
124
125 # the root deserves some special handling
126 open IN,"html/modules.html" || die;
127 open OUT,">html/modules.new.html" || die;
128 my $line;
129 while ($line = <IN>) {
130   last if $line =~ /<h1>SimGrid Modules</;
131   print OUT $line;
132 }
133
134 print OUT "<div class=\"tabs\">\n  <ul>\n";
135 foreach $current (@{ ${$top->{'down'}}[0]->{'down'} }) {
136   print OUT "   <li><a href=\"$current->{'file'}\"><span>$current->{'label'}</span></a></li>\n";
137 }
138 print OUT "  </ul></div>\n";
139 print OUT $line;
140 while (<IN>) {
141   print OUT $_;
142 }
143
144 close OUT;
145 close IN;
146 rename("html/modules.new.html","html/modules.html") unless $debug{'rename'};
147
148 # Operate the recursion
149 sub handle_page {
150   my $current=shift;
151   my $level=shift;
152
153   print "Handle $current->{'file'} at level $level\n" if $debug{'handle'};
154     
155   # we generate the tabs bottom up begining from where we are in the tree
156   # and display them top down, as it should in a file
157   my @tabs = ();
158
159   if (defined ($current->{'label'}) and $current->{'label'} ne 'ROOT') {
160 #    print "handle $current->{'file'}, at level $level\n";
161     # generate the tabs
162     my $iterator = $current;
163     my $lvl_it=$level;
164     while ($lvl_it >= 0) {
165       my $father = $iterator->{'up'};
166       $tabs[$lvl_it] = "<div class=\"tabs\">\n  <ul>\n";
167       foreach my $bro (@{$father->{'down'}}) {
168         $tabs[$lvl_it] .= "  <li".($bro==$iterator?" id=\"current\"":"")."> <a href=\"$bro->{'file'}\"><span>$bro->{'label'}</span></a></li>\n";      
169       }
170       $tabs[$lvl_it] .= "  </ul></div>\n";
171       $iterator = $father;
172       $lvl_it--;
173     }
174     if (defined $current->{'down'}) { # there's some kid. Display them too
175       $tabs[$level+1] = "<div class=\"tabs\">\n  <ul>\n";
176       foreach my $kid (@{$current->{'down'}}) {
177         $tabs[$level+1] .= "  <li> <a href=\"$kid->{'file'}\"><span>$kid->{'label'}</span></a></li>\n";      
178       }
179       $tabs[$level+1] .= "  </ul></div>\n";      
180     }
181     
182     # put them in place
183     open FROM,"html/$current->{'file'}" || die;
184     my $newname="html/$current->{'file'}";
185     $newname =~ s/.html/.new.html/;
186     open TO,">$newname" || die;
187     while (<FROM>) {
188       # add "current" to the module API granfather page
189       s|<li><a href="modules.html"><span>[^<]*</span></a></li>|<li id="current"><a href="modules.html"><span>Modules API</span></a></li>|;
190       print TO $_;
191       last if m|</ul></div>|;
192     }
193     foreach (@tabs) {
194       print TO $_;
195     }
196     while (<FROM>) {
197       print TO $_;
198     }    
199     close FROM;
200     close TO;
201     rename("$newname","html/$current->{'file'}") unless $debug{'rename'};
202 #    print "mv $newname html/$current->{'file'}\n";
203   } 
204   
205   # recurse on childs
206   foreach my $entry (@{$current->{'down'}}) {
207     handle_page($entry,$level+1);
208   }
209 }
210
211 ###
212 ### Launch the modules navbar reworking
213 ###
214 handle_page($top,-2);# skip roots (we have 2 roots) in level counting
215
216
217 ###
218 ### Post-processsing common to all pages
219 ###
220 map {push @allfiles,$_} @extra_files;
221
222 foreach my $file (@allfiles) {
223     open FROM,"$file" || die;
224     my $outfile = "$file";
225     $outfile =~ s/.(html|php)$/.new.$1/;
226     open TO,">$outfile" || die;
227 #    print "POSTPROCESSING $file (tmp=$outfile)\n";
228     while (<FROM>) {
229       # Add the simgrid css, just in case
230       print TO '<link href="simgrid.css" rel="stylesheet" type="text/css">'."\n"
231         if (m|</head>|);
232
233       # Rework the navbar
234       if (m,<li><a href="(doc/)?index.html"><span>Main\&nbsp;Page</span></a></li>,) {
235         print TO '<li><a href="'.$1.'index.html"><span>Overview</span></a></li>'."\n";
236         print TO '<li><a href="'.$1.'faq.html"><span>FAQ</span></a></li>'."\n";
237         next;
238       }
239       if (m,<li><a href="(doc/)?annotated.html"><span>Data\&nbsp;Structures</span></a></li>,) {
240         print TO '<li><a href="'.$1.'publis.html"><span>Publications</span></a></li>'."\n";
241         next;
242       }
243       s|<span>Modules</span>|<span>Modules API</span>|g;
244 #      s|<li><a href="(doc/)?dirs.html"><span>Directories</span></a></li>||g;
245                                                                                                  
246       print TO $_;
247     }
248     close FROM;
249     close TO;
250     rename("$outfile", "$file") unless $debug{'rename'};
251 }
252
253
254