misc/libfreetype/builds/wince/ftdebug.c
changeset 9372 915436ff64ab
parent 9371 f3840de881bd
child 9373 b769a8e38cbd
equal deleted inserted replaced
9371:f3840de881bd 9372:915436ff64ab
     1 /***************************************************************************/
       
     2 /*                                                                         */
       
     3 /*  ftdebug.c                                                              */
       
     4 /*                                                                         */
       
     5 /*    Debugging and logging component for WinCE (body).                    */
       
     6 /*                                                                         */
       
     7 /*  Copyright 1996-2001, 2002, 2005, 2008, 2009 by                         */
       
     8 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
       
     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 #include <ft2build.h>
       
    45 #include FT_INTERNAL_DEBUG_H
       
    46 
       
    47 
       
    48 #ifdef FT_DEBUG_LEVEL_ERROR
       
    49 
       
    50 
       
    51 #include <stdarg.h>
       
    52 #include <stdlib.h>
       
    53 #include <string.h>
       
    54 
       
    55 #include <windows.h>
       
    56 
       
    57 
       
    58   void
       
    59   OutputDebugStringEx( const char*  str )
       
    60   {
       
    61     static WCHAR  buf[8192];
       
    62 
       
    63 
       
    64     int sz = MultiByteToWideChar( CP_ACP, 0, str, -1, buf,
       
    65                                   sizeof ( buf ) / sizeof ( *buf ) );
       
    66     if ( !sz )
       
    67       lstrcpyW( buf, L"OutputDebugStringEx: MultiByteToWideChar failed" );
       
    68 
       
    69     OutputDebugStringW( buf );
       
    70   }
       
    71 
       
    72 
       
    73   FT_BASE_DEF( void )
       
    74   FT_Message( const char*  fmt, ... )
       
    75   {
       
    76     static char  buf[8192];
       
    77     va_list      ap;
       
    78 
       
    79 
       
    80     va_start( ap, fmt );
       
    81     vprintf( fmt, ap );
       
    82     /* send the string to the debugger as well */
       
    83     vsprintf( buf, fmt, ap );
       
    84     OutputDebugStringEx( buf );
       
    85     va_end( ap );
       
    86   }
       
    87 
       
    88 
       
    89   FT_BASE_DEF( void )
       
    90   FT_Panic( const char*  fmt, ... )
       
    91   {
       
    92     static char  buf[8192];
       
    93     va_list      ap;
       
    94 
       
    95 
       
    96     va_start( ap, fmt );
       
    97     vsprintf( buf, fmt, ap );
       
    98     OutputDebugStringEx( buf );
       
    99     va_end( ap );
       
   100 
       
   101     exit( EXIT_FAILURE );
       
   102   }
       
   103 
       
   104 
       
   105 #ifdef FT_DEBUG_LEVEL_TRACE
       
   106 
       
   107 
       
   108   /* array of trace levels, initialized to 0 */
       
   109   int  ft_trace_levels[trace_count];
       
   110 
       
   111   /* define array of trace toggle names */
       
   112 #define FT_TRACE_DEF( x )  #x ,
       
   113 
       
   114   static const char*  ft_trace_toggles[trace_count + 1] =
       
   115   {
       
   116 #include FT_INTERNAL_TRACE_H
       
   117     NULL
       
   118   };
       
   119 
       
   120 #undef FT_TRACE_DEF
       
   121 
       
   122 
       
   123   /*************************************************************************/
       
   124   /*                                                                       */
       
   125   /* Initialize the tracing sub-system.  This is done by retrieving the    */
       
   126   /* value of the "FT2_DEBUG" environment variable.  It must be a list of  */
       
   127   /* toggles, separated by spaces, `;' or `,'.  Example:                   */
       
   128   /*                                                                       */
       
   129   /*    "any:3 memory:6 stream:5"                                          */
       
   130   /*                                                                       */
       
   131   /* This will request that all levels be set to 3, except the trace level */
       
   132   /* for the memory and stream components which are set to 6 and 5,        */
       
   133   /* respectively.                                                         */
       
   134   /*                                                                       */
       
   135   /* See the file <freetype/internal/fttrace.h> for details of the         */
       
   136   /* available toggle names.                                               */
       
   137   /*                                                                       */
       
   138   /* The level must be between 0 and 6; 0 means quiet (except for serious  */
       
   139   /* runtime errors), and 6 means _very_ verbose.                          */
       
   140   /*                                                                       */
       
   141   FT_BASE_DEF( void )
       
   142   ft_debug_init( void )
       
   143   {
       
   144     /* Windows Mobile doesn't have environment API:           */
       
   145     /* GetEnvironmentStrings, GetEnvironmentVariable, getenv. */
       
   146     /*                                                        */
       
   147     /* FIXME!!! How to set debug mode?                        */
       
   148 
       
   149     /* const char*  ft2_debug = getenv( "FT2_DEBUG" ); */
       
   150 
       
   151     const char*  ft2_debug = 0;
       
   152 
       
   153 
       
   154     if ( ft2_debug )
       
   155     {
       
   156       const char*  p = ft2_debug;
       
   157       const char*  q;
       
   158 
       
   159 
       
   160       for ( ; *p; p++ )
       
   161       {
       
   162         /* skip leading whitespace and separators */
       
   163         if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' )
       
   164           continue;
       
   165 
       
   166         /* read toggle name, followed by ':' */
       
   167         q = p;
       
   168         while ( *p && *p != ':' )
       
   169           p++;
       
   170 
       
   171         if ( *p == ':' && p > q )
       
   172         {
       
   173           int  n, i, len = p - q;
       
   174           int  level = -1, found = -1;
       
   175 
       
   176 
       
   177           for ( n = 0; n < trace_count; n++ )
       
   178           {
       
   179             const char*  toggle = ft_trace_toggles[n];
       
   180 
       
   181 
       
   182             for ( i = 0; i < len; i++ )
       
   183             {
       
   184               if ( toggle[i] != q[i] )
       
   185                 break;
       
   186             }
       
   187 
       
   188             if ( i == len && toggle[i] == 0 )
       
   189             {
       
   190               found = n;
       
   191               break;
       
   192             }
       
   193           }
       
   194 
       
   195           /* read level */
       
   196           p++;
       
   197           if ( *p )
       
   198           {
       
   199             level = *p++ - '0';
       
   200             if ( level < 0 || level > 7 )
       
   201               level = -1;
       
   202           }
       
   203 
       
   204           if ( found >= 0 && level >= 0 )
       
   205           {
       
   206             if ( found == trace_any )
       
   207             {
       
   208               /* special case for "any" */
       
   209               for ( n = 0; n < trace_count; n++ )
       
   210                 ft_trace_levels[n] = level;
       
   211             }
       
   212             else
       
   213               ft_trace_levels[found] = level;
       
   214           }
       
   215         }
       
   216       }
       
   217     }
       
   218   }
       
   219 
       
   220 
       
   221 #else  /* !FT_DEBUG_LEVEL_TRACE */
       
   222 
       
   223 
       
   224   FT_BASE_DEF( void )
       
   225   ft_debug_init( void )
       
   226   {
       
   227     /* nothing */
       
   228   }
       
   229 
       
   230 
       
   231 #endif /* !FT_DEBUG_LEVEL_TRACE */
       
   232 
       
   233 #endif /* FT_DEBUG_LEVEL_ERROR */
       
   234 
       
   235 
       
   236 /* END */