
/*   $VER: MailCheck.rexx 1.45 (28.04.98)   */
/*                                          */
/*   e-mail retreival with Miami and YAM    */
/*                                          */
/*  This script is part of MailCheck v1.45  */
/*    and may not be modified or copied     */
/*  without the authors written permission  */
/*                                          */
/*  ©1997-98 DCS Software by Robert Wilson  */

/*     Temp fix to work with YAM 2.0 P4     */

parse arg clioption

if ~show('l','rexxtricks.library') then do
  call addlib('rexxtricks.library',0,-30,0)
end

if ~show('l','rexxsupport.library') then do
  call addlib('rexxsupport.library',0,-30,0)
end

NL = '0A'x

requestdelay = ReadConfig('MailCheck:MailCheck.config','REQDELAY','1000')

if clioption = 'REQUEST' then do
  if ReadConfig('MailCheck:MailCheck.config','CHECKMODEM','1000') = '1' then do
    serialdevice = ReadConfig('MailCheck:MailCheck.config','SERIALDEVICE','1000')
    serialunit = ReadConfig('MailCheck:MailCheck.config','SERIALUNIT','1000')
    address 'COMMAND'
    'execute MailCheck:S/TestModem' serialdevice serialunit
    modemstatus = ReadEnv('MCModem')
    if modemstatus ~= 1 then do
      exit 5
    end
  end
  mcreqscreen = getdefaultpubscreen()
  address 'COMMAND' 'run >nil: execute MailCheck:S/StartAutoAnswer' mcreqscreen requestdelay 1
  if ~show('L','rexxreqtools.library') then do
    call addlib('rexxreqtools.library',0,-30,0)
  end
  answer = rtezrequest('Check mail now?','_Yes|_No','MailCheck v1.45','rtez_flags = ezreqf_centertext rt_reqpos = reqpos_centerscr rt_pubscrname='mcreqscreen) 
  address 'COMMAND' 'sys:rexxc/rx MailCheck:Rexx/StopAutoAnswer.rexx'
  if answer = ~1 then do
    exit 5  
  end
  else
    exit 0 
end

options results

duration = '00:00:00'
mailin = 0
mailout = 0
maxtime = 0
inresult = 0
outresult = 0
send = 0
out = 0
inresult = -1

if clioption = 'BREAKLOOP' then do
  address 'MCWAIT'
  QUIT
  exit
end

if clioption = 'ALWAYS' then do

    outmail = ReadConfig('MailCheck:MailCheck.config','SENDALWAYS','1000') 

    if outmail ~= '0' then do

      call StartYAM()
      address 'YAM'

      getfolderinfo num
      oldfolder = RESULT
      if oldfolder ~= 1 then do
        setfolder 1
      end
      getfolderinfo max
      if RESULT >= outmail then do
        if oldfolder ~= 1 then do
          setfolder oldfolder
        end
        exit 0
      end
      else do
        if oldfolder ~= 1 then do
          setfolder oldfolder
        end
        exit 5
      end  
    end
    else
      exit 5

end

address 'COMMAND'

if open(file,'env:MCPlayer','r') then do
  SamplePlayer = readln(file)
  call close(file)
end
else
  SamplePlayer = 'c:play16'

if open(file,'env:MCFile','r') then do
  MessageFile = readln(file)
  call close(file)
end
else
  MessageFile = 'default'

call ReadMessages('MailCheck:msg/'MessageFile'.msg')

call ExecuteUserScript('MailCheck:User_Scripts/User_Script_01')

