1 /***************************************************************************/
5 /* Debugging and logging component for Win32 (body). */
7 /* Copyright 1996-2002, 2005, 2008, 2009, 2013 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. */
16 /***************************************************************************/
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 */
39 /* debugging parts. */
41 /*************************************************************************/
45 #include FT_INTERNAL_DEBUG_H
48 #ifdef FT_DEBUG_LEVEL_ERROR
57 /* documentation is in ftdebug.h */
60 FT_Message( const char* fmt,
63 static char buf[8192];
69 /* send the string to the debugger as well */
70 vsprintf( buf, fmt, ap );
71 OutputDebugStringA( buf );
76 /* documentation is in ftdebug.h */
79 FT_Panic( const char* fmt,
82 static char buf[8192];
87 vsprintf( buf, fmt, ap );
88 OutputDebugStringA( buf );
95 /* documentation is in ftdebug.h */
98 FT_Throw( FT_Error error,
110 #ifdef FT_DEBUG_LEVEL_TRACE
113 /* array of trace levels, initialized to 0 */
114 int ft_trace_levels[trace_count];
116 /* define array of trace toggle names */
117 #define FT_TRACE_DEF( x ) #x ,
119 static const char* ft_trace_toggles[trace_count + 1] =
121 #include FT_INTERNAL_TRACE_H
128 /*************************************************************************/
130 /* Initialize the tracing sub-system. This is done by retrieving the */
131 /* value of the "FT2_DEBUG" environment variable. It must be a list of */
132 /* toggles, separated by spaces, `;' or `,'. Example: */
134 /* "any:3 memory:6 stream:5" */
136 /* This will request that all levels be set to 3, except the trace level */
137 /* for the memory and stream components which are set to 6 and 5, */
140 /* See the file <internal/fttrace.h> for details of the available toggle */
143 /* The level must be between 0 and 6; 0 means quiet (except for serious */
144 /* runtime errors), and 6 means _very_ verbose. */
147 ft_debug_init( void )
149 const char* ft2_debug = getenv( "FT2_DEBUG" );
154 const char* p = ft2_debug;
160 /* skip leading whitespace and separators */
161 if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' )
164 /* read toggle name, followed by ':' */
166 while ( *p && *p != ':' )
172 if ( *p == ':' && p > q )
174 int n, i, len = (int)( p - q );
175 int level = -1, found = -1;
178 for ( n = 0; n < trace_count; n++ )
180 const char* toggle = ft_trace_toggles[n];
183 for ( i = 0; i < len; i++ )
185 if ( toggle[i] != q[i] )
189 if ( i == len && toggle[i] == 0 )
201 if ( level < 0 || level > 7 )
205 if ( found >= 0 && level >= 0 )
207 if ( found == trace_any )
209 /* special case for "any" */
210 for ( n = 0; n < trace_count; n++ )
211 ft_trace_levels[n] = level;
214 ft_trace_levels[found] = level;
222 #else /* !FT_DEBUG_LEVEL_TRACE */
226 ft_debug_init( void )
232 #endif /* !FT_DEBUG_LEVEL_TRACE */
234 #endif /* FT_DEBUG_LEVEL_ERROR */