]> git.p6c8.net - devedit.git/blob - modules/Config/DevEdit.pm
8adfd358748ce720c082025247c30a9637cf918d
[devedit.git] / modules / Config / DevEdit.pm
1 package Config::DevEdit;
2
3 #
4 # Dev-Editor - Module Config::DevEdit
5 #
6 # Parse the configuration file
7 #
8 # Author: Patrick Canterino <patshaping@gmx.net>
9 # Last modified: 2004-01-16
10 #
11
12 use strict;
13
14 use vars qw(@EXPORT);
15 use Carp qw(croak);
16
17 ### Export ###
18
19 use base qw(Exporter);
20
21 @EXPORT = qw(read_config);
22
23 # read_config()
24 #
25 # Parse the configuration file
26 #
27 # Params: Path to configuration file
28 #
29 # Return: Configuration (Hash Reference)
30
31 sub read_config($)
32 {
33 my $file = shift;
34 local *CF;
35
36 open(CF,"<$file") or croak("Open $file: $!");
37 read(CF, my $data, -s $file);
38 close(CF);
39
40 my @lines = split(/\015\012|\012|\015/,$data);
41 my $config = {};
42
43 foreach my $line(@lines)
44 {
45 next if($line =~ /^\s*#/);
46 next if($line !~ /^.+=.+$/);
47
48 my ($key,$value) = split(/=/,$line,2);
49
50 # Remove whitespaces at the beginning and at the end
51
52 $key =~ s/^\s*//g;
53 $key =~ s/\s*$//g;
54 $value =~ s/^\s*//g;
55 $value =~ s/\s*$//g;
56
57 croak "Double defined value '$key' in configuration file '$file'" if($config->{$key});
58
59 $config->{$key} = $value;
60 }
61
62 return $config;
63 }
64
65 # it's true, baby ;-)
66
67 1;
68
69 #
70 ### End ###

patrick-canterino.de