ReactOS 0.4.16-dev-2332-g4cba65d
ftdebug.c
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * ftdebug.c
4 *
5 * Debugging and logging component for Win32 (body).
6 *
7 * Copyright (C) 1996-2020 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
9 *
10 * This file is part of the FreeType project, and may only be used,
11 * modified, and distributed under the terms of the FreeType project
12 * license, LICENSE.TXT. By continuing to use, modify, or distribute
13 * this file you indicate that you have read the license and
14 * understand and accept it fully.
15 *
16 */
17
18
19 /**************************************************************************
20 *
21 * This component contains various macros and functions used to ease the
22 * debugging of the FreeType engine. Its main purpose is in assertion
23 * checking, tracing, and error detection.
24 *
25 * There are now three debugging modes:
26 *
27 * - trace mode
28 *
29 * Error and trace messages are sent to the log file (which can be the
30 * standard error output).
31 *
32 * - error mode
33 *
34 * Only error messages are generated.
35 *
36 * - release mode:
37 *
38 * No error message is sent or generated. The code is free from any
39 * debugging parts.
40 *
41 */
42
43
44#include <freetype/freetype.h>
46
47
48#ifdef FT_DEBUG_LEVEL_ERROR
49
50#include <stdarg.h>
51#include <stdlib.h>
52#include <string.h>
53
54#ifndef __REACTOS__
55#include <windows.h>
56#endif
57
58 /* documentation is in ftdebug.h */
59
60#ifndef __REACTOS__ /* win32ss/drivers/font/ftfd/rosglue.c defines this */
61 FT_BASE_DEF( void )
62 FT_Message( const char* fmt,
63 ... )
64 {
65 static char buf[8192];
66 va_list ap;
67
68
69 va_start( ap, fmt );
70 vfprintf( stderr, fmt, ap );
71 /* send the string to the debugger as well */
72 vsprintf( buf, fmt, ap );
74 va_end( ap );
75 }
76#endif
77
78 /* documentation is in ftdebug.h */
79
80#ifndef __REACTOS__ /* win32ss/drivers/font/ftfd/rosglue.c defines this */
81 FT_BASE_DEF( void )
82 FT_Panic( const char* fmt,
83 ... )
84 {
85 static char buf[8192];
86 va_list ap;
87
88
89 va_start( ap, fmt );
90 vsprintf( buf, fmt, ap );
92 va_end( ap );
93
95 }
96#endif
97
98 /* documentation is in ftdebug.h */
99
100 FT_BASE_DEF( int )
101 FT_Throw( FT_Error error,
102 int line,
103 const char* file )
104 {
105#if 0
106 /* activating the code in this block makes FreeType very chatty */
108 "%s:%d: error 0x%02x: %s\n",
109 file,
110 line,
111 error,
113#else
114 FT_UNUSED( error );
115 FT_UNUSED( line );
116 FT_UNUSED( file );
117#endif
118
119 return 0;
120 }
121
122#endif /* FT_DEBUG_LEVEL_ERROR */
123
124
125#ifdef FT_DEBUG_LEVEL_TRACE
126
127 /* array of trace levels, initialized to 0; */
128 /* this gets adjusted at run-time */
129 static int ft_trace_levels_enabled[trace_count];
130
131 /* array of trace levels, always initialized to 0 */
132 static int ft_trace_levels_disabled[trace_count];
133
134 /* a pointer to either `ft_trace_levels_enabled' */
135 /* or `ft_trace_levels_disabled' */
136 int* ft_trace_levels;
137
138 /* define array of trace toggle names */
139#define FT_TRACE_DEF( x ) #x ,
140
141 static const char* ft_trace_toggles[trace_count + 1] =
142 {
144 NULL
145 };
146
147#undef FT_TRACE_DEF
148
149
150 /* documentation is in ftdebug.h */
151
153 FT_Trace_Get_Count( void )
154 {
155 return trace_count;
156 }
157
158
159 /* documentation is in ftdebug.h */
160
161 FT_BASE_DEF( const char * )
163 {
164 int max = FT_Trace_Get_Count();
165
166
167 if ( idx < max )
168 return ft_trace_toggles[idx];
169 else
170 return NULL;
171 }
172
173
174 /* documentation is in ftdebug.h */
175
176 FT_BASE_DEF( void )
177 FT_Trace_Disable( void )
178 {
179 ft_trace_levels = ft_trace_levels_disabled;
180 }
181
182
183 /* documentation is in ftdebug.h */
184
185 FT_BASE_DEF( void )
186 FT_Trace_Enable( void )
187 {
188 ft_trace_levels = ft_trace_levels_enabled;
189 }
190
191
192 /**************************************************************************
193 *
194 * Initialize the tracing sub-system. This is done by retrieving the
195 * value of the `FT2_DEBUG' environment variable. It must be a list of
196 * toggles, separated by spaces, `;', or `,'. Example:
197 *
198 * export FT2_DEBUG="any:3 memory:7 stream:5"
199 *
200 * This requests that all levels be set to 3, except the trace level for
201 * the memory and stream components which are set to 7 and 5,
202 * respectively.
203 *
204 * See the file `include/freetype/internal/fttrace.h' for details of
205 * the available toggle names.
206 *
207 * The level must be between 0 and 7; 0 means quiet (except for serious
208 * runtime errors), and 7 means _very_ verbose.
209 */
210 FT_BASE_DEF( void )
211 ft_debug_init( void )
212 {
213 const char* ft2_debug = getenv( "FT2_DEBUG" );
214
215
216 if ( ft2_debug )
217 {
218 const char* p = ft2_debug;
219 const char* q;
220
221
222 for ( ; *p; p++ )
223 {
224 /* skip leading whitespace and separators */
225 if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' )
226 continue;
227
228 /* read toggle name, followed by ':' */
229 q = p;
230 while ( *p && *p != ':' )
231 p++;
232
233 if ( !*p )
234 break;
235
236 if ( *p == ':' && p > q )
237 {
238 FT_Int n, i, len = (FT_Int)( p - q );
239 FT_Int level = -1, found = -1;
240
241
242 for ( n = 0; n < trace_count; n++ )
243 {
244 const char* toggle = ft_trace_toggles[n];
245
246
247 for ( i = 0; i < len; i++ )
248 {
249 if ( toggle[i] != q[i] )
250 break;
251 }
252
253 if ( i == len && toggle[i] == 0 )
254 {
255 found = n;
256 break;
257 }
258 }
259
260 /* read level */
261 p++;
262 if ( *p )
263 {
264 level = *p - '0';
265 if ( level < 0 || level > 7 )
266 level = -1;
267 }
268
269 if ( found >= 0 && level >= 0 )
270 {
271 if ( found == trace_any )
272 {
273 /* special case for `any' */
274 for ( n = 0; n < trace_count; n++ )
275 ft_trace_levels_enabled[n] = level;
276 }
277 else
278 ft_trace_levels_enabled[found] = level;
279 }
280 }
281 }
282 }
283
284 ft_trace_levels = ft_trace_levels_enabled;
285 }
286
287
288#else /* !FT_DEBUG_LEVEL_TRACE */
289
290
291 FT_BASE_DEF( void )
293 {
294 /* nothing */
295 }
296
297
300 {
301 return 0;
302 }
303
304
305 FT_BASE_DEF( const char * )
307 {
308 FT_UNUSED( idx );
309
310 return NULL;
311 }
312
313
314 FT_BASE_DEF( void )
316 {
317 /* nothing */
318 }
319
320
321 /* documentation is in ftdebug.h */
322
323 FT_BASE_DEF( void )
325 {
326 /* nothing */
327 }
328
329
330#endif /* !FT_DEBUG_LEVEL_TRACE */
331
332
333/* END */
#define FT_BASE_DEF(x)
#define NULL
Definition: types.h:112
unsigned int idx
Definition: utils.c:41
char *CDECL getenv(const char *name)
Definition: environ.c:227
int WINAPIV fprintf(FILE *file, const char *format,...)
Definition: file.c:5549
int CDECL vfprintf(FILE *file, const char *format, va_list valist)
Definition: file.c:5349
#define stderr
#define va_end(v)
Definition: stdarg.h:28
#define va_start(v, l)
Definition: stdarg.h:26
_ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl vsprintf(char *, const char *, va_list) __WINE_CRT_PRINTF_ATTR(2
char * va_list
Definition: vadefs.h:50
void FT_Panic(const char *format,...)
Definition: rosglue.c:27
FT_Trace_Get_Name(FT_Int idx)
Definition: ftdebug.c:306
FT_Trace_Get_Count(void)
Definition: ftdebug.c:299
FT_Trace_Disable(void)
Definition: ftdebug.c:315
ft_debug_init(void)
Definition: ftdebug.c:292
FT_Trace_Enable(void)
Definition: ftdebug.c:324
FT_BEGIN_HEADER FT_Error_String(FT_Error error_code)
Definition: fterrors.c:26
void FT_Message(const char *format,...)
Definition: rosglue.c:16
int FT_Error
Definition: fttypes.h:299
signed int FT_Int
Definition: fttypes.h:220
GLint level
Definition: gl.h:1546
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLdouble n
Definition: glext.h:7729
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
void WINAPI SHIM_OBJ_NAME() OutputDebugStringA(LPCSTR lpOutputString)
Definition: ignoredbgout.c:18
#define EXIT_FAILURE
Definition: jerror.c:33
#define error(str)
Definition: mkdosfs.c:1605
#define FT_UNUSED(arg)
#define exit(n)
Definition: config.h:202
Definition: fci.c:127
Definition: dsound.c:943
Definition: parser.c:49
#define max(a, b)
Definition: svc.c:63
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36