#!/usr/bin/perl
# URL2HTML.pl = Converts URLs and descriptions to Bulleted HTML lists.
#$ver = "v1.0"; # 25-Apr-1996 JPV
#$ver = "v1.1"; # 11-Mar-1998 JPV fixed greeting bugs
#$ver = "v1.1a"; # 19-Mar-2000 JPV Minor message changes, fixed $0 problem
#$ver = "v1.1b"; # 15-Nov-2000 JPV Bugfix for file close problem
$ver = "v2.0"; # 2003-06-25 JPV Updated code, allowed use a filter.
####################################################################################
(($myname = $0) =~ s/^.*(\/|\\)//ig); # remove up to last "\" or "/"
$Greeting = ("$myname $ver Copyright 1996-2003 JP Vossen (http://www.jpsdomain.org/)\n");
$Greeting .= (" Licensed under the GNU GENERAL PUBLIC LICENSE:\n");
$Greeting .= (" See http://www.gnu.org/copyleft/gpl.html for full text and details.\n");
if (("@ARGV" =~ /\?/) || ("@ARGV" =~ /-h/) || "@ARGV" =~ /--help/) {
print STDERR ("\n$Greeting\n\n");
print STDERR <<"EoN"; # Usage notes
Usage: $myname (-i [FILE]) (-o [FILE] | -W) (-q)
-i {infile} = Use infile as the input file, otherwise use STDIN.
-o {outfile} = Use outfile as the output file, otherwise use STDOUT.
-W = Write output to the Windows Clipboard instead of a file.
-q = Be quiet about it.
Converts tab delimited URLs and descriptions to bulleted HTML list bodies.
EoN
die ("\n");
} # end of usage
use Getopt::Std; # Use Perl5 built-in program argument handler
getopts('i:o:Wq'); # Define possible args.
if (! $opt_i) { $opt_i = "-"; } # If no input file specified, use STDIN
if (! $opt_o) { $opt_o = "-"; } # If no output file specified, use STDOUT
open (INFILE, "$opt_i") or die ("$myname: error opening '$opt_i' for input: $!\n");
if ($opt_W) { # We're sending the output directly into the Clipboard
# If output not STDOUT, then we're confused:
if ($opt_o ne "-") { die ("$myname: Can't use -o and -W at the same time!\n"); }
use Win32::Clipboard; # Import the clipboard module
use IO::File; # Import File IO (for a temp file)
# Use a secure temp file that's automatically deleted when we're finished.
$OUTFILE = IO::File->new_tmpfile || die ("$myname: error opening temp file: $!\n");
} else {
# Note use of indirect file handle (e.g. '$' on $OUTFILE), needed for temp file
open ($OUTFILE, ">$opt_o") or die ("$myname: error opening '$opt_o' for output: $!\n");
} # end of if using clipboard
if (! $opt_q) {
print STDERR ("\n$Greeting\n");
print STDERR ("Converting URLs and descriptions in $opt_i to a bulleted HTML list in $opt_o.\n");
} # end of greeting if not quiet
while ($aline = ) {
chop($aline);
if ($aline =~ /:\/\//) {
$aline = '/g; # Replace one or more TABs with middle stuff
$aline .= ""; # Append closing code
}
print $OUTFILE ("$aline\n");
} # end of while input
if ($opt_W) { # We're sending the output directly into the Clipboard
seek($OUTFILE, 0, 0) or die ("$myname: error couldn't rewind temp OUTPUT file: $!\n");
undef ($/); # Undefine the input line terminator so we grab the whole thing
my $cboard = <$OUTFILE>; # Grab it ALL
Win32::Clipboard::Set("$cboard"); # Send it to the clipboard
} # end of output to clipboard
if (! $opt_q) { print STDERR ("\n\a$myname finished in ",time()-$^T," seconds.\n"); }
##########################################################################