Fix hwengine --help returning with exit code 51
authorWuzzy <Wuzzy2@mail.ru>
Sun, 15 Jul 2018 19:49:31 +0200
changeset 13488 d23731fe84d4
parent 13487 4ef83bcb850b
child 13489 dbf4f7a677be
Fix hwengine --help returning with exit code 51
hedgewars/ArgParsers.pas
hedgewars/hwengine.pas
hedgewars/uTypes.pas
--- a/hedgewars/ArgParsers.pas	Sun Jul 15 14:21:06 2018 +0200
+++ b/hedgewars/ArgParsers.pas	Sun Jul 15 19:49:31 2018 +0200
@@ -34,6 +34,7 @@
 implementation
 uses uVariables, uTypes, uUtils, uSound, uConsts;
 var isInternal: Boolean;
+    helpCommandUsed: Boolean;
 
 {$IFDEF HWLIBRARY}
 
@@ -101,7 +102,8 @@
     WriteLn(stdout, '');
     WriteLn(stdout, 'For more detailed help and examples go to:');
     WriteLn(stdout, 'http://hedgewars.org/kb/CommandLineOptions');
-    GameType:= gmtSyntax;
+    GameType:= gmtSyntaxHelp;
+    helpCommandUsed:= true;
 end;
 
 procedure setDepth(var paramIndex: LongInt);
@@ -357,12 +359,13 @@
         inc(paramIndex);
         end;
     if wrongParameter = true then
-        GameType:= gmtSyntax;
+        GameType:= gmtBadSyntax;
 end;
 
 procedure GetParams;
 begin
     isInternal:= (ParamStr(1) = '--internal');
+    helpCommandUsed:= false;
 
     UserPathPrefix := _S'.';
     PathPrefix     := cDefaultPathPrefix;
@@ -372,18 +375,19 @@
     if (isInternal) and (ParamCount<=1) then
         begin
         WriteLn(stderr, '--internal should not be manually used');
-        GameType := gmtSyntax;
+        GameType := gmtBadSyntax;
         end;
 
-    if (not cTestLua) and (not isInternal) and (recordFileName = '') then
-        begin
-        WriteLn(stderr, 'You must specify a replay file');
-        GameType := gmtSyntax;
-        end
-    else if (recordFileName <> '') then
-        WriteLn(stdout, 'Attempting to play demo file "' + recordFilename + '"');
+    if (not helpCommandUsed) then
+        if (not cTestLua) and (not isInternal) and (recordFileName = '') then
+            begin
+            WriteLn(stderr, 'You must specify a replay file');
+            GameType := gmtBadSyntax;
+            end
+        else if (recordFileName <> '') then
+            WriteLn(stdout, 'Attempting to play demo file "' + recordFilename + '"');
 
-    if (GameType = gmtSyntax) then
+    if (GameType = gmtBadSyntax) then
         WriteLn(stderr, 'Please use --help to see possible arguments and their usage');
 
     (*
--- a/hedgewars/hwengine.pas	Sun Jul 15 14:21:06 2018 +0200
+++ b/hedgewars/hwengine.pas	Sun Jul 15 19:49:31 2018 +0200
@@ -630,11 +630,11 @@
 
     if GameType = gmtLandPreview then
         GenLandPreview()
-    else if GameType <> gmtSyntax then
+    else if (GameType <> gmtBadSyntax) and (GameType <> gmtSyntaxHelp) then
         Game();
 
-    // return 1 when engine is not called correctly
-    if GameType = gmtSyntax then
+    // return error when engine is not called correctly
+    if GameType = gmtBadSyntax then
         {$IFDEF PAS2C}
         exit(HaltUsageError);
         {$ELSE}
--- a/hedgewars/uTypes.pas	Sun Jul 15 14:21:06 2018 +0200
+++ b/hedgewars/uTypes.pas	Sun Jul 15 19:49:31 2018 +0200
@@ -39,7 +39,7 @@
     TGameState = (gsLandGen, gsStart, gsGame, gsConfirm, gsExit, gsSuspend);
 
     // Game types that help determining what the engine is actually supposed to do
-    TGameType = (gmtLocal, gmtDemo, gmtNet, gmtSave, gmtLandPreview, gmtSyntax, gmtRecord);
+    TGameType = (gmtLocal, gmtDemo, gmtNet, gmtSave, gmtLandPreview, gmtBadSyntax, gmtRecord, gmtSyntaxHelp);
 
     // Different files are stored in different folders, this enumeration is used to tell which folder to use
     TPathType = (ptNone, ptData, ptGraphics, ptThemes, ptCurrTheme, ptConfig, ptTeams, ptMaps,