hedgewars/ArgParsers.pas
changeset 10173 fff5e4b0dfcb
parent 10108 c68cf030eded
child 10175 c92668840ea8
equal deleted inserted replaced
10172:7cfd1a9356b5 10173:fff5e4b0dfcb
    23 
    23 
    24 {$IFNDEF HWLIBRARY}
    24 {$IFNDEF HWLIBRARY}
    25 procedure GetParams;
    25 procedure GetParams;
    26 {$ELSE}
    26 {$ELSE}
    27 procedure parseCommandLine(argc: LongInt; argv: PPChar);
    27 procedure parseCommandLine(argc: LongInt; argv: PPChar);
       
    28 
       
    29 var operatingsystem_parameter_argc: integer = 0; export;
       
    30     operatingsystem_parameter_argv: pointer = nil; export;
       
    31     operatingsystem_parameter_envp: pointer = nil; export;
    28 {$ENDIF}
    32 {$ENDIF}
    29 
    33 
    30 implementation
    34 implementation
    31 uses uVariables, uTypes, uUtils, uSound, uConsts;
    35 uses uVariables, uTypes, uUtils, uSound, uConsts;
    32 var isInternal: Boolean {$IFDEF HWLIBRARY} = true{$ENDIF};
    36 var isInternal: Boolean {$IFDEF HWLIBRARY} = true{$ENDIF};
   144 procedure startVideoRecording(var paramIndex: LongInt);
   148 procedure startVideoRecording(var paramIndex: LongInt);
   145 begin
   149 begin
   146     // Silence the hint that appears when USE_VIDEO_RECORDING is not defined
   150     // Silence the hint that appears when USE_VIDEO_RECORDING is not defined
   147     paramIndex:= paramIndex;
   151     paramIndex:= paramIndex;
   148 {$IFDEF USE_VIDEO_RECORDING}
   152 {$IFDEF USE_VIDEO_RECORDING}
       
   153 {$IFNDEF HWLIBRARY}
   149     GameType:= gmtRecord;
   154     GameType:= gmtRecord;
   150     inc(paramIndex);
   155     inc(paramIndex);
   151     cVideoFramerateNum:= StrToInt(ParamStr(paramIndex)); inc(paramIndex);
   156     cVideoFramerateNum:= StrToInt(ParamStr(paramIndex)); inc(paramIndex);
   152     cVideoFramerateDen:= StrToInt(ParamStr(paramIndex)); inc(paramIndex);
   157     cVideoFramerateDen:= StrToInt(ParamStr(paramIndex)); inc(paramIndex);
   153     RecPrefix:= ParamStr(paramIndex);                    inc(paramIndex);
   158     RecPrefix:= ParamStr(paramIndex);                    inc(paramIndex);
   154     cAVFormat:= ParamStr(paramIndex);                    inc(paramIndex);
   159     cAVFormat:= ParamStr(paramIndex);                    inc(paramIndex);
   155     cVideoCodec:= ParamStr(paramIndex);                  inc(paramIndex);
   160     cVideoCodec:= ParamStr(paramIndex);                  inc(paramIndex);
   156     cVideoQuality:= StrToInt(ParamStr(paramIndex));      inc(paramIndex);
   161     cVideoQuality:= StrToInt(ParamStr(paramIndex));      inc(paramIndex);
   157     cAudioCodec:= ParamStr(paramIndex);                  inc(paramIndex);
   162     cAudioCodec:= ParamStr(paramIndex);                  inc(paramIndex);
   158 {$ENDIF}
   163 {$ENDIF}
       
   164 {$ENDIF}
   159 end;
   165 end;
   160 
   166 
   161 function getLongIntParameter(str:shortstring; var paramIndex:LongInt; var wrongParameter:Boolean): LongInt;
   167 function getLongIntParameter(str:shortstring; var paramIndex:LongInt; var wrongParameter:Boolean): LongInt;
   162 var tmpInt, c: LongInt;
   168 var tmpInt, c: LongInt;
   163 begin
   169 begin
   164     inc(paramIndex);
   170     inc(paramIndex);
   165 {$IFDEF PAS2C}
   171 {$IFDEF PAS2C OR HWLIBRARY}
   166     val(str, tmpInt);
   172     val(str, tmpInt);
   167 {$ELSE}
   173 {$ELSE}
   168     val(str, tmpInt, c);
   174     val(str, tmpInt, c);
   169     wrongParameter:= c <> 0;
   175     wrongParameter:= c <> 0;
   170     if wrongParameter then
   176     if wrongParameter then
   175 
   181 
   176 function getstringParameter(str:shortstring; var paramIndex:LongInt; var wrongParameter:Boolean): shortstring;
   182 function getstringParameter(str:shortstring; var paramIndex:LongInt; var wrongParameter:Boolean): shortstring;
   177 begin
   183 begin
   178     inc(paramIndex);
   184     inc(paramIndex);
   179     wrongParameter:= (str='') or (Copy(str,1,2) = '--');
   185     wrongParameter:= (str='') or (Copy(str,1,2) = '--');
       
   186     {$IFNDEF HWLIBRARY}
   180     if wrongParameter then
   187     if wrongParameter then
   181          WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"');
   188         WriteLn(stderr, 'ERROR: '+ParamStr(paramIndex-1)+' expects a string, you passed "'+str+'"');
       
   189     {$ENDIF}
   182     getstringParameter:= str;
   190     getstringParameter:= str;
   183 end;
   191 end;
   184 
   192 
   185 procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt); forward;
   193 procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt); forward;
   186 
   194 
   275     while (index < size) do
   283     while (index < size) do
   276         begin
   284         begin
   277         newSyntax:= '';
   285         newSyntax:= '';
   278         inc(paramIndex);
   286         inc(paramIndex);
   279         cmd:= cmdarray[index];
   287         cmd:= cmdarray[index];
   280         arg:= ParamStr(paramIndex);
   288         arg:= cmdarray[paramIndex];
   281         isValid:= (cmd<>'--depth');
   289         isValid:= (cmd<>'--depth');
   282 
   290 
   283         // check if the parameter is a boolean one
   291         // 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');
   292         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');
   285         if isBool and (arg='0') then
   293         if isBool and (arg='0') then
   307     paramTotal: LongInt;
   315     paramTotal: LongInt;
   308     index, nextIndex: LongInt;
   316     index, nextIndex: LongInt;
   309     wrongParameter: boolean;
   317     wrongParameter: boolean;
   310 //var tmpInt: LongInt;
   318 //var tmpInt: LongInt;
   311 begin
   319 begin
       
   320     {$IFDEF HWLIBRARY}
       
   321     operatingsystem_parameter_argc:= argc;
       
   322     operatingsystem_parameter_argv:= argv;
       
   323     {$ENDIF}
       
   324 
   312     paramIndex:= {$IFDEF HWLIBRARY}0{$ELSE}1{$ENDIF};
   325     paramIndex:= {$IFDEF HWLIBRARY}0{$ELSE}1{$ENDIF};
   313     paramTotal:= {$IFDEF HWLIBRARY}argc-1{$ELSE}ParamCount{$ENDIF}; //-1 because pascal enumeration is inclusive
   326     paramTotal:= {$IFDEF HWLIBRARY}argc-1{$ELSE}ParamCount{$ENDIF}; //-1 because pascal enumeration is inclusive
   314     (*
   327     (*
   315     WriteLn(stdout, 'total parameters: ' + inttostr(paramTotal));
   328     WriteLn(stdout, 'total parameters: ' + inttostr(paramTotal));
   316     tmpInt:= 0;
   329     tmpInt:= 0;