ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Utilities/SCRAMUtils.pm
Revision: 1.6
Committed: Mon Jul 31 12:37:20 2000 UTC (24 years, 9 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.5: +4 -2 lines
Log Message:
fix lookup problem

File Contents

# User Rev Content
1 williamc 1.1 #
2     # Utility Routines for the SCRAM tools
3     #
4    
5     package SCRAMUtils;
6 williamc 1.2 require 5.001;
7 williamc 1.1 require Exporter;
8     @ISA = qw(Exporter);
9     @EXPORT = qw(checkfile updatelookup);
10     use Carp;
11    
12 williamc 1.3 sub checkfile {
13 williamc 1.1 my $filename=shift;
14     my $thisfile="";
15 williamc 1.5 $thisfile=$ENV{LOCALTOP}."/".$filename;
16 williamc 1.1 return $thisfile, if ( -e $thisfile );
17 williamc 1.5 $thisfile=$ENV{RELEASETOP}."/".$filename;
18 williamc 1.1 return $thisfile, if ( -e $thisfile );
19     return "";
20     }
21    
22     #
23     # Replace or add an entry in a hashing file
24     #
25     sub updatelookup {
26     my $filename=shift;
27     my $key=shift;
28     my $rest=shift;
29     my $update=0;
30     use File::Copy;
31    
32     open ( SCRAMWORK, ">$filename.wk" ) or
33     croak "Unable to open $filename.wk ".$!."\n";
34     open ( SCRAMUPDATEFILE, $filename );
35 williamc 1.4 print "Searching for ".$key."\n";
36 williamc 1.1 while ( <SCRAMUPDATEFILE> ) {
37 williamc 1.6 chomp;
38     print $_."\n".$key."\n\n";
39     if ( $_=~/^\Q$key\E/ ) {
40 williamc 1.1 $update=1;
41     print SCRAMWORK $key.$rest."\n";
42     }
43 williamc 1.4 else {
44 williamc 1.6 print SCRAMWORK $_."\n";
45 williamc 1.4 }
46 williamc 1.1 }
47     close SCRAMUPDATEFILE;
48     if ( $update==0 ) {
49     print SCRAMWORK $key.$rest."\n";
50     }
51     close SCRAMWORK;
52     copy "$filename.wk", $filename or croak "Unable to update file "
53     ."$filename $!\n";
54    
55     }