fterrors.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /***************************************************************************/
  2. /* */
  3. /* fterrors.h */
  4. /* */
  5. /* FreeType error code handling (specification). */
  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. /* This special header file is used to define the handling of FT2 */
  20. /* enumeration constants. It can also be used to generate error message */
  21. /* strings with a small macro trick explained below. */
  22. /* */
  23. /* I - Error Formats */
  24. /* ----------------- */
  25. /* */
  26. /* Since release 2.1, the error constants have changed. The lower */
  27. /* byte of the error value gives the "generic" error code, while the */
  28. /* higher byte indicates in which module the error occurred. */
  29. /* */
  30. /* You can use the macro FT_ERROR_BASE(x) macro to extract the generic */
  31. /* error code from an FT_Error value. */
  32. /* */
  33. /* The configuration macro FT_CONFIG_OPTION_USE_MODULE_ERRORS can be */
  34. /* undefined in ftoption.h in order to make the higher byte always */
  35. /* zero, in case you need to be compatible with previous versions of */
  36. /* FreeType 2. */
  37. /* */
  38. /* */
  39. /* II - Error Message strings */
  40. /* -------------------------- */
  41. /* */
  42. /* The error definitions below are made through special macros that */
  43. /* allow client applications to build a table of error message strings */
  44. /* if they need it. The strings are not included in a normal build of */
  45. /* FreeType 2 to save space (most client applications do not use */
  46. /* them). */
  47. /* */
  48. /* To do so, you have to define the following macros before including */
  49. /* this file: */
  50. /* */
  51. /* FT_ERROR_START_LIST :: */
  52. /* This macro is called before anything else to define the start of */
  53. /* the error list. It is followed by several FT_ERROR_DEF calls */
  54. /* (see below). */
  55. /* */
  56. /* FT_ERROR_DEF( e, v, s ) :: */
  57. /* This macro is called to define one single error. */
  58. /* `e' is the error code identifier (e.g. FT_Err_Invalid_Argument). */
  59. /* `v' is the error numerical value. */
  60. /* `s' is the corresponding error string. */
  61. /* */
  62. /* FT_ERROR_END_LIST :: */
  63. /* This macro ends the list. */
  64. /* */
  65. /* Additionally, you have to undefine __FTERRORS_H__ before #including */
  66. /* this file. */
  67. /* */
  68. /* Here is a simple example: */
  69. /* */
  70. /* { */
  71. /* #undef __FTERRORS_H__ */
  72. /* #define FT_ERRORDEF( e, v, s ) { e, s }, */
  73. /* #define FT_ERROR_START_LIST { */
  74. /* #define FT_ERROR_END_LIST { 0, 0 } }; */
  75. /* */
  76. /* const struct */
  77. /* { */
  78. /* int err_code; */
  79. /* const char* err_msg */
  80. /* } ft_errors[] = */
  81. /* */
  82. /* #include FT_ERRORS_H */
  83. /* } */
  84. /* */
  85. /*************************************************************************/
  86. #ifndef __FTERRORS_H__
  87. #define __FTERRORS_H__
  88. /* include module base error codes */
  89. #include FT_MODULE_ERRORS_H
  90. /*******************************************************************/
  91. /*******************************************************************/
  92. /***** *****/
  93. /***** SETUP MACROS *****/
  94. /***** *****/
  95. /*******************************************************************/
  96. /*******************************************************************/
  97. #undef FT_NEED_EXTERN_C
  98. #undef FT_ERR_XCAT
  99. #undef FT_ERR_CAT
  100. #define FT_ERR_XCAT( x, y ) x ## y
  101. #define FT_ERR_CAT( x, y ) FT_ERR_XCAT( x, y )
  102. /* FT_ERR_PREFIX is used as a prefix for error identifiers. */
  103. /* By default, we use `FT_Err_'. */
  104. /* */
  105. #ifndef FT_ERR_PREFIX
  106. #define FT_ERR_PREFIX FT_Err_
  107. #endif
  108. /* FT_ERR_BASE is used as the base for module-specific errors. */
  109. /* */
  110. #ifdef FT_CONFIG_OPTION_USE_MODULE_ERRORS
  111. #ifndef FT_ERR_BASE
  112. #define FT_ERR_BASE FT_Mod_Err_Base
  113. #endif
  114. #else
  115. #undef FT_ERR_BASE
  116. #define FT_ERR_BASE 0
  117. #endif /* FT_CONFIG_OPTION_USE_MODULE_ERRORS */
  118. /* If FT_ERRORDEF is not defined, we need to define a simple */
  119. /* enumeration type. */
  120. /* */
  121. #ifndef FT_ERRORDEF
  122. #define FT_ERRORDEF( e, v, s ) e = v,
  123. #define FT_ERROR_START_LIST enum {
  124. #define FT_ERROR_END_LIST FT_ERR_CAT( FT_ERR_PREFIX, Max ) };
  125. #ifdef __cplusplus
  126. #define FT_NEED_EXTERN_C
  127. extern "C" {
  128. #endif
  129. #endif /* !FT_ERRORDEF */
  130. /* this macro is used to define an error */
  131. #define FT_ERRORDEF_( e, v, s ) \
  132. FT_ERRORDEF( FT_ERR_CAT( FT_ERR_PREFIX, e ), v + FT_ERR_BASE, s )
  133. /* this is only used for FT_Err_Ok, which must be 0! */
  134. #define FT_NOERRORDEF_( e, v, s ) \
  135. FT_ERRORDEF( FT_ERR_CAT( FT_ERR_PREFIX, e ), v, s )
  136. #ifdef FT_ERROR_START_LIST
  137. FT_ERROR_START_LIST
  138. #endif
  139. /* no include the error codes */
  140. #include FT_ERROR_DEFINITIONS_H
  141. #ifdef FT_ERROR_END_LIST
  142. FT_ERROR_END_LIST
  143. #endif
  144. /*******************************************************************/
  145. /*******************************************************************/
  146. /***** *****/
  147. /***** SIMPLE CLEANUP *****/
  148. /***** *****/
  149. /*******************************************************************/
  150. /*******************************************************************/
  151. #ifdef FT_NEED_EXTERN_C
  152. }
  153. #endif
  154. #undef FT_ERROR_START_LIST
  155. #undef FT_ERROR_END_LIST
  156. #undef FT_ERRORDEF
  157. #undef FT_ERRORDEF_
  158. #undef FT_NOERRORDEF_
  159. #undef FT_NEED_EXTERN_C
  160. #undef FT_ERR_PREFIX
  161. #undef FT_ERR_BASE
  162. #undef FT_ERR_CONCAT
  163. #endif /* __FTERRORS_H__ */
  164. /* END */