home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Enigma Amiga Life 109
/
EnigmaAmiga109CD.iso
/
software
/
on-line
/
gmsuite
/
rexx
/
gmcleanconf.thor
< prev
next >
Wrap
Text File
|
2000-01-23
|
13KB
|
504 lines
/*
** $VER: GMCleanConf.thor 5.003 (23.01.00)
** © Gian Maria Calzolari <gcalzo@geocities.com>
**
** FUNCTION:
** Saving and purging messages from Thor Conferences
**
** Parameters:
** <none> to use Thor's RequestInteger function
**
** or
**
** MONTH message creation month to search
** YEAR message creation year to search
**
** $HISTORY:
**
** 23 Jan 2000 : 005.003 : To avoid unwanted "deadlock" the needed "signal on"
** routines have been created
** 07 Jan 2000 : 005.002 : Nothing, bumped up rev
** 21 Dec 1999 : 005.001 : Nothing, bumped up rev
** 17 Nov 1999 : 005.000 : Bumped up rev for consistency with first aminet
** release of GMsuite!
** Messages Unread or SuperUnread are not processed
** Added pack of Event, User, Kill & File data at script end
** 17 Nov 1999 : 000.013 : Got the way to use conference's KeepDays!
** Removed tag ARCHIVE in config file:
** if KeepDays is used then no messages are saved!
** 16 Nov 1999 : 000.012 : added directory search for execution within Thor
** 15 Nov 1999 : 000.011 : added validation to shell params
** 14 Nov 1999 : 000.010 : added external config file because there is no way
** to get the KeepDays or KeepMsgs from the Conference
** configuration! :-(
** 08 Nov 1999 : 000.009 : Added conference recursion
** 07 Nov 1999 : 000.008 : ...started migration to Thor...
** 11 Feb 1995 : 000.007 : Last EMS version...
**
*/
signal on syntax
signal on break_c
signal on failure
signal on halt
options results
VerStr = subword(sourceline(2),3)
parse arg SMonth SYear .
call Init
if address() ~= thorport then
address(thorport)
CurrentSystem stem Current
if rc = 1 then ExitMsg('This script must be called from INSIDE a Systme!')
if rc > 5 then signal error
ConfigFile = 'ENV:Thor/' || Current.BBSNAME || '_C.cfg'
/* default path & default KeepDays */
GETGLOBALCONFIG stem GLOBALDATA
if rc > 5 then signal error
AltPath = GLOBALDATA.SAVEDIR
if bittst(GLOBALDATA.FLAGS,GCB_IGNORE_KEEPTIME) then
GlbIgnoreKeepDays = true
else
GlbIgnoreKeepDays = false
/**/
call ReadConfig
call Validate
/*
** 15-11-99 RequestInteger is trashing TAGS.0 if keyword 'var' is used!
** Using 'result' solves the error!
*/
if SMonth = "" then do
REQUESTINTEGER MIN 1 MAX 12 TITLE '"Enter the Month number:"' BT '"Ok|Cancel"'
if rc = 5 then ExitMsg('Cancel button pressed!')
if rc > 5 then signal error
SMonth = result
end
if SYear = "" then do
REQUESTINTEGER MIN 1978 MAX 2050 TITLE '"Enter the Year:"' BT '"Ok|Cancel"'
if rc = 5 then ExitMsg('Cancel button pressed!')
if rc > 5 then signal error
SYear = result
end
LockGUI
address BBSREAD
GetConfList bbsname Current.BBSNAME stem ConfList
if rc > 5 then signal error
say ''
do k = 1 to ConfList.COUNT
CurrentConf = ConfList.k
GETCONFDATA bbsname Current.BBSNAME confname CurrentConf stem ConfData
if rc > 5 then signal error
/*
** Archive flag was a TAG in the external config file, now is set when
** KeepDays is not used neither in the conference nor in the global
** Thor's configuration!
*/
archive = false
if bittst(ConfData.FLAGS,CDB_IGNORE_KEEPTIME) then
archive = true
else
if bittst(ConfData.FLAGS,CDB_BBS_KEEPTIME) & GlbIgnoreKeepDays then
archive = true
index = SrcConf(CurrentConf)
if index = 0 then
index = SrcConf("DEFAULT")
if archive then do /* Archive, delete */
if symbol('Tags.index.PATH') ~= 'VAR' then
Tags.index.PATH = AltPath
if Smonth < 10 then
SaveFile = Tags.index.PATH || '/' || trim(left(CurrentConf,22)) || '_' || '0' || SMonth || '-' || SYear
else
SaveFile = Tags.index.PATH || '/' || trim(left(CurrentConf,22)) || '_' || SMonth || '-' || SYear
call SearchMsgs
end
PACKDATAFILE BbsName '"' || Current.BBSNAME || '"',
ConfName '"' || CurrentConf || '"',
ShowProgress
if rc > 5 then signal error
end
say ''
PACKDATAFILE BbsName '"' || Current.BBSNAME || '"',
EventData UserData KillData FileData,
ShowProgress
if rc > 5 then signal error
if address() ~= thorport then
address(thorport)
UnLockGUI
UPDATECONFWINDOW
if rc > 5 then signal error
if SavedDir ~= "" then
call Pragma(D,SavedDir)
exit 0
/* ...game over... */
/* Search loop in conference */
SearchMsgs:
drop msgs.
Msgs.0 = 0
MsgsNum = 0
do y = ConfData.FIRSTMSG to ConfData.LASTMSG
drop MsgHead.
ReadBRMessage bbsname '"' || Current.BBSNAME || '"',
confname '"' || CurrentConf || '"',
msgnr y,
headstem MsgHead datastem MsgData
if rc > 5 then signal error
if ~bittst(MsgData.FLAGS,MDB_DELETED) then do
/* My tests proved that 'Marked' means 'Unread' :-| */
if ~bittst(MsgData.FLAGS,MDB_MARKED) & ~bittst(MsgData.FLAGS,MDB_SUPERMARKED) then do
if symbol('MsgHead.CREATIONDATE') = "VAR" then do
Amiga2Date MsgHead.CREATIONDATE MsgD
if rc > 5 then signal error
if MsgD.month = SMonth & MsgD.year = SYear then do
MsgsNum = MsgsNum + 1
Msgs.MsgsNum = y
Msgs.MsgsNum.flags = MsgData.FLAGS
end
end
end
end
end
Msgs.0 = MsgsNum
if Msgs.0 ~= 0 then do
do i = 1 to Msgs.0
call GMarchive.thor Current.BBSNAME CurrentConf Msgs.i SaveFile
if result > 0 then signal error
if ~bittst(Msgs.i.flags,MDB_KEEP) & Tags.index.KEEP = false then do
UpdateBRMessage bbsname '"' || Current.BBSNAME || '"',
confname '"' || CurrentConf || '"',
msgnr Msgs.i,
SetDeleted
if rc > 5 then signal error
end
end
end
return
/* Searches the conference in the config
** parm1 conference to be searched
**
** returns the index or 0 if not found
*/
SrcConf:
cnfr = upper(arg(1))
do i = 1 to Tags.0
CONF = cnfr
if Tags.i.PAT = 0 then do
if CONF = Tags.i then return i
end
else do
select
when Tags.i.PAT = 1 then do
CONF = left(CONF, length(Tags.i))
if CONF = Tags.i then return i
end
when Tags.i.PAT = 2 then do
CONF = right(CONF, length(Tags.i))
if CONF = Tags.i then return i
end
when Tags.i.PAT = 3 then do
if index(CONF, Tags.i) > 0 then return i
end
end
end
end
return 0
Validate:
do i = 1 to Tags.0
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
end
end
return
/* Initialization */
Init:
p = ' ' || address() || ' ' || show('P',,)
thorport = pos(' THOR.',p)
if thorport > 0 then
thorport = word(substr(p,thorport+1),1)
else
ExitMsg('This script must be called from THOR!')
/* Load bbsread.library if necessary */
if ~show('p', 'BBSREAD') then do
address command
'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
'WaitForPort BBSREAD'
end
TPath = GetClip('ThorPath')
if TPath = "" then do
address command 'RXSET ThorPath="`GetEnv THOR/THORPath`"'
TPath = GetClip('ThorPath')
end
if right(TPath,1) ~= ":" & right(TPath,1) ~= "/" then
TPath = TPath || "/"
SavedDir = pragma(D,TPath || "rexx")
if SMonth ~= "" then
if SMonth < 1 | SMonth > 12 then
call ExitMsg(SMonth "is not a valid month!")
if SYear ~= "" then
if Syear < 1978 | SYear > 2050 then
call ExitMsg(SYear "is not a valid year!")
/* from $VER: GlobalDefs.br 4.2 (9.9.97) */
/* Bit numbers for message flags */
MDB_READ = 0 /* Message is read. */
MDB_REPLIED = 1 /* Message is replied. */
MDB_PRIVATE = 2 /* Message is private. */
MDB_TO_USER = 3 /* Message is to the user. */
MDB_FROM_USER = 4 /* Message is from the user. */
MDB_DELETED = 5 /* Message is deleted. */
MDB_UNRECOVERABLE = 6 /* Message is can not be undeleted. */
MDB_KEEP = 7 /* Keep message. Message will not be deleted during conference packing. */
MDB_TO_ALL = 8 /* Message is to all. (has no reciever) */
MDB_XPK_TEXT = 9 /* Message text is Xpk'ed. (Private flag) */
MDB_MARKED = 10 /* Message is marked. */
MDB_URGENT = 11 /* Message is urgent. */
MDB_IMPORTANT = 12 /* Message is important. */
MDB_SUPERMARKED = 13 /* Message will not be unmarked as long as this flag is set. */
MDB_BINARY_PARTS = 14 /* Message contains 1 or more binary parts. */
MDB_TEXT_PARTS = 15 /* Message contains 1 or more extra text parts. */
/* These two flags does also concern possible message parts. */
MDB_MESSAGE_PARTS = 16 /* Message contains 1 or more message parts. */
MDB_HAZE_BIT0 = 24 /* Message haze level bit 0. */
MDB_HAZE_BIT1 = 25 /* Message haze level bit 1. */
/* Bit numbers for conference data */
CDB_BBS_KEEPMSG = 9 /* Use bbs KeepMsg. */
CDB_BBS_KEEPTIME = 10 /* Use bbs KeepTime. */
CDB_IGNORE_KEEPMSG = 11 /* Don't count messages when packing conference. */
CDB_IGNORE_KEEPTIME = 12 /* Don't check time when packing conference. */
/* Bit numbers for global data flags */
GCB_IGNORE_KEEPMSG = 0 /* Don't count messages when packing conferences. */
GCB_IGNORE_KEEPTIME = 1 /* Don't check time when packing conferences. */
true = 1
false = 0
/* This tags can be omitted, default will be "blank" */
TagOptsBlk = "Path"
/* This tags can be omitted, default will be "zero" */
TagOptsZro = "Keep"
TagOptions = "" TagOptsBlk TagOptsZro /* no tags are required... */
NumOpts = words(TagOptions)
return
ReadConfig:
/* Tags.0 will contains the Conference numbers, Tags.X will be the
** Conference name (without the "*" if used...)
** Tags.X.y will be defined as follow:
** Tags.X.Path Full path where msgs will be saved, default is "Thor Save Dir"
** Tags.X.Keep if msg saved: 1 = do not delete msg 0 = delete it (default 0)
** Tags.X.Pat internal field: 0=no pattern, 1=on right, 2=on left, 3=both
*/
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
pattern = 0
if right(CfgVal,1) = '*' then
pattern = pattern +1
if left(CfgVal,1) = '*' then
pattern = pattern +2
CfgVal = compress(CfgVal,'*')
Tags.TagsNum.PAT = pattern
Tags.TagsNum = upper(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
/* Exit with a message */
ExitMsg:
parse arg msgstr
if thorport > 0 then do
if address() ~= thorport then
address(thorport)
UnLockGUI
end
if SavedDir ~= "" then
call Pragma(D,SavedDir)
address command
'RequestChoice >NIL: "GMCleanConf.thor" "'msgstr'" "OK :-("'
exit
error:
syntax:
BEAK_C:
FAILURE:
HALT:
if SavedDir ~= "" then
call Pragma(D,SavedDir)
say '|'
say '|' VerStr
say '| ***BREAK: error at' sigl ',' rc ',' ErrorText(rc)
if symbol('THOR.LASTERROR') = 'VAR' then do
say '|'
say '| * Thor.LastError =' THOR.LASTERROR
end
if symbol('BBSREAD.LASTERROR') = 'VAR' then do
say '|'
say '| * BBSread.LastError =' BBSREAD.LASTERROR
end
if address() ~= thorport then
address(thorport)
UnLockGUI
exit rc