hedgewars/ArgParsers.inc
branchflibqtfrontend
changeset 8304 620560c89284
parent 8278 9cdfcb5b7ddd
parent 8302 a7934cd12469
child 8363 0b4ac686fc44
--- a/hedgewars/ArgParsers.inc	Sun Dec 16 12:05:32 2012 +0400
+++ b/hedgewars/ArgParsers.inc	Sun Dec 16 12:25:13 2012 +0400
@@ -75,32 +75,26 @@
 begin
     WriteLn(stdout, 'Usage:');
     WriteLn(stdout, '');
-    WriteLn(stdout, '  hwengine [path to user hedgewars folder] <path to global data folder> <path to replay file> [options]');
+    WriteLn(stdout, '  hwengine <path to global data folder> <path to replay file> [options]');
     WriteLn(stdout, '');
     WriteLn(stdout, 'where [options] are any of the following:');
-    WriteLn(stdout, ' --locale [path to language file]');
-    WriteLn(stdout, ' --width  [screen width in pixels]');
+    WriteLn(stdout, ' --user-dir [path to user data folder]');
+    WriteLn(stdout, ' --locale [name of language file]');
+    WriteLn(stdout, ' --width [screen width in pixels]');
     WriteLn(stdout, ' --height [screen height in pixels]');
-    WriteLn(stdout, ' --depth  [color depth]');
     WriteLn(stdout, ' --volume [sound level]');
-    WriteLn(stdout, ' --time   [number of seconds]');
+    WriteLn(stdout, ' --frame-interval [milliseconds]');
+    WriteLn(stdout, ' --raw-quality [flags]');
+    WriteLn(stdout, ' --low-quality');
     WriteLn(stdout, ' --nomusic');
     WriteLn(stdout, ' --nosound');
     WriteLn(stdout, ' --fullscreen');
     WriteLn(stdout, ' --showfps');
     WriteLn(stdout, ' --altdmg');
-    WriteLn(stdout, ' --lowquality');
     WriteLn(stdout, ' --stats-only');
     WriteLn(stdout, ' --help');
     WriteLn(stdout, '');
-    WriteLn(stdout, 'Deprecated options:');
-    WriteLn(stdout, ' --set-video [screen width] [screen height] [color dept]');
-    WriteLn(stdout, ' --set-audio [volume] [enable music] [enable sounds]');
-    WriteLn(stdout, ' --set-other [language file] [full screen] [show FPS]');
-    WriteLn(stdout, ' --set-multimedia [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen]');
-    WriteLn(stdout, ' --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]');
-    WriteLn(stdout, '');
-    WriteLn(stdout, 'For a more detailed help and examples go to:');
+    WriteLn(stdout, 'For more detailed help and examples go to:');
     WriteLn(stdout, 'http://code.google.com/p/hedgewars/wiki/CommandLineOptions');
 end;
 
@@ -115,12 +109,16 @@
     getLongIntParameter:= tmpInt;
 end;
 
-function getStringParameter(str:String; var paramIndex:LongInt): String;
+function getStringParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): String;
 begin
     paramIndex:= paramIndex + 1;
+    wrongParameter:= (str='') or (Copy(str,1,2) = '--');
+    if wrongParameter then
+         WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"');
     getStringParameter:= str;
 end;
 
+
 procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt); Forward;
 
 function parseParameter(cmd:String; arg:String; var paramIndex:LongInt): Boolean;
@@ -129,60 +127,67 @@
 const otherArray: Array [1..3] of String = ('--locale','--fullscreen','--showfps');
 const mediaArray: Array [1..8] of String = ('--width','--height','--depth','--volume','--nomusic','--nosound','--locale','--fullscreen');
 const allArray: Array [1..12] of String = ('--width','--height','--depth','--volume','--nomusic','--nosound','--locale','--fullscreen','--showfps','--altdmg','--time','--lowquality');
