home *** CD-ROM | disk | FTP | other *** search
/ New Horizons Shareware Collection / HORIZONS1.BIN / TICK.ZIP / mpmtic.cmd < prev   
OS/2 REXX Batch file  |  1994-11-14  |  11KB  |  322 lines

  1. /***************************************************************************/
  2. /*                                                                         */
  3. /* REXX TIC processor using MaxFile/PM's REXX extensions.                  */
  4. /* Copyright (C) 1994 by Craig Morrison, All Rights Reserved.              */
  5. /*                                                                         */
  6. /* This REXX script only processes inbound TICs, it does not have downlink */
  7. /* capabilities. What you have here is a good start.                       */
  8. /*                                                                         */
  9. /* PLEASE, PLEASE look through this file and see how it works BEFORE you   */
  10. /* blindly run it. As it is written you specify an area for all your "bad" */
  11. /* TIC distributions to go into. You may not want this behaviour. This is  */
  12. /* a REXX script so you can change this.                                   */
  13. /*                                                                         */
  14. /* The TIC `Replaces' verb isn't supported. That can be an exercise for    */
  15. /* the student. :-)                                                        */
  16. /*                                                                         */
  17. /* The configuration file format is very simple. It consists of a file     */
  18. /* with each line formatted like so:                                       */
  19. /*                                                                         */
  20. /*      <tick_area_tag> <your_area_tag> <from_node> <password>             */
  21. /*                                                                         */
  22. /* See the example MAXTIC.CFG included in the archive.                     */
  23. /*                                                                         */
  24. /***************************************************************************/
  25. '@echo off'
  26.  
  27. Signal On Syntax Name ErrorHandler
  28. Signal On Halt Name ErrorHandler
  29.  
  30. /* Define some constants we will use later */
  31. BadFileArea = '0'
  32. InboundPath = 'D:\Binkley\Inbound\'
  33. ConfigFile = 'D:\BCOS2\MaxFile\MaxTic.Cfg'
  34. LogFile = 'D:\BCOS2\MaxFile\MaxTic.Log'
  35. Verbs = 'AREA CRC DESC FILE FROM PW'
  36.  
  37. Call LineOut LogFile, Date('N')' 'Time('N')' MaxTic - Begin'
  38.  
  39. /* Load up the RexxUtil Library */
  40. Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  41. Call SysLoadFuncs
  42.  
  43. /* Get a list of all the file areas we have */
  44. Call MPM_QueryAreaList 'FileAreas'
  45.  
  46. /* Make sure the Bad File Area exists so we can toss to there */
  47. BadAreaIdx = FindFileArea(BadFileArea)
  48. if BadAreaIdx = 0 Then
  49.     Signal NoBadArea
  50.  
  51. /* Check for configuration file and bail out if it doesn't exist */
  52. If Stream(ConfigFile, 'c', 'query exists')='' Then
  53.     Signal NoConfig
  54.  
  55. /* Read in and parse configuration file into the Cfg stem */
  56. i = 1
  57. Cfg.0 = 0
  58. Do Until Lines(ConfigFile)=0
  59.     cfgLine = LineIn(ConfigFile)
  60.     Parse Upper Var cfgLine Cfg.i.tictag,
  61.                             Cfg.i.ourtag,
  62.                             Cfg.i.from,
  63.                             Cfg.i.pwd,
  64.                             extra
  65.     Cfg.0 = i
  66.     i = i + 1
  67. End
  68. Call Stream ConfigFile, 'c', 'close'
  69.  
  70. /* Gather TIC file names into the ticFiles stem */
  71. Call SysFileTree InboundPath'*.TIC', 'ticFiles', 'FO'
  72.  
  73. /* If no TIC files are present bail out */
  74. If ticFiles.0 = 0 Then
  75.     Signal NoFiles
  76.  
  77. /* Process each TIC file */
  78. Do i = 1 To ticFiles.0
  79.     Say 'Processing 'ticFiles.i'. . .'
  80.     tArea = ''
  81.     tCRC = ''
  82.     tDesc = ''
  83.     tFile = ''
  84.     tFrom = ''
  85.     tPWD = ''
  86.     Do Until Lines(ticFiles.i)=0
  87.         tLine = LineIn(ticFiles.i)
  88.         Parse Var tLine tVerb tExtra
  89.         verbNo = WordPos(Translate(tVerb), Verbs)
  90.         Select
  91.             When verbNo = 1 Then Do
  92.                 Parse Upper Var tExtra tArea junk
  93.                 End
  94.             When verbNo = 2 Then Do
  95.                 Parse Upper Var tExtra tCRC junk
  96.                 End
  97.             When verbNo = 3 Then Do
  98.                 Parse Var tExtra tDesc
  99.                 End
  100.             When verbNo = 4 Then Do
  101.                 Parse Var tExtra tFile junk
  102.                 End
  103.             When verbNo = 5 Then Do
  104.                 Parse Var tExtra tFrom junk
  105.                 End
  106.             When verbNo = 6 Then Do
  107.                 Parse Upper Var tExtra tPWD junk
  108.                 End
  109.             Otherwise
  110.                 Nop
  111.         End
  112.     End
  113.     Call Stream ticFiles.i, 'c', 'close'
  114.  
  115.     If Stream(InboundPath||tFile, 'c', 'query exists')='' Then Do
  116.         Call LineOut LogFile,,
  117.             Date('N')' 'Time('N')' 'tFile' does not exist'
  118.         badTIC = MakeBadTicName(ticFiles.i)
  119.         Call LineOut LogFile,,
  120.             Date('N')' 'Time('N')' Check inbound for 'badTIC
  121.         dosCmd = 'REN 'ticFiles.i' 'badTIC' >nul'
  122.         dosCmd
  123.         Iterate
  124.     End
  125.  
  126.     /* Find the index of the TIC area tag in our configuration stem */
  127.     cfgIdx = 0
  128.     Do j = 1 To Cfg.0
  129.         If Cfg.j.tictag = tArea Then Do
  130.             cfgIdx = j
  131.             Leave
  132.         End
  133.     End
  134.  
  135.     if cfgIdx = 0 Then Do
  136.         Call TossFile InboundPath||tFile,,
  137.                       FileAreas.BadAreaIdx.path||tFile,,
  138.                       FileAreas.BadAreaIdx.fbbs,,
  139.                       tFile' Bad TIC - 'tDesc
  140.         Call LineOut LogFile,,
  141.             Date('N')' 'Time('N')' Unknown TIC area 'tArea
  142.         badTIC = MakeBadTicName(ticFiles.i)
  143.         Call LineOut LogFile,,
  144.             Date('N')' 'Time('N')' Check inbound for 'badTIC
  145.         dosCmd = 'REN 'ticFiles.i' 'badTIC' >nul'
  146.         dosCmd
  147.         Iterate
  148.     End
  149.  
  150.     /* NOTE: this is a BOGUS loop, I did this because it is easier */
  151.     /* to use Leave instead of an obfuscated set of If-Then-Else's */
  152.     /* Purists will argue this isn't structured REXX, that's their */
  153.     /* problem. It works fine the way it is.                       */
  154.  
  155.     Do Forever
  156.         AreaIdx = FindFileArea(Cfg.cfgIdx.ourtag)
  157.         if AreaIdx = 0 Then Do
  158.             Call TossFile InboundPath||tFile,,
  159.                           FileAreas.BadAreaIdx.path||tFile,,
  160.                           FileAreas.BadAreaIdx.fbbs,,
  161.                           tFile' Bad TIC - 'tDesc
  162.             Call LineOut LogFile,,
  163.                 Date('N')' 'Time('N')' Area tag 'Cfg.cfgIdx.ourtag' bogus'
  164.             badTIC = MakeBadTicName(ticFiles.i)
  165.             Call LineOut LogFile,,
  166.                 Date('N')' 'Time('N')' Check inbound for 'badTIC
  167.             dosCmd = 'REN 'ticFiles.i' 'badTIC' >nul'
  168.             dosCmd
  169.             Leave
  170.         End
  171.  
  172.         If tFrom<>Cfg.cfgIdx.from Then Do
  173.             Call TossFile InboundPath||tFile,,
  174.                           FileAreas.BadAreaIdx.path||tFile,,
  175.                           FileAreas.BadAreaIdx.fbbs,,
  176.                           tFile' Bad TIC - 'tDesc
  177.             Call LineOut LogFile,,
  178.                 Date('N')' 'Time('N')' TIC from unknown origin 'tFile
  179.             badTIC = MakeBadTicName(ticFiles.i)
  180.             Call LineOut LogFile,,
  181.                 Date('N')' 'Time('N')' Check inbound for 'badTIC
  182.             dosCmd = 'REN 'ticFiles.i' 'badTIC' >nul'
  183.             dosCmd
  184.             Leave
  185.         End
  186.  
  187.         If tPWD<>Cfg.cfgIdx.pwd Then Do
  188.             Call TossFile InboundPath||tFile,,
  189.                           FileAreas.BadAreaIdx.path||tFile,,
  190.                           FileAreas.BadAreaIdx.fbbs,,
  191.                           tFile' Bad TIC - 'tDesc
  192.             Call LineOut LogFile,,
  193.                 Date('N')' 'Time('N')' Bad TIC Password for 'tFile
  194.             badTIC = MakeBadTicName(ticFiles.i)
  195.             Call LineOut LogFile,,
  196.                 Date('N')' 'Time('N')' Check inbound for 'badTIC
  197.             dosCmd = 'REN 'ticFiles.i' 'badTIC' >nul'
  198.             dosCmd
  199.             Leave
  200.         End
  201.  
  202.         ticCRC = MPM_Crc32(InboundPath||tFile)
  203.         if (tCRC <> '' & ticCRC <> tCRC) Then Do
  204.             Call TossFile InboundPath||tFile,,
  205.                           FileAreas.BadAreaIdx.path||tFile,,
  206.                           FileAreas.BadAreaIdx.fbbs,,
  207.                           tFile' Bad TIC - 'tDesc
  208.             Call LineOut LogFile,,
  209.                 Date('N')' 'Time('N')' Bad TIC CRC for 'tFile
  210.             badTIC = MakeBadTicName(ticFiles.i)
  211.             Call LineOut LogFile,,
  212.                 Date('N')' 'Time('N')' Check inbound for 'badTIC
  213.             dosCmd = 'REN 'ticFiles.i' 'badTIC' >nul'
  214.             dosCmd
  215.             Leave
  216.         End
  217.  
  218.         /* If we get here, the file is okay and should be sent to */
  219.         /* its proper file area.                                  */
  220.         Call TossFile InboundPath||tFile,,
  221.                       FileAreas.AreaIdx.path||tFile,,
  222.                       FileAreas.AreaIdx.fbbs,,
  223.                       tFile' 'tDesc
  224.         dosCmd = 'DEL 'ticFiles.i' >nul'
  225.         dosCmd
  226.         If rc<>0 Then
  227.             Call LineOut LogFile,,
  228.                 Date('N')' 'Time('N')' Error deleting 'ticFiles.i
  229.         Leave
  230.     End
  231. End
  232.  
  233. /* Get outta Dodge */
  234. ByeBye:
  235. Call LineOut LogFile, Date('N')' 'Time('N')' MaxTic - END'
  236. Call Stream LogFile, 'c', 'close'
  237. Exit
  238.  
  239. /* Move file from the inbound to its destination and update the FILES.BBS */
  240. TossFile:
  241.  
  242.     Parse Arg fromFile, toFile, filesBBS, ticDescription
  243.  
  244.     tossError = 0
  245.     dosCmd = 'COPY 'fromFile' 'toFile' >nul'
  246.     dosCmd
  247.     If rc<>0 Then Do
  248.         Call LineOut LogFile,,
  249.             Date('N')' 'Time('N')' Error copying 'fromFile' to 'toFile
  250.         tossError = 1
  251.     End
  252.     Else Do
  253.         Call LineOut LogFile,,
  254.             Date('N')' 'Time('N')' 'fromFile' copied to 'toFile
  255.         Call LineOut filesBBS, ticDescription
  256.         Call Stream filesBBS, 'c', 'close'
  257.         Call LineOut LogFile, Date('N')' 'Time('N')' 'filesBBS' updated'
  258.         dosCmd = 'DEL 'fromFile' >nul'
  259.         dosCmd
  260.         If rc<>0 Then Do
  261.             Call LineOut LogFile,,
  262.                 Date('N')' 'Time('N')' Error deleting 'fromFile
  263.             tossError = 2
  264.         End
  265.         If tossError = 0 Then
  266.             Call LineOut LogFile,,
  267.                 Date('N')' 'Time('N')' 'fromFile' deleted after copy'
  268.     End
  269.  
  270. Return tossError
  271.  
  272. /* Search through FileAreas looking for a file area tag (name) */
  273. FindFileArea:
  274.  
  275.     Parse Arg atag
  276.  
  277.     itag = 0
  278.     Do ii = 1 to FileAreas.0
  279.         If FileAreas.ii.area = atag Then Do
  280.             itag = ii
  281.             Leave
  282.         End
  283.     End
  284.  
  285. Return itag
  286.  
  287. /* Take *.TIC and make it *.BAD */
  288. MakeBadTicName:
  289.  
  290.     Parse Arg inTIC
  291.  
  292.     ppos = LastPos('.', inTIC)
  293.     If ppos = 0 Then
  294.         ppos = Length(inTIC)
  295.     Else
  296.         ppos = ppos - 1
  297.  
  298.     BadTicName = Left(inTIC, ppos)'.BAD'
  299.  
  300. Return BadTicName
  301.  
  302. /* No files to process */
  303. NoFiles:
  304.     Call LineOut LogFile, Date('N')' 'Time('N')' No TIC files to process'
  305.     Signal ByeBye
  306.  
  307. /* Bitch about not having a configuration file */
  308. NoConfig:
  309.     Call LineOut LogFile, Date('N')' 'Time('N')' No configuration file'
  310.     Signal ByeBye
  311.  
  312. /* Bitch about not having a valid BadFileArea */
  313. NoBadArea:
  314.     Call LineOut LogFile, Date('N')' 'Time('N')' Area 'BadFileArea' invalid'
  315.     Signal ByeBye
  316.  
  317. ErrorHandler:
  318.     RexxError = rc
  319.     Call MPM_MsgBox('REXX Error ('RexxError')', 'MaxTic - Error Handler')
  320.     Call LineOut LogFile, Date('N')' 'Time('N')' REXX Error ('RexxError')'
  321.     Signal ByeBye
  322.