0
|
1 /*
|
|
2 * $Id: jis_in.c,v 1.3 2001/06/14 18:16:07 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 FreeWnn Project 1999, 2000
|
|
14 *
|
|
15 * Maintainer: FreeWnn Project <freewnn@tomo.gr.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 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 * JIS 入力のためのプログラム
|
|
34 * programs for JIS NYUURYOKU
|
|
35 */
|
|
36
|
|
37 #include <stdio.h>
|
|
38 #include <ctype.h>
|
|
39 #include "commonhd.h"
|
|
40 #include "sdefine.h"
|
|
41 #include "sheader.h"
|
|
42
|
|
43 #define FROM_JIS 0x21
|
|
44 #define TO_JIS 0x7E
|
|
45
|
|
46 static int get_jis_ichiran ();
|
|
47
|
|
48 int
|
|
49 in_jis () /* returns code for a moji */
|
|
50 {
|
|
51 char buffer[5];
|
|
52 int code;
|
|
53 int c_p = 0; /* 何文字はいったかを示す */
|
|
54 int c, k;
|
|
55 extern int t_quit ();
|
|
56 extern int henkan_off ();
|
|
57 int not_redrawtmp = not_redraw;
|
|
58 not_redraw = 1; /*リドローしない */
|
|
59
|
|
60 for (k = 0; k < 5; k++)
|
|
61 {
|
|
62 buffer[k] = ' ';
|
|
63 }
|
|
64
|
|
65 completely_start:
|
|
66 throw_c (0); /* モード表示の後に出す */
|
|
67 printf (MSG_GET (6));
|
|
68 /*
|
|
69 printf("JISコード: ");
|
|
70 */
|
|
71 clr_line ();
|
|
72 flush ();
|
|
73 start:
|
|
74 while (1)
|
|
75 {
|
|
76
|
|
77 throw_c (10);
|
|
78 h_r_on ();
|
|
79 for (k = 0; k < 4; k++)
|
|
80 {
|
|
81 putchar (buffer[k]);
|
|
82 }
|
|
83 h_r_off ();
|
|
84 clr_line ();
|
|
85 flush ();
|
|
86
|
|
87 c = keyin ();
|
|
88 if ((c == ESC) || (t_quit == main_table[5][c]))
|
|
89 {
|
|
90 throw_c (0);
|
|
91 clr_line ();
|
|
92 flush ();
|
|
93 not_redraw = not_redrawtmp;
|
|
94 return (-1);
|
|
95 }
|
|
96 else if (henkan_off == main_table[5][c])
|
|
97 { /*きたない! */
|
|
98 henkan_off ();
|
|
99 }
|
|
100 else if (c_p < 4 && ((c <= '9' && c >= '0') || (c <= 'F' && c >= 'A') || (c <= 'f' && c >= 'a')))
|
|
101 {
|
|
102 if ((c_p == 0 || c_p == 2) ? (c <= 'F' && c >= 'A') || /* For EUC */
|
|
103 (c <= 'f' && c >= 'a') || /* For EUC */
|
|
104 (c <= '7' && c >= '2') :
|
|
105 !(((buffer[c_p - 1] == '2' ||
|
|
106 buffer[c_p - 1] == 'A' || buffer[c_p - 1] == 'a') && c == '0') || ((buffer[c_p - 1] == '7' || buffer[c_p - 1] == 'F' || buffer[c_p - 1] == 'f') && (c == 'F' || c == 'f'))))
|
|
107 {
|
|
108 buffer[c_p++] = (char) c;
|
|
109 }
|
|
110 else
|
|
111 {
|
|
112 ring_bell ();
|
|
113 }
|
|
114 }
|
|
115 else if (c == rubout_code && c_p)
|
|
116 {
|
|
117 buffer[--c_p] = ' ';
|
|
118 }
|
|
119 else if (c == rubout_code && c_p == 0)
|
|
120 {
|
|
121 throw_c (0);
|
|
122 clr_line ();
|
|
123 flush ();
|
|
124 not_redraw = not_redrawtmp;
|
|
125 return (-1);
|
|
126 }
|
|
127 else if (c == NEWLINE || c == CR)
|
|
128 {
|
|
129 if (c_p <= 1)
|
|
130 {
|
|
131 goto start;
|
|
132 }
|
|
133 else if (c_p == 4)
|
|
134 {
|
|
135 code = 0;
|
|
136 for (k = 0; k < 4; k++)
|
|
137 {
|
|
138 code = code * 16 + hextodec (buffer[k]);
|
|
139 }
|
|
140 code |= 0x8080; /* ujis にして返す */
|
|
141 break;
|
|
142 }
|
|
143 if ((code = get_jis_ichiran (buffer, c_p)) == -1)
|
|
144 {
|
|
145 goto completely_start;
|
|
146 }
|
|
147 break;
|
|
148 }
|
|
149 else
|
|
150 {
|
|
151 ring_bell ();
|
|
152 }
|
|
153 }
|
|
154 throw_c (0);
|
|
155 clr_line ();
|
|
156 not_redraw = not_redrawtmp;
|
|
157 return (code);
|
|
158 }
|
|
159
|
|
160 int
|
|
161 hextodec (c)
|
|
162 char c;
|
|
163 {
|
|
164 if (c >= '0' && c <= '9')
|
|
165 {
|
|
166 return (c - '0');
|
|
167 }
|
|
168 else if (c >= 'A' && c <= 'F')
|
|
169 {
|
|
170 return (c - 'A' + 10);
|
|
171 }
|
|
172 else if (c >= 'a' && c <= 'f')
|
|
173 {
|
|
174 return (c - 'a' + 10);
|
|
175 }
|
|
176 else
|
|
177 return (-1);
|
|
178 }
|
|
179
|
|
180
|
|
181 static int
|
|
182 get_jis_ichiran (st, num)
|
|
183 char *st;
|
|
184 int num;
|
|
185 {
|
|
186 int from;
|
|
187 int i;
|
|
188 char *c;
|
|
189 int maxh;
|
|
190 int code;
|
|
191 char buf[512];
|
|
192 char *buf_ptr[96];
|
|
193
|
|
194 if (num == 2)
|
|
195 {
|
|
196 from = hextodec (st[0]) << (8 + 4) | hextodec (st[1]) << 8 | 0x21;
|
|
197 from |= 0x8080;
|
|
198 maxh = 94;
|
|
199 }
|
|
200 else
|
|
201 {
|
|
202 from = hextodec (st[0]) << (8 + 4) | hextodec (st[1]) << 8 | hextodec (st[2]) << 4;
|
|
203 from |= 0x8080;
|
|
204 maxh = 16;
|
|
205 if ((from & 0xf0) == 0xf0)
|
|
206 {
|
|
207 maxh--;
|
|
208 }
|
|
209 else if ((from & 0xf0) == 0xa0)
|
|
210 {
|
|
211 maxh--;
|
|
212 from++;
|
|
213 }
|
|
214 }
|
|
215
|
|
216 for (i = 0, c = buf; i < maxh; i++)
|
|
217 {
|
|
218 code = from + i;
|
|
219 buf_ptr[i] = c;
|
|
220 *c++ = (code & 0xff00) >> 8;
|
|
221 *c++ = (code & 0x00ff);
|
|
222 *c++ = 0;
|
|
223 }
|
|
224 if ((i = select_one_element (buf_ptr, maxh, 0, "", 0, 0, main_table[4])) == -1)
|
|
225 {
|
|
226 return (-1);
|
|
227 }
|
|
228 return (from + i);
|
|
229 }
|