aboutsummaryrefslogtreecommitdiffstats
path: root/libical/scripts/mkderivedparameters.pl
diff options
context:
space:
mode:
Diffstat (limited to 'libical/scripts/mkderivedparameters.pl')
-rwxr-xr-xlibical/scripts/mkderivedparameters.pl75
1 files changed, 42 insertions, 33 deletions
diff --git a/libical/scripts/mkderivedparameters.pl b/libical/scripts/mkderivedparameters.pl
index 89f25306a5..5439509aa8 100755
--- a/libical/scripts/mkderivedparameters.pl
+++ b/libical/scripts/mkderivedparameters.pl
@@ -1,4 +1,4 @@
-#!/usr/local/bin/perl
+#!/usr/bin/env perl
require "readvaluesfile.pl";
@@ -18,27 +18,24 @@ if ($opt_i) {
open(IN,$opt_i) || die "Can't open input file $opt_i";
while(<IN>){
-
- if (/Do not edit/){
- last;
- }
-
- print;
+ if (/<insert_code_here>/){
+ insert_code();
+ } else {
+ print;
+ }
}
if($opt_p){
- print "# Everything below this line is machine generated. Do not edit. \n";
+ print "# Everything below this line is machine generated. Do not edit. \n";
} else {
print "/* Everything below this line is machine generated. Do not edit. */\n";
}
}
-
-# Write parameter string map
-if ($opt_c){
-}
+sub insert_code
+{
# Write parameter enumerations and datatypes
@@ -108,21 +105,28 @@ if($opt_h){
if ($opt_c){
- # Create the icalparameter_value to icalvalue_kind conversion table
- print "struct icalparameter_value_kind_map value_kind_map[] = {\n";
+ # Create the icalparameter_value to icalvalue_kind conversion table
+ my $count = 0;
+ my $out;
+
foreach $enum (@{$params{'VALUE'}->{'enums'}}){
next if $enum eq 'NO' or $enum eq 'ERROR';
$uc = join("",map {uc(lc($_));} split(/-/,$enum));
- print " {ICAL_VALUE_${uc},ICAL_${uc}_VALUE},\n";
+ $out.=" {ICAL_VALUE_${uc},ICAL_${uc}_VALUE},\n";
+ $count++;
}
-
+
+ $count+=2;
+ print "static struct icalparameter_value_kind_map value_kind_map[$count] = {\n";
+ print $out;
print " {ICAL_VALUE_X,ICAL_X_VALUE},\n";
print " {ICAL_VALUE_NONE,ICAL_NO_VALUE}\n};\n\n";
#Create the parameter Name map
- print "static struct icalparameter_kind_map parameter_map[] = { \n";
+ $out="";
+ $count=0;
foreach $param (sort keys %params) {
next if !$param;
@@ -132,18 +136,18 @@ if ($opt_c){
my $lc = join("",map {lc($_);} split(/-/,$param));
my $uc = join("",map {uc(lc($_));} split(/-/,$param));
-
- print " {ICAL_${uc}_PARAMETER,\"$param\"},\n";
+ $count++;
+ $out.=" {ICAL_${uc}_PARAMETER,\"$param\"},\n";
}
-
+ $count+=1;
+ print "static struct icalparameter_kind_map parameter_map[$count] = { \n";
+ print $out;
print " { ICAL_NO_PARAMETER, \"\"}\n};\n\n";
# Create the parameter value map
-
- print "static struct icalparameter_map icalparameter_map[] = {\n";
- print "{ICAL_ANY_PARAMETER,0,\"\"},\n";
-
+ $out ="";
+ $count=0;
foreach $param (sort keys %params) {
next if !$param;
@@ -159,12 +163,17 @@ if ($opt_c){
foreach $e (@enums){
my $uce = join("",map {uc(lc($_));} split(/-/,$e));
- print " {ICAL_${uc}_PARAMETER,ICAL_${uc}_${uce},\"$e\"},\n";
+ $count++;
+ $out.=" {ICAL_${uc}_PARAMETER,ICAL_${uc}_${uce},\"$e\"},\n";
}
}
}
+ $count+=3;
+ print "static struct icalparameter_map icalparameter_map[] = {\n";
+ print "{ICAL_ANY_PARAMETER,0,\"\"},\n";
+ print $out;
print " {ICAL_NO_PARAMETER,0,\"\"}};\n\n";
}
@@ -186,20 +195,18 @@ foreach $param (keys %params){
if ($type=~/char/ ) {
- $charorenum = " icalerror_check_arg_rz( (param!=0), \"param\");\n return ($type)((struct icalparameter_impl*)param)->string;";
+ $charorenum = " icalerror_check_arg_rz( (param!=0), \"param\");\n return param->string;";
- $set_code = "if (((struct icalparameter_impl*)param)->string != 0)\n" .
- " free((void *) ((struct icalparameter_impl*)param)->string);\n" .
- " ((struct icalparameter_impl*)param)->string = icalmemory_strdup(v);";
+ $set_code = "((struct icalparameter_impl*)param)->string = icalmemory_strdup(v);";
$pointer_check = "icalerror_check_arg_rz( (v!=0),\"v\");";
$pointer_check_v = "icalerror_check_arg_rv( (v!=0),\"v\");";
} else {
- $xrange =" if ( ((struct icalparameter_impl*)param)->string != 0){\n return ICAL_${uc}_X;\n }\n" if !exists $no_xname{$uc};
+ $xrange =" if (param->string != 0){\n return ICAL_${uc}_X;\n }\n" if !exists $no_xname{$uc};
- $charorenum= "icalerror_check_arg( (param!=0), \"param\");\n$xrange\nreturn ($type)((struct icalparameter_impl*)param)->data;";
+ $charorenum= "icalerror_check_arg( (param!=0), \"param\");\n$xrange\nreturn ($type)(param->data);";
$pointer_check = "icalerror_check_arg_rz(v >= ICAL_${uc}_X,\"v\");\n icalerror_check_arg_rz(v < ICAL_${uc}_NONE,\"v\");";
@@ -234,7 +241,7 @@ icalparameter* icalparameter_new_${lc}($type v)
return (icalparameter*) impl;
}
-${type} icalparameter_get_${lc}(icalparameter* param)
+${type} icalparameter_get_${lc}(const icalparameter* param)
{
icalerror_clear_errno();
$charorenum
@@ -256,7 +263,7 @@ EOM
print <<EOM;
/* $param */
icalparameter* icalparameter_new_${lc}($type v);
-${type} icalparameter_get_${lc}(icalparameter* value);
+${type} icalparameter_get_${lc}(const icalparameter* value);
void icalparameter_set_${lc}(icalparameter* value, ${type} v);
EOM
@@ -321,3 +328,5 @@ print <<EOM;
EOM
}
+
+}