Actually encrypt passwords before storing them
[claws.git] / src / plugins / vcalendar / libical / scripts / mkderivedparameters.pl
1 #!/usr/local/bin/perl
2
3 require "readvaluesfile.pl";
4
5 use Getopt::Std;
6 getopts('chspi:');
7
8 %no_xname = (RELATED=>1,RANGE=>1,RSVP=>1,XLICERRORTYPE=>1,XLICCOMPARETYPE=>1);
9
10 %params = read_parameters_file($ARGV[0]);
11
12
13 # Write the file inline by copying everything before a demarcation
14 # line, and putting the generated data after the demarcation
15
16 if ($opt_i) {
17
18   open(IN,$opt_i) || die "Can't open input file $opt_i";
19
20   while(<IN>){
21
22     if (/Do not edit/){
23       last;
24     }
25
26     print;
27
28   }    
29
30   if($opt_p){
31     print "# Everything below this line is machine generated. Do not edit. \n";
32   } else {
33     print "/* Everything below this line is machine generated. Do not edit. */\n";
34   }
35
36 }
37
38
39 # Write parameter string map
40 if ($opt_c){
41 }
42
43 # Write parameter enumerations and datatypes
44
45 if($opt_h){
46   print "typedef enum icalparameter_kind {\n    ICAL_ANY_PARAMETER = 0,\n";
47   foreach $param (sort keys %params) {
48     
49     next if !$param;
50     
51     next if $param eq 'NO' or $param eq 'ANY';
52
53     my $uc = join("",map {uc($_);}  split(/-/,$param));
54
55     my @enums = @{$params{$param}->{'enums'}};
56         
57     print "    ICAL_${uc}_PARAMETER, \n";
58     
59   }  
60   print "    ICAL_NO_PARAMETER\n} icalparameter_kind;\n\n";
61
62   # Now create enumerations for parameter values
63   $idx = 20000;
64   
65   print "#define ICALPARAMETER_FIRST_ENUM $idx\n\n";
66   
67   foreach $param (sort keys %params) {
68     
69     next if !$param;
70     
71     next if $param eq 'NO' or $prop eq 'ANY';
72
73     my $type = $params{$param}->{"C"};
74     my $ucv = join("",map {uc(lc($_));}  split(/-/,$param));    
75     my @enums = @{$params{$param}->{'enums'}};
76
77     if(@enums){
78
79       print "typedef enum $type {\n";
80       my $first = 1;
81
82       unshift(@enums,"X");
83
84       push(@enums,"NONE");
85
86       foreach $e (@enums) {
87         if (!$first){
88           print ",\n";
89         } else {
90           $first = 0;
91         }
92         
93         my $uce = join("",map {uc(lc($_));}  split(/-/,$e));    
94         
95         print "    ICAL_${ucv}_${uce} = $idx";
96         
97         $idx++;
98       }
99       $c_type =~ s/enum //;
100
101       print "\n} $type;\n\n";
102     }
103   }
104
105   print "#define ICALPARAMETER_LAST_ENUM $idx\n\n";
106
107 }
108
109 if ($opt_c){
110
111   # Create the icalparameter_value to icalvalue_kind conversion table
112   print "static struct  icalparameter_value_kind_map value_kind_map[] = {\n";
113   
114   foreach $enum (@{$params{'VALUE'}->{'enums'}}){
115     next if $enum eq 'NO' or $enum eq 'ERROR';
116     $uc = join("",map {uc(lc($_));}  split(/-/,$enum));    
117     print "    {ICAL_VALUE_${uc},ICAL_${uc}_VALUE},\n";
118   }
119   
120   print "    {ICAL_VALUE_X,ICAL_X_VALUE},\n";
121   print "    {ICAL_VALUE_NONE,ICAL_NO_VALUE}\n};\n\n";
122   
123   #Create the parameter Name map
124   print "static struct icalparameter_kind_map parameter_map[] = { \n";
125
126   foreach $param (sort keys %params) {
127     
128     next if !$param;
129     
130     next if $param eq 'NO' or $prop eq 'ANY';
131
132     my $lc = join("",map {lc($_);}  split(/-/,$param));    
133     my $uc = join("",map {uc(lc($_));}  split(/-/,$param));    
134
135
136     print "    {ICAL_${uc}_PARAMETER,\"$param\"},\n";
137
138   }
139
140   print "    { ICAL_NO_PARAMETER, \"\"}\n};\n\n";
141   
142   # Create the parameter value map
143
144   print "static struct icalparameter_map icalparameter_map[] = {\n";
145   print "{ICAL_ANY_PARAMETER,0,\"\"},\n";
146
147   foreach $param (sort keys %params) {
148     
149     next if !$param;
150     
151     next if $param eq 'NO' or $prop eq 'ANY';
152
153     my $type = $params{$param}->{"C"};
154     my $uc = join("",map {uc(lc($_));}  split(/-/,$param));    
155     my @enums = @{$params{$param}->{'enums'}};
156
157     if(@enums){
158
159       foreach $e (@enums){
160         my $uce = join("",map {uc(lc($_));}  split(/-/,$e));    
161
162         print "    {ICAL_${uc}_PARAMETER,ICAL_${uc}_${uce},\"$e\"},\n";
163       }
164
165     }
166   }
167
168   print "    {ICAL_NO_PARAMETER,0,\"\"}};\n\n";
169
170 }
171
172 foreach $param  (keys %params){
173
174   my $type = $params{$param}->{'C'};
175
176   my $ucf = join("",map {ucfirst(lc($_));}  split(/-/,$param));
177   
178   my $lc = lc($ucf);
179   my $uc = uc($lc);
180  
181   my $charorenum;
182   my $set_code;
183   my $pointer_check;
184   my $pointer_check_v;
185   my $xrange;
186
187   if ($type=~/char/ ) {
188
189      $charorenum = "    icalerror_check_arg_rz( (param!=0), \"param\");\n    return ($type)((struct icalparameter_impl*)param)->string;";
190     
191      $set_code = "((struct icalparameter_impl*)param)->string = icalmemory_strdup(v);";
192
193      $pointer_check = "icalerror_check_arg_rz( (v!=0),\"v\");"; 
194      $pointer_check_v = "icalerror_check_arg_rv( (v!=0),\"v\");"; 
195
196   } else {
197
198     $xrange ="     if ( ((struct icalparameter_impl*)param)->string != 0){\n        return ICAL_${uc}_X;\n        }\n" if !exists $no_xname{$uc};
199     
200     $charorenum= "icalerror_check_arg( (param!=0), \"param\");\n$xrange\nreturn ($type)((struct icalparameter_impl*)param)->data;";
201      
202     $pointer_check = "icalerror_check_arg_rz(v >= ICAL_${uc}_X,\"v\");\n    icalerror_check_arg_rz(v < ICAL_${uc}_NONE,\"v\");";
203
204     $pointer_check_v = "icalerror_check_arg_rv(v >= ICAL_${uc}_X,\"v\");\n    icalerror_check_arg_rv(v < ICAL_${uc}_NONE,\"v\");";
205
206      $set_code = "((struct icalparameter_impl*)param)->data = (int)v;";
207
208    }
209   
210   
211   
212   if ($opt_c) {
213     
214   print <<EOM;
215 /* $param */
216 icalparameter* icalparameter_new_${lc}($type v)
217 {
218    struct icalparameter_impl *impl;
219    icalerror_clear_errno();
220    $pointer_check
221    impl = icalparameter_new_impl(ICAL_${uc}_PARAMETER);
222    if (impl == 0) {
223       return 0;
224    }
225
226    icalparameter_set_${lc}((icalparameter*) impl,v);
227    if (icalerrno != ICAL_NO_ERROR) {
228       icalparameter_free((icalparameter*) impl);
229       return 0;
230    }
231
232    return (icalparameter*) impl;
233 }
234
235 ${type} icalparameter_get_${lc}(icalparameter* param)
236 {
237    icalerror_clear_errno();
238 $charorenum
239 }
240
241 void icalparameter_set_${lc}(icalparameter* param, ${type} v)
242 {
243    $pointer_check_v
244    icalerror_check_arg_rv( (param!=0), "param");
245    icalerror_clear_errno();
246    
247    $set_code
248 }
249
250 EOM
251
252   } elsif( $opt_h) {
253
254   print <<EOM;
255 /* $param */
256 icalparameter* icalparameter_new_${lc}($type v);
257 ${type} icalparameter_get_${lc}(icalparameter* value);
258 void icalparameter_set_${lc}(icalparameter* value, ${type} v);
259
260 EOM
261
262 }
263
264 if ($opt_p) {
265     
266   print <<EOM;
267
268 # $param 
269
270 package Net::ICal::Parameter::${ucf};
271 \@ISA=qw(Net::ICal::Parameter);
272
273 sub new
274 {
275    my \$self = [];
276    my \$package = shift;
277    my \$value = shift;
278
279    bless \$self, \$package;
280
281    my \$p;
282
283    if (\$value) {
284       \$p = Net::ICal::icalparameter_new_from_string(\$Net::ICal::ICAL_${uc}_PARAMETER,\$value);
285    } else {
286       \$p = Net::ICal::icalparameter_new(\$Net::ICal::ICAL_${uc}_PARAMETER);
287    }
288
289    \$self->[0] = \$p;
290
291    return \$self;
292 }
293
294 sub get
295 {
296    my \$self = shift;
297    my \$impl = \$self->_impl();
298
299    return Net::ICal::icalparameter_as_ical_string(\$impl);
300
301 }
302
303 sub set
304 {
305    # This is hard to implement, so I've punted for now. 
306    die "Set is not implemented";
307 }
308
309 EOM
310
311 }
312
313 }
314
315 if ($opt_h){
316
317 print <<EOM;
318 #endif /*ICALPARAMETER_H*/
319
320 EOM
321 }