home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 616.lha / Notify_v1.01 / NotifyChime < prev    next >
Text File  |  1992-02-21  |  7KB  |  131 lines

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