| 181 | } |
| 182 | |
| 183 | int 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; |
nothing calls this directly
no test coverage detected