Algorithmique Numérique Distribuée Public GIT Repository
567b95a1a62c3ab82e52e65c0a8bb4593cf2d668
1 #!/usr/bin/perl -w
3 (\$#ARGV >= 2) or die "Usage: index_php.pl <input-php.in-file> <input-html-file> <output-php-file>";
5 my(@toc);
6 my(\$level,\$label,\$name);
8 \$inputphp  = \$ARGV[0];
9 \$inputhtml  = \$ARGV[1];
10 \$output = \$ARGV[2];
12 my(\$onglets) = "";
13 my(\$body) = "";
15 open FILE,\$inputhtml;
16 while(defined(\$line=<FILE>)) {
17     if(\$line =~/<div class="tabs">/) {
18         \$onglets = \$line;
19         while(defined(\$line=<FILE>) && !(\$line =~/<\/div>/)) {
20             \$onglets.=\$line;
21         }
22         \$onglets.=\$line;
23         \$onglets.="<center></center><p><br>\n"
24     }
25     if(\$line =~/<!-- ______BODY_BEGIN______ --!>(.*)\$/) {
26         \$tmp=\$1;
27         if(\$tmp =~/(.*)<!-- ______BODY_END______ --!>/) {
28             \$body .= \$1;
29         } else {
30             \$body .= \$tmp;
31             while(defined(\$line=<FILE>) && !(\$line =~/<!-- ______BODY_END______ --!>/)) {
32                 \$body.=\$line;
33             }
34             \$line =~/^(.*)<!-- ______BODY_END______ --!>/;
35             \$body.=\$1;
36         }
37     }
38 }
39 close FILE;
41 # (?!http) : A zero-width negative look-ahead assertion.
42 # For example "/foo(?!bar)/" matches any occurrence of "foo" that isnâ€™t followed by "bar".
44 \$onglets =~ s/href=\"(?!http)/href=\"doc\//gi;
45 \$onglets =~ s/src=\"(?!http)/src=\"doc\//gi;
47 \$body =~ s/href=\"(?!http)/href=\"doc\//gi;
48 \$body =~ s/src=\"(?!http)/src=\"doc\//gi;
50 open FILE,\$inputphp;
51 open OUTPUT,"> \$output";
53 while(defined(\$line=<FILE>)) {
54     chomp \$line;
55     if(\$line =~/______ONGLETS______/) {
56         \$line =~ s/______ONGLETS______/\$onglets/g;
57     } elsif(\$line =~/______BODY______/) {
58         \$line =~ s/______BODY______/\$body/g;
59     }
60     print OUTPUT "\$line\n";
61 }
63 close(FILE);
64 close(OUTPUT);