0
|
1 /*
|
|
2 * $Id: prologue.c,v 1.2 2001/06/14 18:16:17 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 "commonhd.h"
|
|
48 #include "config.h"
|
|
49 #include "sdefine.h"
|
|
50 #include <X11/Xos.h>
|
|
51 #include "xim.h"
|
|
52 #include "sheader.h"
|
|
53 #include "ext.h"
|
|
54 #include "rk_spclval.h"
|
|
55 #include "rk_fundecl.h"
|
|
56
|
|
57 extern char *getenv ();
|
|
58 extern FILE *fopen ();
|
|
59
|
|
60 /** Initialize of romkan */
|
|
61 int
|
|
62 open_romkan (ld)
|
|
63 XIMLangDataBase *ld;
|
|
64 {
|
|
65 int rk_option_flg;
|
|
66
|
|
67 rk_option_flg = RK_REDRAW | RK_CHMOUT | (excellent_delete ? 0 : RK_SIMPLD);
|
|
68
|
|
69 if (ld->rk_table == NULL)
|
|
70 {
|
|
71 if ((ld->rk_table = romkan_table_init (NULL, ld->rkfile_name, NULL, bytcntfn, NULL, 0))
|
|
72 /*
|
|
73 bytcntfn, letterpickfn, NULL, 0))
|
|
74 */
|
|
75 == NULL)
|
|
76 {
|
|
77 return (-1);
|
|
78 }
|
|
79 }
|
|
80 cur_rk_table = ld->rk_table;
|
|
81 c_c->rk = (Romkan *) romkan_init5 (rubout_code, rk_option_flg);
|
|
82 if (c_c->rk == NULL)
|
|
83 return (-1);
|
|
84 else
|
|
85 {
|
|
86 c_c->rk->rk_table = cur_rk_table;
|
|
87 return (0);
|
|
88 }
|
|
89 }
|
|
90
|
|
91
|
|
92
|
|
93 /** Open the wnnenvrc_R file */
|
|
94 static int
|
|
95 get_envrc_name_reverse (str, lang)
|
|
96 char *str, *lang;
|
|
97 {
|
|
98 extern int access ();
|
|
99
|
|
100 if (c_c->cur_reverse_env == NULL || reverse_envrcname == NULL || reverse_envrcname[0] == '\0')
|
|
101 return (0);
|
|
102 strcpy (str, reverse_envrcname);
|
|
103 if (access (str, R_OK) == -1)
|
|
104 {
|
|
105 return (-1);
|
|
106 }
|
|
107 return (1);
|
|
108 }
|
|
109
|
|
110 /** Open the wnnenvrc file */
|
|
111 static int
|
|
112 get_envrc_name (str, lang)
|
|
113 char *str, *lang;
|
|
114 {
|
|
115 if (c_c->cur_normal_env == NULL || envrcname == NULL || envrcname[0] == '\0')
|
|
116 {
|
|
117 strcpy (str, LIBDIR);
|
|
118 strcat (str, "/");
|
|
119 strcat (str, lang);
|
|
120 strcat (str, ENVRCFILE);
|
|
121 }
|
|
122 else
|
|
123 {
|
|
124 strcpy (str, envrcname);
|
|
125 }
|
|
126 return (1);
|
|
127 }
|
|
128
|
|
129 /* Allocate of Wnn Area */
|
|
130 int
|
|
131 allocate_areas ()
|
|
132 {
|
|
133 char *area_start;
|
|
134 char *area_pter;
|
|
135
|
|
136 int k;
|
|
137 int total_size;
|
|
138 int len1 = maxchg * sizeof (w_char);
|
|
139 int return_buf_len = len1 * 7;
|
|
140
|
|
141 total_size = return_buf_len + len1 * 3 + maxbunsetsu * sizeof (int) * 3 + maxbunsetsu * sizeof (struct wnn_env *);
|
|
142
|
|
143 if ((area_start = Malloc (total_size)) == NULL)
|
|
144 {
|
|
145 malloc_error ("allocation of Wnn's area");
|
|
146 return (-1);
|
|
147 }
|
|
148
|
|
149 area_pter = area_start;
|
|
150 return_buf = (w_char *) area_pter;
|
|
151 area_pter += return_buf_len;
|
|
152 input_buffer = (w_char *) area_pter;
|
|
153 area_pter += len1;
|
|
154 kill_buffer = (w_char *) area_pter;
|
|
155 area_pter += len1;
|
|
156 remember_buf = (w_char *) area_pter;
|
|
157 *remember_buf = 0;
|
|
158 area_pter += len1;
|
|
159
|
|
160 bunsetsu = (int *) area_pter;
|
|
161 area_pter += maxbunsetsu * sizeof (int);
|
|
162 bunsetsuend = (int *) area_pter;
|
|
163 area_pter += maxbunsetsu * sizeof (int);
|
|
164 bunsetsu_env = (struct wnn_env **) area_pter;
|
|
165 area_pter += maxbunsetsu * sizeof (struct wnn_env *);
|
|
166 touroku_bnst = (int *) area_pter;
|
|
167 area_pter += maxbunsetsu * sizeof (int);
|
|
168 for (k = 0; k < maxbunsetsu; k++)
|
|
169 {
|
|
170 bunsetsu[k] = 0;
|
|
171 bunsetsuend[k] = 0;
|
|
172 touroku_bnst[k] = 0;
|
|
173 }
|
|
174 return (0);
|
|
175 }
|
|
176
|
|
177 void
|
|
178 free_areas ()
|
|
179 {
|
|
180 Free (return_buf);
|
|
181 }
|
|
182
|
|
183 static struct wnn_buf *
|
|
184 local_jl_open_lang ()
|
|
185 {
|
|
186 struct wnn_buf *buf;
|
|
187 register char **c, *p;
|
|
188
|
|
189 if (!(p = Malloc (sizeof (struct wnn_buf) + sizeof (char *))))
|
|
190 {
|
|
191 malloc_error ("allocation of work area for Wnn");
|
|
192 return (NULL);
|
|
193 }
|
|
194 buf = (struct wnn_buf *) p;
|
|
195 p += sizeof (struct wnn_buf);
|
|
196 buf->bun_suu = 0;
|
|
197 buf->zenkouho_suu = 0;
|
|
198 buf->zenkouho_daip = 0;
|
|
199 buf->c_zenkouho = -1;
|
|
200 buf->zenkouho_bun = -1;
|
|
201 buf->zenkouho_end_bun = -1;
|
|
202 buf->free_heap = NULL;
|
|
203 c = (char **) p;
|
|
204 *c = NULL;
|
|
205 buf->heap = (char *) c;
|
|
206 buf->zenkouho_dai_suu = 0;
|
|
207 buf->msize_bun = 0;
|
|
208 buf->msize_zenkouho = 0;
|
|
209 buf->zenkouho_dai_suu = 0;
|
|
210 buf->bun = NULL;
|
|
211 buf->zenkouho_dai = NULL;
|
|
212 buf->zenkouho = NULL;
|
|
213 buf->down_bnst = NULL;
|
|
214 buf->zenkouho_dai = NULL;
|
|
215 buf->env = NULL;
|
|
216 return (buf);
|
|
217 }
|
|
218
|
|
219 /** Connecting to jserver */
|
|
220 int
|
|
221 connect_server (db)
|
|
222 XIMLangDataBase *db;
|
|
223 {
|
|
224 char environment[PATHNAMELEN];
|
|
225 char uumrc_name[PATHNAMELEN];
|
|
226 register WnnEnv *p;
|
|
227 WnnEnv *save_cur_normal_env = NULL, *save_cur_reverse_env = NULL;
|
|
228
|
|
229 if ((db->lang == NULL) || (db->connect_serv == False))
|
|
230 {
|
|
231 if (c_c->normal_env == NULL)
|
|
232 {
|
|
233 if (get_new_env (c_c, NULL, 0) < 0)
|
|
234 return (-1);
|
|
235 }
|
|
236 c_c->use_server = 0;
|
|
237 c_c->cur_normal_env = c_c->normal_env;
|
|
238 uumrc_name[0] = '\0';
|
|
239 if (!(bun_data_ = local_jl_open_lang ()))
|
|
240 return (-1);
|
|
241 return (0);
|
|
242 }
|
|
243 else
|
|
244 {
|
|
245 c_c->use_server = 1;
|
|
246 }
|
|
247
|
|
248 if (c_c->cur_normal_env)
|
|
249 save_cur_normal_env = c_c->cur_normal_env;
|
|
250 for (p = c_c->normal_env; p; p = p->next)
|
|
251 {
|
|
252 c_c->cur_normal_env = p;
|
|
253 get_envrc_name (uumrc_name, db->lang); /* use username for env-name */
|
|
254 environment[0] = '\0';
|
|
255 strcpy (environment, username);
|
|
256 strcat (environment, p->env_name_str);
|
|
257 if (servername == NULL && def_servername && *def_servername)
|
|
258 {
|
|
259 servername = alloc_and_copy (def_servername);
|
|
260 }
|
|
261 if (bun_data_ == NULL)
|
|
262 {
|
|
263 bun_data_ = jl_open_lang (environment, servername, db->lang, uumrc_name, yes_or_no_lock, print_msg_wait, WNN_TIMEOUT);
|
|
264 if (!bun_data_)
|
|
265 {
|
|
266 if (wnn_errorno == WNN_ALLOC_FAIL)
|
|
267 {
|
|
268 malloc_error ("alloction of work area for Wnn");
|
|
269 }
|
|
270 return (-1);
|
|
271 }
|
|
272 if (bun_data_->env != NULL)
|
|
273 {
|
|
274 env_normal = bun_data_->env;
|
|
275 }
|
|
276 }
|
|
277 else if (env_normal == 0 || jl_isconnect_e (env_normal) == 0)
|
|
278 {
|
|
279 env_normal = jl_connect_lang (environment, servername, db->lang, uumrc_name, yes_or_no_lock, print_msg_wait, WNN_TIMEOUT);
|
|
280 }
|
|
281 if (env_normal)
|
|
282 {
|
|
283 if (normal_sticky)
|
|
284 jl_env_sticky_e (env_normal);
|
|
285 else
|
|
286 jl_env_un_sticky_e (env_normal);
|
|
287 }
|
|
288 }
|
|
289 if (save_cur_normal_env)
|
|
290 {
|
|
291 c_c->cur_normal_env = save_cur_normal_env;
|
|
292 if (env_normal)
|
|
293 jl_env_set (bun_data_, env_normal);
|
|
294 }
|
|
295 if (c_c->normal_env == NULL)
|
|
296 {
|
|
297 if (get_new_env (c_c, NULL, 0) < 0)
|
|
298 return (-1);
|
|
299 c_c->use_server = 0;
|
|
300 c_c->cur_normal_env = c_c->normal_env;
|
|
301 uumrc_name[0] = '\0';
|
|
302 if (!(bun_data_ = local_jl_open_lang ()))
|
|
303 return (-1);
|
|
304 }
|
|
305
|
|
306 if (c_c->cur_reverse_env)
|
|
307 save_cur_reverse_env = c_c->cur_reverse_env;
|
|
308 for (p = c_c->reverse_env; p; p = p->next)
|
|
309 {
|
|
310 c_c->cur_reverse_env = p;
|
|
311 if (get_envrc_name_reverse (uumrc_name, db->lang) > 0)
|
|
312 {
|
|
313 environment[0] = '\0';
|
|
314 strcpy (environment, username);
|
|
315 strcat (environment, p->env_name_str);
|
|
316 strcat (environment, "R");
|
|
317 if (reverse_servername == NULL && def_reverse_servername && *def_reverse_servername)
|
|
318 {
|
|
319 reverse_servername = alloc_and_copy (def_reverse_servername);
|
|
320 }
|
|
321 env_reverse = jl_connect_lang (environment, reverse_servername, db->lang, uumrc_name, yes_or_no_lock, print_msg_wait, WNN_TIMEOUT);
|
|
322 if (env_reverse)
|
|
323 {
|
|
324 if (reverse_sticky)
|
|
325 jl_env_sticky_e (env_reverse);
|
|
326 else
|
|
327 jl_env_un_sticky_e (env_reverse);
|
|
328 }
|
|
329 }
|
|
330 }
|
|
331 if (save_cur_reverse_env)
|
|
332 c_c->cur_reverse_env = save_cur_reverse_env;
|
|
333 #ifdef USING_XJUTIL
|
|
334 if (!isstart_xjutil (db->lang))
|
|
335 xjutil_start ();
|
|
336 #endif /* USING_XJUTIL */
|
|
337 return (0);
|
|
338 }
|
|
339
|
|
340 int
|
|
341 init_xcvtkey ()
|
|
342 {
|
|
343 char tmp_file[MAXPATHLEN];
|
|
344 int ret;
|
|
345
|
|
346 cvt_key_tbl_cnt = 0;
|
|
347 /* Backward compatibility for cvt_meta and cvt_fun. */
|
|
348 if (cvt_fun_file && *cvt_fun_file)
|
|
349 {
|
|
350 if ((ret = cvt_meta_and_fun_setup (cvt_fun_file, cvt_key_tbl, NULL)) == -1)
|
|
351 {
|
|
352 print_out1 ("I can't open cvt_fun file \"%s\".", cvt_fun_file);
|
|
353 cvt_fun_file = NULL;
|
|
354 }
|
|
355 else
|
|
356 {
|
|
357 cvt_key_tbl_cnt = ret;
|
|
358 }
|
|
359 }
|
|
360 if (cvt_meta_file && *cvt_meta_file)
|
|
361 {
|
|
362 if ((ret = cvt_meta_and_fun_setup (cvt_meta_file, cvt_key_tbl, "Meta")) == -1)
|
|
363 {
|
|
364 print_out1 ("I can't open cvt_meta file \"%s\".", cvt_meta_file);
|
|
365 cvt_meta_file = NULL;
|
|
366 }
|
|
367 else
|
|
368 {
|
|
369 cvt_key_tbl_cnt = ret;
|
|
370 }
|
|
371 }
|
|
372
|
|
373 if (cvt_key_file && *cvt_key_file)
|
|
374 {
|
|
375 if (cvt_key_setup (cvt_key_file) == -1)
|
|
376 {
|
|
377 print_out1 ("I can't open cvt_key file \"%s\", use default file.", cvt_key_file);
|
|
378 cvt_key_file = NULL;
|
|
379 }
|
|
380 }
|
|
381 if (cvt_key_file == NULL)
|
|
382 {
|
|
383 strcat (strcpy (tmp_file, LIBDIR), CVTKEYFILE);
|
|
384 if (!(cvt_key_file = alloc_and_copy (tmp_file)))
|
|
385 return (-1);
|
|
386 if (cvt_key_setup (cvt_key_file) == -1)
|
|
387 {
|
|
388 print_out1 ("I can't open default cvt_key file \"%s\".\n I don't convert function keys.", cvt_key_file);
|
|
389 Free (cvt_key_file);
|
|
390 cvt_key_file = NULL;
|
|
391 }
|
|
392 }
|
|
393 return (0);
|
|
394 }
|