UFO: Alien Invasion
Loading...
Searching...
No Matches
parse.cpp File Reference

Shared parsing functions. More...

#include "parse.h"
#include "defines.h"
#include "ufotypes.h"
Include dependency graph for parse.cpp:

Go to the source code of this file.

Functions

void Com_UnParseLastToken (void)
 Put back the last token into the parser The next call of Com_Parse will return the same token again.
const char * Com_GetToken (const char **data_p)
 Get the current token value.
Com_TokenType_t Com_GetType (const char **data_p)
 Get the current token type.
Com_TokenType_t Com_NextToken (const char **data_p)
 Compute the next token.
int Com_CountTokensInBuffer (const char *buffer)
 Counts the tokens in the given buffer that the Com_Parse function would extract.
const char * Com_Parse (const char *data_p[], char *target, size_t size, bool replaceWhitespaces)
 Parse a token out of a string.
void Com_SkipBlock (const char **text)
 Skips a block of {} in our script files.
int Com_GetBlock (const char **text, const char **start)
 Get the start and end point of a block in the given text.

Variables

static char com_token [4096]
static bool isUnparsedToken
static Com_TokenType_t type

Detailed Description

Shared parsing functions.

Definition in file parse.cpp.

Function Documentation

◆ Com_CountTokensInBuffer()

int Com_CountTokensInBuffer ( const char * buffer)

Counts the tokens in the given buffer that the Com_Parse function would extract.

Parameters
[in]bufferThe buffer to count the tokens in
Returns
The amount of tokens in the given buffer

Definition at line 80 of file parse.cpp.

References Com_Parse().

Referenced by R_ModLoadAnims().

◆ Com_GetBlock()

int Com_GetBlock ( const char ** text,
const char ** start )

Get the start and end point of a block in the given text.

Parameters
[in,out]textThe text pointer to get the start and end for. The pointer is set to the end of the block in this function.
[out]startThe pointer to the beginning of the block
Returns
The amount of characters in the block, or -1 if the text does not start with the script block character '{'

Definition at line 272 of file parse.cpp.

References Com_Parse(), and Com_SkipBlock().

Referenced by ParseUMP(), SV_ParseUMP(), and TEST_F().

◆ Com_GetToken()

const char * Com_GetToken ( const char ** data_p)

Get the current token value.

Returns
The current token value

Definition at line 51 of file parse.cpp.

References com_token.

Referenced by Com_ParseList().

◆ Com_GetType()

Com_TokenType_t Com_GetType ( const char ** data_p)

Get the current token type.

Returns
The current token type

Definition at line 60 of file parse.cpp.

References type.

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), UI_ParseNode(), UI_ParseProperty(), UI_ParseValueExpression(), and UI_ParseWindow().

◆ Com_NextToken()

Com_TokenType_t Com_NextToken ( const char ** data_p)

Compute the next token.

Returns
Type of the next token

Definition at line 69 of file parse.cpp.

References Com_Parse(), and type.

Referenced by Com_ParseList().

◆ Com_Parse()

const char * Com_Parse ( const char * data_p[],
char * target,
size_t size,
bool replaceWhitespaces )

Parse a token out of a string.

Parameters
data_pPointer to a string which is to be parsed
targetA place to put the parsed data. If 0, an internal buffer of 4096 is used.
sizeThe length of target buffer, if any
replaceWhitespacesReplace "\\t" and "\\n" to "\t" and "\n"
Precondition
data_p is expected to be null-terminated
Returns
The string result of parsing in a string.
Note
if used to parse a quoted string that needs further parsing the returned string must be copied first, as Com_Parse returns a pointer to a static buffer that it holds. this will be re-used on the next call.
See also
Com_EParse

Definition at line 107 of file parse.cpp.

References com_token, data, isUnparsedToken, len, TT_EOF, TT_QUOTED_WORD, TT_WORD, and type.

