home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Enigma Amiga Life 109
/
EnigmaAmiga109CD.iso
/
software
/
on-line
/
gmsuite
/
rexx
/
gmautowrite.thor
< prev
next >
Wrap
Text File
|
2000-01-23
|
9KB
|
335 lines
/*
** $VER: GMAutoWrite.thor 5.003 (23.01.00)
** © Gian Maria Calzolari <gcalzo@geocities.com>
**
** Thanks to Neil Bothwick to let me use his AutoReply as a start base
** for the adaption of my script originally written for EMS (FidoNet
** mailer)
**
** FUNCTION:
** Automatically write a message at desired intervals, can be called
** anytime but's best to call it at Thor startup
**
** $HISTORY:
**
** 23 Jan 2000 : 005.003 : Nothing, bumped up rev
** 07 Jan 2000 : 005.002 : Nothing, bumped up rev
** 21 Dec 1999 : 005.001 : added CC and BCC headers
** 17 Nov 1999 : 005.000 : Nothing! Bumped up rev for consistency with first
** aminet release of GMsuite!
** 08 Nov 1999 : 004.003 : Version for GMsuite v1.0
** 23 Oct 1999 : 004.002 : Added "First-Of-Month" support for Kimme Utsi and,
** since it was easy, also a "fixed-day-of-the-month" too! :-)
** 17 Oct 1999 : 004.001 : added options ExtPgm & ExtPgmType (Simone "Wiz" Tellini)
** 16 Oct 1999 : 004.000 : First public version!! :-)
** 15 Oct 1999 : 003.007 : First internal beta! OptionalTags are ignored... :-(
** 11 Oct 1999 : 003.006 : Started adaption to Thor
**
** v3.0 11-10-93 Version for EMS 1.0
** v2.0 28-06-93 Version for GCC 4.0
**
*/
VerStr = subword(sourceline(2),3)
ConfigFile = 'ENV:Thor/GMAutoWrite.cfg'
true = 1
false = 0
/* This tags can be omitted, default will be "blank" */
TagOptsBlk = "ToName CcAddr BccAddr Subject SigFile HdrFile FtrFile ExtPgm"
/* This tags can be omitted, default will be "zero" */
TagOptsZro = "ExtPgmType Prog_PVT Date_PVT"
TagOptions = "System Conf Active Days BdyFile ToAddr" TagOptsBlk TagOptsZro
NumOpts = words(TagOptions)
/* Load bbsread.library if necessary */
if ~show('p', 'BBSREAD') then do
address command
'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
'WaitForPort BBSREAD'
end
call ReadConfig
if Tags.0 > 0 then do
progr = date('I')
today = Dom()
do i = 1 to Tags.0
call Validate
if (Tags.i.ACTIVE) then do
OkToGo = false
if Tags.i.DAYS < 0 then do
if today = abs(Tags.i.DAYS) then
OkToGo = true
end
else
if progr - Tags.i.PROG_PVT >= Tags.i.DAYS then
OkToGo = true
if OkToGo then do
if Tags.i.EXTPGM ~= '' then ExecutePgm(Tags.i.EXTPGM, Tags.i.EXTPGMTYPE, Tags.i.BDYFILE)
call WriteMsg
Tags.i.PROG_PVT = progr
Tags.i.DATE_PVT = date('E')
end
end
end
call WriteConfig
end
exit
/* ...game over... */
Validate:
do y = 1 to NumOpts
Opt = upper(word(TagOptions, y))
OptDef = symbol('Tags.i.Opt')
Select
When find(upper(TagOptsBlk),Opt) > 0 then
if OptDef ~= 'VAR' then Tags.i.Opt = ''
When find(upper(TagOptsZro),Opt) > 0 then
if OptDef ~= 'VAR' then Tags.i.Opt = 0
Otherwise
if OptDef ~= 'VAR' then call ExitMsg("'" || Opt || "' not defined in tag '" || Tags.i || "'")
end
if Opt = 'EXTPGM' & Tags.i.Opt ~='' & pos('%F',upper(Tags.i.Opt)) = 0 then
call ExitMsg("%F in '" || Opt || "' missing in tag '" || Tags.i || "'")
end
return
ExecutePgm:
/*
** This will process an external pgm or arexx script to create the
** message body
*/
InsertPos = pos('%F',upper( arg(1) ))
Pgm = left(arg(1),InsertPos-1) || arg(3) || substr(arg(1),InsertPos+2)
if Arg(2) = 0 then /* Arexx */
Pgm
else /* dos */
address command Pgm
return RESULT
WriteMsg:
address BBSREAD
drop MsgBody. MsgHead.
/* Create message file */
UNIQUEMSGFILE bbsname '"'Tags.i.System'"' stem MsgFile
if ~open(out,MsgFile.NAME,'w') then call ExitMsg('Unable to create message file')
/* Write headers */
headline = 'X-Generator:' VerStr
call writeln(out,headline)
if Tags.i.HDRFILE ~= '' then do
if ~open(headers,Tags.i.HDRFILE,'R') then call ExitMsg('Unable to open header file' Tags.i.HDRFILE)
do until eof(headers)
call writeln(out,readln(headers))
end
call close(headers)
end
if Tags.i.CCADDR ~= '' then
call writeln(out,'Cc:' Tags.i.CCADDR)
if Tags.i.BCCADDR ~= '' then
call writeln(out,'bcc:' Tags.i.BCCADDR)
call writeln(out,'')
/* Write message body */
if ~open(body,Tags.i.BDYFILE,'R') then call ExitMsg('Unable to open body file' Tags.i.BDYFILE)
do until eof(body)
call writeln(out,readln(body))
end
call close(body)
/* Add signature */
if Tags.i.SIGFILE ~= '' then do
if ~open(sig,Tags.i.SIGFILE,'R') then call ExitMsg('Unable to open signature file' Tags.i.SIGFILE)
do until eof(sig)
call writeln(out,readln(sig))
end
call close(sig)
end
/* Add footer file */
if Tags.i.FTRFILE ~= '' then do
if ~open(foot,Tags.i.FTRFILE,'R') then call ExitMsg('Unable to open footer file' Tags.i.FTRFILE)
do until eof(foot)
call writeln(out,readln(foot))
end
call close(foot)
end
call close(out)
/* Create EMail event */
drop EventData.
EventData.TONAME = Tags.i.TONAME
EventData.TOADDR = Tags.i.TOADDR
EventData.SUBJECT = Tags.i.SUBJECT
EventData.CONFERENCE = Tags.i.CONF
EventData.MSGFILE = MsgFile.FILEPART
WRITEBREVENT bbsname '"'Tags.i.SYSTEM'"' event 0 stem EventData
if RC > 0 then call ExitMsg(BBSREAD.LASTERROR)
return
ReadConfig:
/* Tags.0 will contains the tag numbers, Tags.X will contains the tag name
** Tags.X.y will be defined as follow:
** Tags.X.System System name
** Tags.X.Conf Conference name
** Tags.X.ToName To user name
** Tags.X.ToAddr To user address
** Tags.X.Subject Message subject
** Tags.X.BdyFile File to be used as message body
** Tags.X.SigFile File to be used as message sign
** Tags.X.HdrFile File to be used as message header
** Tags.X.FtrFile File to be used as message footer
** Tags.X.ExtPgm External pgm that will create the BdyFile
** Tags.X.ExtPgmType External pgm type (0 = ARexx / 1 = dos)
** Tags.X.Days Post message every Y days
** Tags.X.Active Tags.X active or not? (1 = True / 0 = False)
** Tags.X.Prog_PVT Progressive number, private field updated by the pgm!
** Tags.X.Date_PVT Last posted date, private field updated by the pgm!
*/
drop Tags.
Tags.0 = 0
TagsNum = 0
CfgOpen = open(cfgfile,ConfigFile,'r')
if ~(CfgOpen) then call ExitMsg('Reading: failed to open' ConfigFile)
do until eof(cfgfile)
nextline = readln(cfgfile)
if compress(nextline) = "" then iterate
parse var nextline CfgName CfgVal
CfgName = upper(CfgName)
CfgVal = strip(compress(CfgVal,'"'))
if CfgName = 'TAG' then do
TagsNum = TagsNum + 1
Tags.TagsNum = CfgVal
end
else do
if TagsNum = 0 then call ExitMsg('No Tag names found!')
if find(upper(TagOptions), CfgName) > 0 then
Tags.TagsNum.CfgName = CfgVal
else
call ExitMsg("Option '" || CfgName || "' (with value '" || CfgVal || "') in tag '" || Tags.TagsNum || "' not allowed!")
end
end
if TagsNum = 0 then call ExitMsg('No Tag names found!')
Tags.0 = TagsNum
if (CfgOpen) then dummy = close(cfgfile)
return
WriteConfig:
CfgOpen = open(cfgfile,ConfigFile,'W')
if ~(CfgOpen) then call ExitMsg('Saving: failed to open' ConfigFile)
NL = trunc( length(TagOptions) / NumOpts)
NL = NL + trunc( (length(TagOptions) - NL) / NumOpts)
do x = 1 to Tags.0
call writeln(cfgfile,'TAG ' Tags.x)
do y = 1 to NumOpts
OptL = word(TagOptions, y)
Opt = upper(OptL)
if Tags.x.Opt ~= "" & Tags.x.Opt ~= 0 | Opt = 'ACTIVE' then do
if pos(" ",Tags.x.Opt) > 0 then
call writeln(cfgfile,' ' || pad(OptL,NL) || '"' || Tags.x.Opt || '"')
else
call writeln(cfgfile,' ' || pad(OptL,NL) || Tags.x.Opt)
end
end
call writeln(cfgfile,'')
end
if (CfgOpen) then dummy = close(cfgfile)
address command 'copy >NIL: clone' ConfigFile 'EnvArc:Thor'
return
/*
** Returns the current Day number
*/
Dom:
return Word( Date(N), 1)
/* pad a string with blank to the left
** parm1 string to be padded with blank
** parm2 new lenght
*/
Pad:
return left( arg(1) || copies(' ', arg(2) ), arg(2) )
/* Exit with a message */
ExitMsg:
parse arg msgstr
address command
if symbol('MsgFile.NAME') = 'VAR' then do
call close(out)
'delete >NIL:' MsgFile.NAME
end
'RequestChoice >NIL: "GMAutoWrite.thor" "'msgstr'" "OK :-("'
exit