]>
code.delx.au - gnu-emacs-elpa/blob - packages/notes-mode/NotesVars.pm
5 # $Id: NotesVars.pm,v 1.8 2003/05/23 16:26:22 johnh Exp $
7 # Copyright (C) 1996,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.
17 # basic initialization
20 no strict
'vars'; # avoid %::notes
21 $notes{'home'} = ((getpwuid($<))[7]);
22 my(@config) = `"$ENV{'NOTES_BIN_DIR'}/mkconfig" perl`;
23 die "$0: mkconfig failed\n" if ($#config == -1);
24 eval join("", @config);
25 unshift(@INC, $notes{'bin_dir'});
33 @EXPORT = qw(pathname_to_Ymd Ymd_to_epoch
34 pathname_to_epoch epoch_to_pathname
39 use POSIX
qw(strftime);
46 ## Because "use POSIX" is so slow, I wrote a standalone strftime program.
47 ## I'm not distributing it because mknew caching seems to solve this problem.
50 #my($strftime_inited) = 0;
53 # # We currently don't support an external strftime.
54 # if (-x "$::notes{'bin_dir'}/strftime" ) {
57 # sub strftime_backend {
58 # my($output) = `> .$::notes{'bin_dir'} .
59 # q</strftime '$_[0]' $_[1]`;
66 # # This option is about 10 times slower to load.
67 # # Unfortunately eval'ing this code causes perl5.002
71 # sub strftime_backend {
72 # return POSIX::strftime($_[0],localtime($_[1])) ;
77 # $strftime_inited = 1;
81 # &init_strftime() unless ($strftime_inited);
82 # return &strftime_backend(@_);
86 return POSIX
::strftime
($_[0], localtime($_[1]));
91 # NEEDSWORK: not general (assumes file_form is %y%m%d)
92 my($Y, $m, $d) = ($pathname =~ /(..)(..)(..)$/);
93 $Y += 1900 if ($Y >= 90 && $Y < 100);
94 $Y += 2000 if ($Y < 90 && $Y < 100);
100 $y -= 1900 if ($y > 1000); # convert possible $Y to $y
101 return timelocal
(0, 0, 12, $d, ($m-1), $y);
104 sub pathname_to_epoch
{
106 my($Y, $m, $d) = &pathname_to_Ymd
($pathname);
107 return &Ymd_to_epoch
($Y, $m, $d);
110 sub epoch_to_pathname
{
112 return strftime_epoch
("$::notes{dir}/$::notes{int_form}/$::notes{file_form}", $epoch);
115 sub url_to_pathname
{
117 $url =~ s@
^file
:///@@
;
118 my($home) = $::notes
{home
};
119 $url =~ s@
^\
~@
${home
}@
;
120 $url =~ s@\#\
* .*$@@
;