-const reallyAll: array[0..19] of shortstring = (
-            '--locale', '--width', '--height', '--depth', '--time'
-            , '--volume', '--nomusic', '--nosound', '--fullscreen', '--showfps'
-            , '--altdmg', '--lowquality', '--set-video', '--set-audio', '--set-other'
-            , '--set-multimedia', '--set-everything', '--stats-only', '--gci', '--help');
+const reallyAll: array[0..21] of shortstring = (
+                '--user-dir', '--locale', '--width', '--height', '--frame-interval', '--volume','--nomusic', '--nosound',
+                '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality',
+  {deprecated}  '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
+                '--stats-only', '--gci', '--help');
 var cmdIndex: byte;
 begin
     parseParameter:= false;
     cmdIndex:= 0;
+
+    //NOTE: Any update to the list of parameters must be reflected in the case statement below, the reallyAll array above,
+    //      the the DisplayUsage() procedure, the HWForm::getDemoArguments() function, and the online wiki
+
     while (cmdIndex <= High(reallyAll)) and (cmd <> reallyAll[cmdIndex]) do inc(cmdIndex);
     case cmdIndex of
-        {--locale}   0 : cLocaleFName   := getStringParameter (arg, paramIndex);
-        {--width}    1 : cScreenWidth   := getLongIntParameter(arg, paramIndex, parseParameter);
-        {--height}   2 : cScreenHeight  := getLongIntParameter(arg, paramIndex, parseParameter);
-        {--depth}    3 : cBits          := getLongIntParameter(arg, paramIndex, parseParameter);
-        {--time}     4 : cTimerInterval := getLongIntParameter(arg, paramIndex, parseParameter);
-        {--volume}   5 : SetVolume       ( getLongIntParameter(arg, paramIndex, parseParameter) );
-        {--nomusic}  6 : SetMusic        ( false );
-        {--nosound}  7 : SetSound        ( false );
-        {--fullscreen}   8 : cFullScreen    := true;
-        {--showfps}      9 : cShowFPS       := true;
-        {--altdmg}      10 : cAltDamage     := true;
-        {--lowquality}  11 : cReducedQuality:= ($FFFFFFFF * getLongIntParameter(arg, paramIndex, parseParameter)) xor rqLowRes; //HACK!
-        {--set-video}   12 : parseClassicParameter(videoArray,3,paramIndex);
-        {--set-audio}   13 : parseClassicParameter(audioArray,3,paramIndex);
-        {--set-other}   14 : parseClassicParameter(otherArray,3,paramIndex);
-        {--set-multimedia}  15 : parseClassicParameter(mediaArray,8,paramIndex);
-        {--set-everything}  16 : parseClassicParameter(allArray,12,paramIndex);
-        {--stats-only}  17 : begin
-                             cOnlyStats:= true;
-                             SetSound(false);
-                             SetMusic(false);
-                             cReducedQuality:= $FFFFFFFF xor rqLowRes;
-                             end;
-        {--gci}  18 : begin            //     We had to make up all this saved space some how...     \\
-                      WriteLn(stdout, '                                                                ');
-                      WriteLn(stdout, '      /\\\\\\\\\\\\        /\\\\\\\\\  /\\\\\\\\\\\             ');
-                      WriteLn(stdout, '     /\\\//////////      /\\\////////  \/////\\\///             ');
-                      WriteLn(stdout, '     /\\\               /\\\/               \/\\\               ');
-                      WriteLn(stdout, '     \/\\\    /\\\\\\\  /\\\                 \/\\\              ');
-                      WriteLn(stdout, '      \/\\\   \/////\\\ \/\\\                 \/\\\             ');
-                      WriteLn(stdout, '       \/\\\       \/\\\ \//\\\                \/\\\            ');
-                      WriteLn(stdout, '        \/\\\       \/\\\  \///\\\              \/\\\           ');
-                      WriteLn(stdout, '         \//\\\\\\\\\\\\/     \////\\\\\\\\\  /\\\\\\\\\\\      ');
-                      WriteLn(stdout, '          \////////////           \/////////  \///////////      ');
-                      WriteLn(stdout, '                                                                ');
-                      WriteLn(stdout, ' Command Line Parser Implementation by a Google Code-In Student ');
-                      WriteLn(stdout, '             ASCII Art easter egg idea by @sheepluva            ');
-                      WriteLn(stdout, '                                                                ');
-                      end;
-        {--help}  19 : begin
-                       DisplayUsage();
-                       GameType:= gmtSyntax;
-                       end;
+        {--user-dir}        0 : UserPathPrefix := getStringParameter (arg, paramIndex, parseParameter);
+        {--locale}          1 : cLocaleFName   := getStringParameter (arg, paramIndex, parseParameter);
+        {--width}           2 : cScreenWidth   := getLongIntParameter(arg, paramIndex, parseParameter);
+        {--height}          3 : cScreenHeight  := getLongIntParameter(arg, paramIndex, parseParameter);
+        {--frame-interval}  4 : cTimerInterval := getLongIntParameter(arg, paramIndex, parseParameter);
+        {--volume}          5 : SetVolume       ( getLongIntParameter(arg, paramIndex, parseParameter) );
+        {--nomusic}         6 : SetMusic        ( false );
+        {--nosound}         7 : SetSound        ( false );
+        {--fullscreen}      8 : cFullScreen    := true;
+        {--showfps}         9 : cShowFPS       := true;
+        {--altdmg}         10 : cAltDamage     := true;
+        {--low-quality}    11 : cReducedQuality:= $FFFFFFFF xor rqLowRes;
+        {--raw-quality}    12 : cReducedQuality:= getLongIntParameter(arg, paramIndex, parseParameter);
+        {deprecated options}
+        {--depth}          13 : cBits          := getLongIntParameter(arg, paramIndex, parseParameter);
+        {--set-video}      14 : parseClassicParameter(videoArray,3,paramIndex);
+        {--set-audio}      15 : parseClassicParameter(audioArray,3,paramIndex);
+        {--set-other}      16 : parseClassicParameter(otherArray,3,paramIndex);
+        {--set-multimedia} 17 : parseClassicParameter(mediaArray,8,paramIndex);
+        {--set-everything} 18 : parseClassicParameter(allArray,12,paramIndex);
+        {anything else}
+        {--stats-only}     19 : begin
+                                cOnlyStats:= true;
+                                cReducedQuality:= $FFFFFFFF xor rqLowRes;
+                                SetSound(false);
+                                end;
+        {--gci}            20 : begin            //     We had to make up all this saved space some how...     \\
+                                WriteLn(stdout, '                                                                ');
+                                WriteLn(stdout, '      /\\\\\\\\\\\\        /\\\\\\\\\  /\\\\\\\\\\\             ');
+                                WriteLn(stdout, '     /\\\//////////      /\\\////////  \/////\\\///             ');
+                                WriteLn(stdout, '     /\\\               /\\\/               \/\\\               ');
+                                WriteLn(stdout, '     \/\\\    /\\\\\\\  /\\\                 \/\\\              ');
+                                WriteLn(stdout, '      \/\\\   \/////\\\ \/\\\                 \/\\\             ');
+                                WriteLn(stdout, '       \/\\\       \/\\\ \//\\\                \/\\\            ');
+                                WriteLn(stdout, '        \/\\\       \/\\\  \///\\\              \/\\\           ');
+                                WriteLn(stdout, '         \/\\\\\\\\\\\\\/     \////\\\\\\\\\  /\\\\\\\\\\\      ');
+                                WriteLn(stdout, '          \/////////////          \/////////  \///////////      ');
+                                WriteLn(stdout, '                                                                ');
+                                WriteLn(stdout, ' Command Line Parser Implementation by a Google Code-In Student ');
+                                WriteLn(stdout, '             ASCII Art easter egg idea by @sheepluva            ');
+                                WriteLn(stdout, '                                                                ');
+                                end;
+        {--help}           21 : begin
+                                DisplayUsage();
+                                GameType:= gmtSyntax;
+                                end;
     else
         begin
         WriteLn(stderr, 'ERROR: '+cmd+' is not a valid argument');
@@ -206,7 +211,7 @@
             or (cmdArray[index] = '--fullscreen')
             or (cmdArray[index] = '--showfps')
             or (cmdArray[index] = '--altdmg')
-            or (cmdArray[index] = '--lowquality');
+            or (cmdArray[index] = '--low-quality');
         if (not isBool) or ((ParamStr(paramIndex)='1') and (cmdArray[index]<>'--nomusic') and (cmdArray[index]<>'--nosound')) then
             parseParameter(cmdArray[index], ParamStr(paramIndex), tmpInt);
         index:= index+1;