Edinburgh Speech Tools 2.4-release
siod_main.cc
1/*************************************************************************/
2/* */
3/* Centre for Speech Technology Research */
4/* University of Edinburgh, UK */
5/* Copyright (c) 1999 */
6/* All Rights Reserved. */
7/* */
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 */
20/* permission. */
21/* */
22/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30/* THIS SOFTWARE. */
31/* */
32/*************************************************************************/
33/* Authors: Alan W Black */
34/* Date : February 1999 */
35/*-----------------------------------------------------------------------*/
36/* A simple wrap-around for SIOD giving a basic command line SIOD */
37/* interpreter */
38/* */
39/*=======================================================================*/
40#include <cstdlib>
41#include "EST_cmd_line.h"
42#include "EST_cutils.h"
43#include "EST_Pathname.h"
44#include "siod.h"
45
46static void siod_lisp_vars(void);
47static void siod_load_default_files(void);
48
49/** @name <command>siod</command> <emphasis>Scheme Interpreter</emphasis>
50 @id siod-manual
51 * @toc
52 */
53
54//@{
55
56
57/**@name Synopsis
58 */
59//@{
60
61//@synopsis
62
63/**
64
65 <command>siod</command> is a command line interface to the
66 <productname>Scheme In One Defun</productname> Scheme interpreter,
67 as modified by CSTR for use in &theEST;. It is essentially &festival;
68 without the speech synthesis code.
69
70 */
71
72//@}
73
74/**@name OPTIONS
75 */
76//@{
77
78//@options
79
80//@}
81
82
83int main(int argc, char **argv)
84{
85 EST_Option al;
86 EST_StrList files;
87 EST_Litem *p;
88 int stdin_input,interactive;
89 int heap_size = DEFAULT_HEAP_SIZE;
90
91 parse_command_line
92 (argc, argv,
93 EST_String("[options] [input files]\n")+
94 "Summary: Scheme in one Defun interpreter, file arguments are loaded\n"+
95 "-b Run in batch mode (no interaction)\n"+
96 "--batch Run in batch mode (no interaction)\n"+
97 "-i Run in interactive mode (default)\n"+
98 "--interactive\n"+
99 " Run in interactive mode (default)\n"+
100 "--pipe Run in pipe mode, reading commands from\n"+
101 " stdin, but no prompt or return values\n"+
102 " are printed (default if stdin not a tty)\n"+
103 "-heap <int> {512000}\n"+
104 " Initial size of heap\n",
105 files, al);
106
107 if (al.present("-heap"))
108 heap_size = al.ival("-heap");
109
110 // What to do about standard input and producing prompts etc.
111 if ((al.present("-i")) || (al.present("--interactive")))
112 {
113 interactive = TRUE;
114 stdin_input = TRUE;
115 }
116 else if ((al.present("--pipe")))
117 {
118 interactive=FALSE;
119 stdin_input = TRUE;
120 }
121 else if ((al.present("-b")) || (al.present("--batch")))
122 {
123 interactive=FALSE;
124 stdin_input=FALSE;
125 }
126 else if (isatty(0)) // if stdin is a terminal assume interactive
127 {
128 interactive = TRUE;
129 stdin_input = TRUE;
130 }
131 else // else assume pipe mode
132 {
133 interactive = FALSE;
134 stdin_input = TRUE;
135 }
136
137 siod_init(heap_size);
138 siod_est_init();
139 /* siod_server_init();
140 siod_fringe_init(); */
141
142 siod_prog_name = "siod";
143
144 siod_lisp_vars();
145
146 if (interactive)
147 siod_load_default_files();
148
149 for (p=files.head(); p != 0; p=p->next())
150 {
151 if (files(p) == "-")
152 continue;
153 else if (files(p).matches(make_regex("^(.*")))
154 {
155 LISP l;
156 l = read_from_string(files(p));
157 leval(l,NIL);
158 }
159 else
160 vload(files(p),0);
161
162 }
163
164 if (stdin_input)
165 {
166 siod_print_welcome(EST_String::cat("Modified for ", est_name, " v", est_tools_version));
167 siod_repl(interactive); // expect input from stdin
168 }
169
170 return 0;
171}
172
173static void siod_load_default_files(void)
174{
175 // Load in default files, init.scm. Users ~/.festivalrc
176 // (or whatever you wish to call it) is loaded by init.scm
177
178 EST_Pathname initfile;
179
180 // Load library init first
181 initfile = EST_Pathname(est_datadir).as_directory();
182 initfile += "siod";
183 initfile += "init.scm";
184
185 if (access((const char *)initfile,R_OK) == 0)
186 vload(initfile,FALSE);
187 else
188 cerr << "Initialization file " << initfile << " not found" << endl;
189}
190
191static void siod_lisp_vars(void)
192{
193 // set up specific lisp variables
194 int major=0,minor=0,subminor=0;
195
196 EST_Pathname lib;
197
198 lib = EST_Pathname(est_libdir).as_directory();
199 lib += "siod";
200 siod_set_lval("libdir",strintern(lib));
201
202 lib = EST_Pathname(est_datadir).as_directory();
203 lib += "siod";
204 siod_set_lval("datadir",strintern(lib));
205
206 if (!strcmp(est_ostype,""))
207 siod_set_lval("*ostype*",rintern(est_ostype));
208 siod_set_lval("est_version",
209 strcons(strlen(est_tools_version),est_tools_version));
210
211 EST_String bits[4];
212 EST_Regex sep = "[^0-9]+";
213 int nbits = split(est_tools_version, bits, 4, sep);
214
215 if (nbits>0)
216 major = bits[0].Int();
217 if (nbits>1)
218 minor = bits[1].Int();
219 if (nbits>2)
220 subminor = bits[2].Int();
221
222 siod_set_lval("est_version_number",
223 cons(flocons(major),
224 cons(flocons(minor),
225 cons(flocons(subminor),NIL))));
226
227 // Modify my PATH to include these directories
228 EST_String path = getenv("PATH");
229
230 path += ":" + EST_String(est_libdir);
231
232 putenv(wstrdup("PATH=" + path));
233
234 siod_set_lval("*modules*",NIL);
235
236 return;
237}
238
int ival(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:76
static EST_String cat(const EST_String s1, const EST_String s2=Empty, const EST_String s3=Empty, const EST_String s4=Empty, const EST_String s5=Empty, const EST_String s6=Empty, const EST_String s7=Empty, const EST_String s8=Empty, const EST_String s9=Empty)
Definition: EST_String.cc:1096
const int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222