~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/freetype/builds/win32/ftdebug.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************/
 
2
/*                                                                         */
 
3
/*  ftdebug.c                                                              */
 
4
/*                                                                         */
 
5
/*    Debugging and logging component for Win32 (body).                    */
 
6
/*                                                                         */
 
7
/*  Copyright 1996-2001, 2002 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
  FT_EXPORT_DEF( void )
 
59
  FT_Message( const char*  fmt, ... )
 
60
  {
 
61
    static char buf[8192];
 
62
    va_list     ap;
 
63
 
 
64
 
 
65
    va_start( ap, fmt );
 
66
    vsprintf( buf, fmt, ap );
 
67
    OutputDebugStringA( buf );
 
68
    va_end( ap );
 
69
  }
 
70
 
 
71
 
 
72
  FT_EXPORT_DEF( void )
 
73
  FT_Panic( const char*  fmt, ... )
 
74
  {
 
75
    static char buf[8192];
 
76
    va_list     ap;
 
77
 
 
78
 
 
79
    va_start( ap, fmt );
 
80
    vsprintf( buf, fmt, ap );
 
81
    OutputDebugStringA( buf );
 
82
    va_end( ap );
 
83
 
 
84
    exit( EXIT_FAILURE );
 
85
  }
 
86
 
 
87
 
 
88
#  ifdef FT_DEBUG_LEVEL_TRACE
 
89
 
 
90
 
 
91
  /* array of trace levels, initialized to 0 */
 
92
  int  ft_trace_levels[trace_count];
 
93
 
 
94
  /* define array of trace toggle names */
 
95
#    define FT_TRACE_DEF( x )  #x ,
 
96
 
 
97
  static const char*  ft_trace_toggles[trace_count + 1] =
 
98
  {
 
99
#    include FT_INTERNAL_TRACE_H
 
100
    NULL
 
101
  };
 
102
 
 
103
#    undef FT_TRACE_DEF
 
104
 
 
105
 
 
106
  /*************************************************************************/
 
107
  /*                                                                       */
 
108
  /* Initialize the tracing sub-system.  This is done by retrieving the    */
 
109
  /* value of the "FT2_DEBUG" environment variable.  It must be a list of  */
 
110
  /* toggles, separated by spaces, `;' or `,'.  Example:                   */
 
111
  /*                                                                       */
 
112
  /*    "any:3 memory:6 stream:5"                                          */
 
113
  /*                                                                       */
 
114
  /* This will request that all levels be set to 3, except the trace level */
 
115
  /* for the memory and stream components which are set to 6 and 5,        */
 
116
  /* respectively.                                                         */
 
117
  /*                                                                       */
 
118
  /* See the file <freetype/internal/fttrace.h> for details of the         */
 
119
  /* available toggle names.                                               */
 
120
  /*                                                                       */
 
121
  /* The level must be between 0 and 6; 0 means quiet (except for serious  */
 
122
  /* runtime errors), and 6 means _very_ verbose.                          */
 
123
  /*                                                                       */
 
124
  FT_BASE_DEF( void )
 
125
  ft_debug_init( void )
 
126
  {
 
127
    const char*  ft2_debug = getenv( "FT2_DEBUG" );
 
128
 
 
129
 
 
130
    if ( ft2_debug )
 
131
    {
 
132
      const char*  p = ft2_debug;
 
133
      const char*  q;
 
134
 
 
135
 
 
136
      for ( ; *p; p++ )
 
137
      {
 
138
        /* skip leading whitespace and separators */
 
139
        if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' )
 
140
          continue;
 
141
 
 
142
        /* read toggle name, followed by ':' */
 
143
        q = p;
 
144
        while ( *p && *p != ':' )
 
145
          p++;
 
146
 
 
147
        if ( *p == ':' && p > q )
 
148
        {
 
149
          int  n, i, len = p - q;
 
150
          int  level = -1, found = -1;
 
151
 
 
152
 
 
153
          for ( n = 0; n < trace_count; n++ )
 
154
          {
 
155
            const char*  toggle = ft_trace_toggles[n];
 
156
 
 
157
 
 
158
            for ( i = 0; i < len; i++ )
 
159
            {
 
160
              if ( toggle[i] != q[i] )
 
161
                break;
 
162
            }
 
163
 
 
164
            if ( i == len && toggle[i] == 0 )
 
165
            {
 
166
              found = n;
 
167
              break;
 
168
            }
 
169
          }
 
170
 
 
171
          /* read level */
 
172
          p++;
 
173
          if ( *p )
 
174
          {
 
175
            level = *p++ - '0';
 
176
            if ( level < 0 || level > 6 )
 
177
              level = -1;
 
178
          }
 
179
 
 
180
          if ( found >= 0 && level >= 0 )
 
181
          {
 
182
            if ( found == trace_any )
 
183
            {
 
184
              /* special case for "any" */
 
185
              for ( n = 0; n < trace_count; n++ )
 
186
                ft_trace_levels[n] = level;
 
187
            }
 
188
            else
 
189
              ft_trace_levels[found] = level;
 
190
          }
 
191
        }
 
192
      }
 
193
    }
 
194
  }
 
195
 
 
196
 
 
197
#  else  /* !FT_DEBUG_LEVEL_TRACE */
 
198
 
 
199
 
 
200
  FT_BASE_DEF( void )
 
201
  ft_debug_init( void )
 
202
  {
 
203
    /* nothing */
 
204
  }
 
205
 
 
206
 
 
207
#  endif /* !FT_DEBUG_LEVEL_TRACE */
 
208
 
 
209
#endif /* FT_DEBUG_LEVEL_ERROR */
 
210
 
 
211
/* END */