2
0

pas2js.pp 1.7 KB

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