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

Function PS_ReadString

codemp/botlib/l_script.cpp:444–526  ·  view source on GitHub ↗

end of the function PS_ReadEscapeCharacter ============================================================================ Reads C-like string. Escape characters are interpretted. Quotes are included with the string. Reads two strings with a white space between them as one string. Parameter: script : script to read from token : buffer to store the string Returns: qtrue when a string was re

Source from the content-addressed store, hash-verified

442// Changes Globals: -
443//============================================================================
444int PS_ReadString(script_t *script, token_t *token, int quote)
445{
446 int len, tmpline;
447 char *tmpscript_p;
448
449 if (quote == '\"') token->type = TT_STRING;
450 else token->type = TT_LITERAL;
451
452 len = 0;
453 //leading quote
454 token->string[len++] = *script->script_p++;
455 //
456 while(1)
457 {
458 //minus 2 because trailing double quote and zero have to be appended
459 if (len >= MAX_TOKEN - 2)
460 {
461 ScriptError(script, "string longer than MAX_TOKEN = %d", MAX_TOKEN);
462 return 0;
463 } //end if
464 //if there is an escape character and
465 //if escape characters inside a string are allowed
466 if (*script->script_p == '\\' && !(script->flags & SCFL_NOSTRINGESCAPECHARS))
467 {
468 if (!PS_ReadEscapeCharacter(script, &token->string[len]))
469 {
470 token->string[len] = 0;
471 return 0;
472 } //end if
473 len++;
474 } //end if
475 //if a trailing quote
476 else if (*script->script_p == quote)
477 {
478 //step over the double quote
479 script->script_p++;
480 //if white spaces in a string are not allowed
481 if (script->flags & SCFL_NOSTRINGWHITESPACES) break;
482 //
483 tmpscript_p = script->script_p;
484 tmpline = script->line;
485 //read unusefull stuff between possible two following strings
486 if (!PS_ReadWhiteSpace(script))
487 {
488 script->script_p = tmpscript_p;
489 script->line = tmpline;
490 break;
491 } //end if
492 //if there's no leading double qoute
493 if (*script->script_p != quote)
494 {
495 script->script_p = tmpscript_p;
496 script->line = tmpline;
497 break;
498 } //end if
499 //step over the new leading double quote
500 script->script_p++;
501 } //end if

Callers 1

PS_ReadTokenFunction · 0.85

Calls 3

ScriptErrorFunction · 0.85
PS_ReadEscapeCharacterFunction · 0.85
PS_ReadWhiteSpaceFunction · 0.85

Tested by

no test coverage detected