if ReadConfig('MailCheck:MailCheck.config','CHECKMODEM','1000') = '1' then do

  serialdevice = ReadConfig('MailCheck:MailCheck.config','SERIALDEVICE','1000')
  serialunit = ReadConfig('MailCheck:MailCheck.config','SERIALUNIT','1000')

  'execute MailCheck:S/TestModem' serialdevice serialunit

  modemstatus = ReadEnv('MCModem')

  if modemstatus ~= 1 then do
    if show('p', 'MIAMI.1') then do
	    address 'MIAMI.1'
      isonline
      if RC ~= 1 then do
        day = left(GetCurrentDay(),'3')
        date = GetCurrentDate()
        time = GetCurrentTime()
        call WriteDDT(day,date,time)
        call WriteLog(message.2)
        call WriteIO('0','0')
        call WriteDuration('00:00:00')
        call QuitMiami()
        exit 
      end 
    end
    if ~show('p', 'MIAMI.1') then do
      day = left(GetCurrentDay(),'3')
      date = GetCurrentDate()
      time = GetCurrentTime()
      call WriteDDT(day,date,time)
      call WriteLog(message.2)
      call WriteIO('0','0')
      call WriteDuration('00:00:00')
      call QuitMiami()
      exit
    end
  end

end

if date(b) > ReadConfig('MailCheck:MailCheck.config','LASTUSED','1000') then do
  if time(s) >= 21600 then do
    call ExecuteUserScript('MailCheck:User_Scripts/User_Script_02')
    call WriteConfig('MailCheck:MailCheck.config','LASTUSED','1000',date(b)) 
  end
end

call StartYAM()
call StartMiami()

address 'MIAMI.1'

isonline
alreadyonline = RC
if alreadyonline = 0 then do
  day = left(GetCurrentDay(),'3')
  date = GetCurrentDate()
  time = GetCurrentTime()
  call WriteDDT(day,date,time)
  online
end

isonline
if RC = 0 then do
  call WriteLog(message.5)
  call WriteIO('0','0')
  call WriteDuration('00:00:00')
  call QuitMiami()
  exit 
end

call ExecuteUserScript('MailCheck:User_Scripts/User_Script_03')

startbase = date(b)
startsecs = time(s)
startday = GetCurrentDay()
shortstart = left(startday,'3')
startdate = GetCurrentDate()
starttime = GetCurrentTime()

call WriteDDT(shortstart,startdate,starttime)

if show('p','MAXTIME') then do
  address 'MAXTIME'
  stop
end

address 'COMMAND' 
'run <>nil: sys:rexxc/rx MailCheck:Rexx/MaxTime.rexx'

call CheckYAM()
call CheckMiami()

call YAM2Front()

call delay(5*50)

address 'YAM'

getfolderinfo num
oldfolder = RESULT
if oldfolder ~= 0 then do
  setfolder 0
end

setfolder 0
getfolderinfo max
beforeqty = result

/* mailcheck - removed for 2p4 fix */
/* inresult = RESULT */

call YAM2Front()

if ~show('p','input_stream_rx') then do
  address 'COMMAND'
  'c:inputstream'
end

address 'input_stream_rx'

WINDOW 'YAM SELECT'
STRING 'g'

killloop = 0
rexxport = 'MCWAIT'

call openport(rexxport)

do while killloop = 0 
  call delay(1*50)
  pkt = getpkt(rexxport)
  if pkt ~= '0000 0000'x then do
    cmd = upper(getarg(pkt))
    if cmd = 'QUIT' then do
      killloop = 1	 	
    end
    call reply(pkt, 0)
  end
end

address 'YAM'

setfolder 0
getfolderinfo max
afterqty = result

inresult = afterqty - beforeqty

maxtime = GetMaxTime()

if inresult = -1 then do
  if maxtime = 1 then do
    call WriteLog(message.7)
    call WriteIO('0','0')
    duration = CalculateDuration(startbase,startsecs)
    call WriteDuration(duration)
    call QuitMiami()
    exit 
  end
  mailin = 0  
end
else
  mailin = inresult  

if maxtime = 1 then do
  call WriteLog(message.8)
  call WriteIO(mailin,'0')
  duration = CalculateDuration(startbase,startsecs)
  call WriteDuration(duration)
  call QuitMiami()
  exit
end

if inresult ~= -1 then do
  call WriteEnv('MCReturn','1')
  call WriteConfig('MailCheck:MailCheck.config','LASTBASE','1000',startbase)
  call WriteConfig('MailCheck:MailCheck.config','LASTDAY','1000',startday)
  call WriteConfig('MailCheck:MailCheck.config','LASTDATE','1000',startdate)
  call WriteConfig('MailCheck:MailCheck.config','LASTTIME','1000',starttime)
  call WriteConfig('MailCheck:MailCheck.config','LASTQTY','1000',mailin)
