/* Invert.rexx */

options results

parse ARG file

   /* !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\]^_`abcdefghijklmnopqrstuvwxyz{|}~ */
out=' i,#$%&,()*+`-`/0IZEhS9L86:;<=>¿@V8)D3¿ÐHIrx7WNOdbjS+n^MXhZ/]v-,eq)pa¿&y!rxlwuodbjs+n^mxhz}|{~'

old.=''
do i=32 to 91
    old.i=substr(out,(i-31),1)
end
old.92='\'
do i=93 to 127
    old.i=substr(out,(i-32),1)
end

if open(f,file,'r') then do
    if open(out,file||'.new','w') then do
        do while ~eof(f)
            txt=readln(f)
            Call inv
            Call Writeln(out,new)
        end
        Call close(out)
    end
    Call close(f)
end
else do
    say 'File not found'
    exit
end

address command
delete '"'file'"' quiet
rename '"'file||.new'"' '"'file'"'

exit

inv:
new=''

do i=1 to length(txt)
    t=substr(txt,i,1)
    tv=c2d(t)
    tmp=old.tv
    new=new||tmp
end

new=reverse(new)

return

