1 /***************************************************************************/
5 /* Debugging and logging component for amiga (body). */
7 /* Copyright 1996-2002, 2004, 2005, 2013 by */
8 /* David Turner, Robert Wilhelm, Werner Lemberg and Detlef Würkner. */
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. */
16 /***************************************************************************/
19 /*************************************************************************/
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. */
25 /* There are now three debugging modes: */
29 /* Error and trace messages are sent to the log file (which can be the */
30 /* standard error output). */
34 /* Only error messages are generated. */
38 /* No error message is sent or generated. The code is free from any */
39 /* debugging parts. */
41 /*************************************************************************/
45 * Based on the default ftdebug.c,
46 * replaced vprintf() with KVPrintF(),
47 * commented out exit(),
48 * replaced getenv() with GetVar().
51 #include <exec/types.h>
52 #include <utility/tagitem.h>
53 #include <dos/exall.h>
56 #define __NOLOBALIFACE__
57 #define __USE_INLINE__
58 #include <proto/dos.h>
59 #include <clib/debug_protos.h>
62 extern struct Library *DOSBase;
64 extern struct DOSIFace *IDOS;
69 #include FT_FREETYPE_H
70 #include FT_INTERNAL_DEBUG_H
73 #if defined( FT_DEBUG_LEVEL_ERROR )
75 /* documentation is in ftdebug.h */
78 FT_Message( const char* fmt,
90 /* documentation is in ftdebug.h */
93 FT_Panic( const char* fmt,
103 /* exit( EXIT_FAILURE ); */
107 /* documentation is in ftdebug.h */
110 FT_Throw( FT_Error error,
121 #endif /* FT_DEBUG_LEVEL_ERROR */
125 #ifdef FT_DEBUG_LEVEL_TRACE
127 /* array of trace levels, initialized to 0 */
128 int ft_trace_levels[trace_count];
131 /* define array of trace toggle names */
132 #define FT_TRACE_DEF( x ) #x ,
134 static const char* ft_trace_toggles[trace_count + 1] =
136 #include FT_INTERNAL_TRACE_H
143 /* documentation is in ftdebug.h */
145 FT_BASE_DEF( FT_Int )
146 FT_Trace_Get_Count( void )
152 /* documentation is in ftdebug.h */
154 FT_BASE_DEF( const char * )
155 FT_Trace_Get_Name( FT_Int idx )
157 int max = FT_Trace_Get_Count();
161 return ft_trace_toggles[idx];
167 /*************************************************************************/
169 /* Initialize the tracing sub-system. This is done by retrieving the */
170 /* value of the `FT2_DEBUG' environment variable. It must be a list of */
171 /* toggles, separated by spaces, `;', or `,'. Example: */
173 /* export FT2_DEBUG="any:3 memory:7 stream:5" */
175 /* This requests that all levels be set to 3, except the trace level for */
176 /* the memory and stream components which are set to 7 and 5, */
179 /* See the file <include/internal/fttrace.h> for details of the */
180 /* available toggle names. */
182 /* The level must be between 0 and 7; 0 means quiet (except for serious */
183 /* runtime errors), and 7 means _very_ verbose. */
186 ft_debug_init( void )
188 /* const char* ft2_debug = getenv( "FT2_DEBUG" ); */
190 const char* ft2_debug = &buf[0];
193 /* if ( ft2_debug ) */
194 if ( GetVar( "FT2_DEBUG", (STRPTR)ft2_debug, 256, LV_VAR ) > 0 )
196 const char* p = ft2_debug;
202 /* skip leading whitespace and separators */
203 if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' )
206 /* read toggle name, followed by ':' */
208 while ( *p && *p != ':' )
214 if ( *p == ':' && p > q )
216 FT_Int n, i, len = (FT_Int)( p - q );
217 FT_Int level = -1, found = -1;
220 for ( n = 0; n < trace_count; n++ )
222 const char* toggle = ft_trace_toggles[n];
225 for ( i = 0; i < len; i++ )
227 if ( toggle[i] != q[i] )
231 if ( i == len && toggle[i] == 0 )
243 if ( level < 0 || level > 7 )
247 if ( found >= 0 && level >= 0 )
249 if ( found == trace_any )
251 /* special case for `any' */
252 for ( n = 0; n < trace_count; n++ )
253 ft_trace_levels[n] = level;
256 ft_trace_levels[found] = level;
264 #else /* !FT_DEBUG_LEVEL_TRACE */
268 ft_debug_init( void )
274 FT_BASE_DEF( FT_Int )
275 FT_Trace_Get_Count( void )
281 FT_BASE_DEF( const char * )
282 FT_Trace_Get_Name( FT_Int idx )
290 #endif /* !FT_DEBUG_LEVEL_TRACE */