summaryrefslogtreecommitdiff
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 @@
1#!/usr/bin/perl 1#!/usr/bin/perl
2use Switch;
3use List::Util 'shuffle'; # standard from Perl 5.8 and later 2use List::Util 'shuffle'; # standard from Perl 5.8 and later
4 3
5my $tempfile = "multigcc.out"; 4my $tempfile = "multigcc.out";
@@ -26,23 +25,22 @@ my $command = join " ", @params;
26 25
27# count number of cores 26# count number of cores
28my $cores; 27my $cores;
29switch($^O) { 28# Don't use given/when here - it's not compatible with old perl versions
30 case "darwin" { 29if ($^O eq 'darwin') {
31 chomp($cores = `sysctl -n hw.ncpu`); 30 chomp($cores = `sysctl -n hw.ncpu`);
32 $cores = 1 if ($?); 31 $cores = 1 if ($?);
33 } 32}
34 case "solaris" { 33elsif ($^O eq 'solaris') {
35 $cores = scalar grep /on-line/i, `psrinfo`; 34 $cores = scalar grep /on-line/i, `psrinfo`;
36 $cores = 1 if ($?); 35 $cores = 1 if ($?);
36}
37else {
38 if (open CPUINFO, "</proc/cpuinfo") {
39 $cores = scalar grep /^processor/i, <CPUINFO>;
40 close CPUINFO;
37 } 41 }
38 else { 42 else {
39 if (open CPUINFO, "</proc/cpuinfo") { 43 $cores = 1;
40 $cores = scalar grep /^processor/i, <CPUINFO>;
41 close CPUINFO;
42 }
43 else {
44 $cores = 1;
45 }
46 } 44 }
47} 45}
48 46
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;
19use warnings; 19use warnings;
20use File::Basename; 20use File::Basename;
21use File::Copy; 21use File::Copy;
22use Switch;
23use vars qw($V $C $t $l $e $E $s $S $i $v); 22use vars qw($V $C $t $l $e $E $s $S $i $v);
24use IPC::Open2; 23use IPC::Open2;
25use IPC::Open3; 24use IPC::Open3;
@@ -74,36 +73,35 @@ sub init_tts {
74 our $verbose; 73 our $verbose;
75 my ($tts_engine, $tts_engine_opts, $language) = @_; 74 my ($tts_engine, $tts_engine_opts, $language) = @_;
76 my %ret = ("name" => $tts_engine); 75 my %ret = ("name" => $tts_engine);
77 switch($tts_engine) { 76 # Don't use given/when here - it's not compatible with old perl versions
78 case "festival" { 77 if ($tts_engine eq 'festival') {
79 print("> festival $tts_engine_opts --server\n") if $verbose; 78 print("> festival $tts_engine_opts --server\n") if $verbose;
80 my $pid = open(FESTIVAL_SERVER, "| festival $tts_engine_opts --server > /dev/null 2>&1"); 79 my $pid = open(FESTIVAL_SERVER, "| festival $tts_engine_opts --server > /dev/null 2>&1");
81 my $dummy = *FESTIVAL_SERVER; #suppress warning 80 my $dummy = *FESTIVAL_SERVER; #suppress warning
82 $SIG{INT} = sub { kill TERM => $pid; print("foo"); panic_cleanup(); }; 81 $SIG{INT} = sub { kill TERM => $pid; print("foo"); panic_cleanup(); };
83 $SIG{KILL} = sub { kill TERM => $pid; print("boo"); panic_cleanup(); }; 82 $SIG{KILL} = sub { kill TERM => $pid; print("boo"); panic_cleanup(); };
84 $ret{"pid"} = $pid; 83 $ret{"pid"} = $pid;
85 } 84 }
86 case "sapi" { 85 elsif ($tts_engine eq 'sapi') {
87 my $toolsdir = dirname($0); 86 my $toolsdir = dirname($0);
88 my $path = `cygpath $toolsdir -a -w`; 87 my $path = `cygpath $toolsdir -a -w`;
89 chomp($path); 88 chomp($path);
90 $path = $path . '\\'; 89 $path = $path . '\\';
91 my $cmd = $path . "sapi_voice.vbs /language:$language $tts_engine_opts"; 90 my $cmd = $path . "sapi_voice.vbs /language:$language $tts_engine_opts";
92 $cmd =~ s/\\/\\\\/g; 91 $cmd =~ s/\\/\\\\/g;
93 print("> cscript //nologo $cmd\n") if $verbose; 92 print("> cscript //nologo $cmd\n") if $verbose;
94 my $pid = open2(*CMD_OUT, *CMD_IN, "cscript //nologo $cmd"); 93 my $pid = open2(*CMD_OUT, *CMD_IN, "cscript //nologo $cmd");
95 binmode(*CMD_IN, ':encoding(utf16le)'); 94 binmode(*CMD_IN, ':encoding(utf16le)');
96 binmode(*CMD_OUT, ':encoding(utf16le)'); 95 binmode(*CMD_OUT, ':encoding(utf16le)');
97 $SIG{INT} = sub { print(CMD_IN "QUIT\r\n"); panic_cleanup(); }; 96 $SIG{INT} = sub { print(CMD_IN "QUIT\r\n"); panic_cleanup(); };
98 $SIG{KILL} = sub { print(CMD_IN "QUIT\r\n"); panic_cleanup(); }; 97 $SIG{KILL} = sub { print(CMD_IN "QUIT\r\n"); panic_cleanup(); };
99 print(CMD_IN "QUERY\tVENDOR\r\n"); 98 print(CMD_IN "QUERY\tVENDOR\r\n");
100 my $vendor = readline(*CMD_OUT); 99 my $vendor = readline(*CMD_OUT);
101 $vendor =~ s/\r\n//; 100 $vendor =~ s/\r\n//;
102 %ret = (%ret, 101 %ret = (%ret,
103 "stdin" => *CMD_IN, 102 "stdin" => *CMD_IN,
104 "stdout" => *CMD_OUT, 103 "stdout" => *CMD_OUT,
105 "vendor" => $vendor); 104 "vendor" => $vendor);
106 }
107 } 105 }
108 return \%ret; 106 return \%ret;
109} 107}
@@ -111,15 +109,13 @@ sub init_tts {
111# Shutdown TTS engine if necessary. 109# Shutdown TTS engine if necessary.
112sub shutdown_tts { 110sub shutdown_tts {
113 my ($tts_object) = @_; 111 my ($tts_object) = @_;
114 switch($$tts_object{"name"}) { 112 if ($$tts_object{'name'} eq 'festival') {
115 case "festival" { 113 # Send SIGTERM to festival server
116 # Send SIGTERM to festival server 114 kill TERM => $$tts_object{"pid"};
117 kill TERM => $$tts_object{"pid"}; 115 }
118 } 116 elsif ($$tts_object{'name'} eq 'sapi') {
119 case "sapi" { 117 print({$$tts_object{"stdin"}} "QUIT\r\n");
120 print({$$tts_object{"stdin"}} "QUIT\r\n"); 118 close($$tts_object{"stdin"});
121 close($$tts_object{"stdin"});
122 }
123 } 119 }
124} 120}
125 121
@@ -146,48 +142,47 @@ sub voicestring {
146 our $verbose; 142 our $verbose;
147 my ($string, $output, $tts_engine_opts, $tts_object) = @_; 143 my ($string, $output, $tts_engine_opts, $tts_object) = @_;
148 my $cmd; 144 my $cmd;
149 printf("Generate \"%s\" with %s in file %s\n", $string, $$tts_object{"name"}, $output) if $verbose; 145 my $name = $$tts_object{'name'};
150 switch($$tts_object{"name"}) { 146 printf("Generate \"%s\" with %s in file %s\n", $string, $name, $output) if $verbose;
151 case "festival" { 147 if ($name eq 'festival') {
152 # festival_client lies to us, so we have to do awful soul-eating 148 # festival_client lies to us, so we have to do awful soul-eating
153 # work with IPC::open3() 149 # work with IPC::open3()
154 $cmd = "festival_client --server localhost --otype riff --ttw --output \"$output\""; 150 $cmd = "festival_client --server localhost --otype riff --ttw --output \"$output\"";
155 # Use festival-prolog.scm if it's there (created by user of tools/configure) 151 # Use festival-prolog.scm if it's there (created by user of tools/configure)
156 if (-f "festival-prolog.scm") { 152 if (-f "festival-prolog.scm") {
157 $cmd .= " --prolog festival-prolog.scm"; 153 $cmd .= " --prolog festival-prolog.scm";
158 }
159 print("> $cmd\n") if $verbose;
160 # Open command, and filehandles for STDIN, STDOUT, STDERR
161 my $pid = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, $cmd);
162 # Put the string to speak into STDIN and close it
163 print(CMD_IN $string);
164 close(CMD_IN);
165 # Read all output from festival_client (because it LIES TO US)
166 while (<CMD_ERR>) {
167 }
168 close(CMD_OUT);
169 close(CMD_ERR);
170 }
171 case "flite" {
172 $cmd = "flite $tts_engine_opts -t \"$string\" \"$output\"";
173 print("> $cmd\n") if $verbose;
174 `$cmd`;
175 }
176 case "espeak" {
177 $cmd = "espeak $tts_engine_opts -w \"$output\"";
178 print("> $cmd\n") if $verbose;
179 open(ESPEAK, "| $cmd");
180 print ESPEAK $string . "\n";
181 close(ESPEAK);
182 } 154 }
183 case "sapi" { 155 print("> $cmd\n") if $verbose;
184 print({$$tts_object{"stdin"}} "SPEAK\t$output\t$string\r\n"); 156 # Open command, and filehandles for STDIN, STDOUT, STDERR
185 } 157 my $pid = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, $cmd);
186 case "swift" { 158 # Put the string to speak into STDIN and close it
187 $cmd = "swift $tts_engine_opts -o \"$output\" \"$string\""; 159 print(CMD_IN $string);
188 print("> $cmd\n") if $verbose; 160 close(CMD_IN);
189 system($cmd); 161 # Read all output from festival_client (because it LIES TO US)
162 while (<CMD_ERR>) {
190 } 163 }
164 close(CMD_OUT);
165 close(CMD_ERR);
166 }
167 elsif ($name eq 'flite') {
168 $cmd = "flite $tts_engine_opts -t \"$string\" \"$output\"";
169 print("> $cmd\n") if $verbose;
170 `$cmd`;
171 }
172 elsif ($name eq 'espeak') {
173 $cmd = "espeak $tts_engine_opts -w \"$output\"";
174 print("> $cmd\n") if $verbose;
175 open(ESPEAK, "| $cmd");
176 print ESPEAK $string . "\n";
177 close(ESPEAK);
178 }
179 elsif ($name eq 'sapi') {
180 print({$$tts_object{"stdin"}} "SPEAK\t$output\t$string\r\n");
181 }
182 elsif ($name eq 'swift') {
183 $cmd = "swift $tts_engine_opts -o \"$output\" \"$string\"";
184 print("> $cmd\n") if $verbose;
185 system($cmd);
191 } 186 }
192} 187}
193 188