]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/notes-mode/NotesIndex.pm
Add notes-mode.
[gnu-emacs-elpa] / packages / notes-mode / NotesIndex.pm
diff --git a/packages/notes-mode/NotesIndex.pm b/packages/notes-mode/NotesIndex.pm
new file mode 100644 (file)
index 0000000..aead72c
--- /dev/null
@@ -0,0 +1,100 @@
+#!/usr/bin/perl
+
+#
+# NotesIndex.pm
+# $Id: NotesIndex.pm,v 1.3 2003/05/23 16:26:19 johnh Exp $
+#
+# Copyright (C) 1996 by John Heidemann.
+# Comments to <johnh@isi.edu>.
+#
+# This file is under the Gnu Public License, version 2.
+# For details see the COPYING which accompanies this distribution.
+#
+
+#
+# A Perl module implement a notes-index class. 
+#
+
+package NotesIndex;
+use Carp;
+use strict;
+
+require 5.000;
+$Notes::revsion = '$Id: NotesIndex.pm,v 1.3 2003/05/23 16:26:19 johnh Exp $';
+$Notes::VERSION = 1.00;
+
+=head1 NAME
+
+NotesIndex - a simple class for notes-index files
+
+=head1 Public Methods
+
+new, read_from_file, subjects, by_subject, prelude
+
+=cut
+#' # font-lock hack
+
+#----------------------------------------------------------------------
+
+
+# public method
+sub new {
+    my ($class, $file) = @_;
+    my $self = bless {};
+    if (!defined($file)) {
+        $self->init();
+    } else {
+       $self->read_from_file($file);
+    };
+    return $self;
+}
+
+
+# public method
+sub read_from_file {
+    my ($self, $filename) = @_;
+
+    $self->init();
+
+    open(FILE, "<$filename") || croak "Cannot open $filename";
+
+    while (<FILE>) {
+       chomp;
+       $self->push_link($_);
+    }; 
+
+    close FILE;
+    return 1;
+}
+
+# public_method
+sub subjects {
+    my($self) = @_;
+    return keys %{$self->{'links_by_subject'}};
+}
+
+# public method
+sub by_subject {
+    my($self, $subject) = @_;
+    $subject = lc($subject);
+    my($resref) = $self->{'links_by_subject'}{$subject};
+    return wantarray ? () : undef
+       if (!defined($resref));
+    return wantarray ? @$resref : 1;
+}
+
+
+# private method
+sub push_link {
+    my($self, $link) = @_;
+    my($subject) = ($link =~ m/\d{2}\#\* (.*)$/);
+    $subject = lc($subject);
+    push (@{ $self->{'links_by_subject'}{$subject} }, $link);
+}
+
+
+# private method
+sub init {
+    my($self) = @_;
+}
+