summaryrefslogtreecommitdiff
path: root/libyelp/yelp-debug.h
blob: 6e057d51db8536658634bdaed8c09df93c1e0e58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Copyright (C) 2006 Brent Smith <gnome@nextreality.net> 
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __YELP_DEBUG_H__
#define __YELP_DEBUG_H__

G_BEGIN_DECLS

#include <unistd.h>
#include <glib.h>

typedef enum {
	DB_FUNCTION   = 1 << 0,
	DB_ARG        = 1 << 1,
	DB_PROFILE    = 1 << 2,
	DB_LOG        = 1 << 3,
	DB_INFO       = 1 << 4,
	DB_DEBUG      = 1 << 5,
	DB_WARN       = 1 << 6,
	DB_ERROR      = 1 << 7,
	DB_ALL        = 1 << 8
} YelpDebugEnums;

#if defined(__STDC_VERSION__) && __STDC_VERSION__ < 199901L
# if __GNUC__ >= 2
#  define __func__ __FUNCTION__
# else
#  define __func__ "<unknown>"
# endif
#endif

/* __VA_ARGS__ is C99 compliant but may not work on older versions of cpp, 
 * so we provide a fallback */
#ifdef YELP_DEBUG
# if defined(__STDC_VERSION__) && __STDC_VERSION__ < 199901L
#  define debug_print(format, args...) yelp_debug (__FILE__, __LINE__, __func__, format, args)
# else
#  define debug_print(format, ...) yelp_debug (__FILE__, __LINE__, __func__, format, __VA_ARGS__)
# endif
#else
# if defined(__STDC_VERSION__) && __STDC_VERSION__ < 199901L
#  define debug_print(format, args...)
# else
#  define debug_print(format, ...)
# endif
#endif

#ifdef YELP_DEBUG
# define d(x) x
#else
# define d(x)
#endif

G_GNUC_INTERNAL
void yelp_debug (const gchar *file, guint line, 
                 const gchar *function, guint flags,
                 const gchar *format, ...) G_GNUC_PRINTF (5, 6);

G_END_DECLS

#endif /* __YELP_DEBUG_H__ */