program SelfTestLineNumbers;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils, IOUtils;

begin

  TFile.Copy('C:\Users\Andreas Rejbrand\Documents\Dev\AlgoSim\SelfTest.pas', 'C:\Users\Andreas Rejbrand\Documents\Dev\AlgoSim\SelfTest.bak', True);

  var Source := TFile.ReadAllLines('C:\Users\Andreas Rejbrand\Documents\Dev\AlgoSim\SelfTest.pas', TEncoding.UTF8);

  for var i := 0 to High(Source) do
  begin
    var L := Source[i];
    var p := Pos('{LINENUM}', L);
    if p > 0 then
    begin
      var p2 := Pos(',', L, p + 9);
      if p2 > 0 then
      begin
        Delete(L, p + 9, p2 - p - 9);
        Insert((i + 1).ToString, L, p + 9);
      end;
    end;
    Source[i] := L;
  end;

  TFile.WriteAllLines('C:\Users\Andreas Rejbrand\Documents\Dev\AlgoSim\SelfTest.pas', Source, TEncoding.UTF8);

end.
