Mercurial > projects > hoofbaby
comparison deps/Platinum/ThirdParty/Neptune/Source/System/Win32/NptWin32Debug.cpp @ 0:3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
author | fraserofthenight |
---|---|
date | Mon, 06 Jul 2009 08:06:28 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3425707ddbf6 |
---|---|
1 /***************************************************************** | |
2 | | |
3 | Neptune - Debug Support: Win32 Implementation | |
4 | | |
5 | (c) 2002-2006 Gilles Boccon-Gibod | |
6 | Author: Gilles Boccon-Gibod (bok@bok.net) | |
7 | | |
8 ****************************************************************/ | |
9 | |
10 /*---------------------------------------------------------------------- | |
11 | includes | |
12 +---------------------------------------------------------------------*/ | |
13 #include <stdarg.h> | |
14 #include <stdio.h> | |
15 #if defined(_XBOX) | |
16 #include <xtl.h> | |
17 #else | |
18 #include <windows.h> | |
19 #endif | |
20 | |
21 #include "NptConfig.h" | |
22 #include "NptDefs.h" | |
23 #include "NptTypes.h" | |
24 #include "NptDebug.h" | |
25 #include "NptLogging.h" | |
26 | |
27 /*---------------------------------------------------------------------- | |
28 | constants | |
29 +---------------------------------------------------------------------*/ | |
30 #define NPT_DEBUG_LOCAL_BUFFER_SIZE 1024 | |
31 #define NPT_DEBUG_BUFFER_INCREMENT 4096 | |
32 #define NPT_DEBUG_BUFFER_MAX_SIZE 65536 | |
33 | |
34 #if defined(NPT_CONFIG_ENABLE_LOGGING) | |
35 /*---------------------------------------------------------------------- | |
36 | logging | |
37 +---------------------------------------------------------------------*/ | |
38 NPT_SET_LOCAL_LOGGER("neptune,debug.win32") | |
39 | |
40 /*---------------------------------------------------------------------- | |
41 | NPT_Print | |
42 +---------------------------------------------------------------------*/ | |
43 static void | |
44 NPT_Print(const char* message) | |
45 { | |
46 #if !defined(_WIN32_WCE) | |
47 OutputDebugString(message); | |
48 #endif | |
49 NPT_LOG_FINER_1("%s", message); | |
50 } | |
51 #elif defined(NPT_DEBUG) | |
52 /*---------------------------------------------------------------------- | |
53 | NPT_Print | |
54 +---------------------------------------------------------------------*/ | |
55 static void | |
56 NPT_Print(const char* message) | |
57 { | |
58 #if !defined(_WIN32_WCE) | |
59 OutputDebugString(message); | |
60 #endif | |
61 printf("%s", message); | |
62 } | |
63 #endif | |
64 | |
65 /*---------------------------------------------------------------------- | |
66 | NPT_Debug | |
67 +---------------------------------------------------------------------*/ | |
68 void | |
69 NPT_Debug(const char* format, ...) | |
70 { | |
71 #if defined(NPT_DEBUG) || defined(NPT_CONFIG_ENABLE_LOGGING) | |
72 char local_buffer[NPT_DEBUG_LOCAL_BUFFER_SIZE]; | |
73 unsigned int buffer_size = NPT_DEBUG_LOCAL_BUFFER_SIZE; | |
74 char* buffer = local_buffer; | |
75 va_list args; | |
76 | |
77 va_start(args, format); | |
78 | |
79 for(;;) { | |
80 int result; | |
81 | |
82 /* try to format the message (it might not fit) */ | |
83 #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(_WIN32_WCE) | |
84 /* use the secure function for VC 8 and above */ | |
85 result = _vsnprintf_s(buffer, buffer_size, _TRUNCATE, format, args); | |
86 #else | |
87 result = _vsnprintf(buffer, buffer_size-1, format, args); | |
88 #endif | |
89 buffer[buffer_size-1] = 0; /* force a NULL termination */ | |
90 if (result >= 0) break; | |
91 | |
92 /* the buffer was too small, try something bigger */ | |
93 buffer_size = (buffer_size+NPT_DEBUG_BUFFER_INCREMENT)*2; | |
94 if (buffer_size > NPT_DEBUG_BUFFER_MAX_SIZE) break; | |
95 if (buffer != local_buffer) delete[] buffer; | |
96 buffer = new char[buffer_size]; | |
97 if (buffer == NULL) return; | |
98 } | |
99 | |
100 NPT_Print(buffer); | |
101 if (buffer != local_buffer) delete[] buffer; | |
102 | |
103 va_end(args); | |
104 #else | |
105 NPT_COMPILER_UNUSED(format); | |
106 #endif | |
107 } |