home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / mkarea10.zip / makearea.cmd < prev    next >
OS/2 REXX Batch file  |  1995-06-10  |  9KB  |  215 lines

  1. /* This REXX file is used to Auto-Setup EchoMail Areas In a MAX/SQUISH environment */
  2. CpyRite = 'MakeArea.Cmd, Copyright 1995, Herman Freeman.'
  3. Say CpyRite
  4. PreFile = 'NUL:'
  5. SufFile = 'NUL:'
  6. LogFile = 'MakeArea.Log'            /* default log */
  7. BadPath = 'Mail\MsgBad\'            /* Where to Find Untossed Msgs */
  8. AreaDat = 'ELArea.Dat'                /* Where to Find ELAREA.DAT file */
  9. NewPath = 'Mail\'                /* Where to put Newly-created areas */
  10. SqshCfg = 'Squish.Cfg'                /* Where to put new EchoArea defs for Squish*/
  11. MaxArea = 'MsgArea.Ctl'                /* Where to put new MsgArea defs for Max */
  12. RulPath = '.\'                    /* Where to look for Rules files */
  13. DscPath = 'NUL: '                /* Where to put Long Description Files extracted from ELAREA.DAT */
  14. Deflags = '-$m6000 -$d6'            /* Default Number for Days to Keep Messages */    
  15. DefPriv = 'Disgrace'                /* Default Priviledge level to access area */
  16. SysPriv = 'AsstSysop'                /* Priv. Req'd to access restricted echoes */
  17. DefKeys = ''                    /* Keys Req'd to access echo */
  18. ErrLevl = '0'                    /* ErrorLevel for Nothing Done Exit */
  19. DefLink = '3615/50'                /* Default Link to Area def for Squish */
  20. WrapLen = 78                    /* Wrap text lines to this length */
  21.                         /* Set it up to be able to use RexxUtils */
  22.  
  23. c = arg()                    /* find out if a cfg file has been passed */
  24. if c = 0
  25.   then CfgFile = 'MakeArea.Cfg'            /* no command line arg, so use default cfg */
  26.   else CfgFile = arg(1)                /* use first arg passed on command line */
  27.  
  28. rc = stream(CfgFile, 'c', 'open')        /* open the cfg file */
  29. do until lines(CfgFile) = 0
  30.   TempStr = space(translate(LineIn(CfgFile), ' ', '    '))
  31.   parse value TempStr with KeyWord TempStr
  32.   KeyWord = translate(KeyWord)
  33.   select
  34.     when left(KeyWord, 1) < 'A'            /* any character lower than a space is a comment line */
  35.       then nop                    /* so do nothing */
  36.     when KeyWord = 'BADMSGDIR'
  37.       then BadPath = TempStr
  38.     when KeyWord = 'ELAREAFILE'
  39.       then AreaDat = TempStr
  40.     when KeyWord = 'LOGFILE'
  41.       then LogFile = TempStr
  42.     when KeyWord = 'DEFAULTMAILDIR'
  43.       then NewPath = TempStr
  44.     when KeyWord = 'SQUISHCFGFILE'
  45.       then SqshCfg = TempStr
  46.     when KeyWord = 'MSGAREACTLFILE'
  47.       then MaxArea = TempStr
  48.     when KeyWord = 'RULEFILEDIR'
  49.       then RulPath = TempStr
  50.     when KeyWord = 'DESCRIPTIONDIR'
  51.       Then DscPath = TempStr
  52.     when KeyWord = 'DEFAULTSQUISHFLAGS'
  53.       then Deflags = TempStr
  54.     when KeyWord = 'DEFAULTUSERPRIV'
  55.       then DefPriv = TempStr
  56.     when KeyWord = 'SYSOPUSERPRIV'
  57.       then SysPriv = TempStr
  58.     when KeyWord = 'DEFAULTKEYS'
  59.       then DefKeys = TempStr
  60.     when KeyWord = 'DEFAULTNODELINK'
  61.       then DefLink = TempStr
  62.     when KeyWord = 'WRAPDESCLINES'
  63.       then WrapLen = TempStr
  64.     when KeyWord = 'MECCAPREFIXFILE'
  65.       then PreFile = TempStr
  66.     when KeyWord = 'MECCASUFFIXFILE'
  67.       then SufFile = TempStr
  68.     otherwise
  69. call lineout LogFile, 'Unknown Keyword in cfg file, ' || KeyWord
  70.   end
  71. end
  72. rc = stream(CfgFile, 'c', 'close')
  73.  
  74. call lineout LogFile, d2c(13) || 'MakeArea Started ' || date() time()
  75. rc  =  RxFuncQuery( 'SysLoadFuncs' )          /* Ask if SysLoadFuncs has already been done */
  76. if rc = 1 then                    /* Nope, so do it */
  77.   do
  78.     rc = RxFuncAdd( 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' )
  79.     call SysLoadFuncs
  80.   end
  81.  
  82. rc = stream(PreFile, 'c', 'open')            /* open the Mecca Prefix File */
  83. rc = stream(PreFile, 'c', 'query size')        /* find out how big it is */
  84. MeccPre = charin(Prefile, , rc)            /* read it into a variable */
  85. rc = stream(Prefile, 'c', 'close')            /* close  it */
  86.  
  87. rc = stream(SufFile, 'c', 'open')            /* open the Mecca Suffix File */
  88. rc = stream(SufFile, 'c', 'query size')        /* find out how big it is */
  89. MeccSuf = charin(SufFile, , rc)            /* read it into a variable */
  90. rc = stream(SufFile, 'c', 'close')            /* close  it */
  91.  
  92. call lineout LogFile, ' Searching ' || BadPath || ' for untossed EchoMail...'    /* Load up dir of untossed msgs int BadMsgs stem */
  93. rc = SysFileTree( BadPath  || '*.MSG', 'BadMsgs', 'FO')
  94. if BadMsgs.0 = 0 then do
  95.   call lineout LogFile, ' No untossed EchoMail found.  Exiting, EL = 0'
  96.   exit Errlevl
  97. end /* end if BadMsgs.0 */
  98.  
  99. NewArea.0 = BadMsgs.0                /* save the count of untossed msgs */
  100. SrchStr = ' '                    /* Define Search Variable */
  101. k = 0
  102. call lineout LogFile, ' Retrieving Echo Tags and Uplink paths...'
  103. do j = 1 to BadMsgs.0                /* retrieve the AREA: name from every *.msg file in the BadPath dir */
  104.   rc = stream(BadMsgs.j, 'c', 'open')
  105.   NewArea.j = ''
  106.   NewLink.j = ''
  107.   c = 0
  108.   do while lines(BadMsgs.j) > 0
  109.     TempStr = translate(linein(BadMsgs.j))
  110.     if pos(d2c(0) || 'AREA:', TempStr) > 0 then
  111.       do
  112.         TestStr = substr(TempStr, pos(d2c(0) || 'AREA:', TempStr) + 6)
  113.         c = pos(TestStr, SrchStr)
  114.         if c = 0 then
  115.           do
  116.             SrchStr = SrchStr || TestStr || ' '
  117.             k = k + 1
  118.             NewArea.k = TestStr
  119.           end
  120.       end 
  121.     if pos(d2c(1) || 'PATH:', TempStr) > 0 & c = 0
  122.       then NewLink.k = substr(TempStr, lastpos(' ', TempStr) + 1)
  123.     if lastpos('/', TempStr) < lastpos(' ', TempStr) & c = 0
  124.       then NewLink.k = DefLink
  125.   end
  126.   rc = stream(BadMsgs.j, 'c', 'close')
  127. end /* do j */
  128. /*
  129.   
  130. */
  131. drop BadMsgs                    /* drop stem variable no longer needed */
  132. drop SrchStr
  133.  
  134. call lineout LogFile, ' Searching ELAREA.DAT for Matching Echo Tags...'
  135. rc = stream(AreaDat, 'c', 'open')            /* open the ELAREA.DAT file */
  136. do until lines(AreaDat) = 0
  137.   TempStr = LineIn(AreaDat)        
  138.   c = 0
  139.   do until TempStr = ''
  140.     c = c + 1
  141.     f = 0
  142.     if left(TempStr, 1) = '"'
  143.       then parse value TempStr With ELField.c '",' TempStr
  144.       else parse value TempStr With ELField.c ',' TempStr
  145.   end /* do until TempStr */
  146.   do j = 1 to k
  147.     ro = (pos('READ-ONLY', translate(ELField.5)) > 0 | pos('READ ONLY', translate(ELField.5)) > 0)
  148.     if translate(NewArea.j) = translate(strip(ELField.1, B, '"')) then
  149.      do
  150.        if NewLink.j = '' then NewLink.j = DefLink
  151.        TempStr = 'EchoArea ' || translate(NewArea.j), 
  152.                 || copies(' ', 24 - length(NewArea.j)), 
  153.                 || NewPath || strip(ELField.2, B, '"'), 
  154.                 || copies(' ', 12 - length(ELField.2)), 
  155.                 || Deflags || ' ' || NewLink.j
  156.        call lineout LogFile, '  Writing New Squish Definition for ' || ELField.1 || '"'
  157.        call lineout SqshCfg, TempStr
  158.  
  159.        call lineout LogFile, '  Writing MsgArea Definition for ', 
  160.                 || ELField.1 || '" ' || ro || ' ' || strip(ELField.23, B, '"')
  161.        call lineout MaxArea, '% AutoAdded by MakeArea ' || date()
  162.        call lineout MaxArea, 'Area ' || strip(ELField.2, B, '"')
  163.        call lineout MaxArea, '    Type Squish'
  164.        if translate(strip(ELField.23, B, '"')) = 'Y'
  165.          then call lineout MaxArea, '    MsgAccess ' || SysPriv || '/' || DefKeys
  166.          else call Lineout MaxArea, '    MsgAccess ' || DefPriv || '/' || DefKeys
  167.        call lineout MaxArea, '    MsgInfo ' || strip(ELField.4, B, '"')
  168.        call lineout MaxArea, '    MsgName ' || strip(ELField.1, B, '"')
  169.        call lineout MaxArea, '    EchoMail ' || NewPath || strip(ELField.2, B, '"')
  170.        if ro = 0
  171.          then call lineout MaxArea, '    Public Only'
  172.          else call lineout MaxArea, '    Read-Only'
  173.        call lineout MaxArea, 'End Area'
  174.        call lineout MaxArea
  175.  
  176.        TempStr = space(strip(ELField.5, B, '"'))        /* remove extra spaces and leading " */
  177.        DscFile = DscPath || strip(ELField.2, B, '"') || '.BBS'
  178.        rc = stream(DscFile, 'c', 'open')            /* open the Desc.BBS file */
  179.        call lineout LogFile, '  Writing Description file...' || DscFile
  180.        call lineout DscFile, , 1
  181.        call charout DscFile, MeccPre    /* mecca prefix */
  182.        o = 1
  183.        l = length(TempStr)
  184.        do until o > l|o = l
  185.          c = lastpos(' ', substr(TempStr, o, WrapLen + 1))
  186.          h = lastpos('-', substr(TempStr, o, WrapLen + 1))
  187.          if (h < WrapLen|h = WrapLen) & h > c then c = h
  188.          call lineout DscFile, substr(TempStr, o, c - 1)
  189.          o = o + c
  190.        end
  191.        call lineout DscFile, MeccSuf    /* mecca suffix */
  192.        rc = stream(DscFile, 'c', 'close')
  193.        ErrLevl = 1
  194.        f = 1
  195.        NewArea.j = ''
  196.      end /* if translate(NewArea.j) */
  197.     if f = 1 then leave /* do j = 1 to NewArea.0 */
  198.   end /* do j = 1 to NewArea.0 */
  199. end /* do until lines(AreaDat) */
  200.  
  201. call lineout LogFile, "  Couldn't Create Following Areas:"
  202.  
  203. do j = 1 to NewArea.0
  204.   if NewArea.j > '' 
  205.     then call lineout LogFile, '    EchoArea ' ||,
  206.     translate(NewArea.j) || copies(' ', 24 - length(NewArea.j)) ||,
  207.     NewPath || 'JunkArea   -$m500 -0  ' || NewLink.j
  208.  
  209. end
  210.  
  211. call SysDropFuncs            /* clean up before we leave */
  212. call lineout LogFile, 'MakeArea Ended ' || date() time()                /* say when we finished     */
  213. say 'MakeArea.Cmd, Ended with ErrorLevel = ' || ErrLevl
  214. Exit Errlevl                /* Exit with ErrorLevel set */
  215.