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 | 415235d | 2001-06-28 17:49:10 +0000 | [diff] [blame] | 7 | /* Copyright 1996-2001 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 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 49 | #if defined( FT_DEBUG_LEVEL_ERROR ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 50 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 51 | FT_EXPORT_DEF( void ) |
| 52 | FT_Message( const char* fmt, ... ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 53 | { |
| 54 | va_list ap; |
| 55 | |
| 56 | |
| 57 | va_start( ap, fmt ); |
| 58 | vprintf( fmt, ap ); |
| 59 | va_end( ap ); |
| 60 | } |
| 61 | |
| 62 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 63 | FT_EXPORT_DEF( void ) |
| 64 | FT_Panic( const char* fmt, ... ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 65 | { |
| 66 | va_list ap; |
| 67 | |
| 68 | |
| 69 | va_start( ap, fmt ); |
| 70 | vprintf( fmt, ap ); |
| 71 | va_end( ap ); |
| 72 | |
| 73 | exit( EXIT_FAILURE ); |
| 74 | } |
| 75 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 76 | #endif /* FT_DEBUG_LEVEL_ERROR */ |
| 77 | |
| 78 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 79 | |
| 80 | #ifdef FT_DEBUG_LEVEL_TRACE |
| 81 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 82 | /* array of trace levels, initialized to 0 */ |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 83 | int ft_trace_levels[trace_count]; |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 84 | |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 85 | /* define array of trace toggle names */ |
| 86 | #define FT_TRACE_DEF(x) #x , |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 87 | |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 88 | static const char* ft_trace_toggles[trace_count + 1] = |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 89 | { |
| 90 | #include FT_INTERNAL_TRACE_H |
| 91 | NULL |
| 92 | }; |
| 93 | |
| 94 | #undef FT_TRACE_DEF |
| 95 | |
| 96 | |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 97 | /*************************************************************************/ |
| 98 | /* */ |
| 99 | /* Initialize the tracing sub-system. This is done by retrieving the */ |
| 100 | /* value of the "FT2_DEBUG" environment variable. It must be a list of */ |
| 101 | /* toggles, separated by spaces, `;' or `:'. Example: */ |
| 102 | /* */ |
| 103 | /* "any=3 memory=6 stream=5" */ |
| 104 | /* */ |
| 105 | /* This will request that all levels be set to 3, except the trace level */ |
| 106 | /* for the memory and stream components which are set to 6 and 5, */ |
| 107 | /* respectively. */ |
| 108 | /* */ |
| 109 | /* See the file <freetype/internal/fttrace.h> for details of the */ |
| 110 | /* available toggle names. */ |
| 111 | /* */ |
| 112 | /* The level must be between 0 and 6; 0 means quiet (except for serious */ |
| 113 | /* runtime errors), and 6 means _very_ verbose. */ |
| 114 | /* */ |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 115 | FT_BASE_DEF( void ) |
| 116 | ft_debug_init( void ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 117 | { |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 118 | const char* ft2_debug = getenv( "FT2_DEBUG" ); |
| 119 | |
| 120 | if ( ft2_debug ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 121 | { |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 122 | const char* p = ft2_debug; |
| 123 | const char* q; |
| 124 | |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 125 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 126 | for ( ; *p; p++ ) |
| 127 | { |
| 128 | /* skip leading whitespace and separators */ |
| 129 | if ( *p == ' ' || *p == '\t' || *p == ':' || *p == ';' || *p == '=' ) |
| 130 | continue; |
| 131 | |
| 132 | /* read toggle name, followed by '=' */ |
| 133 | q = p; |
| 134 | while ( *p && *p != '=' ) |
| 135 | p++; |
| 136 | |
| 137 | if ( *p == '=' && p > q ) |
| 138 | { |
| 139 | int n, i, len = p - q; |
| 140 | int level = -1, found = -1; |
| 141 | |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 142 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 143 | for ( n = 0; n < trace_count; n++ ) |
| 144 | { |
| 145 | const char* toggle = ft_trace_toggles[n]; |
| 146 | |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 147 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 148 | for ( i = 0; i < len; i++ ) |
| 149 | { |
| 150 | if ( toggle[i] != q[i] ) |
| 151 | break; |
| 152 | } |
| 153 | |
| 154 | if ( i == len && toggle[i] == 0 ) |
| 155 | { |
| 156 | found = n; |
| 157 | break; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | /* read level */ |
| 162 | p++; |
| 163 | if ( *p ) |
| 164 | { |
| 165 | level = *p++ - '0'; |
| 166 | if ( level < 0 || level > 6 ) |
| 167 | level = -1; |
| 168 | } |
| 169 | |
| 170 | if ( found >= 0 && level >= 0 ) |
| 171 | { |
| 172 | if ( found == trace_any ) |
| 173 | { |
| 174 | /* special case for "any" */ |
| 175 | for ( n = 0; n < trace_count; n++ ) |
| 176 | ft_trace_levels[n] = level; |
| 177 | } |
| 178 | else |
Werner Lemberg | af8df85 | 2002-02-22 00:58:04 +0000 | [diff] [blame] | 179 | ft_trace_levels[found] = level; |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 183 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 184 | } |
| 185 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 186 | #else /* !FT_DEBUG_LEVEL_TRACE */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 187 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 188 | FT_BASE_DEF( void ) |
David Turner | 88027fd | 2002-04-17 11:32:10 +0000 | [diff] [blame] | 189 | ft_debug_init( void ) |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 190 | { |
| 191 | /* nothing */ |
| 192 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 193 | |
David Turner | 222cec8 | 2002-02-21 11:48:48 +0000 | [diff] [blame] | 194 | #endif /* !FT_DEBUG_LEVEL_TRACE */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 195 | |
Werner Lemberg | 63408a1 | 2000-12-13 23:44:37 +0000 | [diff] [blame] | 196 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 197 | /* END */ |