es40_debug.h

Go to the documentation of this file.
00001 /*  ES40 emulator.
00002  * Copyright (C) 2007-2008 by the ES40 Emulator Project
00003  *
00004  * WWW    : http://sourceforge.net/projects/es40
00005  * E-mail : camiel@camicom.com
00006  * 
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00020  * 
00021  * Although this is not required, the author would appreciate being notified of, 
00022  * and receiving any modifications you may make to the source code that might serve
00023  * the general public.
00024  *
00025  * Parts of this file based upon GXemul, which is Copyright (C) 2004-2007  
00026  * Anders Gavare.  All rights reserved.
00027  */
00028 
00059 #include <stdarg.h>
00060 
00061 #if !defined(INCLUDED_DEBUG_H)
00062 #define INCLUDED_DEBUG_H
00063 
00064 #define DEBUG_BUFSIZE     1024
00065 #define DEBUG_INDENTATION 4
00066 
00067 #ifdef HAVE___FUNCTION__
00068 #define FAILURE(cls, error_msg)                                          \
00069   {                                                                      \
00070     char  where_msg[800];                                                \
00071     sprintf(where_msg, "%s, line %i, function '%s'", __FILE__, __LINE__, \
00072             __FUNCTION__);                                               \
00073     throw C##cls##Exception(error_msg, where_msg);                       \
00074   }
00075 
00076 #else
00077 #define FAILURE(cls, error_msg)                            \
00078   {                                                        \
00079     char  where_msg[800];                                  \
00080     sprintf(where_msg, "%s, line %i", __FILE__, __LINE__); \
00081     throw C##cls##Exception(error_msg, where_msg);         \
00082   }
00083 #endif /*  !HAVE___FUNCTION__  */
00084 
00085 #define FAILURE_1(cls, error_msg, a) \
00086   {                                  \
00087     char  what_msg[800];             \
00088     sprintf(what_msg, error_msg, a); \
00089     FAILURE(cls, what_msg);          \
00090   }
00091 
00092 #define FAILURE_2(cls, error_msg, a, b) \
00093   {                                     \
00094     char  what_msg[800];                \
00095     sprintf(what_msg, error_msg, a, b); \
00096     FAILURE(cls, what_msg);             \
00097   }
00098 
00099 #define FAILURE_3(cls, error_msg, a, b, c) \
00100   {                                        \
00101     char  what_msg[800];                   \
00102     sprintf(what_msg, error_msg, a, b, c); \
00103     FAILURE(cls, what_msg);                \
00104   }
00105 
00106 #define FAILURE_4(cls, error_msg, a, b, c, d) \
00107   {                                           \
00108     char  what_msg[800];                      \
00109     sprintf(what_msg, error_msg, a, b, c, d); \
00110     FAILURE(cls, what_msg);                   \
00111   }
00112 
00113 #define FAILURE_5(cls, error_msg, a, b, c, d, e) \
00114   {                                              \
00115     char  what_msg[800];                         \
00116     sprintf(what_msg, error_msg, a, b, c, d, e); \
00117     FAILURE(cls, what_msg);                      \
00118   }
00119 
00120 #define FAILURE_6(cls, error_msg, a, b, c, d, e, f) \
00121   {                                                 \
00122     char  what_msg[800];                            \
00123     sprintf(what_msg, error_msg, a, b, c, d, e, f); \
00124     FAILURE(cls, what_msg);                         \
00125   }
00126 
00127 #define CHECK_ALLOCATION(ptr)                \
00128   {                                          \
00129     if((ptr) == NULL)                        \
00130       FAILURE(OutOfMemory, "Out of memory"); \
00131   }
00132 
00133 #define CHECK_REALLOCATION(dst, src, type)   \
00134   {                                          \
00135     type*   rea_x;                           \
00136     rea_x = (type*) src;                     \
00137     if((rea_x) == NULL)                      \
00138     {                                        \
00139       FAILURE(OutOfMemory, "Out of memory"); \
00140     }                                        \
00141     else                                     \
00142     {                                        \
00143       dst = rea_x;                           \
00144     }                                        \
00145   }
00146 
00147 void  debug_indentation(int diff);
00148 void  debug(char* fmt, ...);
00149 void  fatal(char* fmt, ...);
00150 #endif

SourceForge.net Logo
Project space on SourceForge.net