misc/libfreetype/builds/amiga/src/base/ftdebug.c
changeset 5172 88f2e05288ba
equal deleted inserted replaced
5171:f9283dc4860d 5172:88f2e05288ba
       
     1 /***************************************************************************/
       
     2 /*                                                                         */
       
     3 /*  ftdebug.c                                                              */
       
     4 /*                                                                         */
       
     5 /*    Debugging and logging component (body).                              */
       
     6 /*                                                                         */
       
     7 /*  Copyright 1996-2001, 2002, 2004, 2005 by                               */
       
     8 /*  David Turner, Robert Wilhelm, Werner Lemberg and Detlef Würkner.       */
       
     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 
       
    18 
       
    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 
       
    43 
       
    44 /*
       
    45  * Based on the default ftdebug.c,
       
    46  * replaced vprintf() with KVPrintF(),
       
    47  * commented out exit(),
       
    48  * replaced getenv() with GetVar().
       
    49  */
       
    50 
       
    51 #include <exec/types.h>
       
    52 #include <utility/tagitem.h>
       
    53 #include <dos/exall.h>
       
    54 #include <dos/var.h>
       
    55 #define __NOLIBBASE__
       
    56 #define __NOLOBALIFACE__
       
    57 #define __USE_INLINE__
       
    58 #include <proto/dos.h>
       
    59 #include <clib/debug_protos.h>
       
    60 
       
    61 #ifndef __amigaos4__
       
    62 extern struct Library *DOSBase;
       
    63 #else
       
    64 extern struct DOSIFace *IDOS;
       
    65 #endif
       
    66 
       
    67 
       
    68 #include <ft2build.h>
       
    69 #include FT_FREETYPE_H
       
    70 #include FT_INTERNAL_DEBUG_H
       
    71 
       
    72 
       
    73 #if defined( FT_DEBUG_LEVEL_ERROR )
       
    74 
       
    75   /* documentation is in ftdebug.h */
       
    76 
       
    77   FT_BASE_DEF( void )
       
    78   FT_Message( const char*  fmt, ... )
       
    79   {
       
    80     va_list  ap;
       
    81 
       
    82 
       
    83     va_start( ap, fmt );
       
    84 /*  vprintf( fmt, ap ); */
       
    85     KVPrintF( fmt, ap );
       
    86     va_end( ap );
       
    87   }
       
    88 
       
    89 
       
    90   /* documentation is in ftdebug.h */
       
    91 
       
    92   FT_BASE_DEF( void )
       
    93   FT_Panic( const char*  fmt, ... )
       
    94   {
       
    95     va_list  ap;
       
    96 
       
    97 
       
    98     va_start( ap, fmt );
       
    99 /*  vprintf( fmt, ap ); */
       
   100     KVPrintF( fmt, ap );
       
   101     va_end( ap );
       
   102 
       
   103 /*  exit( EXIT_FAILURE ); */
       
   104   }
       
   105 
       
   106 #endif /* FT_DEBUG_LEVEL_ERROR */
       
   107 
       
   108 
       
   109 
       
   110 #ifdef FT_DEBUG_LEVEL_TRACE
       
   111 
       
   112   /* array of trace levels, initialized to 0 */
       
   113   int  ft_trace_levels[trace_count];
       
   114 
       
   115 
       
   116   /* define array of trace toggle names */
       
   117 #define FT_TRACE_DEF( x )  #x ,
       
   118 
       
   119   static const char*  ft_trace_toggles[trace_count + 1] =
       
   120   {
       
   121 #include FT_INTERNAL_TRACE_H
       
   122     NULL
       
   123   };
       
   124 
       
   125 #undef FT_TRACE_DEF
       
   126 
       
   127 
       
   128   /* documentation is in ftdebug.h */
       
   129 
       
   130   FT_BASE_DEF( FT_Int )
       
   131   FT_Trace_Get_Count( void )
       
   132   {
       
   133     return trace_count;
       
   134   }
       
   135 
       
   136 
       
   137   /* documentation is in ftdebug.h */
       
   138 
       
   139   FT_BASE_DEF( const char * )
       
   140   FT_Trace_Get_Name( FT_Int  idx )
       
   141   {
       
   142     int  max = FT_Trace_Get_Count();
       
   143 
       
   144 
       
   145     if ( idx < max )
       
   146       return ft_trace_toggles[idx];
       
   147     else
       
   148       return NULL;
       
   149   }
       
   150 
       
   151 
       
   152   /*************************************************************************/
       
   153   /*                                                                       */
       
   154   /* Initialize the tracing sub-system.  This is done by retrieving the    */
       
   155   /* value of the `FT2_DEBUG' environment variable.  It must be a list of  */
       
   156   /* toggles, separated by spaces, `;', or `,'.  Example:                  */
       
   157   /*                                                                       */
       
   158   /*    export FT2_DEBUG="any:3 memory:7 stream:5"                         */
       
   159   /*                                                                       */
       
   160   /* This requests that all levels be set to 3, except the trace level for */
       
   161   /* the memory and stream components which are set to 7 and 5,            */
       
   162   /* respectively.                                                         */
       
   163   /*                                                                       */
       
   164   /* See the file <include/freetype/internal/fttrace.h> for details of the */
       
   165   /* available toggle names.                                               */
       
   166   /*                                                                       */
       
   167   /* The level must be between 0 and 7; 0 means quiet (except for serious  */
       
   168   /* runtime errors), and 7 means _very_ verbose.                          */
       
   169   /*                                                                       */
       
   170   FT_BASE_DEF( void )
       
   171   ft_debug_init( void )
       
   172   {
       
   173 /*  const char*  ft2_debug = getenv( "FT2_DEBUG" ); */
       
   174     char         buf[256];
       
   175     const char*  ft2_debug = &buf[0];
       
   176 
       
   177 
       
   178 /*  if ( ft2_debug ) */
       
   179     if ( GetVar( "FT2_DEBUG", (STRPTR)ft2_debug, 256, LV_VAR ) > 0 )
       
   180     {
       
   181       const char*  p = ft2_debug;
       
   182       const char*  q;
       
   183 
       
   184 
       
   185       for ( ; *p; p++ )
       
   186       {
       
   187         /* skip leading whitespace and separators */
       
   188         if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' )
       
   189           continue;
       
   190 
       
   191         /* read toggle name, followed by ':' */
       
   192         q = p;
       
   193         while ( *p && *p != ':' )
       
   194           p++;
       
   195 
       
   196         if ( *p == ':' && p > q )
       
   197         {
       
   198           FT_Int  n, i, len = (FT_Int)( p - q );
       
   199           FT_Int  level = -1, found = -1;
       
   200 
       
   201 
       
   202           for ( n = 0; n < trace_count; n++ )
       
   203           {
       
   204             const char*  toggle = ft_trace_toggles[n];
       
   205 
       
   206 
       
   207             for ( i = 0; i < len; i++ )
       
   208             {
       
   209               if ( toggle[i] != q[i] )
       
   210                 break;
       
   211             }
       
   212 
       
   213             if ( i == len && toggle[i] == 0 )
       
   214             {
       
   215               found = n;
       
   216               break;
       
   217             }
       
   218           }
       
   219 
       
   220           /* read level */
       
   221           p++;
       
   222           if ( *p )
       
   223           {
       
   224             level = *p++ - '0';
       
   225             if ( level < 0 || level > 7 )
       
   226               level = -1;
       
   227           }
       
   228 
       
   229           if ( found >= 0 && level >= 0 )
       
   230           {
       
   231             if ( found == trace_any )
       
   232             {
       
   233               /* special case for `any' */
       
   234               for ( n = 0; n < trace_count; n++ )
       
   235                 ft_trace_levels[n] = level;
       
   236             }
       
   237             else
       
   238               ft_trace_levels[found] = level;
       
   239           }
       
   240         }
       
   241       }
       
   242     }
       
   243   }
       
   244 
       
   245 
       
   246 #else  /* !FT_DEBUG_LEVEL_TRACE */
       
   247 
       
   248 
       
   249   FT_BASE_DEF( void )
       
   250   ft_debug_init( void )
       
   251   {
       
   252     /* nothing */
       
   253   }
       
   254 
       
   255 
       
   256   FT_BASE_DEF( FT_Int )
       
   257   FT_Trace_Get_Count( void )
       
   258   {
       
   259     return 0;
       
   260   }
       
   261 
       
   262 
       
   263   FT_BASE_DEF( const char * )
       
   264   FT_Trace_Get_Name( FT_Int  idx )
       
   265   {
       
   266     FT_UNUSED( idx );
       
   267 
       
   268     return NULL;
       
   269   }
       
   270 
       
   271 
       
   272 #endif /* !FT_DEBUG_LEVEL_TRACE */
       
   273 
       
   274 /*
       
   275 Local Variables:
       
   276 coding: latin-1
       
   277 End:
       
   278 */
       
   279 /* END */