0
|
1 /*
|
|
2 * $Id: cvt_read.c,v 1.8 2006/03/04 19:01:45 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, 2003, 2006
|
|
14 * Copyright Taketo Kabe 2003
|
|
15 *
|
|
16 * Maintainer: FreeWnn Project
|
|
17 *
|
|
18 * This program is free software; you can redistribute it and/or modify
|
|
19 * it under the terms of the GNU General Public License as published by
|
|
20 * the Free Software Foundation; either version 2 of the License, or
|
|
21 * (at your option) any later version.
|
|
22 *
|
|
23 * This program is distributed in the hope that it will be useful,
|
|
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
26 * GNU General Public License for more details.
|
|
27 *
|
|
28 * You should have received a copy of the GNU General Public License
|
|
29 * along with this program; if not, write to the Free Software
|
|
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
31 */
|
|
32
|
|
33 /***********************************************************************
|
|
34 convert_read.c ___
|
|
35 88/06/19|訂補|
|
|
36  ̄ ̄ ̄
|
|
37 ファンクションキーコンバート処理の、変換表リーダ。
|
|
38 convert_key.c の部分品。指定した変換表及びtermcap・
|
|
39 terminfoからの読みこみを行う関数を定義してある。
|
|
40 ***********************************************************************/
|
|
41 /* Version 4.0 */
|
|
42 #ifdef HAVE_CONFIG_H
|
|
43 # include <config.h>
|
|
44 #endif
|
|
45
|
|
46 #include <stdio.h>
|
|
47 #include <ctype.h>
|
|
48 #if STDC_HEADERS
|
|
49 # include <string.h>
|
|
50 #elif HAVE_STRINGS_H
|
|
51 # include <strings.h>
|
|
52 #endif /* STDC_HEADERS */
|
|
53 #if HAVE_FCNTL_H
|
|
54 # include <fcntl.h>
|
|
55 #endif
|
|
56 #ifdef HAVE_UNISTD_H
|
|
57 # include <unistd.h>
|
|
58 #endif
|
|
59
|
|
60 /* Solaris 2.x needs termio.h , so include both. */
|
|
61 #if HAVE_TERMIOS_H
|
|
62 # include <termios.h>
|
|
63 #endif
|
|
64 #if HAVE_TERMIO_H
|
|
65 # include <termio.h>
|
|
66 #endif
|
|
67
|
|
68 #if defined(HAVE_TERMIOS_H)
|
|
69 /* # include <termios.h> */
|
|
70 # define USE_TERMIOS 1
|
|
71 #elif defined(HAVE_TERMIO_H)
|
|
72 /* # include <termio.h> */
|
|
73 # define USE_TERMIO 1
|
|
74 #elif defined(HAVE_SYS_TERMIO_H)
|
|
75 # include <sys/termio.h>
|
|
76 # define USE_TERMIO 1
|
|
77 #elif defined(HAVE_SGTTY_H)
|
|
78 # include <sgtty.h>
|
|
79 # define USE_SGTTY
|
|
80 #else
|
|
81 # error "No termio header."
|
|
82 #endif /* HAVE_TERMIOS_H */
|
|
83
|
|
84 #ifdef HAVE_TERMINFO
|
|
85 # define TERMINFO 1
|
|
86 #else
|
|
87 # define TERMCAP 1
|
|
88 #endif /* HAVE_TERMINFO */
|
|
89
|
|
90 /* ncurses' term.h defines them to either 0 or 1! */
|
|
91 #ifndef HAVE_TERMIOS_H
|
|
92 # define DONT_HAVE_TERMIOS_H
|
|
93 #endif
|
|
94 #ifndef HAVE_TERMIO_H
|
|
95 # define DONT_HAVE_TERMIO_H
|
|
96 #endif
|
|
97 #ifndef HAVE_SYS_TERMIO_H
|
|
98 # define DONT_HAVE_SYS_TERMIO_H
|
|
99 #endif
|
|
100 #ifndef HAVE_SGTTY_H
|
|
101 # define DONT_HAVE_SGTTY_H
|
|
102 #endif
|
|
103
|
|
104 #if defined(HAVE_TERMINFO)
|
|
105 # if defined(HAVE_CURSES_H)
|
|
106 # include <curses.h>
|
|
107 # elif defined(HAVE_NCURSES_H)
|
|
108 # include <ncurses.h>
|
|
109 # else
|
|
110 # error "no terminfo header"
|
|
111 # endif /* HAVE_CURSES_H */
|
|
112 # ifdef HAVE_TERM_H
|
|
113 # include <term.h>
|
|
114 # endif
|
|
115 #else /* HAVE_TERMINFO */
|
|
116 # if defined(HAVE_TERMCAP_H)
|
|
117 # include <termcap.h>
|
|
118 # endif /* HAVE_TERMCAP_H */
|
|
119 #endif /* HAVE_TERMINFO */
|
|
120
|
|
121 #ifdef DONT_HAVE_TERMIOS_H
|
|
122 # undef HAVE_TERMIOS_H
|
|
123 # undef DONT_HAVE_TERMIOS_H
|
|
124 #endif
|
|
125 #ifdef DONT_HAVE_TERMIO_H
|
|
126 # undef HAVE_TERMIO_H
|
|
127 # undef DONT_HAVE_TERMIO_H
|
|
128 #endif
|
|
129 #ifdef DONT_HAVE_SYS_TERMIO_H
|
|
130 # undef HAVE_SYS_TERMIO_H
|
|
131 # undef DONT_HAVE_SYS_TERMIO_H
|
|
132 #endif
|
|
133 #ifdef DONT_HAVE_SGTTY_H
|
|
134 # undef HAVE_SGTTY_H
|
|
135 # undef DONT_HAVE_SGTTY_H
|
|
136 #endif
|
|
137
|
|
138 #include "wnn_os.h"
|
|
139 #include "cvt_head.h"
|
|
140
|
|
141 #define ENTRY_LEN 10 /* コンバート表のエントリ名の最大長 */
|
|
142
|
|
143 /*
|
|
144 #define NOFILE_NOT_ABORT
|
|
145 */
|
|
146 /* これをdefineしておくと、変換表がopenできない時にエラー終了せず、
|
|
147 単に変換関数が恒等関数になる。 */
|
|
148
|
|
149 #define is_digit(x) (isascii(x) && isdigit(x))
|
|
150 #define is_xdigit(x) (isascii(x) && isxdigit(x))
|
|
151 #define is_upper(x) (isascii(x) && isupper(x))
|
|
152 #define is_lower(x) (isascii(x) && islower(x))
|
|
153 #define is_space(x) (isascii(x) && isspace(x))
|
|
154
|
|
155 #define is_eofnl(x) ((x) == '\n'|| (x) == EOF)
|
|
156 #define is_eofsp(x) (is_space(x) || (x) == EOF)
|
|
157 #define is_octal(x) (is_digit(x) && (x) < '8')
|
|
158
|
|
159 #define ESCCHR '\033'
|
|
160
|
|
161 /* convert_key 用変換表のファイル名のデフォルトをセット。
|
|
162 変換表の名が明示的に指定されたら、それがこの変数の値になる。 */
|
|
163 static char *convert_filename;
|
|
164 static char default_cvt_fn[128];
|
|
165
|
|
166 static FILE *convert_hyo;
|
|
167
|
|
168
|
|
169 /** エラーメッセージを表示 */
|
|
170 #define errdsp1(mes, conv_fnm) \
|
|
171 fprintf(stderr, "%s: %s.\r\n%s = %s\r\n\n", \
|
|
172 "convert_key", mes, "convert-table filename", conv_fnm)
|
|
173
|
|
174 #define errdsp2(mes, termnm) \
|
|
175 fprintf(stderr, "%s: %s.\r\n%s = %s\r\n\n", \
|
|
176 "convert_key", mes, "termname", termnm)
|
|
177
|
|
178 /* Warningメッセージを表示 */
|
|
179 #define warn1(conv_fnm) \
|
|
180 fprintf(stderr, "%s: %s.\r\n%s.\r\n%s = %s\r\n\n", \
|
|
181 "convert_key", \
|
|
182 "Warning! Convert-table file is not found", \
|
|
183 "Key conversion will not be performed", \
|
|
184 "convert-table filename", conv_fnm)
|
|
185
|
|
186 #define warn2(nm, conv_fnm) \
|
|
187 fprintf(stderr, "%s: %s \"%s\" %s.\r\n%s.\r\n%s = %s\r\n\n", \
|
|
188 "convert_key", \
|
|
189 "Warning! Entry name", nm, "is duplicated", \
|
|
190 "The previous one was ignored", \
|
|
191 "convert-table filename", conv_fnm)
|
|
192
|
|
193 #define warn3(nm, conv_fnm) \
|
|
194 fprintf(stderr, "%s: %s \"%s\" %s.\r\n%s = %s\r\n\n", \
|
|
195 "convert_key", \
|
|
196 "Warning! Illegal entry name", nm, "was ignored", \
|
|
197 "convert-table filename", conv_fnm)
|
|
198
|
|
199 #define warn4(entry, conv_fnm, code) { \
|
|
200 fprintf(stderr, "%s: %s \"%s\" %s,\r\n%s ", \
|
|
201 "convert_key", "Warning! Entry name", entry, \
|
|
202 "isn't described in TERMCAP/INFO", \
|
|
203 "so the corresponding key can't generate"); \
|
|
204 printcode(stderr, code); \
|
|
205 fprintf(stderr, ".\r\n%s = %s\r\n\n", \
|
|
206 "convert-table filename", conv_fnm); \
|
|
207 }
|
|
208
|
|
209 /** コードcを目に見える形で印字 */
|
|
210 static void
|
|
211 printcode (f, c)
|
|
212 FILE *f;
|
|
213 int c;
|
|
214 {
|
|
215 fprintf (f, (' ' <= c && c < '\177') ? "'%c'" : ((c & ~0xff) ? "0x%X" : "'\\%03o'"), c);
|
|
216 }
|
|
217
|
|
218 /*
|
|
219 getterm_fkeydata(pterp)
|
|
220 char **pterp;
|
|
221 {廃止}
|
|
222 */
|
|
223
|
|
224 /** 8・10・16進コード用のキャラクタを実際のコードに直す。入力のチェックは
|
|
225 しない(入力は英数字と仮定している)。*/
|
|
226 static int
|
|
227 charvalue (c)
|
|
228 char c;
|
|
229 {
|
|
230 if (isupper (c))
|
|
231 return (c - 'A' + 10);
|
|
232 if (islower (c))
|
|
233 return (c - 'a' + 10);
|
|
234 return (c - '0');
|
|
235 }
|
|
236
|
|
237
|
|
238 #ifdef TERMCAP
|
|
239 char *cvttbl_entry[] = {
|
|
240 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7", "k8", "k9",
|
|
241 #ifdef SUPPORT_TWODIGIT_FUNCTIONS
|
|
242 "k;",
|
|
243 "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "FA",
|
|
244 "FB", "FC", "FD", "FE", "FF", "FG", "FH", "FI", "FJ", "FK",
|
|
245 "FL", "FM", "FN", "FO", "FP", "FQ", "FR", "FS", "FT", "FU",
|
|
246 "FV", "FW", "FX", "FY", "FZ", "Fa", "Fb", "Fc", "Fd", "Fe",
|
|
247 "Ff", "Fg", "Fh", "Fi", "Fj", "Fk", "Fl", "Fm", "Fn", "Fo",
|
|
248 "Fp", "Fq", "Fr",
|
|
249 #endif /* SUPPORT_TWODIGIT_FUNCTIONS */
|
|
250 "ku", "kr", "kl", "kd", "kh",
|
|
251 "up", "ri", "le", "do", "ho",
|
|
252 "kb",
|
|
253 "!del", /* 暫定 */
|
|
254 };
|
|
255 #endif /* TERMCAP */
|
|
256 #ifdef TERMINFO
|
|
257 char *cvttbl_entry[] = {
|
|
258 "kf0", "kf1", "kf2", "kf3", "kf4", "kf5", "kf6", "kf7",
|
|
259 "kf8", "kf9", "kf10",
|
|
260 #ifdef SUPPORT_TWODIGIT_FUNCTIONS
|
|
261 "kf11", "kf12", "kf13", "kf14", "kf15", "kf16", "kf17",
|
|
262 "kf18", "kf19", "kf20", "kf21", "kf22", "kf23", "kf24",
|
|
263 "kf25", "kf26", "kf27", "kf28", "kf29", "kf30", "kf31",
|
|
264 #ifndef uniosu
|
|
265 "kf32", "kf33", "kf34", "kf35", "kf36", "kf37", "kf38",
|
|
266 "kf39", "kf40", "kf41", "kf42", "kf43", "kf44", "kf45",
|
|
267 "kf46", "kf47", "kf48", "kf49", "kf50", "kf51", "kf52",
|
|
268 "kf53", "kf54", "kf55", "kf56", "kf57", "kf58", "kf59",
|
|
269 "kf60", "kf61", "kf62", "kf63",
|
|
270 #endif
|
|
271 #endif /* SUPPORT_TWODIGIT_FUNCTIONS */
|
|
272 "kcuu1", "kcuf1", "kcub1", "kcud1", "khome",
|
|
273 "kbs", "ktbc", "kclr", "kctab", "kdch1", "kdl1",
|
|
274 "krmir", "kel", "ked", "kich1", "kil1",
|
|
275 "kll", "knp", "kpp", "kind", "kri", "khts",
|
|
276 };
|
|
277 #endif /* TERMINFO */
|
|
278
|
|
279 #define ENTRY_CNT (sizeof(cvttbl_entry) / sizeof(*cvttbl_entry))
|
|
280 #define CVTTBLSIZ ENTRY_CNT
|
|
281
|
|
282 char *keydef_key[ENTRY_CNT]; /* terminfo/termcapの各データへのポインタ */
|
|
283 char tdataarea[AREASIZE]; /* データ収納のための専用エリア */
|
|
284
|
|
285 struct CONVCODE tbl[CVTTBLSIZ];
|
|
286 int cnv_tbl_cnt; /* convert table count */
|
|
287 /* これらは元は convert_key.c中のstatic変数だった */
|
|
288
|
|
289 /** コンバート表のエントリ部分をとる。許される最大長を超えたら0を返す */
|
|
290 static int
|
|
291 get_entrynm (buf)
|
|
292 char *buf;
|
|
293 {
|
|
294 int i, c;
|
|
295
|
|
296 for (i = 0; i <= ENTRY_LEN; i++)
|
|
297 {
|
|
298 c = getc (convert_hyo);
|
|
299 if (is_eofsp (c))
|
|
300 {
|
|
301 ungetc (c, convert_hyo);
|
|
302 *buf = '\0';
|
|
303 return (1);
|
|
304 }
|
|
305 else
|
|
306 *buf++ = c;
|
|
307 }
|
|
308 return (0);
|
|
309 }
|
|
310
|
|
311 /** 空白(改行文字を除く)をとばして次の文字を返す */
|
|
312 static int
|
|
313 blank_ign_getc (f)
|
|
314 FILE *f;
|
|
315 {
|
|
316 int c;
|
|
317
|
|
318 while (c = getc (f), is_space (c) && c != '\n');
|
|
319 return (c);
|
|
320 }
|
|
321
|
|
322 /** 行末(又はEOF)まで飛ばす。その間に非空白文字があったら非0を返す。*/
|
|
323 static int
|
|
324 linepass (f)
|
|
325 FILE *f;
|
|
326 {
|
|
327 int c, flg = 0;
|
|
328
|
|
329 while (c = getc (f), !is_eofnl (c))
|
|
330 flg = (flg || !is_space (c));
|
|
331 return (flg);
|
|
332 }
|
|
333
|
|
334 /** コントロールコード形式のコード表記一文字分をとる。エラーがあれば返値≠0*/
|
|
335 static int
|
|
336 get_ctrl (cptr)
|
|
337 int *cptr;
|
|
338 {
|
|
339 int c;
|
|
340
|
|
341 if (!(' ' <= (c = getc (convert_hyo)) && c < '\177'))
|
|
342 return (1);
|
|
343 *cptr = (c == '?' ? '\177' : c & 0x1f);
|
|
344 return (0);
|
|
345 }
|
|
346
|
|
347 /** バックスラッシュ形式のコード表記一文字分をとる。エラーがあれば非0を返す*/
|
|
348 static int
|
|
349 get_bcksla (cptr)
|
|
350 int *cptr;
|
|
351 {
|
|
352 int c, code = 0, digflg = 0;
|
|
353
|
|
354 switch (c = getc (convert_hyo))
|
|
355 {
|
|
356 case 'n':
|
|
357 *cptr = '\n';
|
|
358 return (0);
|
|
359 case 't':
|
|
360 *cptr = '\t';
|
|
361 return (0);
|
|
362 case 'b':
|
|
363 *cptr = '\b';
|
|
364 return (0);
|
|
365 case 'r':
|
|
366 *cptr = '\r';
|
|
367 return (0);
|
|
368 case 'f':
|
|
369 *cptr = '\f';
|
|
370 return (0);
|
|
371 case 'e':
|
|
372 case 'E':
|
|
373 *cptr = ESCCHR;
|
|
374 return (0);
|
|
375 case 'o':
|
|
376 while (c = getc (convert_hyo), is_octal (c))
|
|
377 {
|
|
378 code <<= 3;
|
|
379 code += charvalue (c);
|
|
380 digflg = 1;
|
|
381 }
|
|
382 ungetc (c, convert_hyo);
|
|
383 *cptr = code;
|
|
384 return (digflg == 0);
|
|
385 case 'd':
|
|
386 while (c = getc (convert_hyo), is_digit (c))
|
|
387 {
|
|
388 code *= 10;
|
|
389 code += charvalue (c);
|
|
390 digflg = 1;
|
|
391 }
|
|
392 ungetc (c, convert_hyo);
|
|
393 *cptr = code;
|
|
394 return (digflg == 0);
|
|
395 case 'x':
|
|
396 while (c = getc (convert_hyo), is_xdigit (c))
|
|
397 {
|
|
398 code <<= 4;
|
|
399 code += charvalue (c);
|
|
400 digflg = 1;
|
|
401 }
|
|
402 ungetc (c, convert_hyo);
|
|
403 *cptr = code;
|
|
404 return (digflg == 0);
|
|
405 default:
|
|
406 if (is_octal (c))
|
|
407 {
|
|
408 code = charvalue (c);
|
|
409 while (c = getc (convert_hyo), is_octal (c))
|
|
410 {
|
|
411 code <<= 3;
|
|
412 code += charvalue (c);
|
|
413 }
|
|
414 ungetc (c, convert_hyo);
|
|
415 *cptr = code;
|
|
416 return (0);
|
|
417 }
|
|
418 else
|
|
419 {
|
|
420 *cptr = c;
|
|
421 return (0);
|
|
422 }
|
|
423 }
|
|
424 }
|
|
425
|
|
426 /** コード表記をとって、cptrの指し先にそのコードを入れる。
|
|
427 文法エラー発見時は非0を返す。*/
|
|
428 static int
|
|
429 get_code (cptr)
|
|
430 int *cptr;
|
|
431 {
|
|
432 int c;
|
|
433
|
|
434 switch (c = getc (convert_hyo))
|
|
435 {
|
|
436 case '\\':
|
|
437 return (get_bcksla (cptr));
|
|
438 case '^':
|
|
439 return (get_ctrl (cptr));
|
|
440 default:
|
|
441 *cptr = c;
|
|
442 return (0);
|
|
443 }
|
|
444 }
|
|
445
|
|
446 #ifdef TERMCAP
|
|
447 /** tgetstrと同等の関数。但し、エントリ名「!del」(DELキーの変換をするため
|
|
448 暫定的に追加してあるエントリ)に対しては、定文字列"\177"を返す。*/
|
|
449 static char *
|
|
450 my_tgetstr (name, ptr)
|
|
451 char *name, **ptr;
|
|
452 {
|
|
453 extern char *tgetstr ();
|
|
454 static char *del = "\177";
|
|
455
|
|
456 if (strcmp (name, "!del") == 0)
|
|
457 return (del);
|
|
458 return (tgetstr (name, ptr));
|
|
459 }
|
|
460 #endif
|
|
461
|
|
462 #ifdef TERMINFO
|
|
463 /** pp1の指しているエリアにp2の内容を入れた後、pp1のポインタを進めておく*/
|
|
464 static char *
|
|
465 stradd (pp1, p2)
|
|
466 char **pp1, *p2;
|
|
467 {
|
|
468 if (p2 != NULL)
|
|
469 {
|
|
470 strcpy (*pp1, p2);
|
|
471 (*pp1) += strlen (p2 = *pp1) + 1;
|
|
472 }
|
|
473 return (p2);
|
|
474 }
|
|
475 #endif
|
|
476
|
|
477 /** termcap/infoから読んだキーのデータを専用エリアにコピー。*/
|
|
478 static void
|
|
479 convert_getstrs (flg)
|
|
480 int flg; /* verboseモードで起こすかのフラグ(今の所それだけだが、将来
|
|
481 拡張があるかもしれないので、1か0で与えて下さい。このファイル
|
|
482 中の、名前がconvert_で始まる他の関数でも同じです) */
|
|
483 {
|
|
484 char *tdataptr;
|
|
485 int i;
|
|
486
|
|
487 tdataptr = tdataarea;
|
|
488
|
|
489 #ifdef TERMCAP
|
|
490 for (i = 0; i < ENTRY_CNT; i++)
|
|
491 keydef_key[i] = my_tgetstr (cvttbl_entry[i], &tdataptr);
|
|
492 /* keydef_key[i] の値は、NULL又はtdataareaの範囲内とは限らない。
|
|
493 "\177"などの特殊データを指すこともある。 */
|
|
494
|
|
495 if (flg)
|
|
496 fprintf (stderr, "convert_key: finished getting TERMCAP.\r\n");
|
|
497 #endif
|
|
498
|
|
499 #ifdef TERMINFO
|
|
500 i = 0;
|
|
501 keydef_key[i++] = stradd (&tdataptr, key_f0);
|
|
502 keydef_key[i++] = stradd (&tdataptr, key_f1);
|
|
503 keydef_key[i++] = stradd (&tdataptr, key_f2);
|
|
504 keydef_key[i++] = stradd (&tdataptr, key_f3);
|
|
505 keydef_key[i++] = stradd (&tdataptr, key_f4);
|
|
506 keydef_key[i++] = stradd (&tdataptr, key_f5);
|
|
507 keydef_key[i++] = stradd (&tdataptr, key_f6);
|
|
508 keydef_key[i++] = stradd (&tdataptr, key_f7);
|
|
509 keydef_key[i++] = stradd (&tdataptr, key_f8);
|
|
510 keydef_key[i++] = stradd (&tdataptr, key_f9);
|
|
511 keydef_key[i++] = stradd (&tdataptr, key_f10);
|
|
512 #ifdef SUPPORT_TWODIGIT_FUNCTIONS
|
|
513 keydef_key[i++] = stradd (&tdataptr, key_f11);
|
|
514 keydef_key[i++] = stradd (&tdataptr, key_f12);
|
|
515 keydef_key[i++] = stradd (&tdataptr, key_f13);
|
|
516 keydef_key[i++] = stradd (&tdataptr, key_f14);
|
|
517 keydef_key[i++] = stradd (&tdataptr, key_f15);
|
|
518 keydef_key[i++] = stradd (&tdataptr, key_f16);
|
|
519 keydef_key[i++] = stradd (&tdataptr, key_f17);
|
|
520 keydef_key[i++] = stradd (&tdataptr, key_f18);
|
|
521 keydef_key[i++] = stradd (&tdataptr, key_f19);
|
|
522 keydef_key[i++] = stradd (&tdataptr, key_f20);
|
|
523 keydef_key[i++] = stradd (&tdataptr, key_f21);
|
|
524 keydef_key[i++] = stradd (&tdataptr, key_f22);
|
|
525 keydef_key[i++] = stradd (&tdataptr, key_f23);
|
|
526 keydef_key[i++] = stradd (&tdataptr, key_f24);
|
|
527 keydef_key[i++] = stradd (&tdataptr, key_f25);
|
|
528 keydef_key[i++] = stradd (&tdataptr, key_f26);
|
|
529 keydef_key[i++] = stradd (&tdataptr, key_f27);
|
|
530 keydef_key[i++] = stradd (&tdataptr, key_f28);
|
|
531 keydef_key[i++] = stradd (&tdataptr, key_f29);
|
|
532 keydef_key[i++] = stradd (&tdataptr, key_f30);
|
|
533 keydef_key[i++] = stradd (&tdataptr, key_f31);
|
|
534 # ifndef uniosu
|
|
535 keydef_key[i++] = stradd (&tdataptr, key_f32);
|
|
536 keydef_key[i++] = stradd (&tdataptr, key_f33);
|
|
537 keydef_key[i++] = stradd (&tdataptr, key_f34);
|
|
538 keydef_key[i++] = stradd (&tdataptr, key_f35);
|
|
539 keydef_key[i++] = stradd (&tdataptr, key_f36);
|
|
540 keydef_key[i++] = stradd (&tdataptr, key_f37);
|
|
541 keydef_key[i++] = stradd (&tdataptr, key_f38);
|
|
542 keydef_key[i++] = stradd (&tdataptr, key_f39);
|
|
543 keydef_key[i++] = stradd (&tdataptr, key_f40);
|
|
544 keydef_key[i++] = stradd (&tdataptr, key_f41);
|
|
545 keydef_key[i++] = stradd (&tdataptr, key_f42);
|
|
546 keydef_key[i++] = stradd (&tdataptr, key_f43);
|
|
547 keydef_key[i++] = stradd (&tdataptr, key_f44);
|
|
548 keydef_key[i++] = stradd (&tdataptr, key_f45);
|
|
549 keydef_key[i++] = stradd (&tdataptr, key_f46);
|
|
550 keydef_key[i++] = stradd (&tdataptr, key_f47);
|
|
551 keydef_key[i++] = stradd (&tdataptr, key_f48);
|
|
552 keydef_key[i++] = stradd (&tdataptr, key_f49);
|
|
553 keydef_key[i++] = stradd (&tdataptr, key_f50);
|
|
554 keydef_key[i++] = stradd (&tdataptr, key_f51);
|
|
555 keydef_key[i++] = stradd (&tdataptr, key_f52);
|
|
556 keydef_key[i++] = stradd (&tdataptr, key_f53);
|
|
557 keydef_key[i++] = stradd (&tdataptr, key_f54);
|
|
558 keydef_key[i++] = stradd (&tdataptr, key_f55);
|
|
559 keydef_key[i++] = stradd (&tdataptr, key_f56);
|
|
560 keydef_key[i++] = stradd (&tdataptr, key_f57);
|
|
561 keydef_key[i++] = stradd (&tdataptr, key_f58);
|
|
562 keydef_key[i++] = stradd (&tdataptr, key_f59);
|
|
563 keydef_key[i++] = stradd (&tdataptr, key_f60);
|
|
564 keydef_key[i++] = stradd (&tdataptr, key_f61);
|
|
565 keydef_key[i++] = stradd (&tdataptr, key_f62);
|
|
566 keydef_key[i++] = stradd (&tdataptr, key_f63);
|
|
567 # endif /* !uniosu */
|
|
568 #endif /* SUPPORT_TWODIGIT_FUNCTIONS */
|
|
569 /* 以下順に
|
|
570 "kcuu1", "kcuf1", "kcub1", "kcud1", "khome",
|
|
571 "kbs", "ktbc", "kclr", "kctab", "kdch1", "kdl1",
|
|
572 "krmir", "kel", "ked", "kich1", "kil1",
|
|
573 "kll", "knp", "kpp", "kind", "kri", "khts",
|
|
574 */
|
|
575 keydef_key[i++] = stradd (&tdataptr, key_up);
|
|
576 keydef_key[i++] = stradd (&tdataptr, key_right);
|
|
577 keydef_key[i++] = stradd (&tdataptr, key_left);
|
|
578 keydef_key[i++] = stradd (&tdataptr, key_down);
|
|
579 keydef_key[i++] = stradd (&tdataptr, key_home);
|
|
580 keydef_key[i++] = stradd (&tdataptr, key_backspace);
|
|
581 keydef_key[i++] = stradd (&tdataptr, key_catab);
|
|
582 keydef_key[i++] = stradd (&tdataptr, key_clear);
|
|
583 keydef_key[i++] = stradd (&tdataptr, key_ctab);
|
|
584 keydef_key[i++] = stradd (&tdataptr, key_dc);
|
|
585 keydef_key[i++] = stradd (&tdataptr, key_dl);
|
|
586 keydef_key[i++] = stradd (&tdataptr, key_eic);
|
|
587 keydef_key[i++] = stradd (&tdataptr, key_eol);
|
|
588 keydef_key[i++] = stradd (&tdataptr, key_eos);
|
|
589 keydef_key[i++] = stradd (&tdataptr, key_ic);
|
|
590 keydef_key[i++] = stradd (&tdataptr, key_il);
|
|
591 keydef_key[i++] = stradd (&tdataptr, key_ll);
|
|
592 keydef_key[i++] = stradd (&tdataptr, key_npage);
|
|
593 keydef_key[i++] = stradd (&tdataptr, key_ppage);
|
|
594 keydef_key[i++] = stradd (&tdataptr, key_sf);
|
|
595 keydef_key[i++] = stradd (&tdataptr, key_sr);
|
|
596 keydef_key[i++] = stradd (&tdataptr, key_stab);
|
|
597
|
|
598 if (flg)
|
|
599 fprintf (stderr, "convert_key: finished getting TERMINFO.\r\n");
|
|
600 #endif
|
|
601 }
|
|
602
|
|
603 /** TERMINFO の場合は setupterm()、TERMCAPの場合は tgetent()の処理を行った
|
|
604 後、キーが発生するシーケンスのデータを専用のエリアにコピーする。
|
|
605 termcap/infoのデータベースがオープンできなかったら非0を返す。*/
|
|
606 #ifdef TERMCAP
|
|
607 int
|
|
608 convert_getterm (termname, flg)
|
|
609 char *termname;
|
|
610 int flg;
|
|
611 {
|
|
612 extern int tgetent ();
|
|
613 char tcaparea[AREASIZE];
|
|
614
|
|
615 if (flg)
|
|
616 fprintf (stderr, "convert_key: using TERMCAP entry %s...\r\n", termname);
|
|
617 if (tgetent (tcaparea, termname) <= 0)
|
|
618 {
|
|
619 errdsp2 ("Can't get termcap entry", termname);
|
|
620 return (1);
|
|
621 }
|
|
622 convert_getstrs (flg);
|
|
623 return (0);
|
|
624 }
|
|
625 #endif
|
|
626 #ifdef TERMINFO
|
|
627 int
|
|
628 convert_getterm (termname, flg)
|
|
629 char *termname;
|
|
630 int flg;
|
|
631 {
|
|
632 int fd, rsl;
|
|
633
|
|
634 if (flg)
|
|
635 fprintf (stderr, "convert_key: using TERMINFO entry %s...\r\n", termname);
|
|
636 fd = open ("/dev/null", O_WRONLY, 0);
|
|
637 setupterm (termname, fd, &rsl);
|
|
638 close (fd);
|
|
639 if (rsl != 1)
|
|
640 {
|
|
641 errdsp2 ("Can't get terminfo entry", termname);
|
|
642 /* このときresetterm()は必要か? */
|
|
643 return (1);
|
|
644 }
|
|
645 convert_getstrs (flg);
|
|
646 resetterm ();
|
|
647 return (0);
|
|
648 }
|
|
649 #endif
|
|
650
|
|
651 /** termcap/infoから取ったキーのデータが既に専用エリアに収まっていると
|
|
652 して、それを使ってconvert_key処理の初期化をする。返値は正常終了時0、
|
|
653 表読み込み時にWarningが発生した時1、Errorを検出したとき-1。*/
|
|
654 int
|
|
655 convert_key_setup (filename, flg)
|
|
656 char *filename;
|
|
657 int flg;
|
|
658 {
|
|
659 register int i;
|
|
660 int c, d, cnt = 0, warn_occur = 0, entry_found;
|
|
661 char name[ENTRY_LEN + 1];
|
|
662
|
|
663 int keydef_code[ENTRY_CNT]; /* convert code */
|
|
664
|
|
665 if (CHANGE_MAX < div_up (ENTRY_CNT, BITSIZ))
|
|
666 {
|
|
667 fprintf (stderr, "%s%s%d%s", "Sorry, please set CHANGE_MAX(in file ", "conv/cvt_head.h) larger than ", div_up (ENTRY_CNT, BITSIZ) - 1, ",\r\nand recompile.\r\n");
|
|
668 return (-1);
|
|
669 }
|
|
670
|
|
671 for (i = 0; i < ENTRY_CNT; i++)
|
|
672 keydef_code[i] = -1;
|
|
673 /* codeが -1 のままなら、convert_key表にエントリがないことを示す。 */
|
|
674
|
|
675 if (NULL != filename)
|
|
676 convert_filename = filename;
|
|
677 else
|
|
678 {
|
|
679 convert_filename = default_cvt_fn;
|
|
680 #ifdef WNNDEFAULT
|
|
681 strcpy (convert_filename, LIBDIR); /* /usr/local/lib/wnn */
|
|
682 strcat (convert_filename, CONVERT_FILENAME); /* /cvt_key_tbl */
|
|
683 #else
|
|
684 strcpy (convert_filename, CONVERT_FILENAME);
|
|
685 #endif /* WNNDEFAULT */
|
|
686 }
|
|
687 if (flg)
|
|
688 fprintf (stderr, "convert_key: using convert_key table %s...\r\n", convert_filename);
|
|
689 if (NULL == (convert_hyo = fopen (convert_filename, "r")))
|
|
690 {
|
|
691 #ifdef NOFILE_NOT_ABORT
|
|
692 warn1 (convert_filename);
|
|
693 cnv_tbl_cnt = 0;
|
|
694 return (1);
|
|
695 #else
|
|
696 errdsp1 ("Convert-table file is not found", convert_filename);
|
|
697 return (-1);
|
|
698 #endif
|
|
699 }
|
|
700
|
|
701 /* 表からの読みこみ */
|
|
702 while (EOF != (d = getc (convert_hyo)))
|
|
703 {
|
|
704 if (d == '#' || d == ';')
|
|
705 {
|
|
706 /* '#'又は';'で始まる行は注釈として読み飛ばす。 */
|
|
707 linepass (convert_hyo);
|
|
708 continue;
|
|
709 }
|
|
710 ungetc (d, convert_hyo);
|
|
711
|
|
712 d = blank_ign_getc (convert_hyo);
|
|
713 if (is_eofnl (d))
|
|
714 continue; /* 空行 */
|
|
715 else
|
|
716 ungetc (d, convert_hyo);
|
|
717 if (!get_entrynm (name))
|
|
718 {
|
|
719 errdsp1 ("Entry name too long", convert_filename);
|
|
720 fclose (convert_hyo);
|
|
721 return (-1);
|
|
722 } /* エントリ名を読み込んだ。 */
|
|
723
|
|
724 d = blank_ign_getc (convert_hyo);
|
|
725 if (is_eofnl (d))
|
|
726 {
|
|
727 errdsp1 ("Convert code missing", convert_filename);
|
|
728 fclose (convert_hyo);
|
|
729 return (-1);
|
|
730 }
|
|
731 else
|
|
732 ungetc (d, convert_hyo);
|
|
733 if (get_code (&c) != 0 || linepass (convert_hyo) != 0)
|
|
734 {
|
|
735 errdsp1 ("Convert code illegal", convert_filename);
|
|
736 fclose (convert_hyo);
|
|
737 return (-1);
|
|
738 } /* 変換コードを読み込んだ。 */
|
|
739 #ifdef DEBUG
|
|
740 printf ("%s %d\n", name, c);
|
|
741 #endif
|
|
742 for (entry_found = i = 0; i < ENTRY_CNT; i++)
|
|
743 {
|
|
744 if (!strcmp (cvttbl_entry[i], name))
|
|
745 {
|
|
746 if (keydef_code[i] != -1)
|
|
747 {
|
|
748 warn2 (name, convert_filename);
|
|
749 warn_occur = 1;
|
|
750 }
|
|
751 keydef_code[i] = c;
|
|
752 entry_found = 1;
|
|
753 break;
|
|
754 }
|
|
755 }
|
|
756 if (!entry_found)
|
|
757 {
|
|
758 warn3 (name, convert_filename);
|
|
759 warn_occur = 1;
|
|
760 }
|
|
761 }
|
|
762
|
|
763 /* 読みこんだデータをテーブルにセット */
|
|
764 for (i = 0; i < ENTRY_CNT; i++)
|
|
765 {
|
|
766 if (keydef_key[i] != NULL)
|
|
767 {
|
|
768 if (keydef_code[i] != -1 && ((int) strlen (keydef_key[i]) > 1 || *keydef_key[i] != keydef_code[i]))
|
|
769 {
|
|
770 tbl[cnt].fromkey = keydef_key[i];
|
|
771 tbl[cnt++].tokey = keydef_code[i];
|
|
772 }
|
|
773 }
|
|
774 else if (keydef_code[i] != -1)
|
|
775 {
|
|
776 warn4 (cvttbl_entry[i], convert_filename, keydef_code[i]);
|
|
777 warn_occur = 1;
|
|
778 }
|
|
779 }
|
|
780
|
|
781 cnv_tbl_cnt = cnt;
|
|
782 fclose (convert_hyo);
|
|
783 if (flg)
|
|
784 fprintf (stderr, "convert_key: finished setting up.\r\n");
|
|
785 return (warn_occur);
|
|
786 }
|
|
787
|
|
788 /** convert_key処理初期化ルーチン。TERMINFO の場合は setupterm()、TERMCAPの
|
|
789 場合は tgetent()をそれぞれコールした後に呼ぶ。返値はconvert_key_setup
|
|
790 参照。*/
|
|
791 int
|
|
792 convert_key_init (filename, flg)
|
|
793 char *filename;
|
|
794 int flg;
|
|
795 {
|
|
796 convert_getstrs (flg);
|
|
797 return (convert_key_setup (filename, flg));
|
|
798 }
|
|
799
|
|
800 /** TERMINFO の場合は setupterm()、TERMCAPの場合は tgetent()まで含めて実行
|
|
801 convert_key処理初期化ルーチン。返す値はconvert_key_setup参照。但し、
|
|
802 termcap/infoの読み込みに失敗した場合は、-2が返る。*/
|
|
803 int
|
|
804 convert_getterm_init (termname, filename, flg)
|
|
805 char *termname, *filename;
|
|
806 int flg;
|
|
807 {
|
|
808 if (convert_getterm (termname, flg) != 0)
|
|
809 return (-2);
|
|
810 return (convert_key_setup (filename, flg));
|
|
811 }
|