EHS Embedded HTTP Server  1.5.1.0
debug.h
1 /* $Id: debug.h 81 2012-03-20 12:03:05Z felfert $
2  *
3  * EHS is a library for embedding HTTP(S) support into a C++ application
4  *
5  * Copyright (C) 2004 Zachary J. Hansen
6  *
7  * Code cleanup, new features and bugfixes: Copyright (C) 2010 Fritz Elfert
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1 as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  * This can be found in the 'COPYING' file.
23  *
24  */
25 
26 #ifndef _DEBUG_H
27 #define _DEBUG_H
28 
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32 
33 #ifdef EHS_DEBUG
34 # include <iostream>
35 # include <cstdio>
36 # include <cstdarg>
37 #endif
38 
39 static inline void _ehs_trace(const char*
40 #ifdef EHS_DEBUG
41  szFormat
42 #endif
43  ... )
44 {
45 #ifdef EHS_DEBUG
46  const int bufsize = 100000;
47  char buf [ bufsize ] ;
48  va_list VarList;
49  va_start( VarList, szFormat );
50  vsnprintf(buf, bufsize - 1, szFormat, VarList ) ;
51  va_end ( VarList ) ;
52 # ifdef _WIN32
53  OutputDebugStringA(buf) ;
54 # else
55  std::cerr << buf << std::endl; std::cerr.flush();
56 # endif
57 #endif
58 }
59 
60 #define _STR(x) #x
61 #define EHS_TODO (_message) message (" *** TODO: " ##_message "\t\t\t\t" __FILE__ ":" _STR(__LINE__) )
62 #define EHS_FUTURE (_message) message (" *** FUTURE: " ##_message "\t\t\t\t" __FILE__ ":" _STR(__LINE__) )
63 #define EHS_TODOCUMENT (_message) message (" *** TODOCUMENT: " ##_message "\t\t\t\t" __FILE__ ":" _STR(__LINE__) )
64 #define EHS_DEBUGCODE (_message) message (" *** DEBUG CODE (REMOVE!): " ##_message "\t\t\t\t" __FILE__ ":" _STR(__LINE__) )
65 
66 #ifdef HAVE_GNU_VAMACROS
67 # ifdef HAVE_GNU_PRETTY_FUNCTION
68 # define EHS_TRACE(fmt, ...) _ehs_trace("%s [%s:%d]: " fmt, __PRETTY_FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
69 # else
70 # define EHS_TRACE(fmt, ...) _ehs_trace("%s [%s:%d]: " fmt, __func__, __FILE__, __LINE__, ##__VA_ARGS__)
71 # endif
72 #else
73 # define EHS_TRACE _ehs_trace
74 #endif
75 
76 #endif // _DEBUG_H