non/sequencer/src/debug.C

63 lines
2.2 KiB
C++
Raw Normal View History

2007-12-18 05:09:02 +01:00
/*******************************************************************************/
/* Copyright (C) 2008 Jonathan Moore Liles */
/* */
/* 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; see the file COPYING. If not,write to the Free Software */
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*******************************************************************************/
#include "debug.h"
void
warnf ( warning_t level,
const char *module,
const char *file,
const char *function, size_t line, const char *fmt, ... )
{
va_list args;
static const char *level_tab[] = {
"message", "\033[1;32m",
"warning", "\033[1;33m",
"assertion", "\033[1;31m"
};
FILE *fp = W_MESSAGE == level ? stdout : stderr;
2007-12-18 05:09:02 +01:00
if ( module )
fprintf( fp, "[%s] ", module );
2007-12-18 05:09:02 +01:00
#ifndef NDEBUG
if ( file )
fprintf( fp, "%s", file );
2007-12-18 05:09:02 +01:00
if ( line )
fprintf( fp, ":%i", line );
2007-12-18 05:09:02 +01:00
if ( function )
fprintf( fp, " %s()", function );
2007-12-18 05:09:02 +01:00
fprintf( fp, ": " );
2007-12-18 05:09:02 +01:00
#endif
if ( unsigned( ( level << 1 ) + 1 ) <
( sizeof( level_tab ) / sizeof( level_tab[0] ) ) )
fprintf( fp, "%s", level_tab[( level << 1 ) + 1] );
2007-12-18 05:09:02 +01:00
if ( fmt )
{
va_start( args, fmt );
vfprintf( fp, fmt, args );
2007-12-18 05:09:02 +01:00
va_end( args );
}
fprintf( fp, "\033[0m\n" );
2007-12-18 05:09:02 +01:00
}