end

if inresult = 0 then do
  call CloseLastCheck()
  call ExecuteUserScript('MailCheck:User_Scripts/User_Script_04') 
end
if inresult > 0 then do
  if ReadConfig('MailCheck:MailCheck.config','PLAYSAMPLE','1000') = '1' then do
    address 'COMMAND'
    sample = ReadConfig('MailCheck:MailCheck.config','SAMPLENAME','1000')
    if exists(sample) then do 
      'run <>nil: 'SamplePlayer sample
    end
    address 'YAM'
  end
  call CloseLastCheck() 
  call ExecuteUserScript('MailCheck:User_Scripts/User_Script_05')
end

if ReadConfig('MailCheck:MailCheck.config','SENDMAIL','1000') = '1' then do
  call CheckYAM()
  address 'MIAMI.1' siamese
  address 'MIAMI.1' isonline
  call CheckMiami()
  setfolder 1
  getfolderinfo max
  outfolder = RESULT
  if outfolder > 0 then do
    if ReadConfig('MailCheck:MailCheck.config','SENDREQ','1000') = '1' then do
      if ReadConfig('MailCheck:MailCheck.config','SENDYESDEF','1000') = '1' then do 
         defaultsend = 1 
      end
      else
         defaultsend = 0
      mcreqscreen = getdefaultpubscreen()
      address 'COMMAND' 'run >nil: execute MailCheck:S/StartAutoAnswer' mcreqscreen requestdelay defaultsend
      if ~show('L','rexxreqtools.library') then do
        call addlib('rexxreqtools.library',0,-30,0)
      end
      if outfolder = 1 then do
        setmail 0
        getmailinfo to
        who = result
        getmailinfo sub
        what = result
        answer = rtezrequest('There is 1 mail in' || NL || 'your outgoing folder.' || NL || NL || 'To: 'who || NL || 'Subject: 'what,'_Send|_Keep','MailCheck v1.45','rtez_flags = ezreqf_centertext rt_reqpos = reqpos_centerscr rt_pubscrname='mcreqscreen) 
      end
      if outfolder > 1 then do
        answer = rtezrequest('There are' outfolder 'mails in' || NL || 'your outgoing folder?','_Send all|_Interactive|_Cancel','MailCheck v1.45','rtez_flags = ezreqf_centertext rt_reqpos = reqpos_centerscr rt_pubscrname='mcreqscreen) 
      end
      address 'COMMAND' 'sys:rexxc/rx MailCheck:Rexx/StopAutoAnswer.rexx'
      if answer = 1 then send = 1
      if answer = 2 then do
        send = 0
        call SendInteractive()
      end
      if answer = 0 then do
        send = 0
        if outfolder = 0 then call CheckForReg()
      end
    end
    else
     send = 1
  end
end
else 
  outresult = 0

if send = 1 then do
  call Mail2Rob()
  call CheckYAM()   
  call CheckMiami()

  /* mailsendall
     outresult = RESULT */

  totalnumber = outfolder
  out = 0

  do until out >= totalnumber
    address 'YAM'
    out = out + 1
    setmail out-1
    getmailinfo fil
    mailfile = RESULT
    address 'COMMAND'
    'c:filenote' mailfile 'W'
  end

  address 'YAM'
   
  mailupdate

  call YAM2Front()

  address 'input_stream_rx'

  WINDOW 'YAM SELECT'
  STRING 's'
  
  killloop = 0

  address 'YAM'

  do while killloop = 0
    call delay(1*50) 
    getfolderinfo max
    if result = 0 then do
      call delay(1*50)
      killloop = 1
    end
  end
 
  setfolder 1
  getfolderinfo max
 
  outresult = outfolder-result

end


