1 /***************************************************************************/ 2 /* */ 3 /* ftdebug.h */ 4 /* */ 5 /* Debugging and logging component (specification). */ 6 /* */ 7 /* Copyright 1996-2001, 2002 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 /* 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. */ 20 /* */ 21 /***************************************************************************/ 22 23 24 #ifndef __FTDEBUG_H__ 25 #define __FTDEBUG_H__ 26 27 28 #include <ft2build.h> 29 #include FT_CONFIG_CONFIG_H 30 31 32 FT_BEGIN_HEADER 33 34 35 /* force the definition of FT_DEBUG_LEVEL_ERROR if FT_DEBUG_LEVEL_TRACE */ 36 /* is already defined; this simplifies the following #ifdefs */ 37 /* */ 38 #ifdef FT_DEBUG_LEVEL_TRACE 39 #undef FT_DEBUG_LEVEL_ERROR 40 #define FT_DEBUG_LEVEL_ERROR 41 #endif 42 43 44 /*************************************************************************/ 45 /* */ 46 /* Define the trace enums as well as the trace levels array when they */ 47 /* are needed. */ 48 /* */ 49 /*************************************************************************/ 50 51 #ifdef FT_DEBUG_LEVEL_TRACE 52 53 #define FT_TRACE_DEF( x ) trace_ ## x , 54 55 /* defining the enumeration */ 56 typedef enum 57 { 58 #include FT_INTERNAL_TRACE_H 59 trace_count 60 61 } FT_Trace; 62 63 64 /* defining the array of trace levels, provided by `src/base/ftdebug.c' */ 65 extern int ft_trace_levels[trace_count]; 66 67 #undef FT_TRACE_DEF 68 69 #endif /* FT_DEBUG_LEVEL_TRACE */ 70 71 72 /*************************************************************************/ 73 /* */ 74 /* Define the FT_TRACE macro */ 75 /* */ 76 /* IMPORTANT! */ 77 /* */ 78 /* Each component must define the macro FT_COMPONENT to a valid FT_Trace */ 79 /* value before using any TRACE macro. */ 80 /* */ 81 /*************************************************************************/ 82 83 #ifdef FT_DEBUG_LEVEL_TRACE 84 85 #define FT_TRACE( level, varformat ) \ 86 do \ 87 { \ 88 if ( ft_trace_levels[FT_COMPONENT] >= level ) \ 89 FT_Message varformat; \ 90 } while ( 0 ) 91 92 #else /* !FT_DEBUG_LEVEL_TRACE */ 93 94 #define FT_TRACE( level, varformat ) do ; while ( 0 ) /* nothing */ 95 96 #endif /* !FT_DEBUG_LEVEL_TRACE */ 97 98 99 /*************************************************************************/ 100 /* */ 101 /* You need two opening resp. closing parentheses! */ 102 /* */ 103 /* Example: FT_TRACE0(( "Value is %i", foo )) */ 104 /* */ 105 /*************************************************************************/ 106 107 #define FT_TRACE0( varformat ) FT_TRACE( 0, varformat ) 108 #define FT_TRACE1( varformat ) FT_TRACE( 1, varformat ) 109 #define FT_TRACE2( varformat ) FT_TRACE( 2, varformat ) 110 #define FT_TRACE3( varformat ) FT_TRACE( 3, varformat ) 111 #define FT_TRACE4( varformat ) FT_TRACE( 4, varformat ) 112 #define FT_TRACE5( varformat ) FT_TRACE( 5, varformat ) 113 #define FT_TRACE6( varformat ) FT_TRACE( 6, varformat ) 114 #define FT_TRACE7( varformat ) FT_TRACE( 7, varformat ) 115 116 117 /*************************************************************************/ 118 /* */ 119 /* Define the FT_ERROR macro */ 120 /* */ 121 /*************************************************************************/ 122 123 #ifdef FT_DEBUG_LEVEL_ERROR 124 125 #define FT_ERROR( varformat ) FT_Message varformat 126 127 #else /* !FT_DEBUG_LEVEL_ERROR */ 128 129 #define FT_ERROR( varformat ) do ; while ( 0 ) /* nothing */ 130 131 #endif /* !FT_DEBUG_LEVEL_ERROR */ 132 133 134 /*************************************************************************/ 135 /* */ 136 /* Define the FT_ASSERT macro */ 137 /* */ 138 /*************************************************************************/ 139 140 #ifdef FT_DEBUG_LEVEL_ERROR 141 142 #define FT_ASSERT( condition ) \ 143 do \ 144 { \ 145 if ( !( condition ) ) \ 146 FT_Panic( "assertion failed on line %d of file %s\n", \ 147 __LINE__, __FILE__ ); \ 148 } while ( 0 ) 149 150 #else /* !FT_DEBUG_LEVEL_ERROR */ 151 152 #define FT_ASSERT( condition ) do ; while ( 0 ) 153 154 #endif /* !FT_DEBUG_LEVEL_ERROR */ 155 156 157 /*************************************************************************/ 158 /* */ 159 /* Define 'FT_Message' and 'FT_Panic' when needed */ 160 /* */ 161 /*************************************************************************/ 162 163 #ifdef FT_DEBUG_LEVEL_ERROR 164 165 #include "stdio.h" /* for vprintf() */ 166 167 /* print a message */ 168 FT_EXPORT( void ) 169 FT_Message( const char* fmt, ... ); 170 171 /* print a message and exit */ 172 FT_EXPORT( void ) 173 FT_Panic( const char* fmt, ... ); 174 175 #endif /* FT_DEBUG_LEVEL_ERROR */ 176 177 178 FT_BASE( void ) 179 ft_debug_init( void ); 180 181 182 #if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */ 183 184 /* we disable the warning `conditional expression is constant' here */ 185 /* in order to compile cleanly with the maximum level of warnings */ 186 #pragma warning( disable : 4127 ) 187 188 #endif /* _MSC_VER */ 189 190 191 FT_END_HEADER 192 193 #endif /* __FTDEBUG_H__ */ 194 195 196 /* END */ 197