0
|
1 /*
|
|
2 * $Id: key_bind.c,v 1.5 2002/03/30 01:45:41 hiroo 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
|
|
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 0: 変換後、変換結果を修正しているモード
|
|
34 1: 変換前の文字列を入力しているモード
|
|
35 2: 変換後、文節の区切りを伸ばしたり縮めたりしているモード
|
|
36 3: バッファに文字が何も入っていないモード
|
|
37 4: カーソルを動かしながら、何か候補を選択する時のモード
|
|
38 5: 単語登録時に、漢字の範囲を設定している時のモード
|
|
39 6: 単語登録時の読み入力などの文字列を入力している時
|
|
40 7: 単語検索のモード
|
|
41 8: 辞書検索のモード
|
|
42 9:インスペクトのモード
|
|
43 */
|
|
44 #ifdef HAVE_CONFIG_H
|
|
45 # include <config.h>
|
|
46 #endif
|
|
47
|
|
48 #include <stdio.h>
|
|
49 #if STDC_HEADERS
|
|
50 # include <stdlib.h>
|
|
51 # include <string.h>
|
|
52 #else
|
|
53 # if HAVE_STRINGS_H
|
|
54 # include <strings.h>
|
|
55 # endif
|
|
56 #endif /* STDC_HEADERS */
|
|
57
|
|
58 #include "commonhd.h"
|
|
59 #include "wnn_config.h"
|
|
60 #include "sdefine.h"
|
|
61 #include "sheader.h"
|
|
62 #define MADA NULL
|
|
63
|
|
64 extern int insert_it_as_yomi ();
|
|
65 extern int select_jikouho ();
|
|
66 extern int select_jikouho_dai ();
|
|
67 extern int jikouho_c ();
|
|
68 extern int zenkouho_c ();
|
|
69 extern int jikouho_dai_c ();
|
|
70 extern int zenkouho_dai_c ();
|
|
71 extern int enlarge_bunsetsu ();
|
|
72 extern int smallen_bunsetsu ();
|
|
73 extern int top_bunsetsu ();
|
|
74 extern int end_bunsetsu ();
|
|
75 extern int ren_henkan ();
|
|
76 extern int tan_henkan ();
|
|
77 extern int tan_henkan_dai ();
|
|
78 extern int nobi_henkan ();
|
|
79 extern int nobi_henkan_dai ();
|
|
80 extern int send_string ();
|
|
81 extern int t_yank ();
|
|
82 extern int yank_c ();
|
|
83 extern int kakutei ();
|
|
84 extern int remember_me ();
|
|
85 extern int reset_line ();
|
|
86 extern int touroku_c ();
|
|
87 extern int forward_char ();
|
|
88 extern int backward_char ();
|
|
89 extern int forward ();
|
|
90 extern int backward ();
|
|
91 extern int c_top ();
|
|
92 extern int c_end ();
|
|
93 extern int c_end_nobi ();
|
|
94 extern int t_quit ();
|
|
95 extern int t_delete_char ();
|
|
96 extern int delete_c ();
|
|
97 extern int t_rubout ();
|
|
98 extern int rubout_c ();
|
|
99 extern int t_markset ();
|
|
100 extern int kuten ();
|
|
101 extern int t_kill ();
|
|
102 extern int kill_c ();
|
|
103 extern int kaijo ();
|
|
104 extern int t_jmp_forward ();
|
|
105 extern int t_jmp_backward ();
|
|
106 extern int t_ret ();
|
|
107 extern int previous_history ();
|
|
108 extern int next_history ();
|
|
109 extern int forward_bunsetsu ();
|
|
110 extern int backward_bunsetsu ();
|
|
111 extern int jutil_c ();
|
|
112 extern int jis ();
|
|
113 extern int tijime ();
|
|
114 extern int jmptijime ();
|
|
115 extern int henkan_forward ();
|
|
116 extern int henkan_backward ();
|
|
117 extern int backward_c ();
|
|
118 extern int quote ();
|
|
119 extern int send_ascii ();
|
|
120 extern int not_send_ascii ();
|
|
121 extern int toggle_send_ascii ();
|
|
122 extern int send_ascii_e ();
|
|
123 extern int not_send_ascii_e ();
|
|
124 extern int toggle_send_ascii_e ();
|
|
125 extern int pop_send_ascii ();
|
|
126 extern int pop_send_ascii_e ();
|
|
127 extern int quote_send_ascii_e ();
|
|
128 extern int reconnect_jserver ();
|
|
129
|
|
130 extern int select_select ();
|
|
131 extern int quit_select ();
|
|
132 extern int lineend_select ();
|
|
133 extern int linestart_select ();
|
|
134 extern int redraw_select ();
|
|
135 extern int previous_select ();
|
|
136 extern int next_select ();
|
|
137 extern int backward_select ();
|
|
138 extern int forward_select ();
|
|
139
|
|
140 extern int select_select_line ();
|
|
141 extern int quit_select_line ();
|
|
142 extern int lineend_select_line ();
|
|
143 extern int linestart_select_line ();
|
|
144 extern int redraw_select_line ();
|
|
145 extern int previous_select_line ();
|
|
146 extern int next_select_line ();
|
|
147 extern int backward_select_line ();
|
|
148 extern int forward_select_line ();
|
|
149 extern int inspect_kouho ();
|
|
150 extern int sakujo_kouho ();
|
|
151
|
|
152 extern int henkan_off ();
|
|
153
|
|
154 extern int kdicdel ();
|
|
155 extern int kdicuse ();
|
|
156 extern int kdiccom ();
|
|
157 extern int kworddel ();
|
|
158 extern int kworduse ();
|
|
159 extern int kwordcom ();
|
|
160 extern int kwordima ();
|
|
161 extern int kwordhindo ();
|
|
162
|
|
163 extern int inspectdel ();
|
|
164 extern int inspectuse ();
|
|
165 extern int previous_inspect ();
|
|
166 extern int next_inspect ();
|
|
167
|
|
168 extern int kankana_ren_henkan ();
|
|
169
|
|
170 static struct kansuu kansuu_hyo[] = {
|
|
171 {"send_string", "send what is in the buffer to pty.", 0, send_string, send_string, send_string, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
172 {"forward_char", "cursor wo hitotu maeni susumeru.", 1, forward_bunsetsu, forward_char, henkan_forward, NULL, NULL, forward_char, forward_char, NULL, NULL, NULL},
|
|
173 {"backward_char", "cursor wo hitotu usironi susumeru.", 1, backward_bunsetsu, backward_c, henkan_backward, NULL, NULL, backward_char, backward_char, NULL, NULL, NULL},
|
|
174 {"goto_top_of_line", "", 1, top_bunsetsu, c_top, jmptijime, NULL, NULL, c_top, c_top, NULL, NULL, NULL},
|
|
175 {"goto_end_of_line", "", 1, end_bunsetsu, c_end, c_end_nobi, NULL, NULL, c_end, c_end, NULL, NULL, NULL},
|
|
176 {"delete_char_at_cursor", "", 1, NULL, delete_c, NULL, NULL, NULL, t_delete_char, t_delete_char, NULL, NULL, NULL},
|
|
177 {"kaijo", "", 0, kaijo, NULL, kaijo, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
178 {"henkan", "", 1, NULL, ren_henkan, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
179 {"tan_henkan", "", 1, NULL, tan_henkan, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
180 {"tan_henkan_dai", "", 1, NULL, tan_henkan_dai, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
181 {"jikouho", "", 0, jikouho_c, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
182 {"zenkouho", "", 0, zenkouho_c, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
183 {"jikouho_dai", "", 0, jikouho_dai_c, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
184 {"zenkouho_dai", "", 0, zenkouho_dai_c, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
185 {"select_jikouho", "", 0, select_jikouho, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
186 {"select_jikouho_dai", "", 0, select_jikouho_dai, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
187 {"kill", "", 1, NULL, kill_c, NULL, NULL, NULL, t_kill, t_kill, NULL, NULL, NULL},
|
|
188 {"yank", "", 1, NULL, yank_c, NULL, NULL, NULL, t_yank, t_yank, NULL, NULL, NULL},
|
|
189 {"yank_e", "", 1, NULL, yank_c, NULL, yank_c, NULL, t_yank, t_yank, NULL, NULL, NULL},
|
|
190 {"bunsetu_nobasi", "", 0, enlarge_bunsetsu, NULL, forward, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
191 {"bunsetu_chijime", "", 0, smallen_bunsetsu, NULL, tijime, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
192 {"jisho_utility", "", 0, jutil_c, jutil_c, jutil_c, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
193 {"jisho_utility_e", "", 0, jutil_c, jutil_c, jutil_c, jutil_c, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
194 {"touroku", "", 1, touroku_c, touroku_c, touroku_c, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
195 {"touroku_e", "", 1, touroku_c, touroku_c, touroku_c, touroku_c, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
196 {"kakutei", "", 1, kakutei, kakutei, kakutei, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
197 {"sainyuuryoku", "", 1, NULL, remember_me, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
198 {"sainyuuryoku_e", "", 1, NULL, remember_me, NULL, remember_me, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
199 {"kuten", "", 0, NULL, kuten, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
200 {"kuten_e", "", 0, NULL, kuten, NULL, kuten, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
201 {"jis", "", 0, NULL, jis, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
202 {"jis_e", "", 0, NULL, jis, NULL, jis, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
203 {"redraw_line", "", 1, reset_line, reset_line, reset_line, NULL, redraw_select, reset_line, reset_line, redraw_select_line, redraw_select_line, redraw_select_line},
|
|
204 {"redraw_line_e", "", 1, reset_line, reset_line, reset_line, reset_line, redraw_select, reset_line, reset_line, redraw_select_line, redraw_select_line, redraw_select_line},
|
|
205 {"previous_history_e", "", 1, NULL, previous_history, NULL, previous_history, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
206 {"previous_history", "", 1, NULL, previous_history, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
207 {"next_history_e", "", 1, NULL, next_history, NULL, next_history, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
208 {"next_history", "", 1, NULL, next_history, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
209 {"touroku_mark_set", "", 0, NULL, NULL, NULL, NULL, NULL, t_markset, NULL, NULL, NULL, NULL},
|
|
210 {"touroku_return", "", 0, NULL, NULL, NULL, NULL, NULL, NULL, t_ret, NULL, NULL, NULL},
|
|
211 {"quit", "", 0, NULL, NULL, NULL, NULL, quit_select, t_quit, t_quit, quit_select_line, quit_select_line, quit_select_line},
|
|
212 {"touroku_jump_forward", "", 0, NULL, NULL, NULL, NULL, NULL, t_jmp_forward, NULL, NULL, NULL, NULL},
|
|
213 {"touroku_jump_backward", "", 0, NULL, NULL, NULL, NULL, NULL, t_jmp_backward, NULL, NULL, NULL, NULL},
|
|
214 {"change_to_insert_mode", "", 0, insert_it_as_yomi, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
215 {"quote_e", "", 0, NULL, quote, NULL, quote, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
216 {"quote", "", 0, NULL, quote, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
217 {"send_ascii_char", "", 0, send_ascii, send_ascii, send_ascii, send_ascii_e, send_ascii, send_ascii, send_ascii, send_ascii, send_ascii, send_ascii},
|
|
218
|
|
219 {"toggle_send_ascii_char", "", 0, toggle_send_ascii, toggle_send_ascii, toggle_send_ascii, toggle_send_ascii_e, toggle_send_ascii, toggle_send_ascii, toggle_send_ascii, toggle_send_ascii,
|
|
220 toggle_send_ascii, toggle_send_ascii},
|
|
221 {"not_send_ascii_char", "", 0, not_send_ascii, not_send_ascii, not_send_ascii, not_send_ascii_e, not_send_ascii, not_send_ascii, not_send_ascii, not_send_ascii, not_send_ascii, not_send_ascii},
|
|
222 {"pop_send_ascii_char", "", 0, pop_send_ascii, pop_send_ascii, pop_send_ascii, pop_send_ascii_e, pop_send_ascii, pop_send_ascii, pop_send_ascii, pop_send_ascii, pop_send_ascii, pop_send_ascii},
|
|
223 {"quote_send_ascii_char", "", 0, NULL, NULL, NULL, quote_send_ascii_e, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
224 {"select_select", "", 0, NULL, NULL, NULL, NULL, select_select, NULL, NULL, select_select_line, select_select_line, select_select_line},
|
|
225 {"lineend_select", "", 0, NULL, NULL, NULL, NULL, lineend_select, NULL, NULL, lineend_select_line, lineend_select_line, lineend_select_line},
|
|
226 {"linestart_select", "", 0, NULL, NULL, NULL, NULL, linestart_select, NULL, NULL, linestart_select_line, linestart_select_line, linestart_select_line},
|
|
227 {"previous_select", "", 0, NULL, NULL, NULL, NULL, previous_select, NULL, NULL, previous_select_line, previous_select_line, previous_inspect},
|
|
228 {"next_select", "", 0, NULL, NULL, NULL, NULL, next_select, NULL, NULL, next_select_line, next_select_line, next_inspect},
|
|
229 {"backward_select", "", 0, NULL, NULL, NULL, NULL, backward_select, NULL, NULL, backward_select_line, backward_select_line, backward_select_line},
|
|
230 {"forward_select", "", 0, NULL, NULL, NULL, NULL, forward_select, NULL, NULL, forward_select_line, forward_select_line, forward_select_line},
|
|
231
|
|
232 {"reconnect_jserver", "", 0, reconnect_jserver, reconnect_jserver, reconnect_jserver, NULL, reconnect_jserver, reconnect_jserver, reconnect_jserver, reconnect_jserver, reconnect_jserver,
|
|
233 reconnect_jserver},
|
|
234 {"henkan_on", "", 0, henkan_off, henkan_off, henkan_off, henkan_off, henkan_off, henkan_off, henkan_off, henkan_off, henkan_off, henkan_off},
|
|
235 {"inspect", "", 0, inspect_kouho, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
236 {"sakujo_kouho", "", 0, sakujo_kouho, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
237 {"nobi_henkan_dai", "", 0, NULL, NULL, nobi_henkan_dai, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
238 {"nobi_henkan", "", 0, NULL, NULL, nobi_henkan, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
239 {"del_entry", "", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, kworddel, kdicdel, inspectdel},
|
|
240 {"use_entry", "", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, kworduse, kdicuse, inspectuse},
|
|
241 {"com_entry", "", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, kwordcom, kdiccom, NULL},
|
|
242 {"kana_henkan", "", 1, NULL, kankana_ren_henkan, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
|
243 {"hindo_set", "", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, kwordhindo, NULL, NULL},
|
|
244 {"ima_bit", "", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, kwordima, NULL, NULL}
|
|
245 };
|
|
246
|
|
247 int kansuu_hyo_entry_suu = sizeof (kansuu_hyo) / sizeof (struct kansuu);
|
|
248
|
|
249 static char key_binded[sizeof (kansuu_hyo) / sizeof (struct kansuu) + 1];
|
|
250
|
|
251 int key_binding ();
|
|
252
|
|
253 int
|
|
254 init_key_table ()
|
|
255 {
|
|
256 FILE *fp, *fopen ();
|
|
257 char file_name[PATHNAMELEN];
|
|
258 int j, k;
|
|
259
|
|
260 for (k = 0; k < sizeof (kansuu_hyo) / sizeof (struct kansuu); k++)
|
|
261 {
|
|
262 key_binded[k] = 0;
|
|
263 }
|
|
264
|
|
265 /* uumrcファイルから。 */
|
|
266 if (uumkey_name_in_uumrc[0] != '\0')
|
|
267 {
|
|
268 strcpy (file_name, uumkey_name_in_uumrc);
|
|
269 }
|
|
270 else if (strcpy (file_name, LIBDIR), strcat (file_name, "/"), strcat (file_name, lang_dir), strcat (file_name, CPFILE), (fp = fopen (file_name, "r")) != NULL)
|
|
271 {
|
|
272 /* default */
|
|
273 fclose (fp);
|
|
274 }
|
|
275 else
|
|
276 {
|
|
277 /* fprintf(stderr, "Can't open default key bind file.%s\n" , CPFILE); */
|
|
278 /* fprintf(stderr,"デフォルトのキーバインドが異常です。 %s\n",CPFILE); */
|
|
279 fprintf (stderr, MSG_GET (29), CPFILE);
|
|
280 return (-1);
|
|
281 }
|
|
282
|
|
283 for (j = 0; j < 3; j++)
|
|
284 {
|
|
285 /*
|
|
286 for(k = 0; k < 32;k++){
|
|
287 main_table[j][k] = null_fun;
|
|
288 }
|
|
289 */
|
|
290 for (k = 0; k < TBL_SIZE; k++)
|
|
291 {
|
|
292 main_table[j][k] = NULL;
|
|
293 }
|
|
294 main_table[j][NEWLINE] = (int (*)()) 0;
|
|
295 main_table[j][CR] = (int (*)()) 0;
|
|
296 }
|
|
297 for (j = 3; j < TBL_CNT; j++)
|
|
298 {
|
|
299 for (k = 0; k < TBL_SIZE; k++)
|
|
300 {
|
|
301 main_table[j][k] = NULL;
|
|
302 }
|
|
303 }
|
|
304 if (key_binding (file_name) == -1)
|
|
305 return (-1);
|
|
306 return (0);
|
|
307 }
|
|
308
|
|
309
|
|
310 int
|
|
311 key_binding (file_name)
|
|
312 char file_name[64];
|
|
313 {
|
|
314 register int k, kk;
|
|
315 FILE *fp, *fopen ();
|
|
316 char func_name[64];
|
|
317 int com_cnt;
|
|
318 int com_num;
|
|
319 char buf[256];
|
|
320 char com_name[16][EXPAND_PATH_LENGTH];
|
|
321 int lc = 0;
|
|
322 int tbl;
|
|
323
|
|
324 if (verbose_option)
|
|
325 fprintf (stderr, "keybind: using keybind-file %s\r\n", file_name);
|
|
326 if ((fp = fopen (file_name, "r")) == NULL)
|
|
327 {
|
|
328 printf ("Key_binding file \"%s\" doesn't exist.\r\n", file_name);
|
|
329 return (-1);
|
|
330 }
|
|
331
|
|
332 for (tbl = 0; tbl < TBL_CNT; tbl++)
|
|
333 {
|
|
334 romkan_clear_tbl[tbl][rubout_code] = 0; /* Not clear romkan when rubout */
|
|
335 }
|
|
336 main_table[1][rubout_code] = rubout_c;
|
|
337 main_table[5][rubout_code] = t_rubout;
|
|
338 main_table[6][rubout_code] = t_rubout;
|
|
339
|
|
340 lc = 0;
|
|
341 while (fgets (buf, 256, fp))
|
|
342 {
|
|
343 lc += 1;
|
|
344 if ((*buf == ';') || (*buf == ':') || (*buf == '\n'))
|
|
345 continue; /* for comment lines */
|
|
346 if ((com_cnt = sscanf (buf, "%s %s %s %s %s %s %s %s %s %s %s", func_name, com_name[0],
|
|
347 com_name[1], com_name[2], com_name[3], com_name[4], com_name[5], com_name[6], com_name[7], com_name[8], com_name[9])) < 2)
|
|
348 { /* able to get at most 9 arguments. */
|
|
349 printf ("uumkey:file %s. Line %d is illegal.\r\n", file_name, lc);
|
|
350 continue; /* every command needs at least 1 argument. */
|
|
351 }
|
|
352
|
|
353 /* henkan_on is treated as like others. so REMOVE below if possible.
|
|
354 if (strcmp(func_name, "henkan_on")== 0){
|
|
355 if ((com_num = expand_argument(com_name[0])) < 0) {
|
|
356 fprintf(stderr,"uumkey: %s に対する %s は不適切なコードです。\r\n",
|
|
357 func_name, com_name[0]);
|
|
358 fflush(stderr);
|
|
359 } else kk_on = com_num;
|
|
360 } else
|
|
361 */
|
|
362 if (strcmp (func_name, "include") == 0)
|
|
363 {
|
|
364 if (0 != expand_expr (com_name[0]))
|
|
365 {
|
|
366 /*
|
|
367 fprintf(stderr,"uumkey: %s を展開できません。\r\n", com_name[0]);
|
|
368 */
|
|
369 fprintf (stderr, MSG_GET (29), com_name[0]);
|
|
370 }
|
|
371 key_binding (com_name[0]);
|
|
372 }
|
|
373 else if (strcmp (func_name, "unset") == 0)
|
|
374 {
|
|
375 if ((k = find_entry (com_name[0])) != -1)
|
|
376 {
|
|
377 key_binded[k] = 0;
|
|
378 remove_key_bind (k);
|
|
379 }
|
|
380 else if (strcmp (com_name[0], "quote_keyin") == 0)
|
|
381 {
|
|
382 quote_code = -1;
|
|
383 }
|
|
384 }
|
|
385 else if (strcmp (func_name, "quote_keyin") == 0)
|
|
386 {
|
|
387 if ((com_num = expand_argument (com_name[0])) < 0)
|
|
388 {
|
|
389 fprintf (stderr, "uumkey: %s is an inappropriate code for %s.\r\n", com_name[0], func_name);
|
|
390 fflush (stderr);
|
|
391 }
|
|
392 else
|
|
393 quote_code = com_num;
|
|
394 }
|
|
395 else
|
|
396 {
|
|
397 for (k = 0; k < kansuu_hyo_entry_suu; k++)
|
|
398 {
|
|
399 if (strcmp (func_name, kansuu_hyo[k].kansuumei) == 0)
|
|
400 { /* found ! */
|
|
401 if (key_binded[k])
|
|
402 {
|
|
403 remove_key_bind (k);
|
|
404 }
|
|
405 key_binded[k] = 1;
|
|
406 for (kk = 0; kk < com_cnt - 1; kk++)
|
|
407 {
|
|
408 com_num = expand_argument (com_name[kk]);
|
|
409 if (com_num < 0)
|
|
410 {
|
|
411 fprintf (stderr, "uumkey: %s is an inappropriate code for %s.\r\n", com_name[kk], func_name);
|
|
412 fflush (stderr);
|
|
413 }
|
|
414 else
|
|
415 {
|
|
416 for (tbl = 0; tbl < TBL_CNT; tbl++)
|
|
417 {
|
|
418 if ((main_table[tbl][com_num] != NULL) && (kansuu_hyo[k].func[tbl] != NULL))
|
|
419 {
|
|
420 /* fprintf(stderr, "uumkey: Duplicate Definition at key: %s.\n",com_name[kk]); */
|
|
421 /*
|
|
422 fprintf(stderr, "uumkey: %s(0x%x)のキーが二重定義です。at line %d (%s)(table No. %d).\r\n",
|
|
423 */
|
|
424 fprintf (stderr, MSG_GET (30), com_name[kk], com_num, lc, kansuu_hyo[k].kansuumei, tbl);
|
|
425 /* fprintf(stderr, "lc = %d,kansuu_hyo %d(%s) ,%d , \
|
|
426 %s(0x%x)のキーが二重定義です。\n",lc,k,kansuu_hyo[k].kansuumei,tbl ,com_name[kk],
|
|
427 com_num);
|
|
428 */
|
|
429 main_table[tbl][com_num] = kansuu_hyo[k].func[tbl];
|
|
430 romkan_clear_tbl[tbl][com_num] = kansuu_hyo[k].romkan_flag;
|
|
431 }
|
|
432 else if (kansuu_hyo[k].func[tbl] != NULL)
|
|
433 {
|
|
434 main_table[tbl][com_num] = kansuu_hyo[k].func[tbl];
|
|
435 romkan_clear_tbl[tbl][com_num] = kansuu_hyo[k].romkan_flag;
|
|
436 }
|
|
437 }
|
|
438 }
|
|
439 }
|
|
440 break;
|
|
441 } /* end of routine when command is founded. */
|
|
442
|
|
443 /* loop while command is founded */
|
|
444 }
|
|
445 if (k == kansuu_hyo_entry_suu)
|
|
446 {
|
|
447 fprintf (stderr, "uumkey: unknown entry name %s.\r\n", func_name);
|
|
448 }
|
|
449 }
|
|
450 }
|
|
451 fclose (fp);
|
|
452 return (0);
|
|
453 }
|
|
454
|
|
455 /** argument expansion. */
|
|
456 int
|
|
457 expand_argument (st)
|
|
458 char *st;
|
|
459 {
|
|
460 int num;
|
|
461
|
|
462 if (*st == '^')
|
|
463 {
|
|
464 num = (*(st + 1)) & 0x1f;
|
|
465 }
|
|
466 else if (*st == '0' || *st == '\\')
|
|
467 {
|
|
468 if (*(st + 1) == 'x' || *(st + 1) == 'X')
|
|
469 {
|
|
470 sscanf (st + 2, "%x", &num);
|
|
471 }
|
|
472 else
|
|
473 {
|
|
474 sscanf (st, "%o", &num);
|
|
475 }
|
|
476 }
|
|
477 else if (!('0' <= *st && *st <= '9'))
|
|
478 {
|
|
479 return (-1);
|
|
480 }
|
|
481 else
|
|
482 {
|
|
483 num = atoi (st);
|
|
484 }
|
|
485 if (num >= TBL_SIZE)
|
|
486 {
|
|
487 printf ("uumkey: You can only bind a function to code less than %d.\r\n", TBL_SIZE);
|
|
488 return (-1);
|
|
489 }
|
|
490 return (num);
|
|
491 }
|
|
492
|
|
493 void
|
|
494 remove_key_bind (key)
|
|
495 int key;
|
|
496 {
|
|
497 int tbl;
|
|
498 int com;
|
|
499
|
|
500 for (com = 0; com < TBL_SIZE; com++)
|
|
501 {
|
|
502 for (tbl = 0; tbl < TBL_CNT; tbl++)
|
|
503 {
|
|
504 if (kansuu_hyo[key].func[tbl] != NULL)
|
|
505 {
|
|
506 if (main_table[tbl][com] == kansuu_hyo[key].func[tbl])
|
|
507 {
|
|
508 main_table[tbl][com] = NULL;
|
|
509 }
|
|
510 }
|
|
511 }
|
|
512 }
|
|
513 }
|
|
514
|
|
515
|
|
516 int
|
|
517 find_entry (com_name)
|
|
518 char *com_name;
|
|
519 {
|
|
520 int k;
|
|
521
|
|
522 for (k = 0; k < kansuu_hyo_entry_suu; k++)
|
|
523 {
|
|
524 if (strcmp (com_name, kansuu_hyo[k].kansuumei) == 0)
|
|
525 {
|
|
526 if (key_binded[k])
|
|
527 {
|
|
528 return (k);
|
|
529 }
|
|
530 }
|
|
531 }
|
|
532 return (-1);
|
|
533 }
|