root/libswish3/tags/10Feb2008/src/libswish3/error.c

Revision 1952, 2.2 kB (checked in by karpet, 1 year ago)

rename messaging functions and add file, line and function name to output

Line 
1 /*
2  * This file is part of libswish3
3  * Copyright (C) 2007 Peter Karman
4  *
5  *  libswish3 is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  libswish3 is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with libswish3; if not, write to the Free Software
17  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19
20 /* error handling based on Swish-e ver2 error.c */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <errno.h>
26 #include <err.h>
27 #include <string.h>
28 #include <libxml/globals.h>
29
30 #include "libswish3.h"
31
32 extern int      SWISH_DEBUG;
33
34
35 static FILE *error_handle = NULL;
36
37 void swish_set_error_handle( FILE *where )
38 {
39     error_handle = where;
40 }
41
42 void swish_croak(const char *file, int line, const char *func, char *msgfmt,...)
43 {
44   va_list args;
45
46   if ( !error_handle )
47       error_handle = stderr;
48
49   va_start (args,msgfmt);
50   fprintf  (error_handle, "Swish ERROR %s:%d %s: ", file, line, func);
51   vfprintf (error_handle, msgfmt, args);
52   fprintf  (error_handle, "\n");
53   va_end   (args);
54
55   if(!errno)
56     errno = 1;
57    
58   exit(errno);
59 }
60
61 void swish_warn(const char *file, int line, const char *func, char *msgfmt,...)
62 {
63   va_list args;
64
65   if ( !error_handle )
66       error_handle = stderr;
67
68   va_start (args,msgfmt);
69   fprintf  (error_handle, "Swish WARNING %s:%d %s: ", file, line, func);
70   vfprintf (error_handle, msgfmt, args);
71   fprintf  (error_handle, "\n");
72   va_end   (args);
73 }
74
75 void swish_debug(const char *file, int line, const char *func, char *msgfmt,...)
76 {
77   va_list args;
78
79   if ( !error_handle )
80       error_handle = stderr;
81
82   va_start (args,msgfmt);
83   fprintf  (error_handle, "Swish DEBUG %s:%d %s: ", file, line, func);
84   vfprintf (error_handle, msgfmt, args);
85   fprintf  (error_handle, "\n");
86   va_end   (args);
87 }
Note: See TracBrowser for help on using the browser.