pas2js.pp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. Classes, SysUtils, CustApp,
  12. Pas2jsFileUtils, Pas2jsLogger, 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. on E: Exception do
  41. begin
  42. writeln(E.Message);
  43. if ExitCode=0 then
  44. ExitCode:=ExitCodeErrorInternal;
  45. end;
  46. end;
  47. finally
  48. ParamList.Free;
  49. Compiler.Log.CloseOutputFile;
  50. end;
  51. // stop program loop
  52. Terminate; // Keep ExitCode!
  53. end;
  54. constructor TPas2jsCLI.Create(TheOwner: TComponent);
  55. begin
  56. inherited Create(TheOwner);
  57. StopOnException:=True;
  58. FCompiler:=TPas2jsCompiler.Create;
  59. end;
  60. destructor TPas2jsCLI.Destroy;
  61. begin
  62. FreeAndNil(FCompiler);
  63. inherited Destroy;
  64. end;
  65. var
  66. Application: TPas2jsCLI;
  67. begin
  68. Application:=TPas2jsCLI.Create(nil);
  69. Application.Run;
  70. Application.Free;
  71. end.