ftdebug.c

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

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