2 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
4 // Centre for Speech Technology Research \\
5 // University of Edinburgh, UK \\
6 // Copyright (c) 1996,1997 \\
7 // All Rights Reserved. \\
8 // Permission is hereby granted, free of charge, to use and distribute \\
9 // this software and its documentation without restriction, including \\
10 // without limitation the rights to use, copy, modify, merge, publish, \\
11 // distribute, sublicense, and/or sell copies of this work, and to \\
12 // permit persons to whom this work is furnished to do so, subject to \\
13 // the following conditions: \\
14 // 1. The code must retain the above copyright notice, this list of \\
15 // conditions and the following disclaimer. \\
16 // 2. Any modifications must be clearly marked as such. \\
17 // 3. Original authors' names are not deleted. \\
18 // 4. The authors' names are not used to endorse or promote products \\
19 // derived from this software without specific prior written \\
21 // THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK \\
22 // DISCLAIM ALL WARRANTIES With REGARD TO THIS SOFTWARE, INCLUDING \\
23 // ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT \\
24 // SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE \\
25 // FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES \\
26 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN \\
27 // AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, \\
28 // ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF \\
31 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
33 // Author: Richard Caley (rjc@cstr.ed.ac.uk) \\
34 // -------------------------------------------------------------------- \\
35 // Mainline for Java festival client. \\
37 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
39 package cstr.festival ;
47 import cstr.festival.client.*;
48 import cstr.festival.scheme.*;
50 class RequestHandler implements RequestListener
54 public RequestHandler(Thread main)
59 public void requestRunning(Request r)
61 System.out.println("Request "+r.command+" running");
64 public void requestResult(Request r, Object res)
66 System.out.println("Request "+r.command+" result="+res);
69 public void requestError(Request r, String mes)
71 System.out.println("Request "+r.command+" error "+mes);
74 public void requestFinished(Request r)
76 System.out.println("Request "+r.command+" finished");
82 public static void useage(String error)
86 System.out.println("");
87 System.out.println(" "+error);
89 System.out.println("");
90 System.out.println("Useage: festival_client_java [options] file...");
91 System.out.println("");
92 System.out.println(" --help Show this message.");
93 System.out.println(" --server <host> Connect to named host.");
94 System.out.println(" --port <portnum> Use the given port.");
95 System.out.println(" --sync Wait for each expression to finish");
96 System.out.println(" executing before reading next.");
97 System.out.println(" --wait Wait for all expressions to finish");
98 System.out.println(" executing before exiting.");
100 System.exit(error!=null?1:0);
103 public static void main (String[] args)
105 String server="localhost";
108 boolean waitAtEnd=false;
111 for(i=0; i<args.length; i++)
113 if (args[i].equals("--help"))
115 else if (args[i].equals("--server"))
119 useage("Need name after --server");
123 else if (args[i].equals("--port"))
127 useage("Need name after --server");
130 port = Integer.parseInt(args[i]);
131 } catch (NumberFormatException ex) {
132 useage("Not a valid port number '" + args[i] + "'");
136 else if (args[i].equals("--wait"))
138 else if (args[i].equals("--sync"))
140 else if (args[i].startsWith("--"))
141 useage("Unknown argument "+args[i]);
146 System.out.println("Server='"+server+":"+port+"'");
151 s = new Session(server, port);
152 } catch (UnknownHostException ex) {
153 useage("Unknown host '"+ex.getMessage()+"'");
154 } catch (IOException ex) {
155 useage("Can't connect '"+ex.getMessage()+"'");
160 System.out.println("Connected");
162 if (i == args.length)
164 args = new String[] { "-" };
168 RequestListener handler = new RequestHandler(Thread.currentThread());
171 for(; i<args.length; i++)
173 System.out.println(" '"+args[i]+"'");
175 String filename = args[i];
177 Reader reader = null;
180 if (filename.equals("-"))
181 reader = new InputStreamReader(System.in);
183 reader = new InputStreamReader(new FileInputStream(filename));
184 } catch (FileNotFoundException ex) {
185 useage("Can't open '"+ ex.getMessage() + "'");
188 ReflectingSchemeReader sreader = new ReflectingSchemeReader(reader);
194 if (filename.equals("-"))
196 System.out.print("> ");
200 exp=sreader.nextExprString();
205 System.out.println(": "+exp);
206 Request r = s.request(exp, handler);
208 while (!r.isFinished())
211 } catch (IOException ioex) {
212 System.out.println(" Error "+ioex.getMessage());
215 System.out.println("--EOF--");
218 System.out.println("call terminate");
219 s.terminate(waitAtEnd);