TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DumpContext.cpp File Reference
#include "../CascLib.h"
#include "../CascCommon.h"
+ Include dependency graph for DumpContext.cpp:

Macros

#define __CASCLIB_SELF__
 

Functions

static TCHARFormatFileName (TCascStorage *hs, const TCHAR *szNameFormat)
 
TDumpContextCreateDumpContext (TCascStorage *hs, const TCHAR *szNameFormat)
 
int dump_print (TDumpContext *dc, const char *szFormat,...)
 
int dump_close (TDumpContext *dc)
 

Macro Definition Documentation

#define __CASCLIB_SELF__

Function Documentation

TDumpContext* CreateDumpContext ( TCascStorage hs,
const TCHAR szNameFormat 
)
57 {
58  TDumpContext * dc;
59  TCHAR * szFileName;
60 
61  // Validate the storage handle
62  if(hs != NULL)
63  {
64  // Calculate the number of bytes needed for dump context
65  dc = CASC_ALLOC(TDumpContext, 1);
66  if(dc != NULL)
67  {
68  // Initialize the dump context
69  memset(dc, 0, sizeof(TDumpContext));
70 
71  // Format the real file name
72  szFileName = FormatFileName(hs, szNameFormat);
73  if(szFileName != NULL)
74  {
75  // Create the file
76  dc->pStream = FileStream_CreateFile(szFileName, 0);
77  if(dc->pStream != NULL)
78  {
79  // Initialize buffers
80  dc->pbBufferBegin =
81  dc->pbBufferPtr = dc->DumpBuffer;
83 
84  // Success
85  CASC_FREE(szFileName);
86  return dc;
87  }
88 
89  // File create failed --> delete the file name
90  CASC_FREE(szFileName);
91  }
92 
93  // Free the dump context
94  CASC_FREE(dc);
95  }
96  }
97 
98  return NULL;
99 }
TFileStream * FileStream_CreateFile(const TCHAR *szFileName, DWORD dwStreamFlags)
Definition: FileStream.cpp:2328
#define CASC_ALLOC(type, count)
Definition: CascCommon.h:302
static TCHAR * FormatFileName(TCascStorage *hs, const TCHAR *szNameFormat)
Definition: DumpContext.cpp:18
LPBYTE pbBufferPtr
Definition: DumpContext.h:25
arena_t NULL
Definition: jemalloc_internal.h:624
char TCHAR
Definition: CascPort.h:148
#define CASC_FREE(ptr)
Definition: CascCommon.h:303
Definition: DumpContext.h:21
LPBYTE pbBufferEnd
Definition: DumpContext.h:26
LPBYTE pbBufferBegin
Definition: DumpContext.h:24
BYTE DumpBuffer[CASC_DUMP_BUFFER_SIZE]
Definition: DumpContext.h:28
#define CASC_DUMP_BUFFER_SIZE
Definition: DumpContext.h:18
TFileStream * pStream
Definition: DumpContext.h:23

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int dump_close ( TDumpContext dc)
137 {
138  // Only if the dump context is valid
139  if(dc != NULL)
140  {
141  // Flush the dump context if there are some data
142  if(dc->pbBufferPtr > dc->pbBufferBegin)
144  dc->pbBufferPtr = dc->pbBufferBegin;
145 
146  // Free the file stream and the entire context
147  if(dc->pStream != NULL)
149  CASC_FREE(dc);
150  }
151 
152  return 0;
153 }
LPBYTE pbBufferPtr
Definition: DumpContext.h:25
arena_t NULL
Definition: jemalloc_internal.h:624
#define CASC_FREE(ptr)
Definition: CascCommon.h:303
void FileStream_Close(TFileStream *pStream)
Definition: FileStream.cpp:2707
unsigned int DWORD
Definition: CascPort.h:139
LPBYTE pbBufferBegin
Definition: DumpContext.h:24
bool FileStream_Write(TFileStream *pStream, ULONGLONG *pByteOffset, const void *pvBuffer, DWORD dwBytesToWrite)
Definition: FileStream.cpp:2577
TFileStream * pStream
Definition: DumpContext.h:23

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int dump_print ( TDumpContext dc,
const char *  szFormat,
  ... 
)
102 {
103  va_list argList;
104  char szBuffer[0x200];
105  int nLength = 0;
106 
107  // Only if the dump context is valid
108  if(dc != NULL)
109  {
110  // Print the buffer using sprintf
111  va_start(argList, szFormat);
112  nLength = vsprintf(szBuffer, szFormat, argList);
113  assert(nLength < 0x200);
114  va_end(argList);
115 
116  // Copy the string. Replace "\n" with "\n\r"
117  for(int i = 0; i < nLength; i++)
118  {
119  // Flush the buffer, if needed
120  if((dc->pbBufferPtr + 2) >= dc->pbBufferEnd)
121  {
123  dc->pbBufferPtr = dc->pbBufferBegin;
124  }
125 
126  // Copy the char
127  if(szBuffer[i] == 0x0A)
128  *dc->pbBufferPtr++ = 0x0D;
129  *dc->pbBufferPtr++ = szBuffer[i];
130  }
131  }
132 
133  return nLength;
134 }
LPBYTE pbBufferPtr
Definition: DumpContext.h:25
arena_t NULL
Definition: jemalloc_internal.h:624
LPBYTE pbBufferEnd
Definition: DumpContext.h:26
unsigned int DWORD
Definition: CascPort.h:139
LPBYTE pbBufferBegin
Definition: DumpContext.h:24
bool FileStream_Write(TFileStream *pStream, ULONGLONG *pByteOffset, const void *pvBuffer, DWORD dwBytesToWrite)
Definition: FileStream.cpp:2577
TFileStream * pStream
Definition: DumpContext.h:23

+ Here is the call graph for this function:

static TCHAR* FormatFileName ( TCascStorage hs,
const TCHAR szNameFormat 
)
static
19 {
20  TCHAR * szFileName;
21  TCHAR * szSrc;
22  TCHAR * szTrg;
23 
24  // Create copy of the file name
25  szFileName = szSrc = szTrg = CascNewStr(szNameFormat, 0);
26  if(szFileName != NULL)
27  {
28  // Format the file name
29  while(szSrc[0] != 0)
30  {
31  if(szSrc[0] == _T('%'))
32  {
33  // Replace "%build%" with a build number
34  if(!_tcsncmp(szSrc, _T("%build%"), 7))
35  {
36  szTrg += _stprintf(szTrg, _T("%u"), hs->dwBuildNumber);
37  szSrc += 7;
38  continue;
39  }
40  }
41 
42  // Just copy the character
43  *szTrg++ = *szSrc++;
44  }
45 
46  // Terminate the target file name
47  szTrg[0] = 0;
48  }
49 
50  return szFileName;
51 }
arena_t NULL
Definition: jemalloc_internal.h:624
char TCHAR
Definition: CascPort.h:148
#define _T(x)
Definition: CascPort.h:171
#define _tcsncmp
Definition: CascPort.h:179
#define _stprintf
Definition: CascPort.h:181
char * CascNewStr(const char *szString, size_t nCharsToReserve)
Definition: Common.cpp:102
DWORD dwBuildNumber
Definition: CascCommon.h:197

+ Here is the call graph for this function:

+ Here is the caller graph for this function: