Back to index

extremetuxracer  0.5beta
error_util.cpp
Go to the documentation of this file.
00001 /* 
00002  * PPRacer 
00003  * Copyright (C) 2004-2005 Volker Stroebel <volker@planetpenguin.de>
00004  * 
00005  * Copyright (C) 1999-2001 Jasmin F. Patry
00006  * 
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020  */
00021 
00022 #include "error_util.h"
00023 #include "winsys.h"
00024 #include "game_config.h"
00025 
00026 /* A note on warning levels:
00027    A warning level of 0 prints nothing
00028    A warning level of 100 prints everything
00029 
00030    1 is reserved for critical warnings -- things that the user really
00031    shouldn't do but that we can continue from anyway. */
00032 
00033 void print_warning( int warning_level, char *fmt, ... )
00034 {
00035     va_list args;
00036 
00037     /* We enforce the fact that warning level 0 prints no warnings */
00038     check_assertion( warning_level > 0, "warning levels must be > 0" );
00039     check_assertion( warning_level <= 100, "warning levels must be <= 100" );
00040 
00041     if ( warning_level > getparam_warning_level() ) {
00042        return;
00043     }
00044 
00045     va_start( args, fmt );
00046 
00047     fprintf( stderr, "%%%%%% " PROG_NAME " warning: " );
00048     vfprintf( stderr, fmt, args );
00049     fprintf( stderr, "\n" );
00050 
00051     va_end( args );
00052 }
00053 
00054 void handle_error( int exit_code, char *fmt, ... )
00055 {
00056     va_list args;
00057 
00058     va_start( args, fmt );
00059 
00060     fprintf( stderr, "*** " PROG_NAME " error: " );
00061     vfprintf( stderr, fmt, args );
00062     fprintf( stderr, "\n" );
00063 
00064     va_end( args );
00065 
00066     winsys_exit( exit_code );
00067 }
00068 
00069 void handle_system_error( int exit_code, char *fmt, ... )
00070 {
00071     va_list args;
00072 
00073     va_start( args, fmt );
00074 
00075     fprintf( stderr, "*** " PROG_NAME " error: " );
00076     vfprintf( stderr, fmt, args );
00077     fprintf( stderr, " (%s)\n", strerror( errno ) );
00078 
00079     va_end( args );
00080 
00081     winsys_exit( exit_code );
00082 }