summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Parker <rockbox@aeparker.com>2011-09-01 14:25:05 +0000
committerAlex Parker <rockbox@aeparker.com>2011-09-01 14:25:05 +0000
commit0f1b77dae8b23844910c20442a86db9486f438aa (patch)
tree948b37cd9b632fa0b71740e93eb5f975d97d5c5a
parent7eef2271548bfc203c5237d90cca7e9667ae760b (diff)
downloadrockbox-v3.9.tar.gz
rockbox-v3.9.zip
Backport r30323/r30169 - perl use if/elsif/else so that it'll build with both new and old perl.v3.9.1-finalv3.9
git-svn-id: svn://svn.rockbox.org/rockbox/branches/v3_9@30406 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--[-rwxr-xr-x]tools/multigcc.pl30
-rw-r--r--[-rwxr-xr-x]tools/voice.pl155
2 files changed, 89 insertions, 96 deletions
diff --git a/tools/multigcc.pl b/tools/multigcc.pl
index 9be9978bd4..c272ebae08 100755..100644
--- a/tools/multigcc.pl
+++ b/tools/multigcc.pl
@@ -1,5 +1,4 @@
#!/usr/bin/perl
-use Switch;
use List::Util 'shuffle'; # standard from Perl 5.8 and later
my $tempfile = "multigcc.out";
@@ -26,23 +25,22 @@ my $command = join " ", @params;
# count number of cores
my $cores;
-switch($^O) {
- case "darwin" {
- chomp($cores = `sysctl -n hw.ncpu`);
- $cores = 1 if ($?);
- }
- case "solaris" {
- $cores = scalar grep /on-line/i, `psrinfo`;
- $cores = 1 if ($?);
+# Don't use given/when here - it's not compatible with old perl versions
+if ($^O eq 'darwin') {
+ chomp($cores = `sysctl -n hw.ncpu`);
+ $cores = 1 if ($?);
+}
+elsif ($^O eq 'solaris') {
+ $cores = scalar grep /on-line/i, `psrinfo`;
+ $cores = 1 if ($?);
+}
+else {
+ if (open CPUINFO, "</proc/cpuinfo") {
+ $cores = scalar grep /^processor/i, <CPUINFO>;
+ close CPUINFO;
}
else {
- if (open CPUINFO, "</proc/cpuinfo") {
- $cores = scalar grep /^processor/i, <CPUINFO>;
- close CPUINFO;
- }
- else {
- $cores = 1;
- }
+ $cores = 1;
}
}
diff --git a/tools/voice.pl b/tools/voice.pl
index ee68c30eb4..f74791babb 100755..100644
--- a/tools/voice.pl
+++ b/tools/voice.pl
@@ -19,7 +19,6 @@ use strict;
use warnings;
use File::Basename;
use File::Copy;
-use Switch;
use vars qw($V $C $t $l $e $E $s $S $i $v);
use IPC::Open2;
use IPC::Open3;
@@ -74,36 +73,35 @@ sub init_tts {
our $verbose;
my ($tts_engine, $tts_engine_opts, $language) = @_;
my %ret = ("name" => $tts_engine);
- switch($tts_engine) {
- case "festival" {
- print("> festival $tts_engine_opts --server\n") if $verbose;
- my $pid = open(FESTIVAL_SERVER, "| festival $tts_engine_opts --server > /dev/null 2>&1");
- my $dummy = *FESTIVAL_SERVER; #suppress warning
- $SIG{INT} = sub { kill TERM => $pid; print("foo"); panic_cleanup(); };
- $SIG{KILL} = sub { kill TERM => $pid; print("boo"); panic_cleanup(); };
- $ret{"pid"} = $pid;
- }
- case "sapi" {
- my $toolsdir = dirname($0);
- my $path = `cygpath $toolsdir -a -w`;
- chomp($path);
- $path = $path . '\\';
- my $cmd = $path . "sapi_voice.vbs /language:$language $tts_engine_opts";
- $cmd =~ s/\\/\\\\/g;
- print("> cscript //nologo $cmd\n") if $verbose;
- my $pid = open2(*CMD_OUT, *CMD_IN, "cscript //nologo $cmd");
- binmode(*CMD_IN, ':encoding(utf16le)');
- binmode(*CMD_OUT, ':encoding(utf16le)');
- $SIG{INT} = sub { print(CMD_IN "QUIT\r\n"); panic_cleanup(); };
- $SIG{KILL} = sub { print(CMD_IN "QUIT\r\n"); panic_cleanup(); };
- print(CMD_IN "QUERY\tVENDOR\r\n");
- my $vendor = readline(*CMD_OUT);
- $vendor =~ s/\r\n//;
- %ret = (%ret,
- "stdin" => *CMD_IN,
- "stdout" => *CMD_OUT,
- "vendor" => $vendor);
- }
+ # Don't use given/when here - it's not compatible with old perl versions
+ if ($tts_engine eq 'festival') {
+ print("> festival $tts_engine_opts --server\n") if $verbose;
+ my $pid = open(FESTIVAL_SERVER, "| festival $tts_engine_opts --server > /dev/null 2>&1");
+ my $dummy = *FESTIVAL_SERVER; #suppress warning
+ $SIG{INT} = sub { kill TERM => $pid; print("foo"); panic_cleanup(); };
+ $SIG{KILL} = sub { kill TERM => $pid; print("boo"); panic_cleanup(); };
+ $ret{"pid"} = $pid;
+ }
+ elsif ($tts_engine eq 'sapi') {
+ my $toolsdir = dirname($0);
+ my $path = `cygpath $toolsdir -a -w`;
+ chomp($path);
+ $path = $path . '\\';
+ my $cmd = $path . "sapi_voice.vbs /language:$language $tts_engine_opts";
+ $cmd =~ s/\\/\\\\/g;
+ print("> cscript //nologo $cmd\n") if $verbose;
+ my $pid = open2(*CMD_OUT, *CMD_IN, "cscript //nologo $cmd");
+ binmode(*CMD_IN, ':encoding(utf16le)');
+ binmode(*CMD_OUT, ':encoding(utf16le)');
+ $SIG{INT} = sub { print(CMD_IN "QUIT\r\n"); panic_cleanup(); };
+ $SIG{KILL} = sub { print(CMD_IN "QUIT\r\n"); panic_cleanup(); };
+ print(CMD_IN "QUERY\tVENDOR\r\n");
+ my $vendor = readline(*CMD_OUT);
+ $vendor =~ s/\r\n//;
+ %ret = (%ret,
+ "stdin" => *CMD_IN,
+ "stdout" => *CMD_OUT,
+ "vendor" => $vendor);
}
return \%ret;
}
@@ -111,15 +109,13 @@ sub init_tts {
# Shutdown TTS engine if necessary.
sub shutdown_tts {
my ($tts_object) = @_;
- switch($$tts_object{"name"}) {
- case "festival" {
- # Send SIGTERM to festival server
- kill TERM => $$tts_object{"pid"};
- }
- case "sapi" {
- print({$$tts_object{"stdin"}} "QUIT\r\n");
- close($$tts_object{"stdin"});
- }
+ if ($$tts_object{'name'} eq 'festival') {
+ # Send SIGTERM to festival server
+ kill TERM => $$tts_object{"pid"};
+ }
+ elsif ($$tts_object{'name'} eq 'sapi') {
+ print({$$tts_object{"stdin"}} "QUIT\r\n");
+ close($$tts_object{"stdin"});
}
}
@@ -146,48 +142,47 @@ sub voicestring {
our $verbose;
my ($string, $output, $tts_engine_opts, $tts_object) = @_;
my $cmd;
- printf("Generate \"%s\" with %s in file %s\n", $string, $$tts_object{"name"}, $output) if $verbose;
- switch($$tts_object{"name"}) {
- case "festival" {
- # festival_client lies to us, so we have to do awful soul-eating
- # work with IPC::open3()
- $cmd = "festival_client --server localhost --otype riff --ttw --output \"$output\"";
- # Use festival-prolog.scm if it's there (created by user of tools/configure)
- if (-f "festival-prolog.scm") {
- $cmd .= " --prolog festival-prolog.scm";
- }
- print("> $cmd\n") if $verbose;
- # Open command, and filehandles for STDIN, STDOUT, STDERR
- my $pid = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, $cmd);
- # Put the string to speak into STDIN and close it
- print(CMD_IN $string);
- close(CMD_IN);
- # Read all output from festival_client (because it LIES TO US)
- while (<CMD_ERR>) {
- }
- close(CMD_OUT);
- close(CMD_ERR);
- }
- case "flite" {
- $cmd = "flite $tts_engine_opts -t \"$string\" \"$output\"";
- print("> $cmd\n") if $verbose;
- `$cmd`;
- }
- case "espeak" {
- $cmd = "espeak $tts_engine_opts -w \"$output\"";
- print("> $cmd\n") if $verbose;
- open(ESPEAK, "| $cmd");
- print ESPEAK $string . "\n";
- close(ESPEAK);
+ my $name = $$tts_object{'name'};
+ printf("Generate \"%s\" with %s in file %s\n", $string, $name, $output) if $verbose;
+ if ($name eq 'festival') {
+ # festival_client lies to us, so we have to do awful soul-eating
+ # work with IPC::open3()
+ $cmd = "festival_client --server localhost --otype riff --ttw --output \"$output\"";
+ # Use festival-prolog.scm if it's there (created by user of tools/configure)
+ if (-f "festival-prolog.scm") {
+ $cmd .= " --prolog festival-prolog.scm";
}
- case "sapi" {
- print({$$tts_object{"stdin"}} "SPEAK\t$output\t$string\r\n");
- }
- case "swift" {
- $cmd = "swift $tts_engine_opts -o \"$output\" \"$string\"";
- print("> $cmd\n") if $verbose;
- system($cmd);
+ print("> $cmd\n") if $verbose;
+ # Open command, and filehandles for STDIN, STDOUT, STDERR
+ my $pid = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, $cmd);
+ # Put the string to speak into STDIN and close it
+ print(CMD_IN $string);
+ close(CMD_IN);
+ # Read all output from festival_client (because it LIES TO US)
+ while (<CMD_ERR>) {
}
+ close(CMD_OUT);
+ close(CMD_ERR);
+ }
+ elsif ($name eq 'flite') {
+ $cmd = "flite $tts_engine_opts -t \"$string\" \"$output\"";
+ print("> $cmd\n") if $verbose;
+ `$cmd`;
+ }
+ elsif ($name eq 'espeak') {
+ $cmd = "espeak $tts_engine_opts -w \"$output\"";
+ print("> $cmd\n") if $verbose;
+ open(ESPEAK, "| $cmd");
+ print ESPEAK $string . "\n";
+ close(ESPEAK);
+ }
+ elsif ($name eq 'sapi') {
+ print({$$tts_object{"stdin"}} "SPEAK\t$output\t$string\r\n");
+ }
+ elsif ($name eq 'swift') {
+ $cmd = "swift $tts_engine_opts -o \"$output\" \"$string\"";
+ print("> $cmd\n") if $verbose;
+ system($cmd);
}
}