3 require "readvaluesfile.pl";
8 # ARG 0 is properties.csv
9 %propmap = read_properties_file($ARGV[0]);
11 # ARG 1 is value-types.txt
12 %valuemap = read_values_file($ARGV[1]);
17 # Write the file inline by copying everything before a demarcation
18 # line, and putting the generated data after the demarcation
22 open(IN,$opt_i) || die "Can't open input file $opt_i";
26 if (/<insert_code_here>/){
39 my $value = $propmap{$prop}->{'lic_value'};
42 die "Can't find value for property \"$prop\"\n";
44 my $ucf = join("",map {ucfirst(lc($_));} split(/-/,$prop));
48 my $ucfvalue = join("",map {ucfirst(lc($_));} split(/-/,$value));
49 my $lcvalue = lc($ucfvalue);
50 my $ucvalue = uc($lcvalue);
52 my $type = $valuemap{$value}->{C}->[1];
54 return ($uc,$lc,$lcvalue,$ucvalue,$type);
60 # Create the property map data
64 my @props = sort keys %propmap;
65 my $count = scalar(@props);
68 print "static const struct icalproperty_map property_map[$count] = {\n";
70 foreach $prop (@props) {
74 next if $prop eq 'NO';
76 my ($uc,$lc,$lcvalue,$ucvalue,$type) = fudge_data($prop);
78 print "{ICAL_${uc}_PROPERTY,\"$prop\",ICAL_${ucvalue}_VALUE},\n";
84 my ($uc,$lc,$lcvalue,$ucvalue,$type) = fudge_data($prop);
86 print "{ICAL_${uc}_PROPERTY,\"\",ICAL_NO_VALUE}};\n\n";
92 foreach $value (sort keys %valuemap) {
95 next if $value eq 'NO' or $prop eq 'ANY';
97 my $ucv = join("",map {uc(lc($_));} split(/-/,$value));
98 my @enums = @{$valuemap{$value}->{'enums'}};
102 my ($c_autogen,$c_type) = @{$valuemap{$value}->{'C'}};
107 foreach $e (@enums) {
109 my $uce = join("",map {uc(lc($_));} split(/-/,$e));
111 if($e ne "X" and $e ne "NONE"){
117 $out.=" {ICAL_${ucv}_PROPERTY,ICAL_${ucv}_${uce},\"$str\" }, /*$idx*/\n";
127 print "static const struct icalproperty_enum_map enum_map[$count] = {\n";
129 print " {ICAL_NO_PROPERTY,0,\"\"}\n};\n\n";
138 # Create the property enumerations list
139 print "typedef enum icalproperty_kind {\n ICAL_ANY_PROPERTY = 0,\n";
140 foreach $prop (sort keys %propmap) {
144 next if $prop eq 'NO' or $prop eq 'ANY';
146 my ($uc,$lc,$lcvalue,$ucvalue,$type) = fudge_data($prop);
148 print " ICAL_${uc}_PROPERTY, \n";
151 print " ICAL_NO_PROPERTY\n} icalproperty_kind;\n\n";
157 foreach $prop (sort keys %propmap) {
161 next if $prop eq 'NO' or $prop eq 'ANY';
163 my ($uc,$lc,$lcvalue,$ucvalue,$type) = fudge_data($prop);
168 $pointer_check = "icalerror_check_arg_rz( (v!=0),\"v\");\n" if $type =~ /\*/;
169 } elsif ( $type eq "void" ){
170 $pointer_check = "icalerror_check_arg_rv( (v!=0),\"v\");\n" if $type =~ /\*/;
174 my $set_pointer_check = "icalerror_check_arg_rv( (v!=0),\"v\");\n" if $type =~ /\*/;
176 if($opt_c) { # Generate C source
178 if ($include_vanew) {
180 icalproperty* icalproperty_vanew_${lc}($type v, ...){
182 struct icalproperty_impl *impl;
184 impl= icalproperty_new_impl(ICAL_${uc}_PROPERTY);
185 icalproperty_set_${lc}((icalproperty*)impl,v);
187 icalproperty_add_parameters(impl, args);
189 return (icalproperty*)impl;
196 icalproperty* icalproperty_new_${lc}($type v) {
197 struct icalproperty_impl *impl;
199 impl = icalproperty_new_impl(ICAL_${uc}_PROPERTY);
200 icalproperty_set_${lc}((icalproperty*)impl,v);
201 return (icalproperty*)impl;
205 # Allow DTSTART, DTEND, DUE, EXDATE and RECURRENCE-ID to take DATE values.
206 if ($lc eq "dtstart" || $lc eq "dtend" || $lc eq "due" || $lc eq "exdate"
207 || $lc eq "recurrenceid") {
209 void icalproperty_set_${lc}(icalproperty* prop, $type v){
212 icalerror_check_arg_rv( (prop!=0),"prop");
214 value = icalvalue_new_date(v);
216 value = icalvalue_new_datetime(v);
217 icalproperty_set_value(prop,value);
223 void icalproperty_set_${lc}(icalproperty* prop, $type v){
225 icalerror_check_arg_rv( (prop!=0),"prop");
226 icalproperty_set_value(prop,icalvalue_new_${lcvalue}(v));
230 # Dirk Theisen pointed out, exdate needs to match TZID parameters in EXDATE
231 if ($lc eq "exdate") {
233 $type icalproperty_get_${lc}(const icalproperty* prop){
235 struct icaltimetype itt;
236 icalparameter* param;
239 icalerror_check_arg( (prop!=0),"prop");
242 * Code by dirk\@objectpark.net:
243 * Set the time zone manually. I am really puzzled that
244 * it doesnot work automatically like in the other functions
245 * like icalproperty_get_dtstart().
247 itt = icalvalue_get_datetime(icalproperty_get_value(prop));
248 param = icalproperty_get_first_parameter(prop, ICAL_TZID_PARAMETER);
250 zone = icaltimezone_get_builtin_timezone(icalparameter_get_tzid(param));
251 icaltime_set_timezone(&itt, zone);
255 return icalvalue_get_datetime(icalproperty_get_value(prop));
261 $type icalproperty_get_${lc}(const icalproperty* prop){
262 icalerror_check_arg( (prop!=0),"prop");
263 return icalvalue_get_${lcvalue}(icalproperty_get_value(prop));
267 } elsif ($opt_h) { # Generate C Header file
272 icalproperty* icalproperty_new_${lc}($type v);\
273 void icalproperty_set_${lc}(icalproperty* prop, $type v);\
274 $type icalproperty_get_${lc}(const icalproperty* prop);";
278 print "icalproperty* icalproperty_vanew_${lc}($type v, ...);\n";
284 } # This brace terminates the main loop
290 print "\n\n#endif /*ICALPROPERTY_H*/\n"