2013-02-13 [colin] 3.9.0cvs65
[claws.git] / src / plugins / vcalendar / libical / libical / icalderivedproperty.c.in
1 /* -*- Mode: C -*- */
2
3 /*======================================================================
4   FILE: icalderivedproperty.c
5   CREATOR: eric 15 Feb 2001
6   
7   $Id$
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
39 #include <string.h> /* For icalmemory_strdup, rindex */
40 #include <assert.h>
41 #include <stdlib.h>
42 #include <errno.h>
43 #include <stdio.h> /* for printf */
44 #include <stdarg.h> /* for va_list, va_start, etc. */
45                                                
46 #define TMP_BUF_SIZE 1024
47
48 struct icalproperty_impl*
49 icalproperty_new_impl (icalproperty_kind kind);
50
51 /* This map associates the property kinds with the string
52    representation of the property name and the kind of VALUE that the
53    property uses as a default */
54
55 struct  icalproperty_map {
56         icalproperty_kind kind;
57         const char *name;
58         icalvalue_kind value;
59
60 };
61
62 static struct icalproperty_map property_map[];
63
64 const char* icalproperty_kind_to_string(icalproperty_kind kind)
65 {
66     int i;
67
68     for (i=0; property_map[i].kind != ICAL_NO_PROPERTY; i++) {
69         if (property_map[i].kind == kind) {
70             return property_map[i].name;
71         }
72     }
73
74     return 0;
75
76 }
77
78
79 icalproperty_kind icalproperty_string_to_kind(const char* string)
80 {
81     int i;
82
83     if (string ==0 ) { 
84         return ICAL_NO_PROPERTY;
85     }
86
87
88     for (i=0; property_map[i].kind  != ICAL_NO_PROPERTY; i++) {
89         if (strcmp(property_map[i].name, string) == 0) {
90             return property_map[i].kind;
91         }
92     }
93
94     if(strncmp(string,"X-",2)==0){
95         return ICAL_X_PROPERTY;
96     }
97
98
99     return ICAL_NO_PROPERTY;
100 }
101
102
103 icalvalue_kind icalproperty_value_kind_to_kind(icalvalue_kind kind)
104 {
105     int i;
106
107     for (i=0; property_map[i].kind  != ICAL_NO_PROPERTY; i++) {
108         if ( property_map[i].value == kind ) {
109             return property_map[i].kind;
110         }
111     }
112
113     return ICAL_NO_VALUE;
114 }
115
116
117
118 icalvalue_kind icalproperty_kind_to_value_kind(icalproperty_kind kind)
119 {
120     int i;
121
122     for (i=0; property_map[i].kind  != ICAL_NO_PROPERTY; i++) {
123         if ( property_map[i].kind == kind ) {
124             return property_map[i].value;
125         }
126     }
127
128     return ICAL_NO_VALUE;
129 }
130
131
132 /* This map associates the property enumerations with the king of
133    property that they are used in and the string representation of the
134    enumeration */
135
136 struct icalproperty_enum_map {
137     icalproperty_kind prop;
138     int prop_enum;
139     const char* str;
140 }; 
141
142 static struct icalproperty_enum_map enum_map[];
143
144
145 const char* icalproperty_enum_to_string(int e)
146 {
147     icalerror_check_arg_rz(e >= ICALPROPERTY_FIRST_ENUM,"e");
148     icalerror_check_arg_rz(e <= ICALPROPERTY_LAST_ENUM,"e");
149
150     return enum_map[e-ICALPROPERTY_FIRST_ENUM].str;
151 }
152
153 int icalproperty_string_to_enum(const char* str)
154 {
155     int i;
156
157     icalerror_check_arg_rz(str!=0,"str")
158
159     while(*str == ' '){
160         str++;
161     }
162
163     for (i=ICALPROPERTY_FIRST_ENUM; i != ICALPROPERTY_LAST_ENUM; i++) {
164         if ( strcmp(enum_map[i-ICALPROPERTY_FIRST_ENUM].str, str) == 0) {
165             return enum_map[i-ICALPROPERTY_FIRST_ENUM].prop_enum;
166         }
167     }
168
169     return 0;
170 }
171
172 int icalproperty_enum_belongs_to_property(icalproperty_kind kind, int e)
173 {
174     int i;
175
176
177     for (i=ICALPROPERTY_FIRST_ENUM; i != ICALPROPERTY_LAST_ENUM; i++) {
178         if(enum_map[i-ICALPROPERTY_FIRST_ENUM].prop_enum == e && 
179            enum_map[i-ICALPROPERTY_FIRST_ENUM].prop == kind ){
180             return 1;
181         }
182     }
183
184     return 0;
185 }
186
187
188 const char* icalproperty_method_to_string(icalproperty_method method)
189 {
190     icalerror_check_arg_rz(method >= ICAL_METHOD_X,"method");
191     icalerror_check_arg_rz(method <= ICAL_METHOD_NONE,"method");
192
193     return enum_map[method-ICALPROPERTY_FIRST_ENUM].str;
194 }
195
196 icalproperty_method icalproperty_string_to_method(const char* str)
197 {
198     int i;
199
200     icalerror_check_arg_rx(str!=0,"str",ICAL_METHOD_NONE)
201
202     while(*str == ' '){
203         str++;
204     }
205
206     for (i=ICAL_METHOD_X-ICALPROPERTY_FIRST_ENUM; 
207          i != ICAL_METHOD_NONE-ICALPROPERTY_FIRST_ENUM;
208          i++) {
209         if ( strcmp(enum_map[i].str, str) == 0) {
210             return (icalproperty_method)enum_map[i].prop_enum;
211         }
212     }
213
214     return ICAL_METHOD_NONE;
215 }
216
217
218 const char* icalenum_status_to_string(icalproperty_status status)
219 {
220     icalerror_check_arg_rz(status >= ICAL_STATUS_X,"status");
221     icalerror_check_arg_rz(status <= ICAL_STATUS_NONE,"status");
222
223     return enum_map[status-ICALPROPERTY_FIRST_ENUM].str;
224 }
225
226 icalproperty_status icalenum_string_to_status(const char* str)
227 {
228     int i;
229
230     icalerror_check_arg_rx(str!=0,"str",ICAL_STATUS_NONE)
231
232     while(*str == ' '){
233         str++;
234     }
235
236     for (i=ICAL_STATUS_X-ICALPROPERTY_FIRST_ENUM; 
237          i != ICAL_STATUS_NONE-ICALPROPERTY_FIRST_ENUM;
238          i++) {
239         if ( strcmp(enum_map[i].str, str) == 0) {
240             return (icalproperty_method)enum_map[i].prop_enum;
241         }
242     }
243
244     return ICAL_STATUS_NONE;
245
246 }
247
248
249
250 /* Everything below this line is machine generated. Do not edit. */