require db4-devel
[platform/upstream/libical.git] / scripts / mkrestrictiontable.pl
1 #!/usr/bin/env perl
2
3 use Getopt::Std;
4 getopts('i:');
5
6 # the argument should be the path to the restriction datafile, usually
7 # design-data/restrictions.csv        
8 open(F,"$ARGV[0]") || die "Can't open restriction data file $ARGV[0]:$!";
9
10 # Write the file inline by copying everything before a demarcation
11 # line, and putting the generated data after the demarcation
12
13 if ($opt_i) {
14
15   open(IN,$opt_i) || die "Can't open input file $opt_i";
16
17   while(<IN>){
18
19     if (/<insert_code_here>/){
20       insert_code();
21     }
22
23     if (/Do not edit/){
24       last;
25     }
26
27     print;
28
29   }
30
31   close IN;
32 }
33
34 sub insert_code {
35 # First build the property restriction table 
36 print "static const icalrestriction_property_record icalrestriction_property_records[] = {\n";
37
38 while(<F>)
39 {
40
41   chop;
42
43   s/\#.*$//;
44
45   my($method,$targetcomp,$prop,$subcomp,$restr,$sub) = split(/,/,$_);
46
47   next if !$method;
48   
49   if(!$sub) {
50     $sub = "0";
51   } else {
52     $sub = "icalrestriction_".$sub;
53   }
54
55   if($prop ne "NONE"){
56     print("    \{ICAL_METHOD_${method},ICAL_${targetcomp}_COMPONENT,ICAL_${prop}_PROPERTY,ICAL_RESTRICTION_${restr},$sub},\n");
57   }
58
59 }
60
61
62 # Print the terminating line 
63 print "    {ICAL_METHOD_NONE,ICAL_NO_COMPONENT,ICAL_NO_PROPERTY,ICAL_RESTRICTION_NONE}\n";
64
65 print "};\n";
66
67 print "static const icalrestriction_component_record icalrestriction_component_records[] = {\n";
68
69
70 # Go back through the entire file and build the component restriction table
71 close(F);  
72 open(F,"$ARGV[0]") || die "Can't open restriction data file $ARGV[0]:$!";
73
74 while(<F>)
75 {
76
77   chop;
78
79   s/\#.*$//;
80
81   my($method,$targetcomp,$prop,$subcomp,$restr,$sub) = split(/,/,$_);
82
83   next if !$method;
84   
85   if(!$sub) {
86     $sub = "0";
87   } else {
88     $sub = "icalrestriction_".$sub;
89   }
90
91
92     if($subcomp ne "NONE"){
93       print("    \{ICAL_METHOD_${method},ICAL_${targetcomp}_COMPONENT,ICAL_${subcomp}_COMPONENT,ICAL_RESTRICTION_${restr},$sub\},\n");
94     }
95
96 }
97
98 # print the terminating line 
99 print "    {ICAL_METHOD_NONE,ICAL_NO_COMPONENT,ICAL_NO_COMPONENT,ICAL_RESTRICTION_NONE}\n";
100 print "};\n";
101 }
102