Back to index

tetex-bin  3.0
xdvi-debug.h
Go to the documentation of this file.
00001 #ifndef XDVI_DEBUG_H_
00002 #define XDVI_DEBUG_H_
00003 
00004 /*
00005  * Copyright (c) 2002-2004 the xdvik development team
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a copy
00008  * of this software and associated documentation files (the "Software"), to
00009  * deal in the Software without restriction, including without limitation the
00010  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00011  * sell copies of the Software, and to permit persons to whom the Software is
00012  * furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included in
00015  * all copies or substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00020  * PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE BE LIABLE FOR ANY CLAIM,
00021  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00022  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00023  * OTHER DEALINGS IN THE SOFTWARE.
00024  *
00025  */
00026 
00027 /* debugging flags and macros */
00028 
00029 #include "xdvi-config.h"
00030 #include "xdvi.h"
00031 #include "version.h"
00032 
00033 #if HAVE_STRINGIZE
00034 #ifdef NDEBUG
00035 /* for production code, a failed ASSERT(x) just prints out a warning;
00036    else it aborts and dumps core.
00037 */
00038 #define ASSERT(x, y) do {                                                    \
00039     if(!(x)) {                                                                      \
00040        fprintf(stderr,                                                              \
00041               "************************************************************\n"      \
00042               "XDvi %s: Failed assertion:\n%s:%d: \"%s\": %s\n"                     \
00043               "Please report this as a bug to:\n"                                   \
00044               "http://sourceforge.net/tracker/?group_id=23164&atid=377580\n"        \
00045               "************************************************************\n",     \
00046               XDVI_VERSION_INFO, __FILE__, __LINE__, #x, y);                        \
00047     } } while (0)
00048 #else /* NDEBUG */
00049 #define ASSERT(x, y) do {                                                    \
00050     if(!(x)) {                                                                      \
00051        fprintf(stderr,                                                              \
00052               "\n************************************************************\n"    \
00053               "XDvi %s: Failed assertion:\n%s:%d: \"%s\": %s\n"                     \
00054               "Aborting now. Please report this as a bug to:\n"                     \
00055               "http://sourceforge.net/tracker/?group_id=23164&atid=377580\n"        \
00056               "If a core dump has been produced, please invoke:\n"                  \
00057               "gdb %s core\nThen type \"bt\", "                              \
00058               "and include the resulting output in your bug report.\n"              \
00059               "************************************************************\n",     \
00060               XDVI_VERSION_INFO, __FILE__, __LINE__, #x, y, globals.program_name);  \
00061        do_abort();                                                           \
00062     } } while (0)
00063 #endif /* NDEBUG */
00064 #else /* HAVE_STRINGIZE */
00065 #define ASSERT(x, y) /* as nothing */
00066 #endif
00067 
00068 /* for temporary debugging statements */
00069 /* #define MYDEBUG 1 */
00070 #ifdef MYDEBUG
00071 # define MYTRACE(X)   do {                          \
00072     fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \
00073     fprintf X;                                      \
00074     fprintf(stderr, "\n");                          \
00075 } while(0)
00076 #else
00077 # define MYTRACE(X)
00078 #endif
00079 
00080 /* NOTE: keep these in sync with the debug_string_options array in util.c! */
00081 #define       DBG_BITMAP           1
00082 #define       DBG_DVI                     2
00083 #define       DBG_PK               4
00084 #define       DBG_BATCH            8
00085 #define       DBG_EVENT            16
00086 #define       DBG_PS               32
00087 /* start of kpathsea debugging options */
00088 #define       DBG_STAT             64
00089 #define       DBG_HASH             128
00090 #define       DBG_OPEN             256
00091 #define       DBG_PATHS            512
00092 #define       DBG_EXPAND           1024
00093 #define       DBG_SEARCH           2048
00094 #define       DBG_KPATHSEA         4032   /* handy abbrev */
00095 /* end of kpathsea debugging options */
00096 #define       DBG_HTEX             4096
00097 #define DBG_SRC_SPECIALS    8192
00098 #define DBG_CLIENT          16384
00099 #define DBG_T1                     32768
00100 #define DBG_T1_VERBOSE             65536
00101 #define DBG_GUI                    131072
00102 #define DBG_FIND            262144
00103 #define DBG_FILES           524288
00104 #define       DBG_ALL                     (~DBG_BATCH)
00105 
00106 /* a mapping of numerical options to descriptive strings, defined in util.c */
00107 struct debug_string_options {
00108     int bitmap;
00109     const char *description;
00110     const char *help_formatting;
00111 };
00112 
00113 /*
00114  */
00115 
00116 #if 0
00117 /* we don't want this defined for NDEBUG, since the tracing macros
00118    are pretty useful also for users reporting bugs etc.; so we 
00119    enable them always.
00120 */
00121 #define TRACE_HTEX(X)
00122 #define TRACE_SRC(X)
00123 #define TRACE_CLIENT(X)
00124 #define TRACE_T1(X)
00125 #define TRACE_T1_VERBOSE(X)
00126 #define TRACE_GUI(X)
00127 #define TRACE_EVENTS(X)
00128 #define TRACE_FIND(X)
00129 #define TRACE_FILES(X)
00130 
00131 #else /* 0 */
00132 
00133 /*
00134  * Note that the argument to these macros is always ((stderr, "...")).
00135  * We could also have
00136  *    TRACE_SRC(("..."));
00137  * and invoke a function, but then gcc (3.1) won't be able to check
00138  * inconsistencies between conversion specifiers and arguments any
00139  * more, and that's a real killer IMHO.
00140  */
00141 
00142 #define TRACE_HTEX(X)                                              \
00143     do {                                                    \
00144        if (globals.debug & DBG_HTEX) {                                    \
00145            fprintf(stderr, "%s:%d: HTEX: ", __FILE__, __LINE__);   \
00146            fprintf X;                                              \
00147            fprintf(stderr, "\n");                           \
00148        }                                                    \
00149     } while(0)
00150 #define TRACE_SRC(X)                                        \
00151     do {                                                    \
00152        if (globals.debug & DBG_SRC_SPECIALS) {                            \
00153            fprintf(stderr, "%s:%d: SRC: ", __FILE__, __LINE__);    \
00154            fprintf X;                                              \
00155            fprintf(stderr, "\n");                           \
00156        }                                                    \
00157     } while(0)
00158 #define TRACE_CLIENT(X)                                            \
00159     do {                                                    \
00160        if (globals.debug & DBG_CLIENT) {                           \
00161            fprintf(stderr, "%s:%d: CLIENT: ", __FILE__, __LINE__); \
00162            fprintf X;                                              \
00163            fprintf(stderr, "\n");                           \
00164        }                                                    \
00165     } while(0)
00166 #define TRACE_T1(X)                                         \
00167     do {                                                    \
00168        if (globals.debug & DBG_T1) {                                      \
00169            fprintf(stderr, "%s:%d: T1: ", __FILE__, __LINE__);     \
00170            fprintf X;                                              \
00171            fprintf(stderr, "\n");                           \
00172        }                                                    \
00173     } while(0)
00174 #define TRACE_T1_VERBOSE(X)                                 \
00175     do {                                                    \
00176        if (globals.debug & DBG_T1_VERBOSE) {                              \
00177            fprintf(stderr, "%s:%d: T1_VERBOSE: ", __FILE__, __LINE__);           \
00178            fprintf X;                                              \
00179            fprintf(stderr, "\n");                           \
00180        }                                                    \
00181     } while(0)
00182 #define TRACE_GUI(X)                                        \
00183     do {                                                    \
00184        if (globals.debug & DBG_GUI) {                                     \
00185            fprintf(stderr, "%s:%d: GUI: ", __FILE__, __LINE__);    \
00186            fprintf X;                                              \
00187            fprintf(stderr, "\n");                           \
00188        }                                                    \
00189     } while(0)
00190 #define TRACE_EVENTS(X)                                            \
00191     do {                                                    \
00192        if (globals.debug & DBG_EVENT) {                            \
00193            fprintf(stderr, "%s:%d: EVENT: ", __FILE__, __LINE__);  \
00194            fprintf X;                                              \
00195            fprintf(stderr, "\n");                           \
00196        }                                                    \
00197     } while(0)
00198 #define TRACE_FIND(X)                                              \
00199     do {                                                    \
00200        if (globals.debug & DBG_FIND) {                                     \
00201            fprintf(stderr, "%s:%d: FIND: ", __FILE__, __LINE__);   \
00202            fprintf X;                                              \
00203            fprintf(stderr, "\n");                           \
00204        }                                                    \
00205     } while(0)
00206 
00207 #define TRACE_FILES(X)                                             \
00208     do {                                                    \
00209        if (globals.debug & DBG_FILES) {                            \
00210            fprintf(stderr, "%s:%d: FILES: ", __FILE__, __LINE__);  \
00211            fprintf X;                                              \
00212            fprintf(stderr, "\n");                           \
00213        }                                                    \
00214     } while(0)
00215 
00216 #endif /* 0 */
00217 
00218 #endif /* XDVI_DEBUG_H_ */