ftdebug.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /***************************************************************************/
  2. /* */
  3. /* ftdebug.h */
  4. /* */
  5. /* Debugging and logging component (specification). */
  6. /* */
  7. /* Copyright 1996-2002, 2004, 2006-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. /* IMPORTANT: A description of FreeType's debugging support can be */
  18. /* found in `docs/DEBUG.TXT'. Read it if you need to use or */
  19. /* understand this code. */
  20. /* */
  21. /***************************************************************************/
  22. #ifndef __FTDEBUG_H__
  23. #define __FTDEBUG_H__
  24. #include <ft2build.h>
  25. #include FT_CONFIG_CONFIG_H
  26. #include FT_FREETYPE_H
  27. FT_BEGIN_HEADER
  28. /* force the definition of FT_DEBUG_LEVEL_ERROR if FT_DEBUG_LEVEL_TRACE */
  29. /* is already defined; this simplifies the following #ifdefs */
  30. /* */
  31. #ifdef FT_DEBUG_LEVEL_TRACE
  32. #undef FT_DEBUG_LEVEL_ERROR
  33. #define FT_DEBUG_LEVEL_ERROR
  34. #endif
  35. /*************************************************************************/
  36. /* */
  37. /* Define the trace enums as well as the trace levels array when they */
  38. /* are needed. */
  39. /* */
  40. /*************************************************************************/
  41. #ifdef FT_DEBUG_LEVEL_TRACE
  42. #define FT_TRACE_DEF( x ) trace_ ## x ,
  43. /* defining the enumeration */
  44. typedef enum FT_Trace_
  45. {
  46. #include FT_INTERNAL_TRACE_H
  47. trace_count
  48. } FT_Trace;
  49. /* defining the array of trace levels, provided by `src/base/ftdebug.c' */
  50. extern int ft_trace_levels[trace_count];
  51. #undef FT_TRACE_DEF
  52. #endif /* FT_DEBUG_LEVEL_TRACE */
  53. /*************************************************************************/
  54. /* */
  55. /* Define the FT_TRACE macro */
  56. /* */
  57. /* IMPORTANT! */
  58. /* */
  59. /* Each component must define the macro FT_COMPONENT to a valid FT_Trace */
  60. /* value before using any TRACE macro. */
  61. /* */
  62. /*************************************************************************/
  63. #ifdef FT_DEBUG_LEVEL_TRACE
  64. #define FT_TRACE( level, varformat ) \
  65. do \
  66. { \
  67. if ( ft_trace_levels[FT_COMPONENT] >= level ) \
  68. FT_Message varformat; \
  69. } while ( 0 )
  70. #else /* !FT_DEBUG_LEVEL_TRACE */
  71. #define FT_TRACE( level, varformat ) do { } while ( 0 ) /* nothing */
  72. #endif /* !FT_DEBUG_LEVEL_TRACE */
  73. /*************************************************************************/
  74. /* */
  75. /* <Function> */
  76. /* FT_Trace_Get_Count */
  77. /* */
  78. /* <Description> */
  79. /* Return the number of available trace components. */
  80. /* */
  81. /* <Return> */
  82. /* The number of trace components. 0 if FreeType 2 is not built with */
  83. /* FT_DEBUG_LEVEL_TRACE definition. */
  84. /* */
  85. /* <Note> */
  86. /* This function may be useful if you want to access elements of */
  87. /* the internal `ft_trace_levels' array by an index. */
  88. /* */
  89. FT_BASE( FT_Int )
  90. FT_Trace_Get_Count( void );
  91. /*************************************************************************/
  92. /* */
  93. /* <Function> */
  94. /* FT_Trace_Get_Name */
  95. /* */
  96. /* <Description> */
  97. /* Return the name of a trace component. */
  98. /* */
  99. /* <Input> */
  100. /* The index of the trace component. */
  101. /* */
  102. /* <Return> */
  103. /* The name of the trace component. This is a statically allocated */
  104. /* C string, so do not free it after use. NULL if FreeType 2 is not */
  105. /* built with FT_DEBUG_LEVEL_TRACE definition. */
  106. /* */
  107. /* <Note> */
  108. /* Use @FT_Trace_Get_Count to get the number of available trace */
  109. /* components. */
  110. /* */
  111. /* This function may be useful if you want to control FreeType 2's */
  112. /* debug level in your application. */
  113. /* */
  114. FT_BASE( const char * )
  115. FT_Trace_Get_Name( FT_Int idx );
  116. /*************************************************************************/
  117. /* */
  118. /* You need two opening and closing parentheses! */
  119. /* */
  120. /* Example: FT_TRACE0(( "Value is %i", foo )) */
  121. /* */
  122. /* Output of the FT_TRACEX macros is sent to stderr. */
  123. /* */
  124. /*************************************************************************/
  125. #define FT_TRACE0( varformat ) FT_TRACE( 0, varformat )
  126. #define FT_TRACE1( varformat ) FT_TRACE( 1, varformat )
  127. #define FT_TRACE2( varformat ) FT_TRACE( 2, varformat )
  128. #define FT_TRACE3( varformat ) FT_TRACE( 3, varformat )
  129. #define FT_TRACE4( varformat ) FT_TRACE( 4, varformat )
  130. #define FT_TRACE5( varformat ) FT_TRACE( 5, varformat )
  131. #define FT_TRACE6( varformat ) FT_TRACE( 6, varformat )
  132. #define FT_TRACE7( varformat ) FT_TRACE( 7, varformat )
  133. /*************************************************************************/
  134. /* */
  135. /* Define the FT_ERROR macro. */
  136. /* */
  137. /* Output of this macro is sent to stderr. */
  138. /* */
  139. /*************************************************************************/
  140. #ifdef FT_DEBUG_LEVEL_ERROR
  141. #define FT_ERROR( varformat ) FT_Message varformat
  142. #else /* !FT_DEBUG_LEVEL_ERROR */
  143. #define FT_ERROR( varformat ) do { } while ( 0 ) /* nothing */
  144. #endif /* !FT_DEBUG_LEVEL_ERROR */
  145. /*************************************************************************/
  146. /* */
  147. /* Define the FT_ASSERT and FT_THROW macros. The call to `FT_Throw' */
  148. /* makes it possible to easily set a breakpoint at this function. */
  149. /* */
  150. /*************************************************************************/
  151. #ifdef FT_DEBUG_LEVEL_ERROR
  152. #define FT_ASSERT( condition ) \
  153. do \
  154. { \
  155. if ( !( condition ) ) \
  156. FT_Panic( "assertion failed on line %d of file %s\n", \
  157. __LINE__, __FILE__ ); \
  158. } while ( 0 )
  159. #define FT_THROW( e ) \
  160. ( FT_Throw( FT_ERR_CAT( FT_ERR_PREFIX, e ), \
  161. __LINE__, \
  162. __FILE__ ) | \
  163. FT_ERR_CAT( FT_ERR_PREFIX, e ) )
  164. #else /* !FT_DEBUG_LEVEL_ERROR */
  165. #define FT_ASSERT( condition ) do { } while ( 0 )
  166. #define FT_THROW( e ) FT_ERR_CAT( FT_ERR_PREFIX, e )
  167. #endif /* !FT_DEBUG_LEVEL_ERROR */
  168. /*************************************************************************/
  169. /* */
  170. /* Define `FT_Message' and `FT_Panic' when needed. */
  171. /* */
  172. /*************************************************************************/
  173. #ifdef FT_DEBUG_LEVEL_ERROR
  174. #include "stdio.h" /* for vfprintf() */
  175. /* print a message */
  176. FT_BASE( void )
  177. FT_Message( const char* fmt,
  178. ... );
  179. /* print a message and exit */
  180. FT_BASE( void )
  181. FT_Panic( const char* fmt,
  182. ... );
  183. /* report file name and line number of an error */
  184. FT_BASE( int )
  185. FT_Throw( FT_Error error,
  186. int line,
  187. const char* file );
  188. #endif /* FT_DEBUG_LEVEL_ERROR */
  189. FT_BASE( void )
  190. ft_debug_init( void );
  191. FT_END_HEADER
  192. #endif /* __FTDEBUG_H__ */
  193. /* END */