From e6f1da7f4681def1f8b0472a504dda549f9f4b89 Mon Sep 17 00:00:00 2001 From: JP Rosevear Date: Tue, 17 Apr 2001 17:54:48 +0000 Subject: Finish merge of new libical 0.23a version 2001-04-17 JP Rosevear * Finish merge of new libical 0.23a version svn path=/trunk/; revision=9420 --- libical/scripts/Makefile.am | 3 +- libical/scripts/mkderivedparameters.pl | 234 +++++++++++-------- libical/scripts/mkderivedproperties.pl | 308 ++++++++++--------------- libical/scripts/mkderivedvalues.pl | 395 +++++++++++++-------------------- 4 files changed, 409 insertions(+), 531 deletions(-) (limited to 'libical/scripts') diff --git a/libical/scripts/Makefile.am b/libical/scripts/Makefile.am index fd1b053cb6..c61eaefdce 100644 --- a/libical/scripts/Makefile.am +++ b/libical/scripts/Makefile.am @@ -5,4 +5,5 @@ mkderivedproperties.pl \ mkderivedvalues.pl \ mkparameterrestrictions.pl \ mkrestrictionrecords.pl \ -mkrestrictiontable.pl +mkrestrictiontable.pl \ +readvaluesfile.pl diff --git a/libical/scripts/mkderivedparameters.pl b/libical/scripts/mkderivedparameters.pl index 5715220ea3..5772065ec4 100755 --- a/libical/scripts/mkderivedparameters.pl +++ b/libical/scripts/mkderivedparameters.pl @@ -1,12 +1,14 @@ #!/usr/local/bin/perl +require "readvaluesfile.pl"; + use Getopt::Std; getopts('chspi:'); %no_xname = (RELATED=>1,RANGE=>1,RSVP=>1,XLICERRORTYPE=>1,XLICCOMPARETYPE=>1); -# Usually, open param-c-types.txt -open(F,"$ARGV[0]") || die "Can't open C parameter types file $ARGV[0]:$!"; +%params = read_parameters_file($ARGV[0]); + # Write the file inline by copying everything before a demarcation # line, and putting the generated data after the demarcation @@ -34,122 +36,174 @@ if ($opt_i) { } +# Write parameter string map +if ($opt_c){ +} -if (($opt_c or $opt_h) and !$opt_i) { +# Write parameter enumerations and datatypes -print <{'enums'}}; + + print " ICAL_${uc}_PARAMETER, \n"; + + } + print " ICAL_NO_PARAMETER\n} icalparameter_kind;\n\n"; -/* - * THIS FILE IS MACHINE GENERATED DO NOT EDIT - */ + # Now create enumerations for parameter values + $idx = 20000; + + print "#define ICALPARAMETER_FIRST_ENUM $idx\n\n"; + + foreach $param (sort keys %params) { + + next if !$param; + + next if $param eq 'NO' or $prop eq 'ANY'; + my $type = $params{$param}->{"C"}; + my $ucv = join("",map {uc(lc($_));} split(/-/,$param)); + my @enums = @{$params{$param}->{'enums'}}; -EOM + if(@enums){ -} + print "typedef enum $type {\n"; + my $first = 1; -if ($opt_p and !$opt_i){ + unshift(@enums,"X"); -print <){ + # Create the icalparameter_value to icalvalue_kind conversion table + print "struct icalparameter_value_kind_map value_kind_map[] = {\n"; - chop; - my ($param,$type) = split(/\s{2,}/,$_); + 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"; + } + 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"; + + foreach $param (sort keys %params) { + + next if !$param; + + next if $param eq 'NO' or $prop eq 'ANY'; + + my $lc = join("",map {lc($_);} split(/-/,$param)); + my $uc = join("",map {uc(lc($_));} split(/-/,$param)); + + + print " {ICAL_${uc}_PARAMETER,\"$param\"},\n"; + + } + + 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"; + + foreach $param (sort keys %params) { + + next if !$param; + + next if $param eq 'NO' or $prop eq 'ANY'; + + my $type = $params{$param}->{"C"}; + my $uc = join("",map {uc(lc($_));} split(/-/,$param)); + my @enums = @{$params{$param}->{'enums'}}; + + if(@enums){ + + foreach $e (@enums){ + my $uce = join("",map {uc(lc($_));} split(/-/,$e)); + + print " {ICAL_${uc}_PARAMETER,ICAL_${uc}_${uce},\"$e\"},\n"; + } + + } + } + + print " {ICAL_NO_PARAMETER,0,\"\"}};\n\n"; + +} + +foreach $param (keys %params){ + + my $type = $params{$param}->{'C'}; + my $ucf = join("",map {ucfirst(lc($_));} split(/-/,$param)); my $lc = lc($ucf); my $uc = uc($lc); - - my $lctype = lc($type); - - + my $charorenum; my $set_code; my $pointer_check; - my $new_pointer_check; - my $new_pointer_check_v; + my $pointer_check_v; my $xrange; - if ($type=~/char/){ - $new_pointer_check = "icalerror_check_arg_rz( (v!=0),\"v\");"; - $new_pointer_check_v = "icalerror_check_arg_rv( (v!=0),\"v\");"; - } - - if ($type=~/char/ ) { - $charorenum = " icalerror_check_arg_rz( (param!=0), \"param\");\n return ((struct icalparameter_impl*)param)->string;"; + $charorenum = " icalerror_check_arg_rz( (param!=0), \"param\");\n return ($type)((struct icalparameter_impl*)param)->string;"; - $pointer_check = "icalerror_check_arg_rz( (v!=0),\"v\");"; + $set_code = "((struct icalparameter_impl*)param)->string = icalmemory_strdup(v);"; - $set_code = "((struct icalparameter_impl*)param)->string = 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}_XNAME;\n }\n" if !exists $no_xname{$uc}; - - $charorenum=<data.v_${lc}; -EOM + $xrange =" if ( ((struct icalparameter_impl*)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;"; - $pointer_check = "icalerror_check_arg( (v!=0),\"v\");"; + $pointer_check = "icalerror_check_arg_rz(v >= ICAL_${uc}_X,\"v\");\n icalerror_check_arg_rz(v < ICAL_${uc}_NONE,\"v\");"; - $set_code = "((struct icalparameter_impl*)param)->data.v_${lc} = v;"; + $pointer_check_v = "icalerror_check_arg_rv(v >= ICAL_${uc}_X,\"v\");\n icalerror_check_arg_rv(v < ICAL_${uc}_NONE,\"v\");"; - $print_code = "switch (impl->data.v_${lc}) {\ncase ICAL_${uc}_: {\n}\ncase ICAL_${uc}_XNAME: /* Fall Through */\n}\n"; + $set_code = "((struct icalparameter_impl*)param)->data = (int)v;"; } @@ -163,7 +217,7 @@ icalparameter* icalparameter_new_${lc}($type v) { struct icalparameter_impl *impl; icalerror_clear_errno(); - $new_pointer_check + $pointer_check impl = icalparameter_new_impl(ICAL_${uc}_PARAMETER); if (impl == 0) { return 0; @@ -186,7 +240,7 @@ $charorenum void icalparameter_set_${lc}(icalparameter* param, ${type} v) { - $new_pointer_check_v + $pointer_check_v icalerror_check_arg_rv( (param!=0), "param"); icalerror_clear_errno(); @@ -205,20 +259,9 @@ void icalparameter_set_${lc}(icalparameter* value, ${type} v); EOM -} elsif ($opt_s) { - -next if $type =~ /char/; - -print<){ - - chop; - my @v = split(/\s+/,$_); - - my $prop = shift @v; - my $value = shift @v; - my $comment = join(" ",@v); - - $propmap{$prop} = $value; -} +require "readvaluesfile.pl"; -close PV; - -# ARG 1 is value-c-types.txt -open(F,"$ARGV[1]") || die "Can't open C parameter types file $ARGV[1 ]:$!"; - -while (){ - - chop; - my @v = split(/\t+/,$_); - - my $value = shift @v; - my $mode = shift @v; - my $type = shift @v; - my $comment = join(" ",@v); +use Getopt::Std; +getopts('chspmi:'); - $valuemap{$value} = $type; +# ARG 0 is properties.csv +%propmap = read_properties_file($ARGV[0]); -} +# ARG 1 is value-types.txt +%valuemap = read_values_file($ARGV[1]); -close F; # Write the file inline by copying everything before a demarcation # line, and putting the generated data after the demarcation @@ -57,78 +29,128 @@ if ($opt_i) { } - if($opt_p){ - 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"; - } + } - -if ( ($opt_h or $opt_s) and !$opt_i ){ +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); -print <{C}->[1]; + + return ($uc,$lc,$lcvalue,$ucvalue,$type); + +} + +# Create the property map data +if($opt_c){ + + print "static struct icalproperty_map property_map[] = {\n"; - \044Id:\044 + 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"; - (C) COPYRIGHT 1999 Eric Busboom - http://www.softwarestudio.org + } + + $prop = "NO"; + + my ($uc,$lc,$lcvalue,$ucvalue,$type) = fudge_data($prop); + + print "{ICAL_${uc}_PROPERTY,\"\",ICAL_NO_VALUE}};\n\n"; - The contents of this file are subject to the Mozilla Public License - Version 1.0 (the "License"); you may not use this file except in - compliance with the License. You may obtain a copy of the License at - http://www.mozilla.org/MPL/ - - Software distributed under the License is distributed on an "AS IS" - basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - the License for the specific language governing rights and - limitations under the License. - - ======================================================================*/ + print "static struct icalproperty_enum_map enum_map[] = {\n"; -/* - * THIS FILE IS MACHINE GENERATED. DO NOT EDIT - */ + $idx = 10000; + foreach $value (sort keys %valuemap) { + + next if !$value; + next if $value eq 'NO' or $prop eq 'ANY'; -EOM + 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"); -if ($opt_p and !$opt_i){ + foreach $e (@enums) { -print <_add_elements(\\\@_); - - return bless \$self, \$package; -} - -sub set_value -{ - my \$self = shift; - my \$v = shift; - - my \$impl = \$self->_impl(); - +} - if ( ref \$v && Net::ICal::icalvalue_isa_value(\$v->_impl())){ - Net::ICal::icalproperty_set_value(\$impl,\$v->_impl); - } else { - my \$value = Net::ICal::icalvalue_new_from_string(\$Net::ICal::ICAL_${ucvalue}_VALUE,\$v); - die if !\$impl; - Net::ICal::icalproperty_set_value(\$impl,\$value) unless !\$value; - } - -} - -sub get_value -{ - my \$self = shift; - my \$impl = \$self->_impl(); - - if (defined \$impl){ - my \$value = Net::ICal::icalproperty_get_value(\$impl); - return "" if !\$value; - return Net::ICal::icalvalue_as_ical_string(\$value); - } else { - return ""; - } -} - -EOM - -} elsif ($opt_m) { # Generate a map - -print "\'${uc}\' => \'Net::ICal::Property::${ucf},\'\n"; - -} } # This brace terminates the main loop -# Add things to the end of the output. - -if ($opt_p) -{ - print "1;\n"; -} - if ($opt_h){ -print < generate c code file -# h-> generate header file -# s -> generate switch statement +use Getopt::Std; +getopts('chi:'); -# Open with value-c-types.txt + #Options + # c -> generate c code file + # h-> generate header file + # Open with value-types.txt -open(F,"$ARGV[0]") || die "Can't open values data file $ARGV[0]:$!"; +my %h = read_values_file($ARGV[0]); -# Write the file inline by copying everything before a demarcation -# line, and putting the generated data after the demarcation + # 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(){ - - if (/Do not edit/){ - last; - } - print; - } - - if($opt_p){ - 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"; - } - } -if (($opt_c || $opt_h) and !$opt_i) { -print < 'int', @@ -118,199 +44,180 @@ EOM URI=>'string', UTCOFFSET=>'int', QUERY=>'string', - BINARY=>'string' + BINARY=>'string', + X=>'string' ); -while() -{ - - chop; - my @v = split(/\t+/,$_); - - my $value = shift @v; - my $mode = shift @v; - my $type = shift @v; - my $comment = join(" ",@v); - - my $ucf = join("",map {ucfirst(lc($_));} split(/-/,$value)); - - my $lc = lc($ucf); - my $uc = uc($lc); - my $pointer_check = "icalerror_check_arg_rz( (v!=0),\"v\");\n" if $type =~ /\*/; - my $pointer_check_rv = "icalerror_check_arg_rv( (v!=0),\"v\");\n" if $type =~ /\*/; +if($opt_h){ - my $assign; + # First print out the value enumerations + $idx = 5000; + print "typedef enum icalvalue_kind {\n"; + print " ICAL_ANY_VALUE=$idx,\n"; - if ($type =~ /char/){ - $assign = "strdup(v);\n\n if (impl->data.v_string == 0){\n errno = ENOMEM;\n }\n"; - } else { - $assign = "v;"; + foreach $value (keys %h) { + + $idx++; + my $ucv = join("",map {uc(lc($_));} split(/-/,$value)); + + next if $value eq "NO"; + + print " ICAL_${ucv}_VALUE=$idx,\n"; } - - my $union_data; - if (exists $union_map{$uc} ){ - $union_data=$union_map{$uc}; - } else { - $union_data = $lc; - } - - if ($opt_c && $mode eq "autogen") { -print <data.v_${union_data}!=0) {free((void*)impl->data.v_${union_data});}\n"; -} - -print <data.v_${union_data} = $assign -} - -$type -icalvalue_get_${lc}(icalvalue* value) -{ - icalerror_check_arg( (value!=0),"value"); - icalerror_check_value_type(value, ICAL_${uc}_VALUE); + $idx++; + print " ICAL_NO_VALUE=$idx\n} icalvalue_kind ;\n\n"; - return ((struct icalvalue_impl*)value)->data.v_${union_data}; -} + # Now create enumerations for property values + $idx = 10000; + + print "#define ICALPROPERTY_FIRST_ENUM $idx\n\n"; + + foreach $value (sort keys %h) { + + next if !$value; + + next if $value eq 'NO' or $prop eq 'ANY'; -EOM + my $ucv = join("",map {uc(lc($_));} split(/-/,$value)); + my @enums = @{$h{$value}->{'enums'}}; -} elsif($opt_h && $mode eq "autogen") { + if(@enums){ - print <{'C'}}; + print "typedef $c_type {\n"; + my $first = 1; -EOM + unshift(@enums,"X"); -} elsif ($opt_s) { + push(@enums,"NONE"); -if ( $ud{$union_data}++ == 0) { + foreach $e (@enums) { + if (!$first){ + print ",\n"; + } else { + $first = 0; + } + + my $uce = join("",map {uc(lc($_));} split(/-/,$e)); + + print " ICAL_${ucv}_${uce} = $idx"; + + $idx++; + } -print<data.v_${union_data} + print "\n} $c_type;\n\n"; + } + } - str = icalmemory_strdup(temp); + print "#define ICALPROPERTY_LAST_ENUM $idx\n\n"; - return str; } -EOM - -} -} elsif ($opt_p) { # Generate perl code -print <[0] = \$p; + + print " {ICAL_NO_VALUE,\"\"}\n};"; - return \$self; } -sub set -{ - my \$self = shift; - my \$v = shift; - my \$impl = \$self->_impl(); - - if (\$v) { - my \$new_value = Net::ICal::icalvalue_new_from_string(\$Net::ICal::ICAL_${uc}_VALUE,\$v); - if (\$new_value){ - Net::ICal::icalvalue_free(\$self->[0]); - \$self->[0] = \$new_value; - } - - } - -} +foreach $value (keys %h) { -sub get -{ - my \$self = shift; - my \$impl = \$self->[0]; + my $autogen = $h{$value}->{C}->[0]; + my $type = $h{$value}->{C}->[1]; - if (defined \$impl){ - - return Net::ICal::icalvalue_as_ical_string(\$impl); + my $ucf = join("",map {ucfirst(lc($_));} split(/-/,$value)); + + my $lc = lc($ucf); + my $uc = uc($lc); + + my $pointer_check = "icalerror_check_arg_rz( (v!=0),\"v\");\n" if $type =~ /\*/; + my $pointer_check_rv = "icalerror_check_arg_rv( (v!=0),\"v\");\n" if $type =~ /\*/; + + my $assign; + + if ($type =~ /char/){ + $assign = "icalmemory_strdup(v);\n\n if (impl->data.v_string == 0){\n errno = ENOMEM;\n }\n"; + } else { + $assign = "v;"; + } + + my $union_data; + + if(@{$h{$value}->{'enums'}}){ + $union_data = 'enum'; - } -} + } elsif (exists $union_map{$uc} ){ + $union_data=$union_map{$uc}; + } else { + $union_data = $lc; + } + + if ($opt_c && $autogen) { + + print "\n\n\ +icalvalue* icalvalue_new_${lc} ($type v){\ + struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_${uc}_VALUE);\ + $pointer_check\ + icalvalue_set_${lc}((icalvalue*)impl,v);\ + return (icalvalue*)impl;\ +}\ +void icalvalue_set_${lc}(icalvalue* value, $type v) {\ + struct icalvalue_impl* impl; \ + icalerror_check_arg_rv( (value!=0),\"value\");\ + $pointer_check_rv\ + icalerror_check_value_type(value, ICAL_${uc}_VALUE);\ + impl = (struct icalvalue_impl*)value;\n"; + + if( $union_data eq 'string') { + + print " if(impl->data.v_${union_data}!=0) {free((void*)impl->data.v_${union_data});}\n"; + } + -EOM -} + print "\n impl->data.v_$union_data = $assign \n }\n"; + print "$type\ icalvalue_get_${lc}(icalvalue* value)\ {\n\ + icalerror_check_arg( (value!=0),\"value\");\ + icalerror_check_value_type(value, ICAL_${uc}_VALUE);\ + return ((struct icalvalue_impl*)value)->data.v_${union_data};\n}\n"; + + } elsif($opt_h && $autogen) { + + print "\n /* $value */ \ +icalvalue* icalvalue_new_${lc}($type v); \ +$type icalvalue_get_${lc}(icalvalue* value); \ +void icalvalue_set_${lc}(icalvalue* value, ${type} v);\n\n"; -} + } -if ($opt_p) -{ - print "1;\n"; } - - + + if ($opt_h){ - -print <