Debian Codegraph @

texk/xdvik/xdvi-debug.h

raw
1 #ifndef XDVI_DEBUG_H_
2 #define XDVI_DEBUG_H_
3
4 /*
5 * Copyright (c) 2002-2013 the xdvik development team
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to
9 * deal in the Software without restriction, including without limitation the
10 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
27 /* debugging flags and macros */
28
29 #include "xdvi.h"
30 #include "version.h"
31
32 #if HAVE_STRINGIZE
33 #ifdef NDEBUG
34 /* for production code, a failed ASSERT(x) just prints out a warning;
35 else it aborts and dumps core.
36 */
37 #define ASSERT(x, y) do { \
38 if(!(x)) { \
39 fprintf(stderr, \
40 "************************************************************\n" \
41 "XDvi %s: Failed assertion:\n%s:%d: \"%s\": %s\n" \
42 "Please report this as a bug to:\n" \
43 "http://sourceforge.net/tracker/?group_id=23164&atid=377580\n" \
44 "************************************************************\n", \
45 XDVI_VERSION_INFO, __FILE__, __LINE__, #x, y); \
46 } } while (0)
47 #else /* NDEBUG */
48 #define ASSERT(x, y) do { \
49 if(!(x)) { \
50 fprintf(stderr, \
51 "\n************************************************************\n" \
52 "XDvi %s: Failed assertion:\n%s:%d: \"%s\": %s\n" \
53 "Aborting now. Please report this as a bug to:\n" \
54 "http://sourceforge.net/tracker/?group_id=23164&atid=377580\n" \
55 "If a core dump has been produced, please invoke:\n" \
56 "gdb %s core\nThen type \"bt\", " \
57 "and include the resulting output in your bug report.\n" \
58 "************************************************************\n", \
59 XDVI_VERSION_INFO, __FILE__, __LINE__, #x, y, globals.program_name); \
60 do_abort(); \
61 } } while (0)
62 #endif /* NDEBUG */
63 #else /* HAVE_STRINGIZE */
64 #define ASSERT(x, y) /* as nothing */
65 #endif
66
67 /* for temporary debugging statements */
68 /* #define MYDEBUG 1 */
69 #ifdef MYDEBUG
70 # define MYTRACE(X) do { \
71 fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \
72 fprintf X; \
73 fprintf(stderr, "\n"); \
74 } while(0)
75 #else
76 # define MYTRACE(X)
77 #endif
78
79 /* NOTE: keep these in sync with the debug_string_options array in util.c! */
80 #define DBG_BITMAP 1
81 #define DBG_DVI 2
82 #define DBG_PK 4
83 #define DBG_BATCH 8
84 #define DBG_EVENT 16
85 #define DBG_PS 32
86 /* start of kpathsea debugging options */
87 #define DBG_STAT 64
88 #define DBG_HASH 128
89 #define DBG_OPEN 256
90 #define DBG_PATHS 512
91 #define DBG_EXPAND 1024
92 #define DBG_SEARCH 2048
93 #define DBG_KPATHSEA 4032 /* handy abbrev */
94 /* end of kpathsea debugging options */
95 #define DBG_HTEX 4096
96 #define DBG_SRC_SPECIALS 8192
97 #define DBG_CLIENT 16384
98 #define DBG_FT 32768
99 #define DBG_FT_VERBOSE 65536 /* not currently used */
100 #define DBG_GUI 131072
101 #define DBG_FIND 262144
102 #define DBG_FILES 524288
103 #define DBG_ALL (~DBG_BATCH)
104
105 /* a mapping of numerical options to descriptive strings, defined in util.c */
106 struct debug_string_options {
107 int bitmap;
108 const char *description;
109 const char *help_formatting;
110 };
111
112 /*
113 */
114
115 #if 0
116 /* we don't want this defined for NDEBUG, since the tracing macros
117 are pretty useful also for users reporting bugs etc.; so we
118 enable them always.
119 */
120 #define TRACE_HTEX(X)
121 #define TRACE_SRC(X)
122 #define TRACE_CLIENT(X)
123 #define TRACE_FT(X)
124 #define TRACE_FT_VERBOSE(X)
125 #define TRACE_GUI(X)
126 #define TRACE_EVENTS(X)
127 #define TRACE_FIND(X)
128 #define TRACE_FILES(X)
129
130 #else /* 0 */
131
132 /*
133 * Note that the argument to these macros is always ((stderr, "...")).
134 * We could also have
135 * TRACE_SRC(("..."));
136 * and invoke a function, but then gcc (3.1) won't be able to check
137 * inconsistencies between conversion specifiers and arguments any
138 * more, and that's a real killer IMHO.
139 */
140
141 #define TRACE_HTEX(X) \
142 do { \
143 if (globals.debug & DBG_HTEX) { \
144 fprintf(stderr, "%s:%d: HTEX: ", __FILE__, __LINE__); \
145 fprintf X; \
146 fprintf(stderr, "\n"); \
147 } \
148 } while(0)
149 #define TRACE_SRC(X) \
150 do { \
151 if (globals.debug & DBG_SRC_SPECIALS) { \
152 fprintf(stderr, "%s:%d: SRC: ", __FILE__, __LINE__); \
153 fprintf X; \
154 fprintf(stderr, "\n"); \
155 } \
156 } while(0)
157 #define TRACE_CLIENT(X) \
158 do { \
159 if (globals.debug & DBG_CLIENT) { \
160 fprintf(stderr, "%s:%d: CLIENT: ", __FILE__, __LINE__); \
161 fprintf X; \
162 fprintf(stderr, "\n"); \
163 } \
164 } while(0)
165 #define TRACE_FT(X) \
166 do { \
167 if (globals.debug & DBG_FT) { \
168 fprintf(stderr, "%s:%d: FT: ", __FILE__, __LINE__); \
169 fprintf X; \
170 fprintf(stderr, "\n"); \
171 } \
172 } while(0)
173 #define TRACE_FT_VERBOSE(X) \
174 do { \
175 if (globals.debug & DBG_FT_VERBOSE) { \
176 fprintf(stderr, "%s:%d: FT_VERBOSE: ", __FILE__, __LINE__); \
177 fprintf X; \
178 fprintf(stderr, "\n"); \
179 } \
180 } while(0)
181 #define TRACE_GUI(X) \
182 do { \
183 if (globals.debug & DBG_GUI) { \
184 fprintf(stderr, "%s:%d: GUI: ", __FILE__, __LINE__); \
185 fprintf X; \
186 fprintf(stderr, "\n"); \
187 } \
188 } while(0)
189 #define TRACE_EVENTS(X) \
190 do { \
191 if (globals.debug & DBG_EVENT) { \
192 fprintf(stderr, "%s:%d: EVENT: ", __FILE__, __LINE__); \
193 fprintf X; \
194 fprintf(stderr, "\n"); \
195 } \
196 } while(0)
197 #define TRACE_FIND(X) \
198 do { \
199 if (globals.debug & DBG_FIND) { \
200 fprintf(stderr, "%s:%d: FIND: ", __FILE__, __LINE__); \
201 fprintf X; \
202 fprintf(stderr, "\n"); \
203 } \
204 } while(0)
205
206 #define TRACE_FILES(X) \
207 do { \
208 if (globals.debug & DBG_FILES) { \
209 fprintf(stderr, "%s:%d: FILES: ", __FILE__, __LINE__); \
210 fprintf X; \
211 fprintf(stderr, "\n"); \
212 } \
213 } while(0)
214
215 #endif /* 0 */
216
217 #endif /* XDVI_DEBUG_H_ */