hedgewars/ArgParsers.pas
changeset 10078 8572d1f8b2f0
parent 10015 4feced261c68
child 10108 c68cf030eded
equal deleted inserted replaced
10077:ca67740f19b2 10078:8572d1f8b2f0
   180     if wrongParameter then
   180     if wrongParameter then
   181          WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"');
   181          WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"');
   182     getstringParameter:= str;
   182     getstringParameter:= str;
   183 end;
   183 end;
   184 
   184 
   185 procedure parseClassicParameter(cmdArray: array of string; size:LongInt; var paramIndex:LongInt); forward;
   185 procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt); forward;
   186 
   186 
   187 function parseParameter(cmd:string; arg:string; var paramIndex:LongInt): Boolean;
   187 function parseParameter(cmd:string; arg:string; var paramIndex:LongInt): Boolean;
   188 const videoArray: Array [1..5] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth');
   188 const videoarray: array [0..4] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth');
   189       audioArray: Array [1..3] of string = ('--volume','--nomusic','--nosound');
   189       audioarray: array [0..2] of string = ('--volume','--nomusic','--nosound');
   190       otherArray: Array [1..3] of string = ('--locale','--fullscreen','--showfps');
   190       otherarray: array [0..2] of string = ('--locale','--fullscreen','--showfps');
   191       mediaArray: Array [1..10] of string = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen');
   191       mediaarray: array [0..9] of string = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen');
   192       allArray: Array [1..18] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth','--volume','--nomusic','--nosound','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags');
   192       allarray: array [0..17] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth','--volume','--nomusic','--nosound','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags');
   193       reallyAll: array[0..35] of shortstring = (
   193       reallyAll: array[0..35] of shortstring = (
   194                 '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
   194                 '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
   195                 '--height', '--frame-interval', '--volume','--nomusic', '--nosound',
   195                 '--height', '--frame-interval', '--volume','--nomusic', '--nosound',
   196                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick',
   196                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick',
   197   {deprecated}  '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
   197   {deprecated}  '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
   225         {--raw-quality}         15 : cReducedQuality   := getLongIntParameter(arg, paramIndex, parseParameter);
   225         {--raw-quality}         15 : cReducedQuality   := getLongIntParameter(arg, paramIndex, parseParameter);
   226         {--stereo}              16 : setStereoMode      ( getLongIntParameter(arg, paramIndex, parseParameter) );
   226         {--stereo}              16 : setStereoMode      ( getLongIntParameter(arg, paramIndex, parseParameter) );
   227         {--nick}                17 : UserNick          := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
   227         {--nick}                17 : UserNick          := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
   228         {deprecated options}
   228         {deprecated options}
   229         {--depth}               18 : setDepth(paramIndex);
   229         {--depth}               18 : setDepth(paramIndex);
   230         {--set-video}           19 : parseClassicParameter(videoArray,5,paramIndex);
   230         {--set-video}           19 : parseClassicParameter(videoarray,5,paramIndex);
   231         {--set-audio}           20 : parseClassicParameter(audioArray,3,paramIndex);
   231         {--set-audio}           20 : parseClassicParameter(audioarray,3,paramIndex);
   232         {--set-other}           21 : parseClassicParameter(otherArray,3,paramIndex);
   232         {--set-other}           21 : parseClassicParameter(otherarray,3,paramIndex);
   233         {--set-multimedia}      22 : parseClassicParameter(mediaArray,10,paramIndex);
   233         {--set-multimedia}      22 : parseClassicParameter(mediaarray,10,paramIndex);
   234         {--set-everything}      23 : parseClassicParameter(allArray,14,paramIndex);
   234         {--set-everything}      23 : parseClassicParameter(allarray,14,paramIndex);
   235         {"internal" options}
   235         {"internal" options}
   236         {--internal}            24 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
   236         {--internal}            24 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
   237         {--port}                25 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
   237         {--port}                25 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
   238         {--recorder}            26 : startVideoRecording(paramIndex);
   238         {--recorder}            26 : startVideoRecording(paramIndex);
   239         {--landpreview}         27 : GameType := gmtLandPreview;
   239         {--landpreview}         27 : GameType := gmtLandPreview;
   240         {anything else}
   240         {anything else}
   241         {--stats-only}          28 : statsOnlyGame();
   241         {--stats-only}          28 : statsOnlyGame();
   242         {--gci}                 29 : GciEasterEgg();
   242         {--gci}                 29 : GciEasterEgg();
   243         {--help}                30 : DisplayUsage();
   243         {--help}                30 : DisplayUsage();
   244         {--no-teamtag}          31 : cTagsMask := cTagsMask and not htTeamName;
   244         {--no-teamtag}          31 : cTagsMask := cTagsMask and (not htTeamName);
   245         {--no-hogtag}           32 : cTagsMask := cTagsMask and not htName;
   245         {--no-hogtag}           32 : cTagsMask := cTagsMask and (not htName);
   246         {--no-healthtag}        33 : cTagsMask := cTagsMask and not htHealth;
   246         {--no-healthtag}        33 : cTagsMask := cTagsMask and (not htHealth);
   247         {--translucent-tags}    34 : cTagsMask := cTagsMask or htTransparent;
   247         {--translucent-tags}    34 : cTagsMask := cTagsMask or htTransparent;
   248         {--lua-test}            35 : begin cTestLua := true; cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
   248         {--lua-test}            35 : begin cTestLua := true; cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
   249     else
   249     else
   250         begin
   250         begin
   251         //Assume the first "non parameter" is the replay file, anything else is invalid
   251         //Assume the first "non parameter" is the replay file, anything else is invalid
   258             end;
   258             end;
   259         end;
   259         end;
   260     end;
   260     end;
   261 end;
   261 end;
   262 
   262 
   263 procedure parseClassicParameter(cmdArray: array of string; size:LongInt; var paramIndex:LongInt);
   263 procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt);
   264 var index, tmpInt: LongInt;
   264 var index, tmpInt: LongInt;
   265     isBool, isValid: Boolean;
   265     isBool, isValid: Boolean;
   266     cmd, arg, newSyntax: string;
   266     cmd, arg, newSyntax: string;
   267 begin
   267 begin
   268     WriteLn(stdout, 'WARNING: you are using a deprecated command, which could be removed in a future version!');
   268     WriteLn(stdout, 'WARNING: you are using a deprecated command, which could be removed in a future version!');
   274     tmpInt:= 1;
   274     tmpInt:= 1;
   275     while (index < size) do
   275     while (index < size) do
   276         begin
   276         begin
   277         newSyntax:= '';
   277         newSyntax:= '';
   278         inc(paramIndex);
   278         inc(paramIndex);
   279         cmd:= cmdArray[index];
   279         cmd:= cmdarray[index];
   280         arg:= ParamStr(paramIndex);
   280         arg:= ParamStr(paramIndex);
   281         isValid:= (cmd<>'--depth');
   281         isValid:= (cmd<>'--depth');
   282 
   282 
   283         // check if the parameter is a boolean one
   283         // check if the parameter is a boolean one
   284         isBool:= (cmd = '--nomusic') or (cmd = '--nosound') or (cmd = '--fullscreen') or (cmd = '--showfps') or (cmd = '--altdmg') or (cmd = '--no-teamtag') or (cmd = '--no-hogtag') or (cmd = '--no-healthtag') or (cmd = '--translucent-tags');
   284         isBool:= (cmd = '--nomusic') or (cmd = '--nosound') or (cmd = '--fullscreen') or (cmd = '--showfps') or (cmd = '--altdmg') or (cmd = '--no-teamtag') or (cmd = '--no-hogtag') or (cmd = '--no-healthtag') or (cmd = '--translucent-tags');