debug.hpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: debug.hpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 /*********************************************************************** 00045 * 00046 * Purpose: support printf() debugging 00047 * Author: Matthias Ohlenroth 00048 * Version: $Id: debug.hpp,v 1.12 2005/07/18 11:08:27 klschoef Exp $ 00049 * Notes: 00050 * 00051 ***********************************************************************/ 00052 00053 #ifndef __DEBUG_H__ 00054 #define __DEBUG_H__ 00055 00056 #include <stdio.h> 00057 #ifndef WINCE 00058 #include <pthread.h> 00059 #endif 00060 00061 #define VITOOKI_DEBUG_ERR 1 00062 #define VITOOKI_DEBUG_SMALL 2 00063 #define VITOOKI_DEBUG_FULL 3 00064 00065 #if VITOOKI_DEBUG_LEVEL >= VITOOKI_DEBUG_ERR 00066 00067 /* adds the filepointer F to a class/method */ 00068 #define dfadd(F) FILE* F; 00069 /* closes the filepointer F */ 00070 #define dfclose(F) { if(F) fclose(F);} 00071 #define dfinit0(F) { F = stdout; } 00072 /* initializes FILE* F, with a file named S */ 00073 #define dfinit(F, S) { F = fopen(S,"wb"); } 00074 /* creates a fileName by converting the integer value I to a string and 00075 concatening it to the string S. */ 00076 #define dfinit2(F, S, I) { char* _fileN_= (char*)malloc(strlen(S)+21);_fileN_[0]=0;strcpy(_fileN_,S);char _number[20];sprintf(_number,"%i",I);strcat(_fileN_, _number); F = fopen(_fileN_,"wb");free(_fileN_); } 00077 #define dfinitlog(F, S, I) { char* _fileN_= (char*)malloc(strlen(S)+25);_fileN_[0]=0;strcpy(_fileN_,S);char _number[20];sprintf(_number,"%i",I);strcat(_fileN_, _number);strcat(_fileN_,".log");F = fopen(_fileN_,"wb");free(_fileN_); } 00078 #else 00079 00080 #define dfadd(F) 00081 #define dfclose(F) {;} 00082 #define dfinit0(F) {;} 00083 #define dfinit(F, S) {;} 00084 #define dfinit2(F, S, I) {;} 00085 #define dfinitlog(F, S, I) {;} 00086 00087 #endif 00088 00089 #ifdef WIN32 00090 #include <cstdio> 00091 00092 #ifndef VITOOKI_DEBUG_LEVEL 00093 #undef dfadd 00094 #define dfadd(F) FILE* F; 00095 #undef dfinit0 00096 #define dfinit0(F) { F = stdout; }; 00097 #endif //vitooki_debug_level 00098 00099 #if VITOOKI_DEBUG_LEVEL < VITOOKI_DEBUG_ERR 00100 #undef dfadd 00101 #define dfadd(F) FILE* F; 00102 #undef dfinit0 00103 #define dfinit0(F) { F = stdout; }; 00104 #endif 00105 00106 void dprintf(const char *format, ...); 00107 void dfprintf(FILE * F, const char *format, ...); 00108 void dprintf_err(const char *format, ...); 00109 void dprintf_err_fatal(const char *format, ...); 00110 void dfprintf_err(FILE * F, const char *format, ...); 00111 void dprintf_small(const char *format, ...); 00112 void dfprintf_small(FILE * F, const char *format, ...); 00113 void dprintf_full(const char *format, ...); 00114 void dfprintf_full(FILE * F, const char *format, ...); 00115 00116 #else // !WIN32, so LINUX 00117 00118 #define dprintf(A, B...) { printf(A, ## B); fflush(stdout);} 00119 #define dfprintf(F, A, B...) { fprintf(F, A, ## B);fflush(F); } 00120 00121 #if VITOOKI_DEBUG_LEVEL >= VITOOKI_DEBUG_ERR 00122 00123 #define dprintf_err(A, B...) { fprintf(stderr,"Log_E: [%d]",(int)pthread_self()); fprintf(stderr,A, ## B); fflush(stderr);} 00124 #define dfprintf_err(F, A, B...) { if(F) { fprintf(F, "Log_E: [%d]",(int)pthread_self()); fprintf(F, A, ## B); fflush(F);} } 00125 #define dprintf_err_fatal(A, B...) {fprintf(stderr,"Log_E: [%d]", (int)pthread_self()); fprintf(stderr,A, ##B); fflush(stderr);} 00126 #else 00127 #define dprintf_err(A, B...) { ; } 00128 #define dfprintf_err(F, A, B...) { ; } 00129 #define dprintf_err_fatal(A, B...) {;} 00130 00131 #endif 00132 00133 #if VITOOKI_DEBUG_LEVEL >= VITOOKI_DEBUG_SMALL 00134 00135 #define dprintf_small(A, B...) { printf("Log_S: [%d]", (int)pthread_self()); printf(A, ## B); fflush(stdout);} 00136 #define dfprintf_small(F, A, B...) { if(F) { fprintf(F,"Log_S: [%d]",(int)pthread_self()); fprintf(F, A, ## B);fflush(F);} } 00137 #else 00138 #define dprintf_small(A, B...) { ; } 00139 #define dfprintf_small(F, A, B...) { ; } 00140 #endif 00141 00142 #if VITOOKI_DEBUG_LEVEL >= VITOOKI_DEBUG_FULL 00143 00144 #define dprintf_full(A, B...) { printf("Log_F: [%d]",(int)pthread_self()); printf(A, ## B); fflush(stdout);} 00145 #define dfprintf_full(F, A, B...) { if (F) { fprintf(F, "Log_F: [%d]",(int)pthread_self()); fprintf(F, A, ## B);fflush(F);} } 00146 #else 00147 #define dprintf_full(A, B...) { ; } 00148 #define dfprintf_full(F, A, B...) { ; } 00149 #endif 00150 00151 #endif 00152 00153 #endif // WIN32