medit/moo/mooutils/mooutils-debug.h

114 lines
4.6 KiB
C
Raw Normal View History

2007-08-20 22:15:58 -05:00
/*
* mooutils-debug.h
*
2009-11-21 23:26:09 -08:00
* Copyright (C) 2004-2009 by Yevgen Muntyan <muntyan@tamu.edu>
2007-08-20 22:15:58 -05:00
*
* This file is part of medit. medit is free software; you can
* redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License,
* or (at your option) any later version.
2007-08-20 22:15:58 -05:00
*
* You should have received a copy of the GNU Lesser General Public
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
2007-08-20 22:15:58 -05:00
*/
#ifndef MOO_UTILS_DEBUG_H
#define MOO_UTILS_DEBUG_H
#include <glib.h>
#include <stdarg.h>
2009-12-06 13:53:50 -08:00
#include <mooutils/mooutils-messages.h>
2007-08-20 22:15:58 -05:00
G_BEGIN_DECLS
2009-11-21 23:26:09 -08:00
#ifdef DEBUG
2007-08-20 22:15:58 -05:00
#define MOO_DEBUG_INIT(domain, def_enabled) \
static const char *moo_debug_domain = "moo-debug-" #domain; \
static gboolean \
_moo_debug_enabled (void) \
{ \
static int enabled = -1; \
if (enabled == -1) \
enabled = moo_debug_enabled (#domain, def_enabled); \
return enabled; \
} \
\
2008-02-02 15:01:12 -06:00
G_GNUC_UNUSED static void \
2007-08-20 22:15:58 -05:00
moo_dmsg (const char *format, ...) G_GNUC_PRINTF (1, 2); \
2008-02-02 15:01:12 -06:00
G_GNUC_UNUSED static void \
moo_dprint (const char *format, ...) G_GNUC_PRINTF (1, 2); \
2007-08-20 22:15:58 -05:00
\
2007-09-22 20:14:14 -05:00
static void \
2007-08-20 22:15:58 -05:00
moo_dmsg (const char *format, ...) \
{ \
va_list args; \
if (_moo_debug_enabled ()) \
{ \
va_start (args, format); \
g_logv (moo_debug_domain, \
G_LOG_LEVEL_MESSAGE, \
format, args); \
va_end (args); \
} \
2008-02-02 15:01:12 -06:00
} \
\
static void \
moo_dprint (const char *format, ...) \
{ \
va_list args; \
2008-02-02 17:32:02 -06:00
char *string; \
2008-02-02 15:01:12 -06:00
\
if (!_moo_debug_enabled ()) \
return; \
\
va_start (args, format); \
2008-02-02 17:32:02 -06:00
string = g_strdup_vprintf (format, args); \
2008-02-02 15:01:12 -06:00
va_end (args); \
\
g_return_if_fail (string != NULL); \
g_print ("%s", string); \
2008-02-02 17:32:02 -06:00
g_free (string); \
2007-08-20 22:15:58 -05:00
}
2009-11-14 22:16:05 -08:00
#define MOO_DEBUG_CODE(code) \
2008-02-02 15:01:12 -06:00
G_STMT_START { \
if (_moo_debug_enabled ()) \
{ \
code ; \
} \
} G_STMT_END
#elif defined(MOO_CL_GCC)
2007-08-20 22:15:58 -05:00
#define MOO_DEBUG_INIT(domain, def_enabled)
#define moo_dmsg(format, args...) G_STMT_START {} G_STMT_END
2008-02-02 15:01:12 -06:00
#define moo_dprint(format, args...) G_STMT_START {} G_STMT_END
2009-11-14 22:16:05 -08:00
#define MOO_DEBUG_CODE(whatever) G_STMT_START {} G_STMT_END
2007-08-20 22:15:58 -05:00
2009-11-21 23:26:09 -08:00
#else /* not gcc, not DEBUG */
2008-01-14 20:34:48 -06:00
#define MOO_DEBUG_INIT(domain, def_enabled)
2009-11-14 22:16:05 -08:00
#define MOO_DEBUG_CODE(whatever) G_STMT_START {} G_STMT_END
2008-01-14 20:34:48 -06:00
2008-06-08 14:54:36 -05:00
static void moo_dmsg (const char *format, ...) G_GNUC_PRINTF(1,2)
2008-01-14 20:34:48 -06:00
{
}
2008-06-08 14:54:36 -05:00
static void moo_dprint (const char *format, ...) G_GNUC_PRINTF(1,2)
2008-02-02 15:01:12 -06:00
{
}
2009-11-21 23:26:09 -08:00
#endif /* gcc or DEBUG */
2007-08-20 22:15:58 -05:00
2009-12-06 13:53:50 -08:00
#define _moo_message moo_debug
2007-08-20 22:15:58 -05:00
2010-02-16 02:34:01 -08:00
gboolean moo_debug_enabled (const char *var,
gboolean def_enabled);
void _moo_set_debug (const char *domains);
2007-08-20 22:15:58 -05:00
G_END_DECLS
#endif /* MOO_UTILS_DEBUG_H */