hedgewars/ArgParsers.inc
branchflibqtfrontend
changeset 8363 0b4ac686fc44
parent 8304 620560c89284
parent 8359 9a7024b2a4d3
equal deleted inserted replaced
8306:50fe80adbfcb 8363:0b4ac686fc44
    14  * You should have received a copy of the GNU General Public License
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    17  *)
    17  *)
    18 
    18 
    19 
    19 procedure GciEasterEgg;
    20 procedure internalStartGameWithParameters();
    20 begin
    21 var tmp: LongInt;
    21     WriteLn(stdout, '                                                                ');
    22 begin
    22     WriteLn(stdout, '      /\\\\\\\\\\\\        /\\\\\\\\\  /\\\\\\\\\\\             ');
    23     UserPathPrefix:= ParamStr(1);
    23     WriteLn(stdout, '     /\\\//////////      /\\\////////  \/////\\\///             ');
    24     cScreenWidth:= StrToInt(ParamStr(2));
    24     WriteLn(stdout, '     /\\\               /\\\/               \/\\\               ');
    25     cScreenHeight:= StrToInt(ParamStr(3));
    25     WriteLn(stdout, '     \/\\\    /\\\\\\\  /\\\                 \/\\\              ');
    26     cBits:= StrToInt(ParamStr(4));
    26     WriteLn(stdout, '      \/\\\   \/////\\\ \/\\\                 \/\\\             ');
    27     ipcPort:= StrToInt(ParamStr(5));
    27     WriteLn(stdout, '       \/\\\       \/\\\ \//\\\                \/\\\            ');
    28     cFullScreen:= ParamStr(6) = '1';
    28     WriteLn(stdout, '        \/\\\       \/\\\  \///\\\              \/\\\           ');
    29     SetSound(ParamStr(7) = '1');
    29     WriteLn(stdout, '         \/\\\\\\\\\\\\\/     \////\\\\\\\\\  /\\\\\\\\\\\      ');
    30     SetMusic(ParamStr(8) = '1');
    30     WriteLn(stdout, '          \/////////////          \/////////  \///////////      ');
    31     SetVolume(StrToInt(ParamStr(9)));
    31     WriteLn(stdout, '                                                                ');
    32     cTimerInterval:= StrToInt(ParamStr(10));
    32     WriteLn(stdout, ' Command Line Parser Implementation by a Google Code-In Student ');
    33     PathPrefix:= ParamStr(11);
    33     WriteLn(stdout, '             ASCII Art easter egg idea by @sheepluva            ');
    34     cShowFPS:= ParamStr(12) = '1';
    34     WriteLn(stdout, '                                                                ');
    35     cAltDamage:= ParamStr(13) = '1';
    35 end;
    36     UserNick:= DecodeBase64(ParamStr(14));
       
    37     cReducedQuality:= StrToInt(ParamStr(15));
       
    38     tmp:= StrToInt(ParamStr(16));
       
    39     GrayScale:= false;
       
    40 {$IFDEF USE_S3D_RENDERING}
       
    41     if (tmp > 9) and (tmp < 16) then
       
    42         begin
       
    43         // set the gray anaglyph rendering
       
    44         GrayScale:= true;
       
    45         cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-9)))
       
    46         end
       
    47     else if tmp <= 9 then
       
    48         // set the fullcolor anaglyph
       
    49         cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp)))
       
    50     else
       
    51         // any other mode
       
    52         cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6)));
       
    53 {$ELSE}
       
    54 	cStereoMode:= smNone;
       
    55 {$ENDIF}
       
    56     cLocaleFName:= ParamStr(17);
       
    57 end;
       
    58 
       
    59 {$IFDEF USE_VIDEO_RECORDING}
       
    60 procedure internalStartVideoRecordingWithParameters();
       
    61 begin
       
    62     internalStartGameWithParameters();
       
    63     GameType:= gmtRecord;
       
    64     cVideoFramerateNum:= StrToInt(ParamStr(18));
       
    65     cVideoFramerateDen:= StrToInt(ParamStr(19));
       
    66     RecPrefix:= ParamStr(20);
       
    67     cAVFormat:= ParamStr(21);
       
    68     cVideoCodec:= ParamStr(22);
       
    69     cVideoQuality:= StrToInt(ParamStr(23));
       
    70     cAudioCodec:= ParamStr(24);
       
    71 end;
       
    72 {$ENDIF}
       
    73 
    36 
    74 procedure DisplayUsage;
    37 procedure DisplayUsage;
    75 begin
    38 begin
    76     WriteLn(stdout, 'Usage:');
    39     WriteLn(stdout, 'Usage: hwengine <path to replay file> [options]');
    77     WriteLn(stdout, '');
    40     WriteLn(stdout, '');
    78     WriteLn(stdout, '  hwengine <path to global data folder> <path to replay file> [options]');
    41     WriteLn(stdout, 'where [options] can be any of the following:');
    79     WriteLn(stdout, '');
    42     WriteLn(stdout, ' --prefix [path to folder]');
    80     WriteLn(stdout, 'where [options] are any of the following:');
    43     WriteLn(stdout, ' --user-prefix [path to folder]');
    81     WriteLn(stdout, ' --user-dir [path to user data folder]');
       
    82     WriteLn(stdout, ' --locale [name of language file]');
    44     WriteLn(stdout, ' --locale [name of language file]');
    83     WriteLn(stdout, ' --width [screen width in pixels]');
    45     WriteLn(stdout, ' --nick [string]');
    84     WriteLn(stdout, ' --height [screen height in pixels]');
    46     WriteLn(stdout, ' --fullscreen-width [fullscreen width 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]');
    85     WriteLn(stdout, ' --volume [sound level]');
    50     WriteLn(stdout, ' --volume [sound level]');
    86     WriteLn(stdout, ' --frame-interval [milliseconds]');
    51     WriteLn(stdout, ' --frame-interval [milliseconds]');
       
    52     Writeln(stdout, ' --stereo [value]');
    87     WriteLn(stdout, ' --raw-quality [flags]');
    53     WriteLn(stdout, ' --raw-quality [flags]');
    88     WriteLn(stdout, ' --low-quality');
    54     WriteLn(stdout, ' --low-quality');
    89     WriteLn(stdout, ' --nomusic');
    55     WriteLn(stdout, ' --nomusic');
    90     WriteLn(stdout, ' --nosound');
    56     WriteLn(stdout, ' --nosound');
    91     WriteLn(stdout, ' --fullscreen');
    57     WriteLn(stdout, ' --fullscreen');
    94     WriteLn(stdout, ' --stats-only');
    60     WriteLn(stdout, ' --stats-only');
    95     WriteLn(stdout, ' --help');
    61     WriteLn(stdout, ' --help');
    96     WriteLn(stdout, '');
    62     WriteLn(stdout, '');
    97     WriteLn(stdout, 'For more detailed help and examples go to:');
    63     WriteLn(stdout, 'For more detailed help and examples go to:');
    98     WriteLn(stdout, 'http://code.google.com/p/hedgewars/wiki/CommandLineOptions');
    64     WriteLn(stdout, 'http://code.google.com/p/hedgewars/wiki/CommandLineOptions');
       
    65     GameType:= gmtSyntax;
       
    66 end;
       
    67 
       
    68 procedure setDepth(var paramIndex: LongInt);
       
    69 begin
       
    70     WriteLn(stdout, 'WARNING: --depth is a deprecated command, which could be removed in a future version!');
       
    71     WriteLn(stdout, '         This option no longer does anything, please consider removing it');
       
    72     WriteLn(stdout, '');
       
    73    inc(ParamIndex);
       
    74 end;
       
    75 
       
    76 procedure statsOnlyGame;
       
    77 begin
       
    78     cOnlyStats:= true;
       
    79     cReducedQuality:= $FFFFFFFF xor rqLowRes;
       
    80     SetSound(false);
       
    81     SetMusic(false);
       
    82     SetVolume(0);
       
    83 end;
       
    84 
       
    85 procedure setIpcPort(port: LongInt; var wrongParameter:Boolean);
       
    86 begin
       
    87     if isInternal then
       
    88         ipcPort := port
       
    89     else
       
    90         begin
       
    91         WriteLn(stderr, 'ERROR: use of --port is not allowed');
       
    92         wrongParameter := true;
       
    93         end
       
    94 end;
       
    95 
       
    96 function parseNick(nick: String): String;
       
    97 begin
       
    98     if isInternal then
       
    99         parseNick:= DecodeBase64(nick)
       
   100     else
       
   101         parseNick:= nick;
       
   102 end;
       
   103 
       
   104 procedure setStereoMode(tmp: LongInt);
       
   105 begin
       
   106     GrayScale:= false;
       
   107 {$IFDEF USE_S3D_RENDERING}
       
   108     if (tmp > 6) and (tmp < 13) then
       
   109         begin
       
   110         // set the gray anaglyph rendering
       
   111         GrayScale:= true;
       
   112         cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6)))
       
   113         end
       
   114     else if tmp <= 6 then
       
   115         // set the fullcolor anaglyph
       
   116         cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp)))
       
   117     else
       
   118         // any other mode
       
   119         cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6)));
       
   120 {$ELSE}
       
   121     cStereoMode:= smNone;
       
   122 {$ENDIF}
       
   123 end;
       
   124 
       
   125 procedure startVideoRecording(var paramIndex: LongInt);
       
   126 begin
       
   127 {$IFDEF USE_VIDEO_RECORDING}
       
   128     GameType:= gmtRecord;
       
   129     inc(paramIndex);
       
   130     cVideoFramerateNum:= StrToInt(ParamStr(paramIndex)); inc(paramIndex);
       
   131     cVideoFramerateDen:= StrToInt(ParamStr(paramIndex)); inc(paramIndex);
       
   132     RecPrefix:= ParamStr(paramIndex);                    inc(paramIndex);
       
   133     cAVFormat:= ParamStr(paramIndex);                    inc(paramIndex);
       
   134     cVideoCodec:= ParamStr(paramIndex);                  inc(paramIndex);
       
   135     cVideoQuality:= StrToInt(ParamStr(paramIndex));      inc(paramIndex);
       
   136     cAudioCodec:= ParamStr(paramIndex);                  inc(paramIndex);
       
   137 {$ENDIF}
    99 end;
   138 end;
   100 
   139 
   101 function getLongIntParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): LongInt;
   140 function getLongIntParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): LongInt;
   102 var tmpInt, c: LongInt;
   141 var tmpInt, c: LongInt;
   103 begin
   142 begin
   104     paramIndex:= paramIndex + 1;
   143     inc(paramIndex);
   105     val(str, tmpInt, c);
   144     val(str, tmpInt, c);
   106     wrongParameter:= c <> 0;
   145     wrongParameter:= c <> 0;
   107     if wrongParameter then
   146     if wrongParameter then
   108         WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a number, you passed "'+str+'"');
   147         WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a number, you passed "'+str+'"');
   109     getLongIntParameter:= tmpInt;
   148     getLongIntParameter:= tmpInt;
   110 end;
   149 end;
   111 
   150 
   112 function getStringParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): String;
   151 function getStringParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): String;
   113 begin
   152 begin
   114     paramIndex:= paramIndex + 1;
   153     inc(paramIndex);
   115     wrongParameter:= (str='') or (Copy(str,1,2) = '--');
   154     wrongParameter:= (str='') or (Copy(str,1,2) = '--');
   116     if wrongParameter then
   155     if wrongParameter then
   117          WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"');
   156          WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"');
   118     getStringParameter:= str;
   157     getStringParameter:= str;
   119 end;
   158 end;
   120 
   159 
   121 
   160 
   122 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;
   123 
   162 
   124 function parseParameter(cmd:String; arg:String; var paramIndex:LongInt): Boolean;
   163 function parseParameter(cmd:String; arg:String; var paramIndex:LongInt): Boolean;
   125 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');
   126 const audioArray: Array [1..3] of String = ('--volume','--nomusic','--nosound');
   165       audioArray: Array [1..3] of String = ('--volume','--nomusic','--nosound');
   127 const otherArray: Array [1..3] of String = ('--locale','--fullscreen','--showfps');
   166       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');
   167       mediaArray: Array [1..10] of String = ('--fullscreen-width', '--fullscreen-height', '--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');
   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');
   130 const reallyAll: array[0..21] of shortstring = (
   169       reallyAll: array[0..30] of shortstring = (
   131                 '--user-dir', '--locale', '--width', '--height', '--frame-interval', '--volume','--nomusic', '--nosound',
   170                 '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width', 
   132                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality',
   171                 '--height', '--frame-interval', '--volume','--nomusic', '--nosound',
       
   172                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick', 
   133   {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',
   134                 '--stats-only', '--gci', '--help');
   174   {internal}    '--internal', '--port', '--recorder', '--landpreview',
       
   175   {misc}        '--stats-only', '--gci', '--help');
   135 var cmdIndex: byte;
   176 var cmdIndex: byte;
   136 begin
   177 begin
   137     parseParameter:= false;
   178     parseParameter:= false;
   138     cmdIndex:= 0;
   179     cmdIndex:= 0;
   139 
   180 
   140     //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,
   141     //      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
   142 
   183 
   143     while (cmdIndex <= High(reallyAll)) and (cmd <> reallyAll[cmdIndex]) do inc(cmdIndex);
   184     while (cmdIndex <= High(reallyAll)) and (cmd <> reallyAll[cmdIndex]) do inc(cmdIndex);
   144     case cmdIndex of
   185     case cmdIndex of
   145         {--user-dir}        0 : UserPathPrefix := getStringParameter (arg, paramIndex, parseParameter);
   186         {--prefix}               0 : PathPrefix        := getStringParameter (arg, paramIndex, parseParameter);
   146         {--locale}          1 : cLocaleFName   := getStringParameter (arg, paramIndex, parseParameter);
   187         {--user-prefix}          1 : UserPathPrefix    := getStringParameter (arg, paramIndex, parseParameter);
   147         {--width}           2 : cScreenWidth   := getLongIntParameter(arg, paramIndex, parseParameter);
   188         {--locale}               2 : cLocaleFName      := getStringParameter (arg, paramIndex, parseParameter);
   148         {--height}          3 : cScreenHeight  := getLongIntParameter(arg, paramIndex, parseParameter);
   189         {--fullscreen-width}     3 : cFullscreenWidth  := getLongIntParameter(arg, paramIndex, parseParameter);
   149         {--frame-interval}  4 : cTimerInterval := getLongIntParameter(arg, paramIndex, parseParameter);
   190         {--fullscreen-height}    4 : cFullscreenHeight := getLongIntParameter(arg, paramIndex, parseParameter);
   150         {--volume}          5 : SetVolume       ( getLongIntParameter(arg, paramIndex, parseParameter) );
   191         {--width}       5 : cWindowedWidth    := getLongIntParameter(arg, paramIndex, parseParameter);
   151         {--nomusic}         6 : SetMusic        ( false );
   192         {--height}      6 : cWindowedHeight   := getLongIntParameter(arg, paramIndex, parseParameter);
   152         {--nosound}         7 : SetSound        ( false );
   193         {--frame-interval}       7 : cTimerInterval    := getLongIntParameter(arg, paramIndex, parseParameter);
   153         {--fullscreen}      8 : cFullScreen    := true;
   194         {--volume}               8 : SetVolume          ( getLongIntParameter(arg, paramIndex, parseParameter) );
   154         {--showfps}         9 : cShowFPS       := true;
   195         {--nomusic}              9 : SetMusic           ( false );
   155         {--altdmg}         10 : cAltDamage     := true;
   196         {--nosound}             10 : SetSound           ( false );
   156         {--low-quality}    11 : cReducedQuality:= $FFFFFFFF xor rqLowRes;
   197         {--fullscreen}          11 : cFullScreen       := true;
   157         {--raw-quality}    12 : cReducedQuality:= getLongIntParameter(arg, paramIndex, parseParameter);
   198         {--showfps}             12 : cShowFPS          := true;
       
   199         {--altdmg}              13 : cAltDamage        := true;
       
   200         {--low-quality}         14 : cReducedQuality   := $FFFFFFFF xor rqLowRes;
       
   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) );
   158         {deprecated options}
   204         {deprecated options}
   159         {--depth}          13 : cBits          := getLongIntParameter(arg, paramIndex, parseParameter);
   205         {--depth}               18 : setDepth(paramIndex);
   160         {--set-video}      14 : parseClassicParameter(videoArray,3,paramIndex);
   206         {--set-video}           19 : parseClassicParameter(videoArray,5,paramIndex);
   161         {--set-audio}      15 : parseClassicParameter(audioArray,3,paramIndex);
   207         {--set-audio}           20 : parseClassicParameter(audioArray,3,paramIndex);
   162         {--set-other}      16 : parseClassicParameter(otherArray,3,paramIndex);
   208         {--set-other}           21 : parseClassicParameter(otherArray,3,paramIndex);
   163         {--set-multimedia} 17 : parseClassicParameter(mediaArray,8,paramIndex);
   209         {--set-multimedia}      22 : parseClassicParameter(mediaArray,10,paramIndex);
   164         {--set-everything} 18 : parseClassicParameter(allArray,12,paramIndex);
   210         {--set-everything}      23 : parseClassicParameter(allArray,14,paramIndex);
       
   211         {"internal" options}
       
   212         {--internal}            24 : {note it, but do nothing};
       
   213         {--port}                25 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
       
   214         {--recorder}            26 : startVideoRecording(paramIndex);
       
   215         {--landpreview}         27 : GameType := gmtLandPreview;
   165         {anything else}
   216         {anything else}
   166         {--stats-only}     19 : begin
   217         {--stats-only}          28 : statsOnlyGame();
   167                                 cOnlyStats:= true;
   218         {--gci}                 29 : GciEasterEgg();
   168                                 cReducedQuality:= $FFFFFFFF xor rqLowRes;
   219         {--help}                30 : DisplayUsage();
   169                                 SetSound(false);
       
   170                                 end;
       
   171         {--gci}            20 : begin            //     We had to make up all this saved space some how...     \\
       
   172                                 WriteLn(stdout, '                                                                ');
       
   173                                 WriteLn(stdout, '      /\\\\\\\\\\\\        /\\\\\\\\\  /\\\\\\\\\\\             ');
       
   174                                 WriteLn(stdout, '     /\\\//////////      /\\\////////  \/////\\\///             ');
       
   175                                 WriteLn(stdout, '     /\\\               /\\\/               \/\\\               ');
       
   176                                 WriteLn(stdout, '     \/\\\    /\\\\\\\  /\\\                 \/\\\              ');
       
   177                                 WriteLn(stdout, '      \/\\\   \/////\\\ \/\\\                 \/\\\             ');
       
   178                                 WriteLn(stdout, '       \/\\\       \/\\\ \//\\\                \/\\\            ');
       
   179                                 WriteLn(stdout, '        \/\\\       \/\\\  \///\\\              \/\\\           ');
       
   180                                 WriteLn(stdout, '         \/\\\\\\\\\\\\\/     \////\\\\\\\\\  /\\\\\\\\\\\      ');
       
   181                                 WriteLn(stdout, '          \/////////////          \/////////  \///////////      ');
       
   182                                 WriteLn(stdout, '                                                                ');
       
   183                                 WriteLn(stdout, ' Command Line Parser Implementation by a Google Code-In Student ');
       
   184                                 WriteLn(stdout, '             ASCII Art easter egg idea by @sheepluva            ');
       
   185                                 WriteLn(stdout, '                                                                ');
       
   186                                 end;
       
   187         {--help}           21 : begin
       
   188                                 DisplayUsage();
       
   189                                 GameType:= gmtSyntax;
       
   190                                 end;
       
   191     else
   220     else
   192         begin
   221         begin
   193         WriteLn(stderr, 'ERROR: '+cmd+' is not a valid argument');
   222         //Asusme the first "non parameter" is the replay file, anything else is invalid
   194         parseParameter:= true;
   223         if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then
   195         end
   224             recordFileName := cmd
       
   225         else
       
   226             begin
       
   227             WriteLn(stderr, '"'+cmd+'" is not a valid option');
       
   228             parseParameter:= true;
       
   229             end;
       
   230         end;
   196     end;
   231     end;
   197 end;
   232 end;
   198 
   233 
   199 procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt);
   234 procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt);
   200 var index, tmpInt: LongInt;
   235 var index, tmpInt: LongInt;
   201     isBool: Boolean;
   236     isBool, isValid: Boolean;
   202 begin
   237     cmd, arg, newSyntax: String;
       
   238 begin
       
   239     WriteLn(stdout, 'WARNING: you are using a deprecated command, which could be removed in a future version!');
       
   240     WriteLn(stdout, '         Consider updating to the latest syntax, which is much more flexible!');
       
   241     WriteLn(stdout, '         Run `hwegine --help` to learn it!');
       
   242     WriteLn(stdout, '');
       
   243 
   203     index:= 0;
   244     index:= 0;
   204     tmpInt:= 1;
   245     tmpInt:= 1;
   205     while (index < size) do
   246     while (index < size) do
   206         begin
   247         begin
   207         paramIndex:= paramIndex+1;
   248         inc(paramIndex);
       
   249         cmd:= cmdArray[index];
       
   250         arg:= ParamStr(paramIndex);
       
   251         isValid:= (cmd<>'--depth');
       
   252 
   208         // check if the parameter is a boolean one
   253         // check if the parameter is a boolean one
   209         isBool:= (cmdArray[index] = '--nomusic')
   254         isBool:= (cmd = '--nomusic') or (cmd = '--nosound') or (cmd = '--fullscreen') or (cmd = '--showfps') or (cmd = '--altdmg');
   210             or (cmdArray[index] = '--nosound')
   255         if isBool and (arg='0') then
   211             or (cmdArray[index] = '--fullscreen')
   256             isValid:= false;
   212             or (cmdArray[index] = '--showfps')
   257         if (cmd='--nomusic') or (cmd='--nosound') then
   213             or (cmdArray[index] = '--altdmg')
   258             isValid:= not isValid;
   214             or (cmdArray[index] = '--low-quality');
   259 
   215         if (not isBool) or ((ParamStr(paramIndex)='1') and (cmdArray[index]<>'--nomusic') and (cmdArray[index]<>'--nosound')) then
   260         if isValid then
   216             parseParameter(cmdArray[index], ParamStr(paramIndex), tmpInt);
   261             begin
   217         index:= index+1;
   262             parseParameter(cmd, arg, tmpInt);
   218         end;
   263             newSyntax := newSyntax + cmd + ' ';
   219 end;
   264             if not isBool then
   220 
   265                 newSyntax := newSyntax + arg + ' ';
   221 procedure playReplayFileWithParameters(paramIndex: LongInt);
   266             end;
   222 var tmpInt: LongInt;
   267         inc(index);
       
   268         end;
       
   269     
       
   270     WriteLn(stdout, 'Attempted to automatically convert to the new syntax:');
       
   271     WriteLn(stdout, newSyntax);
       
   272     WriteLn(stdout, '');
       
   273 end;
       
   274 
       
   275 procedure parseCommandLine{$IFDEF HWLIBRARY}(argc: LongInt; argv: PPChar){$ENDIF};
       
   276 var paramIndex: LongInt;
       
   277     paramTotal: LongInt;
   223     wrongParameter: boolean;
   278     wrongParameter: boolean;
   224 begin
   279 begin
       
   280     paramIndex:= 1;
       
   281     paramTotal:={$IFDEF HWLIBRARY}argc{$ELSE}ParamCount{$ENDIF};
   225     wrongParameter:= false;
   282     wrongParameter:= false;
   226     while (paramIndex <= ParamCount) do
   283     while (paramIndex <= paramTotal) do
   227         begin
   284         begin
   228         if parseParameter( ParamStr(paramIndex), ParamStr(paramIndex+1), paramIndex) then
   285         {$IFDEF HWLIBRARY}
   229             wrongParameter:= true;
   286         wrongParameter:= parseParameter( argv[paramIndex], argv[paramIndex+1], paramIndex);
   230         paramIndex:= paramIndex+1;
   287         {$ELSE}
       
   288         wrongParameter:= parseParameter( ParamStr(paramIndex), ParamStr(paramIndex+1), paramIndex);
       
   289         {$ENDIF}
       
   290         inc(paramIndex);
   231         end;
   291         end;
   232     if wrongParameter = true then
   292     if wrongParameter = true then
   233         begin
   293         GameType:= gmtSyntax;
       
   294 end;
       
   295 
       
   296 {$IFNDEF HWLIBRARY}
       
   297 procedure GetParams;
       
   298 //var tmpInt: LongInt;
       
   299 begin
       
   300     (*
       
   301     tmpInt:=0;
       
   302     while (tmpInt <= ParamCount) do
       
   303         begin
       
   304         WriteLn(stdout, inttostr(tmpInt) + ': ' + ParamStr(tmpInt));
       
   305         inc(tmpInt);
       
   306         end;
       
   307     *)
       
   308 
       
   309     isInternal:= (ParamStr(1) = '--internal');
       
   310 
       
   311     UserPathPrefix := '.';
       
   312     PathPrefix     := cDefaultPathPrefix;
       
   313     recordFileName := '';
       
   314     parseCommandLine();
       
   315 
       
   316     if (isInternal) and (ParamCount<=1) then
       
   317         begin
       
   318         WriteLn(stderr, '--internal should not be manually used');
       
   319         GameType := gmtSyntax;
       
   320         end;
       
   321 
       
   322     if (not isInternal) and (recordFileName = '') then
       
   323         begin
       
   324         WriteLn(stderr, 'You must specify a replay file');
       
   325         GameType := gmtSyntax;
       
   326         end
       
   327     else if (recordFileName <> '') then
       
   328         WriteLn(stdout, 'Attempting to play demo file "' + recordFilename + '"');
       
   329 
       
   330     if (GameType = gmtSyntax) then
   234         WriteLn(stderr, 'Please use --help to see possible arguments and their usage');
   331         WriteLn(stderr, 'Please use --help to see possible arguments and their usage');
   235         GameType:= gmtSyntax;
   332 
   236         end
   333     (*
   237 end;
   334     WriteLn(stdout,'PathPrefix:     ' + PathPrefix);
       
   335     WriteLn(stdout,'UserPathPrefix: ' + UserPathPrefix);
       
   336     *)
       
   337 end;
       
   338 {$ENDIF}
       
   339