ReactOS 0.4.16-dev-981-g80eb313
ftdebug.c
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * ftdebug.c
4 *
5 * Debugging and logging component (body).
6 *
7 * Copyright (C) 1996-2019 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 <ft2build.h>
45#include FT_FREETYPE_H
46#include FT_INTERNAL_DEBUG_H
47
48
49#ifdef FT_DEBUG_LEVEL_ERROR
50
51 /* documentation is in ftdebug.h */
52
53#ifndef __REACTOS__ /* win32ss/drivers/font/ftfd/rosglue.c defines this */
54 FT_BASE_DEF( void )
55 FT_Message( const char* fmt,
56 ... )
57 {
58 va_list ap;
59
60
61 va_start( ap, fmt );
62 vfprintf( stderr, fmt, ap );
63 va_end( ap );
64 }
65#endif
66
67
68 /* documentation is in ftdebug.h */
69
70#ifndef __REACTOS__ /* win32ss/drivers/font/ftfd/rosglue.c defines this */
71 FT_BASE_DEF( void )
72 FT_Panic( const char* fmt,
73 ... )
74 {
75 va_list ap;
76
77
78 va_start( ap, fmt );
79 vfprintf( stderr, fmt, ap );
80 va_end( ap );
81
83 }
84#endif
85
86
87 /* documentation is in ftdebug.h */
88
89 FT_BASE_DEF( int )
90 FT_Throw( FT_Error error,
91 int line,
92 const char* file )
93 {
94#if 0
95 /* activating the code in this block makes FreeType very chatty */
97 "%s:%d: error 0x%02x: %s\n",
98 file,
99 line,
100 error,
102#else
103 FT_UNUSED( error );
104 FT_UNUSED( line );
105 FT_UNUSED( file );
106#endif
107
108 return 0;
109 }
110
111#endif /* FT_DEBUG_LEVEL_ERROR */
112
113
114
115#ifdef FT_DEBUG_LEVEL_TRACE
116
117 /* array of trace levels, initialized to 0; */
118 /* this gets adjusted at run-time */
119 static int ft_trace_levels_enabled[trace_count];
120
121 /* array of trace levels, always initialized to 0 */
122 static int ft_trace_levels_disabled[trace_count];
123
124 /* a pointer to either `ft_trace_levels_enabled' */
125 /* or `ft_trace_levels_disabled' */
126 int* ft_trace_levels;
127
128 /* define array of trace toggle names */
129#define FT_TRACE_DEF( x ) #x ,
130
131 static const char* ft_trace_toggles[trace_count + 1] =
132 {
133#include FT_INTERNAL_TRACE_H
134 NULL
135 };
136
137#undef FT_TRACE_DEF
138
139
140 /* documentation is in ftdebug.h */
141
143 FT_Trace_Get_Count( void )
144 {
145 return trace_count;
146 }
147
148
149 /* documentation is in ftdebug.h */
150
151 FT_BASE_DEF( const char * )
153 {
154 int max = FT_Trace_Get_Count();
155
156
157 if ( idx < max )
158 return ft_trace_toggles[idx];
159 else
160 return NULL;
161 }
162
163
164 /* documentation is in ftdebug.h */
165
166 FT_BASE_DEF( void )
167 FT_Trace_Disable( void )
168 {
169 ft_trace_levels = ft_trace_levels_disabled;
170 }
171
172
173 /* documentation is in ftdebug.h */
174
175 FT_BASE_DEF( void )
176 FT_Trace_Enable( void )
177 {
178 ft_trace_levels = ft_trace_levels_enabled;
179 }
180
181
182 /**************************************************************************
183 *
184 * Initialize the tracing sub-system. This is done by retrieving the
185 * value of the `FT2_DEBUG' environment variable. It must be a list of
186 * toggles, separated by spaces, `;', or `,'. Example:
187 *
188 * export FT2_DEBUG="any:3 memory:7 stream:5"
189 *
190 * This requests that all levels be set to 3, except the trace level for
191 * the memory and stream components which are set to 7 and 5,
192 * respectively.
193 *
194 * See the file `include/freetype/internal/fttrace.h' for details of
195 * the available toggle names.
196 *
197 * The level must be between 0 and 7; 0 means quiet (except for serious
198 * runtime errors), and 7 means _very_ verbose.
199 */
200 FT_BASE_DEF( void )
201 ft_debug_init( void )
202 {
203 const char* ft2_debug = ft_getenv( "FT2_DEBUG" );
204
205
206 if ( ft2_debug )
207 {
208 const char* p = ft2_debug;
209 const char* q;
210
211
212 for ( ; *p; p++ )
213 {
214 /* skip leading whitespace and separators */
215 if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' )
216 continue;
217
218 /* read toggle name, followed by ':' */
219 q = p;
220 while ( *p && *p != ':' )
221 p++;
222
223 if ( !*p )
224 break;
225
226 if ( *p == ':' && p > q )
227 {
228 FT_Int n, i, len = (FT_Int)( p - q );
229 FT_Int level = -1, found = -1;
230
231
232 for ( n = 0; n < trace_count; n++ )
233 {
234 const char* toggle = ft_trace_toggles[n];
235
236
237 for ( i = 0; i < len; i++ )
238 {
239 if ( toggle[i] != q[i] )
240 break;
241 }
242
243 if ( i == len && toggle[i] == 0 )
244 {
245 found = n;
246 break;
247 }
248 }
249
250 /* read level */
251 p++;
252 if ( *p )
253 {
254 level = *p - '0';
255 if ( level < 0 || level > 7 )
256 level = -1;
257 }
258
259 if ( found >= 0 && level >= 0 )
260 {
261 if ( found == trace_any )
262 {
263 /* special case for `any' */
264 for ( n = 0; n < trace_count; n++ )
265 ft_trace_levels_enabled[n] = level;
266 }
267 else
268 ft_trace_levels_enabled[found] = level;
269 }
270 }
271 }
272 }
273
274 ft_trace_levels = ft_trace_levels_enabled;
275 }
276
277
278#else /* !FT_DEBUG_LEVEL_TRACE */
279
280
281 FT_BASE_DEF( void )
283 {
284 /* nothing */
285 }
286
287
290 {
291 return 0;
292 }
293
294
295 FT_BASE_DEF( const char * )
297 {
298 FT_UNUSED( idx );
299
300 return NULL;
301 }
302
303
304 FT_BASE_DEF( void )
306 {
307 /* nothing */
308 }
309
310
311 /* documentation is in ftdebug.h */
312
313 FT_BASE_DEF( void )
315 {
316 /* nothing */
317 }
318
319
320#endif /* !FT_DEBUG_LEVEL_TRACE */
321
322
323/* END */
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define NULL
Definition: types.h:112
unsigned int idx
Definition: utils.c:41
void FT_Panic(const char *format,...)
Definition: rosglue.c:27
#define FT_UNUSED(arg)
Definition: ftconfig.h:100
#define FT_BASE_DEF(x)
Definition: ftconfig.h:418
FT_Trace_Get_Name(FT_Int idx)
Definition: ftdebug.c:296
FT_Trace_Get_Count(void)
Definition: ftdebug.c:289
FT_Trace_Disable(void)
Definition: ftdebug.c:305
ft_debug_init(void)
Definition: ftdebug.c:282
FT_Trace_Enable(void)
Definition: ftdebug.c:314
FT_Error_String(FT_Error error_code)
Definition: fterrors.c:26
void FT_Message(const char *format,...)
Definition: rosglue.c:16
#define ft_getenv
Definition: ftstdlib.h:146
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
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
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_opt_ _CRTIMP int __cdecl vfprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
#define EXIT_FAILURE
Definition: jerror.c:33
#define error(str)
Definition: mkdosfs.c:1605
#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