0
|
1 /*
|
|
2 * $Id: readximrc.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 OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999
|
|
10 * Copyright 1991, 1992 by Massachusetts Institute of Technology
|
|
11 *
|
|
12 * Author: OMRON SOFTWARE Co., Ltd. <freewnn@rd.kyoto.omronsoft.co.jp>
|
|
13 *
|
|
14 * This program is free software; you can redistribute it and/or modify
|
|
15 * it under the terms of the GNU General Public License as published by
|
|
16 * the Free Software Foundation; either version 2, or (at your option)
|
|
17 * any later version.
|
|
18 *
|
|
19 * This program is distributed in the hope that it will be useful,
|
|
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22 * GNU General Public License for more details.
|
|
23 *
|
|
24 * You should have received a copy of the GNU General Public License
|
|
25 * along with GNU Emacs; see the file COPYING. If not, write to the
|
|
26 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
27 *
|
|
28 * Commentary:
|
|
29 *
|
|
30 * Change log:
|
|
31 *
|
|
32 * Last modified date: 8,Feb.1999
|
|
33 *
|
|
34 * Code:
|
|
35 *
|
|
36 */
|
|
37 /* Version 4.0
|
|
38 */
|
|
39 #include <stdio.h>
|
|
40 #include "commonhd.h"
|
|
41 #include "sdefine.h"
|
|
42 #include "xim.h"
|
|
43 #include "sheader.h"
|
|
44 #include "config.h"
|
|
45 #include "ext.h"
|
|
46
|
|
47 /** Set parameter by reading ximrc file */
|
|
48 static int
|
|
49 read_xim_rcfile (filenm, expand_filenm)
|
|
50 char *filenm;
|
|
51 int (*expand_filenm) ();
|
|
52 {
|
|
53 char buf[BUFSIZ];
|
|
54 char entrynm[64];
|
|
55 char s[2][MAXPATHLEN + 1];
|
|
56 int n;
|
|
57 int error;
|
|
58 FILE *fp;
|
|
59 XIMLangDataBase *ld;
|
|
60 extern int fclose ();
|
|
61
|
|
62 if ((fp = fopen (filenm, "r")) == NULL)
|
|
63 {
|
|
64 return (-1);
|
|
65 }
|
|
66
|
|
67 while (fgets (buf, BUFSIZ, fp))
|
|
68 {
|
|
69 if (comment_char (*buf) || (n = sscanf (buf, "%s %s %s", entrynm, s[0], s[1])) < 1)
|
|
70 {
|
|
71 continue;
|
|
72 }
|
|
73 error = 0;
|
|
74 switch (*(entrynm + 3))
|
|
75 {
|
|
76 case 'l':
|
|
77 if (!strcmp (entrynm, "preloadrkfile"))
|
|
78 {
|
|
79 if (n > 1)
|
|
80 {
|
|
81 register ReadRkfileRec *rr, *p, *prev;
|
|
82 if (!(rr = (ReadRkfileList) Malloc (sizeof (ReadRkfileRec))))
|
|
83 goto CLOSE_RET;
|
|
84 if (read_rkfile_list == NULL)
|
|
85 {
|
|
86 read_rkfile_list = rr;
|
|
87 }
|
|
88 else
|
|
89 {
|
|
90 for (p = read_rkfile_list, prev = NULL; p != NULL; prev = p, p = p->next);
|
|
91 prev->next = rr;
|
|
92 }
|
|
93 if (!(rr->name = alloc_and_copy (s[0])))
|
|
94 goto CLOSE_RET;
|
|
95 rr->next = NULL;
|
|
96 }
|
|
97 else
|
|
98 error = 1;
|
|
99 }
|
|
100 else
|
|
101 error = 2;
|
|
102 break;
|
|
103 case 'u':
|
|
104 if (!strcmp (entrynm, "setuumrc"))
|
|
105 {
|
|
106 if (n > 2)
|
|
107 {
|
|
108 for (ld = language_db; ld; ld = ld->next)
|
|
109 {
|
|
110 if (!strcmp (ld->lang, s[0]))
|
|
111 break;
|
|
112 }
|
|
113 if (!ld)
|
|
114 {
|
|
115 print_out2 ("In ximrc \"%s\", I don't support the lang \"%s\".", filenm, s[0]);
|
|
116 }
|
|
117 if ((*expand_filenm) (s[1]) != 0)
|
|
118 {
|
|
119 print_out1 ("In ximrc \"%s\", I could not expand %s.", s[1]);
|
|
120 }
|
|
121 if (!(ld->uumrc_name = alloc_and_copy (s[1])))
|
|
122 goto CLOSE_RET;
|
|
123 if (rkfile_defined_by_option && cur_lang == ld)
|
|
124 {
|
|
125 if (!(ld->rkfile_name = alloc_and_copy (root_rkfilename)))
|
|
126 goto CLOSE_RET;
|
|
127 }
|
|
128 }
|
|
129 else
|
|
130 error = 1;
|
|
131 }
|
|
132 else
|
|
133 error = 2;
|
|
134 break;
|
|
135 case 'b':
|
|
136 if (!strcmp (entrynm, "setbackspacechar"))
|
|
137 {
|
|
138 if (n > 1)
|
|
139 {
|
|
140 rubout_code = s[0][0];
|
|
141 }
|
|
142 else
|
|
143 error = 1;
|
|
144 }
|
|
145 else
|
|
146 error = 2;
|
|
147 break;
|
|
148 default:
|
|
149 error = 2;
|
|
150 break;
|
|
151 }
|
|
152 if (error == 1)
|
|
153 {
|
|
154 print_out2 ("In ximrc file \"%s\", I found a unknown entry name \"%s\".", filenm, entrynm);
|
|
155 }
|
|
156 else if (error == 2)
|
|
157 {
|
|
158 print_out2 ("In ximrc file \"%s\", I found a Illegal line %d.", filenm, entrynm);
|
|
159 }
|
|
160 }
|
|
161 fclose (fp);
|
|
162 return (0);
|
|
163 CLOSE_RET:
|
|
164 fclose (fp);
|
|
165 return (-2);
|
|
166 }
|
|
167
|
|
168 int
|
|
169 read_ximrc ()
|
|
170 {
|
|
171 register char *n;
|
|
172 char tmp_xim_rc_file[MAXPATHLEN + 1];
|
|
173 register int ret;
|
|
174 extern char *getenv ();
|
|
175
|
|
176 if (ximrc_file)
|
|
177 {
|
|
178 n = ximrc_file;
|
|
179 }
|
|
180 else
|
|
181 {
|
|
182 n = getenv (XIM_RCENV);
|
|
183 }
|
|
184 if (n && *n)
|
|
185 {
|
|
186 strcpy (tmp_xim_rc_file, n);
|
|
187 if ((*expand_expr) (tmp_xim_rc_file) != 0)
|
|
188 {
|
|
189 print_out1 ("I could not expand %s.", tmp_xim_rc_file);
|
|
190 }
|
|
191 if ((ret = read_xim_rcfile (tmp_xim_rc_file, expand_expr)) == 0)
|
|
192 {
|
|
193 goto OK_RET;
|
|
194 }
|
|
195 else if (ret == -2)
|
|
196 return (-1);
|
|
197 print_out1 ("Can't open a specified ximrc \"%s\".", tmp_xim_rc_file);
|
|
198 ximrc_file = NULL;
|
|
199 }
|
|
200 if ((n = getenv ("HOME")) && *n)
|
|
201 {
|
|
202 strcat (strcpy (tmp_xim_rc_file, n), USR_XIMRC);
|
|
203 if ((ret = read_xim_rcfile (tmp_xim_rc_file, expand_expr)) == 0)
|
|
204 {
|
|
205 goto OK_RET;
|
|
206 }
|
|
207 else if (ret == -2)
|
|
208 return (-1);
|
|
209 ximrc_file = NULL;
|
|
210 }
|
|
211 strcat (strcpy (tmp_xim_rc_file, LIBDIR), XIMRCFILE);
|
|
212 if (read_xim_rcfile (tmp_xim_rc_file, expand_expr) >= 0)
|
|
213 {
|
|
214 goto OK_RET;
|
|
215 }
|
|
216 print_out1 ("Can't open a default ximrc file \"%s\".", tmp_xim_rc_file);
|
|
217 ximrc_file = NULL;
|
|
218 return (-1);
|
|
219 OK_RET:
|
|
220 if (!(ximrc_file = alloc_and_copy (tmp_xim_rc_file)))
|
|
221 return (-1);
|
|
222 return (0);
|
|
223 }
|
|
224
|
|
225 static void
|
|
226 default_set_of_ld (ld)
|
|
227 register XIMLangDataBase *ld;
|
|
228 {
|
|
229 ld->read = 0;
|
|
230 ld->uumkey_name = NULL;
|
|
231 ld->host_name = NULL;
|
|
232 ld->rev_host_name = NULL;
|
|
233 ld->rk_table = NULL;
|
|
234 ld->jishopath = NULL;
|
|
235 ld->hindopath = NULL;
|
|
236 ld->fuzokugopath = NULL;
|
|
237 ld->h_off_def = 0;
|
|
238 ld->e_delete = 1;
|
|
239 ld->s_ascii_char_def = 0;
|
|
240 ld->m_chg = 0;
|
|
241 ld->m_bunsetsu = 0;
|
|
242 ld->m_history = 0;
|
|
243 ld->t_comment = 0;
|
|
244 ld->h_on_kuten = 0;
|
|
245 #ifdef USING_XJUTIL
|
|
246 ld->xjutil_act = 0;
|
|
247 ld->xjutil_id = (Window) 0;
|
|
248 ld->xjutil_pid = 0;
|
|
249 ld->xjutil_use = NULL;
|
|
250 #endif /* USING_XJUTIL */
|
|
251 }
|
|
252
|
|
253 int
|
|
254 read_ximconf ()
|
|
255 {
|
|
256 char buf[BUFSIZ];
|
|
257 char filenm[MAXPATHLEN + 1];
|
|
258 char s[6][128];
|
|
259 register int n, i, lc_cnt = 0, all_size;
|
|
260 FILE *fp;
|
|
261 register char *p, *ptr, *ret;
|
|
262 FunctionTable *f;
|
|
263 XIMLangDataBase *ld;
|
|
264 XIMLcNameRec *lnl, *lnl_p;
|
|
265
|
|
266 strcpy (filenm, LIBDIR);
|
|
267 strcat (filenm, XIM_CONFIG_FILE);
|
|
268 if ((fp = fopen (filenm, "r")) == NULL)
|
|
269 {
|
|
270 print_out1 ("Can't open xim.conf \"%s\".", filenm);
|
|
271 return (-1);
|
|
272 }
|
|
273
|
|
274 while (1)
|
|
275 {
|
|
276 ptr = buf;
|
|
277 while (1)
|
|
278 {
|
|
279 if (!(ret = fgets (ptr, BUFSIZ, fp)))
|
|
280 {
|
|
281 break;
|
|
282 }
|
|
283 if (*ptr == '\n')
|
|
284 continue;
|
|
285 if ((i = strlen (ptr)) > 1 && ptr[i - 2] == '\\')
|
|
286 {
|
|
287 ptr += i - 2;
|
|
288 continue;
|
|
289 }
|
|
290 break;
|
|
291 }
|
|
292 if (!ret)
|
|
293 break;
|
|
294 if (comment_char (*buf) || (n = sscanf (buf, "%s %s %s %s %s %s", s[0], s[1], s[2], s[3], s[4], s[5])) < 1)
|
|
295 {
|
|
296 continue;
|
|
297 }
|
|
298 if (!strcmp (s[0], "setdefaultlocale"))
|
|
299 {
|
|
300 if (n < 2)
|
|
301 goto ARG_ERR;
|
|
302 if (!(def_locale = alloc_and_copy (s[1])))
|
|
303 goto CLOSE_RET;
|
|
304
|
|
305 }
|
|
306 else if (!strcmp (s[0], "setworldlocale"))
|
|
307 {
|
|
308 if (n < 2)
|
|
309 goto ARG_ERR;
|
|
310 if (!(world_locale = alloc_and_copy (s[1])))
|
|
311 goto CLOSE_RET;
|
|
312 }
|
|
313 else
|
|
314 {
|
|
315 if (n < 6)
|
|
316 goto ARG_ERR;
|
|
317 all_size = sizeof (XIMLangDataBase) + strlen (s[0]) + strlen (s[1]) + strlen (s[2]) + 3;
|
|
318 if (!(p = (char *) Malloc (all_size)))
|
|
319 {
|
|
320 malloc_error ("allocation of the initial area");
|
|
321 goto CLOSE_RET;
|
|
322 }
|
|
323 bzero (p, all_size);
|
|
324 ld = (XIMLangDataBase *) p;
|
|
325 p += sizeof (XIMLangDataBase);
|
|
326 strcpy (p, s[0]);
|
|
327 ptr = p;
|
|
328 lc_cnt = 0;
|
|
329 do
|
|
330 {
|
|
331 if (lc_cnt)
|
|
332 {
|
|
333 *ptr++ = '\0';
|
|
334 }
|
|
335 lc_cnt++;
|
|
336 }
|
|
337 while (*ptr && (ptr = index (ptr, '|')));
|
|
338 if (!(lnl_p = (XIMLcNameRec *) Malloc (sizeof (XIMLcNameRec) * lc_cnt)))
|
|
339 {
|
|
340 malloc_error ("allocation of the initial area");
|
|
341 goto CLOSE_RET;
|
|
342 }
|
|
343 ptr = p;
|
|
344 for (i = 0; i < lc_cnt; i++)
|
|
345 {
|
|
346 for (lnl = lc_name_list; lnl; lnl = lnl->next)
|
|
347 {
|
|
348 if (!strcmp (lnl->lc_name, ptr))
|
|
349 {
|
|
350 print_out2 ("In xim.conf file \"%s\", locale \"%s\" is redeclared.", filenm, ptr);
|
|
351 goto CLOSE_RET;
|
|
352 }
|
|
353 }
|
|
354 lnl_p[i].lc_name = ptr;
|
|
355 ptr += strlen (ptr) + 1;
|
|
356 lnl_p[i].lang_db = ld;
|
|
357 if (i != 0)
|
|
358 {
|
|
359 lnl_p[i].next = &lnl_p[i - 1];
|
|
360 }
|
|
361 }
|
|
362 lnl_p[0].next = lc_name_list;
|
|
363 lc_name_list = &lnl_p[lc_cnt - 1];
|
|
364
|
|
365 p += strlen (s[0]) + 1;
|
|
366 ld->lang = (char *) p;
|
|
367 strcpy (ld->lang, s[1]);
|
|
368
|
|
369 p += strlen (s[1]) + 1;
|
|
370 ld->lc_name = (char *) p;
|
|
371 strcpy (ld->lc_name, s[2]);
|
|
372
|
|
373 if ((ld->cswidth_id = create_cswidth (s[3])) == 0)
|
|
374 {
|
|
375 print_out2 ("In xim.conf file \"%s\", \"%s\" is a bad string for CSWIDTH.", filenm, s[3]);
|
|
376 goto CLOSE_RET;
|
|
377 }
|
|
378 if (!strcmp (s[4], "True") || !strcmp (s[4], "TRUE"))
|
|
379 {
|
|
380 ld->connect_serv = True;
|
|
381 }
|
|
382 else
|
|
383 {
|
|
384 ld->connect_serv = False;
|
|
385 }
|
|
386 ld->f_table = (FunctionTable *) NULL;
|
|
387 for (f = function_db, i = 0; f[i].name; i++)
|
|
388 {
|
|
389 if (!strcmp (s[5], f[i].name))
|
|
390 {
|
|
391 ld->f_table = &(f[i]);
|
|
392 break;
|
|
393 }
|
|
394 }
|
|
395 if (!ld->f_table)
|
|
396 {
|
|
397 print_out2 ("In xim.conf file \"%s\", \"%s\" is a bad string for functions.", filenm, s[5]);
|
|
398 goto CLOSE_RET;
|
|
399 }
|
|
400 if (language_db)
|
|
401 {
|
|
402 ld->next = language_db;
|
|
403 }
|
|
404 else
|
|
405 {
|
|
406 ld->next = NULL;
|
|
407 }
|
|
408 language_db = ld;
|
|
409 default_set_of_ld (ld);
|
|
410 }
|
|
411 }
|
|
412 fclose (fp);
|
|
413 if (!def_locale)
|
|
414 if (!(def_locale = alloc_and_copy (DEFAULT_LANG)))
|
|
415 return (-1);
|
|
416 if (!world_locale)
|
|
417 if (!(world_locale = alloc_and_copy (DEFAULT_WORLD_LOCALE)))
|
|
418 return (-1);
|
|
419 return (0);
|
|
420 ARG_ERR:
|
|
421 print_out2 ("In xim.conf file \"%s\", too few arguments at line \"%s\".", filenm, buf);
|
|
422 CLOSE_RET:
|
|
423 fclose (fp);
|
|
424 return (-1);
|
|
425 }
|