home *** CD-ROM | disk | FTP | other *** search
/ Aminet 10 / aminetcdnumber101996.iso / Aminet / util / time / EZCron.lha / EZCron < prev    next >
Text File  |  1995-12-20  |  7KB  |  265 lines

  1. /* ACron by Jim Hines ©1994-1995 All Rights Reserved
  2. ** 10-23-95 Added requester to verify making a NEW cron.config file. See newrtn:
  3. ** 10-25-95 Fixed Bug in the above and added renaming of the old config file. See newrtn:
  4. ** 11-30-95 added the text string reminder support and the sfx functions
  5. ** 12-05-95 Fixed case sensitivity problem with weekly, monthly & Daily routeens 
  6. ** 12-13-95 Added Speech Function
  7. */
  8. /* call trace(all) */
  9.  
  10.  
  11. /* ======== Envirorment Varables == */
  12.     clock = time('N')
  13.     clock2 = LEFT(clock,5)
  14.     date = Date(USA)
  15.     date2 = Date(S)             /*     -> 19920804  */
  16.     date3 = Date(W, date2, 'S')  /*    -> Friday  */
  17.     sec = right(clock, 2)  /* Get Seconds */
  18.     sec2 = 60 - sec        /* 61 (seconds) minus sec) */
  19.     delayvar = sec2 * 50   /* sec2 x 50 ticks or 1 second sets the delay time */
  20.     LT = delayvar / 50
  21.     LTime = 60 - LT
  22.  
  23. /* ======== CHARACTOR TYPE VARABLES == */
  24.     csi='9b'x
  25.     Ital=csi'3m'
  26.     bold=csi'1m'
  27.     norm=csi'0m'
  28.     black=csi'31m'
  29.     white=csi'32m'
  30.     blue=csi'33m'
  31.     LF = '0a'x
  32.  
  33.  
  34. /* ========END VARABLES == */
  35.  
  36.     arg command lg .
  37.  
  38.     if ~show('L','rexxsupport.library') then
  39.         call addlib('rexxsupport.library',0,-30)
  40.     if ~show('L','rexxreqtools.library') then
  41.             call addlib("rexxreqtools.library", 0, -30, 0)
  42.  
  43. /* ======== THIS IS THE INPUT PARSING / USAGE SECTION WITH A SUB-ROUTINE== */
  44.  
  45.     select
  46.         when command = 'START' then do
  47.             call startrtn()
  48.         end
  49.         when command = "STOP" then do
  50.             call stoprtn()
  51.         end
  52.         when command = "QUIT" then do
  53.             command = "STOP"
  54.             call stoprtn()
  55.         end
  56.         otherwise
  57.             say ''
  58.             say bold'ERROR,'norm 'Unknown option'blue command norm
  59.             call nulinp()
  60.         end
  61.     end
  62.     
  63. stoprtn:
  64.     if command = "STOP" then do
  65.         if showlist('P', 'ACRON_REXX') then do
  66.             say ital 'Exiting ACron: Please Wait. Program will exit in' LT 'seconds!' norm
  67.             address 'ACRON_REXX' STOP
  68.             exit
  69.         end
  70.     else
  71.         say bold ital 'ACron is not running.' norm
  72.         exit
  73.         end
  74.  
  75. /* =======LOOP== */
  76. startrtn:
  77.     if ~exists('s:cron.config') then do
  78.         call rtezrequest('s:cron.config does NOT exist', "Okay", , "rt_reqpos = reqpos_centerscr")
  79.         exit
  80.     end
  81.  
  82.     RC = showlist('P', 'ACRON_REXX')
  83.     if RC = 1 then do
  84.         say bold ital white 'ACron is Already Active' norm
  85.     exit
  86.     end
  87.  
  88.     openport('ACRON_REXX')
  89.     SIGNAL on HALT
  90.  
  91. /* =======PARSE CONFIG FILE SECTION == */
  92.     do forever
  93.     config = 's:cron.config'        /* Name of file for reading events from */
  94.     event. = 0
  95.  
  96.     if ~open(cronfile, config,'READ') then do
  97.         exit 20
  98.     end
  99.  
  100.     errors = 0
  101.  
  102.         do until eof(cronfile)
  103.             /* Grab the line, parse the event and ignore the comments */
  104.             linein = readln(cronfile)
  105.             parse var linein line '#'
  106.     
  107.             next = event.0 + 1
  108.         
  109.             parse var line event.next.command event.next.pargs1 event.next.pargs2,
  110.             event.next.pargs3 event.next.pargs4 event.next.time    event.next.date,
  111.             event.next.sfx event.next.txt
  112.  
  113.             event.next.date = translate(event.next.date, 'abcdefghijklmnopqrstuvwxyz',,
  114.                             'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
  115.                             /* THE ABOVE TRANSLATES THE DATE TO LOWERCASE IF NOT NUMERIC */
  116.  
  117.             event.next.time = translate(event.next.time, 'abcdefghijklmnopqrstuvwxyz',,
  118.                             'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
  119.                             /* THE ABOVE TRANSLATES THE TIME TO LOWERCASE IF NOT NUMERIC */
  120.  
  121.             
  122.     
  123.             select
  124.                 when event.next.command = "" then iterate
  125.                 when event.next.command = "" then do
  126.                     say "Not enough fields in:" linein
  127.                     errors =  1
  128.                     iterate
  129.                 end
  130.                 otherwise event.0 = next
  131.             end
  132.         end
  133.         call close(cronfile)
  134.  
  135. /* ======== END OF PARSE SECTION == */
  136.  
  137.         sec = right(clock, 2)  /* Get Seconds */
  138.         sec2 = 60 - sec        /* 60 (seconds) minus sec) */
  139.         delayvar = sec2 * 50   /* sec2 x 50 ticks or 1 second sets the delay time */
  140.         LT = delayvar / 50
  141.         LTime = 60 - LT
  142.  
  143. /* ======== AREXX PORT STUFF == */
  144.         pkt = getpkt('ACRON_REXX')
  145.             if pkt ~= '0000 0000'x then do
  146.                 call aport(pkt)
  147.             end
  148.  
  149.         call delay(delayvar)    /* 3000 would be equal to 1 minute */
  150.     
  151.         DO i = 1 to event.0
  152.             clock = time('N')
  153.             clock2 = LEFT(clock,5)
  154.             date = Date(USA)               /*  -> 08/04/92  */
  155.             date2 = Date(S)                /*  -> 19920804   only used in next function */
  156.             date3 = Date(W, date2, 'S')    /*  -> Friday    */
  157.     
  158.     /* ======= Arguments Routine == */
  159.             if event.i.pargs1 = '-' then
  160.                 event.i.pargs1 = ''
  161.             if event.i.pargs2 = '-' then
  162.                 event.i.pargs2 = ''
  163.             if event.i.pargs3 = '-' then
  164.                 event.i.pargs3 = ''
  165.             if event.i.pargs4 = '-' then
  166.                 event.i.pargs4 = ''
  167.     
  168.     /* ======= Misc Routines == */
  169.             if event.i.sfx = '-' then
  170.                 event.i.sfx = ''
  171.             if event.i.txt = '-' then
  172.                 event.i.txt = ''
  173.     
  174.     /* ======= Every Minute Routine == */
  175.             if event.i.time = 'minute'
  176.                 then event.i.time = clock2
  177.     
  178.     /* ======= Every Hour Routine == */
  179.             parse var clock2 hrs ':' min
  180.             if min = 00 & event.i.time = 'hourly' then event.i.time = clock2
  181.     
  182.     /* ======= Daily Routine == */
  183.             if event.i.date = 'daily'
  184.                 then event.i.date = date
  185.     
  186.     /* ======= Weekly Routine == */
  187.     /* ======= Note that case IS significant */
  188.  
  189.             if event.i.date = 'sunday' & date3 = 'Sunday'
  190.                 then event.i.date = date
  191.             if event.i.date = 'monday' & date3 = 'Monday'
  192.                 then event.i.date = date
  193.             if event.i.date = 'tuesday' & date3 = 'Tuesday'
  194.                 then event.i.date = date
  195.             if event.i.date = 'wednesday' & date3 = 'Wednesday'
  196.                 then event.i.date = date
  197.             if event.i.date = 'thursday' & date3 = 'Thursday'
  198.                 then event.i.date = date
  199.             if event.i.date = 'friday' & date3 = 'Friday'
  200.                 then event.i.date = date
  201.             if event.i.date = 'saturday' & date3 = 'Saturday'
  202.                 then event.i.date = date
  203.     
  204.     /* ======= Monthly Routine == */
  205.             month.event = event.i.date
  206.             parse var month.event mth '-' day2
  207.             if mth = 'monthly' then do
  208.                 parse var date month '/' day '/' year
  209.                 if day2 = day & event.i.time = clock2 then event.i.date = date
  210.             end
  211.     
  212.     /* ======== Logging Routine == */
  213.             if lg = log then do
  214.                    if event.i.time = clock2 & event.i.date = date then do
  215.                     if ~exists('s:cronlog') then do
  216.                         open(log, 's:cronlog', 'W')
  217.                     end
  218.                 else
  219.                     open(log, 's:cronlog', 'A')
  220.                     writeln(log, event.i.command "was executed at" event.i.time "on" event.i.date)
  221.                     close(log)
  222.                 end
  223.             end
  224.     
  225.     /* ======= Final Routine == */
  226.             if lg = log then delay(25) /* This delay is to allow for the log file
  227.                                           to be deleted automatically if so desired */
  228.                if event.i.time = clock2 & event.i.date = date then
  229.             address command 'run >NIL:' event.i.command event.i.pargs1,
  230.             event.i.pargs2 event.i.pargs3 event.i.pargs4
  231.     
  232.             if event.i.time = clock2 & event.i.date = date & event.i.sfx ~= "" then do
  233.                 if exists('EZCron:prefs/sfx.prefs') then do
  234.                     open(sfxconfig, 'EZCron:prefs/sfx.prefs', 'r')
  235.                     sfxplayer = readln(sfxconfig)
  236.                     close(sfxconfig)
  237.                     address command 'run >nil:' sfxplayer event.i.sfx
  238.                 end
  239.             end
  240.     
  241.             if event.i.time = clock2 & event.i.date = date & event.i.txt ~= "" then do
  242.                 address command 'run >nil: rx >nil: ezcron:rexx/Reminder.rexx' event.i.txt /*This calls the external rexx proggy for the event display */
  243.                 if showlist(h,SPEAK) then do
  244.                         address command 'echo' event.i.txt '>speak:'
  245.                 end
  246.             end
  247.  
  248.             if event.i.time = clock2 & event.i.date = date
  249.             then event.i.date = 'Finished with Event'
  250.         end
  251.     end
  252.  
  253. /* ======== CLEANUP == */
  254.     if event.0 = 0 then exit
  255.     options failat 300
  256.     trace 'Off'
  257.  
  258. /* ======== Arexx Port Message Check == */
  259. aport:
  260.     Cmd = getarg(Pkt)
  261.     if Cmd = 'STOP' then do
  262.         call reply(Pkt, rc)
  263.     exit
  264.     end
  265.