ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Utilities/SCRAMUtils.pm
(Generate patch)

Comparing COMP/SCRAM/src/Utilities/SCRAMUtils.pm (file contents):
Revision 1.3 by williamc, Thu Mar 18 10:32:04 1999 UTC vs.
Revision 1.10 by sashby, Wed Feb 15 17:14:18 2006 UTC

# Line 1 | Line 1
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);
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 <        $thifile=$ENV{LOCALTOP}."/".$filename;
39 >        $thisfile=$ENV{LOCALTOP}."/".$filename;
40          return $thisfile, if ( -e $thisfile );
41 <        $thifile=$ENV{RELEASETOP}."/".$filename;
41 >        $thisfile=$ENV{RELEASETOP}."/".$filename;
42          return $thisfile, if ( -e $thisfile );
43          return "";
44   }
# Line 28 | Line 52 | sub updatelookup {
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 <        while ( <SCRAMUPDATEFILE> ) {
55 >        local $_;
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 SCRAMWORK $key.$rest."\n";
66 >                        print $fhw $key.$rest."\n";
67                  }
68 <                print SCRAMWORK $_;
68 >                else {  
69 >                 print $fhw $_;
70 >                }
71          }
72 <
43 <        close SCRAMUPDATEFILE;
72 >        undef $fh;
73          if ( $update==0 ) {
74 <                print SCRAMWORK $key.$rest."\n";
74 >                print $fhw $key.$rest."\n";
75          }
76 <        close SCRAMWORK;
76 >        undef $fhw;
77          copy "$filename.wk", $filename or croak "Unable to update file "
78                                  ."$filename $!\n";
79 <
51 < }
79 >        }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines