pas2js.pp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. { Author: Mattias Gaertner 2017 [email protected]
  2. Abstract:
  3. Command line interface for the pas2js compiler.
  4. }
  5. program pas2js;
  6. {$mode objfpc}{$H+}
  7. uses
  8. {$IFDEF UNIX}
  9. cthreads, cwstring,
  10. {$ENDIF}
  11. Pas2jsFileUtils, Classes, SysUtils, CustApp,
  12. Pas2jsCompiler;
  13. Type
  14. { TPas2jsCLI }
  15. TPas2jsCLI = class(TCustomApplication)
  16. private
  17. FCompiler: TPas2jsCompiler;
  18. FWriteOutputToStdErr: Boolean;
  19. protected
  20. procedure DoRun; override;
  21. public
  22. constructor Create(TheOwner: TComponent); override;
  23. destructor Destroy; override;
  24. property Compiler: TPas2jsCompiler read FCompiler;
  25. property WriteOutputToStdErr: Boolean read FWriteOutputToStdErr write FWriteOutputToStdErr;
  26. end;
  27. procedure TPas2jsCLI.DoRun;
  28. var
  29. ParamList: TStringList;
  30. i: Integer;
  31. begin
  32. ParamList:=TStringList.Create;
  33. try
  34. for i:=1 to ParamCount do
  35. ParamList.Add(Params[i]);
  36. try
  37. Compiler.Run(ParamStr(0),GetCurrentDirUTF8,ParamList);
  38. except
  39. on E: ECompilerTerminate do ;
  40. end;
  41. finally
  42. ParamList.Free;
  43. Compiler.Log.CloseOutputFile;
  44. end;
  45. // stop program loop
  46. Terminate; // Keep ExitCode!
  47. end;
  48. constructor TPas2jsCLI.Create(TheOwner: TComponent);
  49. begin
  50. inherited Create(TheOwner);
  51. StopOnException:=True;
  52. FCompiler:=TPas2jsCompiler.Create;
  53. end;
  54. destructor TPas2jsCLI.Destroy;
  55. begin
  56. FreeAndNil(FCompiler);
  57. inherited Destroy;
  58. end;
  59. var
  60. Application: TPas2jsCLI;
  61. begin
  62. Application:=TPas2jsCLI.Create(nil);
  63. Application.Run;
  64. Application.Free;
  65. end.