diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/xbox/toollib/scriplib.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'utils/xbox/toollib/scriplib.cpp')
| -rw-r--r-- | utils/xbox/toollib/scriplib.cpp | 264 |
1 files changed, 264 insertions, 0 deletions
diff --git a/utils/xbox/toollib/scriplib.cpp b/utils/xbox/toollib/scriplib.cpp new file mode 100644 index 0000000..e674673 --- /dev/null +++ b/utils/xbox/toollib/scriplib.cpp @@ -0,0 +1,264 @@ +#include "toollib.h" + +char g_tl_token[MAXTOKEN]; +char* g_tl_scriptbuff; +char* g_tl_scriptptr; +char* g_tl_scriptendptr; +int g_tl_scriptsize; +int g_tl_scriptline; +bool g_tl_endofscript; +bool g_tl_tokenready; +int g_tl_oldscriptline; +char* g_tl_oldscriptptr; + +/***************************************************************************** + TL_FreeScriptFile + +*****************************************************************************/ +void TL_FreeScriptFile(void) +{ + if (g_tl_scriptbuff) + { + TL_Free(g_tl_scriptbuff); + g_tl_scriptbuff = NULL; + } +} + +/***************************************************************************** + TL_LoadScriptFile + +*****************************************************************************/ +void TL_LoadScriptFile(const char* filename) +{ + g_tl_scriptsize = TL_LoadFile(filename,(void **)&g_tl_scriptbuff); + + TL_ResetParser(); +} + +/***************************************************************************** + TL_SetScriptData + +*****************************************************************************/ +void TL_SetScriptData(char* data, int length) +{ + g_tl_scriptbuff = data; + g_tl_scriptsize = length; + + TL_ResetParser(); +} + +/***************************************************************************** + TL_UnGetToken + +*****************************************************************************/ +void TL_UnGetToken(void) +{ + g_tl_tokenready = true; +} + +/***************************************************************************** + TL_GetToken + +*****************************************************************************/ +char* TL_GetToken(bool crossline) +{ + char* tokenptr; + + if (g_tl_tokenready) + { + g_tl_tokenready = false; + return (g_tl_token); + } + + g_tl_token[0] = '\0'; + + if (g_tl_scriptptr >= g_tl_scriptendptr) + { + if (!crossline) + TL_Error("TL_GetToken: Line %d is incomplete",g_tl_scriptline); + + g_tl_endofscript = true; + return (NULL); + } + +skipspace: + while (*g_tl_scriptptr <= ' ') + { + if (g_tl_scriptptr >= g_tl_scriptendptr) + { + if (!crossline) + TL_Error("GetToken: Line %i is incomplete",g_tl_scriptline); + + g_tl_endofscript = true; + return (NULL); + } + + if (*g_tl_scriptptr++ == '\n') + { + if (!crossline) + TL_Error("GetToken: Line %i is incomplete",g_tl_scriptline); + + g_tl_scriptline++; + } + } + + if (g_tl_scriptptr >= g_tl_scriptendptr) + { + if (!crossline) + TL_Error("GetToken: Line %i is incomplete",g_tl_scriptline); + + g_tl_endofscript = true; + return (NULL); + } + + // skip commented line + if ((g_tl_scriptptr[0] == ';') || (g_tl_scriptptr[0] == '/' && g_tl_scriptptr[1] == '/')) + { + if (!crossline) + TL_Error("GetToken: Line %i is incomplete",g_tl_scriptline); + + while (*g_tl_scriptptr++ != '\n') + { + if (g_tl_scriptptr >= g_tl_scriptendptr) + { + g_tl_endofscript = true; + return (NULL); + } + } + + g_tl_scriptline++; + goto skipspace; + } + + tokenptr = g_tl_token; + if (g_tl_scriptptr[0] == '\"' && g_tl_scriptptr[1]) + { + // copy quoted token + do + { + *tokenptr++ = *g_tl_scriptptr++; + if (g_tl_scriptptr == g_tl_scriptendptr) + break; + + if (tokenptr == &g_tl_token[MAXTOKEN]) + TL_Error("GetToken: Token too large on line %i",g_tl_scriptline); + } + while (*g_tl_scriptptr >= ' ' && *g_tl_scriptptr != '\"'); + + if (g_tl_scriptptr[0] == '\"') + *tokenptr++ = *g_tl_scriptptr++; + } + else + { + // copy token + while (*g_tl_scriptptr > ' ' && *g_tl_scriptptr != ';' && *g_tl_scriptptr != '\"') + { + *tokenptr++ = *g_tl_scriptptr++; + if (g_tl_scriptptr == g_tl_scriptendptr) + break; + + if (tokenptr == &g_tl_token[MAXTOKEN]) + TL_Error("GetToken: Token too large on line %i",g_tl_scriptline); + } + } + + *tokenptr = '\0'; + + return (g_tl_token); +} + +/***************************************************************************** + TL_SkipRestOfLine + +*****************************************************************************/ +void TL_SkipRestOfLine(void) +{ + while (*g_tl_scriptptr++ != '\n') + { + if (g_tl_scriptptr >= g_tl_scriptendptr) + { + break; + } + } + + g_tl_scriptline++; +} + +/***************************************************************************** + TL_TokenAvailable + + Returns (TRUE) if token available on line. +*****************************************************************************/ +bool TL_TokenAvailable (void) +{ + char* ptr; + + ptr = g_tl_scriptptr; + while (*ptr <= ' ') + { + if (ptr >= g_tl_scriptendptr) + { + g_tl_endofscript = true; + return (false); + } + + if (*ptr++ == '\n') + return (false); + } + + return (true); +} + + +/***************************************************************************** + TL_EndOfScript + + Returns (TRUE) at end of script +*****************************************************************************/ +bool TL_EndOfScript(void) +{ + if (g_tl_scriptptr >= g_tl_scriptendptr) + { + g_tl_endofscript = true; + return (true); + } + + return (false); +} + +/***************************************************************************** + TL_ResetParser + +*****************************************************************************/ +void TL_ResetParser(void) +{ + g_tl_scriptptr = g_tl_scriptbuff; + g_tl_scriptendptr = g_tl_scriptptr + g_tl_scriptsize; + g_tl_scriptline = 1; + g_tl_endofscript = false; + g_tl_tokenready = false; +} + +/***************************************************************************** + TL_SaveParser + +*****************************************************************************/ +void TL_SaveParser(void) +{ + g_tl_oldscriptline = g_tl_scriptline; + g_tl_oldscriptptr = g_tl_scriptptr; +} + +/***************************************************************************** + TL_RestoreParser + +*****************************************************************************/ +void TL_RestoreParser(void) +{ + g_tl_scriptline = g_tl_oldscriptline; + g_tl_scriptptr = g_tl_oldscriptptr; +} + + + + |