tools: Use Carp

Use carp and croak instead of warn and die in library routines.
This commit is contained in:
Andrew Johnson
2011-12-05 14:56:50 -06:00
parent 7529ca7a9b
commit f207b00b05
2 changed files with 14 additions and 10 deletions

View File

@@ -7,6 +7,8 @@
# $Revision-Id$
use Carp;
# Copy directories and files from a template
sub copyTree {
@@ -15,7 +17,7 @@ sub copyTree {
# $Rtextsubs contains substitutions for file content.
opendir my $FILES, $src
or die "opendir failed while copying $src: $!\n";
or croak "opendir failed while copying $src: $!\n";
my @entries = readdir $FILES;
closedir $FILES;
@@ -36,9 +38,9 @@ sub copyTree {
print "." unless $opt_d;
copyFile($srcName, $dstName, $Rtextsubs);
} elsif (-l $srcName) {
warn "\nSoft link in template, ignored:\n\t$srcName\n";
carp "\nSoft link in template, ignored:\n\t$srcName\n";
} else {
warn "\nUnknown file type in template, ignored:\n\t$srcName\n";
carp "\nUnknown file type in template, ignored:\n\t$srcName\n";
}
}
}
@@ -46,11 +48,11 @@ sub copyTree {
sub copyDir {
my ($src, $dst, $Rnamesubs, $Rtextsubs) = @_;
if (-e $dst && ! -d $dst) {
warn "\nTarget exists but is not a directory, skipping:\n\t$dst\n";
carp "\nTarget exists but is not a directory, skipping:\n\t$dst\n";
return;
}
print "Creating directory '$dst'\n" if $opt_d;
mkdir $dst, 0777 or die "Can't create $dst: $!\n"
mkdir $dst, 0777 or croak "Can't create $dst: $!\n"
unless -d $dst;
copyTree($src, $dst, $Rnamesubs, $Rtextsubs);
}
@@ -61,7 +63,7 @@ sub copyFile {
print "Creating file '$dst'\n" if $opt_d;
open(my $SRC, '<', $src)
and open(my $DST, '>', $dst)
or die "$! copying $src to $dst\n";
or croak "$! copying $src to $dst\n";
while (<$SRC>) {
# Substitute any @VARS@ in the text
s{@(\w+?)@}

View File

@@ -7,6 +7,8 @@
# $Revision-Id$
use Carp;
#
# Parse all relevent configure/RELEASE* files and includes
#
@@ -44,7 +46,7 @@ sub readRelease {
my ($file, $Rmacros, $Rapps) = @_;
# $Rmacros is a reference to a hash, $Rapps a ref to an array
open(my $IN, '<', $file) or die "Can't open $file: $!\n";
open(my $IN, '<', $file) or croak "Can't open $file: $!\n";
while (<$IN>) {
chomp;
s/ \r $//x; # Shouldn't need this, but sometimes...
@@ -71,7 +73,7 @@ sub readRelease {
if (-e $path) {
&readRelease($path, $Rmacros, $Rapps);
} elsif ($op eq "include") {
warn "EPICS/Release.pm: Include file '$path' not found\n";
carp "EPICS/Release.pm: Include file '$path' not found\n";
}
}
close $IN;
@@ -100,9 +102,9 @@ sub expandRelease {
while (my ($macro, $val) = each %$Rmacros) {
while (my ($pre,$var,$post) = $val =~ m/ (.*) \$\( (\w+) \) (.*) /x) {
warn "EPICS/Release.pm: Undefined macro \$($var) used\n"
carp "EPICS/Release.pm: Undefined macro \$($var) used\n"
unless exists $Rmacros->{$var};
die "EPICS/Release.pm: Circular definition of macro $macro\n"
croak "EPICS/Release.pm: Circular definition of macro $macro\n"
if $macro eq $var;
$val = $pre . $Rmacros->{$var} . $post;
$Rmacros->{$macro} = $val;