ftdebug.c

Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  ftdebug.c                                                              */
00004 /*                                                                         */
00005 /*    Debugging and logging component (body).                              */
00006 /*                                                                         */
00007 /*  Copyright 1996-2001, 2002, 2004, 2008 by                               */
00008 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
00009 /*                                                                         */
00010 /*  This file is part of the FreeType project, and may only be used,       */
00011 /*  modified, and distributed under the terms of the FreeType project      */
00012 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
00013 /*  this file you indicate that you have read the license and              */
00014 /*  understand and accept it fully.                                        */
00015 /*                                                                         */
00016 /***************************************************************************/
00017 
00018 
00019   /*************************************************************************/
00020   /*                                                                       */
00021   /* This component contains various macros and functions used to ease the */
00022   /* debugging of the FreeType engine.  Its main purpose is in assertion   */
00023   /* checking, tracing, and error detection.                               */
00024   /*                                                                       */
00025   /* There are now three debugging modes:                                  */
00026   /*                                                                       */
00027   /* - trace mode                                                          */
00028   /*                                                                       */
00029   /*   Error and trace messages are sent to the log file (which can be the */
00030   /*   standard error output).                                             */
00031   /*                                                                       */
00032   /* - error mode                                                          */
00033   /*                                                                       */
00034   /*   Only error messages are generated.                                  */
00035   /*                                                                       */
00036   /* - release mode:                                                       */
00037   /*                                                                       */
00038   /*   No error message is sent or generated.  The code is free from any   */
00039   /*   debugging parts.                                                    */
00040   /*                                                                       */
00041   /*************************************************************************/
00042 
00043 
00044 #include <ft2build.h>
00045 #include FT_FREETYPE_H
00046 #include FT_INTERNAL_DEBUG_H
00047 
00048 
00049 #ifdef FT_DEBUG_LEVEL_ERROR
00050 
00051   /* documentation is in ftdebug.h */
00052 
00053   FT_BASE_DEF( void )
00054   FT_Message( const char*  fmt, ... )
00055   {
00056     va_list  ap;
00057 
00058 
00059     va_start( ap, fmt );
00060     vfprintf( stderr, fmt, ap );
00061     va_end( ap );
00062   }
00063 
00064 
00065   /* documentation is in ftdebug.h */
00066 
00067   FT_BASE_DEF( void )
00068   FT_Panic( const char*  fmt, ... )
00069   {
00070     va_list  ap;
00071 
00072 
00073     va_start( ap, fmt );
00074     vfprintf( stderr, fmt, ap );
00075     va_end( ap );
00076 
00077     exit( EXIT_FAILURE );
00078   }
00079 
00080 #endif /* FT_DEBUG_LEVEL_ERROR */
00081 
00082 
00083 
00084 #ifdef FT_DEBUG_LEVEL_TRACE
00085 
00086   /* array of trace levels, initialized to 0 */
00087   int  ft_trace_levels[trace_count];
00088 
00089 
00090   /* define array of trace toggle names */
00091 #define FT_TRACE_DEF( x )  #x ,
00092 
00093   static const char*  ft_trace_toggles[trace_count + 1] =
00094   {
00095 #include FT_INTERNAL_TRACE_H
00096     NULL
00097   };
00098 
00099 #undef FT_TRACE_DEF
00100 
00101 
00102   /* documentation is in ftdebug.h */
00103 
00104   FT_BASE_DEF( FT_Int )
00105   FT_Trace_Get_Count( void )
00106   {
00107     return trace_count;
00108   }
00109 
00110 
00111   /* documentation is in ftdebug.h */
00112 
00113   FT_BASE_DEF( const char * )
00114   FT_Trace_Get_Name( FT_Int  idx )
00115   {
00116     int  max = FT_Trace_Get_Count();
00117 
00118 
00119     if ( idx < max )
00120       return ft_trace_toggles[idx];
00121     else
00122       return NULL;
00123   }
00124 
00125 
00126   /*************************************************************************/
00127   /*                                                                       */
00128   /* Initialize the tracing sub-system.  This is done by retrieving the    */
00129   /* value of the `FT2_DEBUG' environment variable.  It must be a list of  */
00130   /* toggles, separated by spaces, `;', or `,'.  Example:                  */
00131   /*                                                                       */
00132   /*    export FT2_DEBUG="any:3 memory:7 stream:5"                         */
00133   /*                                                                       */
00134   /* This requests that all levels be set to 3, except the trace level for */
00135   /* the memory and stream components which are set to 7 and 5,            */
00136   /* respectively.                                                         */
00137   /*                                                                       */
00138   /* See the file <include/freetype/internal/fttrace.h> for details of the */
00139   /* available toggle names.                                               */
00140   /*                                                                       */
00141   /* The level must be between 0 and 7; 0 means quiet (except for serious  */
00142   /* runtime errors), and 7 means _very_ verbose.                          */
00143   /*                                                                       */
00144   FT_BASE_DEF( void )
00145   ft_debug_init( void )
00146   {
00147     const char*  ft2_debug = getenv( "FT2_DEBUG" );
00148 
00149 
00150     if ( ft2_debug )
00151     {
00152       const char*  p = ft2_debug;
00153       const char*  q;
00154 
00155 
00156       for ( ; *p; p++ )
00157       {
00158         /* skip leading whitespace and separators */
00159         if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' )
00160           continue;
00161 
00162         /* read toggle name, followed by ':' */
00163         q = p;
00164         while ( *p && *p != ':' )
00165           p++;
00166 
00167         if ( *p == ':' && p > q )
00168         {
00169           FT_Int  n, i, len = (FT_Int)( p - q );
00170           FT_Int  level = -1, found = -1;
00171 
00172 
00173           for ( n = 0; n < trace_count; n++ )
00174           {
00175             const char*  toggle = ft_trace_toggles[n];
00176 
00177 
00178             for ( i = 0; i < len; i++ )
00179             {
00180               if ( toggle[i] != q[i] )
00181                 break;
00182             }
00183 
00184             if ( i == len && toggle[i] == 0 )
00185             {
00186               found = n;
00187               break;
00188             }
00189           }
00190 
00191           /* read level */
00192           p++;
00193           if ( *p )
00194           {
00195             level = *p++ - '0';
00196             if ( level < 0 || level > 7 )
00197               level = -1;
00198           }
00199 
00200           if ( found >= 0 && level >= 0 )
00201           {
00202             if ( found == trace_any )
00203             {
00204               /* special case for `any' */
00205               for ( n = 0; n < trace_count; n++ )
00206                 ft_trace_levels[n] = level;
00207             }
00208             else
00209               ft_trace_levels[found] = level;
00210           }
00211         }
00212       }
00213     }
00214   }
00215 
00216 
00217 #else  /* !FT_DEBUG_LEVEL_TRACE */
00218 
00219 
00220   FT_BASE_DEF( void )
00221   ft_debug_init( void )
00222   {
00223     /* nothing */
00224   }
00225 
00226 
00227   FT_BASE_DEF( FT_Int )
00228   FT_Trace_Get_Count( void )
00229   {
00230     return 0;
00231   }
00232 
00233 
00234   FT_BASE_DEF( const char * )
00235   FT_Trace_Get_Name( FT_Int  idx )
00236   {
00237     FT_UNUSED( idx );
00238 
00239     return NULL;
00240   }
00241 
00242 
00243 #endif /* !FT_DEBUG_LEVEL_TRACE */
00244 
00245 
00246 /* END */

Generated on Tue Jul 5 14:13:34 2011 for ROOT_528-00b_version by  doxygen 1.5.1