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

  1. /*
  2. ** $VER: GMSignature.thor 5.003 (23.01.00)
  3. **       © Gian Maria Calzolari <gcalzo@geocities.com>
  4. **
  5. **  FUNCTION:
  6. **      Enhances Thor's signature systems implementing both a random tag
  7. **      and a specific conference's signature. Default signature allowed.
  8. **
  9. ** $HISTORY:
  10. **
  11. ** 23 Jan 2000 : 005.003 : Nothing, bumped up rev
  12. ** 07 Jan 2000 : 005.002 : Used ReadArguments in GMsignature to avoid errors when
  13. **                         crossposting news
  14. ** 21 Dec 1999 : 005.001 : Nothing, bumped up rev
  15. ** 17 Nov 1999 : 005.000 : Nothing! Bumped up rev for consistency with first
  16. **                         aminet release of GMsuite!
  17. ** 14 Nov 1999 : 001.000 : version for GMsuite, changed the cfg file name to
  18. **                         avoid duplication with GMCleanConf!
  19. **                         Now cfg name is 'system name' plus '_S'
  20. ** 21 Oct 1999 : 000.002 : Added pattern support for Conference name
  21. ** 20 Oct 1999 : 000.001 : First attempt, based from mine GMAutoWrite (try it! ;-)
  22. **
  23. */
  24.  
  25. parse upper arg arguments
  26.  
  27. /*
  28. parse upper arg "BBSNAME" BBS "CONFNAME" CNAME .
  29.  
  30. BBS   = strip(compress(BBS,'"'))
  31. CNAME = strip(compress(CNAME,'"'))
  32.  
  33. if BBS = "" | CNAME = "" then
  34.    call ExitMsg("GMSignature.thor must be called as Thor's Signature Command")
  35. */
  36.  
  37. call Init
  38.  
  39. call ReadConfig
  40.  
  41. call Validate
  42.  
  43. index = SrcConf(opts.CONFNAME)
  44.  
  45. if index = 0 then
  46.    index = SrcConf("DEFAULT")
  47.  
  48. if Exists(Tags.index.SIGFILE) then
  49.    address command 'type' Tags.index.SIGFILE
  50.   else
  51.    call ExitMsg("'SigFile' '" || Tags.index.SIGFILE || "' not found!")
  52.  
  53. if Tags.index.TAGPGM ~= '' then do
  54.    say "--"
  55.  
  56.    if Tags.index.TAGPGMTYPE = 0 then  /* Arexx */
  57.       Tags.index.TAGPGM
  58.      else                             /* dos   */
  59.       address command Tags.index.TAGPGM
  60. end
  61.  
  62. exit
  63.  
  64. /* ...game over... */
  65.  
  66.  
  67. Validate:
  68.    DefFound = false
  69.  
  70.    do i = 1 to Tags.0
  71.  
  72.       if upper(Tags.i) = "DEFAULT" then
  73.          DefFound = true
  74.  
  75.       do y = 1 to NumOpts
  76.          Opt = upper(word(TagOptions, y))
  77.          OptDef = symbol('Tags.i.Opt')
  78.  
  79.          Select
  80.              When find(upper(TagOptsBlk),Opt) > 0 then
  81.                if OptDef ~= 'VAR' then Tags.i.Opt = ''
  82.              When find(upper(TagOptsZro),Opt) > 0 then
  83.                if OptDef ~= 'VAR' then Tags.i.Opt = 0
  84.              Otherwise
  85.                if OptDef ~= 'VAR' then call ExitMsg("'" || Opt || "' not defined in tag '" || Tags.i || "'")
  86.          end
  87.  
  88.       end
  89.    end
  90.  
  91.    if ~DefFound then
  92.       call ExitMsg("'DEFAULT' tag not defined in file '" || ConfigFile || "'")
  93.  
  94. return
  95.  
  96.  
  97. /* Searches the conference in the config
  98. **  parm1   conference to be searched
  99. **
  100. **  returns the index or 0 if not found
  101. */
  102. SrcConf:
  103.    cnfr = upper(arg(1))
  104.  
  105.    do i = 1 to Tags.0
  106.       CONF = cnfr
  107.  
  108.       if Tags.i.PAT = 0 then do
  109.  
  110.          if CONF = Tags.i then return i
  111.  
  112.         end
  113.         else do
  114.          select
  115.             when Tags.i.PAT = 1 then do
  116.                  CONF = left(CONF, length(Tags.i))
  117.  
  118.                  if CONF = Tags.i then return i
  119.  
  120.             end
  121.             when Tags.i.PAT = 2 then do
  122.                  CONF = right(CONF, length(Tags.i))
  123.  
  124.                  if CONF = Tags.i then return i
  125.  
  126.             end
  127.             when Tags.i.PAT = 3 then do
  128.  
  129.                  if index(CONF, Tags.i) > 0 then return i
  130.  
  131.             end
  132.          end
  133.       end
  134.    end
  135.  
  136. return 0
  137.  
  138.  
  139. ReadConfig:
  140.     /* Tags.0 will contains the Conference numbers, Tags.X will be the
  141.     **        Conference name (without the "*" if used...)
  142.     ** Tags.X.y will be defined as follow:
  143.     **     Tags.X.SigFile    File to be used as message sign
  144.     **     Tags.X.TagPgm     External pgm that will write a tag to stdout
  145.     **     Tags.X.TagPgmType External pgm type (0 = ARexx / 1 = dos)
  146.     **     Tags.X.Pat        internal field: 0=no pattern, 1=on right, 2=on left, 3=both
  147.     */
  148.     drop Tags.
  149.     Tags.0  = 0
  150.     TagsNum = 0
  151.  
  152.     CfgOpen = open(cfgfile,ConfigFile,'r')
  153.  
  154.     if ~(CfgOpen) then call ExitMsg('Reading: failed to open' ConfigFile)
  155.  
  156.     do until eof(cfgfile)
  157.         nextline = readln(cfgfile)
  158.  
  159.         if compress(nextline) = "" then iterate
  160.  
  161.         parse var nextline CfgName CfgVal
  162.         CfgName = upper(CfgName)
  163.         CfgVal  = strip(compress(CfgVal,'"'))
  164.  
  165.         if CfgName = 'TAG' then do
  166.            TagsNum = TagsNum + 1
  167.  
  168.            pattern = 0
  169.  
  170.            if right(CfgVal,1) = '*' then
  171.               pattern = pattern +1
  172.  
  173.            if left(CfgVal,1) = '*' then
  174.               pattern = pattern +2
  175.  
  176.            CfgVal = compress(CfgVal,'*')
  177.            Tags.TagsNum.PAT = pattern
  178.  
  179.            Tags.TagsNum = upper(CfgVal)
  180.          end
  181.          else do
  182.  
  183.            if TagsNum = 0 then call ExitMsg('No Tag names found!')
  184.  
  185.            if find(upper(TagOptions), CfgName) > 0 then
  186.               Tags.TagsNum.CfgName = CfgVal
  187.              else
  188.               call ExitMsg("Option '" || CfgName || "' (with value '" || CfgVal || "') in tag '" || Tags.TagsNum || "' not allowed!")
  189.         end
  190.     end
  191.  
  192.     if TagsNum = 0 then call ExitMsg('No Tag names found!')
  193.  
  194.     Tags.0 = TagsNum
  195.  
  196.     if (CfgOpen) then dummy = close(cfgfile)
  197. return
  198.  
  199.  
  200.  
  201. /* Initialization */
  202. Init:
  203.    Template = "BBSNAME/K,CONFNAME/K"
  204.  
  205.    VerStr     = subword(sourceline(2),3)
  206.  
  207.    p = ' ' || address() || ' ' || show('P',,)
  208.    thorport = pos(' THOR.',p)
  209.  
  210.    if thorport <= 0 then
  211.       ExitMsg('This script must be called from THOR!')
  212.  
  213.    /* Load bbsread.library if necessary */
  214.    if ~show('p', 'BBSREAD') then do
  215.        address command
  216.        'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  217.        'WaitForPort BBSREAD'
  218.    end
  219.  
  220.    drop opts.
  221.  
  222.    address BBSREAD
  223.  
  224.    ReadArgs Template opts CMDLINE arguments
  225.  
  226.    if rc = 5 then call ExitMsg(arguments || '*N' || BBSREAD.LASTERROR || '*N' || "Template is:" Template)
  227.    if rc > 5 then signal error
  228.  
  229.    ConfigFile = 'ENV:Thor/' || opts.BBSNAME || '_S.cfg'
  230.  
  231.    /* If no Configfile simply exit! */
  232.    if ~Exists(ConfigFile) then
  233.       exit
  234.  
  235.    VerStr     = subword(sourceline(2),3)
  236.  
  237.    true  = 1
  238.    false = 0
  239.  
  240.    /* This tags can be omitted, default will be "blank" */
  241.    TagOptsBlk = "TagPgm"
  242.  
  243.    /* This tags can be omitted, default will be "zero" */
  244.    TagOptsZro = "TagPgmType"
  245.  
  246.    TagOptions = "SigFile" TagOptsBlk TagOptsZro
  247.    NumOpts = words(TagOptions)
  248.  
  249. return
  250.  
  251.  
  252.  
  253. /* Exit with a message */
  254. ExitMsg:
  255.     parse arg msgstr
  256.     address command
  257.     'RequestChoice >NIL: "GMSignature.thor" "'msgstr'" "OK :-("'
  258. exit
  259.  
  260.