fpc/utils/pas2js/pas2js.pp
Mattias Gaertner fc805c4bd2 pas2js: marker for checking writeln statements
git-svn-id: trunk@38139 -
2018-02-06 13:50:18 +00:00

86 lines
1.7 KiB
ObjectPascal

{ Author: Mattias Gaertner 2017 mattias@freepascal.org
Abstract:
Command line interface for the pas2js compiler.
}
program pas2js;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}
cthreads, cwstring,
{$ENDIF}
Classes, SysUtils, CustApp,
Pas2jsFileUtils, Pas2jsLogger, Pas2jsCompiler;
Type
{ TPas2jsCLI }
TPas2jsCLI = class(TCustomApplication)
private
FCompiler: TPas2jsCompiler;
FWriteOutputToStdErr: Boolean;
protected
procedure DoRun; override;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
property Compiler: TPas2jsCompiler read FCompiler;
property WriteOutputToStdErr: Boolean read FWriteOutputToStdErr write FWriteOutputToStdErr;
end;
procedure TPas2jsCLI.DoRun;
var
ParamList: TStringList;
i: Integer;
begin
ParamList:=TStringList.Create;
try
for i:=1 to ParamCount do
ParamList.Add(Params[i]);
try
Compiler.Run(ParamStr(0),GetCurrentDirUTF8,ParamList);
except
on E: ECompilerTerminate do ;
on E: Exception do
begin
{AllowWriteln}
writeln(E.Message);
{AllowWriteln-}
if ExitCode=0 then
ExitCode:=ExitCodeErrorInternal;
end;
end;
finally
ParamList.Free;
Compiler.Log.CloseOutputFile;
end;
// stop program loop
Terminate; // Keep ExitCode!
end;
constructor TPas2jsCLI.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException:=True;
FCompiler:=TPas2jsCompiler.Create;
end;
destructor TPas2jsCLI.Destroy;
begin
FreeAndNil(FCompiler);
inherited Destroy;
end;
var
Application: TPas2jsCLI;
begin
Application:=TPas2jsCLI.Create(nil);
Application.Run;
Application.Free;
end.