summaryrefslogtreecommitdiffabout
path: root/libical/src/libical/icalerror.h
Unidiff
Diffstat (limited to 'libical/src/libical/icalerror.h') (more/less context) (show whitespace changes)
-rw-r--r--libical/src/libical/icalerror.h21
1 files changed, 13 insertions, 8 deletions
diff --git a/libical/src/libical/icalerror.h b/libical/src/libical/icalerror.h
index 52f5ba9..826c8e8 100644
--- a/libical/src/libical/icalerror.h
+++ b/libical/src/libical/icalerror.h
@@ -1,152 +1,157 @@
1/* -*- Mode: C -*- */ 1/* -*- Mode: C -*- */
2/*====================================================================== 2/*======================================================================
3 FILE: icalerror.h 3 FILE: icalerror.h
4 CREATOR: eric 09 May 1999 4 CREATOR: eric 09 May 1999
5 5
6 $Id$ 6 $Id$
7 7
8 8
9 (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org 9 (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
10 10
11 This program is free software; you can redistribute it and/or modify 11 This program is free software; you can redistribute it and/or modify
12 it under the terms of either: 12 it under the terms of either:
13 13
14 The LGPL as published by the Free Software Foundation, version 14 The LGPL as published by the Free Software Foundation, version
15 2.1, available at: http://www.fsf.org/copyleft/lesser.html 15 2.1, available at: http://www.fsf.org/copyleft/lesser.html
16 16
17 Or: 17 Or:
18 18
19 The Mozilla Public License Version 1.0. You may obtain a copy of 19 The Mozilla Public License Version 1.0. You may obtain a copy of
20 the License at http://www.mozilla.org/MPL/ 20 the License at http://www.mozilla.org/MPL/
21 21
22 The original code is icalerror.h 22 The original code is icalerror.h
23 23
24======================================================================*/ 24======================================================================*/
25 25
26 26
27#ifndef ICALERROR_H 27#ifndef ICALERROR_H
28#define ICALERROR_H 28#define ICALERROR_H
29 29
30#include <assert.h> 30#include <assert.h>
31#include <stdio.h> /* For icalerror_warn() */ 31#include <stdio.h> /* For icalerror_warn() */
32 32
33 33
34#ifdef HAVE_CONFIG_H 34#ifdef HAVE_CONFIG_H
35#include "config.h" 35#include "config.h"
36#endif 36#endif
37 37
38#define ICAL_SETERROR_ISFUNC 38#define ICAL_SETERROR_ISFUNC
39 39
40 40
41/* This routine is called before any error is triggered. It is called 41/** This routine is called before any error is triggered. It is called
42 by icalerror_set_errno, so it does not appear in all of the macros 42 by icalerror_set_errno, so it does not appear in all of the macros
43 below */ 43 below */
44void icalerror_stop_here(void); 44void icalerror_stop_here(void);
45 45
46void icalerror_crash_here(void); 46void icalerror_crash_here(void);
47 47
48typedef enum icalerrorenum { 48typedef enum icalerrorenum {
49 49 ICAL_NO_ERROR, /* icalerrno may not be initialized - put it first so and pray that the compiler initialize things to zero */
50 ICAL_BADARG_ERROR, 50 ICAL_BADARG_ERROR,
51 ICAL_NEWFAILED_ERROR, 51 ICAL_NEWFAILED_ERROR,
52 ICAL_ALLOCATION_ERROR, 52 ICAL_ALLOCATION_ERROR,
53 ICAL_MALFORMEDDATA_ERROR, 53 ICAL_MALFORMEDDATA_ERROR,
54 ICAL_PARSE_ERROR, 54 ICAL_PARSE_ERROR,
55 ICAL_INTERNAL_ERROR, /* Like assert --internal consist. prob */ 55 ICAL_INTERNAL_ERROR, /* Like assert --internal consist. prob */
56 ICAL_FILE_ERROR, 56 ICAL_FILE_ERROR,
57 ICAL_USAGE_ERROR, 57 ICAL_USAGE_ERROR,
58 ICAL_UNIMPLEMENTED_ERROR, 58 ICAL_UNIMPLEMENTED_ERROR,
59 ICAL_UNKNOWN_ERROR, /* Used for problems in input to icalerror_strerror()*/ 59 ICAL_UNKNOWN_ERROR /* Used for problems in input to icalerror_strerror()*/
60 ICAL_NO_ERROR
61 60
62} icalerrorenum; 61} icalerrorenum;
63 62
64/* The libical error enumeration, like errno*/ 63icalerrorenum * icalerrno_return(void);
65extern icalerrorenum icalerrno; 64#define icalerrno (*(icalerrno_return()))
66 65
67/* If true, libicl aborts after a call to icalerror_set_error*/ 66/** If true, libicl aborts after a call to icalerror_set_error
67 *
68 * @warning NOT THREAD SAFE -- recommended that you do not change
69 * this in a multithreaded program.
70 */
68extern int icalerror_errors_are_fatal; 71extern int icalerror_errors_are_fatal;
69 72
70/* Warning messages */ 73/* Warning messages */
71 74
72#ifdef __GNUC__ca 75#ifdef __GNUC__ca
73#define icalerror_warn(message) {fprintf(stderr,"%s(), %s:%d: %s\n",__FUNCTION__,__FILE__,__LINE__,message);} 76#define icalerror_warn(message) {fprintf(stderr,"%s(), %s:%d: %s\n",__FUNCTION__,__FILE__,__LINE__,message);}
74#else /* __GNU_C__ */ 77#else /* __GNU_C__ */
75#define icalerror_warn(message) {fprintf(stderr,"%s:%d: %s\n",__FILE__,__LINE__,message);} 78#define icalerror_warn(message) {fprintf(stderr,"%s:%d: %s\n",__FILE__,__LINE__,message);}
76#endif /* __GNU_C__ */ 79#endif /* __GNU_C__ */
77 80
78 81
79void icalerror_clear_errno(void); 82void icalerror_clear_errno(void);
83void _icalerror_set_errno(icalerrorenum);
80 84
81/* Make an individual error fatal or non-fatal. */ 85/* Make an individual error fatal or non-fatal. */
82typedef enum icalerrorstate { 86typedef enum icalerrorstate {
83 ICAL_ERROR_FATAL, /* Not fata */ 87 ICAL_ERROR_FATAL, /* Not fata */
84 ICAL_ERROR_NONFATAL, /* Fatal */ 88 ICAL_ERROR_NONFATAL, /* Fatal */
85 ICAL_ERROR_DEFAULT, /* Use the value of icalerror_errors_are_fatal*/ 89 ICAL_ERROR_DEFAULT, /* Use the value of icalerror_errors_are_fatal*/
86 ICAL_ERROR_UNKNOWN /* Asked state for an unknown error type */ 90 ICAL_ERROR_UNKNOWN /* Asked state for an unknown error type */
87} icalerrorstate ; 91} icalerrorstate ;
88 92
89char* icalerror_strerror(icalerrorenum e); 93char* icalerror_strerror(icalerrorenum e);
90char* icalerror_perror(); 94char* icalerror_perror();
91void icalerror_set_error_state( icalerrorenum error, icalerrorstate); 95void icalerror_set_error_state( icalerrorenum error, icalerrorstate);
92icalerrorstate icalerror_get_error_state( icalerrorenum error); 96icalerrorstate icalerror_get_error_state( icalerrorenum error);
93 97
94#ifndef ICAL_SETERROR_ISFUNC 98#ifndef ICAL_SETERROR_ISFUNC
95#define icalerror_set_errno(x) \ 99#define icalerror_set_errno(x) \
96icalerrno = x; \ 100icalerrno = x; \
101 fprintf(stderr,"Ical error # %d\n", x); \
97if(icalerror_get_error_state(x)==ICAL_ERROR_FATAL || \ 102if(icalerror_get_error_state(x)==ICAL_ERROR_FATAL || \
98 (icalerror_get_error_state(x)==ICAL_ERROR_DEFAULT && \ 103 (icalerror_get_error_state(x)==ICAL_ERROR_DEFAULT && \
99 icalerror_errors_are_fatal == 1 )){ \ 104 icalerror_errors_are_fatal == 1 )){ \
100 icalerror_warn(icalerror_strerror(x)); \ 105 icalerror_warn(icalerror_strerror(x)); \
101 assert(0); \ 106 assert(0); \
102} 107}
103#else 108#else
104void icalerror_set_errno(icalerrorenum); 109void icalerror_set_errno(icalerrorenum x);
105#endif 110#endif
106 111
107#ifdef ICAL_ERRORS_ARE_FATAL 112#ifdef ICAL_ERRORS_ARE_FATAL
108#undef NDEBUG 113#undef NDEBUG
109#endif 114#endif
110 115
111#define icalerror_check_value_type(value,type); 116#define icalerror_check_value_type(value,type);
112#define icalerror_check_property_type(value,type); 117#define icalerror_check_property_type(value,type);
113#define icalerror_check_parameter_type(value,type); 118#define icalerror_check_parameter_type(value,type);
114#define icalerror_check_component_type(value,type); 119#define icalerror_check_component_type(value,type);
115 120
116/* Assert with a message */ 121/* Assert with a message */
117#ifdef ICAL_ERRORS_ARE_FATAL 122#ifdef ICAL_ERRORS_ARE_FATAL
118 123
119#ifdef __GNUC__ 124#ifdef __GNUC__
120#define icalerror_assert(test,message) if(!(test)){fprintf(stderr,"%s(), %s:%d: %s\n",__FUNCTION__,__FILE__,__LINE__,message);icalerror_stop_here(); abort();} 125#define icalerror_assert(test,message) if(!(test)){fprintf(stderr,"%s(), %s:%d: %s\n",__FUNCTION__,__FILE__,__LINE__,message);icalerror_stop_here(); abort();}
121#else /*__GNUC__*/ 126#else /*__GNUC__*/
122#define icalerror_assert(test,message) if(!(test)){fprintf(stderr,"%s:%d: %s\n",__FILE__,__LINE__,message);icalerror_stop_here(); abort();} 127#define icalerror_assert(test,message) if(!(test)){fprintf(stderr,"%s:%d: %s\n",__FILE__,__LINE__,message);icalerror_stop_here(); abort();}
123#endif /*__GNUC__*/ 128#endif /*__GNUC__*/
124 129
125#else /* ICAL_ERRORS_ARE_FATAL */ 130#else /* ICAL_ERRORS_ARE_FATAL */
126#define icalerror_assert(test,message) 131#define icalerror_assert(test,message)
127#endif /* ICAL_ERRORS_ARE_FATAL */ 132#endif /* ICAL_ERRORS_ARE_FATAL */
128 133
129/* Check & abort if check fails */ 134/* Check & abort if check fails */
130#define icalerror_check_arg(test,arg) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); } 135#define icalerror_check_arg(test,arg) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); }
131 136
132/* Check & return void if check fails*/ 137/* Check & return void if check fails*/
133#define icalerror_check_arg_rv(test,arg) if(!(test)) {icalerror_set_errno(ICAL_BADARG_ERROR); return; } 138#define icalerror_check_arg_rv(test,arg) if(!(test)) {icalerror_set_errno(ICAL_BADARG_ERROR); return; }
134 139
135/* Check & return 0 if check fails*/ 140/* Check & return 0 if check fails*/
136#define icalerror_check_arg_rz(test,arg) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); return 0;} 141#define icalerror_check_arg_rz(test,arg) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); return 0;}
137 142
138/* Check & return an error if check fails*/ 143/* Check & return an error if check fails*/
139#define icalerror_check_arg_re(test,arg,error) if(!(test)) { icalerror_stop_here(); assert(0); return error;} 144#define icalerror_check_arg_re(test,arg,error) if(!(test)) { icalerror_stop_here(); assert(0); return error;}
140 145
141/* Check & return something*/ 146/* Check & return something*/
142#define icalerror_check_arg_rx(test,arg,x) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); return x;} 147#define icalerror_check_arg_rx(test,arg,x) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); return x;}
143 148
144 149
145 150
146/* String interfaces to set an error to NONFATAL and restore it to its 151/* String interfaces to set an error to NONFATAL and restore it to its
147 original value */ 152 original value */
148 153
149icalerrorstate icalerror_supress(const char* error); 154icalerrorstate icalerror_supress(const char* error);
150void icalerror_restore(const char* error, icalerrorstate es); 155void icalerror_restore(const char* error, icalerrorstate es);
151 156
152 157