Program Decoder;

Const
     BufSize  =  32768;
     KOIArr=



Var
    SF, DF : File;
NumR, NumW : Word;
         C : Word;
      R, W : Byte;
      Buf  : Array  [ 1..BufSize ] of byte;

Begin
  WriteLn;
  WriteLn('Win-1251 to ASCII decoder');

  If (ParamStr(1)='') or (ParamStr(2)='') then
                      begin
                       WriteLn('Usage: win2asc FileName1 FileName2');
                       WriteLn('FileName1 - Source ( Win-1251 text file )');
                       WriteLn('FileName2 - Destination ( ASCII text file )');
                       Halt(1);
                      end;
  If ParamStr(1) = ParamStr(2) then
                 begin
                    WriteLn ('Error! Can''t decode file to itself!');
                    Halt(2);
                 end;
  Assign  ( SF, ParamStr(1) );
  Assign  ( DF, ParamStr(2) );
  Reset   ( SF, 1 );
  ReWrite ( DF, 1 );

    Repeat
     BlockRead ( SF, Buf, SizeOf(Buf), NumR );
        For C:= 1 to BufSize do
         begin
          R :=  Buf[C];
          W := R;
          If R in [ 192 .. 239 ] then W := R - 64;
          If R in [ 240 .. 255 ] then W := R - 16;
          If R = 150 then W := 45;
          If R = 151 then W := 45;
	  If R = 171 then W := 34;
	  If R = 187 then W := 34;
          If R = 168 then W := 240;
          If R = 184 then W := 241;
          If R = 133 then W := 46;
          Buf[C] := W;
        end;
     BlockWrite ( DF, Buf, NumR, NumW );
    Until ( NumR =  0 ) or ( NumR <> NumW );

  Close   ( SF );
  Close   ( DF );
End.