MCPcopy Create free account
hub / github.com/JACoders/OpenJK / Cmd_TokenizeString2

Function Cmd_TokenizeString2

code/qcommon/cmd.cpp:489–584  ·  view source on GitHub ↗

============ 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. ============ */

Source from the content-addressed store, hash-verified

487============
488*/
489static 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 }

Callers 2

Cmd_TokenizeStringFunction · 0.70

Calls 1

Q_strncpyzFunction · 0.85

Tested by

no test coverage detected