1 /****************************************************************************
5 * Debugging and logging component for WinCE (body).
7 * Copyright (C) 1996-2023 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
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.
19 /**************************************************************************
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.
25 * There are now three debugging modes:
29 * Error and trace messages are sent to the log file (which can be the
30 * standard error output).
34 * Only error messages are generated.
38 * No error message is sent or generated. The code is free from any
44 #include <freetype/freetype.h>
45 #include <freetype/internal/ftdebug.h>
48 #ifdef FT_DEBUG_LEVEL_ERROR
58 OutputDebugStringEx( const char* str )
60 static WCHAR buf[8192];
62 int sz = MultiByteToWideChar( CP_ACP, 0, str, -1, buf,
63 sizeof ( buf ) / sizeof ( *buf ) );
67 lstrcpyW( buf, L"OutputDebugStringEx: MultiByteToWideChar failed" );
69 OutputDebugStringW( buf );
73 /* documentation is in ftdebug.h */
76 FT_Message( const char* fmt,
79 static char buf[8192];
84 vfprintf( stderr, fmt, ap );
85 /* send the string to the debugger as well */
86 vsprintf( buf, fmt, ap );
87 OutputDebugStringEx( buf );
92 /* documentation is in ftdebug.h */
95 FT_Panic( const char* fmt,
98 static char buf[8192];
103 vsprintf( buf, fmt, ap );
104 OutputDebugStringEx( buf );
107 exit( EXIT_FAILURE );
111 /* documentation is in ftdebug.h */
114 FT_Throw( FT_Error error,
119 /* activating the code in this block makes FreeType very chatty */
121 "%s:%d: error 0x%02x: %s\n",
125 FT_Error_String( error ) );
135 #endif /* FT_DEBUG_LEVEL_ERROR */
138 #ifdef FT_DEBUG_LEVEL_TRACE
140 /* array of trace levels, initialized to 0; */
141 /* this gets adjusted at run-time */
142 static int ft_trace_levels_enabled[trace_count];
144 /* array of trace levels, always initialized to 0 */
145 static int ft_trace_levels_disabled[trace_count];
147 /* a pointer to either `ft_trace_levels_enabled' */
148 /* or `ft_trace_levels_disabled' */
149 int* ft_trace_levels;
151 /* define array of trace toggle names */
152 #define FT_TRACE_DEF( x ) #x ,
154 static const char* ft_trace_toggles[trace_count + 1] =
156 #include <freetype/internal/fttrace.h>
163 /* documentation is in ftdebug.h */
165 FT_BASE_DEF( FT_Int )
166 FT_Trace_Get_Count( void )
172 /* documentation is in ftdebug.h */
174 FT_BASE_DEF( const char * )
175 FT_Trace_Get_Name( FT_Int idx )
177 int max = FT_Trace_Get_Count();
181 return ft_trace_toggles[idx];
187 /* documentation is in ftdebug.h */
190 FT_Trace_Disable( void )
192 ft_trace_levels = ft_trace_levels_disabled;
196 /* documentation is in ftdebug.h */
199 FT_Trace_Enable( void )
201 ft_trace_levels = ft_trace_levels_enabled;
205 /**************************************************************************
207 * Initialize the tracing sub-system. This is done by retrieving the
208 * value of the `FT2_DEBUG' environment variable. It must be a list of
209 * toggles, separated by spaces, `;', or `,'. Example:
211 * export FT2_DEBUG="any:3 memory:7 stream:5"
213 * This requests that all levels be set to 3, except the trace level for
214 * the memory and stream components which are set to 7 and 5,
217 * See the file `include/freetype/internal/fttrace.h' for details of
218 * the available toggle names.
220 * The level must be between 0 and 7; 0 means quiet (except for serious
221 * runtime errors), and 7 means _very_ verbose.
224 ft_debug_init( void )
226 /* Windows Mobile doesn't have environment API: */
227 /* GetEnvironmentStrings, GetEnvironmentVariable, getenv. */
229 /* FIXME!!! How to set debug mode? */
231 /* const char* ft2_debug = getenv( "FT2_DEBUG" ); */
233 const char* ft2_debug = NULL;
238 const char* p = ft2_debug;
244 /* skip leading whitespace and separators */
245 if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' )
248 /* read toggle name, followed by ':' */
250 while ( *p && *p != ':' )
256 if ( *p == ':' && p > q )
258 FT_Int n, i, len = (FT_Int)( p - q );
259 FT_Int level = -1, found = -1;
262 for ( n = 0; n < trace_count; n++ )
264 const char* toggle = ft_trace_toggles[n];
267 for ( i = 0; i < len; i++ )
269 if ( toggle[i] != q[i] )
273 if ( i == len && toggle[i] == 0 )
285 if ( level < 0 || level > 7 )
289 if ( found >= 0 && level >= 0 )
291 if ( found == trace_any )
293 /* special case for `any' */
294 for ( n = 0; n < trace_count; n++ )
295 ft_trace_levels_enabled[n] = level;
298 ft_trace_levels_enabled[found] = level;
304 ft_trace_levels = ft_trace_levels_enabled;
308 #else /* !FT_DEBUG_LEVEL_TRACE */
312 ft_debug_init( void )
318 FT_BASE_DEF( FT_Int )
319 FT_Trace_Get_Count( void )
325 FT_BASE_DEF( const char * )
326 FT_Trace_Get_Name( FT_Int idx )
335 FT_Trace_Disable( void )
341 /* documentation is in ftdebug.h */
344 FT_Trace_Enable( void )
350 #endif /* !FT_DEBUG_LEVEL_TRACE */