source: gsdl/tags/start/gsdl/perllib/arcinfo.pm@ 18481

Last change on this file since 18481 was 4, checked in by sjboddie, 26 years ago

Initial revision

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.1 KB
Line 
1# This module stores information about the archives. At the moment
2# this information just consists of the file name (relative to the
3# directory the archives information file is in) and its OID.
4
5# This module assumes there is a one to one correspondance between
6# a file in the archives directory and an OID.
7
8
9package arcinfo;
10
11sub new {
12 my ($class) = @_;
13 my $self = {'info'=>{}};
14
15 return bless $self, $class;
16}
17
18sub load_info {
19 my $self = shift (@_);
20 my ($filename) = @_;
21
22 $self->{'info'} = {};
23
24 if (-e $filename) {
25 open (INFILE, $filename) ||
26 die "arcinfo::load_info couldn't read $filename\n";
27
28 my ($line, @line);
29 while (defined ($line = <INFILE>)) {
30 $line =~ s/\cM|\cJ//g; # remove end-of-line characters
31 @line = split ("\t", $line); # filename,
32 if (scalar(@line) >= 2) {
33 $self->add_info ($line[0], $line[1]);
34 }
35 }
36
37 close (INFILE);
38 }
39}
40
41sub save_info {
42 my $self = shift (@_);
43 my ($filename) = @_;
44
45 my ($OID);
46
47 open (OUTFILE, ">$filename") ||
48 die "arcinfo::save_info couldn't write $filename\n";
49
50 foreach $OID (keys(%{$self->{'info'}})) {
51 my $info = $self->get_info($OID);
52 if (defined $info) {
53 print OUTFILE "$OID\t", join("\t", @$info), "\n";
54 }
55 }
56
57 close (OUTFILE);
58}
59
60sub add_info {
61 my $self = shift (@_);
62 my ($OID, $doc_file) = @_;
63
64 $self->{'info'}->{$OID} = [$doc_file];
65}
66
67# returns a list of the form [[OID, doc_file], ...]
68sub get_OID_list {
69 my $self = shift (@_);
70
71 my ($OID);
72 my @list = ();
73
74 foreach $OID (sort(keys(%{$self->{'info'}}))) {
75 push (@list, [$OID, $self->{'info'}->{$OID}->[0]]);
76 }
77
78 return \@list;
79}
80
81# returns a list of the form [[doc_file, OID], ...]
82sub get_file_list {
83 my $self = shift (@_);
84
85 my ($OID);
86 my @list = ();
87
88 foreach $OID (sort(keys(%{$self->{'info'}}))) {
89 push (@list, [$self->{'info'}->{$OID}->[0], $OID]);
90 }
91
92 return \@list;
93}
94
95
96# returns a list of the form [doc_file]
97sub get_info {
98 my $self = shift (@_);
99 my ($OID) = @_;
100
101 if (defined $self->{'info'}->{$OID}) {
102 return $self->{'info'}->{$OID};
103 }
104
105 return undef;
106}
107
108
1091;
110
Note: See TracBrowser for help on using the repository browser.