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.

132 lines
2.8 KiB

  1. //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // File Utilities.
  4. //
  5. //=====================================================================================//
  6. #ifdef _WIN32
  7. #pragma once
  8. #endif
  9. #define _CRT_SECURE_NO_DEPRECATE 1
  10. #include <ctype.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <stdarg.h>
  14. #include <fcntl.h>
  15. #include <sys/stat.h>
  16. #include <sys/types.h>
  17. #include <string.h>
  18. #ifdef POSIX
  19. #include <unistd.h>
  20. #endif
  21. #if defined( LINUX ) || defined( _LINUX )
  22. #include <sys/io.h>
  23. #endif
  24. #include "tier0/platform.h"
  25. #include "../vpccrccheck/crccheck_shared.h"
  26. template< class T, class NullType, int nMax >
  27. class CSimplePointerStack
  28. {
  29. public:
  30. inline CSimplePointerStack()
  31. {
  32. m_nCount = 0;
  33. }
  34. inline void Purge()
  35. {
  36. for ( int i=0; i < m_nCount; i++ )
  37. m_Values[i] = (NullType)NULL;
  38. m_nCount = 0;
  39. }
  40. inline int Count()
  41. {
  42. return m_nCount;
  43. }
  44. inline T& Top()
  45. {
  46. Assert( m_nCount > 0 );
  47. return m_Values[m_nCount-1];
  48. }
  49. inline void Pop( T &val )
  50. {
  51. Assert( m_nCount > 0 );
  52. --m_nCount;
  53. val = m_Values[m_nCount];
  54. m_Values[m_nCount] = (NullType)NULL;
  55. }
  56. inline void Pop()
  57. {
  58. Assert( m_nCount > 0 );
  59. --m_nCount;
  60. m_Values[m_nCount] = (NullType)NULL;
  61. }
  62. inline void Push( T &val )
  63. {
  64. Assert( m_nCount+1 < nMax );
  65. m_Values[m_nCount] = val;
  66. ++m_nCount;
  67. }
  68. public:
  69. T m_Values[nMax];
  70. int m_nCount;
  71. };
  72. class CXMLWriter
  73. {
  74. public:
  75. CXMLWriter();
  76. bool Open( const char *pFilename, bool bIs2010Format = false );
  77. void Close();
  78. void PushNode( const char *pName );
  79. void PopNode( bool bEmitLabel );
  80. void WriteLineNode( const char *pName, const char *pExtra, const char *pString );
  81. void PushNode( const char *pName, const char *pString );
  82. void Write( const char *p );
  83. CUtlString FixupXMLString( const char *pInput );
  84. private:
  85. void Indent();
  86. bool m_b2010Format;
  87. FILE *m_fp;
  88. CSimplePointerStack< char *, char *, 128 > m_Nodes;
  89. };
  90. long Sys_FileLength( const char* filename, bool bText = false );
  91. int Sys_LoadFile( const char *filename, void **bufferptr, bool bText = false );
  92. void Sys_StripPath( const char *path, char *outpath );
  93. bool Sys_Exists( const char *filename );
  94. bool Sys_FileInfo( const char *pFilename, int64 &nFileSize, int64 &nModifyTime );
  95. bool Sys_StringToBool( const char *pString );
  96. bool Sys_ReplaceString( const char *pStream, const char *pSearch, const char *pReplace, char *pOutBuff, int outBuffSize );
  97. bool Sys_StringPatternMatch( char const *pSrcPattern, char const *pString );
  98. bool Sys_EvaluateEnvironmentExpression( const char *pExpression, const char *pDefault, char *pOutBuff, int nOutBuffSize );
  99. bool Sys_GetActualFilenameCase( const char *pFilename, char *pOutputBuffer, int nOutputBufferSize );
  100. bool Sys_IsFilenameCaseConsistent( const char *pFilename, char *pOutputBuffer, int nOutputBufferSize );