summaryrefslogtreecommitdiff
path: root/xpp/perl_modules/Dahdi/Config/Gen.pm
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir.cohen@xorcom.com>2009-02-13 21:09:51 +0000
committerTzafrir Cohen <tzafrir.cohen@xorcom.com>2009-02-13 21:09:51 +0000
commit66ca50e198ed2989b97293fac59de30f1be48bd3 (patch)
treea4a86ee84b1fbd840cc83500e73ff68e0bcf41c0 /xpp/perl_modules/Dahdi/Config/Gen.pm
parent28afbbbb1753473ed1cf3bd073ff5aae5bbeadfe (diff)
Rework dahdi_genconf to have separate configuration generation modules.
'dahdi_genconf foo bar' will use the modules Dahdi::Config::Gen::Foo and Dahdi::Config::Gen::Bar to generate configuraion files. Extra formats can thus be added without modifying dahdi_genconf and independently of DAHDI. git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@6013 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'xpp/perl_modules/Dahdi/Config/Gen.pm')
-rw-r--r--xpp/perl_modules/Dahdi/Config/Gen.pm48
1 files changed, 48 insertions, 0 deletions
diff --git a/xpp/perl_modules/Dahdi/Config/Gen.pm b/xpp/perl_modules/Dahdi/Config/Gen.pm
new file mode 100644
index 0000000..01d602d
--- /dev/null
+++ b/xpp/perl_modules/Dahdi/Config/Gen.pm
@@ -0,0 +1,48 @@
+package Dahdi::Config::Gen;
+require Exporter;
+@ISA = qw(Exporter);
+
+@EXPORT_OK = qw(is_true);
+
+use strict;
+
+sub is_true($) {
+ my $val = shift || die;
+ return $val =~ /^(1|y|yes)$/i;
+}
+
+sub show_gconfig($) {
+ my $gconfig = shift || die;
+
+ print "Global configuration:\n";
+ foreach my $key (sort keys %{$gconfig}) {
+ printf " %-20s %s\n", $key, $gconfig->{$key};
+ }
+}
+
+sub bchan_range($) {
+ my $span = shift || die;
+ my $first_chan = ($span->chans())[0];
+ my $first_num = $first_chan->num();
+ my $range_start = $first_num;
+ my @range;
+ my $prev = undef;
+
+ die unless $span->is_digital();
+ foreach my $c (@{$span->bchan_list()}) {
+ my $curr = $c + $first_num;
+ if(!defined($prev)) {
+ $prev = $curr;
+ } elsif($curr != $prev + 1) {
+ push(@range, sprintf("%d-%d", $range_start, $prev));
+ $range_start = $curr;
+ }
+ $prev = $curr;
+ }
+ if($prev >= $first_num) {
+ push(@range, sprintf("%d-%d", $range_start, $prev));
+ }
+ return join(',', @range);
+}
+
+1;