#!/usr/local/bin/perl
###########################################################################
# Program:       pix2web
# Version:       1.0
# Revisions:     None, yet.
# Description:   Perl script to take uuencoded picture files as input,
#                decode them, and generate a web page of them.  Will work on
#                any pic formats, but your browser may not be able to
#                view them.
# Requirements:  pix2web was written on a Sun running 4.1.3_U1 and perl5.
#                I know it runs on perl5 and perl4pl36.
#                I think it will require minimal tweaking on other platforms.
# Author:        Matt Leonard
#                mattl@pobox.com
#                http://www.pobox.com/~mattl
# Comments:      If you accept all the defaults, pix2web will assume that
#                you are in the same directory as your pix, and that you
#                want the web page there too.  Also, the links will be rel-
#                ative to "." and thus not particularly portable (or very
#                portable depending on how you look at it).
#                Also, if you don't have uuexplode, you oughta.
# Copyright:     This program is copyright 1995-1997 Matt Leonard.
###########################################################################

system "tput clear";
print "\nPix to Web\n\n";

# get picture directory
print "Enter directory where pictures reside [.]:\n";
chop($Pic_Dir=<STDIN>);
$Pic_Dir || ($Pic_Dir = ".");

# get html target directory
print "Enter directory in which to put html file [.]:\n";
chop($Html_Dir=<STDIN>);
$Html_Dir || ($Html_Dir = ".");

# get html file name
print "Enter the html filename [pix.html]: \n";
chop($Html_File = <STDIN>);
$Html_File || ($Html_File = "pix.html");

open(HTMLFILE, "> $Html_Dir/$Html_File") ||
	die "Couldn't open $Html_Dir\/$Html_File, aborting: $!\n";

# rather than jump through hoops to figure out your name and email
# address, just ask for it. Note that the default is not a good addr.
print "Enter your complete email address: [nobody\@nowhere.non]\n";
chop($Email_Addr= <STDIN>);
$Email_Addr || ($Email_Addr = "nobody\@nowhere.non");

print "Are the pix encoded? [y]:\n";
chop($Answer = <STDIN>);
$Answer || ($Answer = "y");
if ($Answer =~ /^[yY]$/) {
	print "Enter your uudecoder: [uuexplode]\n";
	chop($Uudecoder= <STDIN>);
	$Uudecoder || ($Uudecoder = "uuexplode");
	# change the above line if you want a different default decoder (uudecode)

	system "tput clear";
	print "\nPix to Web--Decoding files...\n\n";
	
	# $Uudecoder all files in $Pic_Dir, then remove encoded files
	chdir("$Pic_Dir") ||
		die "Couldn't cd to $Pic_Dir, aborting: $!\n";
	foreach $Filename (<*>) {
		# leave out the html file
		if ($Filename ne "$Html_File") {
			if (!system "$Uudecoder $Filename") {
				# only remove the file if it was decoded
				unlink($Filename);
			} # if
		} # if
	} # foreach
} # if

system "tput clear";
print "\nPix to Web--Creating web page...\n\n";

# put in html "header" info
print HTMLFILE "<html>\n<head>\n<title>Pics</title>\n";
print HTMLFILE "<link rev = \"made\" href=\"mailto:$Email_Addr\">\n";
print HTMLFILE "</head>\n<body>\n<h1>Pics</h1>\n<p>\n\n";

# put in pix entries
# remember, we're already in $Pic_Dir
foreach $Filename (<*>) {
	# leave out the html file
	if ($Filename ne "$Html_File") {
		print HTMLFILE "<img src=\"$Pic_Dir\/$Filename\">";
		print HTMLFILE "$Filename\n<p>\n\n";
	} # if
} # foreach

# put in html "trailer" info
print HTMLFILE "<hr align=center width=\"75%\">\n";
print HTMLFILE "This page was created by pix2web.<br>\n";
print HTMLFILE "For the latest version and information\n";
print HTMLFILE "(and lots of other neat stuff), click\n";
print HTMLFILE "<a href=\"http://www.pobox.com/~mattl\">here</a>\n<br>\n";
print HTMLFILE "</body>\n</html>";
close HTMLFILE;

print "Created $Html_Dir\/$Html_File\n";
print "\nPix to Web--Done.\n\n";