Referenced by AIR_ParseAircraft(), B_ParseBaseTemplate(), B_ParseBuildings(), CL_DownloadUMPMap(), CL_ParseMapParticle(), CL_ParseMessageID(), CL_ParseParticle(), CL_ParsePtlCmds(), CL_ParseRanks(), CL_ParseSequence(), CL_SpawnParseEntitystring(), CM_LoadMap(), Cmd_TokenizeString(), CMod_LoadEntityString(), Com_CountTokensInBuffer(), Com_EParse(), Com_GetBlock(), Com_MacroExpandString(), Com_NextToken(), Com_ParseActorModels(), Com_ParseActorNames(), Com_ParseActorSounds(), Com_ParseAircraftNames(), Com_ParseArmourOrResistance(), Com_ParseBlock(), Com_ParseBodyPart(), Com_ParseBodyTemplate(), Com_ParseCharacterTemplate(), Com_ParseDamageTypes(), Com_ParseEquipment(), Com_ParseFire(), Com_ParseFireDefinition(), Com_ParseGameTypes(), Com_ParseImplant(), Com_ParseItem(), Com_ParseItemEffect(), Com_ParseMapDefinition(), Com_ParseTeam(), Com_ParseTerrainDefinition(), Com_SkipBlock(), COMP_ParseComponents(), CP_ParseAlienTeam(), CP_ParseCampaign(), CP_ParseResearchableCampaignStates(), CP_ParseResearchedCampaignItems(), ED_CheckNumericType(), ED_GetIntVectorFromString(), ED_ParseEdict(), ED_ParseEntities(), ED_ParseType(), ED_ProcessRanges(), FS_NextScriptHeader(), G_SpawnEntities(), GAME_MP_ParseServerInfoMessage(), GAME_MP_QueryMasterServerThread(), GetToken(), INS_ParseInstallations(), MSO_ParseCategory(), MSO_ParseMessageSettings(), MSO_ParseOption(), ParseMapEntity(), ParseUMP(), R_LoadMaterials(), R_LoadObjModelFace(), R_LoadObjSkin(), R_ModBeginLoading(), R_ModLoadAnims(), R_ParseStage(), R_PreprocessShaderR(), RS_ParseTechnologies(), SV_ParseMapcycle(), SV_ParseUMP(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), UI_BuildRadarImageList(), UI_ParseExpression(), UI_ParseFont(), UI_ParseSprite(), UI_ParseUIModel(), UI_ParseValueExpression(), UI_ParseWindow(), UP_ParseChapter(), and WEB_ListCGameFilesCallback().

◆ Com_SkipBlock()

void Com_SkipBlock ( const char ** text)

Skips a block of {} in our script files.

Parameters
[in,out]textThe text pointer to skip the block in. This pointer is set to the end of the block
Note
Even multiple depth levels are supported. Skipping a block with nested blocks works, too.

Definition at line 253 of file parse.cpp.

References Com_Parse().

Referenced by AIR_ParseAircraft(), CL_ParseMessageID(), Com_GetBlock(), Com_ParseGameTypes(), Com_ParseItemEffect(), Com_ParseTeam(), FS_NextScriptHeader(), and SV_ParseUMP().

◆ Com_UnParseLastToken()

void Com_UnParseLastToken ( void )

Put back the last token into the parser The next call of Com_Parse will return the same token again.

Note
Only allow to use it one time
With it, we can't read to file at the same time

Definition at line 42 of file parse.cpp.

References isUnparsedToken.

Referenced by CL_ParseSequence(), Com_ParseBlockToken(), TEST_F(), UI_ParseCallAction(), UI_ParseExpression(), and UI_ParseSetAction().

Variable Documentation

◆ com_token

char com_token[4096]
static

Definition at line 32 of file parse.cpp.

Referenced by Cmd_TokenizeString(), Com_GetToken(), and Com_Parse().

◆ isUnparsedToken

bool isUnparsedToken
static

Definition at line 33 of file parse.cpp.

Referenced by Com_Parse(), and Com_UnParseLastToken().

◆ type

Com_TokenType_t type
static

Definition at line 34 of file parse.cpp.