summaryrefslogtreecommitdiff
path: root/drivers/dahdi/xpp/XppConfig.pm
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir.cohen@xorcom.com>2008-06-17 17:28:42 +0000
committerTzafrir Cohen <tzafrir.cohen@xorcom.com>2008-06-17 17:28:42 +0000
commitee0bc6496d06fac25b57ac93bab4a439f410ebde (patch)
tree85539cde08b3f2f37bd29c72e1aa118d8388160a /drivers/dahdi/xpp/XppConfig.pm
parentce5f914a7705d42937c0011804b4b4a0372da88d (diff)
Adapt xpp init_card_* scripts to dahdi:
* No more dependency in zconf/ * Add new config file: xpp.conf * Use new perl module XppConfig.pm that read this config file. git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@4373 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'drivers/dahdi/xpp/XppConfig.pm')
-rw-r--r--drivers/dahdi/xpp/XppConfig.pm84
1 files changed, 84 insertions, 0 deletions
diff --git a/drivers/dahdi/xpp/XppConfig.pm b/drivers/dahdi/xpp/XppConfig.pm
new file mode 100644
index 0000000..2ccb6a9
--- /dev/null
+++ b/drivers/dahdi/xpp/XppConfig.pm
@@ -0,0 +1,84 @@
+package XppConf;
+#
+# Written by Oron Peled <oron@actcom.co.il>
+# Copyright (C) 2008, Xorcom
+# This program is free software; you can redistribute and/or
+# modify it under the same terms as Perl itself.
+#
+# $Id$
+#
+use strict;
+
+my $conf_file = "/etc/dahdi/xpp.conf";
+
+$conf_file = $ENV{XPP_CONFIG} if $ENV{XPP_CONFIG};
+
+sub subst_var($$) {
+ my $lookup = shift;
+ my $string = shift;
+
+ if(defined $lookup->{$string}) {
+ return $lookup->{$string};
+ } else {
+ return $string;
+ }
+}
+
+sub read_config($) {
+ my $input = shift || die;
+ my %xpp_config;
+ my $lookup = \%xpp_config;
+
+ open(F, $input) || die "Failed reading configuration $input: $!\n";
+LINE:
+ while(<F>) {
+ chomp;
+ s/#.*//; # strip comments
+ next unless /\S/;
+ s/^\s*//;
+ if(s/\\$//) {
+ my $next = <F>;
+ $next =~ s/^\s*//;
+ $_ .= " $next";
+ redo LINE;
+ }
+ my ($key, $value) = split(/=/, $_, 2);
+ # Trim whitespace around key/value
+ $key =~ s/^\s*(\S+)\s*$/$1/;
+ $value =~ s/^\s*(\S+)\s*$/$1/;
+ # Variable substitution
+ my $new_value = $value;
+ $new_value =~ s/\$(\w+)/subst_var($lookup,$1)/eg;
+ $xpp_config{$key} = $new_value;
+ }
+ close F;
+ return %xpp_config;
+}
+
+my %x = read_config($conf_file);
+
+sub show_vars {
+ my $assoc = shift;
+ foreach (sort keys %{$assoc}) {
+ print "$_\t$assoc->{$_}\n";
+ }
+}
+
+sub source_vars {
+ my @keys = @_;
+ my %conf = read_config($conf_file);
+ my %result;
+ my $k;
+ my $v;
+
+ foreach (@keys) {
+ if(defined $conf{$_}) {
+ $result{$_} = $conf{$_};
+ }
+ }
+ return ($conf_file, %result);
+}
+
+source_vars(qw(XPP_PRI_SETUP opermode));
+
+1;