5 require 'readvaluesfile.pl';
11 # c -> generate c code file
12 # h-> generate header file
14 # Open with value-types.txt
16 my %h = read_values_file($ARGV[0]);
19 # Write the file inline by copying everything before a demarcation
20 # line, and putting the generated data after the demarcation
24 open(IN,$opt_i) || die "Can't open input file $opt_i";
32 # Map type names to the value in the icalvalue_impl data union */
40 DATETIMEPERIOD=>'period',
54 # First print out the value enumerations
56 print "typedef enum icalvalue_kind {\n";
57 print " ICAL_ANY_VALUE=$idx,\n";
59 foreach $value (keys %h) {
62 my $ucv = join("",map {uc(lc($_));} split(/-/,$value));
64 next if $value eq "NO";
66 print " ICAL_${ucv}_VALUE=$idx,\n";
70 print " ICAL_NO_VALUE=$idx\n} icalvalue_kind ;\n\n";
72 # Now create enumerations for property values
75 print "#define ICALPROPERTY_FIRST_ENUM $idx\n\n";
77 foreach $value (sort keys %h) {
81 next if $value eq 'NO' or $prop eq 'ANY';
83 my $ucv = join("",map {uc(lc($_));} split(/-/,$value));
84 my @enums = @{$h{$value}->{'enums'}};
88 my ($c_autogen,$c_type) = @{$h{$value}->{'C'}};
89 print "typedef $c_type {\n";
103 my $uce = join("",map {uc(lc($_));} split(/-/,$e));
105 print " ICAL_${ucv}_${uce} = $idx";
110 $c_type =~ s/enum //;
112 print "\n} $c_type;\n\n";
116 print "#define ICALPROPERTY_LAST_ENUM $idx\n\n";
123 # print out the value to string map
125 print "static struct icalvalue_kind_map value_map[]={\n";
127 foreach $value (keys %h) {
130 my $ucv = join("",map {uc(lc($_));} split(/-/,$value));
132 next if $value eq "NO";
134 print " {ICAL_${ucv}_VALUE,\"$value\"},\n";
138 print " {ICAL_NO_VALUE,\"\"}\n};";
143 foreach $value (keys %h) {
145 my $autogen = $h{$value}->{C}->[0];
146 my $type = $h{$value}->{C}->[1];
148 my $ucf = join("",map {ucfirst(lc($_));} split(/-/,$value));
153 my $pointer_check = "icalerror_check_arg_rz( (v!=0),\"v\");\n" if $type =~ /\*/;
154 my $pointer_check_rv = "icalerror_check_arg_rv( (v!=0),\"v\");\n" if $type =~ /\*/;
158 if ($type =~ /char/){
159 $assign = "icalmemory_strdup(v);\n\n if (impl->data.v_string == 0){\n errno = ENOMEM;\n }\n";
166 if(@{$h{$value}->{'enums'}}){
167 $union_data = 'enum';
169 } elsif (exists $union_map{$uc} ){
170 $union_data=$union_map{$uc};
175 if ($opt_c && $autogen) {
178 icalvalue* icalvalue_new_${lc} ($type v){\
179 struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_${uc}_VALUE);\
181 icalvalue_set_${lc}((icalvalue*)impl,v);\
182 return (icalvalue*)impl;\
184 void icalvalue_set_${lc}(icalvalue* value, $type v) {\
185 struct icalvalue_impl* impl; \
186 icalerror_check_arg_rv( (value!=0),\"value\");\
188 icalerror_check_value_type(value, ICAL_${uc}_VALUE);\
189 impl = (struct icalvalue_impl*)value;\n";
191 if( $union_data eq 'string') {
193 print " if(impl->data.v_${union_data}!=0) {free((void*)impl->data.v_${union_data});}\n";
197 print "\n impl->data.v_$union_data = $assign \n }\n";
199 if ($type =~ /char/){
200 print "$type\ icalvalue_get_${lc}(icalvalue* value)\ {\n\
201 icalerror_check_arg_rz( (value!=0),\"value\");\
202 icalerror_check_value_type(value, ICAL_${uc}_VALUE);\
203 return ((struct icalvalue_impl*)value)->data.v_${union_data};\n}\n";
205 print "$type\ icalvalue_get_${lc}(icalvalue* value)\ {\n\
206 icalerror_check_arg( (value!=0),\"value\");\
207 icalerror_check_value_type(value, ICAL_${uc}_VALUE);\
208 return ((struct icalvalue_impl*)value)->data.v_${union_data};\n}\n";
211 } elsif($opt_h && $autogen) {
213 print "\n /* $value */ \
214 icalvalue* icalvalue_new_${lc}($type v); \
215 $type icalvalue_get_${lc}(icalvalue* value); \
216 void icalvalue_set_${lc}(icalvalue* value, ${type} v);\n\n";
224 print "#endif /*ICALVALUE_H*/\n";