continue the include dance
[apps/madmutt.git] / lib-lib / debug.h
1 /*
2  *  This program is free software; you can redistribute it and/or modify
3  *  it under the terms of the GNU General Public License as published by
4  *  the Free Software Foundation; either version 2 of the License, or (at
5  *  your option) any later version.
6  *
7  *  This program is distributed in the hope that it will be useful, but
8  *  WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10  *  General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License
13  *  along with this program; if not, write to the Free Software
14  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
15  *  MA 02110-1301, USA.
16  *
17  *  Copyright © 2006 Pierre Habouzit
18  */
19 /*
20  * written for mutt-ng by:
21  * Rocco Rutte <pdmef@cs.tu-berlin.de>
22  *
23  * This file is part of mutt-ng, see http://www.muttng.org/.
24  * It's licensed under the GNU General Public License,
25  * please see the file GPL in the top level source directory.
26  */
27
28 /* generic interface for debug messages */
29
30 #ifndef MUTT_LIB_LIB_DEBUG_H
31 #define MUTT_LIB_LIB_DEBUG_H
32
33 #include <stdio.h>
34
35 #define DEBUG_MIN_LEVEL         1
36 #define DEBUG_MIN_LEVEL_S       "1"
37 #define DEBUG_MAX_LEVEL         5
38 #define DEBUG_MAX_LEVEL_S       "5"
39
40 #ifdef DEBUG
41
42 extern short DebugLevel;
43 extern FILE* DebugFile;
44
45 void debug_setlevel (short);
46 void debug_start (const char*);
47
48 void _debug_print_intro (const char*, int, const char*, int);
49 void _debug_print_msg (const char*, ...);
50
51 /*
52  * the debug_print() macro will (in the end) print debug messages of the
53  * following format:
54  *
55  *      (file:line:function:level): message
56  *
57  * for GCC and:
58  *
59  *      (file:line:level): message
60  *
61  * otherwise
62  */
63 #ifdef __GNUC__
64
65 #define debug_print(level,msg)                                      \
66     do {                                                            \
67         if (DebugLevel >= level) {                                  \
68             _debug_print_intro (__FILE__,__LINE__,__func__,level);  \
69             _debug_print_msg msg;                                   \
70         }                                                           \
71     } while(0)
72
73 #else /* __GNUC__ */
74
75 #define debug_print(level,msg)                                      \
76     do {                                                            \
77         if (DebugLevel >= level) {                                  \
78             _debug_print_intro (__FILE__,__LINE__,NULL,level);      \
79             _debug_print_msg msg;                                   \
80         }                                                           \
81     } while(0)
82
83 #endif /* !__GNUC__ */
84
85 #else /* DEBUG */
86
87 /*
88  * without debug support, we don't need these
89  * (this also kills the dozens of #ifdef for debug...
90  */
91 #define debug_start(basedir)
92 #define debug_setlevel(level)
93 #define debug_print(level,msg)
94
95 #endif /* !DEBUG */
96
97 #endif /* MUTT_LIB_LIB_DEBUG_H */