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

# Content
1 #
2 # Utility Routines for the SCRAM tools
3 #
4
5 package SCRAMUtils;
6 require 5.001;
7 require Exporter;
8 @ISA = qw(Exporter);
9 @EXPORT = qw(checkfile updatelookup);
10 use Carp;
11
12 sub checkfile {
13 my $filename=shift;
14 my $thisfile="";
15 $thisfile=$ENV{LOCALTOP}."/".$filename;
16 return $thisfile, if ( -e $thisfile );
17 $thisfile=$ENV{RELEASETOP}."/".$filename;
18 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 print "Searching for ".$key."\n";
36 while ( <SCRAMUPDATEFILE> ) {
37 chomp;
38 if ( $_=~/^\Q$key\E/ ) {
39 $update=1;
40 print SCRAMWORK $key.$rest."\n";
41 }
42 else {
43 print SCRAMWORK $_."\n";
44 }
45 }
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 }