Unit AlarmU;



interface

{***************************************************************************}

{***************************************************************************}

Procedure AlarmList;

Procedure AlarmLoad;

Procedure AlarmSet;

Procedure HelpMenu;

Procedure Main;

Procedure WindowEnter;

Procedure WindowExit;



implementation

{***************************************************************************}

{***************************************************************************}

uses

  Crt,

  Dos,

  Globals,

  Subprogs;



const

  AlarmFile = 'ALARM.DAT';

  MaxC = 10;

  WildNum = 99;



var

  AF: text;

  C: integer;

  alpha: integer;

  Year,

  Month,

  Day,

  Hour,

  Min,

  Sec: word;

  AYear,

  AMonth,

  ADay,

  AHour,

  AMin,

  ASec: array[1..MaxC] of word;

  AMessage: array[1..MaxC] of string;

  SaveX,

  SaveY: byte;

  OldSec: word;



Procedure WindowEnter;

{***************************************************************************}

begin

  Window(1, 3, 80, 25);

  GotoXY(SaveX, SaveY);

end;



Procedure WindowExit;

{***************************************************************************}

begin

  SaveX := WhereX;

  SaveY := WhereY;

  Window(1, 1, 80, 25);

end;



Procedure AlarmSet;

{***************************************************************************}

var

  Year,

  Month,

  Day,

  Hour,

  Min,

  Sec: word;

  YearS,

  MonthS,

  DayS,

  HourS,

  MinS,

  SecS: string;

  Message: string;

begin

  WindowEnter;

  repeat

    write('Year (1990 - 9999) [99]:  ');

    readln(YearS);

    Year := IntStr(YearS);

    if YearS = '' then

      Year := 99;

  until ((Year>=1990) and (Year < 9999)) or (Year = 99);

  repeat

    write('Month (1 - 12) [99]:  ');

    readln(MonthS);

    Month := IntStr(MonthS);

    if MonthS = '' then

      Month := 99;

  until ((Month >= 1) and (Month <= 12)) or (Month = 99);

  repeat

    write('Day (1 - 31) [99]:  ');

    readln(DayS);

    Day := IntStr(DayS);

    if DayS = '' then

      Day := 99;

  until ((Day >= 1) and (Day <= 31)) or (Day = 99);

  repeat

    write('Hour (0 - 23) [99]:  ');

    readln(HourS);

    Hour := IntStr(HourS);

    if HourS = '' then

      Hour := 99;

  until ((Hour >= 0) and (Hour <= 23)) or (Hour = 99);

  repeat

    write('Minute (0 - 59) [99]:  ');

    readln(MinS);

    Min := IntStr(MinS);

    if MinS = '' then

      Min := 99;

  until ((Min >= 0) and (Min <= 59)) or (Min = 99);

  repeat

    write('Second (0 - 59) [0]:  ');

    readln(SecS);

    Sec := IntStr(SecS);

    if SecS = '' then

      Sec := 0;

  until (Sec >= 0) and (Sec <= 59);

  writeln('Message [Beep!]:');

  readln(Message);

  if Message = '' then

    Message := 'Beep!';

  WindowExit;

  Assign(AF, AlarmFile);

  Append(AF);

  writeln(AF, Year,' ',Month,' ',Day,' ',Hour,' ',Min,' ',Sec);

  writeln(AF, Message);

  Close(AF);

  AlarmLoad;

  AlarmList;

end;



Procedure AlarmClear;

{***************************************************************************}

var

  Dead: integer;

begin

  repeat

    AlarmList;

    WindowEnter;

    write('Remove which alarm? [0 - ',C,']:  ');

    readln(Dead);

    WindowExit;

  until (Dead >= 0) and (Dead <= C);

  if Dead <> 0 then

    FileLineDel(AlarmFile, Dead*2-1, Dead*2);

  AlarmLoad;

  AlarmList;

end;



Procedure AlarmList;

{***************************************************************************}

