Program NoCks(input,output);

(* Delete checksum information in a BASIC listing

   Format:

   <CC> ......

   Erases the first five characters from each line
*)

type
  FStr         = string[14];
var
  BAK          : boolean;
  FiN,FoN      : FStr;
  Fi,Fo        : text;

procedure NoFile;
Begin
  writeln('Cannot find file ',FiN,' - abort...');
  halt;
End;

procedure MarkBAK;
var
  p            : integer;
Begin
  BAK:=TRUE;
  p:=pos('.',FiN);
  if p=0 then p:=length(FiN)
         else p:=p-1;
  FoN:=copy(FiN,1,p)+'.BAK';
End;

procedure GetOneFile;
Begin
  FiN:=Paramstr(1);
  MarkBAK;
End;

procedure GetTwoFiles;
Begin
  FiN:=Paramstr(1);
  FoN:=Paramstr(2);
End;

procedure InputFiles;
Begin
  write('Filename: ');
  readln(FiN);
  markBAK;
End;

procedure CopyFile;
var
  CksLine      : string[255];
Begin
  while not eof(Fi) do
  begin
    readln(Fi,CksLine);
    delete(CksLine,1,5);
    writeln(Fo,CksLine);
  end;
End;

procedure RenameFile;
Begin
  writeln('** NOTHING RENAMED **');
End;

BEGIN (* MAIN *)
  BAK:=FALSE;
  case Paramcount of
    1 : GetOneFile;
    2 : GetTwoFiles;
    else InputFiles;
  end;
  assign(Fi,FiN);
  assign(Fo,FoN);
  {$I-}reset(Fi);{$I+}
  if IOresult<>0 then NoFile;
  rewrite(Fo);
  CopyFile;
  close(Fi);
  close(Fo);
  if BAK then RenameFile;
  writeln('Ready');
END.

