Back to index

plt-scheme  4.2.1
pldebug.h
Go to the documentation of this file.
00001 /* $Id: pldebug.h,v 1.1 2004/03/01 20:54:51 cozmic Exp $
00002 
00003     Copyright (C) 1995 by Maurice J. LeBrun
00004 
00005     Debugging support for PLplot.
00006 
00007     This software may be freely copied, modified and redistributed without
00008     fee provided that this copyright notice is preserved intact on all
00009     copies and modified copies. 
00010  
00011     There is no warranty or other guarantee of fitness of this software.
00012     It is provided solely "as is". The author(s) disclaim(s) all
00013     responsibility and liability with respect to this software's usage or
00014     its effect upon hardware or computer systems. 
00015 */
00016 
00017 #ifndef __PLDEBUG_H__
00018 #define __PLDEBUG_H__
00019 
00020 #include <stdarg.h>
00021 
00022 /* For the truly desperate debugging task */
00023 
00024 #ifdef DEBUG_ENTER
00025 #define dbug_enter(a) \
00026 if (plsc->debug) \
00027     fprintf(stderr, "    entered %s (%s, line %d)\n", a, __FILE__, __LINE__);
00028 
00029 #else
00030 #define dbug_enter(a)
00031 #endif
00032 
00033 /* If we're using a debugging malloc, include the header file here */
00034 
00035 #ifdef DEBUGGING_MALLOC
00036 #include <malloc.h>
00037 #endif
00038 
00039 /*--------------------------------------------------------------------------*\
00040  * pldebug()
00041  *
00042  * Included into every plplot source file to control debugging output.  To
00043  * enable printing of debugging output, you must #define DEBUG before
00044  * including plplotP.h or specify -DDEBUG in the compile line, for each file
00045  * that you want to have debug output enabled.  When running the program you
00046  * must in addition specify -debug.  This allows debugging output to tailored
00047  * to many different circumstances but otherwise be fairly unobtrusive. 
00048  *
00049  * Note, any file that actually uses pldebug() must also define NEED_PLDEBUG
00050  * before the plplotP.h include.  This is to eliminate warnings caused by
00051  * those files in which this is defined but never referenced.  All this could
00052  * be much nicer if CPP had the abilities of m4, sigh.. 
00053  *
00054  * Syntax:
00055  *     pldebug(label, format [, arg1, arg2, ...] );
00056  *
00057  * The label is typically the calling function name.
00058 \*--------------------------------------------------------------------------*/
00059 
00060 #ifdef NEED_PLDEBUG
00061 static void
00062 pldebug( const char *label, ... )
00063 {
00064 #ifdef DEBUG
00065     va_list args;
00066     char *fmt;
00067 
00068     if (plsc->debug) {
00069        if (plsc->termin)
00070            c_pltext();
00071        va_start(args, label);
00072 
00073     /* print out identifying tag */
00074 
00075        fprintf(stderr, "%s: ", label);
00076 
00077     /* print out remainder of message */
00078     /* Need to get fmt BEFORE it's used in the vfprintf */
00079 
00080        fmt = (char *) va_arg(args, char *);
00081        vfprintf(stderr, fmt, args);
00082 
00083        va_end(args);
00084        if (plsc->termin)
00085            c_plgra();
00086     }
00087 #endif /* DEBUG */
00088 }
00089 #endif /* NEED_PLDEBUG */
00090 
00091 #endif /* __PLDEBUG_H__ */