#!/home/rebelsky/perl/bin/perl
#Contains a utility for parsing and storing the data from an annotation 
#file
#(POD documentation at end)

##################
# Package Begins #
##################
#Package ID
package AFile;
use Exporter ();
@ISA = (Exporter);
@EXPORT = qw(readFile);

#import modules
use Network;

###########################################################################
# readFile #
###########################################################################
# Opens an annotation file and stores the data found within in a hash
# ARGUMENTS: A typeglob that will act as a reference to a hash and the 
# address of the annotation file in string form
# RETURNS: Returns 1 to say that it ran correctly
###########################################################################
sub readFile 
  {
    #read in arguments
    local(*data) = shift;       #hash to store info from annotation file
    my $file = shift;           #the address of the annotation file
    #other variables
    my @info;                   #contents of annotation file in array form
    my $localtime;              #the local time
    my $info;                   #contents of annotation file in string form
    
    #open annotation file and extract info
    $info = readInFile($file);
    @info = split(/^/m,$info);

    #parse and store info
    chomp($data{'author'} = $info[0]);
    chomp($data{'email'} = $info[1]);
    chomp($localtime = $info[2]);
    $data{'date'}= substr($localtime,1,6);
    $data{'time'}= substr($localtime,8);
    $data{'title'} = $info[3];
    $info = "@info";
    $info =~ s/\n//gi;
    $info =~ /(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)/i;
    chomp($data{'annotated_text'} = $2);
    chomp($data{'annotation'} = $3);
    chomp($data{'context'} = $4);
    chomp($data{'times'} = $5);
    chomp($data{'protection'} = $6);

    $data{'file'} = $file;

    #unescape vertical bars in the hash
    foreach $item (keys(%data))
      {
        $data{$item} =~ s/%7C/\|/sig;
      }#foreach $item (keys(%data))
    
    #return the true value to show that it ran correctly
    return 1;
  }                             #sub readFile

#return the true value
return 1;

#####################
# Pod Documentation #
#####################
=pod

=head1 ID

=over 4

=item Package

AFile.pm (previously known as Annotation.pm)

=item Author

Rachel Heck

=item Description

Contains a utility for parsing and storing the data from an annotation 
file.

=back

=head1 Subroutines

=over 4

=item readFile

Opens an annotation file and stores the data found within in a hash

=back

=head1 History

=over 4

=item [9 July 1999]

readFile is working and fully commented

=item [12 July 1999]

readFile now reads in the protection line in the annotation file.

=item [13 July 1999]

Uses the networked database.

=item [14 July 1999]

Fixed a bug in readFile subroutine.  The time and date are now read out 
correctly.

=item [16 July 1999]

The package name has changed from Annotation.pm to AFile.pm.

=item [28 July 1999]

Replaces the escaped uri characters from the annotation file.

=item [30 July 1999]

Now it must only unescape the vertical bar character instead of all uri 
special characters.

=back

=cut

