pas2js.pp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. { Author: Mattias Gaertner 2018 [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, pas2jspcucompiler, pas2jscompilerpp, pas2JScompilercfg;
  13. Type
  14. { TPas2jsCLI }
  15. TPas2jsCLI = class(TCustomApplication)
  16. private
  17. FCompiler: TPas2jsPCUCompiler;
  18. FWriteOutputToStdErr: Boolean;
  19. protected
  20. procedure DoRun; override;
  21. public
  22. constructor Create(TheOwner: TComponent); override;
  23. destructor Destroy; override;
  24. property Compiler: TPas2jsPCUCompiler 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),GetCurrentDirPJ,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:=TPas2jsPCUCompiler.Create;
  61. FCompiler.ConfigSupport:=TPas2JSFileConfigSupport.Create(FCompiler);
  62. FCompiler.PostProcessorSupport:=TPas2JSFSPostProcessorSupport.Create(FCompiler);
  63. end;
  64. destructor TPas2jsCLI.Destroy;
  65. begin
  66. FreeAndNil(FCompiler);
  67. inherited Destroy;
  68. end;
  69. var
  70. Application: TPas2jsCLI;
  71. begin
  72. Application:=TPas2jsCLI.Create(nil);
  73. Application.Run;
  74. Application.Free;
  75. end.