Mercurial > freewnn
comparison Wnn/uum/basic_op.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: basic_op.c,v 1.5 2006/02/10 18:29:38 aonoto 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 FreeWnn Project 1999, 2000, 2002, 2006 | |
14 * | |
15 * Maintainer: FreeWnn Project | |
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 of the License, or | |
20 * (at your option) 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 this program; if not, write to the Free Software | |
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
30 */ | |
31 | |
32 /* | |
33 bufferの使い方とかbufferの内容がどのように画面に表示されるかとか | |
34 の詳しい説明は、buffer.hか又は、screen.cを参照して下さい。 | |
35 このファイルは、baffer を制御するための基本関数で、 | |
36 ユーザーインターフェース、登録時、その他の入力に共通するような関数を | |
37 定義しています。 | |
38 */ | |
39 #ifdef HAVE_CONFIG_H | |
40 # include <config.h> | |
41 #endif | |
42 | |
43 #include <stdio.h> | |
44 #if STDC_HEADERS | |
45 # include <stdlib.h> | |
46 # include <string.h> | |
47 #else | |
48 # if HAVE_MALLOC_H | |
49 # include <malloc.h> | |
50 # endif | |
51 # if HAVE_STRINGS_H | |
52 # include <strings.h> | |
53 # endif | |
54 #endif /* STDC_HEADERS */ | |
55 #include "jllib.h" | |
56 #include "commonhd.h" | |
57 #include "sdefine.h" | |
58 #include "sheader.h" | |
59 #include "rk_spclval.h" | |
60 #include "buffer.h" | |
61 | |
62 /** bufferを使って、仮名文字列を入力します。 | |
63 buflenはバッファーの長さ。modeは反転、下線の状態 | |
64 bufferの中に初期文字列を入れて置いて下さい。 | |
65 msgは、仮名入力行の先頭に表すメッセージ文(w_charであることに注意) | |
66 横にスクロールする時には、このメッセージも一緒にスクロールします | |
67 これは、bufferを使う高レベルのかな入力ルーチンです。 | |
68 更に高度な指定をしたい人は、buffer_inを用いて下さい。 | |
69 */ | |
70 | |
71 extern int uum_cursor_invisible; | |
72 | |
73 int | |
74 redraw_nisemono () | |
75 { | |
76 call_t_redraw_move (c_b->t_c_p, c_b->t_c_p, c_b->maxlen, 2, 1); | |
77 return (0); | |
78 } | |
79 | |
80 | |
81 int | |
82 kana_in_w_char_msg (msg, mode, buffer, buflen) | |
83 w_char *msg; | |
84 int mode; | |
85 w_char *buffer; | |
86 int buflen; | |
87 { | |
88 struct buf c_b1, *c_btmp; | |
89 int msg_len = Strlen (msg); | |
90 c_btmp = c_b; | |
91 c_b = &c_b1; | |
92 if ((c_b->buffer = (w_char *) malloc ((buflen + msg_len) * 2)) == NULL) | |
93 { | |
94 print_msg_getc (MSG_GET (2)); | |
95 return (-1); | |
96 } | |
97 Strcpy (c_b->buffer, msg); | |
98 c_b->t_m_start = Strlen (c_b->buffer); | |
99 Strcpy (c_b->buffer + msg_len, buffer); | |
100 c_b->buf_msg = ""; | |
101 | |
102 c_b->hanten = mode; | |
103 c_b->start_col = 0; | |
104 c_b->maxlen = Strlen (c_b->buffer); | |
105 c_b->t_c_p = c_b->maxlen; | |
106 c_b->buflen = buflen + msg_len; | |
107 set_screen_vars_default (); | |
108 c_b->redraw_fun = redraw_nisemono; | |
109 c_b->key_table = main_table[6]; | |
110 c_b->rk_clear_tbl = romkan_clear_tbl[6]; | |
111 c_b->key_in_fun = NULL; | |
112 c_b->ctrl_code_fun = (int (*)()) NULL; | |
113 kill_buffer_offset = 0; | |
114 | |
115 init_screen (); | |
116 if (buffer_in () == -1) | |
117 { | |
118 free (c_b->buffer); | |
119 c_b = c_btmp; | |
120 return (-1); | |
121 } | |
122 free (c_b->buffer); | |
123 Strncpy (buffer, c_b->buffer + msg_len, c_b->maxlen - msg_len); | |
124 buffer[c_b->maxlen - msg_len] = 0; | |
125 c_b = c_btmp; | |
126 return (0); | |
127 } | |
128 | |
129 /** bufferを使って、仮名文字列を入力します。 | |
130 kana_in_w_char_msgとの違いは、 | |
131 msgが、charであることと、横にスクロールする時には、このメッセージを除いて | |
132 スクロールすること。 | |
133 */ | |
134 int | |
135 kana_in (msg, mode, buffer, buflen) | |
136 char *msg; | |
137 int mode; | |
138 w_char *buffer; | |
139 int buflen; | |
140 { | |
141 struct buf c_b1, *c_btmp; | |
142 | |
143 c_btmp = c_b; | |
144 c_b = &c_b1; | |
145 | |
146 c_b->buffer = buffer; | |
147 c_b->buf_msg = msg; | |
148 | |
149 c_b->hanten = mode; | |
150 c_b->start_col = strlen (msg); | |
151 c_b->maxlen = Strlen (buffer); | |
152 c_b->t_c_p = c_b->maxlen; | |
153 c_b->buflen = buflen; | |
154 c_b->t_m_start = -2; | |
155 set_screen_vars_default (); | |
156 c_b->key_table = main_table[6]; | |
157 c_b->rk_clear_tbl = romkan_clear_tbl[6]; | |
158 c_b->key_in_fun = NULL; | |
159 c_b->redraw_fun = redraw_nisemono; | |
160 c_b->ctrl_code_fun = (int (*)()) NULL; | |
161 kill_buffer_offset = 0; | |
162 | |
163 init_screen (); | |
164 if (buffer_in () == -1) | |
165 { | |
166 c_b = c_btmp; | |
167 return (-1); | |
168 } | |
169 c_b->buffer[c_b->maxlen] = 0; | |
170 c_b = c_btmp; | |
171 return (0); | |
172 } | |
173 | |
174 /** かな入力を行い、画面制御するための基本ルーチン | |
175 グローバル変数c_bの指す所(struct buf)に、種種な初期設定をしてから | |
176 これを呼んで下さい。 | |
177 文字列は、c_b->bufferに入って終了します。 | |
178 c_b->maxlenに文字列の長さが入ります。 | |
179 */ | |
180 int | |
181 buffer_in () | |
182 { | |
183 int c; | |
184 int ret; | |
185 int romkan; | |
186 int ignored = 0; | |
187 int not_redrawtmp = not_redraw; | |
188 int tmp_send = 0; | |
189 int in; | |
190 unsigned int *output; | |
191 | |
192 extern int kakutei (); | |
193 extern int send_string (); | |
194 extern int return_it (); | |
195 | |
196 not_redraw = 0; | |
197 while (1) | |
198 { | |
199 | |
200 if (uum_cursor_invisible && !cursor_invisible_fun) | |
201 { | |
202 throw_col (maxlength - 1); | |
203 flush (); | |
204 } | |
205 if (if_unget_buf ()) | |
206 { | |
207 output = get_unget_buf (); | |
208 } | |
209 else | |
210 { | |
211 in = keyin (); | |
212 output = romkan_henkan (in); | |
213 } | |
214 | |
215 conv_ltr_to_ieuc (output); | |
216 if (input_func) | |
217 (*input_func) (output, output); | |
218 | |
219 for (; *output != EOLTTR; output++) | |
220 { | |
221 c = ((romkan = *output) & 0x0000ffff); | |
222 if (uum_cursor_invisible && !cursor_invisible_fun) | |
223 { | |
224 t_throw (); | |
225 } | |
226 | |
227 if (isSPCL (romkan)) | |
228 { | |
229 if (romkan == REDRAW) | |
230 { | |
231 (*c_b->redraw_fun) (); | |
232 continue; | |
233 } | |
234 else if (romkan == CHMSIG) | |
235 { /* mode changed */ | |
236 if (redraw_when_chmsig_func) | |
237 (*redraw_when_chmsig_func) (); | |
238 disp_mode (); | |
239 continue; | |
240 } | |
241 else if (romkan == NISEBP) | |
242 { /* error */ | |
243 ring_bell (); | |
244 continue; | |
245 } | |
246 else | |
247 continue; /* if (romkan == EOLTTR) */ | |
248 } | |
249 if (ignored) | |
250 { | |
251 if (isNISE (romkan)) | |
252 { | |
253 if (c == rubout_code) | |
254 { | |
255 --ignored; | |
256 } | |
257 else | |
258 { | |
259 ++ignored; | |
260 } | |
261 } | |
262 else | |
263 { | |
264 ignored = 0; | |
265 } | |
266 continue; | |
267 } | |
268 /* 偽物のコントロールコードは画面表示しないので後で来るrubout | |
269 のコードも無視する必要がある。ignoredは無視すべき | |
270 ruboutの個数を保持する。 */ | |
271 if (isNISE (romkan) && (ESCAPE_CHAR (c) || NOT_NORMAL_CHAR (c)) && c != rubout_code) | |
272 { | |
273 ++ignored; | |
274 continue; | |
275 } | |
276 | |
277 if (c < TBL_SIZE && c_b->key_table[c]) | |
278 { | |
279 if (c_b->rk_clear_tbl[c]) | |
280 romkan_clear (); | |
281 ret = (*c_b->key_table[c]) (c, romkan); | |
282 /* Because 1byte-kana is 0xa0-0xff | |
283 }else if(c >= 0x80 && c < 0xff){ | |
284 */ | |
285 } | |
286 else if (c >= 0x80 && c <= 0x9f) | |
287 { | |
288 if (tmp_send) | |
289 { | |
290 ret = return_it (c, romkan); | |
291 tmp_send = 0; | |
292 } | |
293 else | |
294 { | |
295 ret = 0; | |
296 ring_bell (); | |
297 } | |
298 } | |
299 else if (!(ESCAPE_CHAR (c)) || c == 0x09) | |
300 { /* TAB is not ESCAPE char */ | |
301 if (c_b->maxlen < c_b->buflen) | |
302 { | |
303 if (tmp_send) | |
304 { | |
305 ret = return_it (c); | |
306 tmp_send = 0; | |
307 } | |
308 else if (c_b->key_in_fun) | |
309 { | |
310 ret = (*c_b->key_in_fun) (c, romkan); | |
311 } | |
312 else | |
313 { | |
314 ret = insert_char (c); | |
315 call_t_redraw_move (c_b->t_c_p + 1, c_b->t_c_p, c_b->maxlen, 0, 1); | |
316 if (henkan_on_kuten && c_b->t_c_p == c_b->maxlen) | |
317 henkan_if_maru (c); | |
318 } | |
319 } | |
320 else | |
321 { | |
322 romkan_clear (); | |
323 ret = 0; | |
324 } | |
325 | |
326 } | |
327 else | |
328 { | |
329 if (c_b->ctrl_code_fun) | |
330 { | |
331 ret = (*c_b->ctrl_code_fun) (c, romkan); | |
332 } | |
333 else | |
334 { | |
335 ret = 0; | |
336 ring_bell (); | |
337 } | |
338 } | |
339 if (ret == 1) | |
340 { | |
341 not_redraw = not_redrawtmp; | |
342 return (0); | |
343 } | |
344 else if (ret == -1) | |
345 { | |
346 not_redraw = not_redrawtmp; | |
347 return (-1); | |
348 } | |
349 } | |
350 } | |
351 } | |
352 | |
353 int | |
354 t_rubout (c, romkan) | |
355 int c, romkan; | |
356 { | |
357 | |
358 if (c_b->t_c_p != 0) | |
359 { | |
360 backward (); | |
361 t_delete_char (); | |
362 } | |
363 return (0); | |
364 } | |
365 | |
366 | |
367 void | |
368 delete_char1 () | |
369 { | |
370 if (c_b->t_c_p < c_b->maxlen) | |
371 { | |
372 Strncpy (c_b->buffer + c_b->t_c_p, c_b->buffer + c_b->t_c_p + 1, c_b->maxlen - c_b->t_c_p - 1); | |
373 c_b->maxlen -= 1; | |
374 } | |
375 } | |
376 | |
377 int | |
378 t_delete_char () | |
379 { | |
380 delete_char1 (); | |
381 call_t_redraw_move (c_b->t_c_p, c_b->t_c_p, c_b->maxlen, 2, 1); | |
382 return (0); | |
383 } | |
384 | |
385 extern int in_kuten (); | |
386 extern int in_jis (); | |
387 | |
388 int | |
389 kuten () | |
390 { | |
391 input_a_char_from_function (in_kuten); | |
392 return (0); | |
393 } | |
394 | |
395 int | |
396 jis () | |
397 { | |
398 input_a_char_from_function (in_jis); | |
399 return (0); | |
400 } | |
401 | |
402 int | |
403 input_a_char_from_function (fun) | |
404 int (*fun) (); | |
405 { | |
406 int c; | |
407 int ret = 0; | |
408 | |
409 if ((c = (*fun) ()) != -1) | |
410 { | |
411 if (c_b->key_in_fun) | |
412 { | |
413 ret = (*c_b->key_in_fun) (c, c); | |
414 } | |
415 else | |
416 { | |
417 ret = insert_char (c); | |
418 t_redraw_move (c_b->t_c_p + 1, c_b->t_c_p, c_b->maxlen, 0); | |
419 } | |
420 } | |
421 redraw_line (); | |
422 return (ret); | |
423 } | |
424 | |
425 int | |
426 t_kill () | |
427 { | |
428 kill_buffer_offset = min (c_b->maxlen - c_b->t_c_p, maxchg); | |
429 Strncpy (kill_buffer, c_b->buffer + c_b->t_c_p, kill_buffer_offset); | |
430 c_b->maxlen = c_b->t_c_p; | |
431 t_redraw_move (c_b->t_c_p, c_b->t_c_p, c_b->maxlen, 1); | |
432 return (0); | |
433 } | |
434 | |
435 | |
436 int | |
437 t_yank () | |
438 { | |
439 if (kill_buffer_offset <= c_b->buflen - c_b->t_c_p) | |
440 { | |
441 Strncpy (c_b->buffer + c_b->t_c_p + kill_buffer_offset, c_b->buffer + c_b->t_c_p, c_b->maxlen - c_b->t_c_p); | |
442 Strncpy (c_b->buffer + c_b->t_c_p, kill_buffer, kill_buffer_offset); | |
443 c_b->maxlen += kill_buffer_offset; | |
444 call_t_redraw_move (c_b->t_c_p + kill_buffer_offset, c_b->t_c_p, c_b->maxlen, 0, 1); | |
445 } | |
446 return (0); | |
447 } | |
448 | |
449 int | |
450 t_ret () | |
451 { | |
452 return (1); | |
453 } | |
454 | |
455 int | |
456 t_quit () | |
457 { | |
458 return (-1); | |
459 } | |
460 | |
461 | |
462 int | |
463 c_top () | |
464 { | |
465 (*c_top_func) (); | |
466 return (0); | |
467 } | |
468 | |
469 int | |
470 c_end () | |
471 { | |
472 (*c_end_func) (); | |
473 return (0); | |
474 } | |
475 | |
476 int | |
477 c_end_nobi () | |
478 { | |
479 (*c_end_nobi_func) (); | |
480 return (0); | |
481 } | |
482 | |
483 int | |
484 t_jmp_backward () | |
485 { | |
486 int k; | |
487 | |
488 for (k = 1; k < touroku_bnst_cnt; k++) | |
489 { | |
490 if (touroku_bnst[k] >= c_b->t_c_p) | |
491 { | |
492 if (touroku_bnst[k - 1] >= c_b->t_m_start) | |
493 { | |
494 call_t_redraw_move_1 (touroku_bnst[k - 1], touroku_bnst[k - 1], c_b->maxlen, 0, 1, 0, 3); | |
495 } | |
496 else | |
497 { | |
498 c_top (); | |
499 } | |
500 return (0); | |
501 } | |
502 } | |
503 backward (); | |
504 return (0); | |
505 } | |
506 | |
507 int | |
508 t_jmp_forward () | |
509 { | |
510 int k; | |
511 | |
512 for (k = 1; k < touroku_bnst_cnt; k++) | |
513 { | |
514 if (touroku_bnst[k] > c_b->t_c_p) | |
515 { | |
516 call_t_redraw_move_1 (touroku_bnst[k], c_b->t_c_p, c_b->maxlen, 0, 1, 0, 3); | |
517 return (0); | |
518 } | |
519 } | |
520 forward_char (); | |
521 return (0); | |
522 } | |
523 | |
524 | |
525 int | |
526 forward_char () | |
527 { | |
528 if (c_b->t_c_p < c_b->maxlen) | |
529 { | |
530 call_t_redraw_move_2 (c_b->t_c_p + 1, c_b->t_c_p, c_b->t_m_start, c_b->t_c_p + 2, c_b->t_c_p + 1, 0, 1); | |
531 } | |
532 return (0); | |
533 } | |
534 | |
535 int | |
536 forward () | |
537 { | |
538 if (c_b->t_c_p < c_b->maxlen) | |
539 { | |
540 t_move (c_b->t_c_p + 1); | |
541 } | |
542 return (0); | |
543 } | |
544 | |
545 int | |
546 backward_char () | |
547 { | |
548 if (c_b->t_c_p >= 1 && c_b->t_c_p > c_b->t_m_start) | |
549 { | |
550 call_t_redraw_move_2 (c_b->t_c_p - 1, c_b->t_c_p - 1, c_b->t_m_start, c_b->t_c_p + 1, c_b->t_c_p, 0, 1); | |
551 } | |
552 return (0); | |
553 } | |
554 | |
555 int | |
556 backward () | |
557 { | |
558 if (c_b->t_c_p >= 1 && c_b->t_c_p > c_b->t_m_start) | |
559 { | |
560 t_move (c_b->t_c_p - 1); | |
561 } | |
562 return (0); | |
563 } | |
564 | |
565 int | |
566 insert_char (c) | |
567 w_char c; | |
568 { | |
569 if (c_b->maxlen < c_b->buflen) | |
570 { | |
571 Strncpy (c_b->buffer + c_b->t_c_p + 1, c_b->buffer + c_b->t_c_p, c_b->maxlen - c_b->t_c_p); | |
572 c_b->maxlen += 1; | |
573 c_b->buffer[c_b->t_c_p] = c; | |
574 } | |
575 return (0); | |
576 } | |
577 | |
578 #ifdef nodef | |
579 int | |
580 insert_string (string, len) | |
581 w_char *string; | |
582 int len; | |
583 { | |
584 if (c_b->maxlen + len <= c_b->buflen) | |
585 { | |
586 Strncpy (c_b->buffer + c_b->t_c_p + len, c_b->buffer + c_b->t_c_p, c_b->maxlen - c_b->t_c_p); | |
587 Strncpy (c_b->buffer + c_b->t_c_p, string, len); | |
588 c_b->maxlen += len; | |
589 } | |
590 } | |
591 #endif | |
592 | |
593 /** vlenとduplicateを適当と思われる状態に設定します。*/ | |
594 void | |
595 set_screen_vars_default () | |
596 { | |
597 c_b->vlen = maxlength * conv_lines - c_b->start_col - 3 - disp_mode_length; | |
598 c_b->vst = 0; | |
599 c_b->duplicate = max ((c_b->vlen + 3) >> 2, 2); | |
600 } | |
601 | |
602 int | |
603 quote () | |
604 { | |
605 int c; | |
606 c = keyin (); | |
607 if (c_b->key_table[c] == henkan_off) | |
608 { | |
609 (*c_b->key_table[c]) (); | |
610 return (0); | |
611 } | |
612 if (empty_modep () && c_b->key_in_fun) | |
613 return ((*c_b->key_in_fun) (c, c)); | |
614 insert_char (c); | |
615 t_redraw_move (c_b->t_c_p + 1, c_b->t_c_p, c_b->maxlen, 0); | |
616 return (0); | |
617 } |