if outresult > 0 then call ExecuteUserScript('MailCheck:User_Scripts/User_Script_06')

  maxtime = GetMaxTime()
   
  if outresult = -1 then do
     if maxtime = 1 then do
       if inresult = -1 then do
         call WriteLog(message.13)
         call WriteIO('0','0')
         duration = CalculateDuration(startbase,startsecs)
         call WriteDuration(duration)
         call QuitMiami()
         exit 
       end 
       else do
         call WriteLog(message.10)
         call WriteIO(mailin,'0')
         duration = CalculateDuration(startbase,startsecs)
         call WriteDuration(duration)
         call QuitMiami()
       end
       exit 
     end
  end
  else do
     mailout = outresult
     if maxtime = 1 then do
       call WriteLog(message.11)
       call WriteIO(mailin,mailout)
       duration = CalculateDuration(startbase,startsecs)
       call WriteDuration(duration)
       call QuitMiami()
       exit
     end
  end

call CheckForReg()

call CheckYAM()
getfolderinfo num
currentfolder = RESULT
if currentfolder ~= oldfolder then do
  setfolder oldfolder
end

call WriteIO(mailin,mailout)

if inresult = -1 then do
  if outresult = -1 then do
    call WriteLog(message.12)
  end 
  else
    call WriteLog(message.6)

end

if inresult = 0 then do
  if outresult = -1 then do
    call WriteLog(message.9)
  end
end

if inresult ~= -1 then do
  if outresult ~= -1 then do
    call WriteLog(message.1)
  end
end

duration = CalculateDuration(startbase,startsecs)
call WriteDuration(duration) 

call StopMaxTime() 

call StayOnLine()

call QuitMiami()

exit 


/* ---------------------------------- */

YAM2Front: procedure

address 'YAM'

show
screentofront

/* ---------------------------------- */

ReadMessages: 

parse arg filename
if open(file,filename,'R') then do 
  filestring = readch(file,2000)
  message. = 'Hmm - There is something wrong with the message file!'
  mn = 1
  do until mn > 16
    dataposition = pos('Message'right(mn,2,0),filestring)
    valueposition = pos('#',filestring,dataposition)
    call seek(file,valueposition,'B')
    message.mn = readln(file)
    mn = mn + 1
  end
  call close(file)
end
return 

/* ---------------------------------- */

StayOnLine:

if clioption = 'KEEPONLINE' then do
  alreadyonline = 1
end

if alreadyonline = 0 then do
  if maxtime = 1 then do
    exit
  end
  if ReadConfig('MailCheck:MailCheck.config','MIAMIREQ','1000') = '1' then do
    call CheckMiami()
    mcreqscreen = getdefaultpubscreen()
    address 'COMMAND' 'run >nil: execute MailCheck:S/StartAutoAnswer' mcreqscreen requestdelay 0
    if ~show('L','rexxreqtools.library') then do
      call addlib('rexxreqtools.library',0,-30,0)
    end
    answer = rtezrequest('Keep connection' || NL || 'alive?','_Yes|_No','MailCheck v1.45','rtez_flags = ezreqf_centertext rt_reqpos = reqpos_centerscr rt_pubscrname='mcreqscreen) 
    address 'COMMAND' 'sys:rexxc/rx MailCheck:Rexx/StopAutoAnswer.rexx'
    if answer = 1 then do
      keeponline = 1 
      address 'MIAMI.1' siamese 
    end
    else
      keeponline = 0
    end
  else
    keeponline = 0

  if keeponline = 0 then do
    address 'MIAMI.1'
    offline
  end
end

return


/* ---------------------------------- */

CheckMiami:

if out > 0 then call ExecuteUserScript('MailCheck:User_Scripts/User_Script_06')

if show('p','MIAMI.1') then do
  address 'MIAMI.1' isonline
  if RC ~= 1 then do
    call WriteLog(message.14)
    call WriteIO(mailin,mailout)
    duration = CalculateDuration(startbase,startsecs)
    call WriteDuration(duration)
    call StopMaxTime() 
    call QuitMiami()
    call ExecuteUserScript('MailCheck:User_Scripts/User_Script_10')
    exit
  end
end

if ~show('p','MIAMI.1') then do
  call WriteLog(message.15)
  call WriteIO(mailin,mailout)
  duration = CalculateDuration(startbase,startsecs)
  call WriteDuration(duration)
  call StopMaxTime()
  call ExecuteUserScript('MailCheck:User_Scripts/User_Script_10') 
  exit
