FreeCalypso > hg > tcs211-l1-reconst
comparison g23m/system/busyb/tools/gen_configDef.pl @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 #!perl -w | |
2 use strict; | |
3 | |
4 use File::Glob ':glob'; | |
5 use File::Spec; | |
6 | |
7 # find the config file | |
8 @ARGV > 2 || die "Usage:\tgen_configDef.pl <configDef_Template> <configDef_OutFile> [flags]*\n"; | |
9 | |
10 | |
11 # define global variables | |
12 my $infFile =$ARGV[0]; | |
13 my $tmplFile =$ARGV[1]; | |
14 my $configDefFile =$ARGV[2]; | |
15 | |
16 | |
17 shift(@ARGV); | |
18 shift(@ARGV); | |
19 | |
20 | |
21 | |
22 my %infProperties; | |
23 # parse the remaining command line | |
24 foreach (@ARGV) { | |
25 /^(\w+)=(\d+)/; | |
26 if (defined($1)) { | |
27 if (defined($2)) { | |
28 $infProperties{$1} = $2; | |
29 } | |
30 } | |
31 } | |
32 | |
33 | |
34 # parse the template file | |
35 # | |
36 open (IN,"<$tmplFile")||die "Can't open $tmplFile !\n"; | |
37 | |
38 my %tmplProperties; | |
39 my $line; | |
40 while(defined($line = <IN>)) | |
41 { | |
42 # ignore comments (starting with #) | |
43 if($line =~ /^\s*\#/) { | |
44 next; | |
45 } | |
46 | |
47 # ignore empty lines | |
48 if($line =~ /^\s+$/) { | |
49 next; | |
50 } | |
51 | |
52 # remove trailing \n | |
53 chomp($line); | |
54 | |
55 if ($line =~ /^(\w+)/) { | |
56 my $orgName = $1; | |
57 if ($' =~ /^=(\d+|\w+)/) { | |
58 $tmplProperties{$orgName} = $1; | |
59 } | |
60 else { | |
61 $tmplProperties{$orgName} = ""; | |
62 } | |
63 } | |
64 else { | |
65 next; | |
66 } | |
67 } | |
68 close IN; | |
69 | |
70 # do the mapping/filtering | |
71 my %finalProperties; | |
72 foreach (keys(%infProperties)) { | |
73 if (exists $tmplProperties{$_}) { | |
74 if ($tmplProperties{$_} =~ /^\d+/) { | |
75 # a value | |
76 $finalProperties{$_} = $infProperties{$_}; | |
77 # print "$_=$infProperties{$_}\t\toverridden\n"; | |
78 } | |
79 elsif ($tmplProperties{$_} =~ /^\w+/) { | |
80 # a mapping | |
81 $finalProperties{$tmplProperties{$_}} = $infProperties{$_}; | |
82 # print "$tmplProperties{$_}=$infProperties{$_}\t\tmapped from $_\n"; | |
83 } | |
84 else { | |
85 # used | |
86 $finalProperties{$_} = $infProperties{$_}; | |
87 # print "$_=$infProperties{$_}\t\tused\n"; | |
88 } | |
89 # delete the template entry, so later we can process the remaining defaults | |
90 delete ($tmplProperties{$_}); | |
91 } | |
92 else | |
93 { | |
94 # print "$_=$infProperties{$_}\t\tignored\n" | |
95 } | |
96 | |
97 } | |
98 | |
99 # write the configDef file | |
100 # | |
101 open (OUT,">$configDefFile")||die "Can't open $configDefFile !\n"; | |
102 $configDefFile =~ /(\w+)(.\w+$)/; | |
103 my $name = $1; | |
104 | |
105 print OUT "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; | |
106 print OUT "<configDef description=\"auto generated from: $infFile\" name=\"$name\" reference=\"none\">\n"; | |
107 | |
108 # first the ones that have been overridden/mapped from the commandline | |
109 foreach (keys(%finalProperties)) { | |
110 print OUT "<property name=\"$_\" value=\"$finalProperties{$_}\"/>\n"; | |
111 } | |
112 | |
113 # now the defaults | |
114 foreach (keys(%tmplProperties)) { | |
115 if ($tmplProperties{$_} =~ /^\d+/) { | |
116 print OUT "<property name=\"$_\" value=\"$tmplProperties{$_}\"/>\n"; | |
117 } | |
118 } | |
119 | |
120 print OUT "</configDef>\n"; | |
121 | |
122 close OUT; |