home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d6xx / d652 / notify.lha / Notify / NotifyChime < prev    next >
Text File  |  1992-05-14  |  8KB  |  143 lines

  1. /* NotifyChime 1.02 */
  2. /* Copyright © Michael Tanzer, 1991, 1992 */
  3. /* See additional notices in accompanying documentation */
  4.  
  5. interval = 60                              /* Minutes between chimes       */
  6.  
  7. /* Make sure the necessary libraries are available */
  8. if ~show('L','rexxsupport.library') then
  9.   call addlib('rexxsupport.library',0,-30)
  10. if ~show('L','rexxarplib.library') then
  11.   call addlib('rexxarplib.library',0,-30)
  12.  
  13. /* Test for asynchronous execution */
  14. if getenv('NotifyChime.asynchsw')=1 then do
  15.   call asynch
  16.   exit
  17.   end
  18.  
  19. /* Process user request */
  20. arg minutes .                              /* Was an arg specified?        */
  21. if words(minutes)>0 then do                /* Yes, check it out            */
  22.   if minutes='HELP' | minutes='?' then do  /*   Handle call for help       */
  23.     call help
  24.     exit
  25.     end
  26.   if minutes='STATUS' then do              /*   Handle status request      */
  27.     interval = getenv('NotifyChime.interval')   /* Get current interval    */
  28.     if words(interval)>0 then msg = 'Current interval is' interval 'minutes.'
  29.     else msg = 'NotifyChime is not active.'
  30.     call post                             /*       Go post the message     */
  31.     exit
  32.     end
  33.   if minutes='QUIT' then do                /*   Handle quit request        */
  34.     call bumpcount                         /*     Go increment call count  */
  35.     call setenv('NotifyChime.interval')    /*     Clear interval           */
  36.     msg = 'NotifyChime terminated.'        /*     Set a message            */
  37.     call post                              /*     Go post it               */
  38.     exit
  39.     end
  40.   if ~datatype(minutes,'W') | minutes<1 then do /* Handle invalid value    */
  41.     call request(0,0,'Invalid number of minutes specified.',,'Drat!')
  42.     exit 79
  43.     end
  44.   interval = minutes                       /*   Get new interval           */
  45.   w = getenv('NotifyChime.interval')       /*   See if interval set        */
  46.   if words(w)>0 then w = 'changed'         /*   Handle changed interval    */
  47.   else w = 'set'                           /*   Handle new interval        */
  48.   msg = 'NotifyChime interval' w 'to' interval 'minutes.'
  49.   call post                                /*   Go post the message        */
  50.   end
  51. else do                                    /* No interval specified        */
  52.   w = getenv('NotifyChime.interval')       /*   See if interval set        */
  53.   if words(w)>0 then do                    /*   If so, QUIT                */
  54.     call bumpcount                         /*     Go increment call count  */
  55.     call setenv('NotifyChime.interval')    /*     Clear interval           */
  56.     msg = 'NotifyChime terminated.'        /*     Set a message            */
  57.     call post                              /*     Go post it               */
  58.     exit
  59.     end
  60.   msg = 'NotifyChime interval set to' interval 'minutes.'
  61.   call post                                /*  Go post the message         */
  62.   end
  63. call setenv('NotifyChime.interval',interval)  /* Store interval            */
  64. call setenv('NotifyChime.asynchsw',1)      /* Set switch for asynch task   */
  65. address arexx 'NotifyChime'                /* Start asynch task            */
  66. exit                                       /* Free up CLI task             */
  67.  
  68. /* Handle asynchronous execution */
  69. asynch:
  70.   call setenv('NotifyChime.asynchsw',0)    /* Clear asynch switch          */
  71.   call bumpcount                           /* Go increment call count      */
  72.   interval = getenv('NotifyChime.interval')/* Get interval                 */
  73.   now = time()                             /* Get the current time         */
  74.   cm = substr(now,1,2)*60+substr(now,4,2)  /* Get current time in minutes  */
  75.   call calibrate                           /* Go get end of 1st interval   */
  76.   do forever
  77.     do forever
  78.       mm = dm-cm                           /* Get minutes to wait          */
  79.       if mm<0 then mm=mm+1440              /* Handle midnight crossing     */
  80.       if mm<10 then leave                  /* Leave loop if <10 min        */
  81.       mm = mm*9%10                         /* Get 90% of minutes           */
  82.       call wait                            /* Go wait 90% of time          */
  83.       now = time()                         /* Get current time             */
  84.       cm = substr(now,1,2)*60+substr(now,4,2) /* Get current time in mins  */
  85.       end                                  /*  Go handle remaining 10%     */
  86.     call wait                              /* Wait for end of interval     */
  87.     w = getenv('NotifyChime.count')        /* Get call count               */
  88.     if w~=callcount then exit              /* Exit if new interval set     */
  89.     now = time()                           /* Get the current time         */
  90.     cm = substr(now,1,2)*60+substr(now,4,2)/* Get current time in minutes  */
  91.     address arexx 'NotifyNoise' substr(now,1,5) /* Announce the time       */
  92.     dm = dm+interval                       /* Get new desired minute       */
  93.     if dm>=1440 then dm = dm-1440          /* Adjust for midnight crossing */
  94.     end
  95.  
  96. wait:                                      /* Wait for time to pass        */
  97.   ss = mm*60-substr(now,7)                 /* Get seconds to wait          */
  98.   signal on halt                           /* Disable halt interrupt       */
  99.   call delay(ss*50)                        /* Catch some Z's               */
  100. halt:
  101.   signal off halt                          /* Enable halt interrupt        */
  102.   return
  103.  
  104. calibrate:                                 /* Set for first interval       */
  105.   dm = cm+interval                         /* Assume no adjustment required*/
  106.   if dm>=1440 then dm = dm-1440            /* Adjust for midnight crossing */
  107.   if 60//interval>0 then return            /* Irregular interval           */
  108.   mm = substr(now,4,2)                     /* Get current minutes into hour*/
  109.   if mm//interval=0 then return            /* Cur mm is mult of interval   */
  110.   dm = dm-mm//interval                     /* Set for short interval       */
  111.   if dm<0 then dm = dm+1440                /* Adjust for no midnight cross */
  112.   return
  113.  
  114. bumpcount:                                 /* Bump call count              */
  115.   callcount = getenv('NotifyChime.count')  /* Get previous count           */
  116.   if words(callcount)=0 then callcount = 1 /* Use 1 first time             */
  117.   else callcount = callcount+1             /* Bump count                   */
  118.   call setenv('NotifyChime.count',callcount)  /* Store result              */
  119.   return
  120.  
  121. post:                                      /* Post a message               */
  122.   call postmsg(0,0,msg)                    /* Show the message             */
  123.   call delay(100)                          /* Wait a couple seconds        */
  124.   call postmsg()                           /* Clear the message            */
  125.   return
  126.  
  127. help:                                      /* Give some help               */
  128.   if interval=30 then w = 15
  129.   else w = 30
  130.   w = 'NotifyChime announces the time every' interval 'minutes.\'       || ,
  131.       'To start NotifyChime, enter:\'                                   || ,
  132.       '   rx NotifyChime\'                                              || ,
  133.       'You may specify a different interval (in minutes) on the\'       || ,
  134.       'command line.  For example, enter:\'                             || ,
  135.       '   rx NotifyChime' w'\'                                          || ,
  136.       'to change the interval to' w 'minutes.\'                         || ,
  137.       'In order to display the current interval, enter:\'               || ,
  138.       '   rx NotifyChime status\'                                       || ,
  139.       'In order to terminate NotifyChime, enter:\'                      || ,
  140.       '   rx NotifyChime quit\'
  141.   call request(0,0,w,,'I understand.')
  142.   return
  143.