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.

189 lines
5.2 KiB

  1. //========= Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #ifndef CMDLIB_H
  10. #define CMDLIB_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. // cmdlib.h
  15. #include "basetypes.h"
  16. // This can go away when everything is in bin.
  17. #if defined( CMDLIB_NODBGLIB )
  18. void Error( char const *pMsg, ... );
  19. #else
  20. #include "tier0/dbg.h"
  21. #endif
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <stdlib.h>
  25. #include <errno.h>
  26. #include <ctype.h>
  27. #include <time.h>
  28. #include <stdarg.h>
  29. #include "filesystem.h"
  30. #include "filesystem_tools.h"
  31. // Tools should use this as the read path ID. It'll look into the paths specified by gameinfo.txt
  32. #define TOOLS_READ_PATH_ID "GAME"
  33. // Tools should use this to fprintf data to files.
  34. void CmdLib_FPrintf( FileHandle_t hFile, const char *pFormat, ... );
  35. char* CmdLib_FGets( char *pOut, int outSize, FileHandle_t hFile );
  36. // This can be set so Msg() sends output to hook functions (like the VMPI MySQL database),
  37. // but doesn't actually printf the output.
  38. extern bool g_bSuppressPrintfOutput;
  39. extern IBaseFileSystem *g_pFileSystem;
  40. // These call right into the functions in filesystem_tools.h
  41. void CmdLib_InitFileSystem( const char *pFilename, int maxMemoryUsage = 0 );
  42. void CmdLib_TermFileSystem(); // GracefulExit calls this.
  43. CreateInterfaceFn CmdLib_GetFileSystemFactory();
  44. #ifdef _WIN32
  45. #pragma warning(disable : 4244) // MIPS
  46. #pragma warning(disable : 4136) // X86
  47. #pragma warning(disable : 4051) // ALPHA
  48. #pragma warning(disable : 4018) // signed/unsigned mismatch
  49. #pragma warning(disable : 4305) // truncate from double to float
  50. #pragma warning(disable : 4389) // singned/unsigned mismatch in ==
  51. #pragma warning(disable: 4512) // assignment operator could not be generated
  52. #endif
  53. // the dec offsetof macro doesnt work very well...
  54. #define myoffsetof(type,identifier) offsetof( type, identifier )
  55. // set these before calling CheckParm
  56. extern int myargc;
  57. extern char **myargv;
  58. int Q_filelength (FileHandle_t f);
  59. int FileTime (char *path);
  60. void Q_mkdir( char *path );
  61. char *ExpandArg (char *path); // expand relative to CWD
  62. char *ExpandPath (char *path); // expand relative to gamedir
  63. char *ExpandPathAndArchive (char *path);
  64. // Fills in pOut with "X hours, Y minutes, Z seconds". Leaves out hours or minutes if they're zero.
  65. void GetHourMinuteSecondsString( int nInputSeconds, char *pOut, int outLen );
  66. int CheckParm (char *check);
  67. FileHandle_t SafeOpenWrite ( const char *filename );
  68. FileHandle_t SafeOpenRead ( const char *filename );
  69. void SafeRead( FileHandle_t f, void *buffer, int count);
  70. void SafeWrite( FileHandle_t f, void *buffer, int count);
  71. int LoadFile ( const char *filename, void **bufferptr );
  72. void SaveFile ( const char *filename, void *buffer, int count );
  73. qboolean FileExists ( const char *filename );
  74. int ParseNum (char *str);
  75. // Do a printf in the specified color.
  76. #define CP_ERROR stderr, 1, 0, 0, 1 // default colors..
  77. #define CP_WARNING stderr, 1, 1, 0, 1
  78. #define CP_STARTUP stdout, 0, 1, 1, 1
  79. #define CP_NOTIFY stdout, 1, 1, 1, 1
  80. void ColorPrintf( FILE *pFile, bool red, bool green, bool blue, bool intensity, char const *pFormat, ... );
  81. // Initialize spew output.
  82. void InstallSpewFunction();
  83. // Install allocation hooks so we error out if an allocation can't happen.
  84. void InstallAllocationFunctions();
  85. // This shuts down mgrs that use threads gracefully. If you just call exit(), the threads can
  86. // get in a state where you can't tell if they are shutdown or not, and it can stall forever.
  87. typedef void (*CleanupFn)();
  88. void CmdLib_AtCleanup( CleanupFn pFn ); // register a callback when Cleanup() is called.
  89. void CmdLib_Cleanup();
  90. // entrypoint if chaining spew functions
  91. unsigned short SetConsoleTextColor( int red, int green, int blue, int intensity );
  92. void RestoreConsoleTextColor( unsigned short color );
  93. class CCmdLibStandardLoggingListener : public ILoggingListener
  94. {
  95. public:
  96. virtual void Log( const LoggingContext_t *pContext, const tchar *pMessage );
  97. };
  98. class CCmdLibFileLoggingListener : public ILoggingListener
  99. {
  100. public:
  101. CCmdLibFileLoggingListener();
  102. virtual void Log( const LoggingContext_t *pContext, const tchar *pMessage );
  103. void Open( char const *pFilename );
  104. void Close();
  105. private:
  106. FileHandle_t m_pLogFile;
  107. };
  108. extern CCmdLibStandardLoggingListener g_CmdLibOutputLoggingListener;
  109. extern CCmdLibFileLoggingListener g_CmdLibFileLoggingListener;
  110. char *COM_Parse (char *data);
  111. extern char com_token[1024];
  112. char *copystring(const char *s);
  113. void CreatePath( char *path );
  114. void QCopyFile( char *from, char *to );
  115. void SafeCreatePath( char *path );
  116. extern qboolean archive;
  117. extern char archivedir[1024];
  118. extern qboolean verbose;
  119. void qprintf( char *format, ... );
  120. void ExpandWildcards (int *argc, char ***argv);
  121. void CmdLib_AddBasePath( const char *pBasePath );
  122. void CmdLib_AddNewSearchPath( const char *pBasePath );
  123. bool CmdLib_HasBasePath( const char *pFileName, int &pathLength );
  124. int CmdLib_GetNumBasePaths( void );
  125. const char *CmdLib_GetBasePath( int i );
  126. extern bool g_bStopOnExit;
  127. // for compression routines
  128. typedef struct
  129. {
  130. byte *data;
  131. int count;
  132. } cblock_t;
  133. #endif // CMDLIB_H