Skip to content

Commit 45458a8

Browse files
committed
fix: Correct args parsing for Windows/Linux
1 parent 96ca4c0 commit 45458a8

3 files changed

Lines changed: 37 additions & 27 deletions

File tree

baseline/Common/baseline.console.pas

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface
3939

4040
procedure WriteHelp;
4141
{$IFNDEF FPC}
42-
function ParseCmdLineParams (out aInputFile: string): Boolean;
42+
function ParseCmdLineParams(out aInputFile: string): Boolean;
4343
{$ENDIF}
4444

4545

@@ -66,7 +66,7 @@ procedure WriteHelp;
6666
end;
6767

6868
{$IFNDEF FPC}
69-
function ArrayContains (const aArray: array of string; const aValue: string): Boolean;
69+
function ArrayContains(const aArray: array of string; const aValue: string): Boolean;
7070
var
7171
iValue: string;
7272
begin
@@ -81,41 +81,50 @@ function ArrayContains (const aArray: array of string; const aValue: string): Bo
8181
end;
8282
end;
8383

84-
function ParseCmdLineParams (out aInputFile: string): Boolean;
84+
function ParseCmdLineParams(out aInputFile: string): Boolean;
8585
var
8686
I: Integer;
8787
begin
8888
Result := False;
8989
aInputFile := '';
9090

9191
// 0 is the exe path, so we start at 1
92+
{$IFNDEF LINUX}
9293
for I := 1 to ParamCount do
94+
{$ELSE}
95+
for I := 1 to ParamCount + 1 do
96+
{$ENDIF}
9397
begin
94-
if ArrayContains (cOptionHelp, ParamStr(I)) then
98+
if ArrayContains(cOptionHelp, ParamStr(I)) then
9599
begin
96100
WriteHelp;
97-
exit;
98-
end
99-
else if ArrayContains (cOptionVersion, ParamStr(I)) then
100-
begin
101-
WriteLn(Format(rsGeneratorVersion, [ cVersion ]));
102-
exit;
101+
Exit;
103102
end
104-
else if ArrayContains (cOptionInput, ParamStr(I)) then
105-
begin
106-
// must be followed by the user's specified input file
107-
if (I+1) <= ParamCount then
108-
aInputFile := ExpandFileName (ParamStr (I+1));
109-
if not TFile.Exists (aInputFile) then
110-
WriteLn(Format(rsErrorMessage, [ Format(rsNoInputFile, [aInputFile]) ]))
111-
else
103+
else
104+
if ArrayContains(cOptionVersion, ParamStr(I)) then
112105
begin
113-
Result := True;
106+
WriteLn(Format(rsGeneratorVersion, [ cVersion ]));
114107
exit;
115-
end;
116-
end
117-
else
118-
WriteLn(Format(rsErrorMessage, [ rsMissingInputFlag ]));
108+
end
109+
else
110+
if ArrayContains(cOptionInput, ParamStr(I)) then
111+
begin
112+
// must be followed by the user's specified input file
113+
if (I+1) <= ParamCount then
114+
aInputFile := ExpandFileName (ParamStr (I+1));
115+
if (aInputFile = '') or (not TFile.Exists (aInputFile)) then
116+
begin
117+
WriteLn(Format(rsErrorMessage, [ Format(rsNoInputFile, [aInputFile]) ]));
118+
Exit;
119+
end
120+
else
121+
begin
122+
Result := True;
123+
Exit;
124+
end;
125+
end
126+
else
127+
WriteLn(Format(rsErrorMessage, [ rsMissingInputFlag ]));
119128
end;
120129
end;
121130
{$ENDIF}

baseline/Delphi/src/Baseline.dpr

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ uses
1111
;
1212

1313
var
14-
//vInputFilePath: string;
1514
vBaseline: TBaseline;
1615
begin
1716
try
18-
if ParseCmdLineParams (inputFilename) then
17+
if ParseCmdLineParams(inputFilename) then
1918
begin
20-
vBaseline := TBaseline.Create (inputFilename);
19+
vBaseline := TBaseline.Create(inputFilename);
2120
try
2221
vBaseline.Generate;
2322
finally
@@ -27,6 +26,6 @@ begin
2726

2827
except
2928
on E: Exception do
30-
Writeln(Format(rsErrorMessage, [ E.ClassName, ': ', E.Message ]));
29+
WriteLn(Format(rsErrorMessage, [ E.ClassName, ': ', E.Message ]));
3130
end;
3231
end.

baseline/Delphi/src/Baseline.dproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,15 @@
225225
<Debugger_Launcher>/usr/bin/gnome-terminal -- &quot;%debuggee%&quot;</Debugger_Launcher>
226226
<Manifest_File>(None)</Manifest_File>
227227
<AppDPIAwarenessMode>none</AppDPIAwarenessMode>
228+
<DCC_Define>LINUX;$(DCC_Define)</DCC_Define>
228229
</PropertyGroup>
229230
<PropertyGroup Condition="'$(Cfg_2_Win64)'!=''">
230231
<DCC_ExeOutput>..\..\bin</DCC_ExeOutput>
231232
<DCC_UnitSearchPath>..\..\Common;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
232233
<VerInfo_Locale>1033</VerInfo_Locale>
233234
<Manifest_File>(None)</Manifest_File>
234235
<AppDPIAwarenessMode>none</AppDPIAwarenessMode>
236+
<DCC_Define>WIN64;$(DCC_Define)</DCC_Define>
235237
</PropertyGroup>
236238
<ItemGroup>
237239
<DelphiCompile Include="$(MainSource)">

0 commit comments

Comments
 (0)