src/tool/debug.cpp File Reference

#include <iostream>
#include <vector>
#include <string>
#include <string.h>
#include <stdarg.h>
#include <sys/types.h>
#include <unistd.h>
#include "../include/base.h"

Include dependency graph for debug.cpp:

Go to the source code of this file.

Functions

void PrintDebug (const char *filename, const char *function, unsigned long line, const char *level, const char *message,...)
void AddDebugMode (std::string mode)
void InitDebugModes (int argc, char **argv)

Variables

std::vector< std::string > debugModes


Function Documentation

void AddDebugMode ( std::string  mode  ) 

Add a new debug mode to check.

Definition at line 72 of file debug.cpp.

00072                                    {
00073         debugModes.push_back( mode );
00074 }

Here is the caller graph for this function:

void InitDebugModes ( int  argc,
char **  argv 
)

Parse the command line arguments to find new debug mode to use.

Parameters:
argc Number of arguments.
argv The arguments.

Definition at line 82 of file debug.cpp.

00082                                             {
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 }

Here is the call graph for this function:

Here is the caller graph for this function:

void PrintDebug ( const char *  filename,
const char *  function,
unsigned long  line,
const char *  level,
const char *  message,
  ... 
)

Print a debug message if needed.

Parameters:
filename 
line 
level 
message 

Definition at line 42 of file debug.cpp.

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 }


Variable Documentation

std::vector<std::string> debugModes

The debug modes in use.

Definition at line 32 of file debug.cpp.


Generated on Mon Jan 1 13:24:52 2007 for Wormux by  doxygen 1.4.7