Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.8 KiB

  1. //===================== Copyright (c) Valve Corporation. All Rights Reserved. ======================
  2. //
  3. // This module manages a stack of "script sources".
  4. //
  5. //==================================================================================================
  6. #ifndef SCRIPTSOURCE_H
  7. #define SCRIPTSOURCE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #define MAX_SYSPRINTMSG 4096
  12. #define MAX_SYSTOKENCHARS 4096
  13. class CScriptSource
  14. {
  15. public:
  16. CScriptSource()
  17. {
  18. Set( "", NULL, 0, false );
  19. }
  20. CScriptSource( const char *pScriptName, const char *pScriptData, int nScriptLine, bool bFreeScriptAtPop )
  21. {
  22. Set( pScriptName, pScriptData, nScriptLine, bFreeScriptAtPop );
  23. }
  24. void Set( const char *pScriptName, const char *pScriptData, int nScriptLine, bool bFreeScriptAtPop )
  25. {
  26. m_ScriptName = pScriptName;
  27. m_pScriptData = pScriptData;
  28. m_nScriptLine = nScriptLine;
  29. m_bFreeScriptAtPop = bFreeScriptAtPop;
  30. }
  31. const char *GetName() const { return m_ScriptName.Get(); }
  32. const char *GetData() const { return m_pScriptData; }
  33. int GetLine() const { return m_nScriptLine; }
  34. bool IsFreeScriptAtPop() const { return m_bFreeScriptAtPop; }
  35. private:
  36. CUtlString m_ScriptName;
  37. const char *m_pScriptData;
  38. int m_nScriptLine;
  39. bool m_bFreeScriptAtPop;
  40. };
  41. class CScript
  42. {
  43. public:
  44. CScript();
  45. void PushScript( const char *pFilename );
  46. void PushScript( const char *pScriptName, const char *ppScriptData, int nScriptLine = 1, bool bFreeScriptAtPop = false );
  47. void PushCurrentScript();
  48. void PopScript();
  49. CScriptSource GetCurrentScript();
  50. void RestoreScript( const CScriptSource &scriptSource );
  51. void EnsureScriptStackEmpty();
  52. void SpewScriptStack();
  53. const char *GetName() const { return m_ScriptName.Get(); }
  54. const char *GetData() const { return m_pScriptData; }
  55. int GetLine() const { return m_nScriptLine; }
  56. const char *GetToken( bool bAllowLineBreaks );
  57. const char *PeekNextToken( bool bAllowLineBreaks );
  58. void SkipRestOfLine();
  59. void SkipBracedSection();
  60. void SkipToValidToken();
  61. bool ParsePropertyValue( const char *pBaseString, char *pOutBuff, int outBuffSize );
  62. private:
  63. const char *SkipWhitespace( const char *data, bool *pHasNewLines, int *pNumLines );
  64. const char *SkipToValidToken( const char *data, bool *pHasNewLines, int *pNumLines );
  65. void SkipBracedSection( const char **dataptr, int *numlines );
  66. void SkipRestOfLine( const char **dataptr, int *numlines );
  67. const char *PeekNextToken( const char *dataptr, bool bAllowLineBreaks );
  68. const char *GetToken( const char **dataptr, bool allowLineBreaks, int *pNumLines );
  69. CUtlStack< CScriptSource > m_ScriptStack;
  70. int m_nScriptLine;
  71. int *m_pScriptLine;
  72. const char *m_pScriptData;
  73. CUtlString m_ScriptName;
  74. bool m_bFreeScriptAtPop;
  75. char m_Token[MAX_SYSTOKENCHARS];
  76. char m_PeekToken[MAX_SYSTOKENCHARS];
  77. };
  78. #endif // SCRIPTSOURCE_H