ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Utilities/urlhandler.pm
Revision: 1.1
Committed: Mon Mar 1 10:35:01 1999 UTC (26 years, 2 months ago) by williamc
Content type: text/plain
Branch: MAIN
Log Message:
Utility modules

File Contents

# Content
1 #!/usr/local/bin/perl5
2 #
3 # url handler -> returns the location of the file
4 #
5 # returns file location - or crashes out
6 # can pass a file name for the item to be stored as
7 # if not then stores in a default cache.
8
9 package urlhandler;
10 require Exporter;
11 @ISA = qw(Exporter);
12 @EXPORT = qw(urlhandler);
13
14
15 sub urlhandler($@) {
16 my $origurl=shift;
17 my $filename=shift;
18 my $rest;
19 my $type;
20 my $url;
21 my $version;
22
23 chomp $origurl;
24 # get our version info from the url (after last ??)
25 ( $url, $version) = split /\?\?/, $origurl;
26 if ( $url=~/:/ ) {
27 ($type,$rest) = split /:/, $url;
28 }
29 else {
30 $type='label';
31 $rest=$url.":".$version;
32 }
33
34 my @urltypes = qw(label file cvs);
35 foreach $ty ( @urltypes ) {
36 do { return &$ty($rest, $filename); $supported='yes'; last; }
37 if $type eq $ty;
38 }
39 if ( ! ( $supported=~/yes/ )) {
40 print "urlhandler: Unsupported type $type\n";
41 exit 1;
42 }
43 }
44 sub label {
45 my $label=shift;
46 my $filename=shift;
47 my $returnval="";
48
49 open ( LOOKUP, "$ENV{SCRAM_LOOKUPDB}" )
50 || die "urlhandler: Unable to open DataBase $ENV{SCRAM_LOOKUPDB} $!";
51 while ( <LOOKUP> ) {
52 next if /^#/;
53 if ( $_=~s/^$label\:// ) {
54 $returnval = urlhandler($_,$filename);
55 }
56 }
57 close LOOKUP;
58 return $returnval;
59
60 }
61
62 sub file {
63 use File::Copy;
64 my $urlfile=shift;
65 my $filename=shift;
66 if ( -e "$urlfile" ) {
67 if ( $filename=~/.*/ ) {
68 copy ( $urlfile, $filename ) || return $urlfile;
69 return $filename;
70 }
71 return $urlfile;
72 }
73 else {
74 print "urlhandler: Unable to find file $urlfile : $!\n";
75 exit 1;
76 }
77 }
78
79 sub cvs {
80 print "Coming soon\n";
81 }
82
83 sub cachefilename {
84 use File::Basename;
85 use AddDir;
86 my $filebase=dirname($rest);
87 $cache="/tmp/williamc/urlhandler$$";
88 adddir($cache);
89 $filename=$cache."/".$filebase;
90 }
91