blob: 00d5a4569e4d8b9f1b33e118129b0045949e7b43 [file] [log] [blame]
Glenn Randers-Pehrsonc17c9572010-03-08 21:26:48 -06001
2/* pngdebug.h - Debugging macros for libpng, also used in pngtest.c
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -06003 *
Cosmin Trutaa8738932018-07-28 18:47:21 -04004 * Copyright (c) 2018 Cosmin Truta
Glenn Randers-Pehrson4d8de332015-12-13 22:41:17 -06005 * Copyright (c) 1998-2002,2004,2006-2013 Glenn Randers-Pehrson
Cosmin Trutaa8738932018-07-28 18:47:21 -04006 * Copyright (c) 1996-1997 Andreas Dilger
7 * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
Glenn Randers-Pehrsonc17c9572010-03-08 21:26:48 -06008 *
Glenn Randers-Pehrsonc17c9572010-03-08 21:26:48 -06009 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -060012 */
13
14/* Define PNG_DEBUG at compile time for debugging information. Higher
15 * numbers for PNG_DEBUG mean more debugging information. This has
16 * only been added since version 0.95 so it is not implemented throughout
17 * libpng yet, but more support will be added as needed.
Glenn Randers-Pehrson632a84e2010-03-09 22:28:33 -060018 *
19 * png_debug[1-2]?(level, message ,arg{0-2})
20 * Expands to a statement (either a simple expression or a compound
21 * do..while(0) statement) that outputs a message with parameter
22 * substitution if PNG_DEBUG is defined to 2 or more. If PNG_DEBUG
23 * is undefined, 0 or 1 every png_debug expands to a simple expression
24 * (actually ((void)0)).
25 *
26 * level: level of detail of message, starting at 0. A level 'n'
Glenn Randers-Pehrson83b132f2013-11-28 14:00:04 -060027 * message is preceded by 'n' 3-space indentations (not implemented
Glenn Randers-Pehrson821b7102010-06-24 16:16:32 -050028 * on Microsoft compilers unless PNG_DEBUG_FILE is also
Glenn Randers-Pehrson632a84e2010-03-09 22:28:33 -060029 * defined, to allow debug DLL compilation with no standard IO).
30 * message: a printf(3) style text string. A trailing '\n' is added
31 * to the message.
32 * arg: 0 to 2 arguments for printf(3) style substitution in message.
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -060033 */
Glenn Randers-Pehrsonc957b6b2010-03-08 21:47:07 -060034#ifndef PNGDEBUG_H
35#define PNGDEBUG_H
Glenn Randers-Pehrson53c07f52010-06-18 18:55:55 -050036/* These settings control the formatting of messages in png.c and pngerror.c */
Glenn Randers-Pehrson862cb202010-04-16 22:12:51 -050037/* Moved to pngdebug.h at 1.5.0 */
38# ifndef PNG_LITERAL_SHARP
39# define PNG_LITERAL_SHARP 0x23
40# endif
41# ifndef PNG_LITERAL_LEFT_SQUARE_BRACKET
42# define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5b
43# endif
44# ifndef PNG_LITERAL_RIGHT_SQUARE_BRACKET
45# define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5d
46# endif
47# ifndef PNG_STRING_NEWLINE
48# define PNG_STRING_NEWLINE "\n"
49# endif
50
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -060051#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 */
Glenn Randers-Pehrson862cb202010-04-16 22:12:51 -050071# ifndef PNG_STDIO_SUPPORTED
72# include <stdio.h> /* not included yet */
73# endif
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -060074# ifndef PNG_DEBUG_FILE
75# define PNG_DEBUG_FILE stderr
76# endif /* PNG_DEBUG_FILE */
77
78# if (PNG_DEBUG > 1)
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -060079# ifdef __STDC__
80# ifndef png_debug
81# define png_debug(l,m) \
Glenn Randers-Pehrson632a84e2010-03-09 22:28:33 -060082 do { \
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -060083 int num_tabs=l; \
Glenn Randers-Pehrson1f63da32013-11-28 13:41:10 -060084 fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
85 (num_tabs==2 ? " " : (num_tabs>2 ? " " : "")))); \
Glenn Randers-Pehrson632a84e2010-03-09 22:28:33 -060086 } while (0)
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -060087# endif
88# ifndef png_debug1
89# define png_debug1(l,m,p1) \
Glenn Randers-Pehrson632a84e2010-03-09 22:28:33 -060090 do { \
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -060091 int num_tabs=l; \
Glenn Randers-Pehrson1f63da32013-11-28 13:41:10 -060092 fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
93 (num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1); \
Glenn Randers-Pehrson632a84e2010-03-09 22:28:33 -060094 } while (0)
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -060095# endif
96# ifndef png_debug2
97# define png_debug2(l,m,p1,p2) \
Glenn Randers-Pehrson632a84e2010-03-09 22:28:33 -060098 do { \
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -060099 int num_tabs=l; \
Glenn Randers-Pehrson1f63da32013-11-28 13:41:10 -0600100 fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
101 (num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1,p2);\
Glenn Randers-Pehrson632a84e2010-03-09 22:28:33 -0600102 } while (0)
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -0600103# endif
104# else /* __STDC __ */
105# ifndef png_debug
106# define png_debug(l,m) \
Glenn Randers-Pehrson632a84e2010-03-09 22:28:33 -0600107 do { \
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -0600108 int num_tabs=l; \
109 char format[256]; \
110 snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \
111 (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \
112 m,PNG_STRING_NEWLINE); \
113 fprintf(PNG_DEBUG_FILE,format); \
Glenn Randers-Pehrson632a84e2010-03-09 22:28:33 -0600114 } while (0)
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -0600115# endif
116# ifndef png_debug1
117# define png_debug1(l,m,p1) \
Glenn Randers-Pehrson632a84e2010-03-09 22:28:33 -0600118 do { \
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -0600119 int num_tabs=l; \
120 char format[256]; \
121 snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \
122 (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \
123 m,PNG_STRING_NEWLINE); \
124 fprintf(PNG_DEBUG_FILE,format,p1); \
Glenn Randers-Pehrson632a84e2010-03-09 22:28:33 -0600125 } while (0)
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -0600126# endif
127# ifndef png_debug2
128# define png_debug2(l,m,p1,p2) \
Glenn Randers-Pehrson632a84e2010-03-09 22:28:33 -0600129 do { \
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -0600130 int num_tabs=l; \
131 char format[256]; \
132 snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \
133 (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \
134 m,PNG_STRING_NEWLINE); \
135 fprintf(PNG_DEBUG_FILE,format,p1,p2); \
Glenn Randers-Pehrson632a84e2010-03-09 22:28:33 -0600136 } while (0)
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -0600137# endif
138# endif /* __STDC __ */
139# endif /* (PNG_DEBUG > 1) */
140
141# endif /* _MSC_VER */
142# endif /* (PNG_DEBUG > 0) */
143#endif /* PNG_DEBUG */
144#ifndef png_debug
Glenn Randers-Pehrson632a84e2010-03-09 22:28:33 -0600145# define png_debug(l, m) ((void)0)
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -0600146#endif
147#ifndef png_debug1
Glenn Randers-Pehrson632a84e2010-03-09 22:28:33 -0600148# define png_debug1(l, m, p1) ((void)0)
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -0600149#endif
150#ifndef png_debug2
Glenn Randers-Pehrson632a84e2010-03-09 22:28:33 -0600151# define png_debug2(l, m, p1, p2) ((void)0)
Glenn Randers-Pehrsonc3cd22b2010-03-08 21:10:25 -0600152#endif
Glenn Randers-Pehrsonc957b6b2010-03-08 21:47:07 -0600153#endif /* PNGDEBUG_H */