end

return


/* ---------------------------------- */

CheckYAM:

if out > 0 then call ExecuteUserScript('MailCheck:User_Scripts/User_Script_06')

if ~show('p','YAM') then do
  call WriteLog(message.16)
  call WriteIO(mailin,mailout)
  duration = CalculateDuration(startbase,startsecs)
  call WriteDuration(duration)
  call StopMaxTime() 
  call StayOnLine()
  call QuitMiami()
  call ExecuteUserScript('MailCheck:User_Scripts/User_Script_09')
  exit
end

return


/* ---------------------------------- */

StartMiami:

if show('p','MIAMI.1') = 0 then do
  day = left(GetCurrentDay(),'3')
  date = GetCurrentDate()
  time = GetCurrentTime()
  call WriteDDT(day,date,time)
  address 'COMMAND'
  'run <>nil: Miami:Miami'
  do 3 until show('p','MIAMI.1') > 0
    'sys:rexxc/waitforport MIAMI.1'
  end
  if show('p','MIAMI.1') = 0 then do
    call WriteLog(message.4)
    call WriteIO('0','0')
    call WriteDuration('00:00:00')
    call QuitMiami()
    exit 
  end
end

return


/* ---------------------------------- */

StartYAM:

if show('p','YAM') = 0 then do
  day = left(GetCurrentDay(),'3')
  date = GetCurrentDate()
  time = GetCurrentTime()
  call WriteDDT(day,date,time)
  address 'COMMAND'
  'run <>nil: YAM:YAM nocheck'
  do 3 until show('p','YAM') > 0
    'sys:rexxc/waitforport YAM'
  end
  if show('p','YAM') = 0 then do
    call WriteLog(message.3)
    call WriteIO('0','0')
    call WriteDuration('00:00:00')
    call QuitMiami()
    exit 
  end
end

return


/* ---------------------------------- */

SendInteractive: 

realnumber = 0
mailnumber = 0

call CheckYAM()

totalnumber = outfolder
out = 0
hold = 0

do until out >= totalnumber
  out = out + 1
  call CheckYAM()
  address 'YAM'
  setmail out-1
  getmailinfo to
  who = result
  getmailinfo sub
  what = result
  answer = rtezrequest('Mail' out 'of' totalnumber || NL || NL || 'To: 'who || NL || 'Subject: 'what,'_Send|_Keep','Send Mail Interactive','rtez_flags = ezreqf_centertext rt_reqpos = reqpos_centerscr') 
  if answer = 1 then do
    getmailinfo fil
    mailfile = RESULT
    address 'COMMAND'
    'c:filenote' mailfile 'W'
  end
  else do
    getmailinfo fil
    mailfile = RESULT
    address 'COMMAND'
    'c:filenote' mailfile 'H'
    hold = hold + 1
  end
end

call CheckMiami()

if totalnumber ~= hold then do

  address 'YAM'

  mailupdate

  call YAM2Front()

  address 'input_stream_rx'

  WINDOW 'YAM SELECT'
  STRING 's'
  
  killloop = 0

  address 'YAM'

  do while killloop = 0
    call delay(1*50) 
    setfolder 1
    getfolderinfo max
    if result <= totalnumber-hold then do
      call delay(1*50)
      killloop = 1
    end
  end

  setfolder 1  
  getfolderinfo max
 
  mailout = outfolder-result

  outresult = mailout
end
else do
  mailout = 0
  outresult = 0
end

if mailout > 0 then call ExecuteUserScript('MailCheck:User_Scripts/User_Script_06')

return 

/* ---------------------------------- */

WriteEnv: procedure
parse arg variable,value
call open(file,'env:'variable,'w')
call writeln(file,value)
call close(file)
return

/* ---------------------------------- */

ReadEnv: procedure
parse arg variable
call open(file,'env:'variable,'r')
value = readln(file)
call close(file)
return value


/* ---------------------------------- */

CheckForReg: procedure

maxtime = GetMaxTime()

