David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
| 3 | /* ftdebug.c */ |
| 4 | /* */ |
| 5 | /* Debugging and logging component (body). */ |
| 6 | /* */ |
Werner Lemberg | 16dc51f | 2008-05-18 17:36:15 +0000 | [diff] [blame] | 7 | /* Copyright 1996-2001, 2002, 2004, 2008 by */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
| 9 | /* */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 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 */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 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 | |
| 18 | |
Werner Lemberg | 9a754ce | 2000-06-02 21:31:32 +0000 | [diff] [blame] | 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 | /*************************************************************************/ |
| 42 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 43 | |
| 44 | #include <ft2build.h> |
David Turner | 88027fd | 2002-04-17 11:32:10 +0000 | [diff] [blame] | 45 | #include FT_FREETYPE_H |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 46 | #include FT_INTERNAL_DEBUG_H |
| 47 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 48 | |
Werner Lemberg | 0219728 | 2008-11-29 09:31:44 +0000 | [diff] [blame] | 49 | #ifdef FT_DEBUG_LEVEL_ERROR |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 50 | |
Werner Lemberg | ece8b20 | 2004-12-13 23:16:59 +0000 | [diff] [blame] | 51 | /* documentation is in ftdebug.h */ |
| 52 | |
Wu, Chia-I (吳佳一) | 35bfc0f | 2005-11-17 01:53:07 +0000 | [diff] [blame] | 53 | FT_BASE_DEF( void ) |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 54 | FT_Message( const char* fmt, ... ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 55 | { |
| 56 | va_list ap; |
| 57 | |
| 58 | |
| 59 | va_start( ap, fmt ); |
Werner Lemberg | 16dc51f | 2008-05-18 17:36:15 +0000 | [diff] [blame] | 60 | vfprintf( stderr, fmt, ap ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 61 | va_end( ap ); |
| 62 | } |
| 63 | |
| 64 | |
Werner Lemberg | ece8b20 | 2004-12-13 23:16:59 +0000 | [diff] [blame] | 65 | /* documentation is in ftdebug.h */ |
| 66 | |
Wu, Chia-I (吳佳一) | 35bfc0f | 2005-11-17 01:53:07 +0000 | [diff] [blame] | 67 | FT_BASE_DEF( void ) |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 68 | FT_Panic( const char* fmt, ... ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 69 | { |
| 70 | va_list ap; |
| 71 | |
| 72 | |
| 73 | va_start( ap, fmt ); |
Werner Lemberg | 16dc51f | 2008-05-18 17:36:15 +0000 | [diff] [blame] | 74 | vfprintf( stderr, fmt, ap ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 75 | va_end( ap ); |
| 76 | |
| 77 | exit( EXIT_FAILURE ); |
| 78 | } |
| 79 | |
Werner Lemberg | c58ce3b | 2013-03-13 11:06:39 +0100 | [diff] [blame] | 80 | |
| 81 | /* documentation is in ftdebug.h */ |
| 82 | |
| 83 | FT_BASE_DEF( int ) |
| 84 | FT_Throw( FT_Error error, |
| 85 | int line, |
| 86 | const char* file ) |
| 87 | { |
| 88 | FT_UNUSED( error ); |
| 89 | FT_UNUSED( line ); |
| 90 | FT_UNUSED( file ); |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 95 | #endif /* FT_DEBUG_LEVEL_ERROR */ |
| 96 | |
| 97 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 98 | |
| 99 | #ifdef FT_DEBUG_LEVEL_TRACE |
| 100 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 101 | /* array of trace levels, initialized to 0 */ |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 102 | int ft_trace_levels[trace_count]; |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 103 | |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 104 | |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 105 | /* define array of trace toggle names */ |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 106 | #define FT_TRACE_DEF( x ) #x , |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 107 | |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 108 | static const char* ft_trace_toggles[trace_count + 1] = |
David Turner | 02c3aed | 2002-07-08 23:02:32 +0000 | [diff] [blame] | 109 | { |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 110 | #include FT_INTERNAL_TRACE_H |
| 111 | NULL |
| 112 | }; |
| 113 | |
| 114 | #undef FT_TRACE_DEF |
| 115 | |
| 116 | |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 117 | /* documentation is in ftdebug.h */ |
| 118 | |
Wu, Chia-I (吳佳一) | 35bfc0f | 2005-11-17 01:53:07 +0000 | [diff] [blame] | 119 | FT_BASE_DEF( FT_Int ) |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 120 | FT_Trace_Get_Count( void ) |
| 121 | { |
| 122 | return trace_count; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | /* documentation is in ftdebug.h */ |
| 127 | |
Wu, Chia-I (吳佳一) | 35bfc0f | 2005-11-17 01:53:07 +0000 | [diff] [blame] | 128 | FT_BASE_DEF( const char * ) |
Werner Lemberg | 391de1a | 2004-04-11 16:44:54 +0000 | [diff] [blame] | 129 | FT_Trace_Get_Name( FT_Int idx ) |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 130 | { |
| 131 | int max = FT_Trace_Get_Count(); |
| 132 | |
| 133 | |
Werner Lemberg | 391de1a | 2004-04-11 16:44:54 +0000 | [diff] [blame] | 134 | if ( idx < max ) |
| 135 | return ft_trace_toggles[idx]; |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 136 | else |
| 137 | return NULL; |
| 138 | } |
| 139 | |
| 140 | |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 141 | /*************************************************************************/ |
| 142 | /* */ |
| 143 | /* Initialize the tracing sub-system. This is done by retrieving the */ |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 144 | /* value of the `FT2_DEBUG' environment variable. It must be a list of */ |
| 145 | /* toggles, separated by spaces, `;', or `,'. Example: */ |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 146 | /* */ |
Werner Lemberg | 92c9f10 | 2004-09-04 06:53:36 +0000 | [diff] [blame] | 147 | /* export FT2_DEBUG="any:3 memory:7 stream:5" */ |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 148 | /* */ |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 149 | /* This requests that all levels be set to 3, except the trace level for */ |
Werner Lemberg | 92c9f10 | 2004-09-04 06:53:36 +0000 | [diff] [blame] | 150 | /* the memory and stream components which are set to 7 and 5, */ |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 151 | /* respectively. */ |
| 152 | /* */ |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 153 | /* See the file <include/freetype/internal/fttrace.h> for details of the */ |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 154 | /* available toggle names. */ |
| 155 | /* */ |
Werner Lemberg | 92c9f10 | 2004-09-04 06:53:36 +0000 | [diff] [blame] | 156 | /* The level must be between 0 and 7; 0 means quiet (except for serious */ |
| 157 | /* runtime errors), and 7 means _very_ verbose. */ |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 158 | /* */ |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 159 | FT_BASE_DEF( void ) |
| 160 | ft_debug_init( void ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 161 | { |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 162 | const char* ft2_debug = getenv( "FT2_DEBUG" ); |
David Turner | 02c3aed | 2002-07-08 23:02:32 +0000 | [diff] [blame] | 163 | |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 164 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 165 | if ( ft2_debug ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 166 | { |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 167 | const char* p = ft2_debug; |
| 168 | const char* q; |
David Turner | 02c3aed | 2002-07-08 23:02:32 +0000 | [diff] [blame] | 169 | |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 170 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 171 | for ( ; *p; p++ ) |
| 172 | { |
| 173 | /* skip leading whitespace and separators */ |
David Turner | 02c3aed | 2002-07-08 23:02:32 +0000 | [diff] [blame] | 174 | if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' ) |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 175 | continue; |
David Turner | 02c3aed | 2002-07-08 23:02:32 +0000 | [diff] [blame] | 176 | |
| 177 | /* read toggle name, followed by ':' */ |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 178 | q = p; |
David Turner | 02c3aed | 2002-07-08 23:02:32 +0000 | [diff] [blame] | 179 | while ( *p && *p != ':' ) |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 180 | p++; |
David Turner | 10bf05a | 2004-04-21 14:30:37 +0000 | [diff] [blame] | 181 | |
David Turner | 02c3aed | 2002-07-08 23:02:32 +0000 | [diff] [blame] | 182 | if ( *p == ':' && p > q ) |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 183 | { |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 184 | FT_Int n, i, len = (FT_Int)( p - q ); |
Werner Lemberg | 68e9f92 | 2002-09-27 11:09:23 +0000 | [diff] [blame] | 185 | FT_Int level = -1, found = -1; |
David Turner | 02c3aed | 2002-07-08 23:02:32 +0000 | [diff] [blame] | 186 | |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 187 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 188 | for ( n = 0; n < trace_count; n++ ) |
| 189 | { |
| 190 | const char* toggle = ft_trace_toggles[n]; |
David Turner | 02c3aed | 2002-07-08 23:02:32 +0000 | [diff] [blame] | 191 | |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 192 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 193 | for ( i = 0; i < len; i++ ) |
| 194 | { |
| 195 | if ( toggle[i] != q[i] ) |
| 196 | break; |
| 197 | } |
David Turner | 02c3aed | 2002-07-08 23:02:32 +0000 | [diff] [blame] | 198 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 199 | if ( i == len && toggle[i] == 0 ) |
| 200 | { |
| 201 | found = n; |
| 202 | break; |
| 203 | } |
| 204 | } |
David Turner | 02c3aed | 2002-07-08 23:02:32 +0000 | [diff] [blame] | 205 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 206 | /* read level */ |
| 207 | p++; |
| 208 | if ( *p ) |
| 209 | { |
| 210 | level = *p++ - '0'; |
Werner Lemberg | 92c9f10 | 2004-09-04 06:53:36 +0000 | [diff] [blame] | 211 | if ( level < 0 || level > 7 ) |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 212 | level = -1; |
| 213 | } |
David Turner | 02c3aed | 2002-07-08 23:02:32 +0000 | [diff] [blame] | 214 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 215 | if ( found >= 0 && level >= 0 ) |
| 216 | { |
| 217 | if ( found == trace_any ) |
| 218 | { |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 219 | /* special case for `any' */ |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 220 | for ( n = 0; n < trace_count; n++ ) |
| 221 | ft_trace_levels[n] = level; |
| 222 | } |
| 223 | else |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 224 | ft_trace_levels[found] = level; |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 228 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 231 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 232 | #else /* !FT_DEBUG_LEVEL_TRACE */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 233 | |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 234 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 235 | FT_BASE_DEF( void ) |
David Turner | 88027fd | 2002-04-17 11:32:10 +0000 | [diff] [blame] | 236 | ft_debug_init( void ) |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 237 | { |
| 238 | /* nothing */ |
| 239 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 240 | |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 241 | |
Wu, Chia-I (吳佳一) | 35bfc0f | 2005-11-17 01:53:07 +0000 | [diff] [blame] | 242 | FT_BASE_DEF( FT_Int ) |
David Turner | 10bf05a | 2004-04-21 14:30:37 +0000 | [diff] [blame] | 243 | FT_Trace_Get_Count( void ) |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 244 | { |
David Turner | 10bf05a | 2004-04-21 14:30:37 +0000 | [diff] [blame] | 245 | return 0; |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | |
Wu, Chia-I (吳佳一) | 35bfc0f | 2005-11-17 01:53:07 +0000 | [diff] [blame] | 249 | FT_BASE_DEF( const char * ) |
David Turner | 10bf05a | 2004-04-21 14:30:37 +0000 | [diff] [blame] | 250 | FT_Trace_Get_Name( FT_Int idx ) |
| 251 | { |
| 252 | FT_UNUSED( idx ); |
| 253 | |
| 254 | return NULL; |
Werner Lemberg | 460355a | 2004-02-24 07:52:45 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 258 | #endif /* !FT_DEBUG_LEVEL_TRACE */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 259 | |
Werner Lemberg | 63408a1 | 2000-12-13 23:44:37 +0000 | [diff] [blame] | 260 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 261 | /* END */ |