Debian Codegraph @

perl/Mailsound

raw
1 #!/usr/bin/perl
2 #
3 # $Id: Mailsound,v 1.3 1998/09/19 18:46:41 boyns Exp $
4 #
5 # Copyright (C) 1993-98 Mark R. Boyns <[email protected]>
6 #
7 # This file is part of rplay.
8 #
9 # rplay is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
13 #
14 # rplay is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with rplay; see the file COPYING. If not, write to the
21 # Free Software Foundation, Inc.,
22 # 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
23 #
24
25 unshift (@INC, "/usr/local/lib");
26
27 use RPlay;
28 use Getopt::Long;
29
30 if ($ENV{'HOME'})
31 {
32 $opt_file = "$ENV{'HOME'}/.Mailsounds";
33 }
34 else
35 {
36 $opt_file = (getpwuid ($<))[7] . "/.Mailsounds";
37 }
38
39 $opt_matches = 1;
40 $opt_host = "localhost";
41 $opt_priority = undef;
42 $opt_volume = undef;
43 GetOptions ('file=s', 'host=s', 'priority=i', 'volume=i');
44
45 @patterns = ();
46 @attributes = ();
47 $matches = 0;
48
49 $defaults{'priority'} = $opt_priority if defined $opt_priority;
50 $defaults{'volume'} = $opt_volume if defined $opt_volume;
51
52 open (CONF, $opt_file) || die "$opt_file: $!";
53 while (<CONF>)
54 {
55 next if (/^\#/ || /^[ \t\n]/);
56 chop;
57 ($pattern, $args) = split (/\t+/);
58 push (@patterns, $pattern);
59 local (%attrs) = %defaults;
60 foreach (split (/[\t ]+/, $args))
61 {
62 ($name, $value) = split ('=');
63 $attrs{$name} = $value;
64 }
65 push (@attributes, \%attrs);
66 }
67 close (CONF);
68
69 @lines = <STDIN>;
70 foreach $i (0 .. $#patterns)
71 {
72 foreach (@lines)
73 {
74 last if /^\n/;
75 if (/$patterns[$i]/)
76 {
77 $hash_ref = $attributes[$i];
78 %attrs = %$hash_ref;
79
80 $host = $attrs{'host'};
81 $host = $opt_host unless $host;
82
83 foreach $h (split (':', $host))
84 {
85 $rp = new RPlay;
86 $rp->connect ($h);
87 $rp->play ($hash_ref);
88 $rp->disconnect ();
89 }
90
91 $matches++;
92 last;
93 }
94 }
95
96 last if $matches == $opt_matches;
97 }
98
99 exit 0;