aboutsummaryrefslogtreecommitdiffstats
path: root/libical/src/libical/icalderivedproperty.c.in
blob: ceec0b797d986b02542d27d8782d10780bdc8ff2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/* -*- Mode: C -*- */

/*======================================================================
  FILE: icalderivedproperty.c
  CREATOR: eric 15 Feb 2001
  
  $Id: icalderivedproperty.c.in,v 1.1 2001/04/17 17:23:17 jpr Exp $


 (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org

 This program is free software; you can redistribute it and/or modify
 it under the terms of either: 

    The LGPL as published by the Free Software Foundation, version
    2.1, available at: http://www.fsf.org/copyleft/lesser.html

  Or:

    The Mozilla Public License Version 1.0. You may obtain a copy of
    the License at http://www.mozilla.org/MPL/

  The original code is icalproperty.c

======================================================================*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "icalproperty.h"
#include "icalcomponent.h"
#include "pvl.h"
#include "icalenums.h"
#include "icalerror.h"
#include "icalmemory.h"
#include "icalparser.h"

#include <string.h> /* For icalmemory_strdup, rindex */
#include <assert.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h> /* for printf */
#include <stdarg.h> /* for va_list, va_start, etc. */
                                               
#define TMP_BUF_SIZE 1024

struct icalproperty_impl*
icalproperty_new_impl (icalproperty_kind kind);

/* This map associates the property kinds with the string
   representation of the property name and the kind of VALUE that the
   property uses as a default */

struct  icalproperty_map {
    icalproperty_kind kind;
    const char *name;
    icalvalue_kind value;

};

extern struct icalproperty_map property_map[];

const char* icalproperty_kind_to_string(icalproperty_kind kind)
{
    int i;

    for (i=0; property_map[i].kind != ICAL_NO_PROPERTY; i++) {
    if (property_map[i].kind == kind) {
        return property_map[i].name;
    }
    }

    return 0;

}


icalproperty_kind icalproperty_string_to_kind(const char* string)
{
    int i;

    if (string ==0 ) { 
    return ICAL_NO_PROPERTY;
    }


    for (i=0; property_map[i].kind  != ICAL_NO_PROPERTY; i++) {
    if (strcmp(property_map[i].name, string) == 0) {
        return property_map[i].kind;
    }
    }

    if(strncmp(string,"X-",2)==0){
    return ICAL_X_PROPERTY;
    }


    return ICAL_NO_PROPERTY;
}


icalvalue_kind icalproperty_value_kind_to_kind(icalvalue_kind kind)
{
    int i;

    for (i=0; property_map[i].kind  != ICAL_NO_PROPERTY; i++) {
    if ( property_map[i].value == kind ) {
        return property_map[i].kind;
    }
    }

    return ICAL_NO_VALUE;
}



icalvalue_kind icalproperty_kind_to_value_kind(icalproperty_kind kind)
{
    int i;

    for (i=0; property_map[i].kind  != ICAL_NO_PROPERTY; i++) {
    if ( property_map[i].kind == kind ) {
        return property_map[i].value;
    }
    }

    return ICAL_NO_VALUE;
}


/* This map associates the property enumerations with the king of
   property that they are used in and the string representation of the
   enumeration */

struct icalproperty_enum_map {
    icalproperty_kind prop;
    int prop_enum;
    const char* str;
}; 

extern struct icalproperty_enum_map enum_map[];


const char* icalproperty_enum_to_string(int e)
{
    icalerror_check_arg_rz(e >= ICALPROPERTY_FIRST_ENUM,"e");
    icalerror_check_arg_rz(e <= ICALPROPERTY_LAST_ENUM,"e");

    return enum_map[e-ICALPROPERTY_FIRST_ENUM].str;
}

int icalproperty_string_to_enum(const char* str)
{
    int i;

    icalerror_check_arg_rz(str!=0,"str")

    while(*str == ' '){
    str++;
    }

    for (i=ICALPROPERTY_FIRST_ENUM; i != ICALPROPERTY_LAST_ENUM; i++) {
    if ( strcmp(enum_map[i-ICALPROPERTY_FIRST_ENUM].str, str) == 0) {
        return enum_map[i-ICALPROPERTY_FIRST_ENUM].prop_enum;
    }
    }

    return 0;
}

int icalproperty_enum_belongs_to_property(icalproperty_kind kind, int e)
{
    int i;


    for (i=ICALPROPERTY_FIRST_ENUM; i != ICALPROPERTY_LAST_ENUM; i++) {
        if(enum_map[i-ICALPROPERTY_FIRST_ENUM].prop_enum == e && 
           enum_map[i-ICALPROPERTY_FIRST_ENUM].prop == kind ){
            return 1;
        }
    }

    return 0;
}


const char* icalproperty_method_to_string(icalproperty_method method)
{
    icalerror_check_arg_rz(method >= ICAL_METHOD_X,"method");
    icalerror_check_arg_rz(method <= ICAL_METHOD_NONE,"method");

    return enum_map[method-ICALPROPERTY_FIRST_ENUM].str;
}

icalproperty_method icalproperty_string_to_method(const char* str)
{
    int i;

    icalerror_check_arg_rx(str!=0,"str",ICAL_METHOD_NONE)

    while(*str == ' '){
    str++;
    }

    for (i=ICAL_METHOD_X-ICALPROPERTY_FIRST_ENUM; 
         i != ICAL_METHOD_NONE-ICALPROPERTY_FIRST_ENUM;
         i++) {
    if ( strcmp(enum_map[i].str, str) == 0) {
        return (icalproperty_method)enum_map[i].prop_enum;
    }
    }

    return ICAL_METHOD_NONE;
}


const char* icalenum_status_to_string(icalproperty_status status)
{
    icalerror_check_arg_rz(status >= ICAL_STATUS_X,"status");
    icalerror_check_arg_rz(status <= ICAL_STATUS_NONE,"status");

    return enum_map[status-ICALPROPERTY_FIRST_ENUM].str;
}

icalproperty_status icalenum_string_to_status(const char* str)
{
    int i;

    icalerror_check_arg_rx(str!=0,"str",ICAL_STATUS_NONE)

    while(*str == ' '){
    str++;
    }

    for (i=ICAL_STATUS_X-ICALPROPERTY_FIRST_ENUM; 
         i != ICAL_STATUS_NONE-ICALPROPERTY_FIRST_ENUM;
         i++) {
    if ( strcmp(enum_map[i].str, str) == 0) {
        return (icalproperty_method)enum_map[i].prop_enum;
    }
    }

    return ICAL_STATUS_NONE;

}



/* Everything below this line is machine generated. Do not edit. */