if maxtime = 0 then do
  if exists('envarc:MCReg') then do
    call open(file,'envarc:MCReg','r')
    value = readln(file)
    call close(file)
  end
  else
    value = 0
  if value ~= '1.45' then do
    setfolder 1
    getfolderinfo max
    outfolder = RESULT
    if outfolder = 0 then call Mail2Rob()  
    mailsendall
  end
end

return

/* ---------------------------------- */

Mail2Rob: procedure

if exists('envarc:MCReg') then do
  call open(file,'envarc:MCReg','r')
  value = readln(file)
  call close(file)
end
else
  value = 0

if value ~= '1.45' then do
  loop = 1
  info.1 = 'Name  : #'
  info.2 = 'E-Mail: #'
  info.3 = 'CPU   : #'
  info.4 = 'FPU   : #'
  info.5 = 'Video : #'
  info.6 = 'Kick  : #'
  info.7 = 'Work  : #'
  info.8 = 'MUI   : #'
  info.9 = 'Miami : #'
  info.10 = 'YAM   : #'

  parse version . . cpu . string.5 . 

  getconfiginfo NAM
  string.1 = RESULT

  getconfiginfo EMA
  string.2 = RESULT
  string.3 = CheckCPU(cpu)

  address 'COMMAND'   
  string.4 = CheckFPU(string.3)

  'version >t:MCVersion.tmp'
  call open(file,'t:MCVersion.tmp','r')
  data = readln(file)
  call close(file)
  parse var data . kick . work 
  string.6 = compress(kick,' ,')
  string.7 = compress(work,' ,')
  'version MUI:MUI >t:MCVersion.tmp'
  call open(file,'t:MCVersion.tmp','r')
  string.8 = readln(file)
  call close(file)
  'version MIAMI:MIAMI >t:MCVersion.tmp'
  call open(file,'t:MCVersion.tmp','r')
  string.9 = readln(file)
  call close(file)  
  'version YAM:YAM >t:MCVersion.tmp'
  call open(file,'t:MCVersion.tmp','r')
  string.10 = readln(file)
  call close(file)
  call open(file,'t:MCRegMail.tmp','w')
  do until loop > 10 
    call writeln(file,info.loop''string.loop)
    loop = loop + 1
  end
  call close(file)
  call CheckYAM()
  address 'YAM'
  mailwrite
  writeto '"robert.wilson@bigfoot.com"'
  writesubject '"MailCheck v1.45 registration"'
  writeletter 't:MCRegMail.tmp'
  writequeue
  call open(file,'envarc:MCReg','w')
  call writeln(file,'1.45')
  call close(file)
end

return


/* ---------------------------------- */

CloseLastCheck: procedure

if exists('env:MCLastRun') then do
  call open(file,'env:MCLastRun','r')
  value = readln(file)
  call close(file)

  if value = 1 then do
    lcreqscreen = ReadEnv('LCPubScreen')
    address 'COMMAND' 'run <>nil: MailCheck:C/OkayDokey SC="'lcreqscreen'" WI="LastCheck v1.45" CAN ACT CX QUIET QUITAFTER'
    call delay(3*50)
    call YAM2Front() 
  end
end

return 


/* ---------------------------------- */

QuitMiami:
if show('p','MIAMI.1') then do
  address 'MIAMI.1' isonline
  miamionline = RC
  if miamionline = 0 then do
    if ReadConfig('MailCheck:MailCheck.config','MIAMIQUIT','1000') = '1' then do 
      address 'MIAMI.1'
      quit
    end
  end
end
return

/* ---------------------------------- */


WriteConfig: procedure

parse arg filename, data, filesize, newvalue

if open(file,filename,'R') then do 
  filestring = readch(file,filesize)
  dataposition = pos(data,filestring)
  valueposition = pos('#',filestring,dataposition)
  call seek(file,valueposition,'B')
  oldvalue = readln(file)
end
call close(file)

oldvaluelength = length(oldvalue)
newvaluelength = length(newvalue)


tempstring = delstr(filestring,valueposition,oldvaluelength+1)
filestring = insert('#'newvalue,tempstring,valueposition-1,newvaluelength+1)
/* drop tempstring */

if open(file,filename,'W') then do 
  call writech(file,filestring)
end
call close(file)

return

/* ---------------------------------- */

