2007-08-20 22:15:58 -05:00
|
|
|
/*
|
|
|
|
* mooutils-debug.h
|
|
|
|
*
|
2008-09-05 17:20:50 -05:00
|
|
|
* Copyright (C) 2004-2008 by Yevgen Muntyan <muntyan@tamu.edu>
|
2007-08-20 22:15:58 -05:00
|
|
|
*
|
2008-09-05 17:20:50 -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
|
|
|
*
|
2008-09-05 17:20:50 -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>
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef MOO_DEBUG_ENABLED
|
|
|
|
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
2008-02-02 15:01:12 -06:00
|
|
|
#define MOO_DEBUG(code) \
|
|
|
|
G_STMT_START { \
|
|
|
|
if (_moo_debug_enabled ()) \
|
|
|
|
{ \
|
|
|
|
code ; \
|
|
|
|
} \
|
|
|
|
} G_STMT_END
|
|
|
|
|
2007-08-20 22:15:58 -05:00
|
|
|
void _moo_message (const char *format, ...) G_GNUC_PRINTF (1, 2);
|
|
|
|
gboolean moo_debug_enabled (const char *var,
|
|
|
|
gboolean def_enabled);
|
2008-02-02 17:32:02 -06:00
|
|
|
void _moo_set_debug (const char *domains);
|
2007-08-20 22:15:58 -05:00
|
|
|
|
2008-01-14 20:34:48 -06:00
|
|
|
#elif defined(__GNUC__)
|
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
|
2007-08-20 22:15:58 -05:00
|
|
|
#define _moo_message(format, args...) G_STMT_START {} G_STMT_END
|
|
|
|
#define MOO_DEBUG(whatever) G_STMT_START {} G_STMT_END
|
|
|
|
|
2008-01-14 20:34:48 -06:00
|
|
|
#else
|
|
|
|
|
|
|
|
#define MOO_DEBUG_INIT(domain, def_enabled)
|
|
|
|
#define MOO_DEBUG(whatever) G_STMT_START {} G_STMT_END
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-06-08 14:54:36 -05:00
|
|
|
static void _moo_message_dummy (const char *format, ...) G_GNUC_PRINTF(1,2)
|
2008-01-14 20:34:48 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#define _moo_message _moo_message_dummy
|
|
|
|
|
2007-08-20 22:15:58 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif /* MOO_UTILS_DEBUG_H */
|