src/tool/debug.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
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 }

Generated on Mon Jan 1 13:10:59 2007 for Wormux by  doxygen 1.4.7