require db4-devel
[platform/upstream/libical.git] / scripts / mkderivedcomponents.pl
1 #!/usr/bin/env perl
2
3 use Getopt::Std;
4 getopts('chspi:');
5
6
7 # ARG 0 is components.txt
8 open(PV,"$ARGV[0]") || die "Can't open components  file $ARGV[0]:$!";
9
10 my @components;
11
12 while (<PV>){
13
14   s/#.*//;
15
16   chop;
17
18   push(@components,$_);
19
20 }
21
22 close PV;
23
24 # Write the file inline by copying everything before a demarcation
25 # line, and putting the generated data after the demarcation
26
27 if ($opt_i) {
28
29   open(IN,$opt_i) || die "Can't open input file \"$opt_i\"";
30
31   while(<IN>){
32
33     if (/Do not edit/){
34       last;
35     }
36
37     print;
38
39   }    
40
41   if($opt_i){
42     print "# Everything below this line is machine generated. Do not edit. \n";
43   } else {
44     print "/* Everything below this line is machine generated. Do not edit. */\n";
45   }
46
47 }
48
49 if ($opt_c or $opt_h and !$opt_i){
50
51 print <<EOM;
52 /* -*- Mode: C -*-
53   ======================================================================
54   FILE: icalderivedproperties.{c,h}
55   CREATOR: eric 09 May 1999
56   
57   \044Id:\044
58     
59   (C) COPYRIGHT 1999 Eric Busboom 
60   http://www.softwarestudio.org
61
62   The contents of this file are subject to the Mozilla Public License
63   Version 1.0 (the "License"); you may not use this file except in
64   compliance with the License. You may obtain a copy of the License at
65   http://www.mozilla.org/MPL/
66  
67   Software distributed under the License is distributed on an "AS IS"
68   basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
69   the License for the specific language governing rights and
70   limitations under the License.
71  
72
73  ======================================================================*/
74
75 /*
76  * THIS FILE IS MACHINE GENERATED DO NOT EDIT
77  */
78
79 #include <stdarg.h> /* for va_arg functions */
80
81 EOM
82
83 }
84
85 if ($opt_p and !$opt_i){
86
87 print <<EOM;
88
89 EOM
90
91 }
92
93
94 foreach $comp (@components) {
95
96   next if !$comp;
97
98   my $ucf = join("",map {ucfirst(lc($_));}  split(/-/,$comp));
99   my $lc = lc($ucf);
100   my $uc = uc($lc);
101
102   if($opt_c) { # Make C source
103  print<<EOM;
104
105 /* $comp */
106
107 icalcomponent* icalcomponent_new_${lc}()
108 {
109    return (icalcomponent*)icalcomponent_new_impl(ICAL_${uc}_COMPONENT);
110 }
111
112 icalcomponent* icalcomponent_vanew_${lc}(...)
113 {
114    va_list args;
115    struct icalcomponent_impl *impl = icalcomponent_new_impl(ICAL_${uc}_component);  
116
117    va_start(args,v);
118    icalcomponent_add_properties(impl, args);
119    va_end(args);
120
121    return (icalcomponent*)impl;
122 }
123  
124 EOM
125
126
127   } elsif ($opt_h) { # Make a C header
128  print<<EOM;
129
130 /* $comp */
131 icalcomponent* icalcomponent_new_${lc}();
132 icalcomponent* icalcomponent_vanew_${lc}(...);
133 EOM
134   
135 } elsif ($opt_s) { # Make something for a switch statement
136
137 print <<EOM;
138 case ICAL_${uc}_PROPERTY:
139 EOM
140
141 } elsif ($opt_p) { # make perl source 
142
143 print <<EOM;
144
145 # $comp 
146 package Net::ICal::Component::${ucf};
147 \@ISA=qw(Net::ICal::Component);
148
149 sub new
150 {
151    my \$package = shift;
152    my \$c = Net::ICal::icalcomponent_new(\$Net::ICal::ICAL_${uc}_COMPONENT);
153
154    my \$self = Net::ICal::Component::new_from_ref(\$c);
155    Net::ICal::Component::_add_elements(\$self,\\\@_);
156
157    # Self is blessed in new_from_ref
158
159    return \$self; 
160
161 }
162 EOM
163
164 }
165
166
167
168 }
169
170