home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / packery / lha2lzx / lha2lzx.rexx < prev    next >
OS/2 REXX Batch file  |  1977-12-31  |  6KB  |  181 lines

  1. /* This script converts LHA archives to LZX archives
  2.  * Author: Martin Hilpert (hima0011@fh-karlsruhe.de)
  3.  * $VER: LHA2LZX 1.3 (15.02.97) © 1996 by Martin Hilpert (hima0011@fh-karlsruhe.de)
  4.  */
  5.  
  6. ADDRESS COMMAND   /* for executing DOS commands */
  7.  
  8. IF ARG() ~= 1 THEN DO
  9.   SAY "usage: rx LHA2LZX [options] <LHA archive with full path> <destination path>"
  10.   SAY "options are: -t enable testing of archives"
  11.   SAY "             -f enable filenote"
  12.   SAY "             -n disable deletion of dearchived files"
  13.   SAY "             -s Amiga talks ..."
  14.   SAY "             +v<PathOfVirusZ> enable virus checking"
  15.   SAY "             +z<TempPath> path for the temporary directory"
  16.   EXIT 5
  17. END
  18.  
  19. /* split argument string to different parts */
  20. PARSE ARG Arguments
  21.  
  22. iDevice = LASTPOS(":",Arguments)
  23. iDevice = LASTPOS(":",Arguments,iDevice-1)
  24. iSpace1 = LASTPOS(" ",Arguments,iDevice)
  25. Options = SUBSTR(Arguments,1,iSpace1)
  26. iSpace2 = POS(" ",Arguments,iDevice)
  27. iSourcePath = LASTPOS("/",Arguments,iSpace2)
  28. SourcePath = SUBSTR(Arguments,iSpace1+1,iSourcePath-iSpace1)
  29. LhaArchive = SUBSTR(Arguments,iSourcePath+1,iSpace2-1-iSourcePath)
  30. Basename = SUBSTR(LhaArchive,1,LASTPOS(".",LhaArchive)-1)
  31. Basename = TRANSLATE(Basename,"_","~")   /* ~ -> _ */
  32. iSpace1 = LASTPOS(" ",Arguments)
  33. iDevice = LASTPOS(":",Arguments)
  34. iSpace2 = LASTPOS(" ",Arguments,iDevice)
  35. DestinationPath = SUBSTR(Arguments,iSpace2+1,LENGTH(Arguments)-iSpace2)
  36.  
  37. IF POS("-t",Options) ~= 0 THEN
  38.   o_test = 1
  39. else
  40.   o_test = 0
  41.  
  42. IF POS("-s",Options) ~= 0 THEN
  43.   o_speech = 1
  44. else
  45.   o_speech = 0
  46.  
  47. IF POS("-f",Options) ~= 0 THEN
  48.   o_filenote = 1
  49. else
  50.   o_filenote = 0
  51.  
  52. IF POS("-n",Options) ~= 0 THEN
  53.   o_nodelete = 1
  54. else
  55.   o_nodelete = 0
  56.  
  57. /* temporary path for dearchived files */
  58. TempPath = "RAM:"              /* default path */
  59. Index = POS("+z",Options)
  60. IF Index ~= 0 THEN DO
  61.   iSpace = POS(" ",Options,Index)      /* end of +zDevice:Path */
  62.   IF iSpace == 0 THEN                  /* last option ? */
  63.     iSpace = LENGTH(Options) + 1
  64.   TempPath = SUBSTR(Options,Index+2,iSpace-Index-2)
  65.   TempPath = SPACE(TempPath,0)
  66.   IF LASTPOS("/",TempPath) ~= LENGTH(TempPath) THEN   /* last character a slash? */
  67.     TempPath = TempPath || "/"         /* slash is mandatory */
  68. END
  69. TempPath = TempPath || "LHA2LZX/"
  70.  
  71. o_virustest = 0
  72. Index = POS("+v",Options)
  73. IF Index ~= 0 THEN DO
  74.   iSpace = POS(" ",Options,Index)      /* end of +vDevice:Path */
  75.   IF iSpace == 0 THEN                  /* last option ? */
  76.     iSpace = LENGTH(Options) + 1
  77.   ViruszPath = SUBSTR(Options,Index+2,iSpace-Index-2)
  78.   ViruszPath = SPACE(ViruszPath,0)
  79.   IF EXISTS(ViruszPath'VirusZ') == 1 THEN
  80.     o_virustest = 1
  81.   else
  82.     'echo "*E[31;42mCan''t find VirusZ!*E[0m"'
  83. END
  84.  
  85. IF POS("-c",Options) ~= 0 THEN DO
  86.   'echo "              options:"' Options
  87.   'echo "     source directory:"' SourcePath
  88.   'echo "              archive:"' LhaArchive
  89.   'echo "             basename:"' Basename
  90.   'echo "destination directory:"' DestinationPath
  91.   'echo "  temporary directory:"' TempPath
  92.   IF o_virustest == 1 THEN
  93.     'echo "      VirusZ location:"' ViruszPath
  94. END
  95.  
  96. /**************************************/
  97. IF o_test = 1 THEN DO
  98.   'echo "*E[32;41mtesting LHA archive ...*E[0m"'
  99.   IF o_speech = 1 THEN
  100.     'say "testing Elleigeigh r kive"'
  101.   'LHA -b64 -F t' SourcePath || LhaArchive
  102.   IF RC ~= 0 THEN DO
  103.     'FILENOTE' SourcePath || LhaArchive 'COMMENT "FAILED archive test!"'
  104.     'echo "*E[31;42mLHA archive test failed!*E[0m (exiting...)"'
  105.     IF o_speech = 1 THEN
  106.       'say "Attention! Something went wrong!"'
  107.     EXIT 10
  108.   END
  109.   IF o_filenote = 1 THEN
  110.     'FILENOTE' SourcePath || LhaArchive 'COMMENT "archive tested"'
  111. END
  112.  
  113. /**************************************/
  114. 'echo "*E[32;41mdearchiving LHA ...*E[0m"'
  115. 'DELETE' TempPath'#? ALL FORCE QUIET'   /* clear TempPath */
  116. IF RC ~= 0 & RC ~= 5 THEN DO   /* is there some stuff left? */
  117.   'echo "*E[31;42mCan''t delete whole temporary directory!*E[0m (exiting...)"'
  118.   IF o_speech = 1 THEN
  119.     'say "Attention! Something went wrong!"'
  120.   EXIT 10
  121. END
  122. IF o_speech = 1 THEN
  123.   'say "unpacking Elleigeigh r kive"'
  124. 'LHA -b64 -F x' SourcePath || LhaArchive TempPath
  125. IF RC ~= 0 THEN DO
  126.   'FILENOTE' SourcePath || LhaArchive 'COMMENT "FAILED dearchiving!"'
  127.   'echo "*E[31;42mLHA dearchiving failed!*E[0m (exiting...)"'
  128.   IF o_speech = 1 THEN
  129.     'say "Attention! Something went wrong!"'
  130.   EXIT 10
  131. END
  132.  
  133. /**************************************/
  134. IF o_virustest = 1 THEN DO
  135.   'echo "*E[32;41mchecking files for viruses ...*E[0m"'
  136.   IF o_speech = 1 THEN
  137.     'say "Checking files for viruses"'
  138.   ViruszPath'VirusZ CX_POPUP=NO FILECHECK' TempPath'#? ALL'
  139.   IF RC ~= 0 THEN DO
  140.     'echo "*E[31;42mVirus checking failed!*E[0m (exiting...)"'
  141.   IF o_speech = 1 THEN
  142.     'say "Attention! Something went wrong!"'
  143.   EXIT 10
  144.   END
  145. END
  146.  
  147. /**************************************/
  148. 'echo "*E[32;41marchiving to LZX archive ...*E[0m"'
  149. IF o_speech = 1 THEN
  150.   'say "packing files to Elzetex r kive"'
  151. /* save path and cd to temporary path */
  152. OriDir = PRAGMA('D',TempPath)
  153. 'LZX -r -e -3 -M8000 -F -Y -bi256 -bo256 -wRAM: a' DestinationPath || Basename '*'
  154. IF RC ~= 0 THEN DO
  155.   'echo "*E[31;42mLZX archiving failed!*E[0m (exiting...)"'
  156.   IF o_speech = 1 THEN
  157.     'say "Attention! Something went wrong!"'
  158.   EXIT 10
  159. END
  160. RC = PRAGMA('D',OriDir)   /* restore old path */
  161. IF o_nodelete = 0 THEN
  162.   'DELETE' TempPath'#?' TempPath 'ALL FORCE QUIET'
  163.  
  164. /**************************************/
  165. IF o_test = 1 THEN DO
  166.   'echo "*E[32;41mtesting LZX archive ...*E[0m"'
  167.   IF o_speech = 1 THEN
  168.     'say "testing Elzetex r kive"'
  169.   'LZX -F t' DestinationPath || Basename
  170.   IF o_filenote = 1 THEN
  171.     'FILENOTE' DestinationPath || Basename || ".lzx" 'COMMENT "archive tested"'
  172. END
  173.  
  174. SAY "LHA2LZX finished - goodbye!"
  175. IF o_speech = 1 THEN
  176.   'say "Elleigeigh to Elzetex finished - goodbuy!"'
  177.  
  178. End:
  179. EXIT
  180.  
  181.