/* * GRacer * * Copyright (C) 1999 Takashi Matsuda * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #ifndef __GRACER_DEBUG_H__ #define __GRACER_DEBUG_H__ #include #include #include #include #define TCL_CHECK(cmd,label) if ((cmd) == TCL_ERROR) {goto label;} #define OBJ_RESULT(obj,message) {\ Tcl_SetObjResult (interp, obj); \ Tcl_AppendResult (interp, message, NULL); \ } typedef enum { GR_DEBUG_NONE = 0, GR_DEBUG_ERROR, GR_DEBUG_WARNING, GR_DEBUG_NOTICE, GR_DEBUG_MESSAGE, } GrDebugLevel; GrDebugLevel gr_get_debug_level (void); void gr_set_debug_level (int level); #ifdef GR_ENABLE_DEBUG extern GrDebugLevel __gr_debug_level; #ifdef __GNUC__ #define GR_BEGIN_FUNCTION() \ gr_message ("%s:%s().", __FILE__, __PRETTY_FUNCTION__) extern GLenum __gl_error; #define GL_CHECK(expr) { \ expr; \ if ((__gl_error = glGetError ()) != GL_NO_ERROR) { \ gr_warning ("%s:%d (%s): OpenGL error: %s", \ __FILE__, \ __LINE__, \ __PRETTY_FUNCTION__, \ gluErrorString (__gl_error)); \ }; } #define gr_error(format, args...) { \ if (__gr_debug_level >= GR_DEBUG_ERROR) {\ fputs ("Error: ", stderr); \ fprintf (stderr, format, ##args); \ fputc ('\n', stderr); \ exit (-1); \ } \ } #define gr_warning(format, args...) { \ if (__gr_debug_level >= GR_DEBUG_WARNING) {\ fputs ("Warning: ", stderr); \ fprintf (stderr, format, ##args); \ fputc ('\n', stderr); \ } \ } #define gr_notice(format, args...) { \ if (__gr_debug_level >= GR_DEBUG_NOTICE) {\ fputs ("Notice: ", stderr); \ fprintf (stderr, format, ##args); \ fputc ('\n', stderr); \ } \ } #define gr_message(format, args...) { \ if (__gr_debug_level >= GR_DEBUG_MESSAGE) {\ fputs ("Message: ", stderr); \ fprintf (stderr, format, ##args); \ fputc ('\n', stderr); \ }\ } #define gr_return_val_if_fail(cond,val) \ { \ if (!(cond)) { \ fprintf (stderr, "%s:%d (%s): condition check failed.\n", \ __FILE__, \ __LINE__, \ __PRETTY_FUNCTION__); \ return (val); \ } \ } #define gr_return_if_fail(cond) \ { \ if (!(cond)) { \ fprintf (stderr, "%s:%d (%s): condition check failed.\n", \ __FILE__, \ __LINE__, \ __PRETTY_FUNCTION__); \ return; \ } \ } #else /* !__GNUC__ */ #define GR_BEGIN_FUNCTION() #define GL_CHECK(expr) expr #define gr_return_val_if_fail(cond,val) { if (!(cond)) { return (val); } } #define gr_return_if_fail(cond) { if (!(cond)) { return; } } static void gr_error (const char *format, ...) { if (__gr_debug_level >= GR_DEBUG_ERROR) { va_list args; va_start (args, format); fputs ("Error: ", stderr); g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args); fputc ('\n', stderr); va_end (args); } } static void gr_warning (const char *format, ...) { if (__gr_debug_level >= GR_DEBUG_WARNING) { va_list args; va_start (args, format); fputs ("Warning: ", stderr); vfprintf (stderr, format, args); fputc ('\n', stderr); va_end (args); } } static void gr_notice (const char *format, ...) { if (__gr_debug_level >= GR_DEBUG_NOTICE) { va_list args; va_start (args, format); fputs ("Notice: ", stderr); vfprintf (stderr, format, args); fputc ('\n', stderr); va_end (args); } } static void gr_message (const char *format, ...) { if (__gr_debug_level >= GR_DEBUG_MESSAGE) { va_list args; va_start (args, format); fputs ("Message: ", stderr); vfprintf (stderr, format, args); fputc ('\n', stderr); va_end (args); } } #endif /* __GNUC__ */ #else /* !GR_ENABLE_DEBUG */ #define GR_BEGIN_FUNCTION() #define GL_CHECK(expr) expr #define gr_error(format, args...) #define gr_warning(format, args...) #define gr_message(format, args...) #define gr_return_val_if_fail(cond,val) #define gr_return_if_fail(cond) #endif #endif /* __GRACER_DEBUG_H__ */