Main Page | Data Structures | File List | Data Fields | Globals

error.c

Go to the documentation of this file.
00001 /*
00002  * luau (Lib Update/Auto-Update): Simple Update Library
00003  * Copyright (C) 2003  David Eklund
00004  *
00005  * - This library is free software; you can redistribute it and/or             -
00006  * - modify it under the terms of the GNU Lesser General Public                -
00007  * - License as published by the Free Software Foundation; either              -
00008  * - version 2.1 of the License, or (at your option) any later version.        -
00009  * -                                                                           -
00010  * - This library 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 GNU         -
00013  * - Lesser General Public License for more details.                           -
00014  * -                                                                           -
00015  * - You should have received a copy of the GNU Lesser General Public          -
00016  * - License along with this library; if not, write to the Free Software       -
00017  * - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA -
00018  */
00019 
00020 #ifdef HAVE_CONFIG_H
00021 #  include <config.h>
00022 #endif
00023 
00024 #include <stdarg.h>
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <stdarg.h>
00028 #include <unistd.h>
00029 
00030 #include <glib.h>
00031 
00032 #include "util.h"
00033 #include "error.h"
00034 
00035 #ifdef WITH_DMALLOC
00036 #  include <dmalloc.h>
00037 #endif
00038 
00039 
00040 static void defaultErrorFunc(const char* string, const char* filename, const char* function, int lineno);
00041 static int defaultPromptFunc(const char * title, const char* msg, int nTotal, int nDefault, const char *choice1, va_list args);
00042 
00043 static UErrorFunc  errorFunc_global  = defaultErrorFunc;
00044 static UPromptFunc promptFunc_global = defaultPromptFunc;
00045 
00065 void
00066 lutil_error_setErrorFunc(UErrorFunc errorFunc) {
00067         errorFunc_global = errorFunc;
00068 }
00069 
00085 void
00086 lutil_error_setPromptFunc(UPromptFunc promptFunc) {
00087         promptFunc_global = promptFunc;
00088 }
00089 
00090 void
00091 lutil_error_resetErrorFunc(void) {
00092         errorFunc_global = defaultErrorFunc;
00093 }
00094 
00095 void
00096 lutil_error_resetPromptFunc(void) {
00097         promptFunc_global = defaultPromptFunc;
00098 }
00099 
00110 void
00111 lutil_error_fatal(const char* string, const char* filename, const char* function, int lineno) {
00112         fprintf(stderr, "***FATAL***\n");
00113         fprintf(stderr, "%s\n", string);
00114         exit(1);
00115 }
00116 
00130 int
00131 lutil_error_prompt(const char* title, const char* msg, int nTotal, int nDefault, const char *choice1, ...) {
00132         va_list ap;
00133         int result;
00134         
00135         va_start(ap, choice1);
00136         result = promptFunc_global(title, msg, nTotal, nDefault, choice1, ap);
00137         va_end(ap);
00138         
00139         return result;
00140 }
00141 
00158 void
00159 lutil_error(const char* filename, const char* function, int lineno, const char* template, ...) {
00160         va_list ap;
00161         char* str;
00162         
00163         va_start (ap, template);
00164         str = lutil_valistToString(template, ap);
00165         va_end (ap);
00166         
00167         errorFunc_global(str, filename, function, lineno);
00168         
00169         g_free(str);
00170 }
00171 
00172 
00173 /* Non-Interface Methods */
00174 
00175 static void
00176 defaultErrorFunc(const char* string, const char* filename, const char* function, int lineno) {
00177         fprintf(stderr, "*** ERROR ***\n");
00178         fprintf(stderr, "luau: %s: %s: %s\n", filename, function, string);
00179 }
00180 
00181 static int
00182 defaultPromptFunc(const char * title, const char* msg, int nTotal, int nDefault, const char *choice1, va_list args) {
00183         return nDefault; /* don't prompt; just use the default */
00184 }
00185 

Generated on Mon Apr 12 22:17:10 2004 for luau by doxygen 1.3.2