]>
code.delx.au - gnu-emacs-elpa/blob - packages/notes-mode/mkall
2 # If the above path is incorrect for your system,
3 # FOLLOW THE INSTALLATION INSTRUCTIONS in README.
7 # $Id: mkall,v 1.18 2007/02/23 05:14:59 johnh Exp $
9 # Copyright (C) 1996,2012 Free Software Foundation, Inc.
10 # Comments to <johnh@isi.edu>.
12 # This file is under the Gnu Public License, version 2.
13 # For details see the COPYING which accompanies this distribution.
20 Does all reindexing needed for notes-mode.
27 BEGIN { unshift ( @INC , $ENV { 'NOTES_BIN_DIR' }); };
32 & usage
if (( $#ARGV >= 0 && $ARGV [ 0 ] eq '-?' ));
34 my ( $perl ) = & find_perl_binary
;
36 # xxx: currently rawindex generates @subjects that index uses.
37 # Should remove this dependency.
50 sub find_perl_binary
{
52 return $perl if (- x
$perl );
53 $perl = $Config { 'installbin' } . "/perl" ;
54 return $perl if (- x
$perl );
55 # If we can't find perl, then we assume the user's set the #! lines correctly.
60 sub run_over_all_notes
{
61 my ( $cmd , $user_cmd_name ) = @_ ;
62 open ( CMD
, "| $cmd " ) || die ( " $0 : cannot run $user_cmd_name . \n " );
63 foreach ( glob "$::notes{'int_glob'}/$::notes{'file_glob'}" ) {
68 die " $0 : $user_cmd_name failed." ;
77 # The main thing that happens here is we find and sort the notes entries.
78 # We do the sorting in perl because the system sort is less portable
79 # (wrt stability, for example).
82 chdir ($:: notes
{ 'dir' }) || die " $0 : cannot cd to $::notes{'dir'}. \n " ;
83 # if (-f "rawindex") {
84 # rename('rawindex', 'rawindex~') || die "$0: cannot rename rawindex.\n";
86 # my($sed_arg) = '"s@' . $::notes{home} . '@/~@"';
88 # $::notes{'bin_dir'}/mkrawindex $::notes{'dir'}/$::notes{'int_glob'}/$::notes{'file_glob'} |
90 # sed $sed_arg > rawindex
93 # rename('rawindex', 'rawindex.bad');
94 # rename('rawindex~', 'rawindex');
95 # die "$0: rawindex pipeline failed.";
98 # xxx: eventually this will overflow the buffer and we'll need to
99 # do something like xargs. However, in 10 years of use this hasn't happened
101 run_over_all_notes
( " $perl $::notes{'bin_dir'}/mkrawindex -X >prerawindex" , "mkrawindex" );
102 # open (IF, "$perl $::notes{'bin_dir'}/mkrawindex $::notes{'dir'}/$::notes{'int_glob'}/$::notes{'file_glob'} |") || die "$0: cannot run mkrawindex\n";
104 open ( IF
, "<prerawindex" ) || die " $0 : cannot open prerawindex. \n " ;
106 open ( OF
, ">rawindex+" ) || die " $0 : cannot write to rawindex+ \n " ;
108 my ( $internal_marker ) = chr ( 1 );
111 s@
$:: notes
{ 'home' } @
/~ @
;
112 my ( $left , $right ) = /^([^#]+)\#(.*)$/ ;
113 push ( @subjects , "${right}${internal_marker}${left}" );
116 @subjects = sort { uc ( $a ) cmp uc ( $b ) } @subjects ;
117 foreach ( 0 .. $#subjects ) {
118 my ( $left , $right ) = ( $subjects [ $_ ] =~ /^(.+)${internal_marker}(.*)$/ );
119 $subjects [ $_ ] = " $right # $left " ;
120 print OF
" $subjects [ $_ ] \n " ;
124 rename ( 'rawindex' , 'rawindex~' ) || die " $0 : rename rawindex{,~} failed. \n " ;
126 rename ( 'rawindex+' , 'rawindex' ) || die " $0 : rename rawindex{+,} failed. \n " ;
134 rename ( 'index' , 'index~' ) || die " $0 : rename index{,~} failed. \n " ;
136 open ( OF
, "| $perl $::notes{'bin_dir'}/mkindex > index" ) || die " $0 : cannot run mkindex. \n " ;
139 foreach ( @subjects ) {
140 if (! defined ( $last ) || $last ne uc ( $_ )) {
147 rename ( 'index' , 'index.bad' ) || warn " $0 : recovery rename index{,.bad} failed. \n " ;
148 rename ( 'index~' , 'index' ) || warn " $0 : recovery rename index{~,} failed. \n " ;
149 die " $0 : index pipeline failed." ;
156 # Yes, the code should probably be compiled,
157 # but compilation time doesn't seem to be the problem.
159 sub make_index_cache
{
160 if (- f
'index_cache.el' ) {
161 rename ( 'index_cache.el' , 'index_cache.el~' ) || die " $0 : rename index_cache.el{,~} failed. \n " ;
164 $perl $::notes{'bin_dir'}/mkindexcache < index > index_cache.el
166 # emacs -batch --eval '(byte-compile-file "index_cache.el")' 2>&1 | grep -v 'free variable'
168 rename ( 'index_cache.el' , 'index_cache.el.bad' ) || warn " $0 : reanme index_cache.el{,.bad} failed. \n " ;
169 rename ( 'index_cache.el~' , 'index_cache.el' ) || warn " $0 : rename index_cache.el{~,} failed. \n " ;
170 unlink ( 'index_cache.elc' ) if (- f
'index_cache.elc' );
171 die " $0 : index pipeline failed." ;
174 # Bug found by Klaus Zeitler <kzeitler@lucent.com>:
175 # if we generate index_cache.el in less than a second,
176 # it won't be considered up-to-date.
178 if (- M
'index' == - M
'index_cache.el' ) {
179 # We're too fast---stall and update the file
181 system ( 'touch index_cache.el' ); # "update"
190 run_over_all_notes
( " $perl $::notes{'bin_dir'}/mkprevnext -X ./rawindex" , "mkprevnext" );
196 sub make_mknew_cache
{
197 my ( $todays_file ) = & epoch_to_pathname
( time );
199 $perl $::notes{'bin_dir'}/mknew -c $todays_file >./mknew.cache
208 foreach ( glob ( "*" ), glob ( "*/*" )) {
209 my ( $mode ) = ( stat ( $_ ))[ 2 ];
211 chmod (( $mode & 0700 ), $_ ) || warn " $0 : could not chmod $_ . \n " ;