program NoBackUpFiles__Please;
label
  PunkOut;
type
  Rec128Byte = array[0..127] of byte;
  char_set   = set of char;
  filename   = string[14];
  ActType    = (apply, remove);
const
  LocA = $2E8C;   { for TURBO 1.0, $29D3 should work }
  LocB = $2E92;   { for TURBO 1.0, $29D9 should work }
var
  TurboFile : file;
  OneRecord : Rec128Byte;
  action    : ActType;
{@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
function exists(ThisFile : filename):boolean;
var
  tempFile : text;  {We can get away with assigning a text file to ANY
                     filename because we aren't going to do any input/output}
begin
  assign(tempFile,ThisFile);
  {$I-}
  reset(tempFile);
  {$I+}
  if IOResult = 0 then exists := true
    else exists := false;
  close(tempFile);
end;
{@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
procedure ShowFail;
begin
  close(TurboFile);
  writeLn('This is NOT TURBO 2.0');
  halt;
end;
{@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
function TakeKey(range : char_set):char;
var
  CH : char;
begin
  repeat
    repeat until keypressed;
    read(Kbd,CH);
    CH := UpCase(CH);
  until CH in range;
  write(CH);
end;
{@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
procedure Perform;
begin
  case action of
    apply  : OneRecord[LocB mod 128] := ord('S');
    remove : OneRecord[LocB mod 128] := ord('K');
  end;
  seek(TurboFile,FilePos(TurboFile)-1);
  BlockWrite(TurboFile,OneRecord,1);
  reset(TurboFile);
  seek(TurboFile,LocA div 128);
  BlockRead(TurboFile,OneRecord,1);
  case action of
    apply  : OneRecord[LocA mod 128] := ord('P');
    remove : OneRecord[LocA mod 128] := ord('B');
  end;
  seek(TurboFile,FilePos(TurboFile)-1);
  BlockWrite(TurboFile,OneRecord,1);
  close(TurboFile);
end;
{@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
begin
  WriteLn('                           PATCHER FOR TURBO 2.0');
  writeLn;
  WriteLn(
'This program will apply OR remove the patch that keeps TURBO from creating');
  WriteLn(
'BAK files all over your disk.  If your version of TURBO isn''t 2.0, it will');
  WriteLn(
'NOT apply the patch.');
  WriteLn;
  WriteLn(
'THANKS to Steven Wisdom and PC WORLD magazine for the idea.');
  WriteLn('         -- Neil J. Rubenking');
  writeLn;
  if exists('A:TURBO.COM') then
    begin
      assign(TurboFile,'A:TURBO.COM');
      reset(TurboFile);
      seek(TurboFile,LocA div 128);
      BlockRead(TurboFile,OneRecord,1);
      case chr(OneRecord[LocA mod 128]) of
        'B': action := apply;
        'P': action := remove;
        else
          ShowFail;
      end;
      reset(turboFile);
      seek(TurboFile,LocB div 128);
      BlockRead(TurboFile,OneRecord,1);
      case chr(OneRecord[LocB mod 128]) of
        'K': begin
               if action = remove then
                 begin
                   WriteLn('May be a problem -- should I try anyway?');
                   if TakeKey(['Y','N']) = 'N' then goto punkOut;
                 end;
               Perform;
             end;
        'S': begin
               if action = apply then
                 begin
                   WriteLn('May be a problem -- should I try anyway?');
                   if TakeKey(['Y','N']) = 'N' then goto punkOut;
                 end;
               Perform;
             end;
        else
          ShowFail;
      end;
      WriteLn;
      case action of
        apply  : WriteLn('Successfully applied patch -- no more .BAK files.');
        remove : WriteLn('Successfully removed patch -- .BAK files again.');
      end;
    end
  else
    begin
      WriteLn('You MUST have TURBO.COM on the same disk as this program.');
    end;

  PunkOut:
end.