@echo off

goto endcomment
REVISION HISTORY
----------------

:endcomment

BREAK ON
cls
echo [1;44;37mÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»[0;40;37m
echo [1;44;37mº                              ALARM                                          º[0;40;37m
echo [1;44;37mº Function: Wait until a certain time, then sound an alarm.                   º[0;40;37m
echo [1;44;37mº           Press CTL+BREAK to exit.                                          º[0;40;37m
echo [1;44;37mÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼[0;40;37m

if not (%1)==() goto start
rem color is white on blue
echo [1;44;37mÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»[0;40;37m
echo [1;44;37mº USAGE   : ALARM                      shows current time in hhmm format      º[0;40;37m
echo [1;44;37mº USAGE   : ALARM hhmm [msg]           waits until hhmm, then sounds an alarm º[0;40;37m
echo [1;44;37mº                                                                             º[0;40;37m
echo [1;44;37mº EXAMPLE : ALARM 0930                 [sounds alarm at 9:30 am]              º[0;40;37m
echo [1;44;37mº EXAMPLE : ALARM 930 Staff meeting    [sounds alarm at 9:30 am]              º[0;40;37m
echo [1;44;37mº EXAMPLE : ALARM 1800                 [sounds alarm at 6:00 pm]              º[0;40;37m
echo [1;44;37mº                                                                             º[0;40;37m
echo [1;44;37mº           For midnight, specify 0000 or 2400 for hhmm.                      º[0;40;37m
echo [1;44;37mº EXAMPLE : ALARM 2400  START MIDNIGHT BATCH RUN                              º[0;40;37m
echo [1;44;37mº                                                                             º[0;40;37m
echo [1;44;37mº Note:  Because this batch file does a LOT of disk activity,                 º[0;40;37m
echo [1;44;37mº        it is STRONGLY recommended that you make your current                º[0;40;37m
echo [1;44;37mº        directory a RAM disk before running it.                              º[0;40;37m
echo [1;44;37mº                                                                             º[0;40;37m
echo [1;44;37mº        To prevent repeated disk accesses to find the FDATE program,         º[0;40;37m
echo [1;44;37mº        you should also have FDATE on the RAM disk, or be using a cache.     º[0;40;37m
echo [1;44;37mÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼[0;40;37m
fdate /Ff /Ohh:mm:ss /P"Time is now: "
goto endit

:start

rem If RAMDISK is specified, change to RAM disk.  This will eliminate
rem the tremendous amount of disk accesses this batch file does.
rem ----------------------------------------------------------------
IF NOT "%RAMDISK%"=="" %RAMDISK%:

set alarm=%1
shift

rem get time now numeric representation
fdate /Ff /Ohhmm /P"@set timenow=" >junktemp.bat
call junktemp.bat
del  junktemp.bat

rem do a numeric compare: alarm time to 2400
fdate /f#comp /A%alarm% /B2400 /P"@set comp=" >junktemp.bat
call junktemp.bat
del  junktemp.bat

if (%comp%)==(ERROR) goto endit

if (%comp%)==(LT) goto OKtime

if (%comp%)==(EQ) set alarm=0000
if (%comp%)==(EQ) goto OKtime

echo ALARM REQUEST REJECTED.  ALARM TIME [%alarm%] IS GREATER THAN 2400.
goto endit

:OKtime

rem do a numeric compare: alarm time to timenow
fdate /f#comp /A%alarm% /B%timenow% /P"@set comp=" >junktemp.bat
call junktemp.bat
del  junktemp.bat

if (%comp%)==(EQ) echo ALARM REQUEST REJECTED.  ALARM TIME [%alarm%] AND TIME NOW ARE THE SAME.
if (%comp%)==(EQ) goto endit

rem  display time that alarm was set
fdate /Ff
fdate /Ff /Ohh:mm:ss /P"Alarm wait started at "

if (%comp%)==(GT) goto latertoday

rem else: fall through to tomorrow ...

:tomorrow

rem get the date that the alarm was set, i.e. today's date
fdate /Ff /Omm-dd-ccyy /P"@set setdate=" >junktemp.bat
call junktemp.bat
del  junktemp.bat

ECHO.
ECHO WAITING UNTIL MIDNIGHT (TOMORROW, 0000 HOURS) BEFORE STARTING MAIN WAIT.
ECHO.
ECHO WAITING UNTIL: %alarm%
ECHO MESSAGE:
ECHO    %1 %2 %3 %4 %5 %6 %7 %8 %9

rem loop until tomorrow
:top1
   rem ---- WHILE condition ----------------------------------------
   rem compare today's date to setdate
   fdate /Fcomp /At /B%setdate% /P"@set comp=" >junktemp.bat
   call junktemp.bat
   del  junktemp.bat

   if (%comp%)==(GT) goto end1

   rem ---- loopbody -----------------------------------------------
   fdate /Ff /Ohh:mm:ss /P"Current time : "
   echo [2A

   goto top1
:end1

ECHO.
ECHO MIDNIGHT ...


rem -------------------------------------------------------------
:latertoday
ECHO.
ECHO WAITING UNTIL: %alarm%
ECHO MESSAGE:
ECHO    %1 %2 %3 %4 %5 %6 %7 %8 %9

:top2
   rem ---- WHILE condition ----------------------------------------
   rem get time now numeric representation
   fdate /Ff /Ohhmm /P"@set timenow=" >junktemp.bat
   call junktemp.bat
   del  junktemp.bat

   rem do a numeric compare: alarm time to timenow
   fdate /f#comp /A%timenow% /B%alarm% /P"@set comp=" >junktemp.bat
   call junktemp.bat
   del  junktemp.bat

   if (%comp%)==(GT) goto end2
   if (%comp%)==(EQ) goto end2

   rem ---- loopbody -----------------------------------------------
   fdate /Ff /Ohh:mm:ss /P"Current time : "
   echo [2A

   goto top2
:end2


rem -------------------------------------------------------------
:alarm

REM The time that was to be waited for has arrived.
REM Sound alarm bell and display message.

:top3
cls
BREAK OFF
fdate /Ff /Ot1 /P"@set timenow=" >junktemp.bat
call junktemp.bat
del  junktemp.bat

rem color is white on red
echo [1;41;37m

echo [1;44;37mÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»[0;40;37m
FOR %%V IN (x x x x x x x x) do echo [1;44;37mº  It is %timenow%    Press ^BREAK to exit.  º[0;40;37m
echo [1;44;37mÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼[0;40;37m

BREAK ON
FOR %%V IN (x x x x x x x x) do echo [1;41;37m     %1 %2 %3 %4 %5 %6 %7 %8 %9   [0;40;37m

rem sound beeps. CONTROL-G is BEEP.
echo                           
GOTO top3

:endit
