Backport r30323/r30169 - perl use if/elsif/else so that it'll build with both new and old perl.

git-svn-id: svn://svn.rockbox.org/rockbox/branches/v3_9@30406 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Alex Parker 2011-09-01 14:25:05 +00:00
parent 7eef227154
commit 0f1b77dae8
2 changed files with 89 additions and 96 deletions

14
tools/multigcc.pl Executable file → Normal file
View file

@ -1,5 +1,4 @@
#!/usr/bin/perl #!/usr/bin/perl
use Switch;
use List::Util 'shuffle'; # standard from Perl 5.8 and later use List::Util 'shuffle'; # standard from Perl 5.8 and later
my $tempfile = "multigcc.out"; my $tempfile = "multigcc.out";
@ -26,16 +25,16 @@ my $command = join " ", @params;
# count number of cores # count number of cores
my $cores; my $cores;
switch($^O) { # Don't use given/when here - it's not compatible with old perl versions
case "darwin" { if ($^O eq 'darwin') {
chomp($cores = `sysctl -n hw.ncpu`); chomp($cores = `sysctl -n hw.ncpu`);
$cores = 1 if ($?); $cores = 1 if ($?);
} }
case "solaris" { elsif ($^O eq 'solaris') {
$cores = scalar grep /on-line/i, `psrinfo`; $cores = scalar grep /on-line/i, `psrinfo`;
$cores = 1 if ($?); $cores = 1 if ($?);
} }
else { else {
if (open CPUINFO, "</proc/cpuinfo") { if (open CPUINFO, "</proc/cpuinfo") {
$cores = scalar grep /^processor/i, <CPUINFO>; $cores = scalar grep /^processor/i, <CPUINFO>;
close CPUINFO; close CPUINFO;
@ -43,7 +42,6 @@ switch($^O) {
else { else {
$cores = 1; $cores = 1;
} }
}
} }
# fork children # fork children

29
tools/voice.pl Executable file → Normal file
View file

@ -19,7 +19,6 @@ use strict;
use warnings; use warnings;
use File::Basename; use File::Basename;
use File::Copy; use File::Copy;
use Switch;
use vars qw($V $C $t $l $e $E $s $S $i $v); use vars qw($V $C $t $l $e $E $s $S $i $v);
use IPC::Open2; use IPC::Open2;
use IPC::Open3; use IPC::Open3;
@ -74,8 +73,8 @@ sub init_tts {
our $verbose; our $verbose;
my ($tts_engine, $tts_engine_opts, $language) = @_; my ($tts_engine, $tts_engine_opts, $language) = @_;
my %ret = ("name" => $tts_engine); my %ret = ("name" => $tts_engine);
switch($tts_engine) { # Don't use given/when here - it's not compatible with old perl versions
case "festival" { if ($tts_engine eq 'festival') {
print("> festival $tts_engine_opts --server\n") if $verbose; print("> festival $tts_engine_opts --server\n") if $verbose;
my $pid = open(FESTIVAL_SERVER, "| festival $tts_engine_opts --server > /dev/null 2>&1"); my $pid = open(FESTIVAL_SERVER, "| festival $tts_engine_opts --server > /dev/null 2>&1");
my $dummy = *FESTIVAL_SERVER; #suppress warning my $dummy = *FESTIVAL_SERVER; #suppress warning
@ -83,7 +82,7 @@ sub init_tts {
$SIG{KILL} = sub { kill TERM => $pid; print("boo"); panic_cleanup(); }; $SIG{KILL} = sub { kill TERM => $pid; print("boo"); panic_cleanup(); };
$ret{"pid"} = $pid; $ret{"pid"} = $pid;
} }
case "sapi" { elsif ($tts_engine eq 'sapi') {
my $toolsdir = dirname($0); my $toolsdir = dirname($0);
my $path = `cygpath $toolsdir -a -w`; my $path = `cygpath $toolsdir -a -w`;
chomp($path); chomp($path);
@ -104,23 +103,20 @@ sub init_tts {
"stdout" => *CMD_OUT, "stdout" => *CMD_OUT,
"vendor" => $vendor); "vendor" => $vendor);
} }
}
return \%ret; return \%ret;
} }
# Shutdown TTS engine if necessary. # Shutdown TTS engine if necessary.
sub shutdown_tts { sub shutdown_tts {
my ($tts_object) = @_; my ($tts_object) = @_;
switch($$tts_object{"name"}) { if ($$tts_object{'name'} eq 'festival') {
case "festival" {
# Send SIGTERM to festival server # Send SIGTERM to festival server
kill TERM => $$tts_object{"pid"}; kill TERM => $$tts_object{"pid"};
} }
case "sapi" { elsif ($$tts_object{'name'} eq 'sapi') {
print({$$tts_object{"stdin"}} "QUIT\r\n"); print({$$tts_object{"stdin"}} "QUIT\r\n");
close($$tts_object{"stdin"}); close($$tts_object{"stdin"});
} }
}
} }
# Apply corrections to a voice-string to make it sound better # Apply corrections to a voice-string to make it sound better
@ -146,9 +142,9 @@ sub voicestring {
our $verbose; our $verbose;
my ($string, $output, $tts_engine_opts, $tts_object) = @_; my ($string, $output, $tts_engine_opts, $tts_object) = @_;
my $cmd; my $cmd;
printf("Generate \"%s\" with %s in file %s\n", $string, $$tts_object{"name"}, $output) if $verbose; my $name = $$tts_object{'name'};
switch($$tts_object{"name"}) { printf("Generate \"%s\" with %s in file %s\n", $string, $name, $output) if $verbose;
case "festival" { if ($name eq 'festival') {
# festival_client lies to us, so we have to do awful soul-eating # festival_client lies to us, so we have to do awful soul-eating
# work with IPC::open3() # work with IPC::open3()
$cmd = "festival_client --server localhost --otype riff --ttw --output \"$output\""; $cmd = "festival_client --server localhost --otype riff --ttw --output \"$output\"";
@ -168,27 +164,26 @@ sub voicestring {
close(CMD_OUT); close(CMD_OUT);
close(CMD_ERR); close(CMD_ERR);
} }
case "flite" { elsif ($name eq 'flite') {
$cmd = "flite $tts_engine_opts -t \"$string\" \"$output\""; $cmd = "flite $tts_engine_opts -t \"$string\" \"$output\"";
print("> $cmd\n") if $verbose; print("> $cmd\n") if $verbose;
`$cmd`; `$cmd`;
} }
case "espeak" { elsif ($name eq 'espeak') {
$cmd = "espeak $tts_engine_opts -w \"$output\""; $cmd = "espeak $tts_engine_opts -w \"$output\"";
print("> $cmd\n") if $verbose; print("> $cmd\n") if $verbose;
open(ESPEAK, "| $cmd"); open(ESPEAK, "| $cmd");
print ESPEAK $string . "\n"; print ESPEAK $string . "\n";
close(ESPEAK); close(ESPEAK);
} }
case "sapi" { elsif ($name eq 'sapi') {
print({$$tts_object{"stdin"}} "SPEAK\t$output\t$string\r\n"); print({$$tts_object{"stdin"}} "SPEAK\t$output\t$string\r\n");
} }
case "swift" { elsif ($name eq 'swift') {
$cmd = "swift $tts_engine_opts -o \"$output\" \"$string\""; $cmd = "swift $tts_engine_opts -o \"$output\" \"$string\"";
print("> $cmd\n") if $verbose; print("> $cmd\n") if $verbose;
system($cmd); system($cmd);
} }
}
} }
# trim leading / trailing silence from the clip # trim leading / trailing silence from the clip