#!/usr/bin/perl #------------------------------------------------------------------------------------# # # file : reminder.pl # owner : mbaker # created : 9-27-02 # description : important dates reminder; reads a data file # #------------------------------------------------------------------------------------# use Win32; $debug = 0; # usage statement if( ( $#ARGV + 1 ) < 1 ) { print "\nusage: $0 \n"; exit; } print "\nrunning $0 ...\n\n"; # open the data file for reading open( FP, "$ARGV[0]" ) or die $!; # get current year ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # get 4-digit year $year += 1900; # days in year is 366 for leap years and 365 otherwise $days_in_year = 365; if ($year % 4 == 0) { if ($year % 100 != 0) { $days_in_year = 366; } elsif ($year % 400 ==0) { $days_in_year = 366; } } # get month for wild card dates $month = `c:\\cygwin\\bin\\date.exe +%m`; chomp( $month ); $remindmsg = ""; while( 1 ) { @record = getRecord( FP ); if( scalar( @record ) == 0 ) { if( $remindmsg ne "" ) { Win32::MsgBox( "$remindmsg", 0 | MB_ICONINFORMATION, "Important Dates Reminder" ); } last; } if( $debug ) { printRecord( @record ); } parseRecord( @record ); # replace wild card with month if( $date =~ /^\*/ ) { $date =~ s/^\*/$month/; } $date_julian = `c:\\cygwin\\bin\\date.exe -d "$date" +%j`; $today_julian = `c:\\cygwin\\bin\\date.exe +%j`; # compute days until date; scale negative results $days_until_date = $date_julian - $today_julian; if( $days_until_date < 0 ) { $days_until_date += $days_in_year; } # remind? if( $days_until_date <= $days_before_to_remind ) { $remindmsg .= "$name $printstr in $days_until_date days\n\n"; } } print "\n$0 finished\n"; exit; sub getRecord { ($fp) = @_; # start with clean storage my @record = (); while( <$fp> ) { # test for end of record delimiter if( $_ =~ /^END.*$/ ) { last; } # comment lines start with a hash; skip blank lines if( $_ =~ /^(#.*|\s*)$/ ) { next; } # extract data; trim surrounding whitespace $_ =~ /^.*:\s*(.*?)\s*$/; # store data push @record, $1; } return @record; } sub parseRecord { ($name, $date, $days_before_to_remind, $printstr) = @_; } sub printRecord { $i = 0; foreach $field (@record) { print "field[ ".( $i++ )." ] = -$field-\n"; } }