1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
|
#!/usr/bin/env perl
################################################################################
# (C) COPYRIGHT 2000, Eric Busboom <eric@civicknowledge.com>
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of either:
#
# The LGPL as published by the Free Software Foundation, version
# 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.txt
#
# Or:
#
# The Mozilla Public License Version 2.0. You may obtain a copy of
# the License at https://www.mozilla.org/MPL/
################################################################################
require "readvaluesfile.pl";
use Getopt::Std;
getopts('chspi:');
%no_xname = (RELATED => 1, RANGE => 1, RSVP => 1, XLICERRORTYPE => 1, XLICCOMPARETYPE => 1);
%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
if ($opt_i) {
open(IN, $opt_i) || die "Can't open input file $opt_i";
while (<IN>) {
if (/<insert_code_here>/) {
$autogenMsg = "of section of machine generated code (mkderivedparameters.pl). Do not edit.";
if ($opt_p) {
$startComment = "#";
$endComment = "";
} else {
$startComment = "/*";
$endComment = " */";
}
print $startComment. " START " . $autogenMsg . $endComment . "\n\n";
insert_code();
print $startComment. " END " . $autogenMsg . $endComment . "\n\n";
} else {
print;
}
}
}
sub insert_code
{
# Write parameter enumerations and datatypes
if ($opt_h) {
my $enumConst = $params{'ANY'}->{"kindEnum"};
print "typedef enum icalparameter_kind {\n ICAL_ANY_PARAMETER = " . $enumConst . ",\n";
$enumVal = 1;
foreach $param (sort keys %params) {
next if !$param;
next if $param eq 'NO' or $param eq 'ANY';
my $uc = join("", map {uc($_);} split(/-/, $param));
$enumConst = $params{$param}->{"kindEnum"};
print " ICAL_${uc}_PARAMETER = " . $enumConst . ",\n";
}
$enumConst = $params{'NO'}->{"kindEnum"};
print " ICAL_NO_PARAMETER = " . $enumConst . "\n} icalparameter_kind;\n\n";
# Now create enumerations for parameter values
$lastidx = $idx = 20000;
print "#define ICALPARAMETER_FIRST_ENUM $idx\n\n";
foreach $param (sort keys %params) {
next if !$param;
next if $param eq 'NO' or $param eq 'ANY';
my $type = $params{$param}->{"C"};
my $ucv = join("", map {uc(lc($_));} split(/-/, $param));
my @enums = @{$params{$param}->{'enums'}};
if (@enums) {
print "typedef enum $type {\n";
my $first = 1;
foreach $e (@enums) {
if (!$first) {
print ",\n";
} else {
$first = 0;
}
$e =~ /([a-zA-Z0-9\-]+)=?([0-9]+)?/;
$e = $1;
if ($2) {
$idx = $2;
} else {
$idx++;
}
if ($idx > $lastidx) {
$lastidx = $idx;
}
my $uce = join("", map {uc(lc($_));} split(/-/, $e));
print " ICAL_${ucv}_${uce} = $idx";
}
$c_type =~ s/enum //;
print "\n} $type;\n\n";
}
}
$lastidx++;
print "#define ICALPARAMETER_LAST_ENUM $lastidx\n\n";
}
if ($opt_c) {
# Create the icalparameter_value to icalvalue_kind conversion table
my $count = 0;
my $out;
foreach $enum (@{$params{'VALUE'}->{'enums'}}) {
$enum =~ /([a-zA-Z0-9\-]+)=?([0-9]+)?/;
$enum = $1;
next if $enum eq 'X' or $enum eq 'NONE';
next if $enum eq 'NO' or $enum eq 'ERROR';
$uc = join("", map {uc(lc($_));} split(/-/, $enum));
$out .= " {ICAL_VALUE_${uc}, ICAL_${uc}_VALUE},\n";
$count++;
}
$count += 2;
print "static const 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
$out = "";
$count = 0;
foreach $param (sort keys %params) {
next if !$param;
next if $param eq 'NO' or $param eq 'ANY';
my $lc = join("", map {lc($_);} split(/-/, $param));
my $uc = join("", map {uc(lc($_));} split(/-/, $param));
$count++;
$out .= " {ICAL_${uc}_PARAMETER, \"$param\"},\n";
}
$count += 1;
print "static const struct icalparameter_kind_map parameter_map[$count] = {\n";
print $out;
print " { ICAL_NO_PARAMETER, \"\"}\n};\n\n";
# Create the parameter value map
$out = "";
$count = 0;
foreach $param (sort keys %params) {
next if !$param;
next if $param eq 'NO' or $param 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) {
$e =~ /([a-zA-Z0-9\-]+)=?([0-9]+)?/;
$e = $1;
next if $e eq 'X' or $e eq 'NONE';
my $uce = join("", map {uc(lc($_));} split(/-/, $e));
$count++;
$out .= " {ICAL_${uc}_PARAMETER,ICAL_${uc}_${uce}, \"$e\"},\n";
}
}
}
$count += 3;
print "static const struct icalparameter_map icalparameter_map[] = {\n";
print " {ICAL_ANY_PARAMETER, 0, \"\"},\n";
print $out;
print " {ICAL_NO_PARAMETER, 0, \"\"}\n};\n\n";
}
foreach $param (sort keys %params) {
next if $param eq 'NO' or $param eq 'ANY';
my $type = $params{$param}->{'C'};
my $ucf = join("", map {ucfirst(lc($_));} split(/-/, $param));
my $lc = lc($ucf);
my $uc = uc($lc);
my $charorenum;
my $set_code;
my $pointer_check;
my $pointer_check_v;
my $xrange;
if ($type =~ /char/) {
$type =~ s/char\*/char \*/;
$charorenum =
" icalerror_check_arg_rz((param != 0), \"param\");\n return param->string;";
$set_code = "((struct icalparameter_impl *)param)->string = icalmemory_strdup(v);";
$pointer_check = " icalerror_check_arg_rz((v != 0), \"v\");";
$pointer_check_v = "\n icalerror_check_arg_rv((v != 0), \"v\");";
} elsif ($type =~ /int/) {
$xrange = " if (param != 0) {\n return param->data;\n } else {\n return 0;\n }";
$charorenum =
" icalerror_check_arg((param != 0), \"param\");\n$xrange";
$set_code = "((struct icalparameter_impl *)param)->data = v;";
} else {
$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 if (!param) {\n return ICAL_${uc}_NONE;\n }\n$xrange\n return ($type)(param->data);";
$pointer_check =
" icalerror_check_arg_rz(v >= ICAL_${uc}_X, \"v\");\n icalerror_check_arg_rz(v < ICAL_${uc}_NONE, \"v\");";
$pointer_check_v =
"\n icalerror_check_arg_rv(v >= ICAL_${uc}_X, \"v\");\n icalerror_check_arg_rv(v < ICAL_${uc}_NONE, \"v\");";
$set_code = "((struct icalparameter_impl *)param)->data = (int)v;";
}
if ($opt_c) {
print <<EOM;
/* $param */
icalparameter *icalparameter_new_${lc}($type v)
{
struct icalparameter_impl *impl;
icalerror_clear_errno();
$pointer_check
impl = icalparameter_new_impl(ICAL_${uc}_PARAMETER);
if (impl == 0) {
return 0;
}
icalparameter_set_${lc}((icalparameter *)impl, v);
if (icalerrno != ICAL_NO_ERROR) {
icalparameter_free((icalparameter *)impl);
return 0;
}
return (icalparameter *)impl;
}
${type} icalparameter_get_${lc}(const icalparameter *param)
{
icalerror_clear_errno();
$charorenum
}
void icalparameter_set_${lc}(icalparameter *param, ${type} v)
{$pointer_check_v
icalerror_check_arg_rv((param != 0), "param");
icalerror_clear_errno();
if (param->string != NULL) {
free((void *)param->string);
}
$set_code
}
EOM
} elsif ($opt_h) {
print <<EOM;
/* $param */
LIBICAL_ICAL_EXPORT icalparameter * icalparameter_new_${lc}($type v);
LIBICAL_ICAL_EXPORT ${type} icalparameter_get_${lc}(const icalparameter *value);
LIBICAL_ICAL_EXPORT void icalparameter_set_${lc}(icalparameter *value, ${type} v);
EOM
}
if ($opt_p) {
print <<EOM;
# $param
package Net::ICal::Parameter::${ucf};
\@ISA=qw(Net::ICal::Parameter);
sub new
{
my \$self = [];
my \$package = shift;
my \$value = shift;
bless \$self, \$package;
my \$p;
if (\$value) {
\$p = Net::ICal::icalparameter_new_from_string(\$Net::ICal::ICAL_${uc}_PARAMETER,\$value);
} else {
\$p = Net::ICal::icalparameter_new(\$Net::ICal::ICAL_${uc}_PARAMETER);
}
\$self->[0] = \$p;
return \$self;
}
sub get
{
my \$self = shift;
my \$impl = \$self->_impl();
return Net::ICal::icalparameter_as_ical_string(\$impl);
}
sub set
{
# This is hard to implement, so I've punted for now.
die "Set is not implemented";
}
EOM
}
}
if ($opt_h) {
print <<EOM;
#endif /*ICALPARAMETER_H*/
EOM
}
}
|