1 /***************************************************************************/
5 /* Debugging and logging component (specification). */
7 /* Copyright 1996-2002, 2004, 2006-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. */
17 /* IMPORTANT: A description of FreeType's debugging support can be */
18 /* found in `docs/DEBUG.TXT'. Read it if you need to use or */
19 /* understand this code. */
21 /***************************************************************************/
29 #include FT_CONFIG_CONFIG_H
30 #include FT_FREETYPE_H
36 /* force the definition of FT_DEBUG_LEVEL_ERROR if FT_DEBUG_LEVEL_TRACE */
37 /* is already defined; this simplifies the following #ifdefs */
39 #ifdef FT_DEBUG_LEVEL_TRACE
40 #undef FT_DEBUG_LEVEL_ERROR
41 #define FT_DEBUG_LEVEL_ERROR
45 /*************************************************************************/
47 /* Define the trace enums as well as the trace levels array when they */
50 /*************************************************************************/
52 #ifdef FT_DEBUG_LEVEL_TRACE
54 #define FT_TRACE_DEF( x ) trace_ ## x ,
56 /* defining the enumeration */
57 typedef enum FT_Trace_
59 #include FT_INTERNAL_TRACE_H
65 /* defining the array of trace levels, provided by `src/base/ftdebug.c' */
66 extern int ft_trace_levels[trace_count];
70 #endif /* FT_DEBUG_LEVEL_TRACE */
73 /*************************************************************************/
75 /* Define the FT_TRACE macro */
79 /* Each component must define the macro FT_COMPONENT to a valid FT_Trace */
80 /* value before using any TRACE macro. */
82 /*************************************************************************/
84 #ifdef FT_DEBUG_LEVEL_TRACE
86 #define FT_TRACE( level, varformat ) \
89 if ( ft_trace_levels[FT_COMPONENT] >= level ) \
90 FT_Message varformat; \
93 #else /* !FT_DEBUG_LEVEL_TRACE */
95 #define FT_TRACE( level, varformat ) do { } while ( 0 ) /* nothing */
97 #endif /* !FT_DEBUG_LEVEL_TRACE */
100 /*************************************************************************/
103 /* FT_Trace_Get_Count */
106 /* Return the number of available trace components. */
109 /* The number of trace components. 0 if FreeType 2 is not built with */
110 /* FT_DEBUG_LEVEL_TRACE definition. */
113 /* This function may be useful if you want to access elements of */
114 /* the internal `ft_trace_levels' array by an index. */
117 FT_Trace_Get_Count( void );
120 /*************************************************************************/
123 /* FT_Trace_Get_Name */
126 /* Return the name of a trace component. */
129 /* The index of the trace component. */
132 /* The name of the trace component. This is a statically allocated */
133 /* C string, so do not free it after use. NULL if FreeType 2 is not */
134 /* built with FT_DEBUG_LEVEL_TRACE definition. */
137 /* Use @FT_Trace_Get_Count to get the number of available trace */
140 /* This function may be useful if you want to control FreeType 2's */
141 /* debug level in your application. */
143 FT_BASE( const char * )
144 FT_Trace_Get_Name( FT_Int idx );
147 /*************************************************************************/
149 /* You need two opening and closing parentheses! */
151 /* Example: FT_TRACE0(( "Value is %i", foo )) */
153 /* Output of the FT_TRACEX macros is sent to stderr. */
155 /*************************************************************************/
157 #define FT_TRACE0( varformat ) FT_TRACE( 0, varformat )
158 #define FT_TRACE1( varformat ) FT_TRACE( 1, varformat )
159 #define FT_TRACE2( varformat ) FT_TRACE( 2, varformat )
160 #define FT_TRACE3( varformat ) FT_TRACE( 3, varformat )
161 #define FT_TRACE4( varformat ) FT_TRACE( 4, varformat )
162 #define FT_TRACE5( varformat ) FT_TRACE( 5, varformat )
163 #define FT_TRACE6( varformat ) FT_TRACE( 6, varformat )
164 #define FT_TRACE7( varformat ) FT_TRACE( 7, varformat )
167 /*************************************************************************/
169 /* Define the FT_ERROR macro. */
171 /* Output of this macro is sent to stderr. */
173 /*************************************************************************/
175 #ifdef FT_DEBUG_LEVEL_ERROR
177 #define FT_ERROR( varformat ) FT_Message varformat
179 #else /* !FT_DEBUG_LEVEL_ERROR */
181 #define FT_ERROR( varformat ) do { } while ( 0 ) /* nothing */
183 #endif /* !FT_DEBUG_LEVEL_ERROR */
186 /*************************************************************************/
188 /* Define the FT_ASSERT and FT_THROW macros. The call to `FT_Throw' */
189 /* makes it possible to easily set a breakpoint at this function. */
191 /*************************************************************************/
193 #ifdef FT_DEBUG_LEVEL_ERROR
195 #define FT_ASSERT( condition ) \
198 if ( !( condition ) ) \
199 FT_Panic( "assertion failed on line %d of file %s\n", \
200 __LINE__, __FILE__ ); \
203 #define FT_THROW( e ) \
204 ( FT_Throw( FT_ERR_CAT( FT_ERR_PREFIX, e ), \
207 FT_ERR_CAT( FT_ERR_PREFIX, e ) )
209 #else /* !FT_DEBUG_LEVEL_ERROR */
211 #define FT_ASSERT( condition ) do { } while ( 0 )
213 #define FT_THROW( e ) FT_ERR_CAT( FT_ERR_PREFIX, e )
215 #endif /* !FT_DEBUG_LEVEL_ERROR */
218 /*************************************************************************/
220 /* Define `FT_Message' and `FT_Panic' when needed. */
222 /*************************************************************************/
224 #ifdef FT_DEBUG_LEVEL_ERROR
226 #include "stdio.h" /* for vfprintf() */
228 /* print a message */
230 FT_Message( const char* fmt,
233 /* print a message and exit */
235 FT_Panic( const char* fmt,
238 /* report file name and line number of an error */
240 FT_Throw( FT_Error error,
244 #endif /* FT_DEBUG_LEVEL_ERROR */
248 ft_debug_init( void );
252 #endif /* __FTDEBUG_H__ */