MCPcopy Create free account
hub / github.com/ddnet/ddnet / ParseArgs

Method ParseArgs

src/engine/shared/console.cpp:183–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181}
182
183int CConsole::ParseArgs(CResult *pResult, const char *pFormat)
184{
185 char *pStr = pResult->m_pArgsStart;
186 bool Optional = false;
187
188 pResult->ResetVictim();
189
190 for(char Command = *pFormat; Command != '\0'; Command = NextParam(pFormat))
191 {
192 if(Command == '?')
193 {
194 Optional = true;
195 continue;
196 }
197
198 pStr = str_skip_whitespaces(pStr);
199
200 if(*pStr == '\0') // error, non optional command needs value
201 {
202 if(!Optional)
203 {
204 return PARSEARGS_MISSING_VALUE;
205 }
206
207 while(Command)
208 {
209 if(Command == 'v')
210 {
211 pResult->SetVictim(CResult::VICTIM_ME);
212 break;
213 }
214 Command = NextParam(pFormat);
215 }
216 return PARSEARGS_OK;
217 }
218
219 // add token
220 if(*pStr == '"')
221 {
222 pStr++;
223 pResult->AddArgument(pStr);
224
225 char *pDst = pStr; // we might have to process escape data
226 while(pStr[0] != '"')
227 {
228 if(pStr[0] == '\\')
229 {
230 if(pStr[1] == '\\')
231 pStr++; // skip due to escape
232 else if(pStr[1] == '"')
233 pStr++; // skip due to escape
234 }
235 else if(pStr[0] == '\0')
236 {
237 return PARSEARGS_MISSING_VALUE; // return error
238 }
239
240 *pDst = *pStr;

Callers

nothing calls this directly

Calls 9

str_skip_whitespacesFunction · 0.85
str_skip_to_whitespaceFunction · 0.85
str_tointFunction · 0.85
str_tofloatFunction · 0.85
ResetVictimMethod · 0.80
SetVictimMethod · 0.80
AddArgumentMethod · 0.80
NumArgumentsMethod · 0.80
GetStringMethod · 0.45

Tested by

no test coverage detected