hedgewars/ArgParsers.inc
changeset 8308 cdf83bdf7b27
parent 8307 8d7c52b24e28
child 8309 edcfb5e43245
equal deleted inserted replaced
8307:8d7c52b24e28 8308:cdf83bdf7b27
    71 end;
    71 end;
    72 {$ENDIF}
    72 {$ENDIF}
    73 
    73 
    74 procedure DisplayUsage;
    74 procedure DisplayUsage;
    75 begin
    75 begin
    76     WriteLn(stdout, 'Usage:');
    76     WriteLn(stdout, 'Usage: hwengine <path to replay file> [options]');
    77     WriteLn(stdout, '');
    77     WriteLn(stdout, '');
    78     WriteLn(stdout, '  hwengine <path to replay file> [options]');
    78     WriteLn(stdout, 'where [options] can be any of the following:');
    79     WriteLn(stdout, '');
       
    80     WriteLn(stdout, 'where [options] are any of the following:');
       
    81     WriteLn(stdout, ' --prefix [path to folder]');
    79     WriteLn(stdout, ' --prefix [path to folder]');
    82     WriteLn(stdout, ' --user-prefix [path to folder]');
    80     WriteLn(stdout, ' --user-prefix [path to folder]');
    83     WriteLn(stdout, ' --locale [name of language file]');
    81     WriteLn(stdout, ' --locale [name of language file]');
    84     WriteLn(stdout, ' --width [screen width in pixels]');
    82     WriteLn(stdout, ' --width [screen width in pixels]');
    85     WriteLn(stdout, ' --height [screen height in pixels]');
    83     WriteLn(stdout, ' --height [screen height in pixels]');
   100 end;
    98 end;
   101 
    99 
   102 function getLongIntParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): LongInt;
   100 function getLongIntParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): LongInt;
   103 var tmpInt, c: LongInt;
   101 var tmpInt, c: LongInt;
   104 begin
   102 begin
   105     paramIndex:= paramIndex + 1;
   103     inc(paramIndex);
   106     val(str, tmpInt, c);
   104     val(str, tmpInt, c);
   107     wrongParameter:= c <> 0;
   105     wrongParameter:= c <> 0;
   108     if wrongParameter then
   106     if wrongParameter then
   109         WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a number, you passed "'+str+'"');
   107         WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a number, you passed "'+str+'"');
   110     getLongIntParameter:= tmpInt;
   108     getLongIntParameter:= tmpInt;
   111 end;
   109 end;
   112 
   110 
   113 function getStringParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): String;
   111 function getStringParameter(str:String; var paramIndex:LongInt; var wrongParameter:Boolean): String;
   114 begin
   112 begin
   115     paramIndex:= paramIndex + 1;
   113     inc(paramIndex);
   116     wrongParameter:= (str='') or (Copy(str,1,2) = '--');
   114     wrongParameter:= (str='') or (Copy(str,1,2) = '--');
   117     if wrongParameter then
   115     if wrongParameter then
   118          WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"');
   116          WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"');
   119     getStringParameter:= str;
   117     getStringParameter:= str;
   120 end;
   118 end;
   206 
   204 
   207 procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt);
   205 procedure parseClassicParameter(cmdArray: Array of String; size:LongInt; var paramIndex:LongInt);
   208 var index, tmpInt: LongInt;
   206 var index, tmpInt: LongInt;
   209     isBool: Boolean;
   207     isBool: Boolean;
   210 begin
   208 begin
       
   209     WriteLn(stdout, 'WARNING: you are using a deprecated command, which could be removed in a future version!');
       
   210     WriteLn(stdout, '         Consider updating to the latest syntax, which is much more flexible!');
       
   211     WriteLn(stdout, '         Run `hwegine --help` to learn it!');
       
   212     WriteLn(stdout, '');
       
   213 
   211     index:= 0;
   214     index:= 0;
   212     tmpInt:= 1;
   215     tmpInt:= 1;
   213     while (index < size) do
   216     while (index < size) do
   214         begin
   217         begin
   215         paramIndex:= paramIndex+1;
   218         paramIndex:= paramIndex+1;
   220             or (cmdArray[index] = '--showfps')
   223             or (cmdArray[index] = '--showfps')
   221             or (cmdArray[index] = '--altdmg')
   224             or (cmdArray[index] = '--altdmg')
   222             or (cmdArray[index] = '--low-quality');
   225             or (cmdArray[index] = '--low-quality');
   223         if (not isBool) or ((ParamStr(paramIndex)='1') and (cmdArray[index]<>'--nomusic') and (cmdArray[index]<>'--nosound')) then
   226         if (not isBool) or ((ParamStr(paramIndex)='1') and (cmdArray[index]<>'--nomusic') and (cmdArray[index]<>'--nosound')) then
   224             parseParameter(cmdArray[index], ParamStr(paramIndex), tmpInt);
   227             parseParameter(cmdArray[index], ParamStr(paramIndex), tmpInt);
   225         index:= index+1;
   228         inc(index);
   226         end;
   229         end;
   227 end;
   230 end;
   228 
   231 
   229 procedure playReplayFileWithParameters(paramIndex: LongInt);
   232 procedure playReplayFileWithParameters;
   230 var tmpInt: LongInt;
   233 var paramIndex: LongInt;
   231     wrongParameter: boolean;
   234     wrongParameter: boolean;
   232 begin
   235 begin
       
   236     paramIndex:= 1;
   233     wrongParameter:= false;
   237     wrongParameter:= false;
   234     while (paramIndex <= ParamCount) do
   238     while (paramIndex <= ParamCount) do
   235         begin
   239         begin
   236         if parseParameter( ParamStr(paramIndex), ParamStr(paramIndex+1), paramIndex) then
   240         if parseParameter( ParamStr(paramIndex), ParamStr(paramIndex+1), paramIndex) then
   237             wrongParameter:= true;
   241             wrongParameter:= true;
   238         paramIndex:= paramIndex+1;
   242         inc(paramIndex);
   239         end;
   243         end;
   240     if wrongParameter = true then
   244     if wrongParameter = true then
   241         begin
   245         begin
   242         WriteLn(stderr, 'Please use --help to see possible arguments and their usage');
   246         WriteLn(stderr, 'Please use --help to see possible arguments and their usage');
   243         GameType:= gmtSyntax;
   247         GameType:= gmtSyntax;
   244         end
   248         end
   245 end;
   249 end;
       
   250 
       
   251 procedure GetParams;
       
   252 begin
       
   253     (*
       
   254     tmpInt:=0;
       
   255     while (tmpInt <= ParamCount) do
       
   256         begin
       
   257         WriteLn(stdout,inttostr(tmpInt) + ': ' + ParamStr(tmpInt));
       
   258         inc(tmpInt);
       
   259         end;
       
   260     *)
       
   261 
       
   262     if (ParamCount = 3) and (ParamStr(3) = 'landpreview') then
       
   263     begin
       
   264         PathPrefix := ParamStr(1);
       
   265         ipcPort    := StrToInt(ParamStr(2));
       
   266         GameType   := gmtLandPreview;
       
   267         exit;
       
   268     end;
       
   269 
       
   270     //TODO: prepend something so that we can use a cDefaultParamNum of parameters
       
   271     if ParamCount = cDefaultParamNum then
       
   272     begin
       
   273         internalStartGameWithParameters();
       
   274         exit;
       
   275     end
       
   276 {$IFDEF USE_VIDEO_RECORDING}
       
   277     else if ParamCount = cVideorecParamNum then
       
   278     begin
       
   279         internalStartVideoRecordingWithParameters();
       
   280         exit;
       
   281     end
       
   282 {$ENDIF};
       
   283 
       
   284     UserPathPrefix := '.';
       
   285     PathPrefix     := cDefaultPathPrefix;
       
   286     recordFileName := '';
       
   287     playReplayFileWithParameters();
       
   288 
       
   289     if (recordFileName = '') then
       
   290         begin
       
   291         DisplayUsage();
       
   292         GameType:= gmtSyntax;
       
   293         end;
       
   294     (*
       
   295     WriteLn(stdout,'PathPrefix:     ' + PathPrefix);
       
   296     WriteLn(stdout,'UserPathPrefix: ' + UserPathPrefix);
       
   297     WriteLn(stdout,'recordFilename: ' + recordFilename);
       
   298     *)
       
   299 end;
       
   300 
       
   301