1 /****************************************************************************
5 * Debugging and logging component for amiga (body).
7 * Copyright (C) 1996-2023 by
8 * David Turner, Robert Wilhelm, Werner Lemberg, and Detlef Wuerkner.
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.
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
45 * Based on the default `ftdebug.c' file,
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>
57 #define __NOLOBALIFACE__
58 #define __USE_INLINE__
60 #include <proto/dos.h>
61 #include <clib/debug_protos.h>
64 extern struct Library* DOSBase;
66 extern struct DOSIFace* IDOS;
71 #include <freetype/freetype.h>
72 #include <freetype/internal/ftdebug.h>
75 #ifdef FT_DEBUG_LEVEL_ERROR
77 /* documentation is in ftdebug.h */
80 FT_Message( const char* fmt,
92 /* documentation is in ftdebug.h */
95 FT_Panic( const char* fmt,
105 /* exit( EXIT_FAILURE ); */
109 /* documentation is in ftdebug.h */
112 FT_Throw( FT_Error error,
117 /* activating the code in this block makes FreeType very chatty */
119 "%s:%d: error 0x%02x: %s\n",
123 FT_Error_String( error ) );
133 #endif /* FT_DEBUG_LEVEL_ERROR */
137 #ifdef FT_DEBUG_LEVEL_TRACE
139 /* array of trace levels, initialized to 0; */
140 /* this gets adjusted at run-time */
141 static int ft_trace_levels_enabled[trace_count];
143 /* array of trace levels, always initialized to 0 */
144 static int ft_trace_levels_disabled[trace_count];
146 /* a pointer to either `ft_trace_levels_enabled' */
147 /* or `ft_trace_levels_disabled' */
148 int* ft_trace_levels;
150 /* define array of trace toggle names */
151 #define FT_TRACE_DEF( x ) #x ,
153 static const char* ft_trace_toggles[trace_count + 1] =
155 #include <freetype/internal/fttrace.h>
162 /* documentation is in ftdebug.h */
164 FT_BASE_DEF( FT_Int )
165 FT_Trace_Get_Count( void )
171 /* documentation is in ftdebug.h */
173 FT_BASE_DEF( const char * )
174 FT_Trace_Get_Name( FT_Int idx )
176 int max = FT_Trace_Get_Count();
180 return ft_trace_toggles[idx];
186 /* documentation is in ftdebug.h */
189 FT_Trace_Disable( void )
191 ft_trace_levels = ft_trace_levels_disabled;
195 /* documentation is in ftdebug.h */
198 FT_Trace_Enable( void )
200 ft_trace_levels = ft_trace_levels_enabled;
204 /**************************************************************************
206 * Initialize the tracing sub-system. This is done by retrieving the
207 * value of the `FT2_DEBUG' environment variable. It must be a list of
208 * toggles, separated by spaces, `;', or `,'. Example:
210 * export FT2_DEBUG="any:3 memory:7 stream:5"
212 * This requests that all levels be set to 3, except the trace level for
213 * the memory and stream components which are set to 7 and 5,
216 * See the file `include/freetype/internal/fttrace.h' for details of
217 * the available toggle names.
219 * The level must be between 0 and 7; 0 means quiet (except for serious
220 * runtime errors), and 7 means _very_ verbose.
223 ft_debug_init( void )
225 /* const char* ft2_debug = ft_getenv( "FT2_DEBUG" ); */
227 const char* ft2_debug = &buf[0];
230 /* if ( ft2_debug ) */
231 if ( GetVar( "FT2_DEBUG", (STRPTR)ft2_debug, 256, LV_VAR ) > 0 )
233 const char* p = ft2_debug;
239 /* skip leading whitespace and separators */
240 if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' )
243 /* read toggle name, followed by ':' */
245 while ( *p && *p != ':' )
251 if ( *p == ':' && p > q )
253 FT_Int n, i, len = (FT_Int)( p - q );
254 FT_Int level = -1, found = -1;
257 for ( n = 0; n < trace_count; n++ )
259 const char* toggle = ft_trace_toggles[n];
262 for ( i = 0; i < len; i++ )
264 if ( toggle[i] != q[i] )
268 if ( i == len && toggle[i] == 0 )
280 if ( level < 0 || level > 7 )
284 if ( found >= 0 && level >= 0 )
286 if ( found == trace_any )
288 /* special case for `any' */
289 for ( n = 0; n < trace_count; n++ )
290 ft_trace_levels_enabled[n] = level;
293 ft_trace_levels_enabled[found] = level;
299 ft_trace_levels = ft_trace_levels_enabled;
303 #else /* !FT_DEBUG_LEVEL_TRACE */
307 ft_debug_init( void )
313 FT_BASE_DEF( FT_Int )
314 FT_Trace_Get_Count( void )
320 FT_BASE_DEF( const char * )
321 FT_Trace_Get_Name( FT_Int idx )
330 FT_Trace_Disable( void )
336 /* documentation is in ftdebug.h */
339 FT_Trace_Enable( void )
345 #endif /* !FT_DEBUG_LEVEL_TRACE */