aboutsummaryrefslogtreecommitdiff
path: root/mp/src/utils/common/cmdlib.h
blob: 5b5b2c7c99a909ab633611a7d6b604e221d712f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $Workfile:     $
// $Date:         $
// $NoKeywords: $
//=============================================================================//

#ifndef CMDLIB_H
#define CMDLIB_H

#ifdef _WIN32
#pragma once
#endif

// cmdlib.h

#include "basetypes.h"

// This can go away when everything is in bin.
#if defined( CMDLIB_NODBGLIB )
	void Error( PRINTF_FORMAT_STRING char const *pMsg, ... );
#else
	#include "tier0/dbg.h"
#endif

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include <time.h>
#include <stdarg.h>
#include "filesystem.h"
#include "filesystem_tools.h"
#include "tier1/utlstring.h"


// Tools should use this as the read path ID. It'll look into the paths specified by gameinfo.txt
#define TOOLS_READ_PATH_ID "GAME"


// Tools should use this to fprintf data to files.
void CmdLib_FPrintf( FileHandle_t hFile, PRINTF_FORMAT_STRING const char *pFormat, ... );
char* CmdLib_FGets( char *pOut, int outSize, FileHandle_t hFile );


// This can be set so Msg() sends output to hook functions (like the VMPI MySQL database),
// but doesn't actually printf the output.
extern bool g_bSuppressPrintfOutput;

extern IBaseFileSystem *g_pFileSystem;

// These call right into the functions in filesystem_tools.h
void				CmdLib_InitFileSystem( const char *pFilename, int maxMemoryUsage = 0 );
void				CmdLib_TermFileSystem();	// GracefulExit calls this.
CreateInterfaceFn	CmdLib_GetFileSystemFactory();


#ifdef _WIN32
#pragma warning(disable : 4244)     // MIPS
#pragma warning(disable : 4136)     // X86
#pragma warning(disable : 4051)     // ALPHA

#pragma warning(disable : 4018)     // signed/unsigned mismatch
#pragma warning(disable : 4305)     // truncate from double to float

#pragma warning(disable : 4389)     // singned/unsigned mismatch in ==
#pragma warning(disable: 4512) // assignment operator could not be generated
#endif


// the dec offsetof macro doesnt work very well...
#define myoffsetof(type,identifier) offsetof( type, identifier )


// set these before calling CheckParm
extern int myargc;
extern char **myargv;

int Q_filelength (FileHandle_t f);
int	FileTime (char *path);

void	Q_mkdir( char *path );

char *ExpandArg (char *path);	// expand relative to CWD
char *ExpandPath (char *path);	// expand relative to gamedir

char *ExpandPathAndArchive (char *path);

// Fills in pOut with "X hours, Y minutes, Z seconds". Leaves out hours or minutes if they're zero.
void GetHourMinuteSecondsString( int nInputSeconds, char *pOut, int outLen );



int		CheckParm (char *check);

FileHandle_t	SafeOpenWrite ( const char *filename );
FileHandle_t	SafeOpenRead ( const char *filename );
void			SafeRead( FileHandle_t f, void *buffer, int count);
void			SafeWrite( FileHandle_t f, void *buffer, int count);

int		LoadFile ( const char *filename, void **bufferptr );
void	SaveFile ( const char *filename, void *buffer, int count );
qboolean	FileExists ( const char *filename );

int 	ParseNum (char *str);

// Do a printf in the specified color.
#define CP_ERROR	stderr, 1, 0, 0, 1		// default colors..
#define CP_WARNING	stderr, 1, 1, 0, 1		
#define CP_STARTUP	stdout, 0, 1, 1, 1		
#define CP_NOTIFY	stdout, 1, 1, 1, 1
void ColorPrintf( FILE *pFile, bool red, bool green, bool blue, bool intensity, PRINTF_FORMAT_STRING char const *pFormat, ... );

// Initialize spew output.
void InstallSpewFunction();

// This registers an extra callback for spew output.
typedef void (*SpewHookFn)( const char * );
void InstallExtraSpewHook( SpewHookFn pFn );

// Install allocation hooks so we error out if an allocation can't happen.
void InstallAllocationFunctions();

// This shuts down mgrs that use threads gracefully. If you just call exit(), the threads can
// get in a state where you can't tell if they are shutdown or not, and it can stall forever.
typedef void (*CleanupFn)();
void CmdLib_AtCleanup( CleanupFn pFn );	// register a callback when Cleanup() is called.
void CmdLib_Cleanup();
void CmdLib_Exit( int exitCode );	// Use this to cleanup and call exit().

// entrypoint if chaining spew functions
SpewRetval_t CmdLib_SpewOutputFunc( SpewType_t type, char const *pMsg );
unsigned short SetConsoleTextColor( int red, int green, int blue, int intensity );
void RestoreConsoleTextColor( unsigned short color );

// Append all spew output to the specified file.
void SetSpewFunctionLogFile( char const *pFilename );

char *COM_Parse (char *data);

extern	char		com_token[1024];

char *copystring(const char *s);

void	CreatePath( char *path );
void	QCopyFile( char *from, char *to );
void	SafeCreatePath( char *path );

extern	qboolean		archive;
extern	char			archivedir[1024];

extern	qboolean verbose;

void qprintf( PRINTF_FORMAT_STRING const char *format, ... );

void ExpandWildcards (int *argc, char ***argv);

void CmdLib_AddBasePath( const char *pBasePath );
bool CmdLib_HasBasePath( const char *pFileName, int &pathLength );
int CmdLib_GetNumBasePaths( void );
const char *CmdLib_GetBasePath( int i );
// Like ExpandPath but expands the path for each base path like SafeOpenRead
int CmdLib_ExpandWithBasePaths( CUtlVector< CUtlString > &expandedPathList, const char *pszPath );

extern bool g_bStopOnExit;

// for compression routines
typedef struct
{
	byte	*data;
	int		count;
} cblock_t;


#endif // CMDLIB_H