]>
git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Conf.pm
3d2d5be9e7881ac1908e4c90e2c477889c298909
3 # ====================================================
4 # Autor: n.d.p. / 2001-01-05
5 # lm : n.d.p. / 2001-02-02
6 # ====================================================
8 # Einlesen der Scriptkonfiguration
9 # ====================================================
17 # ====================================================
19 # ====================================================
21 use base
qw(Exporter);
22 @Conf::EXPORT
= qw(read_script_conf);
24 ################################
25 # sub read_script_conf
28 ################################
30 sub read_script_conf
($$$) {
31 my ($Bin, $Shared, $Script) = @_;
33 $Script =~ s/^(.*)\..*$/$1/; # Vornamen extrahieren
34 my $common = "$Shared/common.xml"; # gemeinsame Konf-datei
35 my $group = "$Bin/config/common.xml"; # gemeinsame (Gruppen-)Konf-datei
36 my $special = "$Bin/config/$Script.xml"; # spezielle Konf-datei
37 my %conf=(); # conf-Hash
39 &parse_script_conf
($common , \
%conf, $Script); # und los...
40 &parse_script_conf
($group, \
%conf, $Script);
41 &parse_script_conf
($special, \
%conf, $Script);
47 # ====================================================
49 # ====================================================
51 sub parse_script_conf
($$$) {
52 my ($filename, $conf, $Script) = @_;
56 my $xml = new XML
::DOM
::Parser
-> parsefile
($filename);
57 my $config = $xml -> getElementsByTagName
('Config',0) -> item
(0);
59 foreach ($config -> getElementsByTagName
('Constant', 0)) {&add_data
($_, $conf)}
60 foreach ($config -> getElementsByTagName
('Property', 0)) {&add_prop
($_, $conf)}
61 foreach ($config -> getElementsByTagName
('Limit', 0)) {&add_limit
($_, $conf, $Script)}}
67 my ($node, $conf) = @_;
68 my $name = $node -> getAttribute
('name');
70 die "element '".$node -> getNodeName
."' requires attribute 'name' - aborted" unless (length ($name) and defined ($name));
71 die "double defined name '$name' - aborted" if ( exists ( $conf -> {$name} ) );
74 $conf -> {$name} = ($node -> hasChildNodes
)?
$node -> getFirstChild
-> getData
:undef;
80 my ($node, $conf) = @_;
82 my $name = $node -> getAttribute
('name');
84 die "element 'Property' requires attribute 'name' - aborted" unless (length ($name));
86 my @props = $node -> getElementsByTagName
('Property', 0);
87 my @vars = $node -> getElementsByTagName
('Variable', 0);
88 my @lists = $node -> getElementsByTagName
('List', 0);
93 my $hash = (defined $conf -> {$name})?
$conf -> {$name}:{};
95 die "name '$name' is defined for 'Property' and 'Variable' - aborted" unless (ref $hash eq 'HASH');
97 &add_prop
($_, $hash);
98 $conf -> {$name} = $hash;}}
103 my $lname = $_ -> getAttribute
('name');
105 die "element 'List' requires attribute 'name' - aborted" unless (length ($lname) and defined ($lname));
106 die "double defined name '$lname' - aborted" if ( exists ( $conf -> {$name} -> {$lname} ) );
108 $conf -> {$name} -> {$lname} = [map {($_ -> hasChildNodes
)?
$_ -> getFirstChild
-> getData
:undef} $_ -> getElementsByTagName
('ListItem', 0)];}}
113 my $vname = $_ -> getAttribute
('name');
115 die "element 'Variable' requires attribute 'name' - aborted" unless (length ($vname) and defined ($vname));
116 die "double defined name '$vname' - aborted" if ( exists ( $conf -> {$name} -> {$vname} ) );
118 $conf -> {$name} -> {$vname} = ($_ -> hasChildNodes
)?
$_ -> getFirstChild
-> getData
:undef;}}
123 sub add_limit
($$$) {
124 my ($node, $conf, $Script) = @_;
126 my %apps = map {($_ -> getFirstChild
-> getData
=> 1)}
127 $node -> getElementsByTagName
('Application',0) -> item
(0)
128 -> getElementsByTagName
('Script',0);
130 if ($apps {$Script}) {
131 foreach ($node -> getElementsByTagName
('Constant', 0)) {&add_data
($_, $conf)}
132 foreach ($node -> getElementsByTagName
('Property', 0)) {&add_prop
($_, $conf)}}
137 # ====================================================
138 # Modulinitialisierung
139 # ====================================================
141 # making require happy
144 # ====================================================
146 # ====================================================
148 package Conf
::Test
;sub show
{print"Content-type: text/plain\n\n";&hash
($_[
149 0],'')}sub hash
{my($ref,$string)=@_;foreach(sort keys%$ref){my$val=$ref->
150 {$_};unless(ref($val)){print$string,$_,' = ',$val,"\n";next;}else{if(ref(
151 $val)eq 'HASH'){&hash
($val,"$string$_ -> ");}else{if(ref($val)eq'ARRAY'){
152 &array
($val,"$string$_ -> ");}}}}}sub array
{my($ref,$string)=@_;my $i=0;
153 foreach (@
$ref){unless(ref($_)){print$string,"[$i] = ", $_,"\n";}else{if(
154 ref($_)eq 'HASH'){&hash
($_,"$string\[$i] -> ")}else{if(ref($_)eq'ARRAY'){
155 &array
($_,"$string\[$i] -> ");}}}$i++;}}# n.d.p./2001-01-05/lm:2001-01-19
156 # FUNCTION: printing the configuration, USAGE: &Conf::Test::show ($conf);
158 # ====================================================
159 # 'real' end of Conf .-))
160 # ====================================================
patrick-canterino.de