hedgewars/ArgParsers.pas
changeset 15300 a3823f0916b8
parent 15299 3bf780084c86
child 15663 d92eeb468dad
equal deleted inserted replaced
15299:3bf780084c86 15300:a3823f0916b8
   128     WriteLn(stdout, IntToStr(cNetProtoVersion));
   128     WriteLn(stdout, IntToStr(cNetProtoVersion));
   129     GameType:= gmtSyntaxHelp;
   129     GameType:= gmtSyntaxHelp;
   130     helpCommandUsed:= true;
   130     helpCommandUsed:= true;
   131 end;
   131 end;
   132 
   132 
   133 procedure setDepth(var paramIndex: LongInt);
       
   134 begin
       
   135     WriteLn(stdout, 'WARNING: --depth is a deprecated command, which could be removed in a future version!');
       
   136     WriteLn(stdout, '         This option no longer does anything, please consider removing it.');
       
   137     WriteLn(stdout, '');
       
   138    inc(ParamIndex);
       
   139 end;
       
   140 
       
   141 procedure statsOnlyGame;
   133 procedure statsOnlyGame;
   142 begin
   134 begin
   143     cOnlyStats:= true;
   135     cOnlyStats:= true;
   144     cReducedQuality:= $FFFFFFFF xor rqLowRes;
   136     cReducedQuality:= $FFFFFFFF xor rqLowRes;
   145     SetSound(false);
   137     SetSound(false);
   248         UserZoom:= cMinZoomLevel;
   240         UserZoom:= cMinZoomLevel;
   249     zoom:= UserZoom;
   241     zoom:= UserZoom;
   250     ZoomValue:= UserZoom;
   242     ZoomValue:= UserZoom;
   251 end;
   243 end;
   252 
   244 
   253 procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt); forward;
       
   254 
       
   255 function parseParameter(cmd:string; arg:string; var paramIndex:LongInt): Boolean;
   245 function parseParameter(cmd:string; arg:string; var paramIndex:LongInt): Boolean;
   256 const videoarray: array [0..5] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--maximized', '--depth');
   246 const reallyAll: array[0..34] of shortstring = (
   257       audioarray: array [0..2] of string = ('--volume','--nomusic','--nosound');
       
   258       otherarray: array [0..2] of string = ('--locale','--fullscreen','--showfps');
       
   259       mediaarray: array [0..10] of string = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--maximized', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen');
       
   260       allarray: array [0..19] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--maximized', '--depth', '--volume','--nomusic','--nosound','--nodampen','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags');
       
   261       reallyAll: array[0..40] of shortstring = (
       
   262                 '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
   247                 '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
   263                 '--height', '--maximized', '--frame-interval', '--volume','--nomusic', '--nosound', '--nodampen',
   248                 '--height', '--maximized', '--frame-interval', '--volume','--nomusic', '--nosound', '--nodampen',
   264                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick',
   249                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick',
   265                 '--zoom',
   250                 '--zoom',
   266   {deprecated}  '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
       
   267   {internal}    '--internal', '--port', '--recorder', '--landpreview',
   251   {internal}    '--internal', '--port', '--recorder', '--landpreview',
   268   {misc}        '--stats-only', '--gci', '--help','--protocol', '--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags','--lua-test','--no-holiday-silliness');
   252   {misc}        '--stats-only', '--gci', '--help','--protocol', '--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags','--lua-test','--no-holiday-silliness');
   269 var cmdIndex: byte;
   253 var cmdIndex: byte;
   270 begin
   254 begin
   271     parseParameter:= false;
   255     parseParameter:= false;
   295         {--low-quality}         16 : cReducedQuality   := $FFFFFFFF xor rqLowRes;
   279         {--low-quality}         16 : cReducedQuality   := $FFFFFFFF xor rqLowRes;
   296         {--raw-quality}         17 : cReducedQuality   := getLongIntParameter(arg, paramIndex, parseParameter);
   280         {--raw-quality}         17 : cReducedQuality   := getLongIntParameter(arg, paramIndex, parseParameter);
   297         {--stereo}              18 : setStereoMode      ( getLongIntParameter(arg, paramIndex, parseParameter) );
   281         {--stereo}              18 : setStereoMode      ( getLongIntParameter(arg, paramIndex, parseParameter) );
   298         {--nick}                19 : UserNick          := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
   282         {--nick}                19 : UserNick          := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
   299         {--zoom}                20 : setZoom(arg, paramIndex, parseParameter);
   283         {--zoom}                20 : setZoom(arg, paramIndex, parseParameter);
   300         {deprecated options}
       
   301         {--depth}               21 : setDepth(paramIndex);
       
   302         {--set-video}           22 : parseClassicParameter(videoarray,5,paramIndex);
       
   303         {--set-audio}           23 : parseClassicParameter(audioarray,3,paramIndex);
       
   304         {--set-other}           24 : parseClassicParameter(otherarray,3,paramIndex);
       
   305         {--set-multimedia}      25 : parseClassicParameter(mediaarray,10,paramIndex);
       
   306         {--set-everything}      26 : parseClassicParameter(allarray,14,paramIndex);
       
   307         {"internal" options}
   284         {"internal" options}
   308         {--internal}            27 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
   285         {--internal}            21 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
   309         {--port}                28 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
   286         {--port}                22 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
   310         {--recorder}            29 : startVideoRecording(paramIndex);
   287         {--recorder}            23 : startVideoRecording(paramIndex);
   311         {--landpreview}         30 : GameType := gmtLandPreview;
   288         {--landpreview}         24 : GameType := gmtLandPreview;
   312         {anything else}
   289         {anything else}
   313         {--stats-only}          31 : statsOnlyGame();
   290         {--stats-only}          25 : statsOnlyGame();
   314         {--gci}                 32 : GciEasterEgg();
   291         {--gci}                 26 : GciEasterEgg();
   315         {--help}                33 : DisplayUsage();
   292         {--help}                27 : DisplayUsage();
   316         {--protocol}            34 : DisplayProtocol();
   293         {--protocol}            28 : DisplayProtocol();
   317         {--no-teamtag}          35 : cTagsMask := cTagsMask and (not htTeamName);
   294         {--no-teamtag}          29 : cTagsMask := cTagsMask and (not htTeamName);
   318         {--no-hogtag}           36 : cTagsMask := cTagsMask and (not htName);
   295         {--no-hogtag}           30 : cTagsMask := cTagsMask and (not htName);
   319         {--no-healthtag}        37 : cTagsMask := cTagsMask and (not htHealth);
   296         {--no-healthtag}        31 : cTagsMask := cTagsMask and (not htHealth);
   320         {--translucent-tags}    38 : cTagsMask := cTagsMask or htTransparent;
   297         {--translucent-tags}    32 : cTagsMask := cTagsMask or htTransparent;
   321         {--lua-test}            39 : begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
   298         {--lua-test}            33 : begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
   322         {--no-holiday-silliness} 40 : cHolidaySilliness:= false;
   299         {--no-holiday-silliness} 34 : cHolidaySilliness:= false;
   323     else
   300     else
   324         begin
   301         begin
   325         //Assume the first "non parameter" is the demo file, anything else is invalid
   302         //Assume the first "non parameter" is the demo file, anything else is invalid
   326         if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then
   303         if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then
   327             recordFileName := cmd
   304             recordFileName := cmd
   332             end;
   309             end;
   333         end;
   310         end;
   334     end;
   311     end;
   335 end;
   312 end;
   336 
   313 
   337 procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt);
       
   338 var index, tmpInt: LongInt;
       
   339     isBool, isValid: Boolean;
       
   340     cmd, arg, newSyntax: string;
       
   341 begin
       
   342     WriteLn(stdout, 'WARNING: You are using a deprecated command, which could be removed in a future version!');
       
   343     WriteLn(stdout, '         Consider updating to the latest syntax, which is much more flexible!');
       
   344     WriteLn(stdout, '         Run "hwegine --help" to learn it!');
       
   345     WriteLn(stdout, '');
       
   346 
       
   347     index:= 0;
       
   348     tmpInt:= 1;
       
   349     while (index < size) do
       
   350         begin
       
   351         newSyntax:= '';
       
   352         inc(paramIndex);
       
   353         cmd:= cmdarray[index];
       
   354         arg:= cmdarray[paramIndex];
       
   355         isValid:= (cmd<>'--depth');
       
   356 
       
   357         // check if the parameter is a boolean one
       
   358         isBool:= (cmd = '--nomusic') or (cmd = '--nosound') or (cmd = '--nodampen') or (cmd = '--maximized') 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');
       
   359         if isBool and (arg='0') then
       
   360             isValid:= false;
       
   361         if (cmd='--nomusic') or (cmd='--nosound') or (cmd='--nodampen') then
       
   362             isValid:= not isValid;
       
   363 
       
   364         if isValid then
       
   365             begin
       
   366             parseParameter(cmd, arg, tmpInt);
       
   367             newSyntax:= newSyntax + cmd + ' ';
       
   368             if not isBool then
       
   369                 newSyntax:= newSyntax + arg + ' ';
       
   370             end;
       
   371         inc(index);
       
   372         end;
       
   373 
       
   374     WriteLn(stdout, 'Attempted to automatically convert to the new syntax:');
       
   375     WriteLn(stdout, newSyntax);
       
   376     WriteLn(stdout, '');
       
   377 end;
       
   378 
       
   379 procedure parseCommandLine;
   314 procedure parseCommandLine;
   380 var paramIndex: LongInt;
   315 var paramIndex: LongInt;
   381     paramTotal: LongInt;
   316     paramTotal: LongInt;
   382     index, nextIndex: LongInt;
   317     index, nextIndex: LongInt;
   383     wrongParameter: boolean;
   318     wrongParameter: boolean;
   384 //var tmpInt: LongInt;
   319 //var tmpInt: LongInt;
   385 begin
   320 begin
   386 
   321 
   387     paramIndex:= {$IFDEF HWLIBRARY}0{$ELSE}1{$ENDIF};
   322     paramIndex:= {$IFDEF HWLIBRARY}0{$ELSE}1{$ENDIF};
   388     paramTotal:= ParamCount; //-1 because pascal enumeration is inclusive
   323     paramTotal:= ParamCount; //-1 because pascal enumeration is inclusive
   389     (*
       
   390     WriteLn(stdout, 'total parameters: ' + inttostr(paramTotal));
       
   391     tmpInt:= 0;
       
   392     while (tmpInt <= paramTotal) do
       
   393         begin
       
   394         WriteLn(stdout, inttostr(tmpInt) + ': ' + {$IFDEF HWLIBRARY}argv[tmpInt]{$ELSE}paramCount(tmpInt){$ENDIF});
       
   395         inc(tmpInt);
       
   396         end;
       
   397     *)
       
   398     wrongParameter:= false;
   324     wrongParameter:= false;
   399     while (paramIndex <= paramTotal) do
   325     while (paramIndex <= paramTotal) do
   400         begin
   326         begin
   401         // avoid going past the number of paramTotal (esp. w/ library)
   327         // avoid going past the number of paramTotal (esp. w/ library)
   402         index:= paramIndex;
   328         index:= paramIndex;
   435             WriteLn(stdout, 'Attempting to play demo file "' + recordFilename + '".');
   361             WriteLn(stdout, 'Attempting to play demo file "' + recordFilename + '".');
   436 
   362 
   437     if (GameType = gmtBadSyntax) then
   363     if (GameType = gmtBadSyntax) then
   438         WriteLn(stderr, 'Please use --help to see possible arguments and their usage.');
   364         WriteLn(stderr, 'Please use --help to see possible arguments and their usage.');
   439 
   365 
   440     (*
       
   441     WriteLn(stdout,'PathPrefix:     ' + PathPrefix);
       
   442     WriteLn(stdout,'UserPathPrefix: ' + UserPathPrefix);
       
   443     *)
       
   444 end;
   366 end;
   445 
   367 
   446 end.
   368 end.
   447 
   369