Team Fortress 2 Source Code as on 22/4/2020
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.

177 lines
5.3 KiB

  1. //========= Copyright 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( PRINTF_FORMAT_STRING 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. #include "tier1/utlstring.h"
  32. // Tools should use this as the read path ID. It'll look into the paths specified by gameinfo.txt
  33. #define TOOLS_READ_PATH_ID "GAME"
  34. // Tools should use this to fprintf data to files.
  35. void CmdLib_FPrintf( FileHandle_t hFile, PRINTF_FORMAT_STRING const char *pFormat, ... );
  36. char* CmdLib_FGets( char *pOut, int outSize, FileHandle_t hFile );
  37. // This can be set so Msg() sends output to hook functions (like the VMPI MySQL database),
  38. // but doesn't actually printf the output.
  39. extern bool g_bSuppressPrintfOutput;
  40. extern IBaseFileSystem *g_pFileSystem;
  41. // These call right into the functions in filesystem_tools.h
  42. void CmdLib_InitFileSystem( const char *pFilename, int maxMemoryUsage = 0 );
  43. void CmdLib_TermFileSystem(); // GracefulExit calls this.
  44. CreateInterfaceFn CmdLib_GetFileSystemFactory();
  45. #ifdef _WIN32
  46. #pragma warning(disable : 4244) // MIPS
  47. #pragma warning(disable : 4136) // X86
  48. #pragma warning(disable : 4051) // ALPHA
  49. #pragma warning(disable : 4018) // signed/unsigned mismatch
  50. #pragma warning(disable : 4305) // truncate from double to float
  51. #pragma warning(disable : 4389) // singned/unsigned mismatch in ==
  52. #pragma warning(disable: 4512) // assignment operator could not be generated
  53. #endif
  54. // the dec offsetof macro doesnt work very well...
  55. #define myoffsetof(type,identifier) offsetof( type, identifier )
  56. // set these before calling CheckParm
  57. extern int myargc;
  58. extern char **myargv;
  59. int Q_filelength (FileHandle_t f);
  60. int FileTime (char *path);
  61. void Q_mkdir( char *path );
  62. char *ExpandArg (char *path); // expand relative to CWD
  63. char *ExpandPath (char *path); // expand relative to gamedir
  64. char *ExpandPathAndArchive (char *path);
  65. // Fills in pOut with "X hours, Y minutes, Z seconds". Leaves out hours or minutes if they're zero.
  66. void GetHourMinuteSecondsString( int nInputSeconds, char *pOut, int outLen );
  67. int CheckParm (char *check);
  68. FileHandle_t SafeOpenWrite ( const char *filename );
  69. FileHandle_t SafeOpenRead ( const char *filename );
  70. void SafeRead( FileHandle_t f, void *buffer, int count);
  71. void SafeWrite( FileHandle_t f, void *buffer, int count);
  72. int LoadFile ( const char *filename, void **bufferptr );
  73. void SaveFile ( const char *filename, void *buffer, int count );
  74. qboolean FileExists ( const char *filename );
  75. int ParseNum (char *str);
  76. // Do a printf in the specified color.
  77. #define CP_ERROR stderr, 1, 0, 0, 1 // default colors..
  78. #define CP_WARNING stderr, 1, 1, 0, 1
  79. #define CP_STARTUP stdout, 0, 1, 1, 1
  80. #define CP_NOTIFY stdout, 1, 1, 1, 1
  81. void ColorPrintf( FILE *pFile, bool red, bool green, bool blue, bool intensity, PRINTF_FORMAT_STRING char const *pFormat, ... );
  82. // Initialize spew output.
  83. void InstallSpewFunction();
  84. // This registers an extra callback for spew output.
  85. typedef void (*SpewHookFn)( const char * );
  86. void InstallExtraSpewHook( SpewHookFn pFn );
  87. // Install allocation hooks so we error out if an allocation can't happen.
  88. void InstallAllocationFunctions();
  89. // This shuts down mgrs that use threads gracefully. If you just call exit(), the threads can
  90. // get in a state where you can't tell if they are shutdown or not, and it can stall forever.
  91. typedef void (*CleanupFn)();
  92. void CmdLib_AtCleanup( CleanupFn pFn ); // register a callback when Cleanup() is called.
  93. void CmdLib_Cleanup();
  94. void CmdLib_Exit( int exitCode ); // Use this to cleanup and call exit().
  95. // entrypoint if chaining spew functions
  96. SpewRetval_t CmdLib_SpewOutputFunc( SpewType_t type, char const *pMsg );
  97. unsigned short SetConsoleTextColor( int red, int green, int blue, int intensity );
  98. void RestoreConsoleTextColor( unsigned short color );
  99. // Append all spew output to the specified file.
  100. void SetSpewFunctionLogFile( char const *pFilename );
  101. char *COM_Parse (char *data);
  102. extern char com_token[1024];
  103. char *copystring(const char *s);
  104. void CreatePath( char *path );
  105. void QCopyFile( char *from, char *to );
  106. void SafeCreatePath( char *path );
  107. extern qboolean archive;
  108. extern char archivedir[1024];
  109. extern qboolean verbose;
  110. void qprintf( PRINTF_FORMAT_STRING const char *format, ... );
  111. void ExpandWildcards (int *argc, char ***argv);
  112. void CmdLib_AddBasePath( const char *pBasePath );
  113. bool CmdLib_HasBasePath( const char *pFileName, int &pathLength );
  114. int CmdLib_GetNumBasePaths( void );
  115. const char *CmdLib_GetBasePath( int i );
  116. // Like ExpandPath but expands the path for each base path like SafeOpenRead
  117. int CmdLib_ExpandWithBasePaths( CUtlVector< CUtlString > &expandedPathList, const char *pszPath );
  118. extern bool g_bStopOnExit;
  119. // for compression routines
  120. typedef struct
  121. {
  122. byte *data;
  123. int count;
  124. } cblock_t;
  125. #endif // CMDLIB_H