hedgewars/ArgParsers.inc
changeset 8354 c25bee85d6f8
parent 8329 f14d16c5277a
child 8359 9a7024b2a4d3
equal deleted inserted replaced
8352:ab7f22530ae0 8354:c25bee85d6f8
    41     WriteLn(stdout, 'where [options] can be any of the following:');
    41     WriteLn(stdout, 'where [options] can be any of the following:');
    42     WriteLn(stdout, ' --prefix [path to folder]');
    42     WriteLn(stdout, ' --prefix [path to folder]');
    43     WriteLn(stdout, ' --user-prefix [path to folder]');
    43     WriteLn(stdout, ' --user-prefix [path to folder]');
    44     WriteLn(stdout, ' --locale [name of language file]');
    44     WriteLn(stdout, ' --locale [name of language file]');
    45     WriteLn(stdout, ' --nick [string]');
    45     WriteLn(stdout, ' --nick [string]');
    46     WriteLn(stdout, ' --width [screen width in pixels]');
    46     WriteLn(stdout, ' --fullscreen-width [fullscreen width in pixels]');
    47     WriteLn(stdout, ' --height [screen height in pixels]');
    47     WriteLn(stdout, ' --fullscreen-height [fullscreen height in pixels]');
       
    48     WriteLn(stdout, ' --width [window width in pixels]');
       
    49     WriteLn(stdout, ' --height [window height in pixels]');
    48     WriteLn(stdout, ' --volume [sound level]');
    50     WriteLn(stdout, ' --volume [sound level]');
    49     WriteLn(stdout, ' --frame-interval [milliseconds]');
    51     WriteLn(stdout, ' --frame-interval [milliseconds]');
    50     Writeln(stdout, ' --stereo [value]');
    52     Writeln(stdout, ' --stereo [value]');
    51     WriteLn(stdout, ' --raw-quality [flags]');
    53     WriteLn(stdout, ' --raw-quality [flags]');
    52     WriteLn(stdout, ' --low-quality');
    54     WriteLn(stdout, ' --low-quality');
   157 
   159 
   158 
   160 
   159 procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt); Forward;
   161 procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt); Forward;
   160 
   162 
   161 function parseParameter(cmd:String; arg:String; var paramIndex:LongInt): Boolean;
   163 function parseParameter(cmd:String; arg:String; var paramIndex:LongInt): Boolean;
   162 const videoArray: Array [1..3] of String = ('--width','--height','--depth');
   164 const videoArray: Array [1..5] of String = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth');
   163       audioArray: Array [1..3] of String = ('--volume','--nomusic','--nosound');
   165       audioArray: Array [1..3] of String = ('--volume','--nomusic','--nosound');
   164       otherArray: Array [1..3] of String = ('--locale','--fullscreen','--showfps');
   166       otherArray: Array [1..3] of String = ('--locale','--fullscreen','--showfps');
   165       mediaArray: Array [1..8] of String = ('--width','--height','--depth','--volume','--nomusic','--nosound','--locale','--fullscreen');
   167       mediaArray: Array [1..10] of String = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen');
   166       allArray: Array [1..12] of String = ('--width','--height','--depth','--volume','--nomusic','--nosound','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality');
   168       allArray: Array [1..14] of String = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth','--volume','--nomusic','--nosound','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality');
   167       reallyAll: array[0..28] of shortstring = (
   169       reallyAll: array[0..30] of shortstring = (
   168                 '--prefix', '--user-prefix', '--locale', '--width', '--height', '--frame-interval', '--volume','--nomusic', '--nosound',
   170                 '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width', 
   169                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick',
   171                 '--height', '--frame-interval', '--volume','--nomusic', '--nosound',
       
   172                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick', 
   170   {deprecated}  '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
   173   {deprecated}  '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
   171   {internal}    '--internal', '--port', '--recorder', '--landpreview',
   174   {internal}    '--internal', '--port', '--recorder', '--landpreview',
   172   {misc}        '--stats-only', '--gci', '--help');
   175   {misc}        '--stats-only', '--gci', '--help');
   173 var cmdIndex: byte;
   176 var cmdIndex: byte;
   174 begin
   177 begin
   178     //NOTE: Any update to the list of parameters must be reflected in the case statement below, the reallyAll array above,
   181     //NOTE: Any update to the list of parameters must be reflected in the case statement below, the reallyAll array above,
   179     //      the the DisplayUsage() procedure, the HWForm::getDemoArguments() function, and the online wiki
   182     //      the the DisplayUsage() procedure, the HWForm::getDemoArguments() function, and the online wiki
   180 
   183 
   181     while (cmdIndex <= High(reallyAll)) and (cmd <> reallyAll[cmdIndex]) do inc(cmdIndex);
   184     while (cmdIndex <= High(reallyAll)) and (cmd <> reallyAll[cmdIndex]) do inc(cmdIndex);
   182     case cmdIndex of
   185     case cmdIndex of
   183         {--prefix}          0 : PathPrefix     := getStringParameter (arg, paramIndex, parseParameter);
   186         {--prefix}               0 : PathPrefix        := getStringParameter (arg, paramIndex, parseParameter);
   184         {--user-prefix}     1 : UserPathPrefix := getStringParameter (arg, paramIndex, parseParameter);
   187         {--user-prefix}          1 : UserPathPrefix    := getStringParameter (arg, paramIndex, parseParameter);
   185         {--locale}          2 : cLocaleFName   := getStringParameter (arg, paramIndex, parseParameter);
   188         {--locale}               2 : cLocaleFName      := getStringParameter (arg, paramIndex, parseParameter);
   186         {--width}           3 : cScreenWidth   := getLongIntParameter(arg, paramIndex, parseParameter);
   189         {--fullscreen-width}     3 : cFullscreenWidth  := getLongIntParameter(arg, paramIndex, parseParameter);
   187         {--height}          4 : cScreenHeight  := getLongIntParameter(arg, paramIndex, parseParameter);
   190         {--fullscreen-height}    4 : cFullscreenHeight := getLongIntParameter(arg, paramIndex, parseParameter);
   188         {--frame-interval}  5 : cTimerInterval := getLongIntParameter(arg, paramIndex, parseParameter);
   191         {--width}       5 : cWindowedWidth    := getLongIntParameter(arg, paramIndex, parseParameter);
   189         {--volume}          6 : SetVolume       ( getLongIntParameter(arg, paramIndex, parseParameter) );
   192         {--height}      6 : cWindowedHeight   := getLongIntParameter(arg, paramIndex, parseParameter);
   190         {--nomusic}         7 : SetMusic        ( false );
   193         {--frame-interval}       7 : cTimerInterval    := getLongIntParameter(arg, paramIndex, parseParameter);
   191         {--nosound}         8 : SetSound        ( false );
   194         {--volume}               8 : SetVolume          ( getLongIntParameter(arg, paramIndex, parseParameter) );
   192         {--fullscreen}      9 : cFullScreen    := true;
   195         {--nomusic}              9 : SetMusic           ( false );
   193         {--showfps}        10 : cShowFPS       := true;
   196         {--nosound}             10 : SetSound           ( false );
   194         {--altdmg}         11 : cAltDamage     := true;
   197         {--fullscreen}          11 : cFullScreen       := true;
   195         {--low-quality}    12 : cReducedQuality:= $FFFFFFFF xor rqLowRes;
   198         {--showfps}             12 : cShowFPS          := true;
   196         {--raw-quality}    13 : cReducedQuality:= getLongIntParameter(arg, paramIndex, parseParameter);
   199         {--altdmg}              13 : cAltDamage        := true;
   197         {--stereo}         14 : setStereoMode   ( getLongIntParameter(arg, paramIndex, parseParameter) );
   200         {--low-quality}         14 : cReducedQuality   := $FFFFFFFF xor rqLowRes;
   198         {--nick}           15 : UserNick       := parseNick( getStringParameter(arg, paramIndex, parseParameter) );
   201         {--raw-quality}         15 : cReducedQuality   := getLongIntParameter(arg, paramIndex, parseParameter);
       
   202         {--stereo}              16 : setStereoMode      ( getLongIntParameter(arg, paramIndex, parseParameter) );
       
   203         {--nick}                17 : UserNick          := parseNick( getStringParameter(arg, paramIndex, parseParameter) );
   199         {deprecated options}
   204         {deprecated options}
   200         {--depth}          16 : setDepth(paramIndex);
   205         {--depth}               18 : setDepth(paramIndex);
   201         {--set-video}      17 : parseClassicParameter(videoArray,3,paramIndex);
   206         {--set-video}           19 : parseClassicParameter(videoArray,5,paramIndex);
   202         {--set-audio}      18 : parseClassicParameter(audioArray,3,paramIndex);
   207         {--set-audio}           20 : parseClassicParameter(audioArray,3,paramIndex);
   203         {--set-other}      19 : parseClassicParameter(otherArray,3,paramIndex);
   208         {--set-other}           21 : parseClassicParameter(otherArray,3,paramIndex);
   204         {--set-multimedia} 20 : parseClassicParameter(mediaArray,8,paramIndex);
   209         {--set-multimedia}      22 : parseClassicParameter(mediaArray,10,paramIndex);
   205         {--set-everything} 21 : parseClassicParameter(allArray,12,paramIndex);
   210         {--set-everything}      23 : parseClassicParameter(allArray,14,paramIndex);
   206         {"internal" options}
   211         {"internal" options}
   207         {--internal}       22 : {note it, but do nothing};
   212         {--internal}            24 : {note it, but do nothing};
   208         {--port}            23 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
   213         {--port}                25 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
   209         {--recorder}       24 : startVideoRecording(paramIndex);
   214         {--recorder}            26 : startVideoRecording(paramIndex);
   210         {--landpreview}    25 : GameType := gmtLandPreview;
   215         {--landpreview}         27 : GameType := gmtLandPreview;
   211         {anything else}
   216         {anything else}
   212         {--stats-only}     26 : statsOnlyGame();
   217         {--stats-only}          28 : statsOnlyGame();
   213         {--gci}            27 : GciEasterEgg();
   218         {--gci}                 29 : GciEasterEgg();
   214         {--help}           28 : DisplayUsage();
   219         {--help}                30 : DisplayUsage();
   215     else
   220     else
   216         begin
   221         begin
   217         //Asusme the first "non parameter" is the replay file, anything else is invalid
   222         //Asusme the first "non parameter" is the replay file, anything else is invalid
   218         if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then
   223         if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then
   219             recordFileName := cmd
   224             recordFileName := cmd