summaryrefslogtreecommitdiff
path: root/scripts/mkrestrictiontable.pl
diff options
context:
space:
mode:
authorAllen Winter <allen.winter@kdab.com>2014-05-31 17:22:41 -0400
committerAllen Winter <allen.winter@kdab.com>2014-05-31 17:22:41 -0400
commitbc831ea040913b1069e8eaf99496dc12704b94a9 (patch)
tree1502b86977c42dd5e5d202a2ff3807b08309f9ff /scripts/mkrestrictiontable.pl
parentc1d3761c08651f469a3bd3a8130e6005b8e26136 (diff)
downloadlibical-git-bc831ea040913b1069e8eaf99496dc12704b94a9.tar.gz
Re-arrange after svn to git conversion
Diffstat (limited to 'scripts/mkrestrictiontable.pl')
-rwxr-xr-xscripts/mkrestrictiontable.pl102
1 files changed, 102 insertions, 0 deletions
diff --git a/scripts/mkrestrictiontable.pl b/scripts/mkrestrictiontable.pl
new file mode 100755
index 00000000..101e8b7c
--- /dev/null
+++ b/scripts/mkrestrictiontable.pl
@@ -0,0 +1,102 @@
+#!/usr/bin/env perl
+
+use Getopt::Std;
+getopts('i:');
+
+# the argument should be the path to the restriction datafile, usually
+# design-data/restrictions.csv
+open(F,"$ARGV[0]") || die "Can't open restriction 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(<IN>){
+
+ if (/<insert_code_here>/){
+ insert_code();
+ }
+
+ if (/Do not edit/){
+ last;
+ }
+
+ print;
+
+ }
+
+ close IN;
+}
+
+sub insert_code {
+# First build the property restriction table
+print "static const icalrestriction_property_record icalrestriction_property_records[] = {\n";
+
+while(<F>)
+{
+
+ chop;
+
+ s/\#.*$//;
+
+ my($method,$targetcomp,$prop,$subcomp,$restr,$sub) = split(/,/,$_);
+
+ next if !$method;
+
+ if(!$sub) {
+ $sub = "0";
+ } else {
+ $sub = "icalrestriction_".$sub;
+ }
+
+ if($prop ne "NONE"){
+ print(" \{ICAL_METHOD_${method},ICAL_${targetcomp}_COMPONENT,ICAL_${prop}_PROPERTY,ICAL_RESTRICTION_${restr},$sub},\n");
+ }
+
+}
+
+
+# Print the terminating line
+print " {ICAL_METHOD_NONE,ICAL_NO_COMPONENT,ICAL_NO_PROPERTY,ICAL_RESTRICTION_NONE}\n";
+
+print "};\n";
+
+print "static const icalrestriction_component_record icalrestriction_component_records[] = {\n";
+
+
+# Go back through the entire file and build the component restriction table
+close(F);
+open(F,"$ARGV[0]") || die "Can't open restriction data file $ARGV[0]:$!";
+
+while(<F>)
+{
+
+ chop;
+
+ s/\#.*$//;
+
+ my($method,$targetcomp,$prop,$subcomp,$restr,$sub) = split(/,/,$_);
+
+ next if !$method;
+
+ if(!$sub) {
+ $sub = "0";
+ } else {
+ $sub = "icalrestriction_".$sub;
+ }
+
+
+ if($subcomp ne "NONE"){
+ print(" \{ICAL_METHOD_${method},ICAL_${targetcomp}_COMPONENT,ICAL_${subcomp}_COMPONENT,ICAL_RESTRICTION_${restr},$sub\},\n");
+ }
+
+}
+
+# print the terminating line
+print " {ICAL_METHOD_NONE,ICAL_NO_COMPONENT,ICAL_NO_COMPONENT,ICAL_RESTRICTION_NONE}\n";
+print "};\n";
+}
+