NB. transcode.ijs - code page transcoder
NB.
NB. EXAMPLES
NB.
NB.    ('abc';'ABC') tr 'abc-def-ghi'
NB. ABC-def-ghi
NB.
NB.    (DOS;WIN) trfiles 'D:\dir\*.txt';'D:\dir\out\'
NB. 7 510315
NB.
NB. AUTHOR
NB.   Oleg Kobchenko 01/20/2005

require 'files dir'

NB.   Ukrainian DOS cp01125 to Cyrillic Windows windows-1251            EeIiJjGgP<-EOP
DOS=: '¿ó'
WIN=: ' +-++-++|||-'

NB.* mapfrom v ascii map for transcoding
NB. ASC=. DOS mapto WIN
mapto=: 4 : '(a.i.y.)(a.i.x.)}i.256'  NB. x mapto y

NB.* tr v transcode
NB. new=. (DOS;WIN) tr old
tr=: 1 : '{&(mapto&>/m.)&.(a.&i.)'

upToEof=: {.~ i.&''
fileFromPath=: }.~ >:@{:@I.@e.&'\/'

NB.* trfiles v transcode files
NB. 'files bytes'=. (FROM;TO) trfiles FROMMASK;TODIR
NB. e.g. (DOS;WIN) trfiles 'd:\dir\*.txt';'d:\dir\out'
trfiles=: 4 : 0
  'FRMASK TODIR'=: y.
  files=. 1 dir FRMASK
  r=. ''
  for_p. files do.
    path=. >p
    fname=. fileFromPath path
    t1=. upToEof fread path
    t2=. x. tr t1
    r=. r,t2 fwrite TODIR,'\',fname
  end.
(#files),+/r
)