const
bufsize=161024;
var
s2:string;
f1,f2:file;
d:searchrec;
nr,nw,i,j:u_val;
bu:array[0..bufsize-1]of byte;
bo:array[0..bufsize2-1]of byte;
function posplus(i:integer;c:char;s:string):integer;
begin
while i<=length(s) do begin
result:=i+1;
if s[i]=c then exit;
inc(i);
end;
result:=-1;
end;
var
op,p:integer;
curr:string;
begin
if (paramcount<1) then error('Usage: crlf [files...]');
randomize;
repeat
s2:='~';for i:=1 to 7 do s2:=s2+mktchar;
s2:=s2+'.~99';
doserror:=FindFirst(s2,flag,D);
until doserror<>0;
for i:=1 to paramcount do begin
doserror:=FindFirst(paramstr(i),flag,D);
while (DosError = 0) do begin
if (paramstr(0)<>fexpand(d.name)) then begin
add(d.name);
end else begin
write(d.name);
write(str_eself);
end;
doserror:=FindNext(D);
end;
p:=posplus(0,'|',all);
op:=1;
while p<>-1 do begin
curr:=copy(all,op,p-op-1);
op:=p;
write(str_conv+curr);
assign(f1,curr);
assign(f2,s2);
reset(f1,1);
if ioresult<>0 then error(str_eopen+curr);
rewrite(f2,1);
if ioresult<>0 then error(str_eopen+s2);
nr:=1;
while not(eof(f1)) do begin
blockread(f1,bu,sizeof(bu), nr);
nw:=0;
if nr>0 then for j:=0 to nr-1 do begin
case bu[j] of
10:begin bo[nw]:=13;inc(nw);bo[nw]:=bu[j];inc(nw);end;
13:;
else begin bo[nw]:=bu[j];inc(nw);end;
end;
end;
blockwrite(f2,bo,nw);
end;
close(f1);
erase(f1);
close(f2);
rename(f2,curr);
if ioresult<>0 then error(str_ewrite);
write(str_done);
p:=posplus(p,'|',all);
end;
end;
write(str_alldone);
end.