From d6b0035a325d060d7f175705c33b0a2d7b60e533 Mon Sep 17 00:00:00 2001 From: Eric Busboom Date: Mon, 15 May 2000 06:18:21 +0000 Subject: reparing damage from removing files svn path=/trunk/; revision=3042 --- libical/scripts/mkderivedvalues.pl | 303 +++++++++++++++++++++++++++++++++++++ 1 file changed, 303 insertions(+) create mode 100755 libical/scripts/mkderivedvalues.pl (limited to 'libical/scripts/mkderivedvalues.pl') diff --git a/libical/scripts/mkderivedvalues.pl b/libical/scripts/mkderivedvalues.pl new file mode 100755 index 0000000000..a0909a6d94 --- /dev/null +++ b/libical/scripts/mkderivedvalues.pl @@ -0,0 +1,303 @@ +#!/usr/bin/perl + + +use Getopt::Std; +getopts('chspi:'); + +#Options +# c -> generate c code file +# h-> generate header file +# s -> generate switch statement + +# Open with value-c-types.txt + + +open(F,"$ARGV[0]") || die "Can't open values data file $ARGV[0]:$!"; + + +# 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; + + } + + print "/* Everything below this line is machine generated. Do not edit. */\n"; + +} + + +if (($opt_c || $opt_h) and !$opt_i) { +print < 'int', + CALADDRESS=>'string', + DATE=>'time', + DATETIME=>'time', + DATETIMEDATE=>'time', + DATETIMEPERIOD=>'period', + DURATION=>'duration', + INTEGER=>'int', + TEXT=>'string', + URI=>'string', + UTCOFFSET=>'int', + QUERY=>'string', + BINARY=>'string' + ); + +while() +{ + + chop; + my @v = split(/\t+/,$_); + + my $value = 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 =~ /\*/; + + my $assign; + + if ($type =~ /char/){ + $assign = "strdup(v);\n\n if (impl->data.v_string == 0){\n errno = ENOMEM;\n }\n"; + } else { + $assign = "v;"; + } + + my $union_data; + + if (exists $union_map{$uc} ){ + $union_data=$union_map{$uc}; + } else { + $union_data = $lc; + } + + if ($opt_c) { +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); + + return ((struct icalvalue_impl*)value)->data.v_${union_data}; +} + +EOM + +} elsif($opt_h) { + + print <data.v_${union_data} + + str = strdup(temp); + + return str; +} + +EOM + +} +} elsif ($opt_p) { # Generate perl code + +print <[0] = \$p; + + return \$self; +} + +sub set +{ + my \$self = shift; + my \$v = shift; + + my \$impl = \$self->_impl(); + + if (\$v) { + my \$new_value = ICal::icalvalue_new_from_string(\$ICal::ICAL_${uc}_VALUE,\$v); + if (\$new_value){ + ICal::icalvalue_free(\$self->[0]); + \$self->[0] = \$new_value; + } + + } + +} + +sub get +{ + my \$self = shift; + my \$impl = \$self->[0]; + + if (defined \$impl){ + + return ICal::icalvalue_as_ical_string(\$impl); + + } +} + +EOM +} + + + +} + +if ($opt_p) +{ + print "1;\n"; +} + + +if ($opt_h){ + +print <