aboutsummaryrefslogtreecommitdiffstats
path: root/libical/scripts/mkderivedproperties.pl
blob: 8bd808e7f5d6a56fccd669627a152cc9c5a1bade (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
#!/usr/local/bin/perl

require "readvaluesfile.pl";

use Getopt::Std;
getopts('chspmi:');

# ARG 0 is properties.csv
%propmap  = read_properties_file($ARGV[0]);

# ARG 1 is value-types.txt
%valuemap  = read_values_file($ARGV[1]);


# Write the file inline by copying everything before a demarcation
# line, and putting the generated data after the demarcation

if ($opt_i) {

  open(IN,$opt_i) || die "Can't open input file $opt_i";

  while(<IN>){

    if (/Do not edit/){
      last;
    }

    print;

  }    

    print "/* Everything below this line is machine generated. Do not edit. */\n";


}

sub fudge_data {
  my $prop = shift;

  my $value = $propmap{$prop}->{'lic_value'};

  if (!$value){
    die "Can't find value for property \"$prop\"\n";
  }
  my $ucf = join("",map {ucfirst(lc($_));}  split(/-/,$prop));
  my $lc = lc($ucf);
  my $uc = uc($lc);

  my $ucfvalue = join("",map {ucfirst(lc($_));}  split(/-/,$value));
  my $lcvalue = lc($ucfvalue);
  my $ucvalue = uc($lcvalue);

  my $type = $valuemap{$value}->{C}->[1];

  return ($uc,$lc,$lcvalue,$ucvalue,$type);

}  

# Create the property map data
if($opt_c){

  print "static struct icalproperty_map property_map[] = {\n";
  
  foreach $prop (sort keys %propmap) {
    
    next if !$prop;
    
    next if $prop eq 'NO';
    
    my ($uc,$lc,$lcvalue,$ucvalue,$type) = fudge_data($prop);
    
    print "{ICAL_${uc}_PROPERTY,\"$prop\",ICAL_${ucvalue}_VALUE},\n";
    
  }
  
  $prop = "NO";
  
  my ($uc,$lc,$lcvalue,$ucvalue,$type) = fudge_data($prop);
  
  print "{ICAL_${uc}_PROPERTY,\"\",ICAL_NO_VALUE}};\n\n";


  print "static struct icalproperty_enum_map enum_map[] = {\n";

  $idx = 10000;

  foreach $value (sort keys %valuemap) {
    
    next if !$value;    
    next if $value eq 'NO' or $prop eq 'ANY';

    my $ucv = join("",map {uc(lc($_));}  split(/-/,$value));    
    my @enums = @{$valuemap{$value}->{'enums'}};

    if(@enums){

      my ($c_autogen,$c_type) = @{$valuemap{$value}->{'C'}};
      
      unshift(@enums,"X");
      push(@enums,"NONE");

      foreach $e (@enums) {

    my $uce = join("",map {uc(lc($_));}  split(/-/,$e));
    
    if($e ne "X" and $e ne "NONE"){
      $str = $e;
    } else {
      $str = "";
    }

    print "    {ICAL_${ucv}_PROPERTY,ICAL_${ucv}_${uce},\"$str\" }, /*$idx*/\n";

    $idx++;
      }
      
    }
  }
  print "    {ICAL_NO_PROPERTY,0,\"\"}\n};\n\n";


}


if($opt_h){

  # Create the property enumerations list
  print "typedef enum icalproperty_kind {\n    ICAL_ANY_PROPERTY = 0,\n";
  foreach $prop (sort keys %propmap) {
    
    next if !$prop;
    
    next if $prop eq 'NO' or $prop eq 'ANY';
    
    my ($uc,$lc,$lcvalue,$ucvalue,$type) = fudge_data($prop);
    
    print "    ICAL_${uc}_PROPERTY, \n";
    
  }  
  print "    ICAL_NO_PROPERTY\n} icalproperty_kind;\n\n";


}


foreach $prop (sort keys %propmap) {

  next if !$prop;

  next if $prop eq 'NO' or $prop eq 'ANY';

  my ($uc,$lc,$lcvalue,$ucvalue,$type) = fudge_data($prop);

  
  my $pointer_check;
  if ($type =~ /\*/){
    $pointer_check = "icalerror_check_arg_rz( (v!=0),\"v\");\n" if $type =~ /\*/;
  } elsif ( $type eq "void" ){
    $pointer_check = "icalerror_check_arg_rv( (v!=0),\"v\");\n" if $type =~ /\*/;

  }    

  my $set_pointer_check = "icalerror_check_arg_rv( (v!=0),\"v\");\n" if $type =~ /\*/;

  if($opt_c) { # Generate C source
 print<<EOM;
/* $prop */
icalproperty* icalproperty_new_${lc}($type v) {
   struct icalproperty_impl *impl = icalproperty_new_impl(ICAL_${uc}_PROPERTY);   $pointer_check
   icalproperty_set_${lc}((icalproperty*)impl,v);
   return (icalproperty*)impl;
}
icalproperty* icalproperty_vanew_${lc}($type v, ...){
   va_list args;
   struct icalproperty_impl *impl = icalproperty_new_impl(ICAL_${uc}_PROPERTY);   $pointer_check
   icalproperty_set_${lc}((icalproperty*)impl,v);
   va_start(args,v);
   icalproperty_add_parameters(impl, args);
   va_end(args);
   return (icalproperty*)impl;
}
EOM

    # Allow DTSTART, DTEND, DUE, EXDATE and RECURRENCE-ID to take DATE values.
    if ($lc eq "dtstart" || $lc eq "dtend" || $lc eq "due" || $lc eq "exdate"
    || $lc eq "recurrenceid") {
    print<<EOM;
void icalproperty_set_${lc}(icalproperty* prop, $type v){
    icalvalue *value;
    $set_pointer_check
    icalerror_check_arg_rv( (prop!=0),"prop");
    if (v.is_date)
        value = icalvalue_new_date(v);
    else
        value = icalvalue_new_datetime(v);
    icalproperty_set_value(prop,value);
}
EOM
    } else {
    print<<EOM;
void icalproperty_set_${lc}(icalproperty* prop, $type v){
    icalvalue *value;
    $set_pointer_check
    icalerror_check_arg_rv( (prop!=0),"prop");
    value = icalvalue_new_${lcvalue}(v);
    icalproperty_set_value(prop,value);
}
EOM
    }

 print<<EOM;
$type icalproperty_get_${lc}(icalproperty* prop){
    icalvalue *value;
    icalerror_check_arg( (prop!=0),"prop");
    value = icalproperty_get_value(prop);
    return icalvalue_get_${lcvalue}(value);
}
EOM


  } elsif ($opt_h) { # Generate C Header file
 print "\
/* $prop */\
icalproperty* icalproperty_new_${lc}($type v);\
icalproperty* icalproperty_vanew_${lc}($type v, ...);\
void icalproperty_set_${lc}(icalproperty* prop, $type v);\
$type icalproperty_get_${lc}(icalproperty* prop);";
  
} 


} # This brace terminates the main loop



if ($opt_h){

print "\n\n#endif /*ICALPROPERTY_H*/\n"
}