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

« back to all changes in this revision

Viewing changes to src/3rdparty/freetype/src/base/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 (body).                              */
 
6
/*                                                                         */
 
7
/*  Copyright 1996-2001, 2002, 2004 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_FREETYPE_H
 
46
#include FT_INTERNAL_DEBUG_H
 
47
 
 
48
 
 
49
#if defined( FT_DEBUG_LEVEL_ERROR )
 
50
 
 
51
  FT_EXPORT_DEF( void )
 
52
  FT_Message( const char*  fmt, ... )
 
53
  {
 
54
    va_list  ap;
 
55
 
 
56
 
 
57
    va_start( ap, fmt );
 
58
    vprintf( fmt, ap );
 
59
    va_end( ap );
 
60
  }
 
61
 
 
62
 
 
63
  FT_EXPORT_DEF( void )
 
64
  FT_Panic( const char*  fmt, ... )
 
65
  {
 
66
    va_list  ap;
 
67
 
 
68
 
 
69
    va_start( ap, fmt );
 
70
    vprintf( fmt, ap );
 
71
    va_end( ap );
 
72
 
 
73
    exit( EXIT_FAILURE );
 
74
  }
 
75
 
 
76
#endif /* FT_DEBUG_LEVEL_ERROR */
 
77
 
 
78
 
 
79
 
 
80
#ifdef FT_DEBUG_LEVEL_TRACE
 
81
 
 
82
  /* array of trace levels, initialized to 0 */
 
83
  int  ft_trace_levels[trace_count];
 
84
 
 
85
 
 
86
  /* define array of trace toggle names */
 
87
#define FT_TRACE_DEF( x )  #x ,
 
88
 
 
89
  static const char*  ft_trace_toggles[trace_count + 1] =
 
90
  {
 
91
#include FT_INTERNAL_TRACE_H
 
92
    NULL
 
93
  };
 
94
 
 
95
#undef FT_TRACE_DEF
 
96
 
 
97
 
 
98
  /* documentation is in ftdebug.h */
 
99
 
 
100
  FT_EXPORT_DEF( FT_Int )
 
101
  FT_Trace_Get_Count( void )
 
102
  {
 
103
    return trace_count;
 
104
  }
 
105
 
 
106
 
 
107
  /* documentation is in ftdebug.h */
 
108
 
 
109
  FT_EXPORT_DEF( const char * )
 
110
  FT_Trace_Get_Name( FT_Int  idx )
 
111
  {
 
112
    int  max = FT_Trace_Get_Count();
 
113
 
 
114
 
 
115
    if ( idx < max )
 
116
      return ft_trace_toggles[idx];
 
117
    else
 
118
      return NULL;
 
119
  }
 
120
 
 
121
 
 
122
  /*************************************************************************/
 
123
  /*                                                                       */
 
124
  /* Initialize the tracing sub-system.  This is done by retrieving the    */
 
125
  /* value of the `FT2_DEBUG' environment variable.  It must be a list of  */
 
126
  /* toggles, separated by spaces, `;', or `,'.  Example:                  */
 
127
  /*                                                                       */
 
128
  /*    export FT2_DEBUG="any:3 memory:6 stream:5"                         */
 
129
  /*                                                                       */
 
130
  /* This requests that all levels be set to 3, except the trace level for */
 
131
  /* the memory and stream components which are set to 6 and 5,            */
 
132
  /* respectively.                                                         */
 
133
  /*                                                                       */
 
134
  /* See the file <include/freetype/internal/fttrace.h> for details of the */
 
135
  /* available toggle names.                                               */
 
136
  /*                                                                       */
 
137
  /* The level must be between 0 and 6; 0 means quiet (except for serious  */
 
138
  /* runtime errors), and 6 means _very_ verbose.                          */
 
139
  /*                                                                       */
 
140
  FT_BASE_DEF( void )
 
141
  ft_debug_init( void )
 
142
  {
 
143
    const char*  ft2_debug = getenv( "FT2_DEBUG" );
 
144
 
 
145
 
 
146
    if ( ft2_debug )
 
147
    {
 
148
      const char*  p = ft2_debug;
 
149
      const char*  q;
 
150
 
 
151
 
 
152
      for ( ; *p; p++ )
 
153
      {
 
154
        /* skip leading whitespace and separators */
 
155
        if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' )
 
156
          continue;
 
157
 
 
158
        /* read toggle name, followed by ':' */
 
159
        q = p;
 
160
        while ( *p && *p != ':' )
 
161
          p++;
 
162
 
 
163
        if ( *p == ':' && p > q )
 
164
        {
 
165
          FT_Int  n, i, len = (FT_Int)( p - q );
 
166
          FT_Int  level = -1, found = -1;
 
167
 
 
168
 
 
169
          for ( n = 0; n < trace_count; n++ )
 
170
          {
 
171
            const char*  toggle = ft_trace_toggles[n];
 
172
 
 
173
 
 
174
            for ( i = 0; i < len; i++ )
 
175
            {
 
176
              if ( toggle[i] != q[i] )
 
177
                break;
 
178
            }
 
179
 
 
180
            if ( i == len && toggle[i] == 0 )
 
181
            {
 
182
              found = n;
 
183
              break;
 
184
            }
 
185
          }
 
186
 
 
187
          /* read level */
 
188
          p++;
 
189
          if ( *p )
 
190
          {
 
191
            level = *p++ - '0';
 
192
            if ( level < 0 || level > 6 )
 
193
              level = -1;
 
194
          }
 
195
 
 
196
          if ( found >= 0 && level >= 0 )
 
197
          {
 
198
            if ( found == trace_any )
 
199
            {
 
200
              /* special case for `any' */
 
201
              for ( n = 0; n < trace_count; n++ )
 
202
                ft_trace_levels[n] = level;
 
203
            }
 
204
            else
 
205
              ft_trace_levels[found] = level;
 
206
          }
 
207
        }
 
208
      }
 
209
    }
 
210
  }
 
211
 
 
212
 
 
213
#else  /* !FT_DEBUG_LEVEL_TRACE */
 
214
 
 
215
 
 
216
  FT_BASE_DEF( void )
 
217
  ft_debug_init( void )
 
218
  {
 
219
    /* nothing */
 
220
  }
 
221
 
 
222
 
 
223
  FT_EXPORT_DEF( FT_Int )
 
224
  FT_Trace_Get_Count( void )
 
225
  {
 
226
    return 0;
 
227
  }
 
228
 
 
229
 
 
230
  FT_EXPORT_DEF( const char * )
 
231
  FT_Trace_Get_Name( FT_Int  idx )
 
232
  {
 
233
    FT_UNUSED( idx );
 
234
 
 
235
    return NULL;
 
236
  }
 
237
 
 
238
 
 
239
#endif /* !FT_DEBUG_LEVEL_TRACE */
 
240
 
 
241
 
 
242
/* END */