ftdebug.c

Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  ftdebug.c                                                              */
00004 /*                                                                         */
00005 /*    Debugging and logging component for Win32 (body).                    */
00006 /*                                                                         */
00007 /*  Copyright 1996-2001, 2002, 2005, 2008, 2009 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_INTERNAL_DEBUG_H
00046 
00047 
00048 #ifdef FT_DEBUG_LEVEL_ERROR
00049 
00050 
00051 #include <stdarg.h>
00052 #include <stdlib.h>
00053 #include <string.h>
00054 
00055 #include <windows.h>
00056 
00057 
00058   FT_BASE_DEF( void )
00059   FT_Message( const char*  fmt, ... )
00060   {
00061     static char  buf[8192];
00062     va_list      ap;
00063 
00064 
00065     va_start( ap, fmt );
00066     vprintf( fmt, ap );
00067     /* send the string to the debugger as well */
00068     vsprintf( buf, fmt, ap );
00069     OutputDebugStringA( buf );
00070     va_end( ap );
00071   }
00072 
00073 
00074   FT_BASE_DEF( void )
00075   FT_Panic( const char*  fmt, ... )
00076   {
00077     static char  buf[8192];
00078     va_list      ap;
00079 
00080 
00081     va_start( ap, fmt );
00082     vsprintf( buf, fmt, ap );
00083     OutputDebugStringA( buf );
00084     va_end( ap );
00085 
00086     exit( EXIT_FAILURE );
00087   }
00088 
00089 
00090 #ifdef FT_DEBUG_LEVEL_TRACE
00091 
00092 
00093   /* array of trace levels, initialized to 0 */
00094   int  ft_trace_levels[trace_count];
00095 
00096   /* define array of trace toggle names */
00097 #define FT_TRACE_DEF( x )  #x ,
00098 
00099   static const char*  ft_trace_toggles[trace_count + 1] =
00100   {
00101 #include FT_INTERNAL_TRACE_H
00102     NULL
00103   };
00104 
00105 #undef FT_TRACE_DEF
00106 
00107 
00108   /*************************************************************************/
00109   /*                                                                       */
00110   /* Initialize the tracing sub-system.  This is done by retrieving the    */
00111   /* value of the "FT2_DEBUG" environment variable.  It must be a list of  */
00112   /* toggles, separated by spaces, `;' or `,'.  Example:                   */
00113   /*                                                                       */
00114   /*    "any:3 memory:6 stream:5"                                          */
00115   /*                                                                       */
00116   /* This will request that all levels be set to 3, except the trace level */
00117   /* for the memory and stream components which are set to 6 and 5,        */
00118   /* respectively.                                                         */
00119   /*                                                                       */
00120   /* See the file <freetype/internal/fttrace.h> for details of the         */
00121   /* available toggle names.                                               */
00122   /*                                                                       */
00123   /* The level must be between 0 and 6; 0 means quiet (except for serious  */
00124   /* runtime errors), and 6 means _very_ verbose.                          */
00125   /*                                                                       */
00126   FT_BASE_DEF( void )
00127   ft_debug_init( void )
00128   {
00129     const char*  ft2_debug = getenv( "FT2_DEBUG" );
00130 
00131 
00132     if ( ft2_debug )
00133     {
00134       const char*  p = ft2_debug;
00135       const char*  q;
00136 
00137 
00138       for ( ; *p; p++ )
00139       {
00140         /* skip leading whitespace and separators */
00141         if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' )
00142           continue;
00143 
00144         /* read toggle name, followed by ':' */
00145         q = p;
00146         while ( *p && *p != ':' )
00147           p++;
00148 
00149         if ( *p == ':' && p > q )
00150         {
00151           int  n, i, len = p - q;
00152           int  level = -1, found = -1;
00153 
00154 
00155           for ( n = 0; n < trace_count; n++ )
00156           {
00157             const char*  toggle = ft_trace_toggles[n];
00158 
00159 
00160             for ( i = 0; i < len; i++ )
00161             {
00162               if ( toggle[i] != q[i] )
00163                 break;
00164             }
00165 
00166             if ( i == len && toggle[i] == 0 )
00167             {
00168               found = n;
00169               break;
00170             }
00171           }
00172 
00173           /* read level */
00174           p++;
00175           if ( *p )
00176           {
00177             level = *p++ - '0';
00178             if ( level < 0 || level > 7 )
00179               level = -1;
00180           }
00181 
00182           if ( found >= 0 && level >= 0 )
00183           {
00184             if ( found == trace_any )
00185             {
00186               /* special case for "any" */
00187               for ( n = 0; n < trace_count; n++ )
00188                 ft_trace_levels[n] = level;
00189             }
00190             else
00191               ft_trace_levels[found] = level;
00192           }
00193         }
00194       }
00195     }
00196   }
00197 
00198 
00199 #else  /* !FT_DEBUG_LEVEL_TRACE */
00200 
00201 
00202   FT_BASE_DEF( void )
00203   ft_debug_init( void )
00204   {
00205     /* nothing */
00206   }
00207 
00208 
00209 #endif /* !FT_DEBUG_LEVEL_TRACE */
00210 
00211 #endif /* FT_DEBUG_LEVEL_ERROR */
00212 
00213 
00214 /* END */

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