program nt;
{ translates UNIX \n, \t codes into CRLF, TAB
  12 Apr 1988 }

const reclg:  integer=128;

var ch: char;
    name1,name2: string[14];
    datei1,datei2: file;
    fsize1,fsize2: integer;
    buff1,buff2: array [1..128] of byte;
    i,j,k: integer;
    ncount,tcount: integer;
    escflag: boolean;

procedure putc(ch:byte);
begin
k:=k+1;
buff2[k]:=ch;
if k=reclg then
    begin blockwrite(datei2,buff2,1); k:=0; end;
end;


begin { crlf }

repeat
writeln; write('Input file '); readln(name1);
for i:=1 to length(name1) do
    name1[i]:=UpCase(name1[i]);
assign(datei1,name1);
{$I-} reset(datei1) {$I+};
if Ioresult<>0 then writeln('File ',name1,' not found.')
else
    begin
    write('Output file '); readln(name2);
    for i:=1 to length(name2) do
        name2[i]:=UpCase(name2[i]);
    assign(datei2,name2);
    {$I-} rewrite(datei2) {$I+};
    if Ioresult<>0 then writeln('Cannot open file ',name2)
    else
        begin
        fsize1:=FileSize(datei1);
        writeln('Input file ',name1:12,' has ',fsize1:4,' records');
        escflag:=false;
        k:=0;
        ncount:=0; tcount:=0;
        repeat
                blockread(datei1,buff1,1);
                for j:=1 to reclg do
                    case buff1[j] of
              {'\'} $5C: if escflag then
                             begin escflag:=false; putc(buff1[j]); end
                         else escflag:=true;
              {'n'} $6E: if escflag then
                             begin escflag:=false; ncount:=ncount+1;
                                   putc($0D); putc($0A); end
                         else putc(buff1[j]);
              {'t'} $74: if escflag then
                             begin escflag:=false; tcount:=tcount+1;
                                   putc($09); end
                         else putc(buff1[j]);
                    else putc(buff1[j]);
                    end;
        until EOF(datei1);
        if k>0 then
            begin
            repeat
                k:=k+1;
                buff2[k]:=$1A;
            until k>=reclg;
            blockwrite(datei2,buff2,1);
            end;
        close(datei1);
        close(datei2);
        writeln; writeln(ncount,' CRs  ',tcount,' TABs');
        end;
    end;
writeln; writeln; write('Restart ? (Y/N) ');
repeat
    read(kbd,ch); writeln(ch);
until ch in ['Y','y','N','n'];
until ch in ['N','n'];

end.


