bump to 1.0.0 and clean up spec file
[platform/upstream/libical.git] / src / libical / icalderivedproperty.c.in
1 /* -*- Mode: C -*- */
2
3 /*======================================================================
4   FILE: icalderivedproperty.c
5   CREATOR: eric 15 Feb 2001
6   
7   $Id: icalderivedproperty.c.in,v 1.15 2008-01-28 22:34:37 artcancro Exp $
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 icalproperty.c
24
25 ======================================================================*/
26
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30
31 #include "icalproperty.h"
32 #include "icalcomponent.h"
33 #include "pvl.h"
34 #include "icalenums.h"
35 #include "icalerror.h"
36 #include "icalmemory.h"
37 #include "icalparser.h"
38 #include "icaltimezone.h"
39
40 #include <string.h> /* For icalmemory_strdup, rindex */
41 #include <assert.h>
42 #include <stdlib.h>
43 #include <errno.h>
44 #include <stdio.h> /* for printf */
45 #include <stdarg.h> /* for va_list, va_start, etc. */
46
47 #ifdef _MSC_VER
48 #define strcasecmp stricmp
49 #endif
50
51 struct icalproperty_impl*
52 icalproperty_new_impl (icalproperty_kind kind);
53 void icalproperty_add_parameters(struct icalproperty_impl *prop,va_list args);
54
55 /* This map associates the property kinds with the string
56    representation of the property name and the kind of VALUE that the
57    property uses as a default */
58
59 struct  icalproperty_map {
60         icalproperty_kind kind;
61         const char *name;
62         icalvalue_kind value;
63
64 };
65
66 /* This map associates the property enumerations with the king of
67    property that they are used in and the string representation of the
68    enumeration */
69
70 struct icalproperty_enum_map {
71     icalproperty_kind prop;
72     int prop_enum;
73     const char* str;
74 }; 
75
76
77 <insert_code_here>
78
79 int icalproperty_kind_is_valid(const icalproperty_kind kind)
80 {
81     int i = 0;
82     do {
83       if (property_map[i].kind == kind)
84         return 1;
85     } while (property_map[i++].kind != ICAL_NO_PROPERTY);
86
87     return 0;
88 }  
89
90 const char* icalproperty_kind_to_string(icalproperty_kind kind)
91 {
92     int i;
93
94     for (i=0; property_map[i].kind != ICAL_NO_PROPERTY; i++) {
95         if (property_map[i].kind == kind) {
96             return property_map[i].name;
97         }
98     }
99
100     return 0;
101
102 }
103
104
105 icalproperty_kind icalproperty_string_to_kind(const char* string)
106 {
107     int i;
108
109     if (string ==0 ) { 
110         return ICAL_NO_PROPERTY;
111     }
112
113
114     for (i=0; property_map[i].kind  != ICAL_NO_PROPERTY; i++) {
115         if (strcasecmp(property_map[i].name, string) == 0) {
116             return property_map[i].kind;
117         }
118     }
119
120     if(strncmp(string,"X-",2)==0){
121         return ICAL_X_PROPERTY;
122     }
123
124
125     return ICAL_NO_PROPERTY;
126 }
127
128
129 icalproperty_kind icalproperty_value_kind_to_kind(icalvalue_kind kind)
130 {
131     int i;
132
133     for (i=0; property_map[i].kind  != ICAL_NO_PROPERTY; i++) {
134         if ( property_map[i].value == kind ) {
135             return property_map[i].kind;
136         }
137     }
138
139     return ICAL_NO_PROPERTY;
140 }
141
142
143
144 icalvalue_kind icalproperty_kind_to_value_kind(icalproperty_kind kind)
145 {
146     int i;
147
148     for (i=0; property_map[i].kind  != ICAL_NO_PROPERTY; i++) {
149         if ( property_map[i].kind == kind ) {
150             return property_map[i].value;
151         }
152     }
153
154     return ICAL_NO_VALUE;
155 }
156
157
158 const char* icalproperty_enum_to_string(int e)
159 {
160     icalerror_check_arg_rz(e >= ICALPROPERTY_FIRST_ENUM,"e");
161     icalerror_check_arg_rz(e <= ICALPROPERTY_LAST_ENUM,"e");
162
163     return enum_map[e-ICALPROPERTY_FIRST_ENUM].str;
164 }
165
166
167 char *icalproperty_enum_to_string_r(int e)
168 {
169         return icalmemory_strdup(icalproperty_enum_to_string(e));
170 }
171
172
173 int icalproperty_kind_and_string_to_enum(const int kind, const char* str)
174 {
175     icalproperty_kind pkind;
176     int i;
177
178     icalerror_check_arg_rz(str!=0,"str")
179
180     if ((pkind = icalproperty_value_kind_to_kind(kind)) == ICAL_NO_PROPERTY)
181         return 0;
182
183     while(*str == ' '){
184         str++;
185     }
186
187     for (i=ICALPROPERTY_FIRST_ENUM; i != ICALPROPERTY_LAST_ENUM; i++) {
188         if (enum_map[i-ICALPROPERTY_FIRST_ENUM].prop == pkind)
189             break;
190     }
191     if (i == ICALPROPERTY_LAST_ENUM)
192             return 0;
193
194     for (; i != ICALPROPERTY_LAST_ENUM; i++) {
195         if(enum_map[i-ICALPROPERTY_FIRST_ENUM].prop == pkind &&
196            strcasecmp(enum_map[i-ICALPROPERTY_FIRST_ENUM].str, str) == 0) {
197             return enum_map[i-ICALPROPERTY_FIRST_ENUM].prop_enum;
198         }
199     }
200
201     return 0;
202 }
203
204 /** @deprecated please use icalproperty_kind_and_string_to_enum instead */
205 int icalproperty_string_to_enum(const char* str)
206 {
207     int i;
208
209     icalerror_check_arg_rz(str!=0,"str")
210
211     while(*str == ' '){
212         str++;
213     }
214
215     for (i=ICALPROPERTY_FIRST_ENUM; i != ICALPROPERTY_LAST_ENUM; i++) {
216         if ( strcasecmp(enum_map[i-ICALPROPERTY_FIRST_ENUM].str, str) == 0) {
217             return enum_map[i-ICALPROPERTY_FIRST_ENUM].prop_enum;
218         }
219     }
220
221     return 0;
222 }
223
224 int icalproperty_enum_belongs_to_property(icalproperty_kind kind, int e)
225 {
226     int i;
227
228
229     for (i=ICALPROPERTY_FIRST_ENUM; i != ICALPROPERTY_LAST_ENUM; i++) {
230         if(enum_map[i-ICALPROPERTY_FIRST_ENUM].prop_enum == e && 
231            enum_map[i-ICALPROPERTY_FIRST_ENUM].prop == kind ){
232             return 1;
233         }
234     }
235
236     return 0;
237 }
238
239
240 const char* icalproperty_method_to_string(icalproperty_method method)
241 {
242     icalerror_check_arg_rz(method >= ICAL_METHOD_X,"method");
243     icalerror_check_arg_rz(method <= ICAL_METHOD_NONE,"method");
244
245     return enum_map[method-ICALPROPERTY_FIRST_ENUM].str;
246 }
247
248 icalproperty_method icalproperty_string_to_method(const char* str)
249 {
250     int i;
251
252     icalerror_check_arg_rx(str!=0,"str",ICAL_METHOD_NONE)
253
254     while(*str == ' '){
255         str++;
256     }
257
258     for (i=ICAL_METHOD_X-ICALPROPERTY_FIRST_ENUM; 
259          i != ICAL_METHOD_NONE-ICALPROPERTY_FIRST_ENUM;
260          i++) {
261         if ( strcasecmp(enum_map[i].str, str) == 0) {
262             return (icalproperty_method)enum_map[i].prop_enum;
263         }
264     }
265
266     return ICAL_METHOD_NONE;
267 }
268
269
270 const char* icalenum_status_to_string(icalproperty_status status)
271 {
272     icalerror_check_arg_rz(status >= ICAL_STATUS_X,"status");
273     icalerror_check_arg_rz(status <= ICAL_STATUS_NONE,"status");
274
275     return enum_map[status-ICALPROPERTY_FIRST_ENUM].str;
276 }
277
278 icalproperty_status icalenum_string_to_status(const char* str)
279 {
280     int i;
281
282     icalerror_check_arg_rx(str!=0,"str",ICAL_STATUS_NONE)
283
284     while(*str == ' '){
285         str++;
286     }
287
288     for (i=ICAL_STATUS_X-ICALPROPERTY_FIRST_ENUM; 
289          i != ICAL_STATUS_NONE-ICALPROPERTY_FIRST_ENUM;
290          i++) {
291         if ( strcasecmp(enum_map[i].str, str) == 0) {
292             return (icalproperty_status)enum_map[i].prop_enum;
293         }
294     }
295
296     return ICAL_STATUS_NONE;
297
298 }