pngdebug.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* pngdebug.h - Debugging macros for libpng, also used in pngtest.c
  2. *
  3. * Copyright (c) 1998-2013 Glenn Randers-Pehrson
  4. * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  5. * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  6. *
  7. * Last changed in libpng 1.6.8 [December 19, 2013]
  8. *
  9. * This code is released under the libpng license.
  10. * For conditions of distribution and use, see the disclaimer
  11. * and license in png.h
  12. */
  13. /* Define PNG_DEBUG at compile time for debugging information. Higher
  14. * numbers for PNG_DEBUG mean more debugging information. This has
  15. * only been added since version 0.95 so it is not implemented throughout
  16. * libpng yet, but more support will be added as needed.
  17. *
  18. * png_debug[1-2]?(level, message ,arg{0-2})
  19. * Expands to a statement (either a simple expression or a compound
  20. * do..while(0) statement) that outputs a message with parameter
  21. * substitution if PNG_DEBUG is defined to 2 or more. If PNG_DEBUG
  22. * is undefined, 0 or 1 every png_debug expands to a simple expression
  23. * (actually ((void)0)).
  24. *
  25. * level: level of detail of message, starting at 0. A level 'n'
  26. * message is preceded by 'n' 3-space indentations (not implemented
  27. * on Microsoft compilers unless PNG_DEBUG_FILE is also
  28. * defined, to allow debug DLL compilation with no standard IO).
  29. * message: a printf(3) style text string. A trailing '\n' is added
  30. * to the message.
  31. * arg: 0 to 2 arguments for printf(3) style substitution in message.
  32. */
  33. #ifndef PNGDEBUG_H
  34. #define PNGDEBUG_H
  35. /* These settings control the formatting of messages in png.c and pngerror.c */
  36. /* Moved to pngdebug.h at 1.5.0 */
  37. # ifndef PNG_LITERAL_SHARP
  38. # define PNG_LITERAL_SHARP 0x23
  39. # endif
  40. # ifndef PNG_LITERAL_LEFT_SQUARE_BRACKET
  41. # define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5b
  42. # endif
  43. # ifndef PNG_LITERAL_RIGHT_SQUARE_BRACKET
  44. # define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5d
  45. # endif
  46. # ifndef PNG_STRING_NEWLINE
  47. # define PNG_STRING_NEWLINE "\n"
  48. # endif
  49. #ifdef PNG_DEBUG
  50. # if (PNG_DEBUG > 0)
  51. # if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  52. # include <crtdbg.h>
  53. # if (PNG_DEBUG > 1)
  54. # ifndef _DEBUG
  55. # define _DEBUG
  56. # endif
  57. # ifndef png_debug
  58. # define png_debug(l,m) _RPT0(_CRT_WARN,m PNG_STRING_NEWLINE)
  59. # endif
  60. # ifndef png_debug1
  61. # define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m PNG_STRING_NEWLINE,p1)
  62. # endif
  63. # ifndef png_debug2
  64. # define png_debug2(l,m,p1,p2) \
  65. _RPT2(_CRT_WARN,m PNG_STRING_NEWLINE,p1,p2)
  66. # endif
  67. # endif
  68. # else /* PNG_DEBUG_FILE || !_MSC_VER */
  69. # ifndef PNG_STDIO_SUPPORTED
  70. # include <stdio.h> /* not included yet */
  71. # endif
  72. # ifndef PNG_DEBUG_FILE
  73. # define PNG_DEBUG_FILE stderr
  74. # endif /* PNG_DEBUG_FILE */
  75. # if (PNG_DEBUG > 1)
  76. # ifdef __STDC__
  77. # ifndef png_debug
  78. # define png_debug(l,m) \
  79. do { \
  80. int num_tabs=l; \
  81. fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
  82. (num_tabs==2 ? " " : (num_tabs>2 ? " " : "")))); \
  83. } while (0)
  84. # endif
  85. # ifndef png_debug1
  86. # define png_debug1(l,m,p1) \
  87. do { \
  88. int num_tabs=l; \
  89. fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
  90. (num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1); \
  91. } while (0)
  92. # endif
  93. # ifndef png_debug2
  94. # define png_debug2(l,m,p1,p2) \
  95. do { \
  96. int num_tabs=l; \
  97. fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
  98. (num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1,p2);\
  99. } while (0)
  100. # endif
  101. # else /* __STDC __ */
  102. # ifndef png_debug
  103. # define png_debug(l,m) \
  104. do { \
  105. int num_tabs=l; \
  106. char format[256]; \
  107. snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \
  108. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \
  109. m,PNG_STRING_NEWLINE); \
  110. fprintf(PNG_DEBUG_FILE,format); \
  111. } while (0)
  112. # endif
  113. # ifndef png_debug1
  114. # define png_debug1(l,m,p1) \
  115. do { \
  116. int num_tabs=l; \
  117. char format[256]; \
  118. snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \
  119. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \
  120. m,PNG_STRING_NEWLINE); \
  121. fprintf(PNG_DEBUG_FILE,format,p1); \
  122. } while (0)
  123. # endif
  124. # ifndef png_debug2
  125. # define png_debug2(l,m,p1,p2) \
  126. do { \
  127. int num_tabs=l; \
  128. char format[256]; \
  129. snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \
  130. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \
  131. m,PNG_STRING_NEWLINE); \
  132. fprintf(PNG_DEBUG_FILE,format,p1,p2); \
  133. } while (0)
  134. # endif
  135. # endif /* __STDC __ */
  136. # endif /* (PNG_DEBUG > 1) */
  137. # endif /* _MSC_VER */
  138. # endif /* (PNG_DEBUG > 0) */
  139. #endif /* PNG_DEBUG */
  140. #ifndef png_debug
  141. # define png_debug(l, m) ((void)0)
  142. #endif
  143. #ifndef png_debug1
  144. # define png_debug1(l, m, p1) ((void)0)
  145. #endif
  146. #ifndef png_debug2
  147. # define png_debug2(l, m, p1, p2) ((void)0)
  148. #endif
  149. #endif /* PNGDEBUG_H */