begin

  WindowEnter;

  writeln('******************** Loaded Alarms Listing ********************');

  for alpha := 1 to C do

    begin

      Writeln('[',

        AYear[alpha], '-',

        StrIntZer(AMonth[alpha], 2), '-',

        StrIntZer(ADay[alpha], 2), ', ',

        StrIntZer(AHour[alpha], 2), ':',

        StrIntZer(AMin[alpha], 2), ':',

        StrIntZer(ASec[alpha], 2), ']');

        Writeln(AMessage[alpha]);

    end;

  writeln('***************************************************************');

  WindowExit;

end;



Procedure AlarmLoad;

{***************************************************************************}

begin

  Assign(AF, AlarmFile);

  if FileExists(AlarmFile) then

    Reset(AF)

  else

    Rewrite(AF);

  C := 0;

  While not(EOF(AF)) do

    begin

      Inc(C);

      if C > MaxC then

        begin

          writeln(#7,'ALARM.DAT file too long!');

          halt;

        end;

      read(AF, AYear[C]);

      read(AF, AMonth[C]);

      read(AF, ADay[C]);

      read(AF, AHour[C]);

      read(AF, AMin[C]);

      readln(AF, ASec[C]);

      readln(AF, AMessage[C]);

    end;

  close(AF);

end;



Procedure HelpMenu;

{***************************************************************************}

begin

  WindowEnter;

  writeln('***************************************************************');

  writeln('ALARM Help Message');

  writeln('F1 for this help message');

  writeln('F2 to clear the screen');

  writeln('F3 to list the loaded alarms');

  writeln('F5 to set an alarm');

  writeln('F6 to clear an alarm');

  writeln('F9 to quit');

  writeln('  ALARM uses a file called ALARM.DAT that has all the times and');

  writeln('messages.  The file can be created but must be in this format:');

  writeln('a line of 6 numbers, example: 1990 12 25 00 00 00');

  writeln('a message line, example: Merry Christmas!');

  writeln('  If any of the 6 numbers is 99, then it will trigger any time.');

  writeln('That way you could set the morning alarm to 99 99 99 06 15 00.');

  writeln('  You can have up to ',MaxC,' alarms set at one time.');

  writeln('***************************************************************');

  WindowExit;

end;



Procedure Main;

{***************************************************************************}

begin

  clrscr;

  GotoXY(24, 1);

  Writeln('ALARM by David Croft, copyright 1990.  F1 for Help.');

  Writeln('--------------------------------------------------------------------------------');

  AlarmLoad;

  SaveX := 1;

  SaveY := 1;

  repeat

    GetDate(Year, Month, Day, DumWord);

    repeat

      OldSec := Sec;

      GetTime(Hour, Min, Sec, DumWord);

    until (Sec <> OldSec) or keypressed;

    if keypressed then

      if readkey = #0 then

        case readkey of

          F1:  HelpMenu;

          F2:

            begin

              WindowEnter;

              clrscr;

              WindowExit;

            end;

          F3:  AlarmList;

          F5:  AlarmSet;

          F6:  AlarmClear;

          F9:  halt;

          else

            write(#7);

        end {* case *}

      else

        write(#7);

    gotoXY(1, 1);

    writeln('[',Year,'-', StrIntZer(Month,2), '-', StrIntZer(Day,2),', ',

      StrIntZer(Hour,2), ':', StrIntZer(Min,2), ':', StrIntZer(Sec,2), ']');

    for alpha := 1 to C do

      begin

        if (Year = AYear[alpha]) or (AYear[alpha] = WildNum) then

        if (Month = AMonth[alpha]) or (AMonth[alpha] = WildNum) then

        if (Day = ADay[alpha]) or (ADay[alpha] = WildNum) then

        if (Hour = AHour[alpha]) or (AHour[alpha] = WildNum) then

        if (Min = AMin[alpha]) or (AMin[alpha] = WildNum) then

        if (Sec = ASec[alpha]) or (ASec[alpha] = WildNum) then

          begin

            WindowEnter;

            Writeln(#7,#7,#7, '[',

              AYear[alpha], '-',

              StrIntZer(AMonth[alpha], 2), '-',

              StrIntZer(ADay[alpha], 2), ', ',

              StrIntZer(AHour[alpha], 2), ':',

              StrIntZer(AMin[alpha], 2), ':',

              StrIntZer(ASec[alpha], 2), ']');

            Writeln(AMessage[alpha]);

            WindowExit;

          end;

      end;

  until false;

end;



begin

end.