summaryrefslogtreecommitdiffabout
path: root/libical/src/libical/icalerror.c
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /libical/src/libical/icalerror.c
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'libical/src/libical/icalerror.c') (more/less context) (ignore whitespace changes)
-rw-r--r--libical/src/libical/icalerror.c209
1 files changed, 209 insertions, 0 deletions
diff --git a/libical/src/libical/icalerror.c b/libical/src/libical/icalerror.c
new file mode 100644
index 0000000..d44d37a
--- a/dev/null
+++ b/libical/src/libical/icalerror.c
@@ -0,0 +1,209 @@
1/* -*- Mode: C -*-
2 ======================================================================
3 FILE: icalerror.c
4 CREATOR: eric 16 May 1999
5
6 $Id$
7 $Locker$
8
9
10 (C) COPYRIGHT 2000, Eric Busboom, 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.c
24
25 ======================================================================*/
26
27
28#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32#include "icalerror.h"
33
34#include <string.h>
35
36icalerrorenum icalerrno;
37
38int foo;
39void icalerror_stop_here(void)
40{
41 foo++; /* Keep optimizers from removing routine */
42}
43
44void icalerror_crash_here(void)
45{
46 int *p=0;
47 *p = 1;
48
49 assert( *p);
50}
51
52#ifdef ICAL_SETERROR_ISFUNC
53void icalerror_set_errno(icalerrorenum x)
54{
55 icalerrno = x;
56 if(icalerror_get_error_state(x)==ICAL_ERROR_FATAL ||
57 (icalerror_get_error_state(x)==ICAL_ERROR_DEFAULT &&
58 icalerror_errors_are_fatal == 1 )){
59 icalerror_warn(icalerror_strerror(x));
60 assert(0);
61 }
62
63}
64#endif
65
66void icalerror_clear_errno() {
67
68 icalerrno = ICAL_NO_ERROR;
69}
70
71#ifdef ICAL_ERRORS_ARE_FATAL
72int icalerror_errors_are_fatal = 1;
73#else
74int icalerror_errors_are_fatal = 0;
75#endif
76
77struct icalerror_state {
78 icalerrorenum error;
79 icalerrorstate state;
80};
81
82struct icalerror_state error_state_map[] =
83{
84 { ICAL_BADARG_ERROR,ICAL_ERROR_DEFAULT},
85 { ICAL_NEWFAILED_ERROR,ICAL_ERROR_DEFAULT},
86 { ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_DEFAULT},
87 { ICAL_PARSE_ERROR,ICAL_ERROR_DEFAULT},
88 { ICAL_INTERNAL_ERROR,ICAL_ERROR_DEFAULT},
89 { ICAL_FILE_ERROR,ICAL_ERROR_DEFAULT},
90 { ICAL_USAGE_ERROR,ICAL_ERROR_DEFAULT},
91 { ICAL_UNIMPLEMENTED_ERROR,ICAL_ERROR_DEFAULT},
92 { ICAL_UNKNOWN_ERROR,ICAL_ERROR_DEFAULT},
93 { ICAL_NO_ERROR,ICAL_ERROR_DEFAULT}
94
95};
96
97struct icalerror_string_map {
98 const char* str;
99 icalerrorenum error;
100 char name[160];
101};
102
103static struct icalerror_string_map string_map[] =
104{
105 {"BADARG",ICAL_BADARG_ERROR,"BADARG: Bad argument to function"},
106 { "NEWFAILED",ICAL_NEWFAILED_ERROR,"NEWFAILED: Failed to create a new object via a *_new() routine"},
107 {"MALFORMEDDATA",ICAL_MALFORMEDDATA_ERROR,"MALFORMEDDATA: An input string was not correctly formed or a component has missing or extra properties"},
108 { "PARSE",ICAL_PARSE_ERROR,"PARSE: Failed to parse a part of an iCal component"},
109 {"INTERNAL",ICAL_INTERNAL_ERROR,"INTERNAL: Random internal error. This indicates an error in the library code, not an error in use"},
110 { "FILE",ICAL_FILE_ERROR,"FILE: An operation on a file failed. Check errno for more detail."},
111 { "USAGE",ICAL_USAGE_ERROR,"USAGE: Failed to propertyl sequence calls to a set of interfaces"},
112 { "UNIMPLEMENTED",ICAL_UNIMPLEMENTED_ERROR,"UNIMPLEMENTED: This feature has not been implemented"},
113 { "NO",ICAL_NO_ERROR,"NO: No error"},
114 {"UNKNOWN",ICAL_UNKNOWN_ERROR,"UNKNOWN: Unknown error type -- icalerror_strerror() was probably given bad input"}
115};
116
117
118icalerrorenum icalerror_error_from_string(const char* str){
119
120 icalerrorenum e;
121 int i = 0;
122
123 for( i = 0; string_map[i].error != ICAL_NO_ERROR; i++){
124 if (strcmp(string_map[i].str,str) == 0){
125 e = string_map[i].error;
126 }
127 }
128
129 return e;
130}
131
132icalerrorstate icalerror_supress(const char* error){
133
134 icalerrorenum e = icalerror_error_from_string(error);
135 icalerrorstate es;
136
137 if (e == ICAL_NO_ERROR){
138 return ICAL_ERROR_UNKNOWN;
139 }
140
141
142 es = icalerror_get_error_state(e);
143 icalerror_set_error_state(e,ICAL_ERROR_NONFATAL);
144
145 return es;
146}
147
148char* icalerror_perror()
149{
150 return icalerror_strerror(icalerrno);
151}
152
153void icalerror_restore(const char* error, icalerrorstate es){
154
155
156 icalerrorenum e = icalerror_error_from_string(error);
157
158 if (e != ICAL_NO_ERROR){
159 icalerror_set_error_state(e,es);
160 }
161
162}
163
164
165
166void icalerror_set_error_state( icalerrorenum error,
167 icalerrorstate state)
168{
169 int i;
170
171 for(i = ICAL_BADARG_ERROR; error_state_map[i].error!= ICAL_NO_ERROR;i++){
172 if(error_state_map[i].error == error){
173 error_state_map[i].state = state;
174 }
175 }
176}
177
178icalerrorstate icalerror_get_error_state( icalerrorenum error)
179{
180 int i;
181
182 for(i = ICAL_BADARG_ERROR; error_state_map[i].error!= ICAL_NO_ERROR;i++){
183 if(error_state_map[i].error == error){
184 return error_state_map[i].state;
185 }
186 }
187
188 return ICAL_ERROR_UNKNOWN;
189}
190
191
192
193
194char* icalerror_strerror(icalerrorenum e) {
195
196 int i;
197
198 for (i=0; string_map[i].error != ICAL_UNKNOWN_ERROR; i++) {
199 if (string_map[i].error == e) {
200 return string_map[i].name;
201 }
202 }
203
204 return string_map[i].name; /* Return string for ICAL_UNKNOWN_ERROR*/
205
206}
207
208
209