Glenn Randers-Pehrson | c17c957 | 2010-03-08 21:26:48 -0600 | [diff] [blame] | 1 | |
| 2 | /* pngdebug.h - Debugging macros for libpng, also used in pngtest.c |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 3 | * |
Glenn Randers-Pehrson | 1f63da3 | 2013-11-28 13:41:10 -0600 | [diff] [blame] | 4 | * Copyright (c) 1998-2013 Glenn Randers-Pehrson |
Glenn Randers-Pehrson | c17c957 | 2010-03-08 21:26:48 -0600 | [diff] [blame] | 5 | * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
| 6 | * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
| 7 | * |
Glenn Randers-Pehrson | 83b132f | 2013-11-28 14:00:04 -0600 | [diff] [blame] | 8 | * Last changed in libpng 1.5.18 [(PENDING RELEASE)] |
Glenn Randers-Pehrson | c17c957 | 2010-03-08 21:26:48 -0600 | [diff] [blame] | 9 | * |
| 10 | * This code is released under the libpng license. |
| 11 | * For conditions of distribution and use, see the disclaimer |
| 12 | * and license in png.h |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 13 | */ |
| 14 | |
| 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. |
Glenn Randers-Pehrson | 632a84e | 2010-03-09 22:28:33 -0600 | [diff] [blame] | 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' |
Glenn Randers-Pehrson | 83b132f | 2013-11-28 14:00:04 -0600 | [diff] [blame] | 28 | * message is preceded by 'n' 3-space indentations (not implemented |
Glenn Randers-Pehrson | 821b710 | 2010-06-24 16:16:32 -0500 | [diff] [blame] | 29 | * on Microsoft compilers unless PNG_DEBUG_FILE is also |
Glenn Randers-Pehrson | 632a84e | 2010-03-09 22:28:33 -0600 | [diff] [blame] | 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. |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 34 | */ |
Glenn Randers-Pehrson | c957b6b | 2010-03-08 21:47:07 -0600 | [diff] [blame] | 35 | #ifndef PNGDEBUG_H |
| 36 | #define PNGDEBUG_H |
Glenn Randers-Pehrson | 53c07f5 | 2010-06-18 18:55:55 -0500 | [diff] [blame] | 37 | /* These settings control the formatting of messages in png.c and pngerror.c */ |
Glenn Randers-Pehrson | 862cb20 | 2010-04-16 22:12:51 -0500 | [diff] [blame] | 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 | |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 52 | #ifdef PNG_DEBUG |
| 53 | # if (PNG_DEBUG > 0) |
| 54 | # if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER) |
| 55 | # include <crtdbg.h> |
| 56 | # if (PNG_DEBUG > 1) |
| 57 | # ifndef _DEBUG |
| 58 | # define _DEBUG |
| 59 | # endif |
| 60 | # ifndef png_debug |
| 61 | # define png_debug(l,m) _RPT0(_CRT_WARN,m PNG_STRING_NEWLINE) |
| 62 | # endif |
| 63 | # ifndef png_debug1 |
| 64 | # define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m PNG_STRING_NEWLINE,p1) |
| 65 | # endif |
| 66 | # ifndef png_debug2 |
| 67 | # define png_debug2(l,m,p1,p2) \ |
| 68 | _RPT2(_CRT_WARN,m PNG_STRING_NEWLINE,p1,p2) |
| 69 | # endif |
| 70 | # endif |
| 71 | # else /* PNG_DEBUG_FILE || !_MSC_VER */ |
Glenn Randers-Pehrson | 862cb20 | 2010-04-16 22:12:51 -0500 | [diff] [blame] | 72 | # ifndef PNG_STDIO_SUPPORTED |
| 73 | # include <stdio.h> /* not included yet */ |
| 74 | # endif |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 75 | # ifndef PNG_DEBUG_FILE |
| 76 | # define PNG_DEBUG_FILE stderr |
| 77 | # endif /* PNG_DEBUG_FILE */ |
| 78 | |
| 79 | # if (PNG_DEBUG > 1) |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 80 | # ifdef __STDC__ |
| 81 | # ifndef png_debug |
| 82 | # define png_debug(l,m) \ |
Glenn Randers-Pehrson | 632a84e | 2010-03-09 22:28:33 -0600 | [diff] [blame] | 83 | do { \ |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 84 | int num_tabs=l; \ |
Glenn Randers-Pehrson | 1f63da3 | 2013-11-28 13:41:10 -0600 | [diff] [blame] | 85 | fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \ |
| 86 | (num_tabs==2 ? " " : (num_tabs>2 ? " " : "")))); \ |
Glenn Randers-Pehrson | 632a84e | 2010-03-09 22:28:33 -0600 | [diff] [blame] | 87 | } while (0) |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 88 | # endif |
| 89 | # ifndef png_debug1 |
| 90 | # define png_debug1(l,m,p1) \ |
Glenn Randers-Pehrson | 632a84e | 2010-03-09 22:28:33 -0600 | [diff] [blame] | 91 | do { \ |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 92 | int num_tabs=l; \ |
Glenn Randers-Pehrson | 1f63da3 | 2013-11-28 13:41:10 -0600 | [diff] [blame] | 93 | fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \ |
| 94 | (num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1); \ |
Glenn Randers-Pehrson | 632a84e | 2010-03-09 22:28:33 -0600 | [diff] [blame] | 95 | } while (0) |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 96 | # endif |
| 97 | # ifndef png_debug2 |
| 98 | # define png_debug2(l,m,p1,p2) \ |
Glenn Randers-Pehrson | 632a84e | 2010-03-09 22:28:33 -0600 | [diff] [blame] | 99 | do { \ |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 100 | int num_tabs=l; \ |
Glenn Randers-Pehrson | 1f63da3 | 2013-11-28 13:41:10 -0600 | [diff] [blame] | 101 | fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \ |
| 102 | (num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1,p2);\ |
Glenn Randers-Pehrson | 632a84e | 2010-03-09 22:28:33 -0600 | [diff] [blame] | 103 | } while (0) |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 104 | # endif |
| 105 | # else /* __STDC __ */ |
| 106 | # ifndef png_debug |
| 107 | # define png_debug(l,m) \ |
Glenn Randers-Pehrson | 632a84e | 2010-03-09 22:28:33 -0600 | [diff] [blame] | 108 | do { \ |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 109 | int num_tabs=l; \ |
| 110 | char format[256]; \ |
| 111 | snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ |
| 112 | (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ |
| 113 | m,PNG_STRING_NEWLINE); \ |
| 114 | fprintf(PNG_DEBUG_FILE,format); \ |
Glenn Randers-Pehrson | 632a84e | 2010-03-09 22:28:33 -0600 | [diff] [blame] | 115 | } while (0) |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 116 | # endif |
| 117 | # ifndef png_debug1 |
| 118 | # define png_debug1(l,m,p1) \ |
Glenn Randers-Pehrson | 632a84e | 2010-03-09 22:28:33 -0600 | [diff] [blame] | 119 | do { \ |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 120 | int num_tabs=l; \ |
| 121 | char format[256]; \ |
| 122 | snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ |
| 123 | (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ |
| 124 | m,PNG_STRING_NEWLINE); \ |
| 125 | fprintf(PNG_DEBUG_FILE,format,p1); \ |
Glenn Randers-Pehrson | 632a84e | 2010-03-09 22:28:33 -0600 | [diff] [blame] | 126 | } while (0) |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 127 | # endif |
| 128 | # ifndef png_debug2 |
| 129 | # define png_debug2(l,m,p1,p2) \ |
Glenn Randers-Pehrson | 632a84e | 2010-03-09 22:28:33 -0600 | [diff] [blame] | 130 | do { \ |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 131 | int num_tabs=l; \ |
| 132 | char format[256]; \ |
| 133 | snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ |
| 134 | (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ |
| 135 | m,PNG_STRING_NEWLINE); \ |
| 136 | fprintf(PNG_DEBUG_FILE,format,p1,p2); \ |
Glenn Randers-Pehrson | 632a84e | 2010-03-09 22:28:33 -0600 | [diff] [blame] | 137 | } while (0) |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 138 | # endif |
| 139 | # endif /* __STDC __ */ |
| 140 | # endif /* (PNG_DEBUG > 1) */ |
| 141 | |
| 142 | # endif /* _MSC_VER */ |
| 143 | # endif /* (PNG_DEBUG > 0) */ |
| 144 | #endif /* PNG_DEBUG */ |
| 145 | #ifndef png_debug |
Glenn Randers-Pehrson | 632a84e | 2010-03-09 22:28:33 -0600 | [diff] [blame] | 146 | # define png_debug(l, m) ((void)0) |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 147 | #endif |
| 148 | #ifndef png_debug1 |
Glenn Randers-Pehrson | 632a84e | 2010-03-09 22:28:33 -0600 | [diff] [blame] | 149 | # define png_debug1(l, m, p1) ((void)0) |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 150 | #endif |
| 151 | #ifndef png_debug2 |
Glenn Randers-Pehrson | 632a84e | 2010-03-09 22:28:33 -0600 | [diff] [blame] | 152 | # define png_debug2(l, m, p1, p2) ((void)0) |
Glenn Randers-Pehrson | c3cd22b | 2010-03-08 21:10:25 -0600 | [diff] [blame] | 153 | #endif |
Glenn Randers-Pehrson | c957b6b | 2010-03-08 21:47:07 -0600 | [diff] [blame] | 154 | #endif /* PNGDEBUG_H */ |