ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Utilities/SCRAMUtils.pm
Revision: 1.9
Committed: Wed Nov 15 10:20:07 2000 UTC (24 years, 5 months ago) by williamc
Content type: text/plain
Branch: MAIN
CVS Tags: V1_0_4p1, V1_0_2, V1_0_2_p1, v102p1, V1_0_1, V1_0_0, V1_pre0, SCRAM_V1, SCRAMV1_IMPORT, V0_19_7, V0_19_6, V0_19_6p1, V0_19_5, SFATEST, V0_19_4, V0_19_4_pre3, V0_19_4_pre2, V0_19_4_pre1, V0_19_3, V0_19_2, V0_19_1, V0_19_0, V0_18_5, V0_18_4, V_18_3_TEST, VO_18_3, V0_18_2, V0_18_1
Branch point for: v103_branch, V1_pre1, SCRAM_V1_BRANCH, V0_19_4_B
Changes since 1.8: +14 -13 lines
Log Message:
IMport from V0_18_0

File Contents

# Content
1 #
2 # Utility Routines for the SCRAM tools
3 #
4 # Interface
5 #
6 # dated(testfile,@dependencies) : returns 1 if testfile is older than any of its
7 # dependencies or does not exist
8
9 package SCRAMUtils;
10 require 5.001;
11 require Exporter;
12 @ISA = qw(Exporter);
13 @EXPORT = qw(checkfile updatelookup dated);
14 use Carp;
15
16 sub dated {
17 my $testfile=shift;
18 my @files=@_;
19
20 my $rv=0;
21 if ( -f $testfile ) {
22 my $time=(stat($testfile))[9];
23 foreach $file ( @files ) {
24 if ( -f $file ) {
25 if ( (stat($file))[9] > $time ) {
26 $rv=1;
27 print "$testfile is out of date relative to $file\n";
28 }
29 }
30 }
31 }
32 else { $rv=1; }
33 return $rv;
34 }
35
36 sub checkfile {
37 my $filename=shift;
38 my $thisfile="";
39 $thisfile=$ENV{LOCALTOP}."/".$filename;
40 return $thisfile, if ( -e $thisfile );
41 $thisfile=$ENV{RELEASETOP}."/".$filename;
42 return $thisfile, if ( -e $thisfile );
43 return "";
44 }
45
46 #
47 # Replace or add an entry in a hashing file
48 #
49 sub updatelookup {
50 my $filename=shift;
51 my $key=shift;
52 my $rest=shift;
53 my $update=0;
54 use File::Copy;
55
56 use FileHandle;
57 my $fhw=FileHandle->new();
58 my $fh=FileHandle->new();
59 open ( $fhw, ">".$filename.".wk" ) ||
60 die "Unable to open $filename.wk ".$!."\n";
61 $fh->open($filename);
62 #print "Searching for ".$key."\n";
63 while ( <$fh> ) {
64 if ( $_=~/^\Q$key\E/o ) {
65 $update=1;
66 print $fhw $key.$rest."\n";
67 }
68 else {
69 print $fhw $_;
70 }
71 }
72 undef $fh;
73 if ( $update==0 ) {
74 print $fhw $key.$rest."\n";
75 }
76 undef $fhw;
77 copy "$filename.wk", $filename or croak "Unable to update file "
78 ."$filename $!\n";
79 }