/src/compiler/android-ndk/jni/freetype/src/base/ftdebug.c

http://ftk.googlecode.com/ · C · 246 lines · 116 code · 61 blank · 69 comment · 35 complexity · f9cf0ce7e96fbc1dd553bbdf110d7d37 MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* ftdebug.c */
  4. /* */
  5. /* Debugging and logging component (body). */
  6. /* */
  7. /* Copyright 1996-2001, 2002, 2004, 2008 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. /* This component contains various macros and functions used to ease the */
  20. /* debugging of the FreeType engine. Its main purpose is in assertion */
  21. /* checking, tracing, and error detection. */
  22. /* */
  23. /* There are now three debugging modes: */
  24. /* */
  25. /* - trace mode */
  26. /* */
  27. /* Error and trace messages are sent to the log file (which can be the */
  28. /* standard error output). */
  29. /* */
  30. /* - error mode */
  31. /* */
  32. /* Only error messages are generated. */
  33. /* */
  34. /* - release mode: */
  35. /* */
  36. /* No error message is sent or generated. The code is free from any */
  37. /* debugging parts. */
  38. /* */
  39. /*************************************************************************/
  40. #include <ft2build.h>
  41. #include FT_FREETYPE_H
  42. #include FT_INTERNAL_DEBUG_H
  43. #ifdef FT_DEBUG_LEVEL_ERROR
  44. /* documentation is in ftdebug.h */
  45. FT_BASE_DEF( void )
  46. FT_Message( const char* fmt, ... )
  47. {
  48. va_list ap;
  49. va_start( ap, fmt );
  50. vfprintf( stderr, fmt, ap );
  51. va_end( ap );
  52. }
  53. /* documentation is in ftdebug.h */
  54. FT_BASE_DEF( void )
  55. FT_Panic( const char* fmt, ... )
  56. {
  57. va_list ap;
  58. va_start( ap, fmt );
  59. vfprintf( stderr, fmt, ap );
  60. va_end( ap );
  61. exit( EXIT_FAILURE );
  62. }
  63. #endif /* FT_DEBUG_LEVEL_ERROR */
  64. #ifdef FT_DEBUG_LEVEL_TRACE
  65. /* array of trace levels, initialized to 0 */
  66. int ft_trace_levels[trace_count];
  67. /* define array of trace toggle names */
  68. #define FT_TRACE_DEF( x ) #x ,
  69. static const char* ft_trace_toggles[trace_count + 1] =
  70. {
  71. #include FT_INTERNAL_TRACE_H
  72. NULL
  73. };
  74. #undef FT_TRACE_DEF
  75. /* documentation is in ftdebug.h */
  76. FT_BASE_DEF( FT_Int )
  77. FT_Trace_Get_Count( void )
  78. {
  79. return trace_count;
  80. }
  81. /* documentation is in ftdebug.h */
  82. FT_BASE_DEF( const char * )
  83. FT_Trace_Get_Name( FT_Int idx )
  84. {
  85. int max = FT_Trace_Get_Count();
  86. if ( idx < max )
  87. return ft_trace_toggles[idx];
  88. else
  89. return NULL;
  90. }
  91. /*************************************************************************/
  92. /* */
  93. /* Initialize the tracing sub-system. This is done by retrieving the */
  94. /* value of the `FT2_DEBUG' environment variable. It must be a list of */
  95. /* toggles, separated by spaces, `;', or `,'. Example: */
  96. /* */
  97. /* export FT2_DEBUG="any:3 memory:7 stream:5" */
  98. /* */
  99. /* This requests that all levels be set to 3, except the trace level for */
  100. /* the memory and stream components which are set to 7 and 5, */
  101. /* respectively. */
  102. /* */
  103. /* See the file <include/freetype/internal/fttrace.h> for details of the */
  104. /* available toggle names. */
  105. /* */
  106. /* The level must be between 0 and 7; 0 means quiet (except for serious */
  107. /* runtime errors), and 7 means _very_ verbose. */
  108. /* */
  109. FT_BASE_DEF( void )
  110. ft_debug_init( void )
  111. {
  112. const char* ft2_debug = getenv( "FT2_DEBUG" );
  113. if ( ft2_debug )
  114. {
  115. const char* p = ft2_debug;
  116. const char* q;
  117. for ( ; *p; p++ )
  118. {
  119. /* skip leading whitespace and separators */
  120. if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' )
  121. continue;
  122. /* read toggle name, followed by ':' */
  123. q = p;
  124. while ( *p && *p != ':' )
  125. p++;
  126. if ( *p == ':' && p > q )
  127. {
  128. FT_Int n, i, len = (FT_Int)( p - q );
  129. FT_Int level = -1, found = -1;
  130. for ( n = 0; n < trace_count; n++ )
  131. {
  132. const char* toggle = ft_trace_toggles[n];
  133. for ( i = 0; i < len; i++ )
  134. {
  135. if ( toggle[i] != q[i] )
  136. break;
  137. }
  138. if ( i == len && toggle[i] == 0 )
  139. {
  140. found = n;
  141. break;
  142. }
  143. }
  144. /* read level */
  145. p++;
  146. if ( *p )
  147. {
  148. level = *p++ - '0';
  149. if ( level < 0 || level > 7 )
  150. level = -1;
  151. }
  152. if ( found >= 0 && level >= 0 )
  153. {
  154. if ( found == trace_any )
  155. {
  156. /* special case for `any' */
  157. for ( n = 0; n < trace_count; n++ )
  158. ft_trace_levels[n] = level;
  159. }
  160. else
  161. ft_trace_levels[found] = level;
  162. }
  163. }
  164. }
  165. }
  166. }
  167. #else /* !FT_DEBUG_LEVEL_TRACE */
  168. FT_BASE_DEF( void )
  169. ft_debug_init( void )
  170. {
  171. /* nothing */
  172. }
  173. FT_BASE_DEF( FT_Int )
  174. FT_Trace_Get_Count( void )
  175. {
  176. return 0;
  177. }
  178. FT_BASE_DEF( const char * )
  179. FT_Trace_Get_Name( FT_Int idx )
  180. {
  181. FT_UNUSED( idx );
  182. return NULL;
  183. }
  184. #endif /* !FT_DEBUG_LEVEL_TRACE */
  185. /* END */