1f521c6a619b8d9f0f46ca26e9f783e1887b6a9b
[claws.git] / src / plugins / vcalendar / libical / libical / icalerror.h
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
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
41    below */
42 void icalerror_stop_here(void);
43
44 typedef enum icalerrorenum {
45     
46     ICAL_BADARG_ERROR,
47     ICAL_NEWFAILED_ERROR,
48     ICAL_ALLOCATION_ERROR,
49     ICAL_MALFORMEDDATA_ERROR, 
50     ICAL_PARSE_ERROR,
51     ICAL_INTERNAL_ERROR, /* Like assert --internal consist. prob */
52     ICAL_FILE_ERROR,
53     ICAL_USAGE_ERROR,
54     ICAL_UNIMPLEMENTED_ERROR,
55     ICAL_UNKNOWN_ERROR, /* Used for problems in input to icalerror_strerror()*/
56     ICAL_NO_ERROR
57
58 } icalerrorenum;
59
60 /* The libical error enumeration, like errno*/
61 extern icalerrorenum icalerrno;
62
63 /* If true, libicl aborts after a call to icalerror_set_error*/
64 extern int icalerror_errors_are_fatal;
65
66 /* Warning messages */
67
68 #ifdef __GNUC__ca
69 #define icalerror_warn(message) {fprintf(stderr,"%s(), %s:%d: %s\n",__FUNCTION__,__FILE__,__LINE__,message);}
70 #else /* __GNU_C__ */
71 #define icalerror_warn(message) {fprintf(stderr,"%s:%d: %s\n",__FILE__,__LINE__,message);}
72 #endif /* __GNU_C__ */
73
74
75 void icalerror_clear_errno(void);
76 void _icalerror_set_errno(icalerrorenum);
77
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 */
84 } icalerrorstate ;
85
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);
90
91
92 #define icalerror_set_errno(x) \
93 icalerrno = 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)); \
98    assert(0); \
99
100
101
102 #ifdef ICAL_ERRORS_ARE_FATAL
103 #undef NDEBUG
104 #endif
105
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);
110
111 /* Assert with a message */
112 #ifdef ICAL_ERRORS_ARE_FATAL
113
114 #ifdef __GNUC__
115 #define icalerror_assert(test,message) if(!(test)){fprintf(stderr,"%s(), %s:%d: %s\n",__FUNCTION__,__FILE__,__LINE__,message);icalerror_stop_here(); abort();}
116 #else /*__GNUC__*/
117 #define icalerror_assert(test,message) if(!(test)){fprintf(stderr,"%s:%d: %s\n",__FILE__,__LINE__,message);icalerror_stop_here(); abort();}
118 #endif /*__GNUC__*/
119
120 #else /* ICAL_ERRORS_ARE_FATAL */
121 #define icalerror_assert(test,message) 
122 #endif /* ICAL_ERRORS_ARE_FATAL */
123
124 /* Check & abort if check fails */
125 #define icalerror_check_arg(test,arg) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); }
126
127 /* Check & return void if check fails*/
128 #define icalerror_check_arg_rv(test,arg) if(!(test)) {icalerror_set_errno(ICAL_BADARG_ERROR); return; }
129
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;}
132
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;}
135
136 /* Check & return something*/
137 #define icalerror_check_arg_rx(test,arg,x) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); return x;}
138
139
140
141 /* String interfaces to set an error to NONFATAL and restore it to its
142    original value */
143
144 icalerrorstate icalerror_supress(const char* error);
145 void icalerror_restore(const char* error, icalerrorstate es);
146
147
148 #endif /* !ICALERROR_H */
149
150
151