Program SPACDELonversion;
{
     Purpose    to DELete unwanted leading spaces from a text
                file.

     Started    April 6, 1985

     Last
     Update     April 6, 1985

}
const
    OutFileName  = 'temp.dat';
Var
    InFile,
    OutFile      :      Text;
    Line,
    Answer,
    MinusLine    :      string[200];
    NumNet       :      Real;
    I,M,N,P,
    datesl,
    NumLines,
    MaxDelete,
    scrnclr      :      Integer;
    StillSpace,
    FileFound    :      Boolean;
    MyFileIn,
    MyFileOut,
    Atest,t      :      String[20];

Procedure OpenInFile;    {Procedure to check for Input File}
Begin
  Repeat
    Gotoxy(8,6);Write('Enter the name of the file to list: ');
    ReadLn(MyFileIn);
    Gotoxy(8,7);ClrEol;
    Assign(Infile,MyFileIn);
    {$I-} Reset(InFile) {$I+} ;
    FileFound := (IOresult = 0);
    If not FileFound then
      begin
        Gotoxy(8,7);sound(440);Delay(500);Nosound;
        Write('CANNOT FIND FILE ',MyFileIn);
      end;
    Until FileFound;
 End;
Procedure CheckOutFile;    {Procedure to check for OutputFile}
Begin
  Repeat
    Gotoxy(8,8);Write('Enter the name for the output file: ');
    ReadLn(MyFileOut);
    Gotoxy(8,9);ClrEol;
    Assign(OutFile,MyFileOut);
    {$I-} Reset(OutFile) {$I+} ;
    FileFound := (IOresult = 0);
    If FileFound then
      begin
        Gotoxy(8,9);sound(440);Delay(500);Nosound;Close(OutFile);
        Write('That file already exists do you wish to continue (y): ');
        Read(Answer);
        If Upcase(Answer)='Y' then FileFound := False;
      end;
    Until not FileFound;
 End;

begin
    ClrScr;
    OpenInFile;
    CheckOutFile;
    Gotoxy(8,10);Write('Enter the maximum number of spaces to delete: ');
    ReadLn(MaxDelete);
    Reset(InFile);
    Assign(OutFile,MyFileOut);
    Rewrite(OutFile);
    Gotoxy(8,12);Write('The Input file is  ' + MyFileIn);
    Gotoxy(8,14);Write('The Output file is ' + MyFileOut);
    Gotoxy(8,16);Write('Working ON Line: ');
    WriteLn(' ');
    Scrnclr := 0;
    NumLines := 0;

  while not EOF(InFile) do begin

      ReadLn(InFile,Line);
      Numlines := Numlines + 1;
      N:=0;
      StillSpace := True;
      {WriteLn(Line);}
      While StillSpace Do
        Begin
          I:=N+1;
          If Line[I]=' '
            then N := N+1
          Else StillSpace := False
      end;
      DELETE(Line,1,N);
        {If scrnclr > 10 then
           begin
           ClrScr;
           scrnclr:=0;
        end
        else scrnclr := scrnclr + 1;}
      GotoXY(25,16);
      WriteLn(NumLines);
      WriteLn(OutFile,Line);
    end;

    WriteLn(' ');
    WriteLn('All Done');
    Close(InFile);
    Close(OutFile);
end.


Ln(OutFile,Line);
    en