forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc_cleanhtml.pl
executable file
·113 lines (86 loc) · 2.91 KB
/
doc_cleanhtml.pl
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env perl
# Time-stamp: <2002-10-25 20:17:59 barre>
#
# Clean the HTML generated by Doxygen to remove some layout quicks
#
# barre : Sebastien Barre <sebastien@barre.nom.fr>
#
# 0.1 (barre)
# - first release
use Carp;
use Getopt::Long;
use Fcntl;
use File::Find;
use strict;
my ($VERSION, $PROGNAME, $AUTHOR) = (0.1, $0, "Sebastien Barre");
$PROGNAME =~ s/^.*[\\\/]//;
print "$PROGNAME $VERSION, by $AUTHOR\n";
# -------------------------------------------------------------------------
# Defaults (add options as you want : "verbose" => 1 for default verbose mode)
my %default =
(
html => "../../../doc/html",
);
# -------------------------------------------------------------------------
# Parse options
my %args;
Getopt::Long::Configure("bundling");
GetOptions (\%args, "help", "verbose|v", "html=s");
if (exists $args{"help"}) {
print <<"EOT";
Usage : $PROGNAME [--help] [--verbose|-v] [--html path]
--help : this message
--verbose|-v : verbose (display filenames while processing)
--html path : 'path' the Doxygen generated HTML doc (default : $default{html})
Example:
$PROGNAME
EOT
exit;
}
$args{"html"} = $default{"html"} if ! exists $args{"html"};
$args{"html"} =~ s/[\\\/]*$// if exists $args{"html"};
my $os_is_win = ($^O =~ m/(MSWin32|Cygwin)/i);
my $open_file_as_text = $os_is_win ? O_TEXT : 0;
my $start_time = time();
# -------------------------------------------------------------------------
# Collect all HTML files
print "Collecting HTML files in ", $args{"html"}, "\n";
my @files;
find sub {
push @files, $File::Find::name
if -f $_ && $_ =~ /\.html$/;
}, $args{"html"};
print " => ", scalar @files, " file(s) collected in ", time() - $start_time, " s.\n";
# -------------------------------------------------------------------------
# Remove path
my $nb_files = 0;
undef $/; # slurp mode
print "Cleaning and writing...\n";
my $intermediate_time = time();
foreach my $filename (@files) {
print " $filename\n" if exists $args{"verbose"};
# Open the file, read it entirely
sysopen(HTMLFILE,
$filename,
O_RDONLY|$open_file_as_text)
or croak "$PROGNAME: unable to open $filename\n";
my $html = <HTMLFILE>;
close(HTMLFILE);
# Clean
my $has_been_cleaned = 0;
if ($html =~ s/<table width="100%" cellpadding="2" cellspacing="0" border="0">/<table class="table-md-params" cellpadding="2" cellspacing="0" border="0">/gms) {
$has_been_cleaned = 1;
}
# Write
if ($has_been_cleaned) {
++$nb_files;
sysopen(HTMLFILE,
$filename,
O_WRONLY|O_TRUNC|O_CREAT|$open_file_as_text)
or croak "$PROGNAME: unable to open destination file $filename\n";
print HTMLFILE $html;
close(HTMLFILE);
}
}
print " => $nb_files file(s) processed and written in ", time() - $intermediate_time, " s.\n";
print "Finished in ", time() - $start_time, " s.\n";