home *** CD-ROM | disk | FTP | other *** search
- /*
- * $VER: arc2arc.rexx 2.8 (9.10.00) Rolf Max Rotvel
- */
-
- call addlib('rexxsupport.library', 0, -30, 0)
- file = arg(1)
- if file = '?' then do
- say 'rx arc2arc [ARCTYPE],DIR/M,P=PAT/K,SUB/K,SINCE/K,UPTO/K,ALL/S'
- exit
- end
-
- maxstr = 65535
- cfgfile = 's:arc2arc.prefs'
- if ~open('tmp', cfgfile, 'r') then do
- say cfgfile' : 'getfault(205)
- exit
- end
- cfg = readch('tmp', maxstr)
- call close('tmp')
- interpret cfg
-
- olddir = ''
- deltmp = 't:arc2arc_deltmp'
- tmpdir = makepath(tmpdir, 'arc2arc_tmp')
- upfile = upper(file)
- arc = ''
- nl = '0a'x
- options prompt '* 'overwritestr' [y/N] '
- listtmp = 't:arc2arc_listtmp'
- arcpath = 'arc2arc:'
-
- address command
- signal on failure
-
- do i = 1 to arc.0
- arctype = word(arc.i, 1)
- uparctype = upper(arctype)
- arcpos = find(upfile, uparctype)
- if arcpos > 0 then do
- arc = subword(arc.i, 2)
- file = delword(file, arcpos, 1)
- leave
- end
- end
- if arc = '' then do
- arctype = word(arc.1, 1)
- arc = subword(arc.1, 2)
- end
-
- if ~exists(tmpdir) then 'makedir 'tmpdir
- 'list 'file' FILES LFORMAT "*"%f%s*" *"%c*"" TO 'listtmp
- tmppat = makepath(tmpdir, '#?')
-
- if ~open('tmp', listtmp, 'r') then do
- say listtmp' : 'getfault(205)
- exit
- end
- lines = readch('tmp', maxstr)
- call close('tmp')
-
- do forever
- if lines = '' then leave
- parse var lines '"'oldfile'"' '"'comment'"' (nl) lines
-
- filename = getfilepart(oldfile)
- oldpath = getpathpart(oldfile)
-
- cmd = ''
- do i = 1 to dearc.0
- pat = word(dearc.i, 1)
- pat = upper(pat)
- patlen = length(pat)
- cuthere = (length(filename) - patlen)
-
- upfilename = upper(filename)
- if pos(pat, upfilename) = cuthere + 1 then do
- cmd = subword(dearc.i, 2)
- leave
- end
- end
-
- if cmd = '' then say '* 'nodearcstr' 'oldfile
- else do
- if pos(' ', filename) > 0 then do
- filename = translate(filename, '-', ' ')
- tmpfile = makepath(oldpath, filename)
- 'rename "'oldfile'" "'tmpfile'"'
- oldfile = tmpfile
- end
-
- newfilename = substr(filename, 1, cuthere)
- newfilename = translate(newfilename, '_', '.')
-
- lowerarctype = lowercase(arctype)
- newfilearc = makepath(oldpath, newfilename'.'lowerarctype)
- say '* 'oldfile' -> 'newfilearc
-
- skipit? = 0
- if exists(newfilearc) then do
- say '* 'newfilearc' : 'getfault(203)
- pull ans
- if ans = 'Y' then do
- 'delete "'newfilearc'" >'deltmp
- call delete(deltmp)
- end
- else skipit? = 1
- end
-
- if ~skipit? then do
- if right(cmd, 1) = '>' then cmd = cmd||makepath(tmpdir, newfilename)
-
- file = makepath(arcpath, filename)
- newfile = makepath(arcpath, newfilename)
- 'assign "'arcpath'" "'oldpath'"'
-
- olddir = pragma('d', tmpdir)
- say
- cmd '"'file'"'
- arc '"'newfile'"' '#?'
- say
- call pragma('d', olddir)
- 'delete "'tmppat'" ALL FORCE QUIET'
-
- if comment ~= '' then do
- comment = translate(comment, "'", '"')
- 'filenote "'newfilearc'" "'comment'"'
- end
- end
- end
- end
-
- 'assign arc2arc:'
- 'delete "'tmpdir'" ALL FORCE >'deltmp
- call delete(deltmp)
- exit
-
-
- GETFILEPART: procedure
- parse arg path
- return strip(substr(path, max(pos(':', path), lastpos('/', path)) + 1))
-
-
- GETPATHPART: procedure
- parse arg path
- return strip(substr(path, 1, max(pos(':', path), lastpos('/', path) - 1)))
-
-
- MAKEPATH: procedure
- parse arg path, file
- if path ~= '' & pos(right(path, 1), ':/') = 0 then return path'/'file
- return path||file
-
-
- GETFAULT: procedure
- num = arg(1)
- faulttmp = 't:getfault.tmp'
- address command 'fault 'num' >'faulttmp
- call open('tmp', faulttmp, 'r')
- parse value readln('tmp') with ':'errmsg
- call close('tmp')
- call delete(faulttmp)
- return strip(errmsg)
-
-
- LOWERCASE: procedure
- return translate(arg(1), xrange('a', 'z'), xrange('A', 'Z'))
-
-
- FAILURE:
- 'assign "'arcpath'"'
- call delete(listtmp)
-
- if olddir ~= '' then do
- call pragma('d', olddir)
- 'delete "'tmppat'" ALL FORCE QUIET'
- call delete(tmpdir)
- end
-
- if exists(deltmp) then do
- 'type "'deltmp'"'
- call delete(deltmp)
- end
- exit
-