home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Online / GMSuite / Rexx / GMAutoWrite.thor < prev    next >
Text File  |  2000-01-23  |  9KB  |  335 lines

  1. /*
  2. ** $VER: GMAutoWrite.thor 5.003 (23.01.00)
  3. **       © Gian Maria Calzolari <gcalzo@geocities.com>
  4. **
  5. **       Thanks to Neil Bothwick to let me use his AutoReply as a start base
  6. **       for the adaption of my script originally written for EMS (FidoNet
  7. **       mailer)
  8. **
  9. **  FUNCTION:
  10. **      Automatically write a message at desired intervals, can be called
  11. **      anytime but's best to call it at Thor startup
  12. **
  13. ** $HISTORY:
  14. **
  15. ** 23 Jan 2000 : 005.003 : Nothing, bumped up rev
  16. ** 07 Jan 2000 : 005.002 : Nothing, bumped up rev
  17. ** 21 Dec 1999 : 005.001 : added CC and BCC headers
  18. ** 17 Nov 1999 : 005.000 : Nothing! Bumped up rev for consistency with first
  19. **                         aminet release of GMsuite!
  20. ** 08 Nov 1999 : 004.003 : Version for GMsuite v1.0
  21. ** 23 Oct 1999 : 004.002 : Added "First-Of-Month" support for Kimme Utsi and,
  22. **                         since it was easy, also a "fixed-day-of-the-month" too! :-)
  23. ** 17 Oct 1999 : 004.001 : added options ExtPgm & ExtPgmType (Simone "Wiz" Tellini)
  24. ** 16 Oct 1999 : 004.000 : First public version!! :-)
  25. ** 15 Oct 1999 : 003.007 : First internal beta! OptionalTags are ignored... :-(
  26. ** 11 Oct 1999 : 003.006 : Started adaption to Thor
  27. **
  28. ** v3.0 11-10-93 Version for EMS 1.0
  29. ** v2.0 28-06-93 Version for GCC 4.0
  30. **
  31. */
  32.  
  33. VerStr     = subword(sourceline(2),3)
  34. ConfigFile = 'ENV:Thor/GMAutoWrite.cfg'
  35.  
  36. true  = 1
  37. false = 0
  38.  
  39. /* This tags can be omitted, default will be "blank" */
  40. TagOptsBlk = "ToName CcAddr BccAddr Subject SigFile HdrFile FtrFile ExtPgm"
  41.  
  42. /* This tags can be omitted, default will be "zero" */
  43. TagOptsZro = "ExtPgmType Prog_PVT Date_PVT"
  44.  
  45. TagOptions = "System Conf Active Days BdyFile ToAddr" TagOptsBlk TagOptsZro
  46. NumOpts = words(TagOptions)
  47.  
  48. /* Load bbsread.library if necessary */
  49. if ~show('p', 'BBSREAD') then do
  50.     address command
  51.     'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  52.     'WaitForPort BBSREAD'
  53. end
  54.  
  55. call ReadConfig
  56.  
  57. if Tags.0 > 0 then do
  58.    progr = date('I')
  59.    today = Dom()
  60.  
  61.    do i = 1 to Tags.0
  62.       call Validate
  63.  
  64.       if (Tags.i.ACTIVE) then do
  65.          OkToGo = false
  66.  
  67.          if Tags.i.DAYS < 0 then do
  68.             if today = abs(Tags.i.DAYS) then
  69.                OkToGo = true
  70.            end
  71.            else
  72.             if progr - Tags.i.PROG_PVT >= Tags.i.DAYS then
  73.                OkToGo = true
  74.  
  75.          if OkToGo then do
  76.             if Tags.i.EXTPGM ~= '' then ExecutePgm(Tags.i.EXTPGM, Tags.i.EXTPGMTYPE, Tags.i.BDYFILE)
  77.  
  78.             call WriteMsg
  79.             Tags.i.PROG_PVT = progr
  80.             Tags.i.DATE_PVT = date('E')
  81.          end
  82.       end
  83.    end
  84.  
  85.    call WriteConfig
  86. end
  87.  
  88. exit
  89.  
  90. /* ...game over... */
  91.  
  92.  
  93. Validate:
  94.  
  95.    do y = 1 to NumOpts
  96.       Opt = upper(word(TagOptions, y))
  97.       OptDef = symbol('Tags.i.Opt')
  98.  
  99.       Select
  100.           When find(upper(TagOptsBlk),Opt) > 0 then
  101.             if OptDef ~= 'VAR' then Tags.i.Opt = ''
  102.           When find(upper(TagOptsZro),Opt) > 0 then
  103.             if OptDef ~= 'VAR' then Tags.i.Opt = 0
  104.           Otherwise
  105.             if OptDef ~= 'VAR' then call ExitMsg("'" || Opt || "' not defined in tag '" || Tags.i || "'")
  106.       end
  107.  
  108.       if Opt = 'EXTPGM' & Tags.i.Opt ~='' & pos('%F',upper(Tags.i.Opt)) = 0 then
  109.          call ExitMsg("%F in '" || Opt || "' missing in tag '" || Tags.i || "'")
  110.  
  111.    end
  112. return
  113.  
  114.  
  115. ExecutePgm:
  116.    /*
  117.    ** This will process an external pgm or arexx script to create the
  118.    ** message body
  119.    */
  120.    InsertPos = pos('%F',upper( arg(1) ))
  121.    Pgm = left(arg(1),InsertPos-1) || arg(3) || substr(arg(1),InsertPos+2)
  122.  
  123.    if Arg(2) = 0 then         /* Arexx */
  124.       Pgm
  125.      else                     /* dos   */
  126.       address command Pgm
  127.  
  128. return RESULT
  129.  
  130. WriteMsg:
  131.     address BBSREAD
  132.     drop MsgBody. MsgHead.
  133.  
  134.     /* Create message file */
  135.     UNIQUEMSGFILE bbsname '"'Tags.i.System'"' stem MsgFile
  136.  
  137.     if ~open(out,MsgFile.NAME,'w') then call ExitMsg('Unable to create message file')
  138.  
  139.     /* Write headers */
  140.     headline = 'X-Generator:' VerStr
  141.     call writeln(out,headline)
  142.  
  143.     if Tags.i.HDRFILE ~= '' then do
  144.  
  145.         if ~open(headers,Tags.i.HDRFILE,'R') then call ExitMsg('Unable to open header file' Tags.i.HDRFILE)
  146.  
  147.         do until eof(headers)
  148.             call writeln(out,readln(headers))
  149.         end
  150.  
  151.         call close(headers)
  152.     end
  153.  
  154.     if Tags.i.CCADDR ~= '' then
  155.        call writeln(out,'Cc:' Tags.i.CCADDR)
  156.  
  157.     if Tags.i.BCCADDR ~= '' then
  158.        call writeln(out,'bcc:' Tags.i.BCCADDR)
  159.  
  160.     call writeln(out,'')
  161.  
  162.     /* Write message body */
  163.  
  164.     if ~open(body,Tags.i.BDYFILE,'R') then call ExitMsg('Unable to open body file' Tags.i.BDYFILE)
  165.  
  166.     do until eof(body)
  167.         call writeln(out,readln(body))
  168.     end
  169.  
  170.     call close(body)
  171.  
  172.     /* Add signature */
  173.     if Tags.i.SIGFILE ~= '' then do
  174.  
  175.         if ~open(sig,Tags.i.SIGFILE,'R') then call ExitMsg('Unable to open signature file' Tags.i.SIGFILE)
  176.  
  177.         do until eof(sig)
  178.             call writeln(out,readln(sig))
  179.         end
  180.  
  181.         call close(sig)
  182.     end
  183.  
  184.     /* Add footer file */
  185.     if Tags.i.FTRFILE ~= '' then do
  186.  
  187.         if ~open(foot,Tags.i.FTRFILE,'R') then call ExitMsg('Unable to open footer file' Tags.i.FTRFILE)
  188.  
  189.         do until eof(foot)
  190.             call writeln(out,readln(foot))
  191.         end
  192.  
  193.         call close(foot)
  194.     end
  195.  
  196.     call close(out)
  197.  
  198.     /* Create EMail event */
  199.     drop EventData.
  200.     EventData.TONAME     = Tags.i.TONAME
  201.     EventData.TOADDR     = Tags.i.TOADDR
  202.     EventData.SUBJECT    = Tags.i.SUBJECT
  203.     EventData.CONFERENCE = Tags.i.CONF
  204.     EventData.MSGFILE    = MsgFile.FILEPART
  205.  
  206.     WRITEBREVENT bbsname '"'Tags.i.SYSTEM'"' event 0 stem EventData
  207.  
  208.     if RC > 0 then call ExitMsg(BBSREAD.LASTERROR)
  209. return
  210.  
  211.  
  212. ReadConfig:
  213.     /* Tags.0 will contains the tag numbers, Tags.X will contains the tag name
  214.     ** Tags.X.y will be defined as follow:
  215.     **     Tags.X.System     System name
  216.     **     Tags.X.Conf       Conference name
  217.     **     Tags.X.ToName     To user name
  218.     **     Tags.X.ToAddr     To user address
  219.     **     Tags.X.Subject    Message subject
  220.     **     Tags.X.BdyFile    File to be used as message body
  221.     **     Tags.X.SigFile    File to be used as message sign
  222.     **     Tags.X.HdrFile    File to be used as message header
  223.     **     Tags.X.FtrFile    File to be used as message footer
  224.     **     Tags.X.ExtPgm     External pgm that will create the BdyFile
  225.     **     Tags.X.ExtPgmType External pgm type (0 = ARexx / 1 = dos)
  226.     **     Tags.X.Days       Post message every Y days
  227.     **     Tags.X.Active     Tags.X active or not? (1 = True / 0 = False)
  228.     **     Tags.X.Prog_PVT   Progressive number, private field updated by the pgm!
  229.     **     Tags.X.Date_PVT   Last posted date, private field updated by the pgm!
  230.     */
  231.     drop Tags.
  232.     Tags.0  = 0
  233.     TagsNum = 0
  234.  
  235.     CfgOpen = open(cfgfile,ConfigFile,'r')
  236.  
  237.     if ~(CfgOpen) then call ExitMsg('Reading: failed to open' ConfigFile)
  238.  
  239.     do until eof(cfgfile)
  240.         nextline = readln(cfgfile)
  241.  
  242.         if compress(nextline) = "" then iterate
  243.  
  244.         parse var nextline CfgName CfgVal
  245.         CfgName = upper(CfgName)
  246.         CfgVal  = strip(compress(CfgVal,'"'))
  247.  
  248.         if CfgName = 'TAG' then do
  249.            TagsNum = TagsNum + 1
  250.            Tags.TagsNum = CfgVal
  251.          end
  252.          else do
  253.  
  254.            if TagsNum = 0 then call ExitMsg('No Tag names found!')
  255.  
  256.            if find(upper(TagOptions), CfgName) > 0 then
  257.               Tags.TagsNum.CfgName = CfgVal
  258.              else
  259.               call ExitMsg("Option '" || CfgName || "' (with value '" || CfgVal || "') in tag '" || Tags.TagsNum || "' not allowed!")
  260.         end
  261.     end
  262.  
  263.     if TagsNum = 0 then call ExitMsg('No Tag names found!')
  264.  
  265.     Tags.0 = TagsNum
  266.  
  267.     if (CfgOpen) then dummy = close(cfgfile)
  268. return
  269.  
  270.  
  271. WriteConfig:
  272.     CfgOpen = open(cfgfile,ConfigFile,'W')
  273.  
  274.     if ~(CfgOpen) then call ExitMsg('Saving: failed to open' ConfigFile)
  275.  
  276.     NL = trunc( length(TagOptions) / NumOpts)
  277.     NL = NL + trunc( (length(TagOptions) - NL) / NumOpts)
  278.  
  279.     do x = 1 to Tags.0
  280.        call writeln(cfgfile,'TAG  ' Tags.x)
  281.  
  282.        do y = 1 to NumOpts
  283.           OptL = word(TagOptions, y)
  284.           Opt  = upper(OptL)
  285.  
  286.           if Tags.x.Opt ~= "" & Tags.x.Opt ~= 0 | Opt = 'ACTIVE' then do
  287.  
  288.              if pos(" ",Tags.x.Opt) > 0 then
  289.                 call writeln(cfgfile,'   ' || pad(OptL,NL) || '"' || Tags.x.Opt || '"')
  290.                else
  291.                 call writeln(cfgfile,'   ' || pad(OptL,NL) || Tags.x.Opt)
  292.           end
  293.        end
  294.  
  295.        call writeln(cfgfile,'')
  296.     end
  297.  
  298.     if (CfgOpen) then dummy = close(cfgfile)
  299.  
  300.     address command 'copy >NIL: clone' ConfigFile 'EnvArc:Thor'
  301. return
  302.  
  303.  
  304.  
  305. /*
  306. ** Returns the current Day number
  307. */
  308. Dom:
  309. return Word( Date(N), 1)
  310.  
  311.  
  312.  
  313. /* pad a string with blank to the left
  314. **  parm1       string to be padded with blank
  315. **  parm2       new lenght
  316. */
  317. Pad:
  318. return left( arg(1) || copies(' ', arg(2) ), arg(2) )
  319.  
  320.  
  321.  
  322. /* Exit with a message */
  323. ExitMsg:
  324.     parse arg msgstr
  325.     address command
  326.  
  327.     if symbol('MsgFile.NAME') = 'VAR' then do
  328.         call close(out)
  329.         'delete >NIL:' MsgFile.NAME
  330.     end
  331.  
  332.     'RequestChoice >NIL: "GMAutoWrite.thor" "'msgstr'" "OK :-("'
  333. exit
  334.  
  335.