Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
ftdebug.c
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* ftdebug.c */
4 /* */
5 /* Debugging and logging component for WinCE (body). */
6 /* */
7 /* Copyright 1996-2001, 2002, 2005, 2008, 2009, 2013 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  {
77  static char buf[8192];
78  va_list ap;
79 
80 
81  va_start( ap, fmt );
82  vprintf( fmt, ap );
83  /* send the string to the debugger as well */
84  vsprintf( buf, fmt, ap );
85  OutputDebugStringEx( buf );
86  va_end( ap );
87  }
88 
89 
90  FT_BASE_DEF( void )
91  FT_Panic( const char* fmt,
92  ... )
93  {
94  static char buf[8192];
95  va_list ap;
96 
97 
98  va_start( ap, fmt );
99  vsprintf( buf, fmt, ap );
100  OutputDebugStringEx( buf );
101  va_end( ap );
102 
103  exit( EXIT_FAILURE );
104  }
105 
106 
107  /* documentation is in ftdebug.h */
108 
109  FT_BASE_DEF( int )
110  FT_Throw( FT_Error error,
111  int line,
112  const char* file )
113  {
114  FT_UNUSED( error );
115  FT_UNUSED( line );
116  FT_UNUSED( file );
117 
118  return 0;
119  }
120 
121 #ifdef FT_DEBUG_LEVEL_TRACE
122 
123 
124  /* array of trace levels, initialized to 0 */
125  int ft_trace_levels[trace_count];
126 
127  /* define array of trace toggle names */
128 #define FT_TRACE_DEF( x ) #x ,
129 
130  static const char* ft_trace_toggles[trace_count + 1] =
131  {
132 #include FT_INTERNAL_TRACE_H
133  NULL
134  };
135 
136 #undef FT_TRACE_DEF
137 
138 
139  /*************************************************************************/
140  /* */
141  /* Initialize the tracing sub-system. This is done by retrieving the */
142  /* value of the "FT2_DEBUG" environment variable. It must be a list of */
143  /* toggles, separated by spaces, `;' or `,'. Example: */
144  /* */
145  /* "any:3 memory:6 stream:5" */
146  /* */
147  /* This will request that all levels be set to 3, except the trace level */
148  /* for the memory and stream components which are set to 6 and 5, */
149  /* respectively. */
150  /* */
151  /* See the file <freetype/internal/fttrace.h> for details of the */
152  /* available toggle names. */
153  /* */
154  /* The level must be between 0 and 6; 0 means quiet (except for serious */
155  /* runtime errors), and 6 means _very_ verbose. */
156  /* */
157  FT_BASE_DEF( void )
158  ft_debug_init( void )
159  {
160  /* Windows Mobile doesn't have environment API: */
161  /* GetEnvironmentStrings, GetEnvironmentVariable, getenv. */
162  /* */
163  /* FIXME!!! How to set debug mode? */
164 
165  /* const char* ft2_debug = getenv( "FT2_DEBUG" ); */
166 
167  const char* ft2_debug = 0;
168 
169 
170  if ( ft2_debug )
171  {
172  const char* p = ft2_debug;
173  const char* q;
174 
175 
176  for ( ; *p; p++ )
177  {
178  /* skip leading whitespace and separators */
179  if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' )
180  continue;
181 
182  /* read toggle name, followed by ':' */
183  q = p;
184  while ( *p && *p != ':' )
185  p++;
186 
187  if ( *p == ':' && p > q )
188  {
189  int n, i, len = p - q;
190  int level = -1, found = -1;
191 
192 
193  for ( n = 0; n < trace_count; n++ )
194  {
195  const char* toggle = ft_trace_toggles[n];
196 
197 
198  for ( i = 0; i < len; i++ )
199  {
200  if ( toggle[i] != q[i] )
201  break;
202  }
203 
204  if ( i == len && toggle[i] == 0 )
205  {
206  found = n;
207  break;
208  }
209  }
210 
211  /* read level */
212  p++;
213  if ( *p )
214  {
215  level = *p++ - '0';
216  if ( level < 0 || level > 7 )
217  level = -1;
218  }
219 
220  if ( found >= 0 && level >= 0 )
221  {
222  if ( found == trace_any )
223  {
224  /* special case for "any" */
225  for ( n = 0; n < trace_count; n++ )
226  ft_trace_levels[n] = level;
227  }
228  else
229  ft_trace_levels[found] = level;
230  }
231  }
232  }
233  }
234  }
235 
236 
237 #else /* !FT_DEBUG_LEVEL_TRACE */
238 
239 
240  FT_BASE_DEF( void )
241  ft_debug_init( void )
242  {
243  /* nothing */
244  }
245 
246 
247 #endif /* !FT_DEBUG_LEVEL_TRACE */
248 
249 #endif /* FT_DEBUG_LEVEL_ERROR */
250 
251 
252 /* END */
int FT_Error
Definition: fttypes.h:296
GLfloat GLfloat p
#define NULL
Definition: ftobjs.h:61
GLdouble GLdouble GLdouble GLdouble q
#define FT_UNUSED(arg)
Definition: ftconfig.h:76
png_uint_32 i
Definition: png.h:2640
GLenum GLuint GLenum GLsizei const GLchar * buf
#define FT_BASE_DEF(x)
Definition: ftconfig.h:258
GLenum GLsizei len
GLint level
FT_Error error
Definition: cffdrivr.c:411
GLdouble n
ft_debug_init(void)
Definition: ftdebug.c:265
#define EXIT_FAILURE
Definition: cdjpeg.h:169