diff options
author | Thomas Jarosch <tomj@simonv.com> | 2011-08-16 19:26:24 +0000 |
---|---|---|
committer | Thomas Jarosch <tomj@simonv.com> | 2011-08-16 19:26:24 +0000 |
commit | 121b26e62fb0bb045dc7926b0b5cdfc4d2d2a0d4 (patch) | |
tree | 6fc264d2ae53b01da0c84cc7371711860b1c23a8 | |
parent | 2e154df92fd86ab90f300a52561a5a192f6c7b96 (diff) | |
download | rockbox-121b26e62fb0bb045dc7926b0b5cdfc4d2d2a0d4.tar.gz rockbox-121b26e62fb0bb045dc7926b0b5cdfc4d2d2a0d4.zip |
perl magic: Use if/elsif/else instead of given/when (FS #12188)
Unbreaks the maemo build.
Patch by Nick Peskett with a small comment added
as suggested by Dominik Riebeling.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30323 a1c6a512-1295-4272-9138-f99709370657
-rwxr-xr-x | tools/multigcc.pl | 32 | ||||
-rwxr-xr-x | tools/voice.pl | 155 |
2 files changed, 90 insertions, 97 deletions
diff --git a/tools/multigcc.pl b/tools/multigcc.pl index e263638d9d..c272ebae08 100755 --- a/tools/multigcc.pl +++ b/tools/multigcc.pl | |||
@@ -1,5 +1,4 @@ | |||
1 | #!/usr/bin/perl | 1 | #!/usr/bin/perl |
2 | use feature "switch"; | ||
3 | use List::Util 'shuffle'; # standard from Perl 5.8 and later | 2 | use List::Util 'shuffle'; # standard from Perl 5.8 and later |
4 | 3 | ||
5 | my $tempfile = "multigcc.out"; | 4 | my $tempfile = "multigcc.out"; |
@@ -26,23 +25,22 @@ my $command = join " ", @params; | |||
26 | 25 | ||
27 | # count number of cores | 26 | # count number of cores |
28 | my $cores; | 27 | my $cores; |
29 | given ($^O) { | 28 | # Don't use given/when here - it's not compatible with old perl versions |
30 | when ("darwin") { | 29 | if ($^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 | when ("solaris") { | 33 | elsif ($^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 | } | ||
37 | else { | ||
38 | if (open CPUINFO, "</proc/cpuinfo") { | ||
39 | $cores = scalar grep /^processor/i, <CPUINFO>; | ||
40 | close CPUINFO; | ||
37 | } | 41 | } |
38 | default { | 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 9c528299b9..f74791babb 100755 --- a/tools/voice.pl +++ b/tools/voice.pl | |||
@@ -17,7 +17,6 @@ | |||
17 | 17 | ||
18 | use strict; | 18 | use strict; |
19 | use warnings; | 19 | use warnings; |
20 | use feature 'switch'; | ||
21 | use File::Basename; | 20 | use File::Basename; |
22 | use File::Copy; | 21 | use File::Copy; |
23 | use vars qw($V $C $t $l $e $E $s $S $i $v); | 22 | use vars qw($V $C $t $l $e $E $s $S $i $v); |
@@ -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 | given ($tts_engine) { | 76 | # Don't use given/when here - it's not compatible with old perl versions |
78 | when ("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 | when ("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. |
112 | sub shutdown_tts { | 110 | sub shutdown_tts { |
113 | my ($tts_object) = @_; | 111 | my ($tts_object) = @_; |
114 | given ($$tts_object{"name"}) { | 112 | if ($$tts_object{'name'} eq 'festival') { |
115 | when ("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 | when ("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 | given ($$tts_object{"name"}) { | 146 | printf("Generate \"%s\" with %s in file %s\n", $string, $name, $output) if $verbose; |
151 | when ("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 | when ("flite") { | ||
172 | $cmd = "flite $tts_engine_opts -t \"$string\" \"$output\""; | ||
173 | print("> $cmd\n") if $verbose; | ||
174 | `$cmd`; | ||
175 | } | ||
176 | when ("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 | when ("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 | when ("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 | ||