2 /*======================================================================
4 CREATOR: eric 09 May 1999
9 (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of either:
14 The LGPL as published by the Free Software Foundation, version
15 2.1, available at: http://www.fsf.org/copyleft/lesser.html
19 The Mozilla Public License Version 1.0. You may obtain a copy of
20 the License at http://www.mozilla.org/MPL/
22 The original code is icalerror.h
24 ======================================================================*/
31 #include <stdio.h> /* For icalerror_warn() */
39 /* This routine is called before any error is triggered. It is called
40 by icalerror_set_errno, so it does not appear in all of the macros
42 void icalerror_stop_here(void);
44 typedef enum icalerrorenum {
48 ICAL_ALLOCATION_ERROR,
49 ICAL_MALFORMEDDATA_ERROR,
51 ICAL_INTERNAL_ERROR, /* Like assert --internal consist. prob */
54 ICAL_UNIMPLEMENTED_ERROR,
55 ICAL_UNKNOWN_ERROR, /* Used for problems in input to icalerror_strerror()*/
60 /* The libical error enumeration, like errno*/
61 extern icalerrorenum icalerrno;
63 /* If true, libicl aborts after a call to icalerror_set_error*/
64 extern int icalerror_errors_are_fatal;
66 /* Warning messages */
69 #define icalerror_warn(message) {fprintf(stderr,"%s(), %s:%d: %s\n",__FUNCTION__,__FILE__,__LINE__,message);}
71 #define icalerror_warn(message) {fprintf(stderr,"%s:%d: %s\n",__FILE__,__LINE__,message);}
72 #endif /* __GNU_C__ */
75 void icalerror_clear_errno(void);
76 void _icalerror_set_errno(icalerrorenum);
78 /* Make an individual error fatal or non-fatal. */
79 typedef enum icalerrorstate {
80 ICAL_ERROR_FATAL, /* Not fata */
81 ICAL_ERROR_NONFATAL, /* Fatal */
82 ICAL_ERROR_DEFAULT, /* Use the value of icalerror_errors_are_fatal*/
83 ICAL_ERROR_UNKNOWN /* Asked state for an unknown error type */
86 char* icalerror_strerror(icalerrorenum e);
87 char* icalerror_perror();
88 void icalerror_set_error_state( icalerrorenum error, icalerrorstate);
89 icalerrorstate icalerror_get_error_state( icalerrorenum error);
92 #define icalerror_set_errno(x) \
94 if(icalerror_get_error_state(x)==ICAL_ERROR_FATAL || \
95 (icalerror_get_error_state(x)==ICAL_ERROR_DEFAULT && \
96 icalerror_errors_are_fatal == 1 )){ \
97 icalerror_warn(icalerror_strerror(x)); \
102 #ifdef ICAL_ERRORS_ARE_FATAL
106 #define icalerror_check_value_type(value,type);
107 #define icalerror_check_property_type(value,type);
108 #define icalerror_check_parameter_type(value,type);
109 #define icalerror_check_component_type(value,type);
111 /* Assert with a message */
112 #ifdef ICAL_ERRORS_ARE_FATAL
115 #define icalerror_assert(test,message) if(!(test)){fprintf(stderr,"%s(), %s:%d: %s\n",__FUNCTION__,__FILE__,__LINE__,message);icalerror_stop_here(); abort();}
117 #define icalerror_assert(test,message) if(!(test)){fprintf(stderr,"%s:%d: %s\n",__FILE__,__LINE__,message);icalerror_stop_here(); abort();}
120 #else /* ICAL_ERRORS_ARE_FATAL */
121 #define icalerror_assert(test,message)
122 #endif /* ICAL_ERRORS_ARE_FATAL */
124 /* Check & abort if check fails */
125 #define icalerror_check_arg(test,arg) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); }
127 /* Check & return void if check fails*/
128 #define icalerror_check_arg_rv(test,arg) if(!(test)) {icalerror_set_errno(ICAL_BADARG_ERROR); return; }
130 /* Check & return 0 if check fails*/
131 #define icalerror_check_arg_rz(test,arg) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); return 0;}
133 /* Check & return an error if check fails*/
134 #define icalerror_check_arg_re(test,arg,error) if(!(test)) { icalerror_stop_here(); assert(0); return error;}
136 /* Check & return something*/
137 #define icalerror_check_arg_rx(test,arg,x) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); return x;}
141 /* String interfaces to set an error to NONFATAL and restore it to its
144 icalerrorstate icalerror_supress(const char* error);
145 void icalerror_restore(const char* error, icalerrorstate es);
148 #endif /* !ICALERROR_H */