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