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