Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / modules / freetype2 / builds / win32 / ftdebug.c
blob8f7a9ab07d96a1bf18687b1e7a5b0a52afc2d465
1 /***************************************************************************/
2 /* */
3 /* ftdebug.c */
4 /* */
5 /* Debugging and logging component for Win32 (body). */
6 /* */
7 /* Copyright 1996-2001, 2002, 2005, 2008 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 /***************************************************************************/
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 /*************************************************************************/
44 #include <ft2build.h>
45 #include FT_INTERNAL_DEBUG_H
48 #ifdef FT_DEBUG_LEVEL_ERROR
51 #include <stdarg.h>
52 #include <stdlib.h>
53 #include <string.h>
55 #include <windows.h>
58 #ifdef _WIN32_WCE
60 void
61 OutputDebugStringEx( const char* str )
63 static WCHAR buf[8192];
66 int sz = MultiByteToWideChar( CP_ACP, 0, str, -1, buf,
67 sizeof ( buf ) / sizeof ( *buf ) );
68 if ( !sz )
69 lstrcpyW( buf, L"OutputDebugStringEx: MultiByteToWideChar failed" );
71 OutputDebugStringW( buf );
74 #else
76 #define OutputDebugStringEx OutputDebugStringA
78 #endif
81 FT_BASE_DEF( void )
82 FT_Message( const char* fmt, ... )
84 static char buf[8192];
85 va_list ap;
88 va_start( ap, fmt );
89 vprintf( fmt, ap );
90 /* send the string to the debugger as well */
91 vsprintf( buf, fmt, ap );
92 OutputDebugStringEx( buf );
93 va_end( ap );
97 FT_BASE_DEF( void )
98 FT_Panic( const char* fmt, ... )
100 static char buf[8192];
101 va_list ap;
104 va_start( ap, fmt );
105 vsprintf( buf, fmt, ap );
106 OutputDebugStringEx( buf );
107 va_end( ap );
109 exit( EXIT_FAILURE );
113 #ifdef FT_DEBUG_LEVEL_TRACE
116 /* array of trace levels, initialized to 0 */
117 int ft_trace_levels[trace_count];
119 /* define array of trace toggle names */
120 #define FT_TRACE_DEF( x ) #x ,
122 static const char* ft_trace_toggles[trace_count + 1] =
124 #include FT_INTERNAL_TRACE_H
125 NULL
128 #undef FT_TRACE_DEF
131 /*************************************************************************/
132 /* */
133 /* Initialize the tracing sub-system. This is done by retrieving the */
134 /* value of the "FT2_DEBUG" environment variable. It must be a list of */
135 /* toggles, separated by spaces, `;' or `,'. Example: */
136 /* */
137 /* "any:3 memory:6 stream:5" */
138 /* */
139 /* This will request that all levels be set to 3, except the trace level */
140 /* for the memory and stream components which are set to 6 and 5, */
141 /* respectively. */
142 /* */
143 /* See the file <freetype/internal/fttrace.h> for details of the */
144 /* available toggle names. */
145 /* */
146 /* The level must be between 0 and 6; 0 means quiet (except for serious */
147 /* runtime errors), and 6 means _very_ verbose. */
148 /* */
149 FT_BASE_DEF( void )
150 ft_debug_init( void )
152 #ifdef _WIN32_WCE
154 /* Windows Mobile doesn't have environment API: */
155 /* GetEnvironmentStrings, GetEnvironmentVariable, getenv. */
156 /* */
157 /* FIXME!!! How to set debug mode? */
158 const char* ft2_debug = 0;
160 #else
162 const char* ft2_debug = getenv( "FT2_DEBUG" );
164 #endif
166 if ( ft2_debug )
168 const char* p = ft2_debug;
169 const char* q;
172 for ( ; *p; p++ )
174 /* skip leading whitespace and separators */
175 if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' )
176 continue;
178 /* read toggle name, followed by ':' */
179 q = p;
180 while ( *p && *p != ':' )
181 p++;
183 if ( *p == ':' && p > q )
185 int n, i, len = p - q;
186 int level = -1, found = -1;
189 for ( n = 0; n < trace_count; n++ )
191 const char* toggle = ft_trace_toggles[n];
194 for ( i = 0; i < len; i++ )
196 if ( toggle[i] != q[i] )
197 break;
200 if ( i == len && toggle[i] == 0 )
202 found = n;
203 break;
207 /* read level */
208 p++;
209 if ( *p )
211 level = *p++ - '0';
212 if ( level < 0 || level > 7 )
213 level = -1;
216 if ( found >= 0 && level >= 0 )
218 if ( found == trace_any )
220 /* special case for "any" */
221 for ( n = 0; n < trace_count; n++ )
222 ft_trace_levels[n] = level;
224 else
225 ft_trace_levels[found] = level;
233 #else /* !FT_DEBUG_LEVEL_TRACE */
236 FT_BASE_DEF( void )
237 ft_debug_init( void )
239 /* nothing */
243 #endif /* !FT_DEBUG_LEVEL_TRACE */
245 #endif /* FT_DEBUG_LEVEL_ERROR */
248 /* END */