CalculateDuration: procedure
parse arg startbase,startsecs

endbase = date(b)
endsecs = time(s)

if endbase > startbase then do
  totalsecs = (86400 * (endbase - startbase)) + (endsecs - startsecs) 
end
else
  totalsecs = endsecs-startsecs

if totalsecs >= 3600 then do
  hours = totalsecs % 3600
  totalsecs = totalsecs // 3600
end
else hours = 0
if hours < 10 then hours = '0'hours

if totalsecs >= 60 then do
  minutes = totalsecs % 60
  totalsecs = totalsecs // 60
end
else minutes = 0
if minutes < 10 then minutes ='0'minutes

seconds = totalsecs
if seconds < 10 then seconds ='0'seconds

duration = hours':'minutes':'seconds

return duration


/* ---------------------------------- */

StopMaxTime: procedure

if show('p','MAXTIME') then do
  address 'MAXTIME' STOP
end

return

/* ---------------------------------- */

GetMaxTime: procedure

call open(file,'env:MCMaxTime','r')
value = readln(file)
call close(file)
return value


/* ---------------------------------- */

WriteDuration: procedure
parse arg duration
call open(file,'env:MCDuration','w')
call writeln(file,duration)
call close(file)
return



/* ---------------------------------- */

WriteIO: procedure
parse arg mailin,mailout
call open(file,'env:MCIn','w')
call writeln(file,mailin)
call close(file)
call open(file,'env:MCOut','w')
call writeln(file,mailout)
call close(file)
return


/* ---------------------------------- */

WriteLog: procedure
parse arg message 
call open(file,'env:MCMessage','w')
call writeln(file,message)
call close(file)
return

/* ---------------------------------- */

WriteDDT: procedure
parse arg day,date,time
call open(file,'env:MCDay','w')
call writeln(file,day)
call close(file)
call open(file,'env:MCDate','w')
call writeln(file,date)
call close(file)
call open(file,'env:MCTime','w')
call writeln(file,time)
call close(file)
return

/* ---------------------------------- */

ExecuteUserScript: procedure
parse arg filename
if exists(filename) then do
  address	COMMAND 'execute 'filename
end
return

/* ---------------------------------- */

ReadConfig: procedure
parse arg filename, data, filesize
if open(file,filename,'R') then do 
  filestring = readch(file,filesize)
  dataposition = pos(data,filestring)
  valueposition = pos('#',filestring,dataposition)
  call seek(file,valueposition,'B')
  value = readln(file)
  call close(file)
end
return value

/* ---------------------------------- */

GetCurrentDate: procedure
address 'COMMAND'
'date >T:MCTempDay'
call open(file,'T:MCTempDay','R')
tempdate = readln(file)
call close(file)
parse var tempdate . date .
/* 'delete T:MCTempDay Quiet' */
return date

/* ---------------------------------- */

GetCurrentTime: procedure
value = time()
return value

/* ---------------------------------- */

GetCurrentDay: procedure /* There must be an easier way of doing this...? */
address 'COMMAND'
'date >T:MCTempDay'
call open(file,'T:MCTempDay','R')
tempdate = readln(file)
call close(file)
parse var tempdate day . .
'delete T:MCTempDay >NIL:'
return day

/* ---------------------------------- */

CheckCPU: procedure
parse arg rexxcpu

if rexxcpu >= 68070 then do
  if rexxcpu = 68070 then cpu = 68040
  if rexxcpu = 68080 then cpu = 68060
end
else
  cpu = rexxcpu 

return cpu


/* ---------------------------------- */

CheckFPU: procedure
parse arg cpu
exitflag = 0
address 'COMMAND'

if exitflag = 0 then do
  'cpu CHECK 68882 >nil:'
  if RC ~= 5 then do

    exitflag = 1
    if cpu >= 68040 then do
      fpu = cpu
    end
    else
      fpu = 68882

  end
end

if exitflag = 0 then do
  'cpu CHECK 68881 >nil:'
  if RC ~= 5 then do
    fpu = 68881
    exitflag = 1
  end
end

if exitflag = 0 then do
  fpu = 'None'
end

return fpu

/* ---------------------------------- */
