Просмотр исходного кода

support multiple channels with same name

Christoph Berg 21 лет назад
Родитель
Сommit
92b7171fdc
3 измененных файлов с 36 добавлено и 19 удалено
  1. 7 1
      docs/Changelog
  2. 2 2
      docs/pisg-doc.xml
  3. 27 16
      modules/Pisg.pm

+ 7 - 1
docs/Changelog

@@ -1,8 +1,14 @@
 pisg (0.67) - ??
    Christoph:
+   * Features:
+     + Recognize ogg and wma suffixes in song stats.
+     + Added support for multiple channels in config with the same name.
+       Even multiple channel directives for the very same channel are
+       supported (closes SF tracker #967404, patch by Torbjörn Svensson).
+   * Documentation:
+     + Local options override global ones, not vice-versa.
    * Formats:
      + Notes on using mIRC.
-   * Recognize ogg and wma suffixes in song stats.
    * Languages:
      + Dutch: small update to shout1 (thanks, Søren Jensen).
      + Finnish: new strings added (thanks, Mikko Nissinen and Matti Peltola).

+ 2 - 2
docs/pisg-doc.xml

@@ -5,7 +5,7 @@
 
 <book id="pisg-documentation">
   <bookinfo>
-    <title>pisg 0.65 documentation</title>
+    <title>pisg 0.66 documentation</title>
     <subtitle>How to install and configure pisg</subtitle>
   </bookinfo>
   <toc></toc>
@@ -206,7 +206,7 @@
      <![CDATA[<set option="VALUE">]]>
      </programlisting>
 
-     Any global option will override anything defined within channel
+     Any global option will be overriden by anything defined within channel
      elements (see <xref linkend="setting-up-a-channel" />)
      </para>
 

+ 27 - 16
modules/Pisg.pm

@@ -30,7 +30,7 @@ sub new
         override_cfg => $args{override_cfg},
         use_configfile => $args{use_configfile},
         search_path => $args{search_path},
-        chans => {},
+        chans => [],
         users => {},
         cfg => {},
         tmps => {},
@@ -352,28 +352,31 @@ sub init_config
             }
 
         } elsif ($line =~ /<channel=(['"])(.+?)\1(.*)>/i) {
-            my ($channel, $settings) = ($2, $3);
-            $self->{chans}->{$channel}->{channel} = $channel;
+            my ($channel, $settings, $tmp) = ($2, $3, {});
+            $tmp->{$channel}->{channel} = $channel;
             $self->{cfg}->{chan_done}{$self->{cfg}->{channel}} = 1; # don't parse channel in $self->{cfg}->{channel} if a channel statement is present
             while ($settings =~ s/\s([^=]+)=(["'])(.+?)\2//) {
                 my $var = lc($1);
                 if ($var eq "logdir" || $var eq "logfile") {
-                    push(@{$self->{chans}->{$channel}{$var}}, $3);
+                    push(@{$tmp->{$channel}{$var}}, $3);
                 } else {
-                    $self->{chans}->{$channel}{$var} = $3;
+                    $tmp->{$channel}{$var} = $3;
                 }
             }
             while (<$fh>) {
                 next if /^\s*#/;
-                last if ($_ =~ /<\/*channel>/i);
+                if ($_ =~ /<\/*channel>/i) {
+                    push @{ $self->{chans} }, $tmp;
+                    last;
+                }
                 if ($_ =~ /^\s*(\w+)\s*=\s*(["'])(.+?)\2/) {
                     my $var = lc($1);
                     unless ((($var eq "logdir" || $var eq "logfile") && scalar(@{$self->{override_cfg}->{$var}}) > 0) || (($var ne "logdir" && $var ne "logfile") && $self->{override_cfg}->{$var})) {
 
                         if($var eq "logdir" || $var eq "logfile") {
-                            push @{$self->{chans}->{$channel}{$var}}, $3;
+                            push @{$tmp->{$channel}{$var}}, $3;
                         } else {
-                            $self->{chans}->{$channel}{$var} = $3;
+                            $tmp->{$channel}{$var} = $3;
                         }
 
                     }
@@ -530,18 +533,26 @@ sub parse_channels
     # make a list of channels to do
     my @chanlist;
     if (scalar @ {$self->{cfg}->{cchannels} } > 0) {
-        @chanlist = @{ $self->{cfg}->{cchannels} };
+        foreach my $channel (@{ $self->{cfg}->{cchannels} }) {
+            my $hits = 0;
+            foreach ( @{ $self->{chans} }) {
+                my $chan = (keys %{ $_ })[0];
+                if ($channel =~ m/^$chan$/i) {
+                    push @chanlist, $_;
+                    $hits++;
+                }
+            }
+            if ($hits < 1) {
+                print STDERR "Channel $channel not in config file, ignoring\n";
+            }
+        }
     } else {
-        @chanlist = keys %{ $self->{chans} };
+        push @chanlist, $_ foreach (@{ $self->{chans} });
     }
 
     foreach my $channel (@chanlist) {
-        if (!defined $self->{chans}->{$channel}) {
-            print STDERR "Channel $channel not in config file, ignoring\n";
-            next;
-        }
-        foreach (keys %{ $self->{chans}->{$channel} }) { # import channel specific config
-            $self->{cfg}->{$_} = $self->{chans}->{$channel}{$_};
+        foreach my $chan (keys %{ $channel }) { # import channel specific config
+            $self->{cfg}->{$_} = $channel->{$chan}->{$_} foreach (keys %{ $channel->{$chan} });
         }
         $self->do_channel();
         $origcfg{chan_done} = $self->{cfg}->{chan_done};