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