-
Notifications
You must be signed in to change notification settings - Fork 27
/
debugprint.cpp
131 lines (118 loc) · 3.41 KB
/
debugprint.cpp
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
//////////////////////////////////////////////////////////////////////
// Yet Another Tibia Client
//////////////////////////////////////////////////////////////////////
// Debug output functions
//////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//////////////////////////////////////////////////////////////////////
#ifdef WIN32
#ifndef WINCE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <wincon.h>
#else
#include <windows.h>
#endif
#endif
#include <stdio.h>
#include <stdarg.h>
#include "debugprint.h"
#include "util.h"
#if USE_OPENGL
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#if defined(WIN32) && defined(GREMDEY)
#include <GL/GRemdeyExtensions.h>
extern PFNGLSTRINGMARKERGREMEDYPROC glStringMarkerGREMEDY;
#endif
#endif
#ifndef DEBUGLEVEL_BUILDTIME
#ifndef _MSC_VER
#warning You should define DEBUGLEVEL_BUILDTIME in compiler options.
#else
#pragma warning(You should define DEBUGLEVEL_BUILDTIME in compiler options.)
#endif
#define DEBUGLEVEL_BUILDTIME 0
#endif
char debuglevel=DEBUGLEVEL_BUILDTIME;
std::string DEBUG_FILE; int DEBUG_LINE;
void DEBUGPRINTx (char msgdebuglevel, char type, const char* txt, ...)
{
va_list vl;
va_start(vl, txt);
if(msgdebuglevel <= debuglevel){
char tx[6000];
#ifndef _MSC_VER
vsnprintf(tx, 6000, txt, vl);
#else
vsprintf(tx, txt, vl);
#endif
#if defined(WIN32) && !defined(WINCE)
HANDLE con = GetStdHandle(STD_OUTPUT_HANDLE);
#endif
#ifdef WINCE
FILE *lf = yatc_fopen("log.txt", "a");
#endif
if (msgdebuglevel < 0) {
printf("<*!*> ");
}
switch (type) {
default:
printf("%s", tx);
#ifdef WINCE
fprintf(lf, "%s", tx);
#endif
break;
case DEBUGPRINT_ERROR:
#if defined(WIN32) && !defined(WINCE)
SetConsoleTextAttribute(con, FOREGROUND_RED | FOREGROUND_INTENSITY);
#endif
printf("[E] %s", tx);
#ifdef WINCE
fprintf(lf, "[E] %s", tx);
#endif
#if defined(WIN32) && !defined(WINCE)
SetConsoleTextAttribute(con, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
#endif
break;
case DEBUGPRINT_WARNING:
#if defined(WIN32) && !defined(WINCE)
SetConsoleTextAttribute(con, FOREGROUND_RED | FOREGROUND_GREEN);
#endif
printf("[W] %s", tx);
#ifdef WINCE
fprintf(lf, "[W] %s", tx);
#endif
#if defined(WIN32) && !defined(WINCE)
SetConsoleTextAttribute(con, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
#endif
break;
}
#ifdef WINCE
fclose(lf);
#endif
}
va_end(vl);
}
void DEBUGMARKER (unsigned int size, const char *val)
{
#if defined(WIN32) && defined(GREMDEY)
if(glStringMarkerGREMEDY)
glStringMarkerGREMEDY(size, val);
#endif
}