comparison Xwnmo/xwnmo/init.c @ 0:bbc77ca4def5

initial import
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Thu, 13 Dec 2007 04:30:14 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bbc77ca4def5
1 /*
2 * $Id: init.c,v 1.2 2001/06/14 18:16:16 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
38 #include "sdefine.h"
39 #include "xim.h"
40 #include "sheader.h"
41 #include "ext.h"
42
43 static void
44 default_flag_set ()
45 {
46 cursor_colum = 0;
47 cursor_reverse = 0;
48 cursor_underline = 0;
49 cursor_invisible = 1;
50 cursor_bold = 0;
51 quote_flag = 0;
52 send_ascii_char = 0;
53 send_ascii_stack = 0;
54 send_ascii_char_quote = 0;
55 c_c->command_func_stack[0] = NULL;
56 c_c->func_stack_count = -1;
57 c_c->buffer_ignored = 0;
58 }
59
60 static int
61 copy_env (wc)
62 register WnnClientRec *wc;
63 {
64 WnnEnv *p;
65
66 for (p = wc->normal_env; p; p = p->next)
67 {
68 if (get_new_env (c_c, NULL, 0) < 0 || (p->host_name && !(servername = alloc_and_copy (p->host_name))))
69 goto ERROR_RET;
70 envrcname = p->envrc_name;
71 strcpy (env_name, p->env_name_str);
72 }
73 for (p = wc->reverse_env; p; p = p->next)
74 {
75 if (get_new_env (c_c, NULL, 1) < 0 || (p->host_name && !(reverse_servername = alloc_and_copy (p->host_name))))
76 goto ERROR_RET;
77 reverse_envrcname = p->envrc_name;
78 strcpy (reverse_env_name, p->env_name_str);
79 }
80
81 send_ascii_char = send_ascii_char_def;
82
83 c_c->m_table = wc->m_table;
84 c_c->m_table->re_count++;
85 return (0);
86 ERROR_RET:
87 free_env (c_c->normal_env);
88 free_env (c_c->reverse_env);
89 return (-1);
90 }
91
92 static void
93 add_wnnclientlist (cl)
94 register WnnClientRec *cl;
95 {
96 cl->next = wnnclient_list;
97 wnnclient_list = cl;
98 }
99
100 static void
101 remove_wnnclientlist (cl)
102 register WnnClientRec *cl;
103 {
104 register WnnClientList p, *prev;
105 for (prev = &wnnclient_list; p = *prev; prev = &p->next)
106 {
107 if (p == cl)
108 {
109 *prev = p->next;
110 break;
111 }
112 }
113 }
114
115 void
116 add_ximclientlist (cl)
117 register XIMClientRec *cl;
118 {
119 cl->next = ximclient_list;
120 ximclient_list = cl;
121 }
122
123 void
124 remove_ximclientlist (cl)
125 register XIMClientRec *cl;
126 {
127 register XIMClientList p, *prev;
128 for (prev = &ximclient_list; p = *prev; prev = &p->next)
129 {
130 if (p == cl)
131 {
132 *prev = p->next;
133 break;
134 }
135 }
136 }
137
138 void
139 add_inputlist (xi)
140 register XIMInputRec *xi;
141 {
142 xi->next = input_list;
143 input_list = xi;
144 }
145
146 void
147 remove_inputlist (xi)
148 register XIMInputRec *xi;
149 {
150 register XIMInputList p, *prev;
151 for (prev = &input_list; p = *prev; prev = &p->next)
152 {
153 if (p == xi)
154 {
155 *prev = p->next;
156 break;
157 }
158 }
159 }
160
161 static WnnClientRec *
162 find_same_lang (lang)
163 char *lang;
164 {
165 register XIMClientRec *p;
166 register XIMLangRec *xl;
167 register int i;
168 for (p = ximclient_list; p != NULL; p = p->next)
169 {
170 for (i = 0; i < p->lang_num; i++)
171 {
172 xl = p->xl[i];
173 if (xl->w_c && xl->w_c->m_table)
174 {
175 if (!strcmp (xl->lang_db->lang, lang) && xl->w_c != NULL)
176 {
177 return ((WnnClientRec *) xl->w_c);
178 }
179 }
180 }
181 }
182 return ((WnnClientRec *) NULL);
183 }
184
185 int
186 allocate_wnn (uname)
187 char *uname;
188 {
189 int len = 0;
190 register char *p;
191 extern void bzero ();
192
193 if (uname && *uname)
194 len = strlen (uname) + 1;
195 if (!(p = Malloc (sizeof (WnnClientRec) + sizeof (ClientBuf) + len)))
196 {
197 malloc_error ("allocation of data for wnn");
198 return (-1);
199 }
200 c_c = (WnnClientList) p;
201 bzero ((char *) c_c, sizeof (WnnClientRec));
202 p += sizeof (WnnClientRec);
203 c_b = (ClientBuf *) p;
204 bzero ((char *) c_b, sizeof (ClientBuf));
205 if (uname && *uname)
206 {
207 p += sizeof (ClientBuf);
208 c_c->user_name = (char *) p;
209 strcpy (c_c->user_name, uname);
210 }
211 add_wnnclientlist (c_c);
212 default_flag_set ();
213 return (0);
214 }
215
216 void
217 free_wnn ()
218 {
219 remove_wnnclientlist (c_c);
220 Free ((char *) c_c);
221 }
222
223 int
224 initialize_wnn (xl, root)
225 XIMLangRec *xl;
226 int root;
227 {
228 WnnClientRec *p;
229
230 if ((p = find_same_lang (xl->lang_db->lang)) != NULL)
231 {
232 if (copy_env (p) < 0)
233 return (-1);
234 }
235 else
236 {
237 if (uumrc_get_entries (xl->lang_db, 0, root) == -1)
238 {
239 return (-1);
240 }
241 if (init_key_table (xl->lang_db->lang) == -1)
242 {
243 del_client (c_c, 4);
244 return (-1);
245 }
246 }
247 henkan_off_flag = henkan_off_def;
248 maxlength = maxchg * 2;
249 if (allocate_areas () == -1)
250 {
251 del_client (c_c, 3);
252 return (-1);
253 }
254 if (init_history () == -1)
255 {
256 del_client (c_c, 2);
257 return (-1);
258 }
259 if (open_romkan (xl->lang_db) == -1)
260 {
261 del_client (c_c, 1);
262 return (-1);
263 }
264 return (0);
265 }