Debian Codegraph @

drivers/dahdi/xpp/XppConfig.pm

raw
1 package XppConfig;
2 #
3 # Written by Oron Peled <[email protected]>
4 # Copyright (C) 2008, Xorcom
5 # This program is free software; you can redistribute and/or
6 # modify it under the same terms as Perl itself.
7 #
8 # $Id$
9 #
10 use strict;
11
12 my $conf_file = "/etc/dahdi/xpp.conf";
13
14 sub import {
15 my $pack = shift || die "Import without package?";
16 my $init_dir = shift || die "$pack::import -- missing init_dir parameter";
17 my $local_conf = "$init_dir/xpp.conf";
18 $conf_file = $local_conf if -r $local_conf;
19 }
20
21 sub read_config($) {
22 my $opts = shift || die;
23
24 open(F, $conf_file) || return ();
25 while(<F>) {
26 chomp;
27 s/#.*//; # strip comments
28 next unless /\S/;
29 s/\s*$//; # Trim trailing whitespace
30 my ($key, $value) = split(/\s+/, $_, 2);
31 $opts->{$key} = $value;
32 }
33 close F;
34 $opts->{'xppconf'} = $conf_file;
35 return %{$opts};
36 }
37
38 1;