Added some error checking around the file input routines.

This commit is contained in:
nsj 1998-03-13 18:48:11 +00:00
parent f040d1a82f
commit 36974307af
Notes: svn2git 2020-12-08 03:00:23 +00:00
svn path=/www/; revision=2527
2 changed files with 52 additions and 10 deletions

View file

@ -1,6 +1,6 @@
#!/usr/local/bin/perl
#
# dump.pl - script to convert tab-delimited gallery db file to
# gengallery.pl - script to convert tab-delimited gallery db file to
# a section of an SGML list (not a full SGML file!) for inclusion
# into another SGML file where the <UL></UL> list element pair is
# already in existence.
@ -9,8 +9,14 @@
# where type is one of: commerical, nonprofit, personal
#
# yymmdd own comments
# ------ --- ------------------------------
# ------ --- ------------------------------------------------
# 980311 nsj First pass
# 980312 jrf Added sorting
# 980313 nsj Wrapped file input routine with error checking
# Setup
# Which sort program are we using?
$sort = "/usr/bin/sort";
# What gallery are we processing?
$type = $ARGV[0];
@ -23,16 +29,30 @@ if ($type =~ m/commercial/i) {
} else {
die "I don't understand type $type";
}
open(FOO, "sort -f $ARGV[1] |");
while (<FOO>)
# Open a pipe from a unix sort of the db file (case insensitive)
if (-f $ARGV[1])
{
$infile = $ARGV[1];
} else {
die "File $ARGV[1] is unreadable or does not exist";
}
# Open the (sorted) file
open(DBFILE, "$sort -f $infile |");
# Iterate through each line, throwing out those that don't
# go in this gallery. Output each entry as list elements.
while (<DBFILE>)
{
# We only want entries of type $type; throw the rest out.
next unless m/^$type/;
# Translate out characters special to SGML (and HTML)
s/&/&amp;/g;
s/</&lt;/g;
# Split the db line into its component parts.
($dummy, $name, $url, $description, $email, $dateadd, $datever) =
m/([^\t]+)\t([^\t]+)\t([^\t]+)\t([^\t]*)\t([^\t]+)\t([^\t]+)\t([^\t]+)/;
@ -40,4 +60,5 @@ while (<FOO>)
print "<LI><A HREF=\"$url\"><STRONG>$name</STRONG></A> -- $description</LI>\n";
};
close(FOO);
# Close the pipe like good little daemons.
close(DBFILE);