ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Utilities/SCRAMUtils.pm
Revision: 1.7
Committed: Mon Jul 31 14:04:17 2000 UTC (24 years, 9 months ago) by williamc
Content type: text/plain
Branch: MAIN
CVS Tags: ProtoEnd
Changes since 1.6: +0 -1 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     if ( $_=~/^\Q$key\E/ ) {
39 williamc 1.1 $update=1;
40     print SCRAMWORK $key.$rest."\n";
41     }
42 williamc 1.4 else {
43 williamc 1.6 print SCRAMWORK $_."\n";
44 williamc 1.4 }
45 williamc 1.1 }
46     close SCRAMUPDATEFILE;
47     if ( $update==0 ) {
48     print SCRAMWORK $key.$rest."\n";
49     }
50     close SCRAMWORK;
51     copy "$filename.wk", $filename or croak "Unable to update file "
52     ."$filename $!\n";
53    
54     }