home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / TASK.ZIP / TASK.MAC < prev    next >
Encoding:
Text File  |  1992-09-07  |  6.1 KB  |  127 lines

  1. Task Macro - A {COMMO} timed execution facility 
  2. Copyright (c) 1992 Joe Hayashi
  3.  
  4. {:start}        ;Begin here
  5.                 ;Process one-time setup stuff
  6.         {sete-p quit}                          ;What to do when you press <esc>
  7.     {setv %day,0}                          ;Set day counter to zero
  8.         {setv %quitcommmand%,quit}             ;Command for tasker to quit
  9. !       {setv schedulefile,c:\commo\task.txt}  ;Name of schedule file
  10.         {setv dayoffset,%_dwn%}                ;Variable used in reading
  11.         {incr dayoffset,5}                     ; the task file
  12.         {setlook 15,checktime}                 ;Check time every 15 seconds
  13. !       {capt y,c:\commo\task%_mon%%_day.log}  ;Save log file of what happened
  14.         {display ,,,^m^j  TASKER fired up on %_dwt%, %_tim%, %_dat%.^m^j}
  15.         {display ,,,^m^j  Later dude!^m^j}
  16. {:main}
  17.         {call schedulesetup}                   ;Repeated init stuff
  18.         {call loop}                            ;Workhorse loop
  19.         {goto quit}                            ;See ya!
  20. {}
  21.                 ;Shared functions
  22.  
  23. {:quit}                                        ;Exits program
  24.         {rclose}
  25.         {display ,,,^m^j  TASKER quit on %_dwt%, %_tim%, %_dat%.^m^j}
  26.         {exit}
  27. {}
  28.  
  29. {:retu} {return} {}                            ;Lets gotos return to a caller
  30.  
  31.                 ;Init stuff each time the schedule file is read
  32.                 ; and process this stuff for the "new" day
  33. {:schedulesetup}
  34.         {beep} {display ,,,  Ho hum.^m^j}
  35.         {incr %day%}                           ;# of days running
  36.         {incr %dayoffset%}                     ;Increment offset variable
  37.         {comp %dayoffset%,13}                  ;Make sure offset var has not
  38.         {ifco-g endofweek,}                    ; gone past Sunday
  39. {:weekhurdle}
  40.         {ropen %schedulefile%,main}
  41.         {return}
  42. {}
  43.                  ;schedulesetup functions
  44.                  ;endofweek - resets the variable that measures the offset
  45.                  ; from the beginning of each line in the command file
  46. {:endofweek}
  47.         {setv dayoffset,7}                     ;Reset var to Monday position
  48.         {goto weekhurdle}                      ;Return to schedulesetup
  49. {}
  50.  
  51.                  ;processline - this function sets up the variables used in
  52.                  ; loop to process tasks.  It checks first to see if the 
  53.                  ; current line is to be executed today, if it is then it
  54.                  ; read the time and compares it to the current time.  This
  55.                  ; lets the program skip task times which have already
  56.                  ; passed when you begin the program.  Finally it reads the
  57.                  ; task it is to execute and returns control to the loop.
  58. {:processline}
  59.         {call getline}                         ;Read an entire line into %line%
  60.         {subs dotoday,%dayoffset%,1,%line%}    ;Look for a " " in today's
  61.         {comp dotoday, } {ifco processline,}   ; location, if found skip line
  62.         {subs nexthour,1,2,%line%}             ;Read hours
  63.         {subs nextmin,4,2,%line%}              ;Read minutes
  64.         {setv nextcomp,%nexthour%%nextmin%}    ;Var to compare to current time
  65.         {setv now,%_24h%%_min%}                ;Make current military time var
  66.         {comp %now%,%nextcomp%}                ;Check if task time has passed
  67.         {ifco-g firstday,}                     ; 
  68. {:continue}
  69.         {subs nexttask,15,128,%line%}          ;read command line of task
  70.         {setv nexttime,%nexthour%:%nextmin%}   ;Set nexttime var
  71.         {return}
  72. {}
  73.  
  74.                 ;functions used by processline
  75.                 ;getline - reads an entire line from the schedule file into
  76.                 ; the variable line, it ignores lines that are too short
  77.                 ; and ignores lines that begin with the comment character "#"
  78. {:getline}
  79.         {read line}
  80.         {inst line,#}
  81.         {comp %_pos,1} {ifco getline,}
  82.         {leng %line%}
  83.         {comp %_len%,14} {ifco-le getline,}
  84.         {setv _len,}
  85.         {return}
  86. {}
  87.                 ;firstday - checks if program has just started today
  88.                 ; example: I start program at 6pm.  There are no tasks until
  89.                 ; tomorrow (i.e. program reads to end of file).  But when it
  90.                 ; finds the first task at 1am, we must process this task
  91.                 ; even though 6pm > 1am (this comparison is made above in
  92.                 ; processline).
  93. {:firstday}
  94.         {comp %day%,1}                         ;compare to first day
  95.         {ifco-g continue,processline}          ;if not first day continue
  96.                                                ; otherwise read next line 
  97. {}
  98.  
  99.                 ;loop - this is the main workhorse loop of program
  100. {:loop}
  101.         {call processline}                     ;Get time & task, see above
  102.         {display ,,,^m^j   Issuing:  %nexttask%^m^j} ;Bother user
  103.         {display ,,,        at:  %nexttime%^m^j}
  104.  {:wait}
  105.         {calook checktime,phonecall,RING}      ;look for RINGs
  106.         {lookfor Godot.}
  107.  {:checktime}
  108.         {setv now,%_24h%%_min%}                ;Make current military time var
  109.         {comp %nextcomp%,%now%}                ;Compare times
  110.         {ifco ,wait}                           ;If equal, continue, else wait
  111.         {comp %nexttask%,%quitcommand%}        ;Check if command is to quit
  112.         {ifco retu,}                           ;If so, quit
  113.         {call exectask}                        ;Otherwise execute task
  114.         {display ,,,^m^j   Command:  %nexttask%^m^j} ;Bother user again
  115.         {display ,,,  returned:  %_err%^m^j^m^j}
  116.         {goto loop}                            ;Re-loop
  117. {}
  118.  
  119.                 ;exectask - executes a command line & returns to caller
  120. {:exectask} {exec-w60 %nexttask%} {return} {}
  121.  
  122.                 ;phonecall - what to do when the phone rings, you could,
  123.                 ; for instance, load host macros, go into host mode, and
  124.                 ; answer the phone if you were so inclined, I just record
  125.                 ; the time 
  126. {:phonecall} {display ,,, at %_24h%:%_min%^m^j} {return} {}
  127.