dvitomp fix from Akira
[mplib] / src / texk / kpathsea / debug.h
1 /* debug.h: runtime tracing.
2
3    Copyright 1993, 1994, 1995, 1996, 2008 Karl Berry.
4    Copyright 1999, 2005 Olaf Weber.
5
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public License
17    along with this library; if not, see <http://www.gnu.org/licenses/>.  */
18
19 #ifndef KPATHSEA_DEBUG_H
20 #define KPATHSEA_DEBUG_H
21
22 /* If NO_DEBUG is defined (not recommended), skip all this.  */
23 #ifndef NO_DEBUG
24
25 #include <kpathsea/c-proto.h>
26 #include <kpathsea/c-std.h>
27 #include <kpathsea/types.h>
28
29 #if defined(WIN32)
30 #if defined(_DEBUG)
31 /* This was needed at some time for catching errors in pdftex. */
32 #include <crtdbg.h>
33 #define  SET_CRT_DEBUG_FIELD(a) \
34             _CrtSetDbgFlag((a) | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
35 #define  CLEAR_CRT_DEBUG_FIELD(a) \
36             _CrtSetDbgFlag(~(a) & _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
37 #define  SETUP_CRTDBG \
38    { _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );    \
39      _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );  \
40      _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );   \
41      _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT ); \
42      _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );  \
43      _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );\
44    }
45 #else /* ! _DEBUG */
46 #define SET_CRT_DEBUG_FIELD(a) 
47 #define CLEAR_CRT_DEBUG_FIELD(a)
48 #define SETUP_CRTDBG
49 #endif /* _DEBUG */
50 #endif /* WIN32 */
51
52 /* OK, we'll have tracing support.  */
53 #define KPSE_DEBUG
54
55 /* Bit vector defining what we should trace.  */
56 extern KPSEDLL unsigned kpathsea_debug;
57
58 /* Set a bit.  */
59 #define KPSE_DEBUG_SET(bit) kpathsea_debug |= 1 << (bit)
60
61 /* Test if a bit is on.  */
62 #define KPSE_DEBUG_P(bit) (kpathsea_debug & (1 << (bit)))
63
64 #define KPSE_DEBUG_STAT 0               /* stat calls */
65 #define KPSE_DEBUG_HASH 1               /* hash lookups */
66 #define KPSE_DEBUG_FOPEN 2              /* fopen/fclose calls */
67 #define KPSE_DEBUG_PATHS 3              /* search path initializations */
68 #define KPSE_DEBUG_EXPAND 4             /* path element expansion */
69 #define KPSE_DEBUG_SEARCH 5             /* searches */
70 #define KPSE_DEBUG_VARS 6               /* variable values */
71 #define KPSE_LAST_DEBUG KPSE_DEBUG_VARS
72
73 /* A printf for the debugging.  */
74 #define DEBUGF_START() do { fputs ("kdebug:", stderr)
75 #define DEBUGF_END()        fflush (stderr); } while (0)
76
77 #define DEBUGF(str)                                                     \
78   DEBUGF_START (); fputs (str, stderr); DEBUGF_END ()
79 #define DEBUGF1(str, e1)                                                \
80   DEBUGF_START (); fprintf (stderr, str, e1); DEBUGF_END ()
81 #define DEBUGF2(str, e1, e2)                                            \
82   DEBUGF_START (); fprintf (stderr, str, e1, e2); DEBUGF_END ()
83 #define DEBUGF3(str, e1, e2, e3)                                        \
84   DEBUGF_START (); fprintf (stderr, str, e1, e2, e3); DEBUGF_END ()
85 #define DEBUGF4(str, e1, e2, e3, e4)                                    \
86   DEBUGF_START (); fprintf (stderr, str, e1, e2, e3, e4); DEBUGF_END ()
87
88 #undef fopen
89 #define fopen kpse_fopen_trace
90 extern KPSEDLL FILE *fopen P2H(const_string filename, const_string mode);
91 #undef fclose
92 #define fclose kpse_fclose_trace
93 extern KPSEDLL int fclose P1H(FILE *);
94
95 #endif /* not NO_DEBUG */
96
97 #endif /* not KPATHSEA_DEBUG_H */