pngdebug.h 5.3 KB

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