-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathhtmlcat
More file actions
62 lines (55 loc) · 1.17 KB
/
htmlcat
File metadata and controls
62 lines (55 loc) · 1.17 KB
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
#!/usr/local/bin/perl
#
# Arnaud Le Hors - lehors@w3.org
# $Id: htmlcat,v 1.4 2006-10-09 18:55:52 ihickson Exp $
$PROGNAME = substr($0, rindex($0, "/") + 1);
if (!$ARGV[0]) {
print "Usage: $PROGNAME output file1 file2 ...\n";
exit 1;
}
open(OUTPUT, "> $ARGV[0]");
shift;
# copy file in memory
sub readfile {
$buf = "";
if (!open(INPUT, $_[0])) {
print STDERR "$PROGNAME Error: Cannot open file: $_[0]\n";
return;
}
while (<INPUT>) {
$buf .= $_;
}
close(INPUT);
}
# 1st file: take everything up to the body end tag or the end otherwise
readfile($ARGV[0]);
$_ = $buf;
if (/<\/body>/sio) {
print OUTPUT $`;
} else {
print OUTPUT $buf;
}
shift;
# then for each other given html file only take the body content
foreach $file (@ARGV) {
readfile($file);
# look for the beginning of the body content
$_ = $buf;
if (/<body>(.*)/sio) {
$buf = $1;
} elsif (/<\/head>/sio) {
$buf = $';
}
# look for the end of the body content
$_ = $buf;
if (/<\/body>/sio) {
print OUTPUT $`;
} elsif (/<\/html>/sio) {
print OUTPUT $`;
} else {
print OUTPUT $buf;
}
}
# close body
print OUTPUT "</body>\n";
close(OUTPUT);