3 # Copyright (c) May 1995 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 # spkrtest - Test script for the speaker driver
29 # v1.0 by Eric S. Raymond (Feb 1990)
30 # v1.1 rightstuff contributed by Eric S. Tiedemann (est@snark.thyrsus.com)
31 # v2.0 dialog+perl by Wolfram Schneider <wosch@FreeBSD.org>, May 1995
33 # NOTE for iso-* (latin1) fonts: use TERM=cons25-iso8859-1
39 contact -- Contact theme from Close Encounters
40 dance -- Lord of the Dance (aka Simple Gifts)
41 loony -- Loony Toons theme
42 sinister -- standard villain's entrance music
43 rightstuff -- a trope from "The Right Stuff" score by Bill Conti
44 toccata -- opening bars of Bach's Toccata and Fugue in D Minor
45 startrek -- opening bars of the theme from Star Trek Classic
49 reveille -- t255l8c.f.afc~c.f.afc~c.f.afc.f.a..f.~c.f.afc~c.f.afc~c.f.afc~c.f..
50 contact -- <cd<a#~<a#>f
51 dance -- t240<cfcfgagaa#b#>dc<a#a.~fg.gaa#.agagegc.~cfcfgagaa#b#>dc<a#a.~fg.gga.agfgfgf.
52 loony -- t255cf8f8edc<a>~cf8f8edd#e~ce8cdce8cd.<a>c8c8c#def8af8
53 sinister -- mst200o2ola.l8bc.~a.~>l2d#
54 rightstuff -- olcega.a8f>cd2bgc.c8dee2
55 toccata -- msl16oldcd4mll8pcb-agf+4.g4p4<msl16dcd4mll8pa.a+f+4p16g4
56 startrek -- l2b.f+.p16a.c+.p l4mn<b.>e8a2mspg+e8c+f+8b2
59 @checklist = ('/usr/bin/dialog', '--title', 'Speaker test', '--checklist',
60 'Please select the melodies you wish to play (space for select)',
63 $speaker = '/dev/speaker';
66 unlink $tmp if $tmp; exit;
69 $SIG{'INT'} = $SIG{'HUP'} = $SIG{'TRAP'} = $SIG{'QUIT'} =
70 $SIG{'TERM'} = '&Exit';
73 # make assoc array from variable 'var'
74 # 'name -- description' -> $var{$name} = $description
77 local($t, $name, $description);
79 foreach $t (split('\n', $var)) {
80 ($name, $description) = split('--', $t);
82 $name =~ s/^\s+//; $name =~ s/\s+$//;
83 $description =~ s/\s+//; $description =~ s/\s+$//;
85 $var{$name} = $description if $name && $description;
92 foreach (sort keys %title) {
93 push(@checklist, ($_, $title{$_}, 'OFF'));
97 $tmp = ($ENV{'TMP'} || "/tmp") . "/_spkrtest" . rand(9999);
99 if (!open(SPEAKER, "> $speaker")) {
100 warn "You have no write access to $speaker or the speaker device is not " .
101 "enabled\nin kernel. Cannot play any melody! See spkr(4).\a\n";
105 open(SAVEERR, ">&STDERR") || die "open >&STDERR: $!\n";
106 open(STDERR, "> $tmp") || do { die "open > $tmp: $!\n"; };
107 system @checklist; # start dialog
108 open(STDERR, ">&SAVEERR") || die "open >&SAVEERR: $!\n";
111 # die if speaker device not avaiable
112 if (fileno(SPEAKER) eq "") {
113 print "\nSorry, cannot play any melody!!!\n"; &Exit;
117 if (!$return) { # not cancel
118 select(SPEAKER); $| = 1;
119 select(STDOUT); $| = 1;
121 if (! -z $tmp) { # select melod(y/ies)
123 open(STDIN, $tmp) || do { die "open $tmp: $!\n"; };
124 foreach $melody (split($", <STDIN>)) {
125 $melody =~ s/^"//; $melody =~ s/"$//;
126 print STDOUT "$title{$melody}\n";
127 print SPEAKER "$music{$melody}";
130 } else { # use default melody
131 $melody = (sort keys %title)[0];
132 print STDOUT "Use default melody: $title{$melody}\n";
133 print SPEAKER "$music{$melody}";