Revision: | 1.5.2.1 |
Committed: | Fri Apr 7 08:22:53 2000 UTC (25 years, 1 month ago) by williamc |
Content type: | text/plain |
Branch: | V0_9branch |
CVS Tags: | V0_14_0, V0_12_12_4, V0_12_12_3, V0_13_3, V0_13_2, V0_12_12_2, V0_12_12_1, V0_12_12_0, PlayGround_0, V0_13_1, V0_13_0, V0_12_12, V0_12_11, V0_12_9b, V0_12_10, V0_12_9, V0_12_8, V0_12_7, V0_12_6, V0_12_5, V0_12_4, V0_12_3, V0_12_2, V0_12_1, V0_12_0, V0_11_4, V0_11_3, V0_11_2, V0_11_1, V0_11_0 |
Branch point for: | HPWbranch |
Changes since 1.5: | +25 -1 lines |
Log Message: | Add dated function |
# | User | Rev | Content |
---|---|---|---|
1 | williamc | 1.1 | # |
2 | # Utility Routines for the SCRAM tools | ||
3 | # | ||
4 | williamc | 1.5.2.1 | # Interface |
5 | # | ||
6 | # dated(testfile,@dependencies) : returns 1 if testfile is older than any of its | ||
7 | # dependencies or does not exist | ||
8 | williamc | 1.1 | |
9 | package SCRAMUtils; | ||
10 | williamc | 1.2 | require 5.001; |
11 | williamc | 1.1 | require Exporter; |
12 | @ISA = qw(Exporter); | ||
13 | williamc | 1.5.2.1 | @EXPORT = qw(checkfile updatelookup dated); |
14 | williamc | 1.1 | use Carp; |
15 | williamc | 1.5.2.1 | |
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 | williamc | 1.1 | |
36 | williamc | 1.3 | sub checkfile { |
37 | williamc | 1.1 | my $filename=shift; |
38 | my $thisfile=""; | ||
39 | williamc | 1.5 | $thisfile=$ENV{LOCALTOP}."/".$filename; |
40 | williamc | 1.1 | return $thisfile, if ( -e $thisfile ); |
41 | williamc | 1.5 | $thisfile=$ENV{RELEASETOP}."/".$filename; |
42 | williamc | 1.1 | 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 | open ( SCRAMWORK, ">$filename.wk" ) or | ||
57 | croak "Unable to open $filename.wk ".$!."\n"; | ||
58 | open ( SCRAMUPDATEFILE, $filename ); | ||
59 | williamc | 1.4 | print "Searching for ".$key."\n"; |
60 | williamc | 1.1 | while ( <SCRAMUPDATEFILE> ) { |
61 | if ( $_=~/^\Q$key\E/o ) { | ||
62 | $update=1; | ||
63 | print SCRAMWORK $key.$rest."\n"; | ||
64 | } | ||
65 | williamc | 1.4 | else { |
66 | print SCRAMWORK $_; | ||
67 | } | ||
68 | williamc | 1.1 | } |
69 | close SCRAMUPDATEFILE; | ||
70 | if ( $update==0 ) { | ||
71 | print SCRAMWORK $key.$rest."\n"; | ||
72 | } | ||
73 | close SCRAMWORK; | ||
74 | copy "$filename.wk", $filename or croak "Unable to update file " | ||
75 | ."$filename $!\n"; | ||
76 | |||
77 | } |