[Ident('2.0'), INHERIT ('SYS$LIBRARY:STARLET')] Program Remind(Output); { Calendar reminder program Copyright © 1989,1990,1991 Bruce Tanner - Cerritos College } { This is essentially a cut down version of Datebook that runs in the background and reminds you when there is an entry that matches the current date/time } %Include 'DBType.PAS' Const Major_Version = 2; Minor_Version = 2; Remind_1 = 10; { First warning at 10 minutes } Remind_2 = 5; { Second warning at 5 minutes } Var { Dates } Null_Date, { A constant record } Todays_Date, Load_Date: D_Type; Null_Time: T_Type; { DB_Date routines } Procedure Date_Init; Extern; Function Same_Date(Date1,Date2: D_Type): Boolean; Extern; Function Parse_Date(PL: String; W_Date: D_Type; Var R_Date: D_Type): Boolean; Extern; { DB_DB routines } Procedure DB_Init; Extern; Function First(LT: List_Type): H_Ptr; Extern; Function Next(LT: List_Type; Ptr: H_Ptr): H_Ptr; Extern; Procedure Store_Cal(T_Date: D_Type); Extern; Procedure Purge(P_List: List_Type); Extern; Procedure Make_Handle(List: List_Type; Var Rec: Cal_Rec; Key: ID_Type); Extern; { DB_FIO routines } Function Open_Calendar(Which_Cal: Whose_Cal; Index: Integer): Boolean; Extern; Procedure Load_Handles; Extern; Function List_Current: Boolean; Extern; { DB_VMS Routines } Procedure Sleep(Length: Real); Extern; Procedure Get_Today(Var Todays_Date: D_Type); Extern; Function Get_Now: Integer; Extern; Procedure Get_Directory(Var Dir: String); Extern; { DB_Str Routines } Procedure Str_Init; Extern; { ############################## } { Init tables of dates, etc. } Procedure Main_Init; Var Dir_Name: String; Ptr: H_Ptr; Did_Header: Boolean; Begin Date_Init; DB_Init; Str_Init; Get_Today(Todays_Date); Null_Date.Year := 0; { Make record type constants } Null_Date.Month := 0; Null_Date.Day := 0; Did_Header := False; If Open_Calendar(Own_Cal, -1) then Load_Handles; { Load the index pointers (handles) } If (First(C_List) = Nil) then Begin { If no entries } Load_Date := Todays_Date; Store_Cal(Todays_Date) { Load up current date's entries } End; Ptr := First(C_List); While Ptr <> Nil do Begin If (Ptr^.Start_Time = 9999) { 2.2 non-timed } or (Ptr^.Start_Time = 0000) { 2.2 or all day } then Begin If Not Did_Header then Begin Writeln('Things to do:'); Did_Header := True End; Writeln(Ptr^.Message) End; Ptr := Next(C_List, Ptr) End; End; { Main_Init } { Send a message if the terminal is receiving system messages } Procedure Display_Entry(Handle: H_Rec); Var Result: Integer; Message: Varying [100] of Char; Begin Writev(Message, Chr(7), '[Remind: ', Handle.Message, ']'); Result := $BRKTHRUW(, Message, 'SYS$OUTPUT', BRK$C_DEVICE,,,, BRK$C_USER1,,,); End; { ############################## } { Check_Loop displays those entries that match Todays_date and Now } Procedure Check_Loop; Var D_Date: String; Ptr: H_Ptr; Now_HHMM, Now_Minutes, Start_Minutes: Integer; Begin Get_Today(Todays_Date); IF Not Same_Date(Load_Date,Todays_Date) then Begin { If entries are not current } Load_Date := Todays_Date; Store_Cal(Todays_Date) { Purge old entries, load up current ones } End; Ptr := First(C_List); Now_HHMM := Get_Now; { Return minutes since midnight } Now_Minutes := (Now_HHMM DIV 100) * 60 + (Now_HHMM MOD 100); While (Ptr <> Nil) do Begin Start_Minutes := (Ptr^.Start_Time DIV 100) * 60 + (Ptr^.Start_Time MOD 100); If (Ptr^.Check in [' ','R']) { Only regular and recurr are displayed } and (Ptr^.End_Time <> 9999) { 2.2 Don't remind 'All Day' at midnight } and ((Now_Minutes + Remind_1 = Start_Minutes) or (Now_Minutes + Remind_2 = Start_Minutes) or (Now_Minutes = Start_Minutes)) then Display_Entry(Ptr^); Ptr := Next(C_List,Ptr); End; End; { Check_Loop } { ############################## } Procedure Wait_For_Update; Begin Sleep(60); If Not List_Current then Begin Purge(C_List); Purge(R_List); Load_Handles; { And load the new calendar file } Load_Date := Null_Date { 2.1 Force a reload of C_List } End End; Begin { Main } Main_Init; { Initialize everything } Repeat Wait_For_Update; { Sleep, wait for update or timeout } Check_Loop { Display messages } Until False { Forever } End. { Main }