From a7258e9fe6b6e1a5ff4752061ebe17c6a5054d74 Mon Sep 17 00:00:00 2001 From: Wolfram Schneider Date: Tue, 2 Jul 1996 23:35:21 +0000 Subject: [PATCH] Print a warning before starting dialog(1) if the user has no write access to /dev/speaker or the speaker device is not enabled in kernel. Code cleanup. --- usr.sbin/spkrtest/spkrtest.pl | 85 +++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 34 deletions(-) diff --git a/usr.sbin/spkrtest/spkrtest.pl b/usr.sbin/spkrtest/spkrtest.pl index d0fe260924ad..6a4754858db1 100644 --- a/usr.sbin/spkrtest/spkrtest.pl +++ b/usr.sbin/spkrtest/spkrtest.pl @@ -1,48 +1,48 @@ #!/usr/bin/perl # -# Test script for the speaker driver +# spkrtest - Test script for the speaker driver # # v1.0 by Eric S. Raymond (Feb 1990) # v1.1 rightstuff contributed by Eric S. Tiedemann (est@snark.thyrsus.com) -# v2.0 dialog+perl by Wolfram Schneider , May 1995 +# v2.0 dialog+perl by Wolfram Schneider , May 1995 # # NOTE for iso-* (latin1) fonts: use TERM=cons25-iso8859-1 # +# $Id: $ -$title = " -reveille -- Reveille -contact -- Contact theme from Close Encounters -dance -- Lord of the Dance (aka Simple Gifts) -loony -- Loony Toons theme -sinister -- standard villain's entrance music -rightstuff -- a trope from \"The Right Stuff\" score by Bill Conti -toccata -- opening bars of Bach's Toccata and Fugue in D Minor +$title = qq{ +reveille -- Reveille +contact -- Contact theme from Close Encounters +dance -- Lord of the Dance (aka Simple Gifts) +loony -- Loony Toons theme +sinister -- standard villain's entrance music +rightstuff -- a trope from "The Right Stuff" score by Bill Conti +toccata -- opening bars of Bach's Toccata and Fugue in D Minor startrek -- opening bars of the theme from Star Trek Classic -"; +}; -$music = " +$music = qq{ reveille -- t255l8c.f.afc~c.f.afc~c.f.afc.f.a..f.~c.f.afc~c.f.afc~c.f.afc~c.f.. -contact -- f -dance -- t240dcdc~cf8f8edd#e~ce8cdce8cd.c8c8c#def8af8 +contact -- f +dance -- t240dcdc~cf8f8edd#e~ce8cdce8cd.c8c8c#def8af8 sinister -- mst200o2ola.l8bc.~a.~>l2d# rightstuff -- olcega.a8f>cd2bgc.c8dee2 -toccata -- msl16oldcd4mll8pcb-agf+4.g4p4e8a2mspg+e8c+f+8b2 -"; +}; -$checklist = 'dialog \ ---title "Speaker test" \ ---checklist "Please select the melodies you wish to play (space for select)" \ --1 -1 10 \ -'; +@checklist = ('/usr/bin/dialog', '--title', 'Speaker test', '--checklist', + 'Please select the melodies you wish to play (space for select)', + '-1', '-1', '10'); +$speaker = '/dev/speaker'; sub Exit { - unlink $tmp if $tmp; + unlink $tmp if $tmp; exit; } -$SIG{'INT'} = $SIG{'HUP'} = $SIG{'TRAP'} = $SIG{'QUIT'} = +$SIG{'INT'} = $SIG{'HUP'} = $SIG{'TRAP'} = $SIG{'QUIT'} = $SIG{'TERM'} = '&Exit'; @@ -65,21 +65,38 @@ sub splitconfig { &splitconfig(*title); &splitconfig(*music); -foreach $e (sort keys %title) { - ($t = $title{$e}) =~ s/(\")/\\$1/g; # quote '"' - $checklist .= "\"$e\" \"$t\" OFF "; +foreach (sort keys %title) { + push(@checklist, ($_, $title{$_}, 'OFF')); } $tmp = ($ENV{'TMP'} || "/tmp") . "/_spkrtest$$"; -system("$checklist 2> $tmp"); # start dialog -if (!$?) { # not cancel - open(SPEAKER, ">/dev/speaker") || die "/dev/speaker: $!\n"; +if (!open(SPEAKER, "> $speaker")) { + warn "You have no write access to $speaker or the speaker device is not " . + "enabled\nin kernel. Cannot play any melody! See spkr(4).\a\n"; + sleep 2; +} + +open(SAVEERR, ">&STDERR") || die "open >&STDERR: $!\n"; +open(STDERR, "> $tmp") || do { die "open > $tmp: $!\n"; }; +system @checklist; # start dialog +open(STDERR, ">&SAVEERR") || die "open >&SAVEERR: $!\n"; +$return = $? >> 8; + +# die if speaker device not avaiable +if (fileno(SPEAKER) eq "") { + print "\nSorry, cannot play any melody!!!\n"; &Exit; +} + + +if (!$return) { # not cancel select(SPEAKER); $| = 1; select(STDOUT); $| = 1; - if (! -z $tmp) { # select melod(y/ies) - foreach $melody (split($", `cat $tmp`)) { + if (! -z $tmp) { # select melod(y/ies) + print STDOUT "\n"; + open(STDIN, $tmp) || do { die "open $tmp: $!\n"; }; + foreach $melody (split($", )) { $melody =~ s/^"//; $melody =~ s/"$//; print STDOUT "$title{$melody}\n"; print SPEAKER "$music{$melody}"; @@ -88,9 +105,9 @@ if (!$?) { # not cancel } else { # use default melody $melody = (sort keys %title)[0]; print STDOUT "Use default melody: $title{$melody}\n"; - print SPEAKER "$music{$melody}"; + print SPEAKER "$music{$melody}"; } close SPEAKER; } -unlink $tmp; +&Exit;