#!/local/bin/perl

# this reminder script takes a file of events, keeps track of today's events,
# and beeps when the current time is the same as an event time
# the time is checked every minute

$inf = "appointments.txt";
open( MTGS, $inf ) or die "\t CANNOT OPEN FILE \'$inf\'\n";
($s, $mm, $hh, $dd, $m, $y, $w, $a, $i ) = localtime( time() );
while( $line = <MTGS> )
{
    @a = split " ", $line;
    $fday  = $a[1]; 
    $fhr   = $a[2];
    $fmin  = $a[3];
    if(( $fday == $dd )&&( $fhr >= $hh )&&( $fmin >= $mm ))
    { 
        push @today, $line; 
    }
}
@b = sort @today;
$c = shift @b;
@d = split " ", $c;
$month  = $d[0]; $day  = $d[1]; $hour = $d[2]; $minute  = $d[3]; $msg  = $d[4];

while( 1 )
{ 
    if(( $dd == $day )&&( $hh == $hour )&&( $mm == $minute )) 
    { 
        system "echo -en \a"; print $msg, "\n"; sleep 1;
        system "echo -en \a"; print $msg, "\n"; sleep 1;
        system "echo -en \a"; print $msg, "\n"; sleep 1;
        system "echo -en \a"; print $msg, "\n"; sleep 1;
        system "echo -en \a"; print $msg, "\n";
    last;
    }
    else
    {
        sleep( 60 ); 
        ($s, $mm, $hh, $dd, $m, $y, $w, $a, $i ) = localtime( time() );
        $c = shift @b;
        @d = split " ", $c;
        $day  = $d[1]; $hour = $d[2]; $minute  = $d[3]; $msg  = $d[4];
    }
}

