program circuitlatex;

{$mode delphi}{$H+}

uses
  Interfaces,
  SysUtils,
  Forms,
  pstcircu;

type
  TCrashLogger = class
    procedure LogException(Sender: TObject; E: Exception);
  end;

procedure TCrashLogger.LogException(Sender: TObject; E: Exception);
var
  I: Integer;
  F: TextFile;
begin
  AssignFile(F, '/tmp/circuitlatex_crash.log');
  Rewrite(F);
  Writeln(F, 'Exception: ', E.ClassName, ': ', E.Message);
  Writeln(F, BackTraceStrFunc(ExceptAddr));
  for I := 0 to ExceptFrameCount - 1 do
    Writeln(F, BackTraceStrFunc(ExceptFrames[I]));
  CloseFile(F);
end;

var
  CrashLogger: TCrashLogger;

begin
  CrashLogger := TCrashLogger.Create;
  Application.OnException := CrashLogger.LogException;
  Application.Initialize;
  Application.CreateForm(TpstCircMainForm, pstCircMainForm);
  Application.Run;
end.
