1 /* $Id$ */ 2 /*- 3 * Copyright (c) 2003-2005 Benedikt Meurer <benny@xfce.org> 4 * All rights reserved. 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free 18 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301 USA 20 */ 21 22 #if !defined(LIBXFCE4UTIL_INSIDE_LIBXFCE4UTIL_H) && !defined(LIBXFCE4UTIL_COMPILATION) 23 #error "Only <libxfce4util/libxfce4util.h> can be included directly, this file may disappear or change contents" 24 #endif 25 26 #ifndef __LIBXFCE4UTIL_DEBUG_H__ 27 #define __LIBXFCE4UTIL_DEBUG_H__ 28 29 #include <stdio.h> 30 31 #include <glib.h> 32 33 #if defined(DEBUG) && (DEBUG > 0) && (defined(G_HAVE_ISO_VARARGS) \ 34 || defined(G_HAVE_GNUC_VARARGS)) 35 36 #if defined(__NetBSD__) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) 37 #define __DBG_FUNC__ __func__ 38 #elif defined(__GNUC__) && __GNUC__ >= 3 39 #define __DBG_FUNC__ __FUNCTION__ 40 #elif defined(__SVR4) && defined(__sun) 41 #define __DBG_FUNC__ __func__ 42 #else 43 #define __DBG_FUNC__ "??" 44 #endif 45 46 #if defined(G_HAVE_ISO_VARARGS) 47 48 #define DBG(...) G_STMT_START{ \ 49 fprintf(stderr, "DBG[%s:%d] %s(): ", __FILE__, __LINE__, __DBG_FUNC__); \ 50 fprintf(stderr, __VA_ARGS__); \ 51 fprintf(stderr, "\n"); \ 52 }G_STMT_END 53 54 #elif defined(G_HAVE_GNUC_VARARGS) 55 56 #define DBG(fmt, args...) G_STMT_START{ \ 57 { \ 58 fprintf(stderr, "DBG[%s:%d] %s(): ", __FILE__, __LINE__, __DBG_FUNC__); \ 59 fprintf(stderr, fmt, ##args); \ 60 fprintf(stderr, "\n"); \ 61 }G_STMT_END 62 63 #endif 64 65 #if defined(DEBUG_TRACE) && (DEBUG_TRACE > 0) 66 67 #if defined(G_HAVE_ISO_VARARGS) 68 69 #define TRACE(...) G_STMT_START{ \ 70 fprintf(stderr, "TRACE[%s:%d] %s(): ",__FILE__,__LINE__,__DBG_FUNC__); \ 71 fprintf(stderr, __VA_ARGS__); \ 72 fprintf(stderr, "\n"); \ 73 }G_STMT_END 74 75 #elif defined (G_HAVE_GNUC_VARARGS) 76 77 #define TRACE(fmt, args...) G_STMT_START{ \ 78 { \ 79 fprintf(stderr, "TRACE[%s:%d] %s(): ",__FILE__,__LINE__,__DBG_FUNC__); \ 80 fprintf(stderr, fmt, ##args); \ 81 fprintf(stderr, "\n"); \ 82 }G_STMT_END 83 84 #endif 85 86 #else /* !defined(DEBUG_TRACE) || DEBUG_TRACE <= 0 */ 87 88 #define TRACE(...) G_STMT_START{ (void)0; }G_STMT_END 89 90 #endif 91 92 #else /* !defined(DEBUG) || DEBUG <= 0 */ 93 94 #define DBG(...) G_STMT_START{ (void)0; }G_STMT_END 95 #define TRACE(...) G_STMT_START{ (void)0; }G_STMT_END 96 97 #endif 98 99 #endif /* !__LIBXFCE4UTIL_DEBUG_H__ */ 100