home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Utilities / arc2arc / arc2arc.rexx < prev    next >
OS/2 REXX Batch file  |  2000-08-16  |  2KB  |  124 lines

  1. /*
  2. ** $VER: arc2arc.rexx 2.5 (16.8.00) Rolf Max Rotvel
  3. */
  4.  
  5. /*
  6. ** Configuration
  7. */
  8.  
  9.  
  10. /* Number of dearchivers */
  11. dearc.0 = 7
  12.  
  13. /* Dearchivers */
  14. dearc.1 = '.TAR.GZ cc:untar020 KEEP'    /* Childpatterns before parentpatterns */
  15. dearc.2 = '.GZ cc:gzip -d -c >'         /* GZip requires redirection */
  16. dearc.3 = '.LZX cc:unlzx -x'
  17. dearc.4 = '.ZIP cc:unzip'
  18. dearc.5 = '.LZH lha x'
  19. dearc.6 = '.TGZ cc:untar020 KEEP'
  20. dearc.7 = '.LHA lha x'
  21.  
  22. /* Number of archivers */
  23. arc.0 = 3
  24.  
  25. /* Archivers */
  26. arc.1 = 'LHA lha a'                     /* Default archiver */
  27. arc.2 = 'LZX cc:lzx040 -bi128 -bo128 -e -F -M4000 -Qf -r -9 a'
  28. arc.3 = 'ZIP cc:zip -R -9'
  29.  
  30.  
  31. /* Tmpdir */
  32. tmpdir = 't:'                           /* Where to unpack archives */
  33.  
  34.  
  35. /*
  36. ** End of configuration
  37. */
  38.  
  39.  
  40. call addlib('rexxsupport.library', 0, -30, 0)
  41. address command
  42. file = arg(1)
  43.  
  44. if file = '?' then do
  45.     say 'Usage: <arctype> filename'
  46.     exit
  47. end
  48.  
  49. arc = ''
  50. arctype = upper(word(file, 1))
  51. do i = 1 to arc.0
  52.     if arctype = word(arc.i, 1) then do
  53.         arc = subword(arc.i, 2)
  54.         leave
  55.     end
  56. end
  57.  
  58. if arc = '' then do
  59.     if exists(file) then do
  60.         arctype = word(arc.1, 1)
  61.         arc = subword(arc.1, 2)
  62.     end
  63.     else do
  64.         say 'No archiver found for "'arctype'"'
  65.         say 'or "'file'" doesn''t exist'
  66.         exit
  67.     end
  68. end
  69. else file = subword(file, 2)
  70.             
  71. cmd = ''
  72. do i = 1 to dearc.0
  73.     pat = upper(word(dearc.i, 1))
  74.     patlen = length(pat)
  75.     cuthere = (length(file) - patlen)
  76.  
  77.     if pos(pat, upper(file)) = cuthere + 1 then do
  78.         cmd = subword(dearc.i, 2)
  79.         leave
  80.     end
  81. end
  82.  
  83. if cmd = '' then do
  84.     say 'No dearchiver found for "'file'"'
  85.     exit
  86. end
  87.  
  88. newfile = substr(file, 1, cuthere)
  89.  
  90. tmpdir = makepath(tmpdir, 'arc2arc_tmp')
  91. olddir = pragma('d', tmpdir)
  92. if olddir = '' then do
  93.     if ~makedir(tmpdir) then exit 10
  94.     call pragma('d', tmpdir)
  95. end
  96.  
  97. /* For unpacking to STDOUT (GZip) */
  98. if right(cmd, 1) = '>' then do
  99.     cmd = cmd||makepath(tmpdir, getfilepart(substr(file, 1, lastpos('.', file)-1)))
  100. end
  101.  
  102. desc = subword(statef(file), 8)
  103. desc = strip(translate(desc, "'", '"'))
  104.  
  105. cmd file 
  106. arc newfile '#?'
  107.  
  108. /* ! */
  109. if desc ~= '' then 'filenote 'newfile'.'arctype' "'desc'" QUIET'
  110.  
  111. 'delete 'makepath(tmpdir, '#?')' ALL FORCE QUIET'
  112. exit
  113.  
  114.  
  115. GETFILEPART: procedure
  116. parse arg path
  117. return strip(substr(path, max(pos(':', path), lastpos('/', path)) + 1))
  118.  
  119.  
  120. MAKEPATH: procedure
  121. parse arg path, file
  122. if pos(right(path, 1), ':/') = 0 then return path'/'file
  123. return path||file
  124.