(*
This code was written by Dimitri Vulis and placed into public domain.
There is no copyright associated with this code. Use it as you wish.
*)
{$C-} {$K-} {$B-} {Options}
const
CYR_A=176; {0}
CYR_ya=239; {o}
uppertot=182;
BUFFERSIZE=16767;
type
bufferptr=0..BUFFERSIZE;
var
upper:array[0..222] of byte; { values }
uppers:array[0..64] of byte; { start }
upperm:array[0..63] of boolean; {multi-letter}
upperu:byte; { used pointer }
infile,outfile:file;
inbuf,outbuf:array[0..BUFFERSIZE] of byte;
inbufptr,outbufptr,inbuflen:integer;
c,i,xbyte:byte;
{We buffer I/O because otherwise it's agonizingly slow}
function getbyte:boolean; {true if read xbyte, false if end of file}
begin
getbyte:=true;
if inbufptr>=inbuflen then begin
blockread(infile, inbuf, BUFFERSIZE+1, inbuflen);
if inbuflen=0 then
getbyte:=false;
inbufptr:=0;
end;
xbyte:=inbuf[inbufptr];
inbufptr:=inbufptr+1;
end;
procedure putbyte;
begin
outbuf[outbufptr]:=xbyte;
if outbufptr=BUFFERSIZE then begin
blockwrite(outfile, outbuf, BUFFERSIZE+1);
outbufptr:=0;
end
else
outbufptr:=outbufptr+1;
end;
procedure closefiles;
begin
close(infile);
if outbufptr>0 then
blockwrite(outfile, outbuf, outbufptr);
close(outfile);
end;
{Standard PASCAL does not allow statically initialized arrays}
procedure add1(u1:char);
begin
upperm[c]:=false;
uppers[c]:=upperu;
upper[upperu]:=ord(u1);
upperu:=upperu+1;
c:=c+1;
end;
if upperu<>uppertot then
writeln('Warning: upperu=',upperu:1,' uppertot=',uppertot:1);
end {initialize};
procedure openfiles;
var
filename: packed array[0..60] of char;
begin
repeat
write('Input file: ');
readln(filename);
assign(infile,filename);
{$I-} reset(infile,1); {$I+}
until ioresult=0;
repeat
write('Output file: ');
readln(filename);
assign(outfile,filename);
{$I-} rewrite(outfile,1); {$I+}
until ioresult=0;
inbufptr:=1;
inbuflen:=0;
outbufptr:=0;
end {openfiles};
begin {main}
initialize;
{
for c:=0 to 63 do begin
if upperm[c] then
for i:=uppers[c] to uppers[c+1]-1 do write(chr(upper[i]))
else write(upper[uppers[c]]);
writeln;
end;
}
openfiles;
while getbyte do begin
if (xbyte>=CYR_A) and (xbyte<=CYR_ya) then begin
c:=xbyte-CYR_A;
if upperm[c] then begin
for i:=uppers[c] to uppers[c+1]-1 do
begin
xbyte:=upper[i];
putbyte;
end
end
else begin
xbyte:=upper[uppers[c]];
putbyte;
end
end
else
putbyte;
end;
closefiles;
end.