line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Festival::Client; |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Perl interface to the Festival server |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# The basis for this code came from the festival_client.pl program by |
6
|
|
|
|
|
|
|
# Kevin A. Lenzo (lenzo@cs.cmu.edu) which comes with the Festival |
7
|
|
|
|
|
|
|
# distribution. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Last updated by gossamer on Thu May 21 16:11:24 EST 1998 |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
1030
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
38
|
|
13
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
146
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
require Exporter; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
1001
|
use Symbol; |
|
1
|
|
|
|
|
1220
|
|
|
1
|
|
|
|
|
76
|
|
18
|
1
|
|
|
1
|
|
5
|
use Fcntl; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
316
|
|
19
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
74
|
|
20
|
1
|
|
|
1
|
|
1012
|
use IO::Socket; |
|
1
|
|
|
|
|
27585
|
|
|
1
|
|
|
|
|
6
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
require 'dumpvar.pl'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
25
|
|
|
|
|
|
|
@EXPORT = qw( Default_Client_PORT ); |
26
|
|
|
|
|
|
|
@EXPORT_OK = qw(); |
27
|
|
|
|
|
|
|
$VERSION = "1.0"; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 NAME |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Festival::Client - Communicate with a Festival server |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SYNOPSIS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use Festival::Client; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$Festival = Festival::Client->New("my.festival.server"); |
38
|
|
|
|
|
|
|
$Festival->say("Something to say"); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 DESCRIPTION |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
C is a class implementing a simple Festival client in |
43
|
|
|
|
|
|
|
Perl. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
################################################################### |
48
|
|
|
|
|
|
|
# Some constants # |
49
|
|
|
|
|
|
|
################################################################### |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $Default_Festival_Port = 1314; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $Client_Info = "0.01"; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $DEBUG = 0; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
################################################################### |
58
|
|
|
|
|
|
|
# Functions under here are member functions # |
59
|
|
|
|
|
|
|
################################################################### |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item new ( [ HOST [, PORT ] ] ) |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
This is the constructor for a new Festival object. C is the |
66
|
|
|
|
|
|
|
name of the remote host to which a Festival connection is required. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
C is the Festival port to connect to, it defaults to the |
69
|
|
|
|
|
|
|
standard port 1314 if nothing else is found. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
The constructor returns the open socket, or C if an error has |
72
|
|
|
|
|
|
|
been encountered. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub new { |
77
|
1
|
|
|
1
|
1
|
53
|
my $prototype = shift; |
78
|
1
|
|
|
|
|
2
|
my $host = shift; |
79
|
1
|
|
|
|
|
3
|
my $port = shift; |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
33
|
|
|
8
|
my $class = ref($prototype) || $prototype; |
82
|
1
|
|
|
|
|
3
|
my $self = {}; |
83
|
|
|
|
|
|
|
|
84
|
1
|
50
|
|
|
|
5
|
warn "new\n" if $DEBUG > 1; |
85
|
|
|
|
|
|
|
|
86
|
1
|
|
0
|
|
|
6
|
$self->{"host"} = $host || $ENV{HWHOST} || $ENV{HGHOST} || 'localhost'; |
87
|
1
|
|
33
|
|
|
20
|
$self->{"port"} = $port || $ENV{HWPORT} || $ENV{HGPORT} || $Default_Festival_Port; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# |
90
|
|
|
|
|
|
|
# Resolve things and open the connection |
91
|
|
|
|
|
|
|
# |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Deal with a port specified from /etc/services list |
94
|
1
|
50
|
|
|
|
8
|
if ($self->{"port"} =~ /\D/) { |
95
|
0
|
|
|
|
|
0
|
$self->{"port"} = getservbyname($self->{"port"}, 'tcp'); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
1
|
50
|
|
|
|
3
|
print "Addr: " . $self->{"host"} . ", Port: " . $self->{"port"} . "\n" if $DEBUG; |
99
|
1
|
|
|
|
|
13
|
$self->{"socket"} = new IO::Socket::INET ( |
100
|
|
|
|
|
|
|
Proto => "tcp", |
101
|
|
|
|
|
|
|
PeerAddr => $self->{"host"}, |
102
|
|
|
|
|
|
|
PeerPort => $self->{"port"}, |
103
|
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#croak "new: connect socket: $!" unless $self->{"socket"}; |
106
|
1
|
50
|
|
|
|
1452
|
return 0 unless $self->{"socket"}; |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
bless($self, $class); |
109
|
0
|
|
|
|
|
|
return $self; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# |
114
|
|
|
|
|
|
|
# destructor |
115
|
|
|
|
|
|
|
# |
116
|
|
|
|
|
|
|
sub DESTROY { |
117
|
0
|
|
|
0
|
|
|
my $self = shift; |
118
|
|
|
|
|
|
|
|
119
|
0
|
0
|
|
|
|
|
warn "DESTROY\n" if $DEBUG > 1; |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
shutdown($self->{"socket"}, 2); |
122
|
0
|
|
|
|
|
|
close($self->{"socket"}); |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
return 1; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 SAY ( TEXT ) |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
The obvious. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub say { |
135
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
136
|
0
|
|
|
|
|
|
my $text = shift; |
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
warn "say \"$text\"\n" if $DEBUG > 1; |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
my $buffer = "(SayText \"$text\")\n"; |
141
|
|
|
|
|
|
|
|
142
|
0
|
0
|
|
|
|
|
if (!defined(syswrite($self->{"socket"}, $buffer, length($buffer)))) { |
143
|
0
|
|
|
|
|
|
warn "syswrite: $!"; |
144
|
0
|
|
|
|
|
|
return 0; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
return 1; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=pod |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 AUTHOR |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Bek Oberin |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 COPYRIGHT |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Copyright (c) 1998 Bek Oberin. All rights reserved. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
162
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# |
167
|
|
|
|
|
|
|
# End code. |
168
|
|
|
|
|
|
|
# |
169
|
|
|
|
|
|
|
1; |