comparison Xwnmo/xwnmo/uif1.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: uif1.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 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 #include <stdio.h>
43 #include "commonhd.h"
44 #include "sdefine.h"
45 #include "xim.h"
46 #include "sheader.h"
47 #include "ext.h"
48 #include "rk_spclval.h"
49 #include "rk_fundecl.h"
50
51 int
52 jutil_c (in)
53 int in;
54 {
55 static WnnClientRec *c_c_sv = NULL;
56 static int jutil_c_step = 0;
57
58 if (c_c_sv != NULL && c_c != c_c_sv)
59 {
60 ring_bell ();
61 return (-1);
62 }
63 if (jutil_c_step == 0)
64 {
65 if (c_c_sv)
66 {
67 return (-1);
68 }
69 c_c_sv = c_c;
70 push_func (c_c, jutil_c);
71 if (!isconect_jserver ())
72 {
73 c_c_sv = NULL;
74 pop_func (c_c);
75 return (0);
76 }
77 jutil_c_step = 1;
78 }
79 if (jutil (in) == BUFFER_IN_CONT)
80 {
81 return (BUFFER_IN_CONT);
82 }
83 c_c_sv = NULL;
84 pop_func (c_c);
85 jutil_c_step = 0;
86 return (0);
87 }
88
89 int
90 touroku_c ()
91 {
92 if (!isconect_jserver ())
93 {
94 return (0);
95 }
96 touroku ();
97 return (0);
98 }
99
100 int
101 reconnect_jserver_body (in)
102 int in;
103 {
104 int k;
105 int c;
106 static int c_p = 0;
107 static WnnClientRec *c_c_sv = 0;
108 static int j_con_step = 0;
109 static char hostname[32];
110 static char *lang;
111
112 if (c_c->use_server == 0)
113 return (0);
114 if (in == -99)
115 {
116 end_ichiran ();
117 c_c_sv = 0;
118 j_con_step = 0;
119 romkan_clear ();
120 return (-1);
121 }
122 if (c_c_sv != 0 && c_c != c_c_sv)
123 {
124 ring_bell ();
125 return (-1);
126 }
127 if (c_c_sv == 0)
128 {
129 for (k = 0; k < 32; hostname[k++] = '\0');
130 c_c_sv = c_c;
131 c_p = 0;
132 lang = cur_lang->lang;
133 }
134 if (j_con_step == 0)
135 {
136 if (init_ichiran ((unsigned char **) NULL, 0, -1,
137 (unsigned char *) msg_get (cd, 29, default_message[29], lang),
138 (unsigned char *) msg_get (cd, 30, default_message[30], lang), (unsigned char *) msg_get (cd, 19, default_message[19], lang), NULL, 32, NYUURYOKU) == -1)
139 {
140 ring_bell ();
141 c_c_sv = 0;
142 return (-1);
143 }
144 sprintf (hostname, "%s", servername);
145 c_p = strlen (hostname);
146 draw_nyuu_w ((unsigned char *) hostname, 1);
147 j_con_step++;
148 return (BUFFER_IN_CONT);
149 }
150 if (j_con_step == 1)
151 {
152 c = in;
153 if (!xim->cur_j_c_root->ichi->map)
154 return (BUFFER_IN_CONT);
155 if (xim->sel_ret == -2)
156 {
157 end_ichiran ();
158 xim->sel_ret = -1;
159 c_c_sv = 0;
160 j_con_step = 0;
161 romkan_clear ();
162 return (-1);
163 }
164 if (c < 256)
165 {
166 if ((c == ESC) || (t_quit == main_table[5][c]))
167 {
168 end_ichiran ();
169 c_c_sv = 0;
170 romkan_clear ();
171 return (-1);
172 }
173 else if (henkan_off == main_table[5][c])
174 {
175 ring_bell ();
176 }
177 else if (c == rubout_code && c_p)
178 {
179 hostname[--c_p] = '\0';
180 }
181 else if (c == NEWLINE || c == CR)
182 {
183 if (c_p == 0)
184 {
185 goto RET;
186 }
187 else
188 {
189 end_ichiran ();
190 goto NEXT;
191 }
192 }
193 else if (c > 20 && c < 128)
194 {
195 hostname[c_p++] = (char) c;
196 goto RET;
197 }
198 else
199 {
200 ring_bell ();
201 }
202 }
203 else
204 {
205 ring_bell ();
206 }
207 RET:
208 clear_nyuu_w ();
209 draw_nyuu_w ((unsigned char *) hostname, 1);
210 return (BUFFER_IN_CONT);
211 }
212 NEXT:
213 if (servername)
214 Free (servername);
215 servername = alloc_and_copy (hostname);
216
217 if (connect_server (cur_lang) < 0)
218 goto ERROR_RET;
219 if (c_c->use_server && !jl_isconnect (bun_data_))
220 {
221 print_msg_getc (" %s", msg_get (cd, 32, default_message[32], lang), NULL, NULL);
222 }
223 else
224 {
225 print_msg_getc (" %s", msg_get (cd, 33, default_message[33], lang), NULL, NULL);
226 }
227 ERROR_RET:
228 c_c_sv = 0;
229 j_con_step = 0;
230 romkan_clear ();
231 return (0);
232 }
233
234 int
235 lang_c (in)
236 int in;
237 {
238 static WnnClientRec *c_c_sv = 0;
239 XIMLangRec *xl;
240 XIMNestLangRec *p;
241 int ret;
242
243 if (in == -99)
244 {
245 c_c_sv = 0;
246 pop_func (c_c);
247 return (0);
248 }
249 if (c_c_sv != 0 && c_c != c_c_sv)
250 {
251 ring_bell ();
252 return (-1);
253 }
254 if (c_c_sv == 0)
255 {
256 c_c_sv = c_c;
257 push_func (c_c, lang_c);
258 }
259 if ((ret = lang_set (in, &xl, &p)) == BUFFER_IN_CONT)
260 {
261 return (BUFFER_IN_CONT);
262 }
263 c_c_sv = 0;
264 pop_func (c_c);
265 if (ret >= 0)
266 {
267 change_lang (xl, p);
268 }
269 return (0);
270 }
271
272 int
273 lang_ct (in)
274 int in;
275 {
276 static WnnClientRec *c_c_sv = 0;
277 XIMLangRec *xl;
278 XIMNestLangRec *p;
279 int ret;
280
281 if (c_c_sv != 0 && c_c != c_c_sv)
282 {
283 ring_bell ();
284 return (-1);
285 }
286 if (c_c_sv == 0)
287 {
288 c_c_sv = c_c;
289 push_func (c_c, lang_ct);
290 }
291 if ((ret = lang_set_ct (in, &xl, &p)) == BUFFER_IN_CONT)
292 {
293 return (BUFFER_IN_CONT);
294 }
295 c_c_sv = 0;
296 pop_func (c_c);
297 if (ret >= 0)
298 {
299 change_lang (xl, p);
300 }
301 return (0);
302 }
303
304 #define UNGETBUFSIZE 32
305 static unsigned int unget_buf[UNGETBUFSIZE];
306 static int count = 0;
307
308 int
309 push_unget_buf (c)
310 int c;
311 {
312 if ((count + 1) >= UNGETBUFSIZE)
313 return (-1);
314 unget_buf[count++] = c;
315 unget_buf[count] = EOLTTR;
316 return (0);
317 }
318
319 unsigned int *
320 get_unget_buf ()
321 {
322 if (count <= 0)
323 unget_buf[0] = EOLTTR;
324 count = 0;
325 return (unget_buf);
326 }
327
328 int
329 if_unget_buf ()
330 {
331 if (count > 0)
332 return (1);
333 return (0);
334 }