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
|
#!/usr/bin/perl
#
# htm2html : Rename .htm files .html and replace the HREF tags accordingly
#
# Author: Peter S. Galbraith <psg@debian.org>
# Created: 18 January 1999
# Version: 1.00 (18 January 1999)
#
# This package is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This package is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
$usage ="
NAME
htm2html : Rename .htm files .html and replace the HREF tags accordingly
Usage:
htm2html [-v] [-h] *.htm */*.htm */*/*.htm
-v : be verbose about files processed.
-h : show this help message.
-n : create FILENAME.html.new if FILENAME.html already exists
";
require "getopts.pl";
&Getopts('hnv');
die "$usage" if $opt_h;
my $newfile = 1;
while (<>) {
if ($newfile) {
if ($ARGV =~ /(.*)\.htm$/) {
if ($opt_n && -f "$1.html") {
print STDERR "File already exists: $1.html\n";
open(OUT,">$1.html.new");
} else {
open(OUT,">$1.html");
}
} else {
die "File $ARGV does not end with .htm";
}
$newfile = 0;
}
# Uncomment _one_ of the s/// expressions below:
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Replace .htm tags with .html tags
s/((HREF|SRC)=\"[^\"]+)\.htm[l]?/$1.html/gi;
#
# Replace .htm tags with .html.gz tags
# and .html tags with .html.gz
# s/((HREF|SRC)=\"[^\"]+)\.htm[l]?/$1.html.gz/gi;
# Keep all index.html uncompressed
# s/((HREF|SRC)=\"[^\"]*index\.html)\.gz/$1/gi;
# Keep all frames files uncompressed (else netscape 4.03 freezes on them)
# frm-help.htm frm-home.htm frm-srch.htm frm-toc.htm
# s/(frm-(help|home|srch|toc)\.html)\.gz/$1/g;
# Set any search-engine tag we encounter
# s|\"/cgi-bin/cgiwrap/mh/mh-index(-frames)?\"|\"http://www.ics.uci.edu/cgi-bin/cgiwrap/mh/mh-index$1/usr/doc/mh-book/html\"|;
# s|\"/cgi-bin/cgiwrap/mh/mh-index(-frames)?\"|\"http://localhost/cgi-bin/mh-book-local-index$1"|;
s|\"/cgi-bin/cgiwrap/mh/mh-index(-frames)?\"|\"/cgi-bin/mh-book-index$1\"|;
# Change the background colour
# We don't do this in V9910 because it's done in the upstream source now.
# s/<BODY>/<BODY BGCOLOR=\"\#FFFFFF\">/i;
print OUT $_;
if (eof) {
close OUT;
if ($opt_v) { print STDERR "Processed: $ARGV\n" }
$newfile = 1;
}
}
|