1 /*
2 * $Id: prologue.c,v 1.2 2001/06/14 18:16:13 ura Exp $
3 */
4
5 /*
6 * FreeWnn is a network-extensible Kana-to-Kanji conversion system.
7 * This file is part of FreeWnn.
8 *
9 * Copyright Kyoto University Research Institute for Mathematical Sciences
10 * 1987, 1988, 1989, 1990, 1991, 1992
11 * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999
12 * Copyright ASTEC, Inc. 1987, 1988, 1989, 1990, 1991, 1992
13 * Copyright 1991, 1992 by Massachusetts Institute of Technology
14 *
15 * Author: OMRON SOFTWARE Co., Ltd. <freewnn@rd.kyoto.omronsoft.co.jp>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
20 * any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with GNU Emacs; see the file COPYING. If not, write to the
29 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 *
31 * Commentary:
32 *
33 * Change log:
34 *
35 * Last modified date: 8,Feb.1999
36 *
37 * Code:
38 *
39 */
40 /* Version 4.0
41 */
42 /* Standard Interface
43 * Initialize Routine
44 */
45
46 #include <stdio.h>
47 #include "jslib.h"
48 #include "jd_sock.h"
49 #include "commonhd.h"
50 #include "config.h"
51 #include "sdefine.h"
52 #include "xjutil.h"
53 #include "sxheader.h"
54 #include "rk_spclval.h"
55 #include "rk_fundecl.h"
56 #include "xext.h"
57
58 extern char *getenv ();
59 extern FILE *fopen ();
60
61 int
open_romkan()62 open_romkan ()
63 {
64 int rk_option_flg;
65 extern int keyin ();
66
67 if (rkfile_name == NULL)
68 return (-1);
69 cur_rk_table = romkan_table_init (NULL, rkfile_name, NULL, bytcntfn, NULL, 0);
70 rk_option_flg = RK_REDRAW | RK_CHMOUT | (excellent_delete ? 0 : RK_SIMPLD);
71
72 cur_rk = (Romkan *) romkan_init5 (rubout_code, rk_option_flg);
73 if (cur_rk == NULL)
74 {
75 return (-1);
76 }
77 else
78 {
79 return (0);
80 }
81 }
82
83 static int
allocate_areas()84 allocate_areas ()
85 {
86 char *area_start;
87 char *area_pter;
88
89 int k;
90 int total_size;
91 int len1 = maxchg * sizeof (w_char);
92 int return_buf_len = len1 * 7;
93
94 total_size = return_buf_len + len1 * 3 + maxbunsetsu * sizeof (int) * 3;
95
96 if ((area_start = (char *) Malloc (total_size)) == NULL)
97 {
98 malloc_error ("allocation of Wnn's area");
99 return (-1);
100 }
101
102 area_pter = area_start;
103 return_buf = (w_char *) area_pter;
104 area_pter += return_buf_len;
105 input_buffer = (w_char *) area_pter;
106 area_pter += len1;
107 kill_buffer = (w_char *) area_pter;
108 area_pter += len1;
109 remember_buf = (w_char *) area_pter;
110 *remember_buf = 0;
111 area_pter += len1;
112 bunsetsu = (int *) area_pter;
113 area_pter += maxbunsetsu * sizeof (int);
114 bunsetsuend = (int *) area_pter;
115 area_pter += maxbunsetsu * sizeof (struct wnn_env *);
116 touroku_bnst = (int *) area_pter;
117 area_pter += maxbunsetsu * sizeof (int);
118 for (k = 0; k < maxbunsetsu; k++)
119 {
120 bunsetsu[k] = 0;
121 bunsetsuend[k] = 0;
122 touroku_bnst[k] = 0;
123 }
124
125 return (0);
126 }
127
128 int
init_wnn()129 init_wnn ()
130 {
131 if (init_key_table (xjutil->lang) == -1)
132 {
133 return (-1);
134 }
135
136 if (open_romkan () == -1)
137 {
138 return (-1);
139 }
140
141 if (allocate_areas () == -1)
142 {
143 return (-1);
144 }
145 return (0);
146 }
147
148 typedef struct _js_list_str
149 {
150 WNN_JSERVER_ID *js;
151 char *host_name;
152 struct _js_list_str *next;
153 }
154 js_list_str;
155
156 static js_list_str *js_list = NULL;
157
158 static WNN_JSERVER_ID *
find_same_js(host_name)159 find_same_js (host_name)
160 char *host_name;
161 {
162 js_list_str *j;
163
164 if (!host_name || !*host_name)
165 {
166 for (j = js_list; j; j = j->next)
167 {
168 if (js_list->host_name == NULL)
169 return (js_list->js);
170 }
171 return (NULL);
172 }
173 else
174 {
175 for (j = js_list; j; j = j->next)
176 {
177 if (!strcmp (js_list->host_name, host_name))
178 return (js_list->js);
179 }
180 return (NULL);
181 }
182 }
183
184 static int
add_same_js(js,host_name)185 add_same_js (js, host_name)
186 WNN_JSERVER_ID *js;
187 char *host_name;
188 {
189 js_list_str *j;
190
191 if (!(j = (js_list_str *) Malloc (sizeof (js_list_str))))
192 return (-1);
193 j->js = js;
194 j->host_name = host_name;
195 j->next = js_list;
196 js_list = j;
197 return (0);
198 }
199
200 int
connect_server()201 connect_server ()
202 {
203 register WNN_JSERVER_ID *js = NULL;
204 char *machine_n;
205 WnnEnv *p;
206 int i;
207 char environment[PATHNAMELEN];
208 extern char *_wnn_get_machine_of_serv_defs ();
209
210 for (i = 0, p = normal_env; p; p = p->next, i++)
211 {
212 cur_normal_env = p;
213 js = NULL;
214 if (!p->host_name || !*p->host_name)
215 {
216 if (machine_n = _wnn_get_machine_of_serv_defs (xjutil->lang))
217 {
218 p->host_name = alloc_and_copy (machine_n);
219 if (js = find_same_js (p->host_name))
220 goto NEXT_STEP1;
221 if ((js = js_open_lang (p->host_name, xjutil->lang, WNN_TIMEOUT)) == NULL)
222 {
223 p->host_name = NULL;
224 }
225 }
226 if (!p->host_name || !*p->host_name)
227 {
228 p->host_name = alloc_and_copy ("unix");
229 }
230 }
231 if (js = find_same_js (p->host_name))
232 goto NEXT_STEP1;
233 if (js == NULL)
234 {
235 if ((js = js_open_lang (p->host_name, xjutil->lang, WNN_TIMEOUT)) == NULL)
236 {
237 return (-1);
238 }
239 }
240 add_same_js (js, p->host_name);
241 NEXT_STEP1:
242 environment[0] = '\0';
243 strcpy (environment, username);
244 strcat (environment, p->env_name_str);
245 if ((p->env = js_connect_lang (js, environment, xjutil->lang)) == NULL)
246 {
247 return (-1);
248 }
249 save_env_id[i] = p->env->env_id;
250 }
251 for (i = 0, p = reverse_env; p; p = p->next, i++)
252 {
253 cur_reverse_env = p;
254 js = NULL;
255 if (!p->host_name || !*p->host_name)
256 {
257 if (machine_n = _wnn_get_machine_of_serv_defs (xjutil->lang))
258 {
259 p->host_name = alloc_and_copy (machine_n);
260 if (js = find_same_js (p->host_name))
261 goto NEXT_STEP2;
262 if ((js = js_open_lang (p->host_name, xjutil->lang, WNN_TIMEOUT)) == NULL)
263 {
264 p->host_name = NULL;
265 }
266 }
267 if (!p->host_name || !*p->host_name)
268 {
269 p->host_name = alloc_and_copy ("unix");
270 }
271 }
272 if (js = find_same_js (p->host_name))
273 goto NEXT_STEP2;
274 if (js == NULL)
275 {
276 if ((js = js_open_lang (p->host_name, xjutil->lang, WNN_TIMEOUT)) == NULL)
277 {
278 return (-1);
279 }
280 }
281 add_same_js (js, p->host_name);
282 NEXT_STEP2:
283 environment[0] = '\0';
284 strcpy (environment, username);
285 strcat (environment, p->env_name_str);
286 if ((p->env = js_connect_lang (js, environment, xjutil->lang)) == NULL)
287 {
288 return (-1);
289 }
290 save_env_id[i] = p->env->env_id;
291 }
292 return (0);
293 }
294
295 int
init_xcvtkey()296 init_xcvtkey ()
297 {
298 int ret;
299
300 cvt_key_tbl_cnt = 0;
301 /* Backward compatibility for cvt_meta and cvt_fun. */
302 if (cvt_fun_file && *cvt_fun_file)
303 {
304 if ((ret = cvt_meta_and_fun_setup (cvt_fun_file, cvt_key_tbl)) == -1)
305 {
306 fprintf (stderr, "File \"%s\" can't open.", cvt_fun_file);
307 }
308 else
309 {
310 cvt_key_tbl_cnt = ret;
311 }
312 }
313 if (cvt_meta_file && *cvt_meta_file)
314 {
315 if ((ret = cvt_meta_and_fun_setup (cvt_meta_file, cvt_key_tbl)) == -1)
316 {
317 fprintf (stderr, "File \"%s\" can't open.", cvt_meta_file);
318 }
319 else
320 {
321 cvt_key_tbl_cnt = ret;
322 }
323 }
324 if (cvt_key_file && *cvt_key_file)
325 {
326 if (cvt_key_setup (cvt_key_file) == -1)
327 {
328 fprintf (stderr, "File \"%s\" can't open.", cvt_key_file);
329 }
330 }
331 return (0);
332 }
333