X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-lib%2Fdebug.h;fp=lib-lib%2Fdebug.h;h=ece38235854c3e4eb2d88a82d58e820a79410974;hp=0000000000000000000000000000000000000000;hb=05a3bbbe420e4afc76e0eea24ce32f859405dc4a;hpb=08fa240d29322ece4c7bceebfae6c6d3fb856f0e diff --git a/lib-lib/debug.h b/lib-lib/debug.h new file mode 100644 index 0000000..ece3823 --- /dev/null +++ b/lib-lib/debug.h @@ -0,0 +1,97 @@ +/* + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * Copyright © 2006 Pierre Habouzit + */ +/* + * written for mutt-ng by: + * Rocco Rutte + * + * This file is part of mutt-ng, see http://www.muttng.org/. + * It's licensed under the GNU General Public License, + * please see the file GPL in the top level source directory. + */ + +/* generic interface for debug messages */ + +#ifndef _LIB_DEBUG_H +#define _LIB_DEBUG_H + +#include + +#define DEBUG_MIN_LEVEL 1 +#define DEBUG_MIN_LEVEL_S "1" +#define DEBUG_MAX_LEVEL 5 +#define DEBUG_MAX_LEVEL_S "5" + +#ifdef DEBUG + +extern short DebugLevel; +extern FILE* DebugFile; + +void debug_setlevel (short); +void debug_start (const char*); + +void _debug_print_intro (const char*, int, const char*, int); +void _debug_print_msg (const char*, ...); + +/* + * the debug_print() macro will (in the end) print debug messages of the + * following format: + * + * (file:line:function:level): message + * + * for GCC and: + * + * (file:line:level): message + * + * otherwise + */ +#ifdef __GNUC__ + +#define debug_print(level,msg) \ + do { \ + if (DebugLevel >= level) { \ + _debug_print_intro (__FILE__,__LINE__,__func__,level); \ + _debug_print_msg msg; \ + } \ + } while(0) + +#else /* __GNUC__ */ + +#define debug_print(level,msg) \ + do { \ + if (DebugLevel >= level) { \ + _debug_print_intro (__FILE__,__LINE__,NULL,level); \ + _debug_print_msg msg; \ + } \ + } while(0) + +#endif /* !__GNUC__ */ + +#else /* DEBUG */ + +/* + * without debug support, we don't need these + * (this also kills the dozens of #ifdef for debug... + */ +#define debug_start(basedir) +#define debug_setlevel(level) +#define debug_print(level,msg) + +#endif /* !DEBUG */ + +#endif /* !_LIB_DEBUG_H */