diff options
author | JP Rosevear <jpr@ximian.com> | 2001-04-18 01:54:48 +0800 |
---|---|---|
committer | JP Rosevear <jpr@src.gnome.org> | 2001-04-18 01:54:48 +0800 |
commit | e6f1da7f4681def1f8b0472a504dda549f9f4b89 (patch) | |
tree | 20975542002d583663c5c728e9f3cde0bd61573f /libical/scripts | |
parent | 3a49d3e43d8e752162e5c4a098e1c0991a7611db (diff) | |
download | gsoc2013-evolution-e6f1da7f4681def1f8b0472a504dda549f9f4b89.tar gsoc2013-evolution-e6f1da7f4681def1f8b0472a504dda549f9f4b89.tar.gz gsoc2013-evolution-e6f1da7f4681def1f8b0472a504dda549f9f4b89.tar.bz2 gsoc2013-evolution-e6f1da7f4681def1f8b0472a504dda549f9f4b89.tar.lz gsoc2013-evolution-e6f1da7f4681def1f8b0472a504dda549f9f4b89.tar.xz gsoc2013-evolution-e6f1da7f4681def1f8b0472a504dda549f9f4b89.tar.zst gsoc2013-evolution-e6f1da7f4681def1f8b0472a504dda549f9f4b89.zip |
Finish merge of new libical 0.23a version
2001-04-17 JP Rosevear <jpr@ximian.com>
* Finish merge of new libical 0.23a version
svn path=/trunk/; revision=9420
Diffstat (limited to 'libical/scripts')
-rw-r--r-- | libical/scripts/Makefile.am | 3 | ||||
-rwxr-xr-x | libical/scripts/mkderivedparameters.pl | 234 | ||||
-rwxr-xr-x | libical/scripts/mkderivedproperties.pl | 308 | ||||
-rwxr-xr-x | libical/scripts/mkderivedvalues.pl | 395 |
4 files changed, 409 insertions, 531 deletions
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 <<EOM; -/* -*- Mode: C -*- - ====================================================================== - FILE: icalderivedparameters.{c,h} - CREATOR: eric 09 May 1999 - - \044Id: mkderivedparameters.pl,v 1.1 1999/05/14 07:04:31 eric Exp eric \044 - \044Locker: eric \044 +if($opt_h){ + print "typedef enum icalparameter_kind {\n ICAL_ANY_PARAMETER = 0,\n"; + foreach $param (sort keys %params) { - (C) COPYRIGHT 1999 Eric Busboom - http://www.softwarestudio.org + next if !$param; + + next if $param eq 'NO' or $param eq 'ANY'; - 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. - + my $uc = join("",map {uc($_);} split(/-/,$param)); - ======================================================================*/ + my @enums = @{$params{$param}->{'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 <<EOM; -# -*- Mode: Perl -*- -# ====================================================================== -# \044Id:\044 -# -# (C) COPYRIGHT 1999 Eric Busboom -# http://www.softwarestudio.org -# -# 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. -# -# The original author is Eric Busboom -# The original code is derivedparams.h -# -# ======================================================================*/ + push(@enums,"NONE"); -EOM + foreach $e (@enums) { + if (!$first){ + print ",\n"; + } else { + $first = 0; + } + + my $uce = join("",map {uc(lc($_));} split(/-/,$e)); + + print " ICAL_${ucv}_${uce} = $idx"; + + $idx++; + } + $c_type =~ s/enum //; + + print "\n} $type;\n\n"; + } + } + + print "#define ICALPARAMETER_LAST_ENUM $idx\n\n"; } +if ($opt_c){ -while(<F>){ + # 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=<<EOM; - icalerror_check_arg( (param!=0), \"param\"); -$xrange - return ((struct icalparameter_impl*)param)->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<<EOM; -case ICAL_${uc}_PARAMETER: -{ - $print_code -} -EOM - } - if ($opt_p) { +if ($opt_p) { print <<EOM; @@ -273,5 +316,6 @@ if ($opt_h){ print <<EOM; #endif /*ICALPARAMETER_H*/ + EOM } diff --git a/libical/scripts/mkderivedproperties.pl b/libical/scripts/mkderivedproperties.pl index 9778c30a77..4e011e112e 100755 --- a/libical/scripts/mkderivedproperties.pl +++ b/libical/scripts/mkderivedproperties.pl @@ -1,44 +1,16 @@ #!/usr/local/bin/perl -use Getopt::Std; -getopts('chsypmi:'); - -# ARG 0 is prop-to-value -open(PV,"$ARGV[0]") || die "Can't open prop to value file $ARGV[0]:$!"; - - -while (<PV>){ - - 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 (<F>){ - - 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 <<EOM; -/* -*- Mode: C -*- - ====================================================================== - FILE: icalderivedproperties.{c,h} - CREATOR: eric 09 May 1999 + 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"; - \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 <<EOM; + 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"; -EOM } -foreach $prop (keys %propmap) { - next if !$prop; +if($opt_h){ - my $value = $propmap{$prop}; + # 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"; - 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}; +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 =~ /\*/){ @@ -142,150 +164,54 @@ foreach $prop (keys %propmap) { 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* 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, ...) -{ +icalproperty* icalproperty_vanew_${lc}($type v, ...){ va_list args; - struct icalproperty_impl *impl = icalproperty_new_impl(ICAL_${uc}_PROPERTY); - $pointer_check - + 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; } - -void icalproperty_set_${lc}(icalproperty* prop, $type v) -{ +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); - } - -$type icalproperty_get_${lc}(icalproperty* prop) -{ +$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<<EOM; - -/* $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); -EOM + 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);"; -} elsif ($opt_s) { # Generate case in a switch statement - -print <<EOM; -case ICAL_${uc}_PROPERTY: -EOM - - -} elsif ($opt_p) { # Generate perl code - -print <<EOM; - -package Net::ICal::Property::${ucf}; -use Net::ICal::Property; -\@ISA=qw(Net::ICal::Property); -sub new -{ - my \$package = shift; - - my \$p = Net::ICal::icalproperty_new(\$Net::ICal::ICAL_${uc}_PROPERTY); - my \$self = Net::ICal::Property::new_from_ref(\$p); - - \$self->_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 <<EOM; -#endif /*ICALPROPERTY_H*/ -EOM +print "\n\n#endif /*ICALPROPERTY_H*/\n" } diff --git a/libical/scripts/mkderivedvalues.pl b/libical/scripts/mkderivedvalues.pl index 10dac3a75f..e7ede34ae7 100755 --- a/libical/scripts/mkderivedvalues.pl +++ b/libical/scripts/mkderivedvalues.pl @@ -1,109 +1,35 @@ #!/usr/bin/perl +use lib '.'; -use Getopt::Std; -getopts('chspi:'); +require 'readvaluesfile.pl'; -#Options -# c -> 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(<IN>){ - - 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 <<EOM; -/* -*- Mode: C -*- - ====================================================================== - FILE: icalderivedvalues.{c,h} - CREATOR: eric 09 May 1999 - - \044Id:\044 - - (C) COPYRIGHT 1999 Eric Busboom - http://www.softwarestudio.org - - 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. - - ======================================================================*/ - -/* - * THIS FILE IS MACHINE GENERATED DO NOT EDIT - */ - - - -EOM -} - -if ($opt_p and !$opt_i){ - -print <<EOM; -# -*- Mode: Perl -*- -# ====================================================================== -# \044Id:\044 -# -# (C) COPYRIGHT 1999 Eric Busboom -# http://www.softwarestudio.org -# -# 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. -# -# The original author is Eric Busboom -# The original code is derivedvalues.h -# -# ======================================================================*/ - -EOM - -} - -# Map type names to the value in the icalvalue_impl data union */ + # Map type names to the value in the icalvalue_impl data union */ %union_map = ( BOOLEAN => 'int', @@ -118,199 +44,180 @@ EOM URI=>'string', UTCOFFSET=>'int', QUERY=>'string', - BINARY=>'string' + BINARY=>'string', + X=>'string' ); -while(<F>) -{ - - 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 <<EOM; - -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; -EOM - -if( ${union_data} eq 'string'){ -print" if(impl->data.v_${union_data}!=0) {free((void*)impl->data.v_${union_data});}\n"; -} - -print <<EOM; - - impl->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 <<EOM; -/* $value $comment */ -icalvalue* icalvalue_new_${lc}($type v); -$type icalvalue_get_${lc}(icalvalue* value); -void icalvalue_set_${lc}(icalvalue* value, ${type} v); + my ($c_autogen,$c_type) = @{$h{$value}->{'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<<EOM; -const char* icalvalue_${union_data}_as_ical_string(icalvalue* value) { + $c_type =~ s/enum //; - $type data; - char temp[1024]; - char *str; - icalerror_check_airg( (value!=0),"value"); - data = ((struct icalvalue_impl*)value)->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 <<EOM; +if($opt_c){ -package Net::ICal::Value::${ucf}; -use Net::ICal::Value; -\@ISA=qw(Net::ICal::Value); -sub new -{ - my \$self = []; - my \$package = shift; - my \$value = shift; + # print out the value to string map - bless \$self, \$package; + print "static struct icalvalue_kind_map value_map[]={\n"; - my \$p; + foreach $value (keys %h) { - if (\$value){ - \$p = Net::ICal::icalvalue_new_from_string(\$Net::ICal::ICAL_${uc}_VALUE,\$value); - } else { - \$p = Net::ICal::icalvalue_new(\$Net::ICal::ICAL_${uc}_VALUE); - } + $idx++; + my $ucv = join("",map {uc(lc($_));} split(/-/,$value)); + + next if $value eq "NO"; + + print " {ICAL_${ucv}_VALUE,\"$value\"},\n"; + } - \$self->[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 <<EOM; -#endif /*ICALVALUE_H*/ -EOM -} - - -__END__ - + print "#endif /*ICALVALUE_H*/\n"; + } + + + __END__ + |