blob: 6ff74aaf9bed2b9a12d0ad1e5ff317f2183a0928 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#!/usr/bin/perl
use File::Copy;
#get target directory and list the files
my $nav = $ARGV[0];
my $topdir = $ARGV[1];
my $dir = $ARGV[2];
my $outdir = $ARGV[3];
opendir $dirhandle, $dir or die "Couldn't open dir $dir: $!";
my @files = readdir $dirhandle; #list of files in $dir
closedir $dirhandle;
@files = sort(@files);
#for each .html file in the target, do:
foreach $file (@files) {
if ($file =~ /([^\/]+).html$/) {
my $infile = "$dir/$file";
my $outfile = "$outdir/$1.php";
print("$file -> $1.php\n");
open $filehandle, "<", $infile or die "Couldn't read file: $!";
open $outfile, ">", $outfile or die "Couldn't write file: $!";
while ($line = <$filehandle>) {
$line =~ s/\.html/\.php/g;
$line =~ s/\<\/?span[^\>]*?\>//g;
$line =~ /<h1>(.*?)<\/h1>/i;
$head = $1;
$line =~ s/style\=\"[^"]*\"//g;
$line =~ s/\<div/\n\<p/gi;
$line =~ s/\<\/div>//gi;
$line =~ s/<html><head><title>.*?\<table width="100%" class="header"\>/<?php\n include("$topdir\/tde-head-and-foot.php");\n doHeader("$head", "Documentation", "$nav", "$topdir\/");\n?>\n<STYLE>\n .question {font-weight:bold;}\n TD {padding-top:10px}\n<\/STYLE>\n\<table width="100%" class="header"\>/gi;
$line =~ s/<\/body><\/html>/\n<?php\n doFooter();\n?>\n/gi;
$line =~ s/[\x80-\xff]//g;
$line =~ s/h1[^\>]*?\>/h2\>/gi;
$line =~ s/\<\/div\>/\n\<\/div\>/gi;
$line =~ s/Chapter(\d+)\./Chapter $1. /gi;
print $outfile "$line\n";
}
close $filehandle;
close $outfile;
}
elsif ($file =~ /([^\/]+).png$/) {
print("copying image $file\n");
copy("$dir/$file", "$outdir/$file");
}
}
|