| 1 | # Speakup::Speakup.pm | ||||||||||||||||||||||||||||||||||
| 2 | ######################################################################### | ||||||||||||||||||||||||||||||||||
| 3 | # This Perl module is Copyright (c) 2002, Peter J Billam # | ||||||||||||||||||||||||||||||||||
| 4 | # c/o P J B Computing, www.pjb.com.au # | ||||||||||||||||||||||||||||||||||
| 5 | # # | ||||||||||||||||||||||||||||||||||
| 6 | # This module is free software; you can redistribute it and/or # | ||||||||||||||||||||||||||||||||||
| 7 | # modify it under the same terms as Perl itself. # | ||||||||||||||||||||||||||||||||||
| 8 | ######################################################################### | ||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | package Speech::Speakup; | ||||||||||||||||||||||||||||||||||
| 11 | 1 | $VERSION = '1.05'; # | |||||||||||||||||||||||||||||||||
| 12 | 1 | my $stupid_bloody_warning = $VERSION; # circumvent -w warning | |||||||||||||||||||||||||||||||||
| 13 | 1 | require Exporter; | |||||||||||||||||||||||||||||||||
| 14 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||
| 15 | 1 | @EXPORT = qw(); | |||||||||||||||||||||||||||||||||
| 16 | 1 | @EXPORT_OK = qw(speakup_get speakup_set synth_get synth_set); | |||||||||||||||||||||||||||||||||
| 17 | 1 | %EXPORT_TAGS = (ALL => [@EXPORT,@EXPORT_OK]); | |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | no strict; no warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | 1 | $Speech::Speakup::Message = undef; | |||||||||||||||||||||||||||||||||
| 22 | 1 | $Speech::Speakup::SpDir = undef; | |||||||||||||||||||||||||||||||||
| 23 | 1 | foreach ('/sys/accessibility/speakup','/proc/speakup') { | |||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | if (-d $_) { $SpDir = $_; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||
| 26 | # if (!$SpDir) { die ; } # results in 100% failure for CPAN-testers :-( | ||||||||||||||||||||||||||||||||||
| 27 | # eval 'require Speech::Speakup'; | ||||||||||||||||||||||||||||||||||
| 28 | # sets $@ to "Can't locate ..." if Speech::Speakup is not installed | ||||||||||||||||||||||||||||||||||
| 29 | # sets $@ to "Compilation failed ..." if $SpDir is not present | ||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | # /usr/lib/i386-linux-gnu/espeak-data/ | ||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | use open ':locale'; # the open pragma was introduced in 5.8.6 | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub speakup_get { get($SpDir, @_); } | ||||||||||||||||||||||||||||||||
|
Subroutine
speakup_get: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub speakup_set { set($SpDir, @_); } | ||||||||||||||||||||||||||||||||
|
Subroutine
speakup_set: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub synth_get { get(synthdir(),@_); } | ||||||||||||||||||||||||||||||||
|
Subroutine
synth_get: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub synth_set { set(synthdir(),@_); } | ||||||||||||||||||||||||||||||||
|
Subroutine
synth_set: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub set { my ($dir, $param, $value) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
set: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if (! $param) { # return a list of all settable params | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if (! opendir(D,$dir)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 43 | 0 | $Message = "can't opendir $dir: "; | |||||||||||||||||||||||||||||||||
| 44 | 0 | return undef; | |||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||
| 46 | my @l = sort grep | ||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | { (!/^\./) && (-f "$dir/$_") && is_w("$dir/$_") } readdir(D); | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
!/^\./ && -f "$dir/$_" && is_w("$dir/$_")
not /^\./ and -f "$dir/$_"
MC/DC0%0/3
!/^\./ && -f "$dir/$_" && is_w("$dir/$_")
not /^\./
-f "$dir/$_"
is_w("$dir/$_")
Truth table0%0/4
not(A) and B && C
A= not /^\./B= -f "$dir/$_"C= is_w("$dir/$_")
| |||||||||||||||||||||||||||||||||||
| 48 | 0 | closedir D; | |||||||||||||||||||||||||||||||||
| 49 | 0 | $Message = undef; | |||||||||||||||||||||||||||||||||
| 50 | 0 | return @l; | |||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if (! open(F, '>', "$dir/$param")) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 53 | 0 | $Message = "can't open $dir/$param: $!"; | |||||||||||||||||||||||||||||||||
| 54 | 0 | return undef; | |||||||||||||||||||||||||||||||||
| 55 | } else { | ||||||||||||||||||||||||||||||||||
| 56 | 0 | print F "$value\n"; close F; | |||||||||||||||||||||||||||||||||
| 57 | 0 | $Message = undef; | |||||||||||||||||||||||||||||||||
| 58 | 0 | return 1; | |||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub get { my ($dir, $param) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
get: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if (! $param) { # return a list of all gettable params | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if (! opendir(D,$dir)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 65 | 0 | $Message = "can't opendir $dir: "; | |||||||||||||||||||||||||||||||||
| 66 | 0 | return undef; | |||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||
| 68 | my @l = sort grep | ||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | { (!/^\./) && (-f "$dir/$_") && is_r("$dir/$_") } readdir(D); | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
!/^\./ && -f "$dir/$_" && is_r("$dir/$_")
not /^\./ and -f "$dir/$_"
MC/DC0%0/3
!/^\./ && -f "$dir/$_" && is_r("$dir/$_")
not /^\./
-f "$dir/$_"
is_r("$dir/$_")
Truth table0%0/4
not(A) and B && C
A= not /^\./B= -f "$dir/$_"C= is_r("$dir/$_")
| |||||||||||||||||||||||||||||||||||
| 70 | 0 | closedir D; | |||||||||||||||||||||||||||||||||
| 71 | 0 | $Message = undef; | |||||||||||||||||||||||||||||||||
| 72 | 0 | return @l; | |||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if (! open(F, '<', "$dir/$param")) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 75 | 0 | $Message = "can't open $dir/$param: $!"; | |||||||||||||||||||||||||||||||||
| 76 | 0 | return undef; | |||||||||||||||||||||||||||||||||
| 77 | } else { | ||||||||||||||||||||||||||||||||||
| 78 | 0 | my @lines = (<F>); close F; | |||||||||||||||||||||||||||||||||
| 79 | 0 | $Message = undef; | |||||||||||||||||||||||||||||||||
| 80 | # 1.03 keymap is 65 lines long ! the others are only one line. | ||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if (1 < @lines) { return join('', @lines); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 82 | 0 | } else { my $value = $lines[0]; $value =~ s/\s+$//; return $value; | |||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub synthdir { | ||||||||||||||||||||||||||||||||
|
Subroutine
synthdir: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 88 | 0 | my $sd = get($SpDir,'synth'); | |||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if (! $sd) { warn "can't find the synth directory\n"; return ''; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 90 | 0 | my $d = "$SpDir/$sd"; | |||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if (! -e $d) { warn "synth directory $d does not exist\n"; return ''; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if (! -d $d) { warn "synth directory $d is not a directory\n"; return ''; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 93 | 0 | return $d; | |||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub is_w { | ||||||||||||||||||||||||||||||||
|
Subroutine
is_w: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 97 | # because -w as root reports yes regardless of file permissions | ||||||||||||||||||||||||||||||||||
| 98 | 0 | my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, | |||||||||||||||||||||||||||||||||
| 99 | $atime,$mtime,$ctime,$blksize,$blocks) = stat($_[0]); | ||||||||||||||||||||||||||||||||||
| 100 | 0 | return $mode & 2; | |||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub is_r { | ||||||||||||||||||||||||||||||||
|
Subroutine
is_r: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 103 | 0 | my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, | |||||||||||||||||||||||||||||||||
| 104 | $atime,$mtime,$ctime,$blksize,$blocks) = stat($_[0]); | ||||||||||||||||||||||||||||||||||
| 105 | 0 | return $mode & 4; | |||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub enter_speakup_silent { # 1.62 | ||||||||||||||||||||||||||||||||
|
Subroutine
enter_speakup_silent: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 109 | # echo 7 > /sys/accessibility/speakup/silent if it exists | ||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if (!$SpeakUpSilentFile) { return 0; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ($IsSpeakUpSilent) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 112 | 0 | warn "enter_speakup_silent but already IsSpeakUpSilent\r\n"; return 1 ; | |||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if (open(S, '>', $SpeakUpSilentFile)) { print S "7\n"; close S; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 115 | 0 | $IsSpeakUpSilent = 1; | |||||||||||||||||||||||||||||||||
| 116 | 0 | return 1; | |||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub leave_speakup_silent { # 1.62 | ||||||||||||||||||||||||||||||||
|
Subroutine
leave_speakup_silent: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 119 | # echo 4 > /sys/accessibility/speakup/silent if it exists | ||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if (!$SpeakUpSilentFile) { return 0; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if (!$IsSpeakUpSilent) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 122 | 0 | warn "leave_speakup_silent but not IsSpeakUpSilent\r\n"; return 1 ; | |||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if (open(S, '>', $SpeakUpSilentFile)) { print S "4\n"; close S; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 125 | 0 | $IsSpeakUpSilent = 0; | |||||||||||||||||||||||||||||||||
| 126 | 0 | return 1; | |||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub which { | ||||||||||||||||||||||||||||||||
|
Subroutine
which: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 130 | 0 | my $f; | |||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | foreach $d (split(":",$ENV{'PATH'})) {$f="$d/$_[0]"; return $f if -x $f;} | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||
| 133 | 1 | %SpeakMode = (); | |||||||||||||||||||||||||||||||||
| 134 | 1 | ▶ | sub END { | ||||||||||||||||||||||||||||||||
|
Subroutine
END: called CC=3 SCAR=17.3
| |||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if ($Eflite_FH) { print $Eflite_FH "s\nq { }\n"; close $Eflite_FH; | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 136 | 0 | } elsif ($Espeak_PID) { kill SIGHUP, $Espeak_PID; wait; | |||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||
| 140 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||
| 142 | __END__ | ||||||||||||||||||||||||||||||||||