]> code.delx.au - gnu-emacs-elpa/blob - packages/notes-mode/mkrawindex
Merge commit '0cda39255827f283e7578cd469ae42daad9556a2' from js2-mode
[gnu-emacs-elpa] / packages / notes-mode / mkrawindex
1 #!/usr/bin/perl -w
2
3 #
4 # mkrawindex -- index notes files
5 # $Id: mkrawindex,v 1.17 2007/02/24 01:25:08 johnh Exp $
6 #
7 # Copyright (C) 1994-2006,2012 Free Software Foundation, Inc.
8 # Comments to <johnh@isi.edu>.
9 #
10 # This file is under the Gnu Public License, version 2.
11 # For details see the COPYING which accompanies this distribution.
12 #
13
14 sub usage {
15 print STDOUT <<END;
16 usage: $0 [-X] [file...]
17 Writes a raw index to stdout.
18
19 If no files are specified as arguments,
20 they are read from stdin.
21
22 Option: -X means read the filesname from stdin rather than the command line.
23
24 END
25 exit 1
26 }
27
28 # old implementation:
29 # To make an index do:
30 # ./mkrawindex /h/local/users/johnh/STUFF/NOTES/9????? |
31 # sort -f -t# +1 +0 |
32 # sed 's:/h/local/users/johnh:~:' >index
33
34 require 5.000;
35 BEGIN { unshift(@INC, $ENV{'NOTES_BIN_DIR'}); };
36 use Notes;
37 use NotesVars;
38
39 my($files_from_stdin) = undef;
40 if ($ARGV[0] eq '-X') {
41 $files_from_stdin = 1;
42 shift @ARGV;
43 }
44
45 &usage if ($#ARGV == 0 && $ARGV[0] eq '-?');
46
47 my($opthost) = "";
48 # could be localhost to have urls be file://localhost/foo instead of
49 # file:///foo.
50
51 #
52 #
53 #
54 foreach (@ARGV) {
55 &add_file_to_index($_);
56 }
57 if ($files_from_stdin) {
58 while (<STDIN>) {
59 chomp;
60 &add_file_to_index($_);
61 };
62 };
63
64 exit 0;
65
66
67 sub add_file_to_index {
68 my($fn) = @_;
69
70 # "cannonicalize" the filename
71 my($cannon_fn) = $fn;
72 if ($cannon_fn !~ m@^/@) {
73 $cannon_fn = $::notes{dir} . "/" . $cannon_fn;
74 $cannon_fn =~ s@^$::notes{home}@/~@;
75 };
76
77 my($n) = new Notes($fn);
78 my($subs_ref) = $n->subjects();
79 if (!defined($subs_ref)) {
80 warn "$0: no subjects for file $fn.\n";
81 return;
82 };
83 foreach (@$subs_ref) {
84 warn("$0: subject $_ in $fn has leading spaces.\n")
85 if (/^\s$/);
86 warn("$0: subject $_ in $fn has trailing spaces.\n")
87 if (/\s$/);
88 warn("$0: subject $_ in $fn has an embedded number sign---this will cause problems with prev/next entries.\n")
89 if (/\#/);
90 print "file://$opthost$cannon_fn#* $_\n";
91 };
92 }