home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Utilities / arc2arc / arc2arc.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  2000-10-12  |  4.2 KB  |  184 lines

  1. /*
  2.  * $VER: arc2arc.rexx 2.8 (9.10.00) Rolf Max Rotvel
  3.  */
  4.  
  5. call addlib('rexxsupport.library', 0, -30, 0)
  6. file = arg(1)
  7. if file = '?' then do
  8.     say 'rx arc2arc [ARCTYPE],DIR/M,P=PAT/K,SUB/K,SINCE/K,UPTO/K,ALL/S'
  9.     exit
  10. end
  11.  
  12. maxstr = 65535
  13. cfgfile = 's:arc2arc.prefs'
  14. if ~open('tmp', cfgfile, 'r') then do
  15.     say cfgfile' : 'getfault(205)
  16.     exit
  17. end
  18. cfg = readch('tmp', maxstr)
  19. call close('tmp')
  20. interpret cfg
  21.  
  22. olddir = ''
  23. deltmp = 't:arc2arc_deltmp'
  24. tmpdir = makepath(tmpdir, 'arc2arc_tmp')
  25. upfile = upper(file)
  26. arc = ''
  27. nl = '0a'x
  28. options prompt '* 'overwritestr' [y/N] '
  29. listtmp = 't:arc2arc_listtmp'
  30. arcpath = 'arc2arc:'
  31.  
  32. address command
  33. signal on failure
  34.  
  35. do i = 1 to arc.0
  36.     arctype = word(arc.i, 1)
  37.     uparctype = upper(arctype)
  38.     arcpos = find(upfile, uparctype)
  39.     if arcpos > 0 then do
  40.         arc = subword(arc.i, 2)
  41.         file = delword(file, arcpos, 1)       
  42.         leave
  43.     end
  44. end
  45. if arc = '' then do
  46.     arctype = word(arc.1, 1)
  47.     arc = subword(arc.1, 2)
  48. end
  49.  
  50. if ~exists(tmpdir) then 'makedir 'tmpdir
  51. 'list 'file' FILES LFORMAT "*"%f%s*" *"%c*"" TO 'listtmp
  52. tmppat = makepath(tmpdir, '#?')
  53.  
  54. if ~open('tmp', listtmp, 'r') then do
  55.     say listtmp' : 'getfault(205)
  56.     exit
  57. end
  58. lines = readch('tmp', maxstr)
  59. call close('tmp')
  60.  
  61. do forever
  62.     if lines = '' then leave
  63.     parse var lines '"'oldfile'"' '"'comment'"' (nl) lines
  64.  
  65.     filename = getfilepart(oldfile)
  66.     oldpath = getpathpart(oldfile)
  67.  
  68.     cmd = ''
  69.     do i = 1 to dearc.0
  70.         pat = word(dearc.i, 1)
  71.         pat = upper(pat)
  72.         patlen = length(pat)
  73.         cuthere = (length(filename) - patlen)
  74.  
  75.         upfilename = upper(filename)
  76.         if pos(pat, upfilename) = cuthere + 1 then do
  77.             cmd = subword(dearc.i, 2)
  78.             leave
  79.         end
  80.     end
  81.  
  82.     if cmd = '' then say '* 'nodearcstr' 'oldfile
  83.     else do
  84.         if pos(' ', filename) > 0 then do
  85.             filename = translate(filename, '-', ' ')
  86.             tmpfile = makepath(oldpath, filename)
  87.             'rename "'oldfile'" "'tmpfile'"'
  88.             oldfile = tmpfile
  89.         end
  90.  
  91.         newfilename = substr(filename, 1, cuthere)
  92.         newfilename = translate(newfilename, '_', '.')
  93.  
  94.         lowerarctype = lowercase(arctype)
  95.         newfilearc = makepath(oldpath, newfilename'.'lowerarctype)
  96.         say '* 'oldfile' -> 'newfilearc
  97.  
  98.         skipit? = 0
  99.         if exists(newfilearc) then do
  100.             say '* 'newfilearc' : 'getfault(203)
  101.             pull ans
  102.             if ans = 'Y' then do
  103.                 'delete "'newfilearc'" >'deltmp
  104.                 call delete(deltmp)
  105.             end
  106.             else skipit? = 1
  107.         end
  108.  
  109.         if ~skipit? then do
  110.             if right(cmd, 1) = '>' then cmd = cmd||makepath(tmpdir, newfilename)
  111.  
  112.             file = makepath(arcpath, filename)
  113.             newfile = makepath(arcpath, newfilename)
  114.             'assign "'arcpath'" "'oldpath'"'
  115.  
  116.             olddir = pragma('d', tmpdir)
  117.             say
  118.             cmd '"'file'"'
  119.             arc '"'newfile'"' '#?'
  120.             say    
  121.             call pragma('d', olddir)
  122.             'delete "'tmppat'" ALL FORCE QUIET'
  123.  
  124.             if comment ~= '' then do
  125.                 comment = translate(comment, "'", '"')
  126.                 'filenote "'newfilearc'" "'comment'"'
  127.             end
  128.         end
  129.     end
  130. end
  131.  
  132. 'assign arc2arc:'
  133. 'delete "'tmpdir'" ALL FORCE >'deltmp
  134. call delete(deltmp)
  135. exit
  136.  
  137.  
  138. GETFILEPART: procedure
  139. parse arg path
  140. return strip(substr(path, max(pos(':', path), lastpos('/', path)) + 1))
  141.  
  142.  
  143. GETPATHPART: procedure
  144. parse arg path
  145. return strip(substr(path, 1, max(pos(':', path), lastpos('/', path) - 1)))
  146.  
  147.  
  148. MAKEPATH: procedure
  149. parse arg path, file
  150. if path ~= '' & pos(right(path, 1), ':/') = 0 then return path'/'file
  151. return path||file
  152.  
  153.  
  154. GETFAULT: procedure
  155. num = arg(1)
  156. faulttmp = 't:getfault.tmp'
  157. address command 'fault 'num' >'faulttmp
  158. call open('tmp', faulttmp, 'r')
  159. parse value readln('tmp') with ':'errmsg
  160. call close('tmp')
  161. call delete(faulttmp)
  162. return strip(errmsg)
  163.  
  164.  
  165. LOWERCASE: procedure
  166. return translate(arg(1), xrange('a', 'z'), xrange('A', 'Z'))
  167.  
  168.  
  169. FAILURE:
  170. 'assign "'arcpath'"'
  171. call delete(listtmp)
  172.  
  173. if olddir ~= '' then do        
  174.     call pragma('d', olddir)
  175.     'delete "'tmppat'" ALL FORCE QUIET'
  176.     call delete(tmpdir)
  177. end
  178.  
  179. if exists(deltmp) then do
  180.     'type "'deltmp'"'
  181.     call delete(deltmp)
  182. end
  183. exit
  184.