#!/usr/bin/perl -sw # jac, 27 / 02 / 2004 use strict; our ($a,$d,$h); our $gap ||= 7; # days to look ahead our $dir ||= "$ENV{HOME}/.upcoming_events"; # events directory die "Usage: upcoming [OPTION] Show upcoming events as stored in files -a add event to list -d debug mode -dir=PATH directory to search events in -gap=days days to look ahead -h display this help " if $h; chdir $dir || die "could not change to '$dir' ($!)\n"; if ($a) { # adding an event # parameters my $type = shift || die "you must provide an event type\n"; my $date = shift || die "you must provide a date\n"; $date =~ /^\d+\/\d+(?:\/\d\d\d\d)?$/ || die "invalid date\n"; my $event = join " ", @ARGV; $event || die "you must provide an event\n"; # writing the event open (F,">>$type") || die "could not open '$type' ($!)\n"; print F "$date\t$event\n" || die "could not write '$type' ($!)\n"; close(F); print "added $event ($date) to $type\n"; # done exit; } if ((localtime(time))[8] ne (localtime(time+$gap*24*60*60))[8]) { print "TIME CHANGE COMING!\n\n"; # daylight savings time } # allowed dates my (@accept,%gap); for (0..$gap) { my @date = (localtime(time+$_*24*60*60))[3,4,5]; my $regex = "(?:0?" . ($date[1] + 1) . "/| )0?" . $date[0] . "(?:/".($date[2] + 1900) . ")? "; push @accept, $regex; $gap{$regex} = $_; #debug("$regex in $_ days"); } my %sig = ( 0 => ' ===>', 1 => ' -->', 2 => ' -->', 3 => ' -->', 4 => '-->', 5 => '->', 6 => '>', 7 => ' ', ); my %gap2; for (<*>) { # each file open (F,$_) || die "could not open '$dir/$_' ($!)\n"; my @lines = grep {! /^#/} ; close (F); my @events = grep { # find near events my $r = 0; for my $a (@accept) { #debug("Matching '$_' with '$a'"); if (/^$a/) { chomp; $gap2{$_} = $gap{$a}; #debug("'$_' -> $gap{$a}"); $r++ && last; #debug("Matched '$_' with '$a'"); } } $r } @lines; @events = map { my $a = $_ ; s#^.....(?!/)#$&\t# ; $gap2{$_} = $gap2{$a} ; $_ } sort @events; if (@events) { # show near events print "upcoming $_\n"; for (@events) { print ($sig{$gap2{$_}} || "($gap2{$_})"); debug("just tried to find '$_'"); print "\t$_\n" } print "\n"; } } # debug sub debug { for (@_) { print "\nDEBUG: $_\n" if $d } } __END__ =head1 NAME I - display upcoming events =head1 SYNOPSIS I [OPTION] [-a event_type date event] =head1 DESCRIPTION I displays events upcoming in the next N days =head1 WHAT YOU SHOULD KNOW The purpose for this script is to store events and notify you about the upcoming ones (or the ones that have passed). An event is of one of the following forms: =over 2 =item I<02/27 I implemented this script (2004)> =item I<02/27/2009 five years have passed since I implemented this script> =back The first one states that on February 27th (or in the vicinity of) I should be notified that C (note that the C<(2004)> part is part of the text; it is there only for reference purposes). The second one states that on February 27th of 2009 I should be notified that C. =head2 EVENT TYPES Events can be stored in different files. The name of the file describes the type of the event (birthdays, deadlines, past events, etc). =head2 ONCE THEY ARE HISTORY... Events such as C<02/26/2004 deadline for the script to be completed> can't hurt you. You are only notified of upcoming events (the ones without an year reference or with a current or future year). Past events don't hurt you (no, you shouldn't have any performance issues... unless you have thousands of events, maybe...). You can keep those past events in the file, since you can always use them for future reference (you can see, for instance, the history of deadlines for a given conference). =head1 USAGE upcoming [-d | -h] [-gap=N] [-dir=PATH] [-a event_type date event] =head1 OPTIONS =head2 -a Add an event =head2 -d Debug mode =head2 -dir Specify a different directory to search events in =head2 -gap Specify a different gap (days to look ahead) =head2 -h Display help and exit =head1 BUG REPORT / COMMENTS / SUGESTIONS All of this should be send to the author, at his current e-mail address (see section below). =head1 AUTHOR Jose' Alves de Castro =cut