//============================================================================ // // Parameter: - // Returns: - // Changes Globals: - //============================================================================ int ScriptSkipTo(script_t *script, char *value) { int len; char firstchar; firstchar = *value; len = strlen(value); do { if(!PS_ReadWhiteSpace(script)) { return 0; } if(*script->script_p == firstchar) { if(!strncmp(script->script_p, value, len)) { return 1; } //end if } //end if script->script_p++; } while(1); } //end of the function ScriptSkipTo
//============================================================================ // // Parameter: - // Returns: - // Changes Globals: - //============================================================================ int PS_ReadToken(script_t* script, token_t* token) { //if there is a token available (from UnreadToken) if (script->tokenavailable) { script->tokenavailable = 0; Com_Memcpy(token, &script->token, sizeof(token_t)); return 1; } //end if //save script pointer script->lastscript_p = script->script_p; //save line counter script->lastline = script->line; //clear the token stuff Com_Memset(token, 0, sizeof(token_t)); //start of the white space script->whitespace_p = script->script_p; token->whitespace_p = script->script_p; //read unusefull stuff if (!PS_ReadWhiteSpace(script)) return 0; //end of the white space script->endwhitespace_p = script->script_p; token->endwhitespace_p = script->script_p; //line the token is on token->line = script->line; //number of lines crossed before token token->linescrossed = script->line - script->lastline; //if there is a leading double quote if (*script->script_p == '\"') { if (!PS_ReadString(script, token, '\"')) return 0; } //end if //if a literal else if (*script->script_p == '\'') { //if (!PS_ReadLiteral(script, token)) return 0; if (!PS_ReadString(script, token, '\'')) return 0; } //end if //if there is a number else if ((*script->script_p >= '0' && *script->script_p <= '9') || (*script->script_p == '.' && (*(script->script_p + 1) >= '0' && *(script->script_p + 1) <= '9'))) { if (!PS_ReadNumber(script, token)) return 0; } //end if //if this is a primitive script else if (script->flags & SCFL_PRIMITIVE) { return PS_ReadPrimitive(script, token); } //end else if //if there is a name else if ((*script->script_p >= 'a' && *script->script_p <= 'z') || (*script->script_p >= 'A' && *script->script_p <= 'Z') || *script->script_p == '_') { if (!PS_ReadName(script, token)) return 0; } //end if //check for punctuations else if (!PS_ReadPunctuation(script, token)) { ScriptError(script, "can't read token"); return 0; } //end if //copy the token into the script structure Com_Memcpy(&script->token, token, sizeof(token_t)); //successfully read a token return 1; } //end of the function PS_ReadToken
//============================================================================ // 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 read successfully // Changes Globals: - //============================================================================ int PS_ReadString(script_t *script, token_t *token, int quote) { int len, tmpline; char *tmpscript_p; if (quote == '\"') token->type = TT_STRING; else token->type = TT_LITERAL; len = 0; //leading quote token->string[len++] = *script->script_p++; // while(1) { //minus 2 because trailing double quote and zero have to be appended if (len >= MAX_TOKEN - 2) { ScriptError(script, "string longer than MAX_TOKEN = %d", MAX_TOKEN); return 0; } //end if //if there is an escape character and //if escape characters inside a string are allowed if (*script->script_p == '\\' && !(script->flags & SCFL_NOSTRINGESCAPECHARS)) { if (!PS_ReadEscapeCharacter(script, &token->string[len])) { token->string[len] = 0; return 0; } //end if len++; } //end if //if a trailing quote else if (*script->script_p == quote) { //step over the double quote script->script_p++; //if white spaces in a string are not allowed if (script->flags & SCFL_NOSTRINGWHITESPACES) break; // tmpscript_p = script->script_p; tmpline = script->line; //read unusefull stuff between possible two following strings if (!PS_ReadWhiteSpace(script)) { script->script_p = tmpscript_p; script->line = tmpline; break; } //end if //if there's no leading double qoute if (*script->script_p != quote) { script->script_p = tmpscript_p; script->line = tmpline; break; } //end if //step over the new leading double quote script->script_p++; } //end if else { if (*script->script_p == '\0') { token->string[len] = 0; ScriptError(script, "missing trailing quote"); return 0; } //end if if (*script->script_p == '\n') { token->string[len] = 0; ScriptError(script, "newline inside string %s", token->string); return 0; } //end if token->string[len++] = *script->script_p++; } //end else } //end while //trailing quote token->string[len++] = quote; //end string with a zero token->string[len] = '\0'; //the sub type is the length of the string token->subtype = len; return 1; } //end of the function PS_ReadString