============ Cmd_TokenizeString Parses the given string into command line tokens. The text is copied to a seperate buffer and 0 characters are inserted in the apropriate place, The argv array will point into this temporary buffer. ============ */
| 487 | ============ |
| 488 | */ |
| 489 | static void Cmd_TokenizeString2( const char *text_in, qboolean ignoreQuotes ) { |
| 490 | const char *text; |
| 491 | char *textOut; |
| 492 | |
| 493 | // clear previous args |
| 494 | cmd_argc = 0; |
| 495 | |
| 496 | if ( !text_in ) { |
| 497 | return; |
| 498 | } |
| 499 | |
| 500 | Q_strncpyz( cmd_cmd, text_in, sizeof(cmd_cmd) ); |
| 501 | |
| 502 | text = text_in; |
| 503 | textOut = cmd_tokenized; |
| 504 | |
| 505 | while ( 1 ) { |
| 506 | if ( cmd_argc == MAX_STRING_TOKENS ) { |
| 507 | return; // this is usually something malicious |
| 508 | } |
| 509 | |
| 510 | while ( 1 ) { |
| 511 | // skip whitespace |
| 512 | while ( *text && *(const unsigned char* /*eurofix*/)text <= ' ' ) { |
| 513 | text++; |
| 514 | } |
| 515 | if ( !*text ) { |
| 516 | return; // all tokens parsed |
| 517 | } |
| 518 | |
| 519 | // skip // comments |
| 520 | if ( text[0] == '/' && text[1] == '/' ) { |
| 521 | return; // all tokens parsed |
| 522 | } |
| 523 | |
| 524 | // skip /* */ comments |
| 525 | if ( text[0] == '/' && text[1] =='*' ) { |
| 526 | while ( *text && ( text[0] != '*' || text[1] != '/' ) ) { |
| 527 | text++; |
| 528 | } |
| 529 | if ( !*text ) { |
| 530 | return; // all tokens parsed |
| 531 | } |
| 532 | text += 2; |
| 533 | } else { |
| 534 | break; // we are ready to parse a token |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | // handle quoted strings |
| 539 | // NOTE TTimo this doesn't handle \" escaping |
| 540 | if ( !ignoreQuotes && *text == '"' ) { |
| 541 | cmd_argv[cmd_argc] = textOut; |
| 542 | cmd_argc++; |
| 543 | text++; |
| 544 | while ( *text && *text != '"' ) { |
| 545 | *textOut++ = *text++; |
| 546 | } |
no test coverage detected