#! /usr/bin/perl # Inspired by src2html.pl by Mark Gaither - WebTechs. # Copyright (c) 1997-1999 by Alex Schroeder # The following variables are default values used by me -- the values # can be overridden using command line options. $docroot = '/usr/local/httpd/htdocs'; $wwwroot = 'http://localhost'; $authorhome = 'http://www.geocities.com/TimesSquare/6120/'; $authorname = 'Alex Schröder'; $authorname_nolatin = 'Alex Schroeder'; $authormail = 'a.schroeder@bsiag.ch'; $usage = 'Usage: html-address [-hdv] [-r docroot] [-w wwwroot] [-u home] [-a author] [-m mail] [file.html ...] OPTIONS -h this message -d debugging -v verbose -r docroot set new docroot -w wwwroot set new wwwroot -u home author\'s homepage directory (no html file) -a author author\'s name -b author author\'s name without latin 1 chars -m mail author\'s mail address EXAMPLES modify addresses of html files in current directory html-address modify addresses of specific files html-address bar.html foo/bar.html Address tag and content being replaced (date is the modification date of the file):
... The address tag content will contain a link to the file. This link is constructed by getting the full filename and replacing docroot by wwwroot. Therefore, you can also provide files in subdirectories -- the subdirectories will not be removed from the link: Assume the files for the web-site are stored in /home/alex/WWW. Assume the file we are modifying is /home/alex/WWW/atlantis/index.html. The way to call html-address is ./html-address -r /home/alex/WWW\ \ -w http://www.geocities.com/TimesSquare/6120 \ atlantis/index.html The script will determine the name of the file: /home/alex/WWW/atlantis/index.html, strip the docroot, giving atlantis/index.html, and prepending wwwroot, resulting in a link to the following page in the address tag: http://www.geocities.com/TimesSquare/6120/atlantis/index.html. '; require "getopts.pl"; &Getopts('hdvr:w:u:a:b:m:'); if($opt_h) { print $usage; exit; } if($opt_d) { $debug = 1; $verbose = 1; print "Debugging...\n"; } if($opt_v) { $verbose = 1; print "Verbose...\n"; } if($opt_r) { $docroot = $opt_r; print "Changed docroot to $docroot.\n" if $debug; } if($opt_w) { $wwwroot = $opt_w; print "Changed wwwroot to $wwwroot.\n" if $debug; } if($opt_u) { $authorhome = $opt_u; print "Changed authorhome to $authorhome.\n" if $debug; } if($opt_a) { $authorname = $opt_a; print "Changed authorname to $authorname.\n" if $debug; } if($opt_b) { $authorname_nolatin = $opt_b; print "Changed authorname_nolatin to $authorname_nolatin.\n" if $debug; } if($opt_m) { $authormail = $opt_m; print "Changed authormail to $authormail.\n" if $debug; } # Convert all files in the current directory if no file spec given on # the command line. if ($#ARGV < 0) { opendir(DIR,'.') || die "Can't open current directory: $!\n"; @srcfiles = grep(/\.html$/,readdir(DIR)); print "Files:\n", join("\n", @srcfiles), "\n" if $debug; close(DIR); } else { print "Files:\n" if $debug; foreach (@ARGV) { push(@srcfiles, $_); print "$_\n" if $debug; } } # Create some dates to use as Macros. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime; $mon++; $year+=1900; $current_date = sprintf '%04d-%02d-%02d', $year, $mon, $mday; # Convert each SRC file into an HTML doc foreach $srcfile (@srcfiles) { if($srcfile =~ /~$/) { print "$srcfile is a backup. Skipping...\n"; next; } # Store modification time (mtime) for the file. ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($srcfile); # Determine the time the file was last changed. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($mtime); $mon++; $year+=1900; $modification_date = sprintf '%04d-%02d-%02d', $year, $mon, $mday; # Start with a clean variable. This will hold the entire document. my $html = ''; # Read file into $html. undef $/; open(DATA, $srcfile); $original = $html = ; close(DATA); # Determine the absolute URL for this HTML file. In order to do # this, get the current directory, strip the docroot directory # from it and append it to the wwwroot string. chop($pwd = `pwd`); ($basedir = $pwd) =~ s/$docroot// ; $docURL = $wwwroot . $basedir . "/" . $srcfile; # $authorname is overwritten by $authorname_nolatin, unless the # necessary meta tag is found. This regexp could be improved, # because this doesn't match all possible ways of writing it. # Feel free to change the regexp. $authorname = $authorname_nolatin if ( $html =~ m||i ); if ( not ( $html =~ s|.*?(\d\d\d\d-\d\d-\d\d)?| $docURL / $authorname <$authormail> / updated: $modification_date / significant changes: $1|si )) { print "No address tag found in $srcfile.\n" if $verbose; next; } # Don't touch the file if nothing has changed. if ( $original eq $html ) { print "No changes in $srcfile.\n" if $verbose; next; } # Backup old HTML file. rename $srcfile, $srcfile . '~'; # Write new HTML file. open(OUT,"> $srcfile") || die "Can't write to $srcfile: $!\n"; print OUT $html; close(OUT); print "Replaced address tag in $srcfile.\n" if $verbose; }