00001 /*************************************************************************** 00002 * Copyright (C) 2006 by André Lindhjem <belgarat@sdf.lonestar.org>, * 00003 * Kjetil Holien <kjetil.holien@gmail.com>, * 00004 * Terje Risa <terje.risa@gmail.com> & * 00005 * Øyvind Nerbråten <oyvind@nerbraten.com> * 00006 * * 00007 * This program is free software; you can redistribute it and/or modify * 00008 * it under the terms of the GNU General Public License as published by * 00009 * the Free Software Foundation; either version 2 of the License, or * 00010 * (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 * 00019 * Free Software Foundation, Inc., * 00020 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00021 *************************************************************************** 00022 * 00023 * \file report.c 00024 * \author André Lindhjem, Kjetil Holien, Terje Risa & Øyvind Nerbråten 00025 * \date 15.02.2006 00026 * 00027 * Functionality for handling error reporting. 00028 */ 00029 00030 00031 #include <stdio.h> 00032 #include <stdlib.h> 00033 00034 #include "report.h" 00035 00036 00041 int reporting_level = 4; 00042 00043 00044 00045 /* ************************************************ * 00046 * Global function definitions * 00047 * ************************************************ */ 00048 00054 void report (const char * error_message, const int level) 00055 { 00056 switch (reporting_level) 00057 { 00058 case 4: 00059 if (level <= REP_DEBUG) /* debug */ 00060 printf ("Debug: %s\n", error_message); 00061 case 3: 00062 if (level == REP_MESSAGE) /* message */ 00063 printf ("Message: %s\n", error_message); 00064 case 2: 00065 if (level == REP_WARNING) /* warning */ 00066 printf ("Warning: %s\n", error_message); 00067 case 1: 00068 if (level == REP_ERROR) /* error */ 00069 printf ("Error: %s\n", error_message); 00070 default: 00071 if (level >= REP_CRITICAL) /* report critical error and exit program */ 00072 { 00073 printf ("Critical Error: %s\n\nExiting program\n", error_message); 00074 exit(-1); 00075 } 00076 } 00077 }