00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 #include <iostream>
00021 #include <vector>
00022 #include <string>
00023 #include <string.h>
00024 #include <stdarg.h>
00025 #include <sys/types.h>
00026 #include <unistd.h>
00027 #include "../include/base.h"
00028 
00032 std::vector<std::string> debugModes;
00033 
00042 void PrintDebug (const char *filename, const char *function, unsigned long line,
00043                 const char *level, const char *message, ...)
00044 {
00045         int levelSize = strlen(level);
00046         unsigned int i = 0;
00047 
00048         for( i = 0; i < debugModes.size(); i++ ){
00049                 int modeSize = debugModes[i].size();
00050                 const char *strMode = debugModes[i].c_str();
00051 
00052                 if( strncmp(strMode, level, modeSize) == 0){
00053                         if( (levelSize != modeSize) && ( level[modeSize] != '.' ) && modeSize != 0)
00054                                 continue;
00055                 
00056                         va_list argp;
00057                         int pid = (int)getpid();
00058 
00059                         fprintf(stderr, "%i|%s:%s:%ld| %s : ", pid, filename, function, line, level);
00060                 va_start(argp, message);
00061                 vfprintf(stderr, message, argp);
00062                 va_end(argp);
00063                         fprintf(stderr, "\n");
00064                         return;
00065                 }
00066         }
00067 }
00068 
00072 void AddDebugMode( std::string mode ){
00073         debugModes.push_back( mode );
00074 }
00075 
00082 void InitDebugModes( int argc, char **argv ){
00083         int i;
00084 
00085         for( i=0; i<argc; i++ ){
00086                 if( strcmp(argv[i], "-d") == 0 ){
00087                         i = i + 1;
00088                         if( i == argc )
00089                                 Error( "Usage : -d mode.truc" );
00090                         AddDebugMode( argv[i] );
00091                 }
00092         }
00093 }