5 # $Id: Notes.pm,v 1.9 2010/06/20 18:31:22 johnh Exp $
7 # Copyright (C) 1996-2006,2012 Free Software Foundation, Inc.
8 # Comments to <johnh@isi.edu>.
10 # This file is under the Gnu Public License, version 2.
11 # For details see the COPYING which accompanies this distribution.
15 # A Perl module implement a notes class.
23 #----------------------------------------------------------------------
25 # my($Notes::revsion) = '$Id: Notes.pm,v 1.9 2010/06/20 18:31:22 johnh Exp $'; #' font-lock hack
26 # my($Notes::VERSION) = 1.00;
29 # optional argument: pathname to read
31 my ($class, $file) = @_;
34 $self->read_from_file($file);
44 my ($self, $filename) = @_;
48 open(FILE
, "<$filename") || croak
"Cannot open $filename";
52 my($start, $Subject) = (0, undef);
55 for ($i = 0; $i < $#lines; $i++) {
56 if ($lines[$i] =~ /^\* / &&
57 $lines[$i+1] =~ /^-+\r?$/) {
58 $self->push_entry($Subject, join("", @lines[$start .. $i-1]));
60 ($Subject) = ($lines[$i] =~ /^\*\s+(.*)\r?$/);
64 $self->push_entry($Subject, join("", @lines[$start .. $i-1]));
71 return $self->{'subjects'};
76 my($self, $Subject) = @_;
77 my($subject) = lc($Subject);
78 return wantarray ?
() : undef
79 if (!defined($self->{'entryis_by_subject'}{$subject}));
81 foreach (@
{$self->{'entryis_by_subject'}{$subject}}) {
82 push (@ret, $self->{'entries'}[$_]);
90 return $self->{'pre'};
96 my($self, $Subject, $entry) = @_;
97 if (!defined($Subject)) {
98 $self->{'pre'} = $entry;
101 my($subject) = lc($Subject);
102 push (@
{ $self->{'subjects'} }, $Subject);
103 push (@
{ $self->{'entries'} }, $entry);
104 push (@
{ $self->{'entryis_by_subject'}{$subject} }, $#{$self->{'entries'}});
111 # These inits break things. Go figure.
112 # @{ $self->{'subjects'} } = @{$self->{'entries'}} = ();
113 # %{ $self->{'entryis_by_subject'} } = ();