]>
git.p6c8.net - devedit.git/blob - modules/Config/DevEdit.pm
24bc3a2e39186850deafbd1b506eea8a60bcacfb
1 package Config
::DevEdit
;
4 # Dev-Editor - Module Config::DevEdit
6 # Read and parse the configuration files
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2010-12-23
11 # Copyright (C) 1999-2000 Roland Bluethgen, Frank Schoenmann
12 # Copyright (C) 2003-2009 Patrick Canterino
13 # All Rights Reserved.
15 # This file can be distributed and/or modified under the terms of
16 # of the Artistic License 1.0 (see also the LICENSE file found at
17 # the top level of the Dev-Editor distribution).
29 use base
qw(Exporter);
31 @EXPORT = qw(read_config);
33 # This variable contains some dependencies for the "disable_commands"
34 # configuration option.
35 # The Hash key defines a command, the value is an Array Reference or String
36 # defining the commands that will also be disabled.
38 my %disable_dependency = ('beginedit' => 'endedit');
42 # Read the configuration files of Dev-Editor
44 # Params: Path to main configuration file
46 # Return: Configuration (Hash Reference)
52 my $config = parse_config
($file);
54 $config->{'errors'} = parse_config
($config->{'error_file'});
55 $config->{'templates'} = parse_config
($config->{'template_file'});
57 # Check if we have to parse the user config file
59 if($ENV{'REMOTE_USER'} && $config->{'userconf_file'} && -f
$config->{'userconf_file'})
61 my $userconf = parse_config
($config->{'userconf_file'});
63 # Parse aliases (we use references, so we won't get a memory
66 foreach my $user(keys(%$userconf))
68 if(my $aliases = $userconf->{$user}->{'aliases'})
70 foreach my $alias(parse_line
('\s+',0,$aliases))
72 $userconf->{$alias} = $userconf->{$user} unless($userconf->{$alias});
77 if($userconf->{$ENV{'REMOTE_USER'}})
79 # The current HTTP Auth user has got an individual configuration
80 # Overwrite the default values
82 my $new_conf = $userconf->{$ENV{'REMOTE_USER'}};
84 $config->{'fileroot'} = $new_conf->{'fileroot'} if($new_conf->{'fileroot'});
85 $config->{'httproot'} = $new_conf->{'httproot'} if($new_conf->{'httproot'});
87 $config->{'forbidden'} = $new_conf->{'forbidden'} if(defined $new_conf->{'forbidden'});
88 $config->{'disable_commands'} = $new_conf->{'disable_commands'} if(defined $new_conf->{'disable_commands'});
90 $config->{'hide_dot_files'} = $new_conf->{'hide_dot_files'} if(defined $new_conf->{'hide_dot_files'});
92 $config->{'user_config'} = 1;
96 # Parse list of forbidden files
98 if($config->{'forbidden'})
102 foreach my $file(parse_line
('\s+',0,$config->{'forbidden'}))
106 $file = '/'.$file unless($file =~ m
!^/!);
112 $config->{'forbidden'} = \
@files;
116 $config->{'forbidden'} = [];
119 # Parse list of disabled commands (we need some universal code!)
121 if($config->{'disable_commands'})
125 foreach my $command(parse_line
('\s+',0,$config->{'disable_commands'}))
127 push(@commands,$command);
129 if(exists($disable_dependency{$command}) && $disable_dependency{$command})
131 if(ref($disable_dependency{$command}) eq 'ARRAY')
133 push(@commands,@
{$disable_dependency{$command}});
137 push(@commands,$disable_dependency{$command});
142 $config->{'disable_commands'} = \
@commands;
146 $config->{'disable_commands'} = [];
154 # Parse a configuration file
156 # Params: Path to configuration file
158 # Return: Configuration (Hash Reference)
165 open(CF
,'<'.$file) or croak
("Open $file: $!");
166 read(CF
, my $data, -s
$file);
169 my @lines = split(/\015\012|\012|\015/,$data);
174 foreach my $line(@lines)
178 next if($line =~ /^\s*#/);
180 if($line =~ /^\s*\[(\S+)\]\s*$/)
182 # Switch to new section
186 elsif($line =~ /^\s*\S+\s*=.*$/)
188 # A normal "key = value" line
190 my ($key,$value) = split(/=/,$line,2);
192 # Remove whitespaces at the beginning and at the end
201 $config->{$sect} = {} if(ref($config->{$sect}) ne 'HASH');
203 croak
"Configuration option '$key' of section '$sect' defined twice in line $count of configuration file '$file'" if($config->{$sect}->{$key});
205 $config->{$sect}->{$key} = $value;
209 croak
"Configuration option '$key' defined twice in line $count of configuration file '$file'" if($config->{$key});
211 $config->{$key} = $value;
219 # it's true, baby ;-)
patrick-canterino.de