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

  1. /* ACron by Jim Hines and some needed advice from Gene Heskett 
  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. ** This does NOT HAVE SPEECH SUPPORT INCLUDED WITHIN IT. See EZCron for details to add it
  6. */
  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 = "ADD" then do
  47.             call addrtn()
  48.         end
  49.         when command = 'START' then do
  50.             call startrtn()
  51.         end
  52.         when command = "STOP" then do
  53.             call stoprtn()
  54.         end
  55.         when command = "QUIT" then do
  56.             command = "STOP"
  57.             call stoprtn()
  58.         end
  59.         when command = "NEW" then do
  60.             call newrtn()
  61.         end
  62.         when command = "DOC" then do
  63.             call docrtn()
  64.             exit
  65.         end
  66.         when command = "LIST" then do
  67.             call listrtn()
  68.         end
  69.         when command = '' then do
  70.             call nulinp()
  71.         end
  72.         otherwise
  73.             say ''
  74.             say bold'ERROR,'norm 'Unknown option'blue command norm
  75.             call nulinp()
  76.         end
  77.     end
  78.     
  79. nulinp:
  80.     say ' '
  81.     say white'    Usage: rx ACron [option] [LOG]' norm
  82.     say ''
  83.     say blue'    [NEW]'norm'   This creates a new blank config file in your s:'
  84.     say '         directory. YOU MUST DO THIS FIRST IF YOU''VE'
  85.         say '                NEVER RUN IT BEFORE'
  86.         say '                (If you already have one this WILL delete it!!)'
  87.     say ''
  88.     say blue'    [ADD]'norm '  This will allow you to set up your config'
  89.     say '         file interactivatly.'
  90.     say ''
  91.     say blue'      [START]'norm '  This runs it. You must create a config'
  92.     say '         file first using the NEW command option.' norm
  93.     say ''
  94.     say blue'       [STOP]'norm '  Just like it says. If its running, this kills it.'
  95.     say ''
  96.     say blue'        [DOC]'norm'   Short Docs'
  97.     say ''
  98.     say blue'       [LIST]'norm'   This will list the events in s:cron.config'
  99.     say ''
  100.     say blue'        [LOG]'norm'   If specified, This will log events in s:cronlog'
  101.     say ''
  102. exit
  103.  
  104. newrtn:
  105.     if command = "NEW" then do
  106.         if ~exists('s:cron.config') then do
  107.                     open(MkCfg, 's:cron.config',W)
  108.                     say ''
  109.                     say 'OKay, a blank cron.config file has been created in your s: directory'
  110.                     say ''
  111.                     close(MkCfg)
  112.         exit
  113.         end
  114.     else
  115.         rtezrequest("A cron.config file already exists."||LF||"Do you wish to overwrite it?.", "_Yes|_No", , "rt_reqpos = reqpos_centerscr")
  116.         if rtresult == 1 then do
  117.             say ''
  118.             say 'Renaming your cron.config file to cron.config.old'
  119.             address command 'c:rename s:cron.config s:cron.config.old'
  120.             call delay(3)
  121.             open(MkCfg, 's:cron.config',W)                
  122.             say ''
  123.             say 'Your cron.config file has been overwritten with a new empty file. Use 'rx acron add' to add new events.'
  124.             say ''
  125.         exit
  126.         end
  127.  
  128.         if rtresult == 0 then do
  129.             say "Operation Cancelled"
  130.         exit
  131.         end
  132.  
  133.  
  134. stoprtn:
  135.     if command = "STOP" then do
  136.         if showlist('P', 'ACRON_REXX') then do
  137.         say ital 'Exiting ACron: Please Wait. Program will exit in' LT 'seconds!' norm
  138.         address 'ACRON_REXX' STOP
  139.         exit
  140.         end
  141.         else
  142.         say bold ital 'ACron is not running.' norm
  143.     exit
  144.     end
  145.  
  146. ADDRTN:
  147.     if command  = "ADD" then do
  148.         filename = rtfilerequest(, , "Pick a File To Run",OK, "rt_reqpos = reqpos_centerscr")
  149.         if rtresult == 0 then do
  150.             say 'ACron ADD operation aborted!'
  151.         exit
  152.         end
  153.         else
  154.         rtezrequest( "Do You Wish To Add Program Arguments?.", "_Yes|_No", , "rt_reqpos = reqpos_centerscr")
  155.  
  156.         if rtresult == 1 then
  157.             pargs = rtgetstring("- - - -","Enter Program Arguments", "Arguments Requester", ,"rt_reqpos = reqpos_centerscr")
  158.         if rtresult == 0 then pargs = "- - - -"
  159.  
  160.         STime = rtgetstring(clock2,'Enter the Time You Wish in Existing Format' , "Enter Start Time:", , "rt_reqpos = reqpos_centerscr")
  161.         if rtresult == 0 then do
  162.             say 'ACron ADD operation aborted!'
  163.         exit
  164.         end
  165.  
  166.         SDate = rtgetstring(date,'Enter the Date You Wish in Existing Format' , "Enter Start Data:", , "rt_reqpos = reqpos_centerscr")
  167.         if rtresult == 0 then do
  168.             say 'ACron ADD operation aborted!'
  169.          exit
  170.         end
  171.  
  172.         rtezrequest( "Do You Wish To Add A Sound Sample?.", "_Yes|_No", , "rt_reqpos = reqpos_centerscr")
  173.         if rtresult == 1 then
  174.             seffect = rtfilerequest(, , "Pick a sound file",_OK, "rt_reqpos = reqpos_centerscr")
  175.         if rtresult == 0 then seffect = '-'
  176.  
  177.         say 'Appending New Data to the Existing Config File.'
  178.         open(dfile, 's:cron.config', 'a')
  179.         writeln(dfile, filename pargs STime SDate seffect '-')
  180.         close(dfile)
  181.  
  182.         say ''
  183.         say 'THIS IS YOUR CURRENT CONFIG'
  184.         say '==========================='
  185.         address command 'c:type s:cron.config'
  186.         say ''
  187.         say "To run the Cron, Type 'rx ACron Start'"
  188.     exit
  189.     end
  190.  
  191. docrtn:
  192.     if command = "DOC" then do
  193.         say ''
  194.         say 'This is pretty much straight forward. The First thing you need to do is'
  195.         say 'type 'rx ACron new'. This sets up an empty config file in your s: dir.'
  196.         say 'Once that is done, type 'rx ACron add' to add files to run to the list.'
  197.         say ''
  198.         say 'Follow the input format given with the requesters with the following'
  199.         say 'exceptions: '
  200.         say ''
  201.         say 'ARGUMENTS REQUESTER'
  202.         say '==================='
  203.         say 'You may enter program arguments at this prompt. The requester will '
  204.         say 'default to "- - - -" representing 4 arguments. If only 1 argument is'
  205.         say 'entered, 3 of the dashes MUST remain. (ie. maxmem=400000 - - - ) and'
  206.         say 'if two args are entered, 2 dashes must remain etc.'
  207.         say ''
  208.         say 'TIME REQUESTER'
  209.         say '=============='
  210.         say 'You may enter "Minute" in the time requester to run an event every minute.'
  211.         say 'You may also enter "Hourly" to run the task every hour on the hour'
  212.         say ''
  213.         say 'DATE REQUESTER'
  214.         say '=============='
  215.         say 'You may enter "Daily" within the DATE requester to run every day at a'
  216.         say 'given time.'
  217.         say 'Yoy may enter a weekday (ie. Sunday, Monday) to run the program once a week'
  218.         say 'at the given time and day.'
  219.         say 'You may enter "Monthly-03" to run a task every month on the given day.'
  220.         say 'In this case the third of every month.'
  221.         say ''
  222.         say 'These exceptions are CASE SENITIVE! (ie. Sunday must be "Sunday" minus the'
  223.         say 'quotes).'
  224.         say ''
  225.         say 'Thats it. Enjoy!'
  226.         say ''
  227.         say 'ACRON by Jim Hines'
  228.         say ''
  229.     exit
  230.     end
  231.  
  232.  
  233. /* =======LOOP== */
  234. startrtn:
  235.     if ~exists('s:cron.config') then do
  236.         say 'The s:cron.config file does not exist. Use "rx cron new" to create one'
  237.         say 'Then use 'rx ACron add' to add your events.'
  238.     exit
  239.     end
  240.  
  241.     RC = showlist('P', 'ACRON_REXX')
  242.     if RC = 1 then do
  243.         say bold ital white 'ACron is Already Active' norm
  244.     exit
  245.     end
  246.  
  247.     openport('ACRON_REXX')
  248.     SIGNAL on HALT
  249.  
  250. /* =======PARSE CONFIG FILE SECTION == */
  251.     do forever
  252.     config = 's:cron.config'        /* Name of file for reading events from */
  253.     event. = 0
  254.  
  255.     if ~open(cronfile, config,'READ') then do
  256.         exit 20
  257.     end
  258.  
  259.     errors = 0
  260.  
  261.         do until eof(cronfile)
  262.             /* Grab the line, parse the event and ignore the comments */
  263.             linein = readln(cronfile)
  264.             parse var linein line '#'
  265.     
  266.             next = event.0 + 1
  267.         
  268.             parse var line event.next.command event.next.pargs1 event.next.pargs2,
  269.             event.next.pargs3 event.next.pargs4 event.next.time    event.next.date,
  270.             event.next.sfx event.next.txt
  271.  
  272.             event.next.date = translate(event.next.date, 'abcdefghijklmnopqrstuvwxyz',,
  273.                             'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
  274.                             /* THE ABOVE TRANSLATES THE DATE TO LOWERCASE IF NOT NUMERIC */
  275.  
  276.             event.next.time = translate(event.next.time, 'abcdefghijklmnopqrstuvwxyz',,
  277.                             'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
  278.                             /* THE ABOVE TRANSLATES THE TIME TO LOWERCASE IF NOT NUMERIC */
  279.     
  280.             select
  281.                 when event.next.command = "" then iterate
  282.                 when event.next.command = "" then do
  283.                     say "Not enough fields in:" linein
  284.                     errors =  1
  285.                     iterate
  286.                 end
  287.                 otherwise event.0 = next
  288.             end
  289.         end
  290.         call close(cronfile)
  291.  
  292. /* ======== END OF PARSE SECTION == */
  293.  
  294.         sec = right(clock, 2)  /* Get Seconds */
  295.         sec2 = 60 - sec        /* 60 (seconds) minus sec) */
  296.         delayvar = sec2 * 50   /* sec2 x 50 ticks or 1 second sets the delay time */
  297.         LT = delayvar / 50
  298.         LTime = 60 - LT
  299.  
  300. /* ======== AREXX PORT STUFF == */
  301.         pkt = getpkt('ACRON_REXX')
  302.             if pkt ~= '0000 0000'x then do
  303.                 call aport(pkt)
  304.             end
  305.  
  306.         say 'The Current Time & Date is:' bold clock2 date norm
  307.         if lg = log then say 'LOG ENABLED'
  308.         call delay(delayvar)    /* 3000 would be equal to 1 minute */
  309.     
  310.         DO i = 1 to event.0
  311.             clock = time('N')
  312.             clock2 = LEFT(clock,5)
  313.             date = Date(USA)               /*  -> 08/04/92  */
  314.             date2 = Date(S)                /*  -> 19920804  */
  315.             date3 = Date(W, date2, 'S')    /*  -> Friday    */
  316.     
  317.     /* ======= Arguments Routine == */
  318.             if event.i.pargs1 = '-' then
  319.                 event.i.pargs1 = ''
  320.             if event.i.pargs2 = '-' then
  321.                 event.i.pargs2 = ''
  322.             if event.i.pargs3 = '-' then
  323.                 event.i.pargs3 = ''
  324.             if event.i.pargs4 = '-' then
  325.                 event.i.pargs4 = ''
  326.     
  327.     /* ======= Misc Routines == */
  328.             if event.i.sfx = '-' then
  329.                 event.i.sfx = ''
  330.             if event.i.txt = '-' then
  331.                 event.i.txt = ''
  332.     
  333.     /* ======= Every Minute Routine == */
  334.             if event.i.time = 'Minute'
  335.                 then event.i.time = clock2
  336.     
  337.     /* ======= Every Hour Routine == */
  338.             parse var clock2 hrs ':' min
  339.             if min = 00 & event.i.time = 'Hourly' then event.i.time = clock2
  340.     
  341.     /* ======= Daily Routine == */
  342.             if event.i.date = 'Daily'
  343.                 then event.i.date = date
  344.     
  345.     /* ======= Weekly Routine == */
  346.     /* ======= Note that case IS significant */
  347.  
  348.             if event.i.date = 'sunday' & date3 = Sunday
  349.                 then event.i.date = date
  350.             if event.i.date = 'monday' & date3 = 'Monday'
  351.                 then event.i.date = date
  352.             if event.i.date = 'tuesday' & date3 = 'Tuesday'
  353.                 then event.i.date = date
  354.             if event.i.date = 'wednesday' & date3 = 'Wednesday'
  355.                 then event.i.date = date
  356.             if event.i.date = 'thursday' & date3 = 'Thursday'
  357.                 then event.i.date = date
  358.             if event.i.date = 'friday' & date3 = 'Friday'
  359.                 then event.i.date = date
  360.             if event.i.date = 'saturday' & date3 = 'Saturday'
  361.                 then event.i.date = date
  362.     
  363.     /* ======= Monthly Routine == */
  364.             month.event = event.i.date
  365.             parse var month.event mth '-' day2
  366.             if mth = 'monthly' then do
  367.                 parse var date month '/' day '/' year
  368.                 if day2 = day & event.i.time = clock2 then event.i.date = date
  369.             end
  370.     
  371.     /* ======== Logging Routine == */
  372.             if lg = log then do
  373.                    if event.i.time = clock2 & event.i.date = date then do
  374.                     if ~exists('s:cronlog') then do
  375.                         open(log, 's:cronlog', 'W')
  376.                     end
  377.                 else
  378.                     open(log, 's:cronlog', 'A')
  379.                     writeln(log, event.i.command "was executed at" event.i.time "on" event.i.date)
  380.                     close(log)
  381.                 end
  382.             end
  383.     
  384.     /* ======= Final Routine == */
  385.             if lg = log then delay(25) /* This delay is to allow for the log file
  386.                                           to be deleted automatically if so desired */
  387.                if event.i.time = clock2 & event.i.date = date then
  388.             address command 'run >NIL:' event.i.command event.i.pargs1,
  389.             event.i.pargs2 event.i.pargs3 event.i.pargs4
  390.     
  391.             if event.i.time = clock2 & event.i.date = date & event.i.sfx ~= "" then do
  392.                 if exists('EZCron:prefs/sfx.prefs') then do
  393.                     open(sfxconfig, 'EZCron:prefs/sfx.prefs', 'r')
  394.                     sfxplayer = readln(sfxconfig)
  395.                     close(sfxconfig)
  396.                 end
  397.                 address command 'run >nil:' sfxplayer event.i.sfx
  398.             end
  399.     
  400.             if event.i.time = clock2 & event.i.date = date & event.i.txt ~= "" then
  401.             address command 'run >nil: rx >nil: ezcron:rexx/Reminder.rexx' event.i.txt
  402.     
  403.             if event.i.time = clock2 & event.i.date = date
  404.             then event.i.date = 'Finished with Event'
  405.     
  406.             say LF ''
  407.             say blue'======================================================' norm
  408.             say bold 'UPCOMING EVENT:    ' norm white event.i.command norm
  409.             say bold 'ARGUMENTS:         ' norm white event.i.pargs1 event.i.pargs2 event.i.pargs3 event.i.pargs4 norm
  410.             say bold 'EVENT TIME:        ' norm white event.i.time norm
  411.             say bold 'EVENT DATE:        ' norm white event.i.date norm
  412.             say bold 'EVENT SOUND FX:    ' norm white event.i.sfx norm
  413.             say bold 'EVENT REMINDER:    ' norm white event.i.txt norm
  414.             say bold 'LOOP EVENT TIME:   ' norm white ltime 'seconds' norm
  415.     
  416.         end
  417.     end
  418.  
  419. listrtn:
  420.     address command 'c:type s:cron.config'
  421.     if showlist('P', 'ACRON_REXX') then do
  422.         say white ital'ACron is currently running' norm
  423.     end
  424.     else
  425.     say white ital'ACron is NOT currently running.' norm
  426.     exit
  427.     end
  428.  
  429. /* ======== CLEANUP == */
  430.     if event.0 = 0 then exit
  431.     options failat 300
  432.     trace 'Off'
  433.  
  434. /* ======== Arexx Port Message Check == */
  435. aport:
  436.     Cmd = getarg(Pkt)
  437.     if Cmd = 'STOP' then do
  438.         call reply(Pkt, rc)
  439.     exit
  440.     end
  441.