1 /*
2 * $Id: kensaku.c,v 1.2 2001/06/14 18:16:13 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 * '99/04/19 TAOKA Satoshi - �IJ� �һ�<taoka@infonets.hiroshima-u.ac.jp>
35 * qsort() ��������ȥ����ȡ�
36 *
37 * Last modified date: 19,Apr.1999
38 *
39 * Code:
40 *
41 */
42 /* Version 4.0
43 */
44 #include <stdio.h>
45 #include "jslib.h"
46 #include "commonhd.h"
47 #include "sdefine.h"
48 #include "xjutil.h"
49 #include "sxheader.h"
50 #include "xext.h"
51
52 extern int (*jutil_table[2][3]) ();
53
54 /* Dirty, but share it with select_elemet.c */
55 struct wnn_jdata *word_searched;
56 int del_point, ima_point, hindo_point, com_point, max_c_len;
57
58 static int
sort_func_ws(a,b)59 sort_func_ws (a, b)
60 register char *a, *b;
61 {
62 int ah, bh, ai, bi, iah, ibh, iai, ibi;
63 ah = ((struct wnn_jdata *) a)->hindo;
64 bh = ((struct wnn_jdata *) b)->hindo;
65 iah = ((struct wnn_jdata *) a)->int_hindo;
66 ibh = ((struct wnn_jdata *) b)->int_hindo;
67 ai = ((struct wnn_jdata *) a)->ima;
68 bi = ((struct wnn_jdata *) b)->ima;
69 iai = ((struct wnn_jdata *) a)->int_ima;
70 ibi = ((struct wnn_jdata *) b)->int_ima;
71
72 if (ai == WNN_IMA_OFF && ah == WNN_ENTRY_NO_USE)
73 return (1);
74 if (bi == WNN_IMA_OFF && bh == WNN_ENTRY_NO_USE)
75 return (-1);
76 if (iai == WNN_IMA_OFF && iah == WNN_ENTRY_NO_USE)
77 return (1);
78 if (ibi == WNN_IMA_OFF && ibh == WNN_ENTRY_NO_USE)
79 return (-1);
80
81 if (ai != bi)
82 {
83 if (ai < bi)
84 return (1);
85 return (-1);
86 }
87 if (iah >= 0)
88 {
89 ah += iah;
90 bh += ibh;
91 }
92 if (ah > bh)
93 return (-1);
94 if (ah < bh)
95 return (1);
96 return (0);
97 }
98
99 void
fill_space(p,size)100 fill_space (p, size)
101 register char *p;
102 register int size;
103 {
104 for (; size > 0; size--, p++)
105 {
106 if (!*p)
107 *p = ' ';
108 }
109 }
110
111 static struct wnn_jdata *
word_list1(flag,tbl)112 word_list1 (flag, tbl)
113 int flag, tbl;
114 {
115 int k;
116 char *c;
117 char tmp[WNN_HINSI_NAME_LEN * 2];
118 w_char kana_buf[2048];
119 char buf[16384];
120 char *info[MAXJIKOUHO];
121 char imatukattayo;
122 int cnt;
123 int rcnt;
124 int tcnt;
125 int type;
126 int max_k_len = 0, max_d_len = 0;
127 static char message4[2048];
128 int ret;
129 char *table_t[6];
130 /* extern int qsort();*/
131
132 if (get_env () == -1)
133 return (NULL);
134
135 table_t[0] = msg_get (cd, 70, default_message[70], xjutil->lang);
136 init_jutil (msg_get (cd, 69, default_message[69], xjutil->lang), msg_get (cd, 8, default_message[8], xjutil->lang), 1, table_t, NULL);
137 change_cur_jutil (MESSAGE1);
138 retry:
139 throw_col (0);
140 JWMline_clear (0);
141 kk_cursor_normal ();
142 kana_buf[0] = 0;
143 if ((ret = kana_in (UNDER_LINE_MODE, kana_buf, 1024)) == -1)
144 {
145 kk_cursor_invisible ();
146 end_jutil ();
147 return (NULL);
148 }
149 kk_cursor_invisible ();
150 if (kana_buf[0] == 0)
151 {
152 ring_bell ();
153 goto retry;
154 }
155 if ((cnt = js_word_search_by_env (cur_env, kana_buf, &wordrb)) < 0)
156 {
157 if_dead_disconnect (cur_env, -1);
158 end_jutil ();
159 errorkeyin ();
160 return (NULL);
161 }
162 word_searched = (struct wnn_jdata *) wordrb.buf;
163 qsort ((char *) word_searched, cnt, sizeof (struct wnn_jdata), sort_func_ws);
164
165 update_dic_list ();
166
167 if (cnt == 0)
168 {
169 print_msg_getc (msg_get (cd, 71, default_message[71], xjutil->lang), NULL, NULL, NULL);
170 goto retry;
171 }
172 /* KURI ���������Ĵ�٤� */
173 if (flag)
174 {
175 tcnt = cnt;
176 }
177 else
178 {
179 for (k = 0, tcnt = 0; k < cnt; k++)
180 {
181 type = dicinfo[find_dic_by_no (word_searched[k].dic_no)].type;
182 if (type == WNN_UD_DICT || type == WNN_REV_DICT || type == CWNN_REV_DICT)
183 {
184 tcnt++;
185 }
186 }
187 }
188 max_k_len = 0;
189 max_d_len = 0;
190 max_c_len = 0;
191 for (c = buf, k = 0; k < cnt; k++)
192 {
193 sStrcpy (c, word_searched[k].kanji);
194 ret = strlen (c);
195 if (max_k_len < ret)
196 max_k_len = ret;
197 if (word_searched[k].com && word_searched[k].com[0])
198 {
199 strcpy (c, "{");
200 sStrcpy (c + strlen (c), word_searched[k].com);
201 strcat (c, "}");
202 ret = strlen (c);
203 if (ret > max_c_len)
204 max_c_len = ret;
205 }
206 dic_nickname (word_searched[k].dic_no, c);
207 sprintf (c + strlen (c), ":%d", word_searched[k].serial);
208 ret = strlen (c) + 2;
209 if (max_d_len < ret)
210 max_d_len = ret;
211 }
212 max_k_len += 2;
213 max_c_len += 2;
214 max_d_len += 2;
215 bzero (buf, sizeof (buf));
216 del_point = 0 + 1;
217 com_point = del_point + 2 + max_k_len;
218 ima_point = com_point + max_c_len + max_d_len;
219 hindo_point = ima_point + 1;
220 for (c = buf, k = 0, rcnt = 0; k < cnt; k++)
221 {
222 type = dicinfo[find_dic_by_no (word_searched[k].dic_no)].type;
223 if (!flag && !(type == WNN_UD_DICT || type == WNN_REV_DICT || type == CWNN_REV_DICT))
224 continue;
225 info[rcnt] = c;
226 strcpy (c, " ");
227 c += strlen (c);
228 sStrcpy (c, word_searched[k].kanji);
229 fill_space (c, max_k_len);
230 c += max_k_len;
231 if (word_searched[k].com && word_searched[k].com[0])
232 {
233 strcat (c, "{");
234 sStrcpy (c + strlen (c), word_searched[k].com);
235 strcat (c, "}");
236 }
237 fill_space (c, max_c_len);
238 c += max_c_len;
239 strcat (c, "(");
240 dic_nickname (word_searched[k].dic_no, c + strlen (c));
241 sprintf (c + strlen (c), ":%d", word_searched[k].serial);
242 strcat (c, ")");
243 fill_space (c, max_d_len);
244 c += max_d_len;
245 if (word_searched[k].ima)
246 imatukattayo = '*';
247 else
248 imatukattayo = ' ';
249 if (word_searched[k].hindo == -1)
250 {
251 sprintf (c, "---- ");
252 }
253 else
254 {
255 sprintf (c, "%c%-3d ", (word_searched[k].ima ? '*' : ' '), word_searched[k].hindo);
256 }
257 c += 6;
258 if (!(word_searched[k].int_ima && word_searched[k].int_hindo == -1))
259 {
260 /* Internal Hindo exist */
261 if (word_searched[k].int_hindo == -1)
262 {
263 sprintf (c, "(----) ");
264 }
265 else
266 {
267 sprintf (c, "(%c%-3d) ", (word_searched[k].int_ima) ? '*' : ' ', word_searched[k].int_hindo);
268 }
269 }
270 else
271 {
272 sprintf (c, " ");
273 }
274 c += 8;
275 if (js_hinsi_name (cur_env->js_id, word_searched[k].hinshi, &rb) == -1)
276 {
277 if_dead_disconnect (cur_env, NULL);
278 return (NULL);
279 }
280 sStrcpy (tmp, (w_char *) (rb.buf));
281 strcat (c, tmp);
282 fill_space (c, 20);
283 rcnt++;
284 c += 20;
285 sprintf (c, " %3d/%-3d", rcnt, tcnt);
286 c += strlen (c) + 1;
287 }
288 end_jutil ();
289 sprintf (message4, "%s %s : %s", msg_get (cd, 69, default_message[69], xjutil->lang), msg_get (cd, 70, default_message[70], xjutil->lang), kana_buf);
290
291 table_t[0] = msg_get (cd, 67, default_message[67], xjutil->lang);
292 table_t[1] = msg_get (cd, 68, default_message[68], xjutil->lang);
293 table_t[2] = msg_get (cd, 39, default_message[39], xjutil->lang);
294 table_t[3] = msg_get (cd, 120, default_message[120], xjutil->lang);
295 table_t[4] = msg_get (cd, 121, default_message[121], xjutil->lang);
296 table_t[5] = msg_get (cd, 122, default_message[122], xjutil->lang);
297 k = xw_select_one_element_keytable (info, rcnt, 0, msg_get (cd, 69, default_message[69], xjutil->lang), 6, table_t, jutil_table[0], main_table[tbl], NULL);
298 if (k == -1 || k == -3)
299 {
300 return (NULL);
301 }
302 if (flag == 0)
303 {
304 for (rcnt = 0; k >= 0 && rcnt < cnt; rcnt++)
305 {
306 type = dicinfo[find_dic_by_no (word_searched[rcnt].dic_no)].type;
307 if (type == WNN_UD_DICT || type == WNN_REV_DICT || type == CWNN_REV_DICT)
308 {
309 k--;
310 }
311 }
312 k = rcnt - 1;
313 }
314 return (word_searched + k);
315 }
316
317 static void
word_list7(flag)318 word_list7 (flag)
319 int flag;
320 {
321 word_list1 (flag, 7);
322 }
323
324 void
kensaku()325 kensaku ()
326 {
327 word_list7 (1); /* 1 for all dicts */
328 }
329