hedgewars/ArgParsers.inc
changeset 8307 8d7c52b24e28
parent 8302 a7934cd12469
child 8308 cdf83bdf7b27
equal deleted inserted replaced
8305:039ceb443aca 8307:8d7c52b24e28
    73 
    73 
    74 procedure DisplayUsage;
    74 procedure DisplayUsage;
    75 begin
    75 begin
    76     WriteLn(stdout, 'Usage:');
    76     WriteLn(stdout, 'Usage:');
    77     WriteLn(stdout, '');
    77     WriteLn(stdout, '');
    78     WriteLn(stdout, '  hwengine <path to global data folder> <path to replay file> [options]');
    78     WriteLn(stdout, '  hwengine <path to replay file> [options]');
    79     WriteLn(stdout, '');
    79     WriteLn(stdout, '');
    80     WriteLn(stdout, 'where [options] are any of the following:');
    80     WriteLn(stdout, 'where [options] are any of the following:');
    81     WriteLn(stdout, ' --user-dir [path to user data folder]');
    81     WriteLn(stdout, ' --prefix [path to folder]');
       
    82     WriteLn(stdout, ' --user-prefix [path to folder]');
    82     WriteLn(stdout, ' --locale [name of language file]');
    83     WriteLn(stdout, ' --locale [name of language file]');
    83     WriteLn(stdout, ' --width [screen width in pixels]');
    84     WriteLn(stdout, ' --width [screen width in pixels]');
    84     WriteLn(stdout, ' --height [screen height in pixels]');
    85     WriteLn(stdout, ' --height [screen height in pixels]');
    85     WriteLn(stdout, ' --volume [sound level]');
    86     WriteLn(stdout, ' --volume [sound level]');
    86     WriteLn(stdout, ' --frame-interval [milliseconds]');
    87     WriteLn(stdout, ' --frame-interval [milliseconds]');
   125 const videoArray: Array [1..3] of String = ('--width','--height','--depth');
   126 const videoArray: Array [1..3] of String = ('--width','--height','--depth');
   126 const audioArray: Array [1..3] of String = ('--volume','--nomusic','--nosound');
   127 const audioArray: Array [1..3] of String = ('--volume','--nomusic','--nosound');
   127 const otherArray: Array [1..3] of String = ('--locale','--fullscreen','--showfps');
   128 const otherArray: Array [1..3] of String = ('--locale','--fullscreen','--showfps');
   128 const mediaArray: Array [1..8] of String = ('--width','--height','--depth','--volume','--nomusic','--nosound','--locale','--fullscreen');
   129 const mediaArray: Array [1..8] of String = ('--width','--height','--depth','--volume','--nomusic','--nosound','--locale','--fullscreen');
   129 const allArray: Array [1..12] of String = ('--width','--height','--depth','--volume','--nomusic','--nosound','--locale','--fullscreen','--showfps','--altdmg','--time','--lowquality');
   130 const allArray: Array [1..12] of String = ('--width','--height','--depth','--volume','--nomusic','--nosound','--locale','--fullscreen','--showfps','--altdmg','--time','--lowquality');
   130 const reallyAll: array[0..21] of shortstring = (
   131 const reallyAll: array[0..22] of shortstring = (
   131                 '--user-dir', '--locale', '--width', '--height', '--frame-interval', '--volume','--nomusic', '--nosound',
   132                 '--prefix', '--user-prefix', '--locale', '--width', '--height', '--frame-interval', '--volume','--nomusic', '--nosound',
   132                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality',
   133                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality',
   133   {deprecated}  '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
   134   {deprecated}  '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
   134                 '--stats-only', '--gci', '--help');
   135                 '--stats-only', '--gci', '--help');
   135 var cmdIndex: byte;
   136 var cmdIndex: byte;
   136 begin
   137 begin
   140     //NOTE: Any update to the list of parameters must be reflected in the case statement below, the reallyAll array above,
   141     //NOTE: Any update to the list of parameters must be reflected in the case statement below, the reallyAll array above,
   141     //      the the DisplayUsage() procedure, the HWForm::getDemoArguments() function, and the online wiki
   142     //      the the DisplayUsage() procedure, the HWForm::getDemoArguments() function, and the online wiki
   142 
   143 
   143     while (cmdIndex <= High(reallyAll)) and (cmd <> reallyAll[cmdIndex]) do inc(cmdIndex);
   144     while (cmdIndex <= High(reallyAll)) and (cmd <> reallyAll[cmdIndex]) do inc(cmdIndex);
   144     case cmdIndex of
   145     case cmdIndex of
   145         {--user-dir}        0 : UserPathPrefix := getStringParameter (arg, paramIndex, parseParameter);
   146         {--prefix}          0 : PathPrefix     := getStringParameter (arg, paramIndex, parseParameter);
   146         {--locale}          1 : cLocaleFName   := getStringParameter (arg, paramIndex, parseParameter);
   147         {--user-prefix}     1 : UserPathPrefix := getStringParameter (arg, paramIndex, parseParameter);
   147         {--width}           2 : cScreenWidth   := getLongIntParameter(arg, paramIndex, parseParameter);
   148         {--locale}          2 : cLocaleFName   := getStringParameter (arg, paramIndex, parseParameter);
   148         {--height}          3 : cScreenHeight  := getLongIntParameter(arg, paramIndex, parseParameter);
   149         {--width}           3 : cScreenWidth   := getLongIntParameter(arg, paramIndex, parseParameter);
   149         {--frame-interval}  4 : cTimerInterval := getLongIntParameter(arg, paramIndex, parseParameter);
   150         {--height}          4 : cScreenHeight  := getLongIntParameter(arg, paramIndex, parseParameter);
   150         {--volume}          5 : SetVolume       ( getLongIntParameter(arg, paramIndex, parseParameter) );
   151         {--frame-interval}  5 : cTimerInterval := getLongIntParameter(arg, paramIndex, parseParameter);
   151         {--nomusic}         6 : SetMusic        ( false );
   152         {--volume}          6 : SetVolume       ( getLongIntParameter(arg, paramIndex, parseParameter) );
   152         {--nosound}         7 : SetSound        ( false );
   153         {--nomusic}         7 : SetMusic        ( false );
   153         {--fullscreen}      8 : cFullScreen    := true;
   154         {--nosound}         8 : SetSound        ( false );
   154         {--showfps}         9 : cShowFPS       := true;
   155         {--fullscreen}      9 : cFullScreen    := true;
   155         {--altdmg}         10 : cAltDamage     := true;
   156         {--showfps}        10 : cShowFPS       := true;
   156         {--low-quality}    11 : cReducedQuality:= $FFFFFFFF xor rqLowRes;
   157         {--altdmg}         11 : cAltDamage     := true;
   157         {--raw-quality}    12 : cReducedQuality:= getLongIntParameter(arg, paramIndex, parseParameter);
   158         {--low-quality}    12 : cReducedQuality:= $FFFFFFFF xor rqLowRes;
       
   159         {--raw-quality}    13 : cReducedQuality:= getLongIntParameter(arg, paramIndex, parseParameter);
   158         {deprecated options}
   160         {deprecated options}
   159         {--depth}          13 : cBits          := getLongIntParameter(arg, paramIndex, parseParameter);
   161         {--depth}          14 : cBits          := getLongIntParameter(arg, paramIndex, parseParameter);
   160         {--set-video}      14 : parseClassicParameter(videoArray,3,paramIndex);
   162         {--set-video}      15 : parseClassicParameter(videoArray,3,paramIndex);
   161         {--set-audio}      15 : parseClassicParameter(audioArray,3,paramIndex);
   163         {--set-audio}      16 : parseClassicParameter(audioArray,3,paramIndex);
   162         {--set-other}      16 : parseClassicParameter(otherArray,3,paramIndex);
   164         {--set-other}      17 : parseClassicParameter(otherArray,3,paramIndex);
   163         {--set-multimedia} 17 : parseClassicParameter(mediaArray,8,paramIndex);
   165         {--set-multimedia} 18 : parseClassicParameter(mediaArray,8,paramIndex);
   164         {--set-everything} 18 : parseClassicParameter(allArray,12,paramIndex);
   166         {--set-everything} 19 : parseClassicParameter(allArray,12,paramIndex);
   165         {anything else}
   167         {anything else}
   166         {--stats-only}     19 : begin
   168         {--stats-only}     20 : begin
   167                                 cOnlyStats:= true;
   169                                 cOnlyStats:= true;
   168                                 cReducedQuality:= $FFFFFFFF xor rqLowRes;
   170                                 cReducedQuality:= $FFFFFFFF xor rqLowRes;
   169                                 SetSound(false);
   171                                 SetSound(false);
   170                                 end;
   172                                 end;
   171         {--gci}            20 : begin            //     We had to make up all this saved space some how...     \\
   173         {--gci}            21 : begin            //     We had to make up all this saved space some how...     \\
   172                                 WriteLn(stdout, '                                                                ');
   174                                 WriteLn(stdout, '                                                                ');
   173                                 WriteLn(stdout, '      /\\\\\\\\\\\\        /\\\\\\\\\  /\\\\\\\\\\\             ');
   175                                 WriteLn(stdout, '      /\\\\\\\\\\\\        /\\\\\\\\\  /\\\\\\\\\\\             ');
   174                                 WriteLn(stdout, '     /\\\//////////      /\\\////////  \/////\\\///             ');
   176                                 WriteLn(stdout, '     /\\\//////////      /\\\////////  \/////\\\///             ');
   175                                 WriteLn(stdout, '     /\\\               /\\\/               \/\\\               ');
   177                                 WriteLn(stdout, '     /\\\               /\\\/               \/\\\               ');
   176                                 WriteLn(stdout, '     \/\\\    /\\\\\\\  /\\\                 \/\\\              ');
   178                                 WriteLn(stdout, '     \/\\\    /\\\\\\\  /\\\                 \/\\\              ');
   182                                 WriteLn(stdout, '                                                                ');
   184                                 WriteLn(stdout, '                                                                ');
   183                                 WriteLn(stdout, ' Command Line Parser Implementation by a Google Code-In Student ');
   185                                 WriteLn(stdout, ' Command Line Parser Implementation by a Google Code-In Student ');
   184                                 WriteLn(stdout, '             ASCII Art easter egg idea by @sheepluva            ');
   186                                 WriteLn(stdout, '             ASCII Art easter egg idea by @sheepluva            ');
   185                                 WriteLn(stdout, '                                                                ');
   187                                 WriteLn(stdout, '                                                                ');
   186                                 end;
   188                                 end;
   187         {--help}           21 : begin
   189         {--help}           22 : begin
   188                                 DisplayUsage();
   190                                 DisplayUsage();
   189                                 GameType:= gmtSyntax;
   191                                 GameType:= gmtSyntax;
   190                                 end;
   192                                 end;
   191     else
   193     else
   192         begin
   194         begin
   193         WriteLn(stderr, 'ERROR: '+cmd+' is not a valid argument');
   195         //Asusme the first "non parameter" is the replay file, anything else is invalid
   194         parseParameter:= true;
   196         if recordFileName = '' then
   195         end
   197             recordFileName := cmd
       
   198         else
       
   199             begin
       
   200             WriteLn(stderr, 'ERROR: '+cmd+' is not a valid argument');
       
   201             parseParameter:= true;
       
   202             end;
       
   203         end;
   196     end;
   204     end;
   197 end;
   205 end;
   198 
   206 
   199 procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt);
   207 procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt);
   200 var index, tmpInt: LongInt;
   208 var index, tmpInt: LongInt;