Modified syntax to accept 'about' as the task mnemonic in addition to 'to'.
[remindme.git] / remindme
blob5c4eb0c66277d75e1e3538a31d6a25bc6e74aaae
1 #!/usr/bin/perl -w
2 use strict;
4 use Date::Manip;
5 use Fcntl qw(:flock);
7 my $reminders = "$ENV{HOME}/reminders/stuff";
9 my $argstring = join (" ", @ARGV);
10 my ($when, $what, $howmany);
12 (undef, $when, undef, $what, $howmany) = ($argstring =~ /^(on |)(.*?) (to|about the|about) (.*?)( for (\d+) days|)$/);
13 if ( $when =~ /^after/ ) {
14 # check for the "after n days" format.
15 # There are better ways of handling multiple regexes, but we'll do
16 # things this way since there are only two for now.
18 my $unit;
19 ($when, $unit, undef, $what, $howmany) =
20 ($argstring =~ /^after (\d+) (days|weeks|months|business days) (to|about the|about) (.*?)( for (\d+) days|)$/);
21 if( $when ) {
22 $when = DateCalc("today", "+$when $unit");
25 quit("what?") unless $what;
26 quit("when?") unless $when;
28 if( $howmany =~ /(\d+)/ ) {
29 $howmany = "+$1";
31 else {
32 $howmany = "+1";
35 # form the line to be appended
36 my $date = ParseDate($when);
37 quit("cannot parse date") unless $date;
39 my $line = UnixDate($date, "REM %b %e %Y $howmany MSG");
40 $line .= " $what %b.%\n";
42 # write in file
44 # open lock file
45 open LOCK, ">$reminders.lock" or quit("cannot open $reminders.lock : $!");
46 flock LOCK, LOCK_EX or quit("cannot obtain lock : $!");
48 # open data file, write and close data file
49 open REMINDERS, ">>$reminders" or quit("cannot open $reminders : $!");
50 print REMINDERS $line;
51 close REMINDERS;
53 # release locks
54 flock LOCK, LOCK_UN;
55 close LOCK;
57 exit (0);
59 sub quit
61 my $msg = shift;
62 print STDERR $msg, "\n";
63 exit (-1);