program crlf;

{ translates CRLF's into LF's
  12.04.88 }

const reclg:  integer=128;

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

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');
        crflag:=false;
        k:=0;
        count:=0;
        repeat
                blockread(datei1,buff1,1);
                for j:=1 to reclg do
                    begin
                    case buff1[j] of
                    $0A: if crflag then
                             begin crflag:=false; count:=count+1; end
                         else k:=k+1;
                    $0D: begin crflag:=true; k:=k+1; end;
                    else begin crflag:=false; k:=k+1; end;
                    end;
                    buff2[k]:=buff1[j];
                    if k=reclg then
                        begin
                        blockwrite(datei2,buff2,1);
                        k:=0;
                        end;
                    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(count,' replacements');
        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.


