TIP: Click on subject to list as thread! ANSI
echo: 4dos
to: ALL
from: Jasen Betts
date: 2003-12-02 20:01:52
subject: sched.btm - dayboot replacemnt

Path: internal1.nntp.ash.giganews.com!border2.nntp.ash.giganews.com!border1.nntp.ash.giganews.com!firehose2!nntp4!intern1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeed.tpinternet.pl!newsfeed.gazeta.pl!news.atman.pl!news.intercom.pl!f124.n480!f127.n480!f112.n480!f200.n2432!f605.n774!f954.n640!f531.n640!f1042.n640!not-for-mail
Newsgroups: fido.4dos
Distribution: fido
From: Jasen Betts 
Date: Tue, 02 Dec 03 20:01:52 +0100
Subject: sched.btm - dayboot replacemnt
Message-ID: 
Organization: Black Holes were created when God divided by zero!
 2443/1181
Lines: 423
Xref: intern1.nntp.aus1.giganews.com fido.4dos:455

Hi All.

recently I was aked to modify dayboot to allow a task to be schedules for
the same day of every month... looking at the source I could see no easy
way to add that feature while maitaining all the other features and keeping
the code tidy, So I ripped its guts out and started again.

as a result the data file is different... but it's got a half dozen new
capabilities and should be easier to extend....

I guess now I've put myself in the front-line for change requests.... :)

anyway here's it is...

:! SCHED.BTM                             VERSION 1.0  dec-2003
:!
:! Sched is by Jasen Betts, it is based on a btm program called Dayboot
:! which was developed by Gerald Miller and Jasen Betts which was based
:! on a btm pprogram by Klaus Meinhard called xbootex
:!
:!  Gerald Miller        Jasen Betts           Klaus Meinhard
:!  Fidonet 1:342/512    Fidonet 3:640/1042    Brahmsstr. 12
:!                                             G 26842 Ostrhauderfehn
:!                       jasen_betts@f1042.    Germany
:!                       n640.z3.fidonet.org   Compuserve 100115,2025
:!
:!

:: lines containing : and ! together appear in the "help" listing
:: they may occur anywhere in this file.

:!
:!       this is not the dayboot.btm you've used before
:!
:!                THE DATA FORMAT IS DIFFERENT
:!
:!   you will have to hand-edit the file to to new format
:!   it's not that hard to do, see the notes below for copnverting
:!   dayboot rules to Sched rules.
:!
:!
:!
:!        S C H E D U L I N G   R U L E S
:!
:!
:!  Pnn  periodical every nn days
:!          tries to have exactly nn days between runs compensates for late
:!          runs
:!          (this is like the "plus rule" of dayboot except for +365 and +366)
:!
:!  Wnn  Wait nn days
:!           runs after nn days have elapsed
:!           (this is the normal dayboot behavior)
:!
:!  Dnn  day-of-month
:!           runs only on day NN of the month
:!           negative numbers count from the end of the month
:!
:!  Mnn  month
:!          runs only during month nn (can list multiple months)
:!          (a combination of D and M rules nay be an apropriate replacemnt
:!          for a +365 dayboot rule)
:!
:!  A    ask
:!          prompt confirmation before running
:!          (this is the ASK=YES of dayboot)
:!
:!  Rnn  random
:!          run with nn% probability
:!
:!  Nn   Day of week
:!          only run on the given days of the week, multiple day-numbers
:!          may appear after the N
:!
:!  O    Option
:!          this rule causes the contents of the
:!          program name field to be ised to set program options
:!          setting an option only effects the lines below it.
:!
:!
:!                S O M E   E X A M P L E   R U L E S
:!
:!      Description             Rule
:!
:!   JB's birthday              M6D27
:!   first day of each season   M3M6M9M12D1
:!   once a week                P7
:!   weekdays                   N12345
:!   again after 4 days         W4
:!   20 percent of the time     R20
:!   first monday of the month  D1D2D3D4D5D6D7N1
:!   first weekday of the month D1D2D3D4D5D6D7N12345W7
:!   last sunday of the month   d-1d-2d-3d-4d-5d-6d-7n0
:!   always use this option     O
:!   this option on sunday only ON0
:!
:!
:!  Documnted Options
:!
:!  SILENCE=Y       - never beep before asking  (rule A)
:!  SILENCE=1       - beep before the first ask only
:!  RAPID=x         - don't delay after running progs (anything for "x")
:!
:! (other options could have effects but theey probably
:!  won't be desirable effects)
:!
:!
:!
:!  INVOOCATION
:!
:!  Call SCHED.BTM from your autoexec.bat.
:!
:!
:!
:! CONVERTING FROM DAYBOOT
:!
:! create a new shaed.dat file and append the dayboot.dat file to it
:! (copy sched.dat+dayboot.dat)
:! then edit the file to fix the fields up.
:!
:! the last-run and program name fileds can stay the same
:! (but the programs name field is now wider) the after-days field has been
:! repalced by the rules field, the other fields are no longer present -
:! the program didn't use them anyway
:!
:! nnnn  the normal dayboot after_days rule is the W rule
:!       so repalce nnnn in after_days with Wnnnn in RULE
:! +nnn  the +nnnn rule is now the P rule (use Pnnnn)
:! +365  the +365 / +366 rules no longer exist use instead a
:!       combination of the M ans D rules (like the example JB's Birthday)
:!
:!
:!
:!      4DOS  VERSION COMPATIBILITY
:!
:! This .BTM was created and tested for use with 4DOS version 6.02B.
:! and version 7.02A it will not work with earlier versions of 4dos.
:!
:!
:!
:!     LEGAL STUFF
:!
:! As far as I am able to determine the software that this program is
:! based on was in the public domain, all the bits I wrote are also.
:!
:! As a user you are responsible for determining the usefullnes for any
:! particular purpose of this software.
:!
:! This is free software as such you are entilteld to a full refund of the
:! purchase price if you are not completely satisfied :)
:!
:! if it breaksyou get to keep the pieces.
:!
:!  Enjoy!

:START
  *setlocal %+ *unalias *
  break on
  on break goto END
  if "%temp" eq "" set temp=C:\


::  Next command establishes the location of the variable "BOOTFILE"
::  (btm_name.DAT) [should be in the same directory as this BTM file...]
  set bootfile=%@path[%@search[%0]]%@upper[%@name[%0]].DAT

::  Next command establishes the location and name of the variable
::  "TEMPFILE" that holds the temporary file information while the
::  action is performed.
  set tempfile=%@unique[%temp]

::  User input
  if [%1]==[-?] .or. [%1]==[/?] .or. [%1]==[?] .or. %=
[%1]==[-h] .or. [%1]==[/h] .or. [%1]==[h] .or. %=
[%1]==[-H] .or. [%1]==[/H] .or. [%1]==[H] goto USAGE

::  df is local date format.
set df=%@replace[2,D,%@replace[20,YY,%@replace[1,M,%@makedate[14936]]]]

if "%1"=="HELP" .or. "/HELP"=="%1" .or. "%1"=="-HELP" %=
 ( *ffind  /VMKT"%@char[58]!" %_BATCHNAME | *list %+ goto usage )


::  Is the file SCHED.DAT there?
  iff not exist %bootfile then

   if [%1]==[DATAFILE] .or. [/DATAFILE]==[%1] .or. [%1]==[-DATAFILE] %=
    ( set tempfile=%bootfile %+ gosub tempfile %+ goto fin )

    echo.
    color bri red on bri whi
    echo ERROR: %@path[%@search[%0]]%@upper[%@name[%0]].DAT was not found!
    echo do "%0 datafile" to create a new (empty) one
    color bri cya on bla
    echo. %+ pause
    goto fin
  endiff

 if [%1]==[DATAFILE] .or. [/DATAFILE]==[%1] .or. [%1]==[-DATAFILE] %=
 ( echo Not overwriting %bootfile - it already exists %+ goto fin )

::  Set variables. If DAYBOOT1 did it's job today already or it's before
::  00:01 am, do nothing. In this case, the "start" time is 00:01 am....
::  Change the %do_time variable to suit your requirements.
  set lastdate=%@date[%@filedate[%bootfile]]
  set today=%@date[%_date]
  set do_time=00:01

  iff %@eval[%lastdate - %today] eq 0 .or. %@eval[%@time[%_time] - %=
%@time[%do_time]] le 0 then
    echo. %+ echo.
    color bri red on bri whi
    echos There is nothing to do today because it's all been done!
    color bri cya on bla
    echo.
    goto fin
  endiff

::  Read DAYBOOT1.DAT, look at which programs to run today, copy info to
::  UNIQUE.TMP and update DAYBOOT1.DAT
  set i=0
  echo.

gosub tempfile
echo PATH\PROGRAM TO RUN                          ³LAST RUN³ RULE >%tempfile
echo ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅ%df%ÅÄÄÄÄÄÄÄÄÄ >> %tempfile

set orig=%@instr[46,8,%@line[%bootfile,1]]

iff %orig == %df then
  set dateconversion=%%date
else
::  Build a date conversion expression in a variable...
  set dateconversion=%=
%%@instr[%@index[%orig,%@instr[0,2,%df]],2,%%date]%@instr[2,1,%df]%=
%%@instr[%@index[%orig,%@instr[3,2,%df]],2,%%date]%@instr[5,1,%df]%=
%%@instr[%@index[%orig,%@instr[6,2,%df]],2,%%date]
echo.
echo  Converting date format from %orig to %df using expression:
echo.
set dateconversion
endiff
unset orig df

set MONTHDAYS=33-%@day[%@makedate[%@eval[%@date[%_DATE]-%@day[%_DATE]+33]]]
set MONTHDAYS=%@eval[%MONTHDAYS]
:: number of days in this month - used for negatives in the D rule

do n=2 to %@lines[%bootfile]
  set prog=%@instr[0,45,%@line[%bootfile,%n]]
  set RULES=%@instr[55,,%@line[%bootfile,%n]]
::  Convert last to local format
  set date=%@instr[46,8,%@line[%bootfile,%n]]
  set last=%dateconversion

  if "%prog" == "" iterate

  unset /q R V RULE_ RULE_P RULE_W RULE_D RULE_M RULE_A RULE_R RULE_N RULE_O

    set RULE=%RULES%.
  do while "%RULE" ne ""
     set X=%@instr[0,1,%RULE]
     set RULE=%@instr[1,99,%RULE]

     iff "%X" == "" then
     elseiff %@index[+-0123456789,%x] ne -1 then
        set V=%V%%X
     else
        if "%V" == "" set V=0
        if "%[RULE_%R]" ne "" set V= %V
        set RULE_%R=%[RULE_%R]%V
        set V=
        SET R=%X
     endiff
  enddo

  if %RULE_ == 0 set RULE_=
  unset /q X V R

  set RUNDATE=%_DATE

  gosub interpret_rules

  echo %@format[-45.45,%prog]³%@format[-8.8,%last ]³%RULES>>%tempfile
  unset/q prog RULES RUNDATE LAST
  unset /q R V RULE_ RULE_P RULE_W RULE_D RULE_M RULE_A RULE_R RULE_N RULE_O

enddo

  unset/q next,
  move/q/u %tempfile %bootfile >& nul
    iff "%ITEM" gt "0" then
      do m=1 to %ITEM
        echo. %+ echo.
        color bri whi on whi
        echos %@upper[%0] Program Execution:
        color bri cya on bla
        echo  %@upper[%[run%m]]
        echo.
        call %[run%m]
        @echo off
      enddo
    endiff

    echo.
    color bri red on bri whi
    echos %@upper[%0] END
    color bri cya on bla
    echo.

:END
    color bri cya on bla
    if "%item" ne "" if "%RAPID"=="" delay 5
    if exist %tempfile del/q %tempfile > nul
:fin
    endlocal
    color bri cya on bla
    quit

:interpret_rules

::  Implementation of the rules
::
:: note for programmers:
:: don't use shortcuts like %_DOW %_DAY %_MONTH, insteead use an expression
:: of _DATE  like %@DOW[%_DATE] that way SET _DATE=... can be used for
:: debugging purposes instead of fiddling with the system date...


iff "%RULE_W" gt "0" then
   if %@eval[%today-%@date[0%last]] lt %@word[0,%RULE_W] return
endiff

iff "%RULE_P" gt "0" then
  if %@eval[%today-%@date[0%last]] lt %@word[0,%RULE_P] return
  if "%last" ne "" set RUNDATE=%@makedate[ %@eval[ %@date[%last] + %=
  ( %today - %@date[%last] ) \ %RULE_P * %RULE_P] ]
endiff

iff "%RULE_R" gt "0" then
  set RULE_R=%@word[0,%RULE_R]
  if %@random[0,99] ge %RULE_R return
endiff

iff "%RULE_D" ne "" then
  for D in (%RULE_D) do set X=%X %@IF[%d gt 0,%d,%@eval[%D+1+%MONTHDAYS]]
  if %@index[ %X , %@DAY[%_DATE] ] == -1 return
endiff


iff "%RULE_M" gt "0" then
  if %@index[ %RULE_M , %@MONTH[%_DATE] ] == -1 return
endiff

iff "%RULE_N" ne "" then
  if %@index[%RULE_N,%@EVAL[(2+%TODAY) %% 7]] == -1 return
endiff

iff "%RULE_A" ne "" then
   iff "%SILENT" ne "Y" then
      beep 294 2 330 2 277 2 294 2 330 2 277 2 294 2 330 2 277 2 294 2
      beep 330 2 0 2 139 2 165 2 196 2 233 2 277 2 466 2 554 2 659 2
      beep 784 2 932 2
   endiff
   if "%SILENT" == "1" then set SILENT=Y
   scrput %_row %@eval[17+%@len[%prog]] bri yel on bla `Y`
   inkey /c/K"YN[esc][enter]" `Execute `%@upper[%prog]` [Y/N] ?` %%X
   echo. %+ echo.
   if not "%X" ne "Y" .and. "%X" ne "@28" return
 endiff

 iF "%RULE_O" ne "" ( set %prog %+ goto nilrun )
  set item=%@inc[%item]
  set run%item=%prog
:nilrun
  set last=%RUNDATE
:norun

return

:tempfile
::   0123456789012345678901234567890123456789012345678901234567890
echo PATH\PROGRAM TO RUN                          ³LAST RUN³ RULE >%tempfile
echo ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅ%df%ÅÄÄÄÄÄÄÄÄÄ >>%tempfile
return

:USAGE
    color bri cya on bla
    text
  ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³ SCHED                   Once a day program execution with many options  ³
  ³                         (selectable intervals, ask before execution).   ³
  ³                         For more info see the header of this file.      ³
  ³                                                                         ³
  ³                         SCHED.DAT is the data file for SCHED.BTM,       ³
  ³                         where you can enter your progs and parameters.  ³
  ³                         It _must_ be in your path or the root dir of    ³
  ³                         your boot drive.                                ³
  ³                                                                         ³
  ³                         SCHED should be CALLed from autoexec.bat        ³
  ³                         or executed atleast once daily in some other way³
  ³                                                                         ³
  ³ Optional parameters:                                                    ³
  ³                                                                         ³
  ³               (none)    run tasks as described above                    ³
  ³  /H /?         (etc)    show this message                               ³
  ³  DATAFILE               create a blank data file                        ³
  ³                                                                         ³
  ³  HELP                   view the program notes, history and rule help   ³
  ³                         (many pages of help)                            ³
  ³                                                                         ³
endtext
echos   À%@repeat[Ä,73]Ù
    goto fin







 -=> Bye <=-

SOURCE: echoes via archive.org

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.