Line 0
Link Here
|
|
|
1 |
/************************************************************************** |
2 |
* X J D F R O N T E N D * |
3 |
* Common Frontend Routines for client & stand-alone vers. * |
4 |
* Japanese-English Dictionary program (X11 version) * |
5 |
* Author: Jim Breen * |
6 |
***************************************************************************/ |
7 |
/* This program is free software; you can redistribute it and/or modify |
8 |
it under the terms of the GNU General Public License as published by |
9 |
the Free Software Foundation; either version 1, or (at your option) |
10 |
any later version. |
11 |
|
12 |
This program is distributed in the hope that it will be useful, |
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
16 |
|
17 |
You should have received a copy of the GNU General Public License |
18 |
along with this program; if not, write to the Free Software |
19 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
20 |
|
21 |
#include <stdio.h> |
22 |
#include <ctype.h> |
23 |
#include <string.h> |
24 |
#include <sys/types.h> |
25 |
#include <sys/stat.h> |
26 |
#include <stdlib.h> |
27 |
#include <signal.h> |
28 |
#include <errno.h> |
29 |
#include "xjdic.h" |
30 |
|
31 |
/* Paul Burchard supplied a patch to provide BSD compatibility for xjdic |
32 |
(it uses the appropriate BSD ioctls in place of the SVR4 stuff). In |
33 |
order to enable this, people should compile with the option |
34 |
-D__STRICT_BSD___ . */ |
35 |
|
36 |
#ifdef __STRICT_BSD__ |
37 |
#include <sgtty.h> |
38 |
#else |
39 |
#ifdef __POSIX__ |
40 |
#include <sys/termios.h> |
41 |
#else |
42 |
#include <termio.h> |
43 |
#endif |
44 |
#endif |
45 |
|
46 |
#define WINSIZE_IOCTL_AVAILABLE |
47 |
|
48 |
|
49 |
|
50 |
static enum |
51 |
{ |
52 |
IOCTL_ORIG, |
53 |
IOCTL_RAW |
54 |
} myi_status = IOCTL_ORIG; |
55 |
|
56 |
#ifdef __STRICT_BSD__ |
57 |
static struct sgttyb orig,new; |
58 |
#else |
59 |
static struct termio orig,new; |
60 |
#endif |
61 |
|
62 |
extern unsigned char CBname[100]; |
63 |
extern unsigned char Dnamet[10][100],XJDXnamet[10][100]; |
64 |
extern unsigned char *dicbufft[10]; |
65 |
extern unsigned long diclent[10], indkent[10],indptrt[10]; |
66 |
extern int NoDics,CurrDic; |
67 |
int thisdic = 0; |
68 |
int gdicnos[10],gdicmax=0,GDmode=FALSE,gdiclen; |
69 |
int GDALLmode=FALSE; |
70 |
|
71 |
FILE *fe, *fex, *fclip, *fopen(); |
72 |
|
73 |
#ifdef XJDCLSERV |
74 |
extern int portno; |
75 |
extern unsigned char host[]; |
76 |
#endif |
77 |
|
78 |
#ifdef XJDDIC |
79 |
extern unsigned long dichits[10],dicmiss[10]; |
80 |
extern unsigned long indhits[10],indmiss[10]; |
81 |
extern unsigned long vbkills; |
82 |
#endif |
83 |
|
84 |
char DicDir[100]; |
85 |
int xfilelen; |
86 |
|
87 |
pid_t pid; |
88 |
int sig=SIGTSTP; |
89 |
int ShiftJIS = FALSE,NoSJIS=FALSE; |
90 |
unsigned char instr[256],radkanj[250][2]; |
91 |
int radnos[250]; |
92 |
unsigned char kanatab[NRKANA*2][7]; |
93 |
int Omode = 0,Smode = 0,Dmode = 0,AKanaMode; |
94 |
int DRow,DCol,MaxY=MAXLINES,MaxX=MAXCOLS-1,KFlushRes,nok; |
95 |
unsigned long hittab[NOHITS]; |
96 |
int verblen,DispHit,ksp,hitind,FirstKanj = 0,prieng = FALSE,Extopen=FALSE,NoSkip; |
97 |
int extlen,extjdxlen; |
98 |
unsigned char kmodes[2][10] = {"ON","OFF"}; |
99 |
unsigned char kmodes_r[2][10] = {"OFF","ON"}; |
100 |
unsigned long chline,chpos,it; |
101 |
unsigned char strfilt[10],tempout[80]; |
102 |
unsigned char KSname[50] = {"kanjstroke"}; |
103 |
unsigned char RKname[50] = {"radkfile"}; |
104 |
unsigned char Rname[50] = {"radicals.tm"}; |
105 |
unsigned char ROMname[60] = {"romkana.cnv"}; |
106 |
unsigned char EXTJDXname[80] = {"edictext.xjdx"}; |
107 |
unsigned char EXTname[80] = {"edictext"}; |
108 |
unsigned char Vname[60] = {"vconj"}; |
109 |
unsigned char ENVname[100]; |
110 |
unsigned char cl_rcfile[100]; |
111 |
unsigned char Clip_File[100] = {"clipboard"}; |
112 |
unsigned char GPL_File[100] = {"gnu_licence"}; |
113 |
unsigned char KDNSlist[50]; |
114 |
int jiver = 14; /*The last time the index structure changed was Version1.4*/ |
115 |
unsigned char sver[] = {SVER}; |
116 |
unsigned char fbuff[512],KLine[KFBUFFSIZE],karray[KANJARRAYSIZE][5]; |
117 |
unsigned char LogLine[200]; |
118 |
unsigned char ksch[50],ktarg[50]; |
119 |
/* The following Help table has "~" to force spaces */ |
120 |
unsigned char Help[40][81] = { |
121 |
"\n~~~~~~~~~~~~~~~~~~XJDIC USAGE SUMMARY ", |
122 |
"At the SEARCH KEY prompt respond with a string of ascii, kana and/or ", |
123 |
"kanji to look up in the current dictionary (prefix with @ or # to invoke ", |
124 |
"conversion of romaji to hiragana or katakana)", |
125 |
"~~~~~~~~~~~~~~~~~~SINGLE CHARACTER COMMANDS", |
126 |
"~~\\ enter Kanji Dictionary mode~~~? ~~get this Help display", |
127 |
"~~_ select dictionary files ~~~~~~=/^ cycle up/down dictionary files", |
128 |
"~~\' set/clear one-off filter~~~~~~; activate/deactivate general filters", |
129 |
"~~/ toggle kanji_within_compound~~- toggle long kanji display on/off", |
130 |
"~~$ set global dictionaries ~~~~~~% toggle global search mode on/off", |
131 |
"~~] display Dictionary Extension ~: toggle verb deinflection on/off", |
132 |
"~~+ toggle priority English keys~~| toggle unedited display mode on/off", |
133 |
"~~[ toggle exact_match on/off~~~~~& toggle kana input mode on/off", |
134 |
"~~{ switch to clipboard input ~~~~} toggle reverse video of matches", |
135 |
"~~` toggle multiple global disp.~~Ctrl-D to exit", |
136 |
"~~! display gnu licence~~~~~~~~~~~Ctrl-Z to suspend", |
137 |
"~~~~~~Kanji Dictionary mode - prompt is KANJI LOOKUP TYPE:. Responses:", |
138 |
"~~a single kanji or a kana reading (default)", |
139 |
"~~j followed by the 4-digit hexadecimal JIS code for a kanji", |
140 |
"~~j followed by k and the 4-digit KUTEN code for a kanji", |
141 |
"~~~~~~~(precede code with `h' for JIS X 0212 kanji.)", |
142 |
"~~j followed by s and the 4-digit hexadecimal Shift-JIS code for a kanji", |
143 |
"~~m followed by an (English) kanji meaning", |
144 |
"~~c followed by an index code such as Nnnn (Nelson), Bnn (Bushu), etc", |
145 |
"~~r initiates a display of all radicals and their numbers", |
146 |
"~~l switches the program into the Radical Lookup mode", |
147 |
"$$$" |
148 |
}; |
149 |
unsigned char RVon[] = {0x1b,'[','7','m',0}; |
150 |
unsigned char RVoff[] = {0x1b,'[','m',0}; |
151 |
int nofilts=FALSE,filton[NOFILT],filtact[NOFILT],filttype[NOFILT],filtcoden[NOFILT]; |
152 |
unsigned char filtnames[NOFILT][50],filtcodes[NOFILT][10][10]; |
153 |
unsigned char testline[1025],SingleFilter[50]; |
154 |
unsigned char vdicf[VMAX][7],vinfl[VMAX][21],vcomms[41][50]; |
155 |
int strf,Jverb = TRUE,SFFlag=FALSE,vcommno[VMAX]; |
156 |
int ROmode = 1,EMmode = 1,KLmode = 1,KImode = 1,KLRmode,KLcount; |
157 |
unsigned char vline[250],vstr[13]; |
158 |
unsigned char RadK1[300],RadK2[300],*RKanj1,*RKanj2,*RKSet[10]; |
159 |
unsigned char RKTarg[21]; |
160 |
int rmax,NoSets=0,NoRads,RKStart[300],RKCnt[300]; |
161 |
unsigned char ops[3],kstrokes[7000]; |
162 |
int kstrokelim,kstroketype; |
163 |
int clipmode=FALSE; |
164 |
unsigned char clipstring1[51]; |
165 |
unsigned char clipstring2[51]={"XXXX"}; |
166 |
int RVACTIVE = TRUE; |
167 |
|
168 |
int DicNum; |
169 |
long DicLoc; |
170 |
|
171 |
/*====== Prototypes========================================================*/ |
172 |
|
173 |
FILE *xfopen(char *file_name, char *file_mode, int *xfilelen); |
174 |
int getcharxx(); |
175 |
void RadDisp(); |
176 |
void RadBuild(); |
177 |
int FindRad(unsigned char char1, unsigned char char2); |
178 |
void DoLOOKUP(); |
179 |
void RadLoad(); |
180 |
void KSLoad(); |
181 |
void xjdserver (int type, int dic_no, long index_posn, int sch_str_len, |
182 |
unsigned char *sch_str, int *sch_resp, long *res_index, |
183 |
int *hit_posn, int *res_len, unsigned char *res_str, |
184 |
long *dic_loc ); |
185 |
void OneShot(); |
186 |
void RadSet(); |
187 |
void Verbtoggle(); |
188 |
void FiltSet(); |
189 |
void xjdicrc(); |
190 |
void DoRADICALS(); |
191 |
int Vlookup(); |
192 |
void AppKanji(unsigned char c1,unsigned char c2); |
193 |
void Verbinit(); |
194 |
void KOut(unsigned char *sout); |
195 |
void LoadKana(); |
196 |
void DoRomaji(unsigned char kc); |
197 |
int kanaconv(int rpos, int rlen); |
198 |
void togglemode(); |
199 |
void engpritoggle(); |
200 |
void altdic(int dicincr); |
201 |
void DoKANJI(); |
202 |
void DoJIS(); |
203 |
int addhit(long spot); |
204 |
void GetEUC(unsigned char *eucline); |
205 |
void cbreakon(); |
206 |
void cbreakoff(); |
207 |
void ioctlorig(); |
208 |
void ioctlraw(); |
209 |
void Lookup(); |
210 |
void Lookup2(); |
211 |
void DicSet(); |
212 |
void sjis2jis(int *p1,int *p2);/* Ken Lunde's routine */ |
213 |
void jis2sjis(unsigned char *p1,unsigned char *p2);/* Ken Lunde's routine */ |
214 |
int stringcomp(unsigned char *s1, unsigned char *s2); |
215 |
void FixSJIS(unsigned char *jline); |
216 |
void GetKBStr(unsigned char *prompt); |
217 |
void ExtFileDisp(); |
218 |
void SeekErr(int iores); |
219 |
void KOutc(int c); |
220 |
void KLookup(); |
221 |
int KFlush(unsigned char *msg); |
222 |
int KEOS (unsigned char *msg); |
223 |
void NewWinSize(); |
224 |
int kcmp (unsigned char *t1, unsigned char *t2); |
225 |
unsigned char *DicName(int dn); |
226 |
/*====== end of prototypes==================================================*/ |
227 |
|
228 |
|
229 |
/* ==== ioctl routines supplied by Cameron Blackwood=======================*/ |
230 |
/* ==== BSD compatibility hacked in by Paul Burchard ==============*/ |
231 |
/* These routines are to disable/re-enable "cbreak", when I want to |
232 |
switch in & out of canonical input processing. Mostly xjdic does |
233 |
not use canonical input, as I want to react immediately to most |
234 |
key-presses */ |
235 |
|
236 |
void ioctlraw() |
237 |
{ |
238 |
if (myi_status == IOCTL_ORIG) |
239 |
{ |
240 |
#ifdef __STRICT_BSD__ |
241 |
ioctl(0, TIOCGETP, &orig); ioctl(0, TIOCGETP, &new); |
242 |
new.sg_flags |= CBREAK; new.sg_flags &= ~ECHO; |
243 |
ioctl(0, TIOCSETP, &new); |
244 |
#else |
245 |
ioctl(0, TCGETA, &orig); ioctl(0, TCGETA, &new); |
246 |
new.c_lflag &= ~ICANON; new.c_lflag &= ~ISIG; new.c_lflag &= ~ECHO; |
247 |
new.c_lflag &= ~IXON; |
248 |
new.c_cc[4] = 1; new.c_cc[5] = 0; ioctl(0, TCSETA, &new); |
249 |
#endif |
250 |
myi_status=IOCTL_RAW; |
251 |
} |
252 |
else return; |
253 |
} |
254 |
|
255 |
void ioctlorig() |
256 |
{ |
257 |
#ifdef __STRICT_BSD__ |
258 |
ioctl(0, TIOCSETP, &orig); |
259 |
#else |
260 |
ioctl(0, TCSETA, &orig); |
261 |
#endif |
262 |
myi_status = IOCTL_ORIG; |
263 |
} |
264 |
|
265 |
|
266 |
void cbreakoff() |
267 |
{ |
268 |
ioctlorig(); |
269 |
/*system("stty -cbreak echo");*/ |
270 |
} |
271 |
|
272 |
void cbreakon() |
273 |
{ |
274 |
ioctlraw(); |
275 |
/*system("stty cbreak -echo");*/ |
276 |
} |
277 |
|
278 |
int getcharxx() |
279 |
{ |
280 |
if (clipmode) |
281 |
{ |
282 |
return('n'); |
283 |
} |
284 |
else |
285 |
{ |
286 |
return(getchar()); |
287 |
} |
288 |
} |
289 |
/*====GetWinSize==== Hank Cohen's routine for getting the (new) window size==*/ |
290 |
/* |
291 |
* (The following was supplied by Hank Cohen) |
292 |
* We would like to use the Berkeley winsize structure to determine |
293 |
* the number of lines and columns in the window. If that's not |
294 |
* available we can use termcap. |
295 |
* If using termcap, you will need to compile with "-lcurses -ltermcap". |
296 |
*/ |
297 |
char termcap_buf[1024]; |
298 |
void GetWinSize() |
299 |
{ |
300 |
char *term_name; |
301 |
|
302 |
#ifdef WINSIZE_IOCTL_AVAILABLE |
303 |
struct winsize window; |
304 |
|
305 |
signal(SIGWINCH, NewWinSize); |
306 |
ioctl(0,TIOCGWINSZ,&window); |
307 |
MaxX = window.ws_col; |
308 |
MaxX--; |
309 |
MaxY = window.ws_row; |
310 |
#else /* Use termcap */ |
311 |
if ((term_name = getenv("TERM")) == 0){ |
312 |
fprintf(stderr,"No TERM in environment!\n"); |
313 |
} else if (tgetent(termcap_buf, term_name) != 1) { |
314 |
fprintf(stderr,"No termcap entry for %s!\n", term_name); |
315 |
} else { |
316 |
MaxX = tgetnum("co"); |
317 |
MaxY = tgetnum("li"); |
318 |
} |
319 |
#endif /* termcap */ |
320 |
} |
321 |
void NewWinSize() |
322 |
{ |
323 |
struct winsize window; |
324 |
ioctl(0,TIOCGWINSZ,&window); |
325 |
MaxX = window.ws_col; |
326 |
MaxX--; |
327 |
MaxY = window.ws_row; |
328 |
} |
329 |
|
330 |
/*=====KSLoad===Load file of kanji/stroke data==========================*/ |
331 |
void KSLoad() |
332 |
{ |
333 |
int i,j,k,lno; |
334 |
FILE *fk,*fopen(); |
335 |
|
336 |
fk = xfopen(KSname,"r",&xfilelen); |
337 |
lno=0; |
338 |
while(!feof(fk)) |
339 |
{ |
340 |
fgets(testline,9,fk); |
341 |
if(feof(fk)) break; |
342 |
testline[3] = 0; |
343 |
lno++; |
344 |
i = ((testline[0] & 0x7f)-0x30)*94 + ((testline[1] & 0x7f) - 0x21); |
345 |
if ((i < 0) || (i > 6999)) |
346 |
{ |
347 |
printf("Bad kanji in %s at line %d (%s)\n",KSname,lno,testline); |
348 |
i = 6999; |
349 |
} |
350 |
kstrokes[i] = testline[2]-'0'; |
351 |
} |
352 |
fclose(fk); |
353 |
} |
354 |
|
355 |
/*=====RadLoad===Load file of Radical Data==============================*/ |
356 |
void RadLoad() |
357 |
{ |
358 |
int i,j,k; |
359 |
FILE *fk,*fopen(); |
360 |
|
361 |
fk = xfopen(RKname,"r", &xfilelen); |
362 |
k = xfilelen/2; |
363 |
RKanj1 = malloc(k*sizeof(char)); |
364 |
if (RKanj1==NULL) |
365 |
{ |
366 |
printf("malloc failed for radical tables!\n"); |
367 |
exit(1); |
368 |
} |
369 |
RKanj2 = malloc(k*sizeof(char)); |
370 |
if (RKanj2==NULL) |
371 |
{ |
372 |
printf("malloc failed for radical tables!\n"); |
373 |
exit(1); |
374 |
} |
375 |
i = -1; |
376 |
j = 0; |
377 |
rmax = 0; |
378 |
while(!feof(fk)) |
379 |
{ |
380 |
fgets(testline,199,fk); |
381 |
if(feof(fk)) break; |
382 |
if (testline[0] == '$') |
383 |
{ |
384 |
i++; |
385 |
RadK1[i] = testline[2]; |
386 |
RadK2[i] = testline[3]; |
387 |
RKStart[i] = j; |
388 |
RKCnt[i] = 0; |
389 |
if (i != 0) |
390 |
{ |
391 |
if (RKCnt[i-1] > rmax) rmax = RKCnt[i-1]; |
392 |
} |
393 |
} |
394 |
else |
395 |
{ |
396 |
for (k = 0; k < strlen(testline); k++) |
397 |
{ |
398 |
if (testline[k] < 127) continue; |
399 |
RKanj1[j] = testline[k]; |
400 |
RKanj2[j] = testline[k+1]; |
401 |
RKCnt[i]++; |
402 |
j++; |
403 |
k++; |
404 |
} |
405 |
} |
406 |
} |
407 |
fclose(fk); |
408 |
NoRads = i; |
409 |
for (i=0; i<10;i++) |
410 |
{ |
411 |
RKSet[i] = malloc(2*rmax+1); |
412 |
if (RKSet[i] == NULL) |
413 |
{ |
414 |
printf("malloc() failed for Radical set(s)!\n"); |
415 |
} |
416 |
} |
417 |
} |
418 |
/*=====DoRomaji==collect search key from keyboard. Convert to kana.======*/ |
419 |
/* Code originally from JDIC */ |
420 |
void DoRomaji(unsigned char kc) |
421 |
{ |
422 |
int is; |
423 |
unsigned char c; |
424 |
|
425 |
/* collect the search string */ |
426 |
Smode = 1; |
427 |
if(kc == '#') Smode = 2; |
428 |
is = 0; |
429 |
ksp = 0; |
430 |
c = 0; |
431 |
ktarg[0] = 0; |
432 |
printf("\r \r%sROMAJI ENTRY:%s ",RVon,RVoff); |
433 |
while (c != 0x0a) /* loop until Enter is pressed */ |
434 |
{ |
435 |
c = getcharxx(); |
436 |
|
437 |
if ((c == 0x8)||(c == 0x7f)) /* backspace */ |
438 |
{ |
439 |
if (is != ksp) /* kana mode - back over a romaji */ |
440 |
{ |
441 |
ksch[is-1] = '\0'; |
442 |
is--; |
443 |
sprintf(tempout,"\r \r%sROMAJI ENTRY:%s %s%s",RVon,RVoff,ktarg,ksch+ksp); |
444 |
KOut(tempout); |
445 |
continue; |
446 |
} |
447 |
else |
448 |
{ |
449 |
if (strlen(ktarg) != 0) /* kana mode - back over a kana */ |
450 |
{ |
451 |
ktarg[strlen(ktarg)-2] = '\0'; |
452 |
sprintf(tempout,"\r \r%sROMAJI ENTRY:%s %s%s",RVon,RVoff,ktarg,ksch+ksp); |
453 |
KOut(tempout); |
454 |
continue; |
455 |
} |
456 |
} |
457 |
} |
458 |
if (c > 32) /* ordinary character - store and display */ |
459 |
{ |
460 |
ksch[is] = c | 0x20; |
461 |
ksch[is+1] = '\0'; |
462 |
is++; |
463 |
sprintf(tempout,"\r \r%sROMAJI ENTRY:%s %s%s",RVon,RVoff,ktarg,ksch+ksp); |
464 |
KOut(tempout); |
465 |
} |
466 |
if (ksp != is) |
467 |
{ |
468 |
|
469 |
/* the input string so far is now parsed for romaji -> kana conversions. |
470 |
function "kanaconv" is used for the various sub-strings */ |
471 |
|
472 |
/* if there is an "nn", "nm" or "mm", convert to first to "q" to force it to be |
473 |
converted to a kana "n" */ |
474 |
if ((ksch[ksp] == 'n')&&(ksch[ksp+1] == 'n')) ksch[ksp] = 'q'; |
475 |
if ((ksch[ksp] == 'm')&&(ksch[ksp+1] == 'm')) ksch[ksp] = 'q'; |
476 |
if ((ksch[ksp] == 'n')&&(ksch[ksp+1] == 'm')) ksch[ksp] = 'q'; |
477 |
/* if there is "nx", where "x" is not a vowel or a "y", force the "n". */ |
478 |
if (((ksch[ksp] == 'n')||(ksch[ksp] == 'm'))&&(ksch[ksp+1] != 0)) |
479 |
{ |
480 |
c = ksch[ksp+1]; |
481 |
if((c!='y')&&(c!='a')&&(c!='e')&&(c!='i')&&(c!='o')&&(c!='u')&&(c!='\'')) |
482 |
{ |
483 |
ksch[ksp] = 'q'; |
484 |
} |
485 |
} |
486 |
if(kanaconv(ksp,1)) /* match on a,e,i,o,u,q or - ? */ |
487 |
{ |
488 |
continue; |
489 |
} |
490 |
if(ksch[ksp] == '\'') |
491 |
{ |
492 |
ksp++; |
493 |
continue; |
494 |
} |
495 |
if (ksch[ksp] == ksch[ksp+1]) /* double consonant - force small |
496 |
"tsu" */ |
497 |
{ |
498 |
ksch[ksp] = '*'; |
499 |
kanaconv(ksp,1); |
500 |
continue; |
501 |
} |
502 |
if(kanaconv(ksp,2)) /* match on two letter syllable */ |
503 |
{ |
504 |
continue; |
505 |
} |
506 |
if(kanaconv(ksp,3)) /*match on 3 letter syllable */ |
507 |
{ |
508 |
continue; |
509 |
} |
510 |
if(kanaconv(ksp,4)) /*match on 4 letter syllable */ |
511 |
{ |
512 |
continue; |
513 |
} |
514 |
} /* end of rom->kana */ |
515 |
} /* end of while loop */ |
516 |
if (ksch[ksp] =='n') /*flush out a trailing "n"*/ |
517 |
{ |
518 |
ksch[ksp] = 'q'; |
519 |
kanaconv(ksp,1); |
520 |
} |
521 |
|
522 |
strcpy(instr,ktarg); |
523 |
} |
524 |
|
525 |
/*========kanaconv==convert romaji to kana==============================*/ |
526 |
/* More code from JDIC */ |
527 |
int kanaconv(int rpos, int rlen) |
528 |
{ |
529 |
/* rpos and rlen are the start and length of the romaji characters in |
530 |
array ksch. Smode specifies hira or kata. If found, the kana is |
531 |
appended to ktarg and TRUE returned. */ |
532 |
|
533 |
int koff,ki; |
534 |
unsigned char targ[50]; |
535 |
|
536 |
koff = (Smode-1)*NRKANA; |
537 |
for(ki = 0; ki < rlen; ki++) |
538 |
{ |
539 |
targ[ki] = ksch[rpos+ki]; |
540 |
} |
541 |
targ[rlen] = 0; |
542 |
for (ki = koff; ki < koff+NRKANA; ki+=2) |
543 |
{ |
544 |
if (strlen(targ) != strlen(kanatab[ki])) continue; |
545 |
if (stringcomp(targ,kanatab[ki]) != 0) continue; |
546 |
strcat(ktarg,kanatab[ki+1]); |
547 |
ksp = ksp+rlen; |
548 |
sprintf(tempout,"\r \r%sROMAJI ENTRY:%s %s%s",RVon,RVoff,ktarg,ksch+ksp); |
549 |
KOut(tempout); |
550 |
return (TRUE); |
551 |
} |
552 |
return(FALSE); |
553 |
} |
554 |
|
555 |
/* ==== LoadKana=== Load the romaji to kana conversion file============*/ |
556 |
void LoadKana() |
557 |
{ |
558 |
int i,ih,mode; |
559 |
FILE *fp,*fopen(); |
560 |
unsigned char LKin[80],*ptr; |
561 |
|
562 |
for (i = 0; i < NRKANA*2; i++) strcpy(kanatab[i]," "); |
563 |
fp = xfopen(ROMname,"r", &xfilelen); |
564 |
mode = 0; |
565 |
while (!feof(fp)) |
566 |
{ |
567 |
fgets(LKin,79,fp); |
568 |
if (feof(fp))break; |
569 |
/*LKin[strlen(LKin)-1] = '\0';*/ |
570 |
if(LKin[0] == '#')continue; |
571 |
if((LKin[0] == '$')&&((LKin[1]|0x20) == 'h')) |
572 |
{ |
573 |
mode = 0; |
574 |
ih = 0; |
575 |
continue; |
576 |
} |
577 |
if((LKin[0] == '$')&&((LKin[1]|0x20) == 'k')) |
578 |
{ |
579 |
mode = 1; |
580 |
ih = 0; |
581 |
continue; |
582 |
} |
583 |
ptr = (unsigned char *)strtok(LKin," \t"); |
584 |
if ( ptr != NULL ) strcpy(kanatab[mode*NRKANA+ih*2+1],ptr); |
585 |
ptr = (unsigned char *)strtok(NULL," \t\r\n"); |
586 |
if ( ptr != NULL ) strcpy(kanatab[mode*NRKANA+ih*2],ptr); |
587 |
ih++; |
588 |
if(ih == NRKANA) |
589 |
{ |
590 |
printf("Too many romaji table entries!"); |
591 |
exit(1); |
592 |
} |
593 |
} |
594 |
fclose(fp); |
595 |
} |
596 |
/*======jis2sjis (from Ken Lunde) =====================================*/ |
597 |
void jis2sjis(unsigned char *p1,unsigned char *p2) /* courtesy of Ken Lunde */ |
598 |
{ |
599 |
register unsigned char c1 = *p1; |
600 |
register unsigned char c2 = *p2; |
601 |
register int rowOffset = c1 < 95 ? 112 : 176; |
602 |
register int cellOffset = c1 % 2 ? 31 + (c2 > 95) : 126; |
603 |
|
604 |
*p1 = ((c1 + 1) >> 1) + rowOffset; |
605 |
*p2 = c2 + cellOffset; |
606 |
} |
607 |
|
608 |
/*====KEOS===End of screen processing for KFlush==================*/ |
609 |
int KEOS (unsigned char *msg) |
610 |
{ |
611 |
unsigned char ck; |
612 |
|
613 |
if (DRow < MaxY-2) return(TRUE); |
614 |
DRow = 0; |
615 |
if (strlen(msg) == 0) return (TRUE); |
616 |
printf("%s\n",msg); |
617 |
ck = getcharxx(); |
618 |
if ((ck == 'n')||(ck == 'N')) return (FALSE); |
619 |
if ((ck == 'y')||(ck == 'Y')) return (TRUE); |
620 |
if ((ck != 0xa) && (ck != 0xd)) ungetc(ck,stdin); |
621 |
return (FALSE); |
622 |
} |
623 |
/*====KFlush==== Output a line, folding if necessary===============*/ |
624 |
/* This is now the main screen output routine. An array "KLine" |
625 |
is built up of text to be output. KFlush() sends it to the screen, |
626 |
folding the line at white-space if it is about to hit the RHS. |
627 |
It also tests for end of screen, and prompts for continuation, |
628 |
using the KEOS(). Returns TRUE for continue, and FALSE for |
629 |
stopping. |
630 |
Called with the prompt measseage. */ |
631 |
|
632 |
int KFlush(unsigned char *msg) |
633 |
{ |
634 |
unsigned char *kptr,ktemp[512]; |
635 |
int retf,it,j; |
636 |
int Test; |
637 |
|
638 |
if (strlen(KLine) == 0) return (TRUE); |
639 |
kptr = (unsigned char *)strtok(KLine," "); |
640 |
while (kptr != NULL) |
641 |
{ |
642 |
Test = MaxX; |
643 |
strcpy(ktemp,kptr); |
644 |
if (ktemp[0] == '\t') |
645 |
{ |
646 |
it = DCol % 10; |
647 |
if (it != 0) |
648 |
{ |
649 |
DCol = DCol+10-it; |
650 |
if (DCol <= Test-1) |
651 |
{ |
652 |
for (j = 0;j < 10-it;j++) KOut(" "); |
653 |
} |
654 |
} |
655 |
strcpy(ktemp,ktemp+1); |
656 |
} |
657 |
it = strlen(ktemp); |
658 |
if (DCol+it < Test) |
659 |
{ |
660 |
DCol = DCol+it+1; |
661 |
} |
662 |
else |
663 |
{ |
664 |
KOut("\n"); |
665 |
DRow++; |
666 |
DCol=it+1; |
667 |
retf = KEOS(msg); |
668 |
if (!retf) return (FALSE); |
669 |
} |
670 |
KOut(ktemp); |
671 |
if (DCol <= MAXCOLS) KOut(" "); |
672 |
kptr = (unsigned char *)strtok(NULL," "); |
673 |
} |
674 |
KOut("\n"); |
675 |
DRow++; |
676 |
retf = KEOS(msg); |
677 |
DCol = 0; |
678 |
if (!retf) return (FALSE); |
679 |
return (TRUE); |
680 |
} |
681 |
/*====KOutc===add a character to KLine=============================*/ |
682 |
void KOutc(int c) |
683 |
{ |
684 |
unsigned char tmp[2]; |
685 |
tmp[0] = c; |
686 |
tmp[1] = 0; |
687 |
strcat(KLine,tmp); |
688 |
return; |
689 |
} |
690 |
|
691 |
/*=====KOut===output kana/kanji according to selected mode===========*/ |
692 |
/* Mostly called from KFlush. Outputs the parameter string, in the |
693 |
specified JIS mode. */ |
694 |
void KOut(unsigned char *sout) |
695 |
{ |
696 |
int i; |
697 |
unsigned char c1,c2; |
698 |
|
699 |
for (i = 0; i < strlen(sout); i++) |
700 |
{ |
701 |
c1 = sout[i]; c2 = sout[i+1]; |
702 |
if (c1 < 127) |
703 |
{ |
704 |
if (c1 == '~') c1 = ' '; |
705 |
printf("%c",c1); |
706 |
continue; |
707 |
} |
708 |
switch(Omode) |
709 |
{ |
710 |
case 0 : /* JIS (default) */ |
711 |
if (c1 == 0x8f) |
712 |
{ |
713 |
printf("%c$(D%c%c%c(B",0x1b,c2&0x7f,sout[i+2]&0x7f,0x1b); |
714 |
i+=2; |
715 |
break; |
716 |
} |
717 |
printf("%c$B%c%c%c(B",0x1b,c1&0x7f,c2&0x7f,0x1b); |
718 |
i++; |
719 |
break; |
720 |
|
721 |
case 1 : /* EUC (internal format) */ |
722 |
if (c1 == 0x8f) |
723 |
{ |
724 |
printf("%c%c%c",c1,c2,sout[i+2]); |
725 |
i+=2; |
726 |
break; |
727 |
} |
728 |
printf("%c%c",c1,c2); |
729 |
i++; |
730 |
break; |
731 |
|
732 |
case 2 : /* Shift-JIS */ |
733 |
c1 -= 128; c2 -= 128; |
734 |
jis2sjis(&c1,&c2); |
735 |
printf("%c%c",c1,c2); |
736 |
i++; |
737 |
break; |
738 |
} |
739 |
} |
740 |
} |
741 |
|
742 |
/*======function to test if this entry has already been displayed=====*/ |
743 |
int addhit(long spot) |
744 |
{ |
745 |
int i; |
746 |
|
747 |
if (spot == 0) return(TRUE); |
748 |
|
749 |
for (i=0;i<=hitind;i++) |
750 |
{ |
751 |
if(hittab[i] == spot) return(FALSE); |
752 |
} |
753 |
if(hitind < NOHITS) hitind++; |
754 |
hittab[hitind] = spot; |
755 |
return(TRUE); |
756 |
} |
757 |
|
758 |
/*====GetEUC - ensures that any JIS in the string is EUC ============*/ |
759 |
/* Based on the GetEUC in JREADER, this routine examines |
760 |
the string "instr" and converts any JIS or SJIS to EUC. |
761 |
The result is placed in the specified string. */ |
762 |
|
763 |
void GetEUC(unsigned char *eucline) |
764 |
{ |
765 |
int i,j,SI,J212,J212sw; |
766 |
|
767 |
J212 = FALSE; |
768 |
eucline[0] = '\0'; |
769 |
chline = 0; |
770 |
chpos = 0; |
771 |
SI = FALSE; |
772 |
ShiftJIS = FALSE; |
773 |
j = 0; |
774 |
for (i = 0; i < strlen(instr); i++) |
775 |
{ |
776 |
if((instr[i]==0x1b)&&(instr[i+1]=='$')&&(instr[i+2]=='(')&&(instr[i+3]=='D')) |
777 |
{ |
778 |
SI = TRUE; |
779 |
J212 = TRUE; |
780 |
J212sw = 0; |
781 |
NoSJIS = TRUE; |
782 |
i+=3; |
783 |
continue; |
784 |
} |
785 |
if((instr[i]==0x1b)&&(instr[i+1]=='$')&&(instr[i+2]=='B')) |
786 |
{ |
787 |
SI = TRUE; |
788 |
J212 = FALSE; |
789 |
i+=2; |
790 |
continue; |
791 |
} |
792 |
if((instr[i]==0x1b)&&(instr[i+1]=='$')&&(instr[i+2]=='@')) |
793 |
{ |
794 |
SI = TRUE; |
795 |
J212 = FALSE; |
796 |
i+=2; |
797 |
continue; |
798 |
} |
799 |
if((instr[i]==0x1b)&&(instr[i+1]=='(')&&(instr[i+2]=='J')) |
800 |
{ |
801 |
SI = FALSE; |
802 |
J212 = FALSE; |
803 |
i+=2; |
804 |
continue; |
805 |
} |
806 |
if((instr[i]==0x1b)&&(instr[i+1]=='(')&&(instr[i+2]=='B')) |
807 |
{ |
808 |
SI = FALSE; |
809 |
J212 = FALSE; |
810 |
i+=2; |
811 |
continue; |
812 |
} |
813 |
if (instr[i] == '\0')break; |
814 |
if (SI) |
815 |
{ |
816 |
if (J212 && (J212sw == 0)) eucline[j++] = 0x8f; |
817 |
eucline[j] = instr[i] | 0x80; |
818 |
J212sw = (J212sw+1) % 2; |
819 |
} |
820 |
else |
821 |
{ |
822 |
eucline[j] = instr[i]; |
823 |
} |
824 |
j++; |
825 |
eucline[j] = '\0'; |
826 |
} |
827 |
/* fix up SHIFT-JIS, if present */ |
828 |
if (!NoSJIS) FixSJIS(eucline); |
829 |
} |
830 |
|
831 |
/*====FixSJIS=== convert any SJIS to EUC in a string==================*/ |
832 |
void FixSJIS(unsigned char *jline) |
833 |
{ |
834 |
int i,p1,p2,ShiftJIS; |
835 |
|
836 |
ShiftJIS = FALSE; |
837 |
for (i = 0; i < strlen(jline); i++) |
838 |
{ |
839 |
p1 = jline[i]; |
840 |
if (p1 < 127)continue; |
841 |
p2 = jline[i+1]; |
842 |
if ((p1 >= 129) && (p1 <= 159)) ShiftJIS = TRUE; |
843 |
if (((p1 >= 224) && (p1 <= 239))&& ((p2 >= 64) && (p2 <= 158))) ShiftJIS = TRUE; |
844 |
if (ShiftJIS) |
845 |
{ |
846 |
sjis2jis (&p1,&p2); |
847 |
p1 += 128; |
848 |
p2 += 128; |
849 |
jline[i] = p1; |
850 |
jline[i+1] = p2; |
851 |
|
852 |
} |
853 |
i++; |
854 |
} |
855 |
} |
856 |
|
857 |
/*===sjis2jis - convert ShiftJIS to JIS ===========================*/ |
858 |
|
859 |
void sjis2jis (int *p1,int *p2) /* Ken Lunde's routine */ |
860 |
{ |
861 |
register unsigned char c1 = *p1; |
862 |
register unsigned char c2 = *p2; |
863 |
register int adjust = c2 < 159; |
864 |
register int rowOffset = c1 < 160 ? 112 : 176; |
865 |
register int cellOffset = adjust ? (31 + (c2 > 127)) : 126; |
866 |
|
867 |
*p1 = ((c1 - rowOffset) << 1) - adjust; |
868 |
*p2 -= cellOffset; |
869 |
} |
870 |
|
871 |
/*====ExtFileDisp===Display from EDICTEXT file=======================*/ |
872 |
|
873 |
void ExtFileDisp() |
874 |
{ |
875 |
|
876 |
unsigned extrec[2],seekoff,iores,hi,lo,mid,ejdxtest[2]; |
877 |
unsigned char Ssch[20]; |
878 |
int bsres,i; |
879 |
|
880 |
printf("%sExtension Key:%s ",RVon,RVoff); |
881 |
|
882 |
GetKBStr("Extension Key:"); |
883 |
if(fbuff[0] < 128) |
884 |
{ |
885 |
printf("\nThe extension file has Kanji & Kana keys\n"); |
886 |
return; |
887 |
} |
888 |
if(!Extopen) |
889 |
{ |
890 |
fe = xfopen(EXTname,"rb", &extlen); |
891 |
fex = xfopen(EXTJDXname,"rb", &extjdxlen); |
892 |
Extopen = TRUE; |
893 |
extlen++; |
894 |
fread(ejdxtest,sizeof(long),1,fex); |
895 |
if (ejdxtest[0] != (extlen+jiver)) |
896 |
{ |
897 |
printf("\nEDICT Extension file & Index Mismatch! %ld %ld\n",ejdxtest[0],extlen+jiver); |
898 |
exit(1); |
899 |
} |
900 |
} |
901 |
|
902 |
lo = 0; |
903 |
hi = (extjdxlen/(2*sizeof(long)))-1; |
904 |
while(TRUE) |
905 |
{ |
906 |
mid = (lo+hi)/2; |
907 |
seekoff = mid; |
908 |
seekoff *= (2*sizeof(long)); |
909 |
seekoff+=sizeof(long); |
910 |
if((iores = fseek(fex,seekoff,SEEK_SET)) != 0)SeekErr(iores); |
911 |
iores = fread(&extrec,sizeof(long),2,fex); |
912 |
seekoff = extrec[0]; |
913 |
if((iores = fseek(fe,seekoff,SEEK_SET)) != 0)SeekErr(iores); |
914 |
iores = fread(&Ssch,sizeof(char),19,fe); |
915 |
Ssch[19] = 0; |
916 |
i = 0; |
917 |
bsres = 0; |
918 |
for (i = 0; Ssch[i] != 0 ;i++) |
919 |
{ |
920 |
if (Ssch[i] < 128) break; |
921 |
if (fbuff[i] < 128) break; |
922 |
if (fbuff[i] < Ssch[i]) |
923 |
{ |
924 |
bsres = -1; |
925 |
break; |
926 |
} |
927 |
if (fbuff[i] > Ssch[i]) |
928 |
{ |
929 |
bsres = 1; |
930 |
break; |
931 |
} |
932 |
} |
933 |
if ((bsres != 0) && ((lo + hi) == 0)) break; |
934 |
if(bsres < 0) |
935 |
{ |
936 |
if (mid == 0) break; |
937 |
hi = mid-1; |
938 |
} |
939 |
else |
940 |
{ |
941 |
lo = mid+1; |
942 |
} |
943 |
if (bsres == 0) break; |
944 |
if (lo > hi) break; |
945 |
if (hi < 0) break; |
946 |
} |
947 |
if (bsres == 0) |
948 |
{ |
949 |
printf("\n%sDictionary Extension Display%s\n",RVon,RVoff); |
950 |
seekoff = extrec[1]; |
951 |
if((iores = fseek(fe,seekoff,SEEK_SET)) != 0)SeekErr(iores); |
952 |
strcpy (KLine," <"); |
953 |
DRow = 0; |
954 |
DCol = 0; |
955 |
while(!feof(fe)) |
956 |
{ |
957 |
fgets(LogLine,199,fe); |
958 |
if (feof(fe)) break; |
959 |
if ((LogLine[0] == '<') && (LogLine[1] > 128)) break; |
960 |
for (i = strlen(LogLine); i >= 0; i--) |
961 |
{ |
962 |
if (LogLine[i] < 0x20) LogLine[i] = 0; |
963 |
} |
964 |
strcat(KLine,LogLine); |
965 |
if (!KFlush("Continue displaying extension information? (y/n)")) break; |
966 |
DCol = 0; |
967 |
strcpy (KLine," "); |
968 |
} |
969 |
return; |
970 |
} |
971 |
if (bsres != 0) |
972 |
{ |
973 |
printf("\nNot found in Extension file!\n"); |
974 |
return; |
975 |
} |
976 |
} |
977 |
/*====kcmp === comparison routine for qsort for kanji table==========*/ |
978 |
int kcmp (unsigned char *t1, unsigned char *t2) |
979 |
{ |
980 |
int i,cmp; |
981 |
for (i=0;i<4;i++) |
982 |
{ |
983 |
cmp = t1[i] - t2[i]; |
984 |
if (cmp == 0) continue; |
985 |
return(cmp); |
986 |
} |
987 |
return(0); |
988 |
} |
989 |
|
990 |
/*==== Verbinit===Load & initialize verb inflection details==========*/ |
991 |
void Verbinit() |
992 |
{ |
993 |
unsigned char tempstr[512],*vptr; |
994 |
int vmode,i; |
995 |
FILE *fi,*fopen(); |
996 |
|
997 |
for (i = 0;i< VMAX;i++) |
998 |
{ |
999 |
vdicf[i][0] = 0; |
1000 |
vinfl[i][0] = 0; |
1001 |
vcommno[i] = 40; |
1002 |
} |
1003 |
for (i = 0;i<40;i++) |
1004 |
{ |
1005 |
vcomms[i][0] = 0; |
1006 |
} |
1007 |
vmode = 1; |
1008 |
strcpy(vcomms[40],"Unknown type"); |
1009 |
verblen = 0; |
1010 |
fi = xfopen(Vname,"r", &xfilelen); |
1011 |
while(TRUE) |
1012 |
{ |
1013 |
fgets(tempstr,511,fi); |
1014 |
if(feof(fi))break; |
1015 |
if (tempstr[0] == '#')continue; |
1016 |
if (tempstr[0] == '$') |
1017 |
{ |
1018 |
vmode = 2; |
1019 |
continue; |
1020 |
} |
1021 |
|
1022 |
switch (vmode) { |
1023 |
case 1 : |
1024 |
vptr = (unsigned char *)strtok(tempstr," \t\n\r"); |
1025 |
i = atoi(vptr); |
1026 |
if ((i < 0) || (i > 39)) break; |
1027 |
vptr = (unsigned char *)strtok(NULL,"\t\n\r"); |
1028 |
strcpy(vcomms[i],vptr); |
1029 |
break; |
1030 |
case 2 : |
1031 |
vptr = (unsigned char *)strtok(tempstr," \t\n\r"); |
1032 |
strcpy(vinfl[verblen],vptr); |
1033 |
vptr = (unsigned char *)strtok(NULL," \t\n\r"); |
1034 |
strcpy(vdicf[verblen],vptr); |
1035 |
vptr = (unsigned char *)strtok(NULL," \t\n\r"); |
1036 |
i = atoi(vptr); |
1037 |
if ((i >= 0)&&(i <= 40)) vcommno[verblen] = i; |
1038 |
verblen++; |
1039 |
if (verblen==VMAX) |
1040 |
{ |
1041 |
printf("Verb data overflow. Ignoring following entries\n"); |
1042 |
verblen--; |
1043 |
fclose(fi); |
1044 |
return; |
1045 |
} |
1046 |
break; |
1047 |
} |
1048 |
} |
1049 |
verblen--; |
1050 |
fclose(fi); |
1051 |
} |
1052 |
|
1053 |
/*=== append a kana/kanji to the verb display line================*/ |
1054 |
void AppKanji(unsigned char c1,unsigned char c2) |
1055 |
{ |
1056 |
unsigned char ops[3]; |
1057 |
|
1058 |
ops[0] = c1; |
1059 |
ops[1] = c2; |
1060 |
ops[2] = 0; |
1061 |
strcat(vline,ops); |
1062 |
} |
1063 |
|
1064 |
/*=======Vlookup== look up plain form verb in dictionary=============*/ |
1065 |
int Vlookup() |
1066 |
{ |
1067 |
|
1068 |
int xjresp,roff,rlen; |
1069 |
unsigned char repstr[512]; |
1070 |
long respos; |
1071 |
int hit,schix; |
1072 |
unsigned char khi,klo,cc,ops[4]; |
1073 |
long it; |
1074 |
|
1075 |
DicNum = CurrDic; |
1076 |
khi = 0; |
1077 |
klo = 0; |
1078 |
vline[0] = 0; |
1079 |
xjdserver (XJ_FIND, DicNum,it, strlen(vstr), vstr, |
1080 |
&xjresp, &respos, &roff, &rlen, repstr, &DicLoc); |
1081 |
if (xjresp != XJ_OK) return (FALSE); |
1082 |
it = respos; |
1083 |
while (xjresp == XJ_OK) |
1084 |
{ |
1085 |
if (roff != 0) |
1086 |
{ |
1087 |
it++; |
1088 |
xjdserver (XJ_ENTRY, DicNum, it, strlen(vstr), vstr, |
1089 |
&xjresp, &respos, &roff, &rlen, repstr, &DicLoc); |
1090 |
continue; |
1091 |
} |
1092 |
schix = 0; |
1093 |
/* now work forwards, displaying the line */ |
1094 |
hit = FALSE; |
1095 |
/* If the first word has already been displayed, skip it. |
1096 |
Otherwise, put braces around the first word (kanji) */ |
1097 |
while (TRUE) |
1098 |
{ |
1099 |
cc = repstr[schix]; |
1100 |
if (cc < 32) break; |
1101 |
/* put a () around the yomikata in an ascii or Kanji search */ |
1102 |
if (cc=='[') |
1103 |
{ |
1104 |
AppKanji(0xa1,0xcA); /* EUC ( */ |
1105 |
schix++; |
1106 |
continue; |
1107 |
} |
1108 |
if (cc==']') |
1109 |
{ |
1110 |
AppKanji(0xA1,0xCB); /* EUC ) */ |
1111 |
schix++; |
1112 |
continue; |
1113 |
} |
1114 |
if (cc < 128) /* non-Japanese, display it |
1115 |
(fix up the "/") */ |
1116 |
{ |
1117 |
ops[0]= cc; |
1118 |
ops[1] = '\0'; |
1119 |
if (ops[0] == '/') |
1120 |
{ |
1121 |
if (hit) |
1122 |
{ |
1123 |
ops[0] = ','; |
1124 |
ops[1] = ' '; |
1125 |
ops[2] = '\0'; |
1126 |
} |
1127 |
else |
1128 |
{ |
1129 |
hit = TRUE; |
1130 |
ops[0] = '\0'; |
1131 |
} |
1132 |
} |
1133 |
strcat(vline,ops); |
1134 |
} |
1135 |
else |
1136 |
{ |
1137 |
if (cc == 0x8f) |
1138 |
{ |
1139 |
AppKanji(cc,0); |
1140 |
schix++; |
1141 |
continue; |
1142 |
} |
1143 |
if (khi == 0) |
1144 |
{ |
1145 |
khi = cc; |
1146 |
} |
1147 |
else |
1148 |
{ |
1149 |
klo = cc; |
1150 |
AppKanji(khi,klo); |
1151 |
khi = 0; |
1152 |
klo = 0; |
1153 |
} |
1154 |
} |
1155 |
schix++; |
1156 |
} |
1157 |
if(strlen(vline) > 0) break; |
1158 |
} |
1159 |
if(strlen(vline) <=1) return(FALSE); |
1160 |
return(TRUE); |
1161 |
} |
1162 |
/*=========== slencal - calculate the actual search string length ===*/ |
1163 |
/* This routine exists to sort out the actual length of the search |
1164 |
string when there is a mix of 2 and 3-byte EUC characters */ |
1165 |
|
1166 |
int slencal (int noch, unsigned char *targ) |
1167 |
{ |
1168 |
int i,j; |
1169 |
|
1170 |
if (targ[0] < 127) return(noch+1); |
1171 |
i = 0; |
1172 |
j = 0; |
1173 |
while(i <= noch) |
1174 |
{ |
1175 |
if (targ[j] == 0x8f) j++; |
1176 |
i++; |
1177 |
j+=2; |
1178 |
} |
1179 |
return(j); |
1180 |
} |
1181 |
|
1182 |
/*=========== Lookup - global frontend to dictionary search ========*/ |
1183 |
void Lookup() |
1184 |
{ |
1185 |
int gi,dicsav,gdiclenbest; |
1186 |
unsigned char retsave[KFBUFFSIZE],rethdr[5]; |
1187 |
|
1188 |
retsave[0] = 0; |
1189 |
gdiclen = 0; |
1190 |
gdiclenbest = 0; |
1191 |
if ((!GDmode) || (Dmode == 1)) |
1192 |
{ |
1193 |
Lookup2(); |
1194 |
return; |
1195 |
} |
1196 |
if (gdicmax == 0) |
1197 |
{ |
1198 |
printf("\nNo global dictionaries specified - disabling!\n"); |
1199 |
GDmode = FALSE; |
1200 |
Lookup2(); |
1201 |
return; |
1202 |
} |
1203 |
dicsav = CurrDic; |
1204 |
for (gi=0;gi<=gdicmax;gi++) |
1205 |
{ |
1206 |
CurrDic = gdicnos[gi]; |
1207 |
Lookup2(); |
1208 |
if (GDALLmode) |
1209 |
{ |
1210 |
strcpy(retsave,KLine); |
1211 |
strcpy(rethdr,"[X] "); |
1212 |
rethdr[1] = '0'+gdicnos[gi]; |
1213 |
strcpy(KLine,rethdr); |
1214 |
strcat(KLine,retsave); |
1215 |
KFlush(""); |
1216 |
continue; |
1217 |
} |
1218 |
if ((gdiclen > gdiclenbest) || ((strlen(KLine) > strlen(retsave)) && (gdiclen == gdiclenbest))) |
1219 |
{ |
1220 |
strcpy(retsave,KLine); |
1221 |
strcpy(rethdr,"[X] "); |
1222 |
rethdr[1] = '0'+gdicnos[gi]; |
1223 |
gdiclenbest = gdiclen; |
1224 |
} |
1225 |
} |
1226 |
if (GDALLmode) |
1227 |
{ |
1228 |
CurrDic = dicsav; |
1229 |
return; |
1230 |
} |
1231 |
strcpy(KLine,rethdr); |
1232 |
strcat(KLine,retsave); |
1233 |
KFlush(""); |
1234 |
CurrDic = dicsav; |
1235 |
} |
1236 |
|
1237 |
|
1238 |
|
1239 |
/*=========== Lookup2 - carry out dictionary search ================*/ |
1240 |
void Lookup2() |
1241 |
{ |
1242 |
/* |
1243 |
|
1244 |
Carries out a search for matches with the string "fbuff" in the specified |
1245 |
dictionary. It matches the full string, then progressively shortens it. |
1246 |
|
1247 |
*/ |
1248 |
int schix,schiy,schiz,j,dind,hit,skip,brace,engrv; |
1249 |
int EngFirst; |
1250 |
int slk,slen,slenx,i,srchlen,srchlenok; |
1251 |
unsigned int khi,klo,cc; |
1252 |
unsigned long zz,bshit[20]; |
1253 |
unsigned char *kptr,*kptr2, k1,k2,kanj1,kanj2,kanj3; |
1254 |
int FiltOK; |
1255 |
unsigned char vlast[11],temp[11],ops[80]; |
1256 |
int vi,vok,prevch,KDNSflag,KDskip,KTest; |
1257 |
int xjresp,roff,rlen; |
1258 |
unsigned char repstr[512]; |
1259 |
unsigned long respos; |
1260 |
|
1261 |
vlast[0] = 0; |
1262 |
KLcount = 0; |
1263 |
DRow = 3; |
1264 |
|
1265 |
if (!GDmode && (Dmode == 0)&&Jverb&&(fbuff[0] > 0xa8) && (fbuff[2] < 0xa5) && (fbuff[4] < 0xa5)) |
1266 |
{ |
1267 |
/* possible inflected verb or adjective, so look up the verb table |
1268 |
for a matching plain form, and serch the dictionary for it */ |
1269 |
|
1270 |
vstr[0] = fbuff[0]; |
1271 |
vstr[1] = fbuff[1]; |
1272 |
vstr[2] = 0; |
1273 |
for(i=0;i<11;i++) temp[i] = fbuff[i]; |
1274 |
|
1275 |
for (vi = 0;vi <= verblen;vi++) |
1276 |
{ |
1277 |
vok = TRUE; |
1278 |
vstr[2] = 0; |
1279 |
for (i = 0;i < strlen(vinfl[vi]);i++) |
1280 |
{ |
1281 |
if (fbuff[2+i] != vinfl[vi][i]) |
1282 |
{ |
1283 |
vok = FALSE; |
1284 |
break; |
1285 |
} |
1286 |
} |
1287 |
if (!vok) continue; |
1288 |
strcat(vstr,vdicf[vi]); |
1289 |
|
1290 |
if(strcmp(vstr,temp) == 0) continue; |
1291 |
if (strcmp(vstr,vlast) == 0)continue; |
1292 |
if (Vlookup()) |
1293 |
{ |
1294 |
strcpy(vlast,vstr); |
1295 |
printf(" Possible inflected verb or adjective: (%s)\n",vcomms[vcommno[vi]]); |
1296 |
strcpy(KLine,vline); |
1297 |
DCol = 0; |
1298 |
KFlush(""); |
1299 |
|
1300 |
printf("Continue with this search (y/n)\n"); |
1301 |
cc = getcharxx(); |
1302 |
if ((cc == 'n')||(cc == 'N')) return; |
1303 |
if ((cc != 'y')&&(cc != 'Y')) |
1304 |
{ |
1305 |
ungetc(cc,stdin); |
1306 |
return; |
1307 |
} |
1308 |
DRow = 1; |
1309 |
} |
1310 |
} |
1311 |
} |
1312 |
/* do a binary search through the index table looking for a match */ |
1313 |
KLine[0] = 0; |
1314 |
DCol = 0; |
1315 |
nok = 0; |
1316 |
DispHit = FALSE; |
1317 |
khi = 0; |
1318 |
klo = 0; |
1319 |
DicNum = CurrDic; |
1320 |
if(Dmode !=0) DicNum = 0; |
1321 |
if (fbuff[strlen(fbuff)-1] < 32) fbuff[strlen(fbuff)-1] = 0; |
1322 |
for (slenx = 1; slenx < 20; slenx++) |
1323 |
{ |
1324 |
if (slencal(slenx-1,fbuff) >= strlen(fbuff)) break; |
1325 |
} |
1326 |
Smode = 0; |
1327 |
if ((fbuff[0] == 0xa4)||(fbuff[0] == 0xa5)) |
1328 |
{ |
1329 |
Smode = 1; |
1330 |
for (i = 0; i < strlen(fbuff); i+=2) |
1331 |
{ |
1332 |
if (fbuff[i] > 0xa5) |
1333 |
{ |
1334 |
Smode = 0; |
1335 |
break; |
1336 |
} |
1337 |
} |
1338 |
} |
1339 |
srchlenok = 0; |
1340 |
for ( slen = 0; slen <slenx; slen++) |
1341 |
{ |
1342 |
srchlen = slencal(slen,fbuff); |
1343 |
xjdserver (XJ_FIND, DicNum, zz, srchlen, fbuff, |
1344 |
&xjresp, &respos, &roff, &rlen, repstr, &DicLoc); |
1345 |
/* printf("F: Returning: %d %ld %d %d %s\n",xjresp,respos,roff,rlen,repstr); */ |
1346 |
if (xjresp == XJ_OK) |
1347 |
{ |
1348 |
bshit[slen] = respos; |
1349 |
srchlenok = srchlen; |
1350 |
continue; |
1351 |
} |
1352 |
else |
1353 |
{ |
1354 |
break; |
1355 |
} |
1356 |
} |
1357 |
if (slen == 0) |
1358 |
{ |
1359 |
if (!GDmode) printf("No Match Found\n"); |
1360 |
return; |
1361 |
} |
1362 |
if (EMmode == 0) |
1363 |
{ |
1364 |
if (srchlenok != strlen(fbuff)) |
1365 |
{ |
1366 |
printf("No Match Found (Exact Test)\n"); |
1367 |
return; |
1368 |
} |
1369 |
if (((fbuff[0] <127) && isalnum(repstr[roff+srchlenok])) |
1370 |
||((fbuff[0] >=0xa4) && (repstr[roff+srchlenok] > 127))) |
1371 |
{ |
1372 |
printf("No Match Found (Exact Test)\n"); |
1373 |
return; |
1374 |
} |
1375 |
} |
1376 |
hitind = 0; |
1377 |
hittab[0] = -1; |
1378 |
gdiclen = slen*2; |
1379 |
/* loop for each possible string length */ |
1380 |
for (dind = slen-1; dind >= 0 ; dind--) |
1381 |
{ |
1382 |
/* this is the display loop - usually one line per entry */ |
1383 |
it = bshit[dind]; |
1384 |
while (TRUE) /* display as long as there are matches*/ |
1385 |
{ |
1386 |
srchlen = slencal(dind,fbuff); |
1387 |
xjdserver (XJ_ENTRY, DicNum, it, srchlen, |
1388 |
fbuff, &xjresp, &respos, &roff, &rlen, repstr, &DicLoc); |
1389 |
/* printf("E: Returning: %d %ld %d %d %ld %s\n",xjresp,respos,roff,rlen,DicLoc,repstr); */ |
1390 |
if (xjresp != XJ_OK) break; |
1391 |
schix = 0; |
1392 |
schiy = roff; |
1393 |
/* make copy of line for filter testing */ |
1394 |
slk=0; |
1395 |
for(schiz=0;repstr[schiz]>=0x20;schiz++) |
1396 |
{ |
1397 |
testline[schiz] = repstr[schiz]; |
1398 |
if(testline[schiz]=='/')slk++; |
1399 |
} |
1400 |
testline[schiz] = '\0'; |
1401 |
kanj1 = testline[0]; |
1402 |
kanj2 = testline[1]; |
1403 |
FiltOK = TRUE; |
1404 |
/* now if filters are active, check the line for a match */ |
1405 |
if((Dmode == 0)&& nofilts && (!GDmode)) |
1406 |
{ |
1407 |
if(nofilts>0) |
1408 |
{ |
1409 |
for (i=0;i<NOFILT;i++) |
1410 |
{ |
1411 |
if(!filtact[i]||!filton[i])continue; |
1412 |
if(filttype[i] == 0) |
1413 |
{ |
1414 |
FiltOK = FALSE; |
1415 |
for(j=0;j<filtcoden[i];j++) |
1416 |
{ |
1417 |
if(strstr(testline,filtcodes[i][j]) != NULL) |
1418 |
{ |
1419 |
FiltOK = TRUE; |
1420 |
break; |
1421 |
} |
1422 |
} |
1423 |
if(FiltOK)break; |
1424 |
} |
1425 |
if((filttype[i] == 1)||((filttype[i] == 2)&&(slk <= 2))) |
1426 |
{ |
1427 |
FiltOK = TRUE; |
1428 |
for(j=0;j<filtcoden[i];j++) |
1429 |
{ |
1430 |
if(strstr(testline,filtcodes[i][j]) != NULL) |
1431 |
{ |
1432 |
FiltOK = FALSE; |
1433 |
break; |
1434 |
} |
1435 |
} |
1436 |
if(!FiltOK) break; |
1437 |
} |
1438 |
} |
1439 |
} |
1440 |
} |
1441 |
if(strf && (Dmode ==1)) |
1442 |
{ |
1443 |
FiltOK = FALSE; |
1444 |
if (strstr(testline,strfilt) != NULL) FiltOK = TRUE; |
1445 |
} |
1446 |
if ((Dmode == 0) && SFFlag && FiltOK) |
1447 |
{ |
1448 |
FiltOK = FALSE; |
1449 |
kptr = strstr(testline,SingleFilter); |
1450 |
if ((kptr != NULL) && (SingleFilter[0] < 128)) |
1451 |
{ |
1452 |
FiltOK = TRUE; |
1453 |
} |
1454 |
else |
1455 |
{ |
1456 |
while (TRUE) |
1457 |
{ |
1458 |
if (kptr == NULL) break; |
1459 |
if ((strlen(testline) - strlen(kptr)) % 2 == 0) |
1460 |
{ |
1461 |
FiltOK = TRUE; |
1462 |
break; |
1463 |
} |
1464 |
else |
1465 |
{ |
1466 |
kptr2 = kptr; |
1467 |
kptr = strstr(kptr2+1,SingleFilter); |
1468 |
} |
1469 |
} |
1470 |
} |
1471 |
} |
1472 |
if ((EMmode == 0) && (((fbuff[0] <127) && isalnum(repstr[roff+srchlenok])) |
1473 |
||((fbuff[0] >=0xa4) && (repstr[roff+srchlenok] > 127)))) |
1474 |
{ |
1475 |
FiltOK = FALSE; |
1476 |
} |
1477 |
KFlushRes = TRUE; |
1478 |
/* now work forwards, displaying the line */ |
1479 |
KTest = TRUE; |
1480 |
if (((fbuff[0] > 0xa5) || (fbuff[0] == 0x8f)) && (roff != 0)) KTest = FALSE; |
1481 |
if ((Dmode == 0) && GDmode) KTest = TRUE; |
1482 |
if (roff != 0) gdiclen--; |
1483 |
if (FiltOK && addhit(DicLoc) && (!FirstKanj || (FirstKanj && KTest))) |
1484 |
{ |
1485 |
DispHit = TRUE; |
1486 |
if ((Dmode == 0) &&(ROmode == 0)) |
1487 |
{ |
1488 |
/* We are in "raw output mode, so just splat out the EDICT line. |
1489 |
Note that this block does its own "end-of display" processing */ |
1490 |
for(schiz=0;repstr[schiz]>=0x20;schiz++) |
1491 |
{ |
1492 |
KLine[schiz] = repstr[schiz]; |
1493 |
} |
1494 |
KLine[schiz] = '\0'; |
1495 |
KFlushRes = KFlush("Continue displaying matches? (y/n)"); |
1496 |
it++; |
1497 |
if (!KFlushRes) return; |
1498 |
continue; |
1499 |
} |
1500 |
engrv = FALSE; |
1501 |
EngFirst = TRUE; |
1502 |
if((Dmode == 0) || ((Dmode ==1)&&(KLRmode == 0))) KLine[0] = 0; |
1503 |
if (Dmode == 0) |
1504 |
{ |
1505 |
if (fbuff[0] == SPTAG) |
1506 |
{ |
1507 |
sprintf(ops,"%d: ",dind); |
1508 |
strcpy(KLine,ops); |
1509 |
} |
1510 |
else |
1511 |
{ |
1512 |
sprintf(ops,"%d: ",dind+1); |
1513 |
strcpy(KLine,ops); |
1514 |
} |
1515 |
DCol = 0; |
1516 |
} |
1517 |
strcat(KLine," "); |
1518 |
if (Dmode == 1) |
1519 |
{ |
1520 |
KDNSflag = TRUE; |
1521 |
prevch = 0; |
1522 |
ops[0] = 0xa1; ops[1] = 0xda; |
1523 |
kanj1 = repstr[0]; |
1524 |
kanj2 = repstr[1]; |
1525 |
kanj3 = repstr[2]; |
1526 |
ops[2] = repstr[0]; |
1527 |
ops[3] = repstr[1]; |
1528 |
ops[4] = repstr[2]; |
1529 |
ops[5] = 0; |
1530 |
if (ops[2] != 0x8f) ops[4] = 0; |
1531 |
instr[0] = 0xa1; instr[1] = 0xdb; instr[2] = 0; |
1532 |
strcat (ops,instr); |
1533 |
if (KLRmode == 0) |
1534 |
{ |
1535 |
if (ops[2] == 0x8f) |
1536 |
{ |
1537 |
sprintf (instr,"%s 1-%x%x [1-%d]",ops,kanj2&0x7f,kanj3&0x7f,((kanj2&0x7f)-0x20)*100+(kanj3&0x7f)-0x20); |
1538 |
schix+=8; |
1539 |
|
1540 |
} |
1541 |
else |
1542 |
{ |
1543 |
k1 = kanj1 & 0x7f; |
1544 |
k2 = kanj2 & 0x7f; |
1545 |
jis2sjis(&k1,&k2); |
1546 |
sprintf (instr,"%s %x%x [%d:%x%x]",ops,kanj1&0x7f,kanj2&0x7f,((kanj1&0x7f)-0x20)*100+(kanj2&0x7f)-0x20,k1,k2); |
1547 |
schix+=7; |
1548 |
} |
1549 |
strcat(KLine,instr); |
1550 |
} |
1551 |
else |
1552 |
{ |
1553 |
KLine[0] = 0; |
1554 |
karray[nok][2] = kanj1; |
1555 |
karray[nok][3] = kanj2; |
1556 |
karray[nok][4] = kanj3; |
1557 |
kptr = strstr(testline,"S"); |
1558 |
if (kptr == NULL) |
1559 |
{ |
1560 |
karray[nok][0] = 0; |
1561 |
} |
1562 |
else |
1563 |
{ |
1564 |
karray[nok][0] = atoi(kptr+1); |
1565 |
} |
1566 |
kptr = strstr(testline,"B"); |
1567 |
if (kptr == NULL) |
1568 |
{ |
1569 |
karray[nok][1] = 0; |
1570 |
} |
1571 |
else |
1572 |
{ |
1573 |
karray[nok][1] = atoi(kptr+1); |
1574 |
} |
1575 |
KLcount++; |
1576 |
if (nok < KANJARRAYSIZE) nok++; |
1577 |
continue; |
1578 |
} |
1579 |
} |
1580 |
KDskip = FALSE; |
1581 |
while ((cc = repstr[schix]) != 0x0a) |
1582 |
{ |
1583 |
if (cc == 0x0d) break; |
1584 |
if (RVACTIVE && (schix == roff)) strcat (KLine,RVon); |
1585 |
if (RVACTIVE && (schix == roff+srchlen)) strcat (KLine,RVoff); |
1586 |
if ((Dmode == 0) && (cc == '[')) |
1587 |
{ |
1588 |
ops[0] = 0xa1; ops[1] = 0xca; ops[2] = 0; /* JIS ( */ |
1589 |
strcat(KLine,ops); |
1590 |
schix++; |
1591 |
continue; |
1592 |
} |
1593 |
if ((Dmode == 0) && (cc == ']')) |
1594 |
{ |
1595 |
ops[0] = 0xa1; ops[1] = 0xcb; ops[2] = 0; /* JIS ( */ |
1596 |
strcat(KLine,ops); |
1597 |
schix++; |
1598 |
continue; |
1599 |
} |
1600 |
if (KDskip) |
1601 |
{ |
1602 |
if (cc == ' ')KDskip = FALSE; |
1603 |
schix++; |
1604 |
continue; |
1605 |
} |
1606 |
if (cc < 128) /* non-Japanese, display it (fix up the EDICT "/") */ |
1607 |
{ |
1608 |
ops[0]= cc; |
1609 |
ops[1] = '\0'; |
1610 |
if (cc == SPTAG) |
1611 |
{ |
1612 |
if (prieng) |
1613 |
{ |
1614 |
strcat (KLine,RVon); |
1615 |
engrv = TRUE; |
1616 |
} |
1617 |
schix++; |
1618 |
continue; |
1619 |
} |
1620 |
if (!isalnum(cc) && engrv) |
1621 |
{ |
1622 |
engrv = FALSE; |
1623 |
strcat (KLine,RVoff); |
1624 |
} |
1625 |
if (KDNSflag && (prevch == ' ') && (Dmode != 0)) |
1626 |
{ |
1627 |
if (strstr(KDNSlist,ops) != NULL) |
1628 |
{ |
1629 |
KDskip = TRUE; |
1630 |
schix++; |
1631 |
continue; |
1632 |
} |
1633 |
} |
1634 |
prevch = cc; |
1635 |
if ((Dmode == 1) && (cc == '}')) /* { */ |
1636 |
{ |
1637 |
ops[0] = ';'; |
1638 |
if ((repstr[schix+2] == 0x0a) && (ops[0] == ';')) ops[0] = '\0'; |
1639 |
} |
1640 |
if ((Dmode == 1) && (cc == '{')) |
1641 |
{ |
1642 |
KDNSflag = FALSE; |
1643 |
schix++; |
1644 |
continue; |
1645 |
} |
1646 |
if ((Dmode == 0) && (ops[0] == '/')) |
1647 |
{ |
1648 |
if (!EngFirst) |
1649 |
{ |
1650 |
ops[0] = ';'; |
1651 |
ops[1] = ' '; |
1652 |
ops[2] = 0; |
1653 |
} |
1654 |
else |
1655 |
{ |
1656 |
EngFirst = FALSE; |
1657 |
ops[0] = 0; |
1658 |
} |
1659 |
} |
1660 |
if ((repstr[schix+1] == 0x0a) && (ops[0] == ';')) ops[0] = '\0'; |
1661 |
if ((repstr[schix+1] == 0x0d) && (ops[0] == ';')) ops[0] = '\0'; |
1662 |
strcat(KLine,ops); |
1663 |
} |
1664 |
else /* kana or kanji */ |
1665 |
{ |
1666 |
if (cc == 0x8f) |
1667 |
{ |
1668 |
KOutc(0x8f); |
1669 |
schix++; |
1670 |
continue; |
1671 |
} |
1672 |
if (khi == 0) |
1673 |
{ |
1674 |
khi = cc; |
1675 |
} |
1676 |
else |
1677 |
{ |
1678 |
klo = cc; |
1679 |
KOutc(khi); |
1680 |
KOutc(klo); |
1681 |
khi = 0; |
1682 |
} |
1683 |
} |
1684 |
schix++; |
1685 |
} /* end of line display loop */ |
1686 |
if (GDmode && (Dmode == 0)) return; /* early return from global*/ |
1687 |
if (Dmode == 0) KFlushRes = KFlush("Continue displaying matches? (y/n)"); |
1688 |
if ((Dmode == 1)&&(KLRmode == 0)) KFlushRes = KFlush("Continue displaying matches? (y/n)"); |
1689 |
} /* of "once-per-line" test */ |
1690 |
it++; |
1691 |
if ((Dmode == 0)||((Dmode ==1)&&(KLRmode == 0))) |
1692 |
{ |
1693 |
if (!KFlushRes) return; |
1694 |
} |
1695 |
} /* end of the "while it matches loop */ |
1696 |
if (!DispHit) printf("No display for this key (filtered or non-initial kanji)\n"); |
1697 |
if ((Dmode == 1)&&(KLRmode == 1)) |
1698 |
{ |
1699 |
if (nok >= KANJARRAYSIZE) printf("\nWarning! Kanji table overflow!\n"); |
1700 |
if (nok == 0) return; |
1701 |
|
1702 |
/* Thanks to Bruce Raup for the casting which fixed the compilation |
1703 |
* warning in the following qsort() call |
1704 |
*/ |
1705 |
qsort(&karray,nok,sizeof(karray[0]),(int (*) (const void *, const void *)) kcmp); |
1706 |
for (i = 0; i < nok; i++) |
1707 |
{ |
1708 |
if ((i != 0) && (karray[i][2] == karray[i-1][2]) && (karray[i][3] == karray[i-1][3]) && (karray[i][4] == karray[i-1][4])) continue; |
1709 |
KOutc(karray[i][2]); |
1710 |
KOutc(karray[i][3]); |
1711 |
if (karray[i][2] == 0x8f) KOutc(karray[i][4]); |
1712 |
KOutc(' '); |
1713 |
} |
1714 |
KFlushRes = KFlush("Continue displaying kanji (y/n)"); |
1715 |
} |
1716 |
if ((Dmode != 0) || (dind == 0)) return; |
1717 |
if (EMmode == 0) return; |
1718 |
printf("End of %d character matches. Continue for shorter matches? (y/n)\n\r",dind+1); |
1719 |
ops[0] = getcharxx(); |
1720 |
DRow = 1; |
1721 |
fflush(stdin); |
1722 |
if ((ops[0] == 'y')||(ops[0] == 'Y')) continue; |
1723 |
if ((ops[0] != 'n')&&(ops[0] != 'N')) |
1724 |
{ |
1725 |
if ((ops[0] != 0x0a) && (ops[0] != 0x0d)) ungetc(ops[0],stdin); |
1726 |
} |
1727 |
break; |
1728 |
} /* end of the dind loop */ |
1729 |
} /* end of lookup */ |
1730 |
|
1731 |
/*======RadSet=== set up Radicals for bushu search=================*/ |
1732 |
void RadSet() |
1733 |
{ |
1734 |
int i,errf; |
1735 |
unsigned char rstr[20]; |
1736 |
FILE *fpr, *fopen(); |
1737 |
|
1738 |
fpr = xfopen(Rname,"r", &xfilelen); |
1739 |
i = 0; |
1740 |
while(TRUE) |
1741 |
{ |
1742 |
errf = (fgets(rstr,19,fpr) == NULL); |
1743 |
if (feof(fpr)||errf) break; |
1744 |
while(rstr[strlen(rstr)-1] < 0x20) rstr[strlen(rstr)-1] = 0; |
1745 |
if (rstr[3] == '0') continue; |
1746 |
radkanj[i][0] = rstr[0]; |
1747 |
radkanj[i][1] = rstr[1]; |
1748 |
if (rstr[3] == '(') |
1749 |
{ |
1750 |
radnos[i] = atoi(rstr+4); |
1751 |
} |
1752 |
else |
1753 |
{ |
1754 |
radnos[i] = atoi(rstr+3); |
1755 |
} |
1756 |
i++; |
1757 |
} |
1758 |
fclose(fpr); |
1759 |
return; |
1760 |
} |
1761 |
/*=====DispLic======display GPL ==============================*/ |
1762 |
void DispLic() |
1763 |
{ |
1764 |
FILE *flic,*fopen(); |
1765 |
|
1766 |
flic = xfopen(GPL_File,"r", &xfilelen); |
1767 |
DRow = 1; |
1768 |
DCol = 0; |
1769 |
while (!feof(flic)) |
1770 |
{ |
1771 |
fgets(KLine,81,flic); |
1772 |
if (feof(flic)) |
1773 |
{ |
1774 |
KFlush(""); |
1775 |
return; |
1776 |
} |
1777 |
KLine[strlen(KLine)-1] = 0; |
1778 |
if(!KFlush("Continue Licence Display? (y/n)")) return; |
1779 |
} |
1780 |
} |
1781 |
/*=====DoRADICALS===display Theresa's Radical File================*/ |
1782 |
|
1783 |
void DoRADICALS() |
1784 |
{ |
1785 |
|
1786 |
int errf,j; |
1787 |
unsigned char rstr[20]; |
1788 |
FILE *fpr, *fopen(); |
1789 |
|
1790 |
fpr = xfopen(Rname,"r", &xfilelen); |
1791 |
printf("\n RADICAL DISPLAY \n"); |
1792 |
DRow = 3; |
1793 |
DCol = 0; |
1794 |
KLine[0] = 0; |
1795 |
fseek(stdin,0L,SEEK_END); /*kill any leftovers*/ |
1796 |
j = 0; |
1797 |
while(TRUE) |
1798 |
{ |
1799 |
errf = (fgets(rstr,19,fpr) == NULL); |
1800 |
if (feof(fpr)||errf) |
1801 |
{ |
1802 |
KFlush(""); |
1803 |
fseek(stdin,0L,SEEK_END); /*kill any leftovers*/ |
1804 |
return; |
1805 |
} |
1806 |
while(rstr[strlen(rstr)-1] < 0x20) rstr[strlen(rstr)-1] = 0; |
1807 |
if ((rstr[strlen(rstr)-2] == ' ')&&(rstr[strlen(rstr)-1] == '0')) |
1808 |
{ |
1809 |
KFlushRes = KFlush("Continue displaying radicals? (y/n)"); |
1810 |
if (!KFlushRes) return; |
1811 |
strcpy(KLine," "); |
1812 |
KFlushRes = KFlush("Continue displaying radicals? (y/n)"); |
1813 |
if (!KFlushRes) return; |
1814 |
rstr[2] = 0; |
1815 |
sprintf(tempout,"%s Stroke Radicals ",rstr); |
1816 |
strcpy(KLine,tempout); |
1817 |
KFlushRes = KFlush("Continue displaying radicals? (y/n)"); |
1818 |
if (!KFlushRes) return; |
1819 |
strcpy(KLine," "); |
1820 |
KFlushRes = KFlush("Continue displaying radicals? (y/n)"); |
1821 |
if (!KFlushRes) return; |
1822 |
continue; |
1823 |
} |
1824 |
strcat(KLine,"\t"); |
1825 |
KOutc(rstr[0]); |
1826 |
KOutc(rstr[1]); |
1827 |
KOutc(0xa1); |
1828 |
KOutc(0xa1); |
1829 |
sprintf(tempout,"%s ",rstr+3); |
1830 |
strcat(KLine,tempout); |
1831 |
} |
1832 |
KFlush(""); |
1833 |
} |
1834 |
|
1835 |
/*=========KLookup=== Special front-end to Lookup for Kanji searches==========*/ |
1836 |
void KLookup() |
1837 |
{ |
1838 |
if (KLmode == 0) /* Long display mode, just pass on call */ |
1839 |
{ |
1840 |
KLRmode = 0; |
1841 |
Lookup(); |
1842 |
return; |
1843 |
} /* Short display mode - see how many there */ |
1844 |
KLRmode = 1; |
1845 |
Lookup(); |
1846 |
if (KLcount == 1) /* only one - force long display */ |
1847 |
{ |
1848 |
KLRmode = 0; |
1849 |
Lookup(); |
1850 |
} |
1851 |
return; |
1852 |
} |
1853 |
|
1854 |
/*=========DoJIS === JIS kanji lookup==========================================*/ |
1855 |
|
1856 |
void DoJIS() |
1857 |
{ |
1858 |
int i,ktf,sjf,hojof,i1,i2; |
1859 |
unsigned char cj; |
1860 |
|
1861 |
ktf = FALSE; |
1862 |
sjf = FALSE; |
1863 |
hojof = FALSE; |
1864 |
cbreakoff(); |
1865 |
scanf("%s",instr); |
1866 |
cbreakon(); |
1867 |
fflush(stdin); |
1868 |
cj = instr[0]; |
1869 |
if ((cj == '-') || (cj == 'k') || (cj == 'K')) |
1870 |
{ |
1871 |
ktf = TRUE; |
1872 |
strcpy(instr,instr+1); |
1873 |
} |
1874 |
else if ((cj == 's')||(cj == 'S')) |
1875 |
{ |
1876 |
sjf = TRUE; |
1877 |
strcpy(instr,instr+1); |
1878 |
} |
1879 |
cj = instr[0]; |
1880 |
if ((cj == 'h') || (cj == 'H')) |
1881 |
{ |
1882 |
hojof = TRUE; |
1883 |
strcpy(instr,instr+1); |
1884 |
} |
1885 |
if (ktf) |
1886 |
{ |
1887 |
for (i = 0;i <4; i++) |
1888 |
{ |
1889 |
if ((instr[i] >= '0') && (instr[i] <= '9'))instr[i] = instr[i] - '0'; |
1890 |
} |
1891 |
instr[0] = (instr[0]*10+instr[1]+0x20) | 0x80; |
1892 |
instr[1] = (instr[2]*10+instr[3]+0x20) | 0x80; |
1893 |
instr[2] = 0; |
1894 |
} |
1895 |
else |
1896 |
{ |
1897 |
for (i = 0;i <4; i++) |
1898 |
{ |
1899 |
if ((instr[i] >= '0') && (instr[i] <= '9'))instr[i] = instr[i] - '0'; |
1900 |
if ((instr[i] >= 'a') && (instr[i] <= 'f'))instr[i] = instr[i]-'a'+0x0a; |
1901 |
if ((instr[i] >= 'A') && (instr[i] <= 'F'))instr[i] = instr[i]-'A'+0x0a; |
1902 |
} |
1903 |
if(sjf) |
1904 |
{ |
1905 |
i1 = (instr[0] << 4) + instr[1]; |
1906 |
i2 = (instr[2] << 4) + instr[3]; |
1907 |
sjis2jis(&i1,&i2); |
1908 |
instr[0] = i1 | 0x80; |
1909 |
instr[1] = i2 | 0x80; |
1910 |
instr[2] = 0; |
1911 |
} |
1912 |
else |
1913 |
{ |
1914 |
instr[0] = ((instr[0] << 4) + instr[1]) | 0x80; |
1915 |
instr[1] = ((instr[2] << 4) + instr[3]) | 0x80; |
1916 |
instr[2] = 0; |
1917 |
} |
1918 |
} |
1919 |
Dmode =1; |
1920 |
fbuff[0] = 0; fbuff[1] = 0; |
1921 |
if (hojof) fbuff[0] = 0x8f; |
1922 |
strcat(fbuff,instr); |
1923 |
fseek(stdin,0L,SEEK_END); /*kill any leftovers*/ |
1924 |
KLookup(); |
1925 |
instr[0] = 0; |
1926 |
} |
1927 |
|
1928 |
/*===== GetKBStr=== Collect ASCII or JIS string from keyboard=========*/ |
1929 |
|
1930 |
void GetKBStr(unsigned char *prompt) |
1931 |
{ |
1932 |
int ShowIt,escf,bit8,i; |
1933 |
unsigned char c; |
1934 |
|
1935 |
escf = FALSE; |
1936 |
bit8 = FALSE; |
1937 |
c='x'; /*keep lint happy*/ |
1938 |
ShowIt = FALSE; |
1939 |
|
1940 |
for (i = 0; (c != 0xd) && (c != 0xa); i++) |
1941 |
{ |
1942 |
instr[i+1] = 0; |
1943 |
c = getcharxx(); |
1944 |
if (!bit8 && !escf && ((c == '@') || (c == '#'))) |
1945 |
{ |
1946 |
DoRomaji(c); |
1947 |
break; |
1948 |
} |
1949 |
if (c == 0x1b) escf = TRUE; |
1950 |
if (c > 0x7f) bit8 = TRUE; |
1951 |
if ((c == 0x7f) || (c == 8)) |
1952 |
{ |
1953 |
if(bit8) i--; |
1954 |
if( i > 0) instr[--i] = 0; |
1955 |
i--; |
1956 |
strcpy(fbuff,instr); |
1957 |
if (!NoSJIS) FixSJIS(fbuff); |
1958 |
printf("\r \r"); |
1959 |
printf("%s%s%s ",RVon,prompt,RVoff); |
1960 |
KOut(fbuff); |
1961 |
continue; |
1962 |
} |
1963 |
instr[i] = c; |
1964 |
if (!escf) |
1965 |
{ |
1966 |
if (!bit8) |
1967 |
{ |
1968 |
printf("\r \r"); |
1969 |
printf("%s%s%s %s",RVon,prompt,RVoff,instr); |
1970 |
} |
1971 |
else |
1972 |
{ |
1973 |
strcpy(fbuff,instr); |
1974 |
if ((strlen(fbuff) % 2) > 0) fbuff[strlen(fbuff)-1] = 0; |
1975 |
printf("\r \r"); |
1976 |
printf("%s%s%s ",RVon,prompt,RVoff); |
1977 |
if (!NoSJIS) FixSJIS(fbuff); |
1978 |
KOut(fbuff); |
1979 |
} |
1980 |
} |
1981 |
if ((instr[i] == 'B')&&(instr[i-1] == '(')&&(instr[i-2] == 0x1b)) |
1982 |
{ |
1983 |
ShowIt = TRUE; |
1984 |
break; |
1985 |
} |
1986 |
} |
1987 |
fseek(stdin,0L,SEEK_END); /*kill any leftovers*/ |
1988 |
fflush(stdin); |
1989 |
GetEUC(fbuff); |
1990 |
if ( fbuff[strlen(fbuff)-1] < 0x20) fbuff[strlen(fbuff)-1] = 0; |
1991 |
if (ShowIt) |
1992 |
{ |
1993 |
printf("\r \r"); |
1994 |
printf("%s%s%s ",RVon,prompt,RVoff); |
1995 |
KOut(fbuff); |
1996 |
} |
1997 |
printf("\n\r"); |
1998 |
} |
1999 |
|
2000 |
/*===== OneShot === Collect and set single filter=============*/ |
2001 |
|
2002 |
void OneShot() |
2003 |
{ |
2004 |
printf("\nFilter inactivated. Enter new filter, or press return\n\n"); |
2005 |
printf("%sFILTER:%s ",RVon,RVoff); |
2006 |
SFFlag = FALSE; |
2007 |
|
2008 |
GetKBStr("FILTER:"); |
2009 |
strcpy(SingleFilter,fbuff); |
2010 |
if (strlen(fbuff) >= 2) |
2011 |
{ |
2012 |
SFFlag = TRUE; |
2013 |
printf("Filter set to: "); |
2014 |
KOut(fbuff); |
2015 |
printf("\n"); |
2016 |
} |
2017 |
else |
2018 |
{ |
2019 |
printf("No filter set\n"); |
2020 |
} |
2021 |
} |
2022 |
|
2023 |
/*====FindRad=== finds the spot in the table for a radical==========*/ |
2024 |
int FindRad(unsigned char char1, unsigned char char2) |
2025 |
{ |
2026 |
int i,j,k,Found; |
2027 |
|
2028 |
Found = FALSE; |
2029 |
for (i = 0; i <= NoRads; i++) |
2030 |
{ |
2031 |
if ((char1 == RadK1[i]) && (char2 == RadK2[i])) |
2032 |
{ |
2033 |
Found = TRUE; |
2034 |
break; |
2035 |
} |
2036 |
} |
2037 |
if (!Found) return(-1); |
2038 |
return(i); |
2039 |
} |
2040 |
/*===RadBuild==Extracts the kanji that meet the multi-radical selection===*/ |
2041 |
void RadBuild() |
2042 |
{ |
2043 |
/* RKTarg will contain the string of target "radicals" |
2044 |
The RKSet tables are progressively loaded with the kanji that |
2045 |
meet the radical criteria */ |
2046 |
|
2047 |
int stest,jtest,i,j,k,l,m,n,lind,hitcount; |
2048 |
|
2049 |
/* the first radical has all its kanji loaded (which meet any stroke count test) */ |
2050 |
i = FindRad((unsigned char)RKTarg[0],(unsigned char)RKTarg[1]); |
2051 |
if (i < 0) |
2052 |
{ |
2053 |
printf("Invalid Radical!\n"); |
2054 |
RKTarg[0] = 0; |
2055 |
return; |
2056 |
} |
2057 |
k = 0; |
2058 |
hitcount = 0; |
2059 |
for (j = RKStart[i]; j < RKStart[i]+RKCnt[i]; j++) |
2060 |
{ |
2061 |
if (kstrokelim > 0) |
2062 |
{ |
2063 |
n = ((RKanj1[j] & 0x7f)-0x30)*94 + ((RKanj2[j] & 0x7f) - 0x21); |
2064 |
if ((kstroketype == 0) && (kstrokelim != kstrokes[n])) continue; |
2065 |
if ((kstroketype == 1) && (kstrokelim > kstrokes[n])) continue; |
2066 |
if ((kstroketype == 2) && (kstrokelim < kstrokes[n])) continue; |
2067 |
} |
2068 |
RKSet[0][k] = RKanj1[j]; |
2069 |
RKSet[0][k+1] = RKanj2[j]; |
2070 |
RKSet[0][k+2] = 0; |
2071 |
hitcount++; |
2072 |
k+=2; |
2073 |
} |
2074 |
ops[0] = RKTarg[0]; ops[1] = RKTarg[1]; ops[2] = 0; |
2075 |
printf("Target Radicals: 0 "); |
2076 |
KOut(ops); |
2077 |
printf(" (%d) ",hitcount); |
2078 |
NoSets = 1; |
2079 |
if (strlen(RKTarg) <= 2) |
2080 |
{ |
2081 |
printf("\n"); |
2082 |
return; |
2083 |
} |
2084 |
/* The second and subsequent radicals only have their matching kanji loaded |
2085 |
if they are a member of the previous set */ |
2086 |
|
2087 |
for (l=2; l< strlen(RKTarg); l+=2) |
2088 |
{ |
2089 |
lind = (l/2)-1; |
2090 |
i = FindRad((unsigned char)RKTarg[l],(unsigned char)RKTarg[l+1]); |
2091 |
ops[0] = RKTarg[l]; ops[1] = RKTarg[l+1]; ops[2] = 0; |
2092 |
printf(" %d ",NoSets); |
2093 |
KOut(ops); |
2094 |
if (i < 0) |
2095 |
{ |
2096 |
printf("\nInvalid Radical!\n"); |
2097 |
RKTarg[l] = 0; |
2098 |
return; |
2099 |
} |
2100 |
k = 0; |
2101 |
RKSet[lind+1][k] = 0; |
2102 |
jtest = RKStart[i]+RKCnt[i]; |
2103 |
for (j = RKStart[i]; j < jtest; j++) |
2104 |
{ |
2105 |
for (n = 0; RKSet[lind][n] != 0; n+=2) |
2106 |
{ |
2107 |
if ((RKSet[lind][n] == RKanj1[j]) && (RKSet[lind][n+1] == RKanj2[j])) |
2108 |
{ |
2109 |
RKSet[lind+1][k] = RKanj1[j]; |
2110 |
RKSet[lind+1][k+1] = RKanj2[j]; |
2111 |
RKSet[lind+1][k+2] = 0; |
2112 |
k+=2; |
2113 |
break; |
2114 |
} |
2115 |
} |
2116 |
} |
2117 |
NoSets++; |
2118 |
printf(" (%d) ",strlen(RKSet[NoSets-1])/2); |
2119 |
} |
2120 |
printf("\n"); |
2121 |
} |
2122 |
|
2123 |
/*=====RadDisp===Display Radical Data==============================*/ |
2124 |
void RadDisp() |
2125 |
{ |
2126 |
FILE *fk,*fopen(); |
2127 |
int j,k,l,n; |
2128 |
unsigned char *ptr; |
2129 |
|
2130 |
fk = xfopen(RKname,"r", &xfilelen); |
2131 |
j = 0; |
2132 |
printf("RADICAL TABLE FOR USE WITH THE XJDIC RADICAL LOOKUP FUNCTION\n"); |
2133 |
DRow = 0; |
2134 |
DCol = 0; |
2135 |
k = 99; |
2136 |
KLine[0] = 0; |
2137 |
while(!feof(fk)) |
2138 |
{ |
2139 |
fgets(testline,199,fk); |
2140 |
if(feof(fk)) break; |
2141 |
if (testline[0] != '$') continue; |
2142 |
ptr = strtok(testline+4," "); |
2143 |
l = atoi(ptr); |
2144 |
if (l != k) |
2145 |
{ |
2146 |
k = l; |
2147 |
for (n = 0; n < strlen(ptr); n++) |
2148 |
{ |
2149 |
if (ptr[n] < 32) break; |
2150 |
KOutc(0xa3); KOutc(ptr[n] | 0x80); |
2151 |
} |
2152 |
KOutc(' '); |
2153 |
} |
2154 |
KOutc(testline[2]); KOutc(testline[3]); KOutc(' '); |
2155 |
} |
2156 |
fclose(fk); |
2157 |
KFlush(""); |
2158 |
} |
2159 |
/*===KanjRad=== Display which "radicals" are used to imdex this kanji=====*/ |
2160 |
void KanjRad() |
2161 |
{ |
2162 |
int i,j; |
2163 |
|
2164 |
printf("%sWhich Kanji:%s",RVon,RVoff); |
2165 |
GetKBStr("Which Kanji:"); |
2166 |
if (fbuff[0] < 127) return; |
2167 |
strcpy(KLine,"Kanji: "); |
2168 |
KOutc(fbuff[0]); |
2169 |
KOutc(fbuff[1]); |
2170 |
strcat(KLine," Elements: "); |
2171 |
DRow = 0; |
2172 |
DCol = 0; |
2173 |
for (i = 0; i <= NoRads; i++) |
2174 |
{ |
2175 |
for (j = RKStart[i]; j < RKStart[i]+RKCnt[i]; j++) |
2176 |
{ |
2177 |
if ((fbuff[0] == RKanj1[j]) && (fbuff[1] == RKanj2[j])) |
2178 |
{ |
2179 |
KOutc(RadK1[i]); |
2180 |
KOutc(RadK2[i]); |
2181 |
KOutc(' '); |
2182 |
} |
2183 |
} |
2184 |
} |
2185 |
KFlush(""); |
2186 |
} |
2187 |
/*====RadKDisp=====display selected kanji============================*/ |
2188 |
void RadKDisp() |
2189 |
{ |
2190 |
int i; |
2191 |
|
2192 |
if (RKTarg[0] == 0) return; |
2193 |
if (NoSets == 0) return; |
2194 |
printf("Selected Kanji: "); |
2195 |
for (i = 0; i < strlen(RKSet[NoSets-1]); i+=2) |
2196 |
{ |
2197 |
ops[0] = RKSet[NoSets-1][i]; ops[1] = RKSet[NoSets-1][i+1]; ops[2] = 0; |
2198 |
KOut(ops); |
2199 |
printf(" "); |
2200 |
} |
2201 |
printf("\n"); |
2202 |
} |
2203 |
/*====DoLOOKUP=====driver routine for the multi-radical lookup=======*/ |
2204 |
void DoLOOKUP() |
2205 |
{ |
2206 |
int i; |
2207 |
|
2208 |
printf("\nRadical Lookup Mode\n"); |
2209 |
RKTarg[0] = 0; |
2210 |
while(TRUE) |
2211 |
{ |
2212 |
printf("%sLookup Code:%s",RVon,RVoff); |
2213 |
GetKBStr("Lookup Code:"); |
2214 |
if (fbuff[0] > 127) |
2215 |
{ |
2216 |
ops[0] = fbuff[0]; ops[1] = fbuff[1]; ops[2] = 0; |
2217 |
if (strlen(RKTarg) == 20) |
2218 |
{ |
2219 |
printf("\nToo many radicals!\n"); |
2220 |
continue; |
2221 |
} |
2222 |
strcat(RKTarg,ops); |
2223 |
RadBuild(); |
2224 |
if(NoSets == 0) continue; |
2225 |
if (strlen(RKSet[NoSets-1]) == 0) continue; |
2226 |
if (strlen(RKSet[NoSets-1]) <=RADLOOKLIM) RadKDisp(); |
2227 |
continue; |
2228 |
} |
2229 |
if ((fbuff[0] | 0x20) == 'r') |
2230 |
{ |
2231 |
RadDisp(); |
2232 |
continue; |
2233 |
} |
2234 |
if ((fbuff[0] | 0x20) == 'v') |
2235 |
{ |
2236 |
KanjRad(); |
2237 |
continue; |
2238 |
} |
2239 |
if ((fbuff[0] | 0x20) == 'x') |
2240 |
{ |
2241 |
instr[0] = 0; |
2242 |
fflush(stdin); |
2243 |
return; |
2244 |
} |
2245 |
if ((fbuff[0] | 0x20) == 'c') |
2246 |
{ |
2247 |
RKTarg[0] = 0; |
2248 |
kstrokelim = 0; |
2249 |
printf("Cleared\n"); |
2250 |
continue; |
2251 |
} |
2252 |
if ((fbuff[0] | 0x20) == 's') |
2253 |
{ |
2254 |
kstroketype = 0; |
2255 |
i = 1; |
2256 |
testline[0] = 0; |
2257 |
if (fbuff[1] == '+') |
2258 |
{ |
2259 |
kstroketype = 1; |
2260 |
strcat(testline," >= "); |
2261 |
i = 2; |
2262 |
} |
2263 |
if (fbuff[1] == '-') |
2264 |
{ |
2265 |
kstroketype = 2; |
2266 |
strcat(testline," <= "); |
2267 |
i = 2; |
2268 |
} |
2269 |
kstrokelim = atoi(fbuff+i); |
2270 |
if (kstrokelim == 0) |
2271 |
{ |
2272 |
printf("Stroke-count cleared\n"); |
2273 |
} |
2274 |
else |
2275 |
{ |
2276 |
printf("Stroke-count set to %s%d\n",testline,kstrokelim); |
2277 |
} |
2278 |
if (strlen(RKTarg) > 0) RadBuild(); |
2279 |
if (NoSets <= 0) continue; |
2280 |
if (strlen(RKSet[NoSets-1]) <=RADLOOKLIM) RadKDisp(); |
2281 |
continue; |
2282 |
} |
2283 |
if ((fbuff[0] | 0x20) == 'd') |
2284 |
{ |
2285 |
i = fbuff[1]-'0'; |
2286 |
if (i >= strlen(RKTarg)/2) |
2287 |
{ |
2288 |
printf("Out of Range!\n"); |
2289 |
continue; |
2290 |
} |
2291 |
strcpy(RKTarg+i*2,RKTarg+i*2+2); |
2292 |
if(strlen(RKTarg) > 0) RadBuild(); |
2293 |
if (strlen(RKSet[NoSets-1]) <=RADLOOKLIM) RadKDisp(); |
2294 |
continue; |
2295 |
} |
2296 |
|
2297 |
if ((fbuff[0] | 0x20) == 'l') RadKDisp(); |
2298 |
} |
2299 |
} |
2300 |
|
2301 |
/*===== DoKANJI === Kanji single lookup ======================*/ |
2302 |
void DoKANJI() |
2303 |
{ |
2304 |
|
2305 |
GetKBStr("KANJI/KANA:"); |
2306 |
Dmode =1; |
2307 |
KLookup(); |
2308 |
instr[0] = 0; |
2309 |
} |
2310 |
/*===EMtoggle==alternate between match display modes===============*/ |
2311 |
void EMtoggle() |
2312 |
{ |
2313 |
EMmode = (EMmode+1) % 2; |
2314 |
printf("Exact Match Display Mode: %s\n",kmodes[EMmode]); |
2315 |
} |
2316 |
/*===togglekana==alternate between kana input modes===============*/ |
2317 |
void togglekana() |
2318 |
{ |
2319 |
KImode = (KImode+1) % 2; |
2320 |
printf("Kana Default Input Mode: %s\n",kmodes[KImode]); |
2321 |
} |
2322 |
/*===togglekanji==alternate between kanji display modes===============*/ |
2323 |
void togglekanji() |
2324 |
{ |
2325 |
KLmode = (KLmode+1) % 2; |
2326 |
printf("Long Kanji Display Mode: %s\n",kmodes[KLmode]); |
2327 |
} |
2328 |
/*===toggleraw===alternate between raw/edited output modes===============*/ |
2329 |
void toggleraw() |
2330 |
{ |
2331 |
ROmode = (ROmode+1) % 2; |
2332 |
printf("Unedited Output Mode: %s\n",kmodes[ROmode]); |
2333 |
} |
2334 |
/*===RVtoggle===alternate between reverse video modes===============*/ |
2335 |
void RVtoggle() |
2336 |
{ |
2337 |
RVACTIVE = (RVACTIVE +1) % 2; |
2338 |
printf("Reverse Video Match Display Mode: %s\n",kmodes_r[RVACTIVE ]); |
2339 |
} |
2340 |
/*===togglemode===alternate between kanji compound modes===============*/ |
2341 |
void togglemode() |
2342 |
{ |
2343 |
FirstKanj = (FirstKanj+1) % 2; |
2344 |
printf("Display All Kanji Mode: %s\n",kmodes[FirstKanj]); |
2345 |
} |
2346 |
|
2347 |
/*=====engpritoggle=====alternate between English priorities=======*/ |
2348 |
void engpritoggle() |
2349 |
{ |
2350 |
if(prieng == FALSE) |
2351 |
{ |
2352 |
prieng = TRUE; |
2353 |
printf("English search will now only select priority keys\n"); |
2354 |
return; |
2355 |
} |
2356 |
prieng = FALSE; |
2357 |
printf("English search will now select all keys\n"); |
2358 |
} |
2359 |
|
2360 |
/*=====seldic=====select dictionary file =====================*/ |
2361 |
void seldic() |
2362 |
{ |
2363 |
int i; |
2364 |
char c; |
2365 |
|
2366 |
if (NoDics == 1) |
2367 |
{ |
2368 |
printf("No alternative dictionary active!\n"); |
2369 |
return; |
2370 |
} |
2371 |
for (i = 1; i <= NoDics; i++) |
2372 |
{ |
2373 |
printf("Dictionary: %d [%s]\n",i,DicName(i)); |
2374 |
} |
2375 |
printf ("Select a dictionary file (1-%d)\n",NoDics); |
2376 |
c = getcharxx(); |
2377 |
if ((c == 0x1b)||(c == 0xa)||(c == 0xd)) return; |
2378 |
i = c-'0'; |
2379 |
if ((i <0)||(i >NoDics)) |
2380 |
{ |
2381 |
printf("INVALID!\n"); |
2382 |
return; |
2383 |
} |
2384 |
CurrDic = i; |
2385 |
printf("Active Dictionary is now #%d (%s)\n",CurrDic,DicName(CurrDic)); |
2386 |
} |
2387 |
|
2388 |
/*=====BuffStats=====report on page buffer stats=====================*/ |
2389 |
void BuffStats() |
2390 |
{ |
2391 |
int i; |
2392 |
|
2393 |
#ifdef XJDDIC |
2394 |
printf("DEMAND-PAGING STATISTICS:\n\n"); |
2395 |
printf("Dic Hits: "); |
2396 |
for (i=0;i<=NoDics;i++) printf("\t%ld ",dichits[i]); |
2397 |
printf("\n"); |
2398 |
printf("Dic Miss: "); |
2399 |
for (i=0;i<=NoDics;i++) printf("\t%ld ",dicmiss[i]); |
2400 |
printf("\n"); |
2401 |
printf("Ind Hits: "); |
2402 |
for (i=0;i<=NoDics;i++) printf("\t%ld ",indhits[i]); |
2403 |
printf("\n"); |
2404 |
printf("Ind Miss: "); |
2405 |
for (i=0;i<=NoDics;i++) printf("\t%ld ",indmiss[i]); |
2406 |
printf("\n"); |
2407 |
printf("Buffer overwrites: \t%ld\n",vbkills); |
2408 |
#else |
2409 |
printf("CLIENT! NO BUFFER STATISTICS\n"); |
2410 |
#endif |
2411 |
} |
2412 |
/*=====altdic=====rotate around dictionaries=======*/ |
2413 |
void altdic(int dicincr) |
2414 |
{ |
2415 |
if (NoDics == 1) |
2416 |
{ |
2417 |
printf("No alternative dictionary active!\n"); |
2418 |
return; |
2419 |
} |
2420 |
CurrDic = CurrDic + dicincr; |
2421 |
if (CurrDic == NoDics+1) CurrDic = 1; |
2422 |
if (CurrDic == 0) CurrDic = NoDics; |
2423 |
printf("Switching to dictionary: %d [%s]\n",CurrDic,DicName(CurrDic)); |
2424 |
} |
2425 |
/*====GDicSet====== initialize the global dictionary list===============*/ |
2426 |
void GDicSet() |
2427 |
{ |
2428 |
char gdtemp[100],*gdp; |
2429 |
|
2430 |
if (NoDics == 1) |
2431 |
{ |
2432 |
printf("No alternative dictionary active!\n"); |
2433 |
return; |
2434 |
} |
2435 |
|
2436 |
gdicmax = 0; |
2437 |
printf("\nEnter the list of dictionary numbers for the global search\n"); |
2438 |
printf("%sDictionary Numbers:%s",RVon,RVoff); |
2439 |
GetKBStr("Dictionary Numbers:"); |
2440 |
strcpy(gdtemp,fbuff); |
2441 |
gdp = strtok(gdtemp," ,\t"); |
2442 |
while(gdp!=NULL) |
2443 |
{ |
2444 |
gdicnos[gdicmax] = atoi(gdp); |
2445 |
gdp = strtok(NULL," ,\t"); |
2446 |
gdicmax++; |
2447 |
if (gdicmax > 9) |
2448 |
{ |
2449 |
printf("Too many dictionary numbers!\n"); |
2450 |
gdicmax--; |
2451 |
break; |
2452 |
} |
2453 |
if (gdicnos[gdicmax-1] > NoDics) |
2454 |
{ |
2455 |
printf("Illegal Dictionary number!\n"); |
2456 |
gdicmax--; |
2457 |
} |
2458 |
} |
2459 |
gdicmax--; |
2460 |
if (gdicmax <1) |
2461 |
{ |
2462 |
printf("Warning! Insufficient dictionaries set!\n"); |
2463 |
} |
2464 |
} |
2465 |
|
2466 |
/*====GDictoggle=== alternate between single & global dics==============*/ |
2467 |
void GDictoggle() |
2468 |
{ |
2469 |
int gi; |
2470 |
|
2471 |
if (GDmode) |
2472 |
{ |
2473 |
GDmode = FALSE; |
2474 |
printf("Global dictionary searching is now OFF\n"); |
2475 |
} |
2476 |
else |
2477 |
{ |
2478 |
if (gdicmax <1) |
2479 |
{ |
2480 |
printf("Insufficient dictionaries set!\n"); |
2481 |
return; |
2482 |
} |
2483 |
GDmode = TRUE; |
2484 |
printf("Global dictionary searching is now ON ["); |
2485 |
for (gi=0;gi<=gdicmax;gi++) |
2486 |
{ |
2487 |
printf("%d",gdicnos[gi]); |
2488 |
if (gi != gdicmax) printf(" "); |
2489 |
} |
2490 |
printf("]\n"); |
2491 |
} |
2492 |
} |
2493 |
/*====GDicALLtoggle=== alternate between single & multiple global dic disp====*/ |
2494 |
void GDicALLtoggle() |
2495 |
{ |
2496 |
if(GDALLmode) |
2497 |
{ |
2498 |
GDALLmode = FALSE; |
2499 |
printf("Multiple Global Display is now OFF\n"); |
2500 |
} |
2501 |
else |
2502 |
{ |
2503 |
GDALLmode = TRUE; |
2504 |
printf("Multiple Global Display is now ON\n"); |
2505 |
} |
2506 |
} |
2507 |
/*====Verbtoggle=== alternate between deinflection on/off===============*/ |
2508 |
void Verbtoggle() |
2509 |
{ |
2510 |
if (Jverb) |
2511 |
{ |
2512 |
Jverb = FALSE; |
2513 |
printf("Verb deinflection is now OFF\n"); |
2514 |
} |
2515 |
else |
2516 |
{ |
2517 |
Jverb = TRUE; |
2518 |
printf("Verb deinflection is now ON\n"); |
2519 |
} |
2520 |
} |
2521 |
/*=== FiltSet=== turn filters on & off==============================*/ |
2522 |
void FiltSet() |
2523 |
{ |
2524 |
unsigned char c,fff[10]; |
2525 |
int anyfilt,j,k; |
2526 |
|
2527 |
anyfilt = FALSE; |
2528 |
printf("%sFilter Setting%s\n",RVon,RVoff); |
2529 |
for(j = 0;j < NOFILT;j++) |
2530 |
{ |
2531 |
if(!filtact[j])continue; |
2532 |
anyfilt = TRUE; |
2533 |
strcpy(fff,"OFF"); |
2534 |
if(filton[j])strcpy(fff,"ON "); |
2535 |
printf("No: %d Type: %d Status: %s Name: %s\n",j,filttype[j],fff,filtnames[j]); |
2536 |
} |
2537 |
if (!anyfilt) |
2538 |
{ |
2539 |
printf("No filters are loaded!\n"); |
2540 |
return; |
2541 |
} |
2542 |
printf("Modify which Filter?\n"); |
2543 |
c = getcharxx(); |
2544 |
if ((c == 0x1b)||(c == 0xa)||(c == 0xd)) return; |
2545 |
k = c-'0'; |
2546 |
if ((k <0)||(k >NOFILT)) |
2547 |
{ |
2548 |
printf("INVALID!\n"); |
2549 |
return; |
2550 |
} |
2551 |
if (!filtact[k]) |
2552 |
{ |
2553 |
printf("Filter %c is not active!\n",c); |
2554 |
return; |
2555 |
} |
2556 |
printf("Filter %c OFF (0) or ON (1)\n",c); |
2557 |
c = getcharxx(); |
2558 |
if ((c != '0') && (c != '1'))return; |
2559 |
if(c == '0') |
2560 |
{ |
2561 |
filton[k] = FALSE; |
2562 |
printf("Filter %d Turned OFF\n",k); |
2563 |
} |
2564 |
if(c == '1') |
2565 |
{ |
2566 |
filton[k] = TRUE; |
2567 |
printf("Filter %d Turned ON\n",k); |
2568 |
} |
2569 |
nofilts = FALSE; |
2570 |
for(j = 0;j < NOFILT;j++)if(filton[j])nofilts=TRUE; |
2571 |
return; |
2572 |
} |
2573 |
|
2574 |
/* M A I N */ |
2575 |
|
2576 |
main(argc,argv) |
2577 |
int argc; |
2578 |
unsigned char **argv; |
2579 |
|
2580 |
{ |
2581 |
int i,j,ip,cmdmode,bit8,escf; |
2582 |
unsigned char *dicenv,strtmp[50]; |
2583 |
unsigned char c; |
2584 |
unsigned char xap[50]; |
2585 |
unsigned char kbprompt[99]; |
2586 |
unsigned char kbprompt2[99]; |
2587 |
|
2588 |
printf("XJDIC Version %s (Japanese Dictionary) Copyright J.W.Breen 2003.\n",sver); |
2589 |
#ifdef XJDDIC |
2590 |
printf(" Stand-alone mode\n"); |
2591 |
#else |
2592 |
printf(" Client mode\n"); |
2593 |
#endif |
2594 |
|
2595 |
for (i=0;i<NOFILT;i++) |
2596 |
{ |
2597 |
filtact[i] = FALSE; |
2598 |
filton[i] = FALSE; |
2599 |
} |
2600 |
dicenv = (unsigned char *)getenv("XJDIC"); |
2601 |
if (!dicenv) dicenv = (unsigned char *)DEFAULT_DICDIR; |
2602 |
if (strlen(dicenv) <= 2) |
2603 |
{ |
2604 |
dicenv = (unsigned char *)getcwd(ENVname,sizeof(ENVname)); |
2605 |
if (dicenv == NULL) |
2606 |
{ |
2607 |
printf("Cannot extract working directory!\n"); |
2608 |
exit(1); |
2609 |
} |
2610 |
} |
2611 |
else |
2612 |
{ |
2613 |
strcpy (ENVname,dicenv); |
2614 |
} |
2615 |
#ifdef XJDDIC |
2616 |
strcpy (Dnamet[1],"edict"); |
2617 |
strcpy (Dnamet[0], "kanjidic"); |
2618 |
strcpy (XJDXnamet[1], "edict.xjdx"); |
2619 |
strcpy (XJDXnamet[0], "kanjidic.xjdx"); |
2620 |
NoDics = 1; |
2621 |
CurrDic = 1; |
2622 |
#endif |
2623 |
cl_rcfile[0] = 0; |
2624 |
/* process command-line options*/ |
2625 |
if (argc > 1) |
2626 |
{ |
2627 |
for (i = 1; i < argc; i++) |
2628 |
{ |
2629 |
strcpy(xap,argv[i]); |
2630 |
if ((xap[0] == '-') && (xap[1] == 'c')) |
2631 |
{ |
2632 |
if(xap[2] != 0) |
2633 |
{ |
2634 |
strcpy(strtmp,xap+2); |
2635 |
} |
2636 |
else |
2637 |
{ |
2638 |
i++; |
2639 |
strcpy(xap,argv[i]); |
2640 |
strcpy (strtmp,xap); |
2641 |
} |
2642 |
strcpy (cl_rcfile,strtmp); |
2643 |
printf ("Using control-file: %s\n",cl_rcfile); |
2644 |
} |
2645 |
if ((xap[0] == '-') && (xap[1] == 'j')) |
2646 |
{ |
2647 |
if(xap[2] != 0) |
2648 |
{ |
2649 |
strcpy(strtmp,xap+2); |
2650 |
} |
2651 |
else |
2652 |
{ |
2653 |
i++; |
2654 |
strcpy(xap,argv[i]); |
2655 |
strcpy (strtmp,xap); |
2656 |
} |
2657 |
if (strtmp[0] == 'j') |
2658 |
{ |
2659 |
Omode = 0; |
2660 |
printf("Output mode set to JIS\n"); |
2661 |
} |
2662 |
if (strtmp[0] == 's') |
2663 |
{ |
2664 |
Omode = 2; |
2665 |
printf("Output mode set to Shift-JIS\n"); |
2666 |
} |
2667 |
if (strtmp[0] == 'e') |
2668 |
{ |
2669 |
Omode = 1; |
2670 |
printf("Output mode set to EUC\n"); |
2671 |
} |
2672 |
continue; |
2673 |
} |
2674 |
#ifdef XJDCLSERV |
2675 |
if ((xap[0] == '-') && (xap[1] == 'S')) |
2676 |
{ |
2677 |
if(xap[2] != 0) |
2678 |
{ |
2679 |
strcpy(host,xap+2); |
2680 |
} |
2681 |
else |
2682 |
{ |
2683 |
i++; |
2684 |
strcpy(xap,argv[i]); |
2685 |
strcpy(host,xap); |
2686 |
} |
2687 |
printf("Command-line request to use server: %s\n",host); |
2688 |
continue; |
2689 |
} |
2690 |
if ((xap[0] == '-') && (xap[1] == 'P')) |
2691 |
{ |
2692 |
if(xap[2] != 0) |
2693 |
{ |
2694 |
portno = atoi(xap+2); |
2695 |
} |
2696 |
else |
2697 |
{ |
2698 |
i++; |
2699 |
strcpy(xap,argv[i]); |
2700 |
portno = atoi(xap); |
2701 |
} |
2702 |
printf("Command-line request to use port: %d\n",portno); |
2703 |
continue; |
2704 |
} |
2705 |
#endif |
2706 |
#ifdef XJDDIC |
2707 |
if ((xap[0] == '-') && (xap[1] == 'C')) |
2708 |
{ |
2709 |
if(xap[2] != 0) |
2710 |
{ |
2711 |
strcpy(strtmp,xap+2); |
2712 |
} |
2713 |
else |
2714 |
{ |
2715 |
i++; |
2716 |
strcpy(xap,argv[i]); |
2717 |
strcpy (strtmp,xap); |
2718 |
} |
2719 |
strcpy (Clip_File,strtmp); |
2720 |
printf ("Using clipboard-file: %s\n",Clip_File); |
2721 |
} |
2722 |
if ((xap[0] == '-') && (xap[1] == 'd')) |
2723 |
{ |
2724 |
if (thisdic == 0) |
2725 |
{ |
2726 |
thisdic = 1; |
2727 |
} |
2728 |
else |
2729 |
{ |
2730 |
thisdic++; |
2731 |
NoDics++; |
2732 |
} |
2733 |
if(xap[2] != 0) |
2734 |
{ |
2735 |
strcpy(strtmp,xap+2); |
2736 |
} |
2737 |
else |
2738 |
{ |
2739 |
i++; |
2740 |
strcpy(xap,argv[i]); |
2741 |
strcpy (strtmp,xap); |
2742 |
} |
2743 |
strcpy (Dnamet[thisdic],strtmp); |
2744 |
strcpy (XJDXnamet[thisdic],strtmp); |
2745 |
strcat (XJDXnamet[thisdic],".xjdx"); |
2746 |
printf("Command-line request to use dictionary files (%d): %s and %s\n", |
2747 |
thisdic,Dnamet[thisdic],XJDXnamet[thisdic]); |
2748 |
continue; |
2749 |
} |
2750 |
if ((xap[0] == '-') && (xap[1] == 'k')) |
2751 |
{ |
2752 |
if(xap[2] != 0) |
2753 |
{ |
2754 |
strcpy(strtmp,xap+2); |
2755 |
} |
2756 |
else |
2757 |
{ |
2758 |
i++; |
2759 |
strcpy(xap,argv[i]); |
2760 |
strcpy (strtmp,xap); |
2761 |
} |
2762 |
strcpy (Dnamet[0],strtmp); |
2763 |
strcpy (XJDXnamet[0],strtmp); |
2764 |
strcat (XJDXnamet[0],".xjdx"); |
2765 |
printf("Command-line request to use kanji dictionary files: %s and %s\n",Dnamet[0],XJDXnamet[0]); |
2766 |
continue; |
2767 |
} |
2768 |
#endif |
2769 |
if ((xap[0] == '-') && (xap[1] == 'V')) |
2770 |
{ |
2771 |
RVACTIVE = FALSE; |
2772 |
printf("Reverse-video match display disabled\n"); |
2773 |
} |
2774 |
if ((xap[0] == '-') && (xap[1] == 'E')) |
2775 |
{ |
2776 |
NoSJIS = TRUE; |
2777 |
printf("EUC (No Shift-JIS) operation enforced\n"); |
2778 |
} |
2779 |
if ((xap[0] == '-') && (xap[1] == 'v')) |
2780 |
{ |
2781 |
Jverb = FALSE; |
2782 |
printf("Verb deinflection turned OFF\n"); |
2783 |
} |
2784 |
if ((xap[0] == '-') && (xap[1] == 'h')) |
2785 |
{ |
2786 |
printf("\nUSAGE: xjdic <options>\n\nwhere options are:\n\n"); |
2787 |
printf(" -h this information\n"); |
2788 |
printf(" -c control-file\n"); |
2789 |
#ifdef XJDCLSERV |
2790 |
printf(" -P port-no\n"); |
2791 |
printf(" -S server\n"); |
2792 |
#else |
2793 |
printf(" -d dictionary file_path\n"); |
2794 |
printf(" -k kanji-dictionary file_path\n"); |
2795 |
#endif |
2796 |
printf(" -v disable verb function\n"); |
2797 |
printf(" -j x (where x is Output code: e = EUC, s = Shift-JIS, j = JIS)\n"); |
2798 |
printf(" -V disable reverse video display\n"); |
2799 |
printf(" -C clipboard-file\n"); |
2800 |
printf("\nSee xjdic24.inf for full information\n"); |
2801 |
exit(0); |
2802 |
} |
2803 |
} |
2804 |
} |
2805 |
xjdicrc(); |
2806 |
#ifdef XJDDIC |
2807 |
printf ("Loading Dictionary and Index files. Please wait...\n"); |
2808 |
#endif |
2809 |
Verbinit(); |
2810 |
DicSet (); |
2811 |
RadSet(); |
2812 |
RadLoad(); |
2813 |
KSLoad(); |
2814 |
LoadKana(); |
2815 |
togglemode(); |
2816 |
togglekanji(); |
2817 |
cbreakon(); |
2818 |
printf("\n(Enter ? for a summary of operating instructions)\n"); |
2819 |
|
2820 |
/* |
2821 |
From here on, the code loops endlessly, reading commands |
2822 |
from the keyboard. This code decodes any kana/kanji/romaji |
2823 |
itself, rather than using the "GetKBStr" function, as it has |
2824 |
to sort out special commands as well. |
2825 |
*/ |
2826 |
while (TRUE) |
2827 |
{ |
2828 |
GetWinSize(); /* Just in case the screen has changed */ |
2829 |
sprintf(kbprompt,"%sXJDIC [%d:%s] SEARCH KEY:%s ",RVon,CurrDic,DicName(CurrDic),RVoff); |
2830 |
sprintf(kbprompt2,"XJDIC [%d:%s] SEARCH KEY: ",CurrDic,DicName(CurrDic)); |
2831 |
if (GDmode) |
2832 |
{ |
2833 |
sprintf(kbprompt,"%sXJDIC [GLOBAL] SEARCH KEY:%s ",RVon,RVoff); |
2834 |
sprintf(kbprompt2,"XJDIC [GLOBAL] SEARCH KEY: "); |
2835 |
} |
2836 |
printf("\n\r%s",kbprompt); |
2837 |
c = 0; |
2838 |
cmdmode = FALSE; |
2839 |
strf = FALSE; |
2840 |
escf = FALSE; |
2841 |
bit8 = FALSE; |
2842 |
AKanaMode = FALSE; |
2843 |
if (KImode == 0) AKanaMode = TRUE; |
2844 |
for (i = 0; (c != 0xd) && (c != 0xa); i++) |
2845 |
{ |
2846 |
instr[i+1] = 0; |
2847 |
if (clipmode) break; |
2848 |
c = getcharxx(); |
2849 |
if (c == 0x1b) |
2850 |
{ |
2851 |
escf = TRUE; |
2852 |
AKanaMode = FALSE; |
2853 |
} |
2854 |
if (c > 0x7f) |
2855 |
{ |
2856 |
bit8 = TRUE; |
2857 |
AKanaMode = FALSE; |
2858 |
} |
2859 |
if (!bit8 && !escf && (c == 0x04)) /* Simulate ^D */ |
2860 |
{ |
2861 |
cbreakoff(); |
2862 |
exit(0); |
2863 |
} |
2864 |
if (!bit8 && !escf && (c == 0x1a)) /* Simulate ^Z */ |
2865 |
{ |
2866 |
cbreakoff(); |
2867 |
printf("\nSuspending XJDIC. Type `fg' to resume.\n"); |
2868 |
pid = getpid(); |
2869 |
kill(pid,sig); |
2870 |
cbreakon(); |
2871 |
break; |
2872 |
} |
2873 |
/* Romaji Input */ |
2874 |
if (!bit8 && !escf && ((c == '@') || (c == '#'))) |
2875 |
{ |
2876 |
DoRomaji(c); |
2877 |
break; |
2878 |
} |
2879 |
/* On-line Help Summmary */ |
2880 |
if ((c == '?') && (!escf) && (!bit8)) |
2881 |
{ |
2882 |
DRow = 0; |
2883 |
for (ip = 0; strcmp(Help[ip],"$$$")!=0;ip++) |
2884 |
{ |
2885 |
strcpy(KLine,Help[ip]); |
2886 |
if(!KFlush("Continue Help Display? (y/n)")) break; |
2887 |
} |
2888 |
break; |
2889 |
} |
2890 |
/* Turn on cmd mode for special characters */ |
2891 |
if ((!escf) && (!bit8) && (strchr("!{}$%*&^=/-:\'+\\;][|_`",c) != NULL)) |
2892 |
{ |
2893 |
cmdmode = TRUE; |
2894 |
break; |
2895 |
} |
2896 |
/* backspace or rubout - shrink i/p buffer and redisplay */ |
2897 |
if ((c == 0x7f) || (c == 8)) |
2898 |
{ |
2899 |
if(bit8) i--; |
2900 |
if( i > 0) instr[--i] = 0; |
2901 |
i--; |
2902 |
strcpy(fbuff,instr); |
2903 |
if (!NoSJIS) FixSJIS(fbuff); |
2904 |
printf("\r \r"); |
2905 |
printf("%s",kbprompt); |
2906 |
KOut(fbuff); |
2907 |
continue; |
2908 |
} |
2909 |
/* Actually an input character */ |
2910 |
instr[i] = c; |
2911 |
if (AKanaMode) |
2912 |
{ |
2913 |
if ((c == 'l') || (c == 'L')) |
2914 |
{ |
2915 |
AKanaMode = FALSE; |
2916 |
GetKBStr(kbprompt2); |
2917 |
break; |
2918 |
} |
2919 |
if (c < 128) |
2920 |
{ |
2921 |
ungetc(c,stdin); |
2922 |
DoRomaji('@'); |
2923 |
break; |
2924 |
} |
2925 |
} |
2926 |
if (!escf) |
2927 |
{ |
2928 |
if (!bit8) |
2929 |
{ |
2930 |
printf("\r \r"); |
2931 |
printf("%s%s",kbprompt,instr); |
2932 |
} |
2933 |
else |
2934 |
{ |
2935 |
strcpy(fbuff,instr); |
2936 |
if ((strlen(fbuff) % 2) > 0) fbuff[strlen(fbuff)-1] = 0; |
2937 |
printf("\r \r"); |
2938 |
printf("%s",kbprompt); |
2939 |
if (!NoSJIS) FixSJIS(fbuff); |
2940 |
KOut(fbuff); |
2941 |
} |
2942 |
} |
2943 |
/* JIS ShiftOUT, so terminate input */ |
2944 |
if ((instr[i] == 'B')&&(instr[i-1] == '(')&&(instr[i-2] == 0x1b)) break; |
2945 |
} |
2946 |
fseek(stdin,0L,SEEK_END); /*kill any leftovers*/ |
2947 |
/* "bye" is the end of the run */ |
2948 |
if ((instr[2] == 'e')&&(instr[1] == 'y')&&(instr[0] == 'b')) |
2949 |
{ |
2950 |
cbreakoff(); |
2951 |
exit(0); |
2952 |
} |
2953 |
/* sort out the special commands */ |
2954 |
if(cmdmode) |
2955 |
{ |
2956 |
if (c == '{') /* } to balance {} */ |
2957 |
{ |
2958 |
printf("\r \r"); |
2959 |
printf("Now in Clipboard Mode\n"); |
2960 |
clipmode = TRUE; |
2961 |
continue; |
2962 |
} |
2963 |
if (c == '}') /* matching { */ |
2964 |
{ |
2965 |
printf("\r \r"); |
2966 |
RVtoggle(); |
2967 |
continue; |
2968 |
} |
2969 |
if (c == '/') |
2970 |
{ |
2971 |
printf("\r \r"); |
2972 |
togglemode(); |
2973 |
continue; |
2974 |
} |
2975 |
if (c == '!') |
2976 |
{ |
2977 |
printf("\r \r"); |
2978 |
DispLic(); |
2979 |
continue; |
2980 |
} |
2981 |
if (c == '|') |
2982 |
{ |
2983 |
printf("\r \r"); |
2984 |
toggleraw(); |
2985 |
continue; |
2986 |
} |
2987 |
if (c == '+') |
2988 |
{ |
2989 |
printf("\r \r"); |
2990 |
engpritoggle(); |
2991 |
continue; |
2992 |
} |
2993 |
if (c == '&') |
2994 |
{ |
2995 |
printf("\r \r"); |
2996 |
togglekana(); |
2997 |
continue; |
2998 |
} |
2999 |
if (c == '-') |
3000 |
{ |
3001 |
printf("\r \r"); |
3002 |
togglekanji(); |
3003 |
continue; |
3004 |
} |
3005 |
if (c == ']') |
3006 |
{ |
3007 |
printf("\r \r"); |
3008 |
ExtFileDisp(); |
3009 |
continue; |
3010 |
} |
3011 |
if (c == '=') |
3012 |
{ |
3013 |
printf("\r \r"); |
3014 |
altdic(+1); |
3015 |
continue; |
3016 |
} |
3017 |
if (c == '^') |
3018 |
{ |
3019 |
printf("\r \r"); |
3020 |
altdic(-1); |
3021 |
continue; |
3022 |
} |
3023 |
if (c == '_') |
3024 |
{ |
3025 |
printf("\r \r"); |
3026 |
seldic(); |
3027 |
continue; |
3028 |
} |
3029 |
if (c == '\'') |
3030 |
{ |
3031 |
printf("\r \r"); |
3032 |
OneShot(); |
3033 |
continue; |
3034 |
} |
3035 |
if (c == ';') |
3036 |
{ |
3037 |
printf("\r \r"); |
3038 |
FiltSet(); |
3039 |
continue; |
3040 |
} |
3041 |
if (c == ':') |
3042 |
{ |
3043 |
printf("\r \r"); |
3044 |
Verbtoggle(); |
3045 |
continue; |
3046 |
} |
3047 |
if (c == '[') |
3048 |
{ |
3049 |
printf("\r \r"); |
3050 |
EMtoggle(); |
3051 |
continue; |
3052 |
} |
3053 |
if (c == '$') |
3054 |
{ |
3055 |
printf("\r \r"); |
3056 |
GDicSet(); |
3057 |
continue; |
3058 |
} |
3059 |
if (c == '`') |
3060 |
{ |
3061 |
printf("\r \r"); |
3062 |
GDicALLtoggle(); |
3063 |
continue; |
3064 |
} |
3065 |
if (c == '%') |
3066 |
{ |
3067 |
printf("\r \r"); |
3068 |
GDictoggle(); |
3069 |
continue; |
3070 |
} |
3071 |
if (c == '*') |
3072 |
{ |
3073 |
#ifdef DEMAND_PAGING |
3074 |
printf("\r \r"); |
3075 |
BuffStats(); |
3076 |
#else |
3077 |
printf("\nNo statistics in this mode!\n"); |
3078 |
#endif |
3079 |
continue; |
3080 |
} |
3081 |
/* none of the above, so it must be a Kanji search */ |
3082 |
printf("\r \r"); |
3083 |
printf("%sKANJI LOOKUP TYPE:%s ",RVon,RVoff); |
3084 |
c = getcharxx(); |
3085 |
|
3086 |
switch (c) |
3087 |
{ |
3088 |
case 'c' : /* a KANJIDIC Index Code */ |
3089 |
case 'C' : |
3090 |
|
3091 |
printf("\r \r"); |
3092 |
printf("%sINDEX CODE:%s",RVon,RVoff); |
3093 |
GetKBStr("INDEX CODE:"); |
3094 |
fflush(stdin); |
3095 |
Dmode =1; |
3096 |
strcat(fbuff," "); |
3097 |
/* For bushu or classical radical, ask for stroke count */ |
3098 |
if (((fbuff[0] | 0x20) == 'b')||((fbuff[0] | 0x20) == 'c')) |
3099 |
{ |
3100 |
if (fbuff[1] >= 0xb0) /* test for "bKANJI" */ |
3101 |
{ |
3102 |
for (i=0;i<250;i++) |
3103 |
{ |
3104 |
if((fbuff[1] != radkanj[i][0]) || (fbuff[2] != radkanj[i][1])) continue; |
3105 |
sprintf(strtmp,"%d",radnos[i]); |
3106 |
strcpy(fbuff+1,strtmp); |
3107 |
strcat(fbuff," "); |
3108 |
printf("Bushu: %s\n",strtmp); |
3109 |
break; |
3110 |
} |
3111 |
if (i == 250) |
3112 |
{ |
3113 |
printf("Invalid Bushu. Assuming B1 \n"); |
3114 |
strcpy(fbuff,"B1 "); |
3115 |
} |
3116 |
} |
3117 |
printf("\r \r"); |
3118 |
printf("%sSTROKE COUNT (0 selects all):%s",RVon,RVoff); |
3119 |
cbreakoff(); |
3120 |
fgets(instr,3,stdin); |
3121 |
i = atoi(instr); |
3122 |
sprintf(strfilt,"S%d",i); |
3123 |
cbreakon(); |
3124 |
fflush(stdin); |
3125 |
fseek(stdin,0L,SEEK_END); /*kill any leftovers*/ |
3126 |
strf = TRUE; |
3127 |
if (atoi(strfilt+1) == 0) strf = FALSE; |
3128 |
} |
3129 |
KLookup(); |
3130 |
instr[0] = 0; |
3131 |
break; |
3132 |
case 'm' : /* "meaning" */ |
3133 |
case 'M' : |
3134 |
printf("\r \r"); |
3135 |
printf("%sMEANING:%s",RVon,RVoff); |
3136 |
cbreakoff(); |
3137 |
scanf("%s",instr); |
3138 |
cbreakon(); |
3139 |
fflush(stdin); |
3140 |
Dmode =1; |
3141 |
strcpy(fbuff,instr); |
3142 |
fseek(stdin,0L,SEEK_END); /*kill any leftovers*/ |
3143 |
KLookup(); |
3144 |
instr[0] = 0; |
3145 |
break; |
3146 |
case 'j' : /* JIS code */ |
3147 |
case 'J' : |
3148 |
printf("\r \r"); |
3149 |
printf("%sJIS CODE:%s",RVon,RVoff); |
3150 |
DoJIS(); |
3151 |
break; |
3152 |
case 'r' : |
3153 |
case 'R' : |
3154 |
DoRADICALS(); |
3155 |
break; |
3156 |
case 'l' : |
3157 |
case 'L' : |
3158 |
DoLOOKUP(); |
3159 |
break; |
3160 |
case 'k' : |
3161 |
case 'K' : |
3162 |
DoKANJI(); |
3163 |
break; |
3164 |
default : |
3165 |
ungetc(c,stdin); |
3166 |
DoKANJI(); |
3167 |
break; |
3168 |
} |
3169 |
} |
3170 |
if (clipmode) |
3171 |
{ |
3172 |
while(TRUE) |
3173 |
{ |
3174 |
sleep(2); |
3175 |
fclip = fopen(Clip_File,"r"); |
3176 |
if (fclip == NULL) |
3177 |
{ |
3178 |
printf("\nNo Clipboard file! (returning to normal mode.)\n"); |
3179 |
strcpy(clipstring1,"XXXX"); |
3180 |
strcpy(clipstring2,"XXXX"); |
3181 |
clipmode = FALSE; |
3182 |
break; |
3183 |
} |
3184 |
fgets(clipstring1,50,fclip); |
3185 |
fclose(fclip); |
3186 |
if (clipstring1[strlen(clipstring1)-1] < 32) clipstring1[strlen(clipstring1)-1] = 0; |
3187 |
if (strcmp(clipstring1,"quit") == 0) |
3188 |
{ |
3189 |
clipmode = FALSE; |
3190 |
printf("\nLeaving Clipboard mode\n"); |
3191 |
break; |
3192 |
} |
3193 |
if (strcmp(clipstring1,clipstring2) == 0) |
3194 |
{ |
3195 |
continue; |
3196 |
} |
3197 |
else |
3198 |
{ |
3199 |
strcpy(clipstring2,clipstring1); |
3200 |
strcpy(instr,clipstring1); |
3201 |
break; |
3202 |
} |
3203 |
} |
3204 |
} |
3205 |
if(strlen(instr) < 2) continue; |
3206 |
GetEUC(fbuff); |
3207 |
if (escf) KOut(fbuff); |
3208 |
sprintf(tempout,"\nSearching for: %s%s%s\n",RVon,fbuff,RVoff); |
3209 |
KOut(tempout); |
3210 |
Dmode = 0; |
3211 |
if (prieng && (fbuff[0] < 128)) /* if priority English key only */ |
3212 |
{ |
3213 |
j = strlen(fbuff); |
3214 |
fbuff[j+1] = 0; |
3215 |
for (i=0 ; i < j ; i++) fbuff[i+1] = fbuff[i]; |
3216 |
fbuff[0] = SPTAG; |
3217 |
} |
3218 |
Lookup(); |
3219 |
} |
3220 |
} |