home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: SysTools
/
SysTools.zip
/
chrdmo.zip
/
CHRONAT.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1994-01-17
|
14KB
|
492 lines
/**
*** ┌───────────────────────────────────────────────────────────────────┐
*** │ ChronAt v1.0 │
*** │═══════════════════════════════════════════════════════════════════│
*** │ This will parse the command line parameters, validate the input │
*** │ and call the EXE to pass the command line information to the │
*** │ Chron application. REXX was chosen to handle the parsing since │
*** │ it is considerably more adept than C at this. It is the intent │
*** │ for the functionality of this code to be incorporated into the │
*** │ executable. │
*** │═══════════════════════════════════════════════════════════════════│
*** │ Copyright (c) 1993, Hilbert Computing │
*** └───────────────────────────────────────────────────────────────────┘
**/
call LoadFunctions
parse arg Options
/* Set default options */
Opt. = ''
Opt.Flag.F = 'o'
Opt.Parm.1 = date('U')
Opt.Parm.2 = left(time(),5)
call ParseOptions Options
if Opt.Parm.1 = '=' then Opt.Parm.1 = date('U')
if Opt.Parm.2 = '=' then Opt.Parm.2 = left(time(),5)
if Opt.Flag.SYNTAX = '+' then
call Syntax
/* Determine the event type */
select
when Opt.Flag.P <> '' then
EventType = 'P'
when Opt.Flag.M <> '' then
EventType = 'M'
otherwise
do
say 'You must enter a required parameter flag of "-P" (for program) or "-M" (for'
say 'message) event.'
say
call Syntax
end
end /* select */
StartDate = ValidateDate(Opt.Parm.1)
StartTime = ValidateTime(Opt.Parm.2)
Freq = ValidateFreq(Opt.Flag.F)
Shell = ValidateShell(Opt.Flag.S)
/* Make sure we can find the CHRONCLI command */
Cli = SysSearchPath("PATH","CHRONCLI.EXE")
if Cli = '' then
do
/* Look in the same directory as this exec */
Cli = ThisDirectory() || "\CHRONCLI.EXE"
if Exists(Cli) = 0 then
do
say "Cannot locate the CHRONCLI.EXE file."
exit
end
end
/* Handle the string values */
code = value("CHRON.PGM", Opt.Flag.P,"OS2ENVIRONMENT")
code = value("CHRON.PARM", Opt.Flag.A,"OS2ENVIRONMENT")
code = value("CHRON.DIR", Opt.Flag.D,"OS2ENVIRONMENT")
code = value("CHRON.MESSAGE",Opt.Flag.M,"OS2ENVIRONMENT")
code = value("CHRON.NAME", Opt.Flag.N,"OS2ENVIRONMENT")
'@'Cli '"'EventType StartDate StartTime Freq Shell'"'
exit
ValidateFreq: procedure
/**
*** This will validate the frequency
**/
arg Freq 2 Ord
select
when Freq = 'O' then nop
when Freq = 'H' then nop
when Freq = 'K' then nop
when Freq = 'D' then nop
when Freq = 'W' then nop
when Freq = 'M' then nop
when Freq = 'Y' then nop
otherwise
do
say "Invalid frequency"
say
call Syntax
end
end /* select */
if Ord = '' then
Ord = 1
if datatype(Ord,"N") = 0 then
do
say "Invalid frequency"
say
call Syntax
end
if Ord <= 0 then
do
say "Invalid frequency"
say
call Syntax
end
return Freq Ord
ValidateDate: procedure
/**
*** This will validate the date passed and reformat it to a consistent
*** format.
**/
parse arg PassedDate
select
when pos('-',PassedDate) > 0 then
parse var PassedDate mm '-' dd '-' yy
when pos('/',PassedDate) > 0 then
parse var PassedDate mm '/' dd '/' yy
when pos('.',PassedDate) > 0 then
parse var PassedDate mm '.' dd '.' yy
otherwise
do
say 'Invalid date.'
say
call Syntax
end
end /* select */
/* Make sure the year is numeric */
Numeric = datatype(mm,"N") + datatype(dd,"N") + datatype(yy,"N")
if Numeric <> 3 then
do
say "Invalid date."
say
call Syntax
end
/* Make sure the year is the full 4 digits */
if yy < 100 then
yy = 1900 + yy
/* Check Ranges */
if mm < 1 | mm > 12 then
do
say "Invalid date."
say
call Syntax
end
select
when mm = 1 then MaxDays = 31
when mm = 2 then MaxDays = 29
when mm = 3 then MaxDays = 31
when mm = 4 then MaxDays = 30
when mm = 5 then MaxDays = 31
when mm = 6 then MaxDays = 30
when mm = 7 then MaxDays = 31
when mm = 8 then MaxDays = 31
when mm = 9 then MaxDays = 30
when mm = 10 then MaxDays = 31
when mm = 11 then MaxDays = 30
when mm = 12 then MaxDays = 31
otherwise
nop
end /* select */
/* Validate the days */
if dd < 1 | dd > MaxDays then
do
say "Invalid date."
say
call Syntax
end
return mm'/'dd'/'yy
ValidateTime: procedure
/**
*** This will validate the time and return a time of consistent format
**/
parse arg PassedTime
select
when pos(':',PassedTime) > 0 then
parse var PassedTime hh ':' mm
when pos('.',PassedTime) > 0 then
parse var PassedTime hh '.' mm
otherwise
do
say 'Invalid time.'
say
call Syntax
end
end /* select */
Numeric = datatype(hh,"N") + datatype(mm,"N")
if Numeric <> 2 then
do
say "Invalid time."
say
call Syntax
end
if hh < 0 | hh > 23 then
do
say "Invalid time."
say
call Syntax
end
if mm < 0 | mm > 59 then
do
say "Invalid time."
say
call Syntax
end
return hh':'mm
ValidateShell: procedure
/**
*** Validate the shell option
**/
parse arg Shell
select
when Shell = '' then Shell = '-'
when Shell = '-' then Shell = '-'
when Shell = '+' then Shell = '+'
otherwise
do
say 'Invalid shell switch.'
say
call Syntax
end
end /* Select */
return Shell
Syntax: procedure
/**
*** Display the syntax of the ChronAt command
**/
say 'Syntax - CHRONAT [mm-dd-yy|= [hh:ss]|=] [-fo|h|k|d|w|m|y[<n>]] [-p<pgmname>]'
say ' [-a<cmdlineparms>][-d<workingdir>][-m<message>][-n<name>][-s]'
say
say 'where: -f -- Scheduling frequency as follows (default is O - One time):'
say ' o - One Time h - Hours k - Weekdays'
say ' d - Days w - Weeks m - Months'
say ' y - Years'
say ' -p -- Executable program name'
say ' -a -- Command like parameters to the program'
say ' -d -- Working directory for the program'
say ' -m -- Message text'
say ' -n -- Name of the event'
say ' -s -- Run under command shell. Req''d for command files'
say
say 'Any parameter containing a blank must be surrounded by double quotes. A date'
say 'or time of "=" defaults to the current date or time.'
say
say 'Example: CHRONAT 11/22/93 4:53 -fk3 -m"This is a test message"'
say ' will schedule a message event for every 3 weekdays.'
exit
/**
*** ┌────────────────────────────────────────────────────────────────────────┐
*** │ Included routines │
*** └────────────────────────────────────────────────────────────────────────┘
**/
/* #include <io.rex> */
Close: procedure
arg file
message = stream(file,c,'CLOSE')
if (message \= 'READY:') & (message \= '') then
do
say 'Error: Close failure on' file'.' message
exit
end
return file
Exists: procedure
arg file
file = stream(file,c,'QUERY EXIST')
if (file = '') then
return 0
else
return 1
Open: procedure
parse arg file, rw
rw = translate(rw)
select
when rw = 'WRITE' then
do
file_ = stream(file,c,'QUERY EXIST')
if file_ <> '' then
'@erase "'file'"'
end
when rw = 'APPEND' then
rw = ''
when rw = 'READ' then
nop
otherwise
rw = 'READ'
end /* select */
message = stream(file,c,'OPEN' rw)
if (message \= 'READY:') then
do
say 'Error: Open failure on' file'.' message
return message
end
return file
/* #include <system.rex> */
/**
*** ┌───────────────────────────────────────────────────────────────────────┐
*** │ Misc system functions │
*** └───────────────────────────────────────────────────────────────────────┘
**/
ThisDirectory: procedure
/**
*** This will return the directory from which this exec was run
**/
parse source . . ThisFile
LastSlash = lastpos('\', ThisFile)
ThisDir = left(ThisFile, (LastSlash-1))
return ThisDir
/* #include <parseopt.rex> */
ParseOptions: procedure expose Opt.
/**
*** This will parse the command line options. Those parameters that
*** begin with a minus (-) or forward slash (/) are considered flags
*** and are placed in Opt.Flag. The remaining options are placed
*** into Opt.parm.<x>.
***
*** NOTE: This code does not clear out the 'Opt.' stem variable since
*** the caller may want to establish defaults prior to calling
*** this code.
***
*** LIMITATIONS: The code currently only looks for the double quote
*** character ("). The apostrophe is treated like any other
*** character. The way this is currently coded, multiple blanks
*** in a quoted string are compressed to a single blanks and
*** probably should not be.
***
**/
parse arg arguments
Opt.Flag.List = ''
Opt.State = 'Normal'
j = 0
do i = 1 to words(arguments)
argument = word(arguments, i)
select
when Opt.State = 'Quoted Positional' then
do
/* Keep appending the words to this parm until an ending quote */
/* is found. */
Opt.Parm.j = Opt.Parm.j argument
if right(argument,1) = '"' then
do
Opt.Parm.j = strip(Opt.Parm.j, 'Both', '"')
Opt.State = 'Normal'
end
end
when Opt.State = 'Quoted Flag' then
do
/* Keep appending until the terminating quote is found */
Opt.Flag.Flagname = Opt.Flag.FlagName argument
if right(argument,1) = '"' then
do
Opt.Flag.Flagname = strip(Opt.Flag.Flagname, 'Both', '"')
Opt.State = 'Normal'
end
end
when Opt.State = 'Normal' then
do
FirstChar = left(argument, 1)
if ((FirstChar = '-') | (FirstChar = '/')) then
do
/* This is a flag. The value of the flag is the remainder of */
/* the string. If the remainder is the null string, then it */
/* has an implicit value of '+' implying "on" or "true" */
FlagName = substr(argument, 2, 1) /* Second character */
FlagName = translate(FlagName) /* Convert to uppercase */
/* See if this flag parm is quoted */
if substr(argument, 3, 1) = '"' then
Opt.State = 'Quoted Flag'
/* If any of the flag names are not a valid character for a REXX */
/* variable, we have to translate into a mnemonic. */
if ((FlagName < 'A') | (FlagName > 'Z')) then
do
select
when FlagName = '?' then FlagName = 'SYNTAX'
when FlagName = '!' then FlagName = 'BANG'
when FlagName = '*' then FlagName = 'STAR'
when FlagName = '#' then FlagName = 'POUND'
when FlagName = '$' then FlagName = 'DOLLAR'
when FlagName = '%' then FlagName = 'PERCENT'
when FlagName = '^' then FlagName = 'HAT'
when FlagName = '&' then FlagName = 'AMP'
when FlagName = '(' then FlagName = 'LPAR'
when FlagName = ')' then FlagName = 'RPAR'
when FlagName = '-' then FlagName = 'DASH'
when FlagName = '=' then FlagName = 'EQUAL'
otherwise /* Force a syntax message */
FlagName = 'SYNTAX'
end /* select */
end /* if */
FlagValue = substr(argument, 3) /* Remainder of string */
if FlagValue = '' then
FlagValue = '+'
Opt.Flag.FlagName = FlagValue
Opt.Flag.List = FlagName Opt.Flag.List
end
else /* it is a positional parameter */
do
j = j + 1
Opt.Parm.j = argument
if left(argument,1) = '"' then
Opt.State = 'Quoted Positional'
end
end /* 'Normal' */
otherwise
nop
end /* select */
end /* do i... */
Opt.Parm.0 = j
return
/* #include LoadFunctions.rex */
LoadFunctions: procedure
/**
*** This will load the DLL for the Rexx system functions supplied
*** with OS/2 v2.0
**/
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs
return