1/* Copyright 1994 NEC Corporation, Tokyo, Japan.
2 *
3 * Permission to use, copy, modify, distribute and sell this software
4 * and its documentation for any purpose is hereby granted without
5 * fee, provided that the above copyright notice appear in all copies
6 * and that both that copyright notice and this permission notice
7 * appear in supporting documentation, and that the name of NEC
8 * Corporation not be used in advertising or publicity pertaining to
9 * distribution of the software without specific, written prior
10 * permission.  NEC Corporation makes no representations about the
11 * suitability of this software for any purpose.  It is provided "as
12 * is" without express or implied warranty.
13 *
14 * NEC CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
16 * NO EVENT SHALL NEC CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
18 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19 * OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 */
22
23/* LINTLIBRARY */
24/* $Id: RKintern.h 10525 2004-12-23 21:23:50Z korli $ */
25/************************************************************************/
26/* THIS SOURCE CODE IS MODIFIED FOR kanBe BY T.MURAI 1997 */
27/************************************************************************/
28#ifndef		_RKintern_h
29#define		_RKintern_h
30
31#define BUNMATU
32
33/* BUNMATU ¥Þ¥¯¥í¤ò define ¤¹¤ë¤È¡¢ËÌΦÀèü²Ê³Øµ»½ÑÂç³Ø±¡Âç³Ø¾ðÊó²Ê³Ø
34   ¸¦µæ²Ê¤ÎÆ£»ÞϹ¨(fujieda@jaist.ac.jp)¤µ¤ó¤¬¡¢¡Ø¤«¤ó¤Ê¡Ù¤Î¤«¤Ê´Á»úÊÑ
35   ´¹¸úΨ¸þ¾å¤Î¤¿¤á¤Ë¡¢1994 ÅߤËÁȤ߹þ¤ó¤À¡Öʸ¾ÏËöµ­¹æ¡×¤¬Í­¸ú¤Ë¤Ê¤ê¤Þ
36   ¤¹¡£¤³¤ì¤Ë¤è¤êʸ¾ÏËö¤Ë¤·¤«¸½¤ì¤Ê¤¤Ê¸»ú¤¬Ê¸Àá¤ÎÅÓÃæ¤Ë½Ð¤ÆÍè¤ë¤³¤È¤¬
37   ¤Ê¤¯¤Ê¤êÊÑ´¹¸úΨ¤¬¸þ¾å¤·¤Þ¤¹¡£¤³¤Î¥³¡¼¥É¤ò¤«¤¤¤Æ²¼¤µ¤¤¤Þ¤·¤¿Æ£»Þ¤µ
38   ¤ó¤Ë´¶¼Õ¤·¤Þ¤¹¡£ */
39
40//#define FUJIEDA_HACK
41/* Æ£»Þ¡÷£Ê£Á£É£Ó£Ô¤Î¥Ï¥Ã¥¯¤òÍ­¸ú¤Ë¤¹¤ë */
42
43#define EXTENSION_NEW
44
45#include "cannaconf.h"
46#include "cannabuild.h"
47
48#if defined(__STDC__) || !DONT_HAVE_RENAME
49#define HAVE_RENAME
50#endif
51
52#include "widedef.h"
53#define RK_INTERNAL
54#include "canna/RK.h"
55
56#include <stdlib.h>
57
58#ifdef NOT_DEF
59#include <errno.h>
60int	Rk_errno;
61#define RkSetErrno(number) {\
62    if (number)
63	Rk_errno = (number);
64    else
65	Rk_errno = errno;
66}
67#else
68#define RkSetErrno(number)
69#endif
70
71#ifndef RK_DEBUG
72#define	RkDebug(fmt, p, q, r)
73#endif
74
75#define	MKDIR_MODE	0775
76#define	CREAT_MODE	0664
77
78typedef unsigned char	*pointer;
79typedef unsigned char   Wrec;
80
81#define WMASK		(~0x0303)
82#define RK_WMASK	WMASK
83#define WNILL		(unsigned short)0x0000
84#define WNULL		(unsigned short *)0
85#define	us_iscodeG0(wc)	(((wc) & 0x8080) == 0x0000)
86#define	us_iscodeG1(wc)	(((wc) & 0x8080) == 0x8080)
87#define	us_iscodeG2(wc)	(((wc) & 0x8080) == 0x0080)
88#define	us_iscodeG3(wc)	(((wc) & 0x8080) == 0x8000)
89
90#define RK_SS2 (unsigned char)0x8e
91#define RK_SS3 (unsigned char)0x8f
92
93#define RK_ESC_CHAR ((WCHAR_T)'\\')
94
95//#ifndef isascii
96//#define isascii(c) (((c) >= 0 && (c) <= 256))
97//#endif
98
99#define	euc_iscodeG0(c)	isascii(c)
100#define	euc_iscodeG1(c)	(((c) & 0x80) && !((c) & RK_SS2) && !((c) & RK_SS3))
101#define	euc_iscodeG2(c)	((c) & RK_SS2)
102#define	euc_iscodeG3(c)	((c) & RK_SS3)
103
104/* RkUnion
105 *	private data at each class.
106 */
107typedef union _rkunion {
108  pointer	ptr;
109  long		var;
110  unsigned long	uvar;
111} RkUnion;
112
113/*	kana kanji henkan jisho
114 *		MS	870713
115 *
116 *	+---------------+
117 *	|     HEADER	|	jisho header (256 byte)
118 *	+---------------+256L
119 *	|		|	yomigana no index
120 *	|   DIRECTORY	|
121 *	+---------------+
122 *	|		|	tango jouhou
123 *	|		|		yomi, {(row, col), tsuduri, hindo}...
124 *	|     WORD	|
125 *	|		|
126 *	|		|
127 *	+---------------+
128 *	|		|	setuzoku jouhou(swd nomi)
129 *	|   CONJUNCT	|		row...
130 *	|		|
131 *	+---------------+
132 */
133
134/* BASIC TYPE:
135 *	subete no data ha MSB first(Motorolla order) de tenkai sareru
136 *		unsigned char	w
137 *		unsigned short	wx
138 *		unsigned long	wxyz
139 */
140#define LOMASK(x)	((x)&255)
141/* #include	"type.h" */
142/*
143 * 	byte stream <=> long or short
144 */
145#define l_to_bst4(src, dst) {\
146    dst[0] = (unsigned char)(((long)(src) >> 24) & 0xff);\
147    dst[1] = (unsigned char)(((long)(src) >> 16) & 0xff);\
148    dst[2] = (unsigned char)(((long)(src) >> 8) & 0xff);\
149    dst[3] = (unsigned char)( (long)(src) & 0xff);\
150}
151
152#define bst4_to_l(src) \
153    (unsigned long)(((long)(src)[0] << 24) |\
154		    ((long)(src)[1] << 16) |\
155		    ((long)(src)[2] << 8) |\
156		     (long)(src)[3])
157
158#define l_to_bst3(src, dst) {\
159    dst[0] = (unsigned char)(((long)(src) >> 16) & 0xff);\
160    dst[1] = (unsigned char)(((long)(src) >> 8) & 0xff);\
161    dst[2] = (unsigned char)( (long)(src) & 0xff);\
162}
163
164#define bst3_to_l(src) \
165    (unsigned long)(((long)(src)[0] << 16) | ((long)(src)[1] << 8) | (long)(src)[2])
166
167#define s_to_bst2(src, dst) {\
168    (dst)[0] = (unsigned char)((src >> 8) & 0xff);\
169    (dst)[1] = (unsigned char)(src & 0xff);\
170}
171
172#define	bst2_to_s(src) \
173    (unsigned short)(((unsigned short)(src)[0] << 8) | (src)[1])
174
175#define l_to_bst	l_to_bst4
176#define bst_to_l	bst4_to_l
177#define s_to_bst	s_to_bst2
178
179#define	L4TOL(l4)\
180	(((((((unsigned long)(l4)[0]<<8)|(l4)[1])<<8) | (l4)[2])<<8)|(l4)[3])
181#define	L3TOL(l3)\
182	(((((unsigned long)(l3)[0]<<8)|(l3)[1])<<8) | (l3)[2])
183#define	S2TOS(s2)	(((unsigned short)(s2)[0]<<8)|(s2)[1])
184#define	LTOL4(l, l4)	{\
185	(l4)[0] = LOMASK((l)>>24); (l4)[1] = LOMASK((l)>>16);\
186	(l4)[2] = LOMASK((l)>> 8); (l4)[3] = LOMASK((l));\
187	}
188#define	LTOL3(l, l3)	{\
189			   (l3)[0] = LOMASK((l)>>16);\
190			   (l3)[1] = LOMASK((l)>> 8);\
191			   (l3)[2] = LOMASK((l));\
192			}
193#define	STOS2(s, s2)	{\
194			   (s2)[0] = LOMASK((s)>> 8);\
195			   (s2)[1] = LOMASK((s));\
196			 }
197
198#define RkNumber(ary) (sizeof(ary)/sizeof(ary[0]))
199
200#define rk_isdigit(c) (!((c) & ~0xff) ? isdigit((int)(c)) : 0)
201#define rk_isascii(c) (!((c) & ~0xff) ? isascii((int)(c)) : 0)
202#define rk_isspace(c) (!((c) & ~0xff) ? isspace((int)(c)) : 0)
203
204#define HD_MAG		0
205#define HD_VER		1
206#define HD_TIME		2
207#define HD_REC		3
208#define HD_CAN		4
209#define HD_L2P		5
210#define HD_L2C		6
211#define HD_PAG		7
212#define HD_LND		8
213#define HD_SND		9
214#define HD_SIZ		10
215#define HD_HSZ		11
216#define HD_DROF		12
217#define HD_PGOF		13
218#define HD_DMNM		14
219#define HD_CODM		15
220#define HD_LANG		16
221#define HD_WWID		17
222#define HD_WTYP		18
223#define HD_COPY		19
224#define HD_NOTE		20
225#define HD_TYPE		21
226
227#define HD_MAXTAG	(HD_TYPE + 1)
228
229#define HD_TAGSIZ	(sizeof(long))
230#define HD_MIN_TAGSIZ	(3 * HD_TAGSIZ)
231
232struct HD {
233    RkUnion	data[HD_MAXTAG];
234    int		flag[HD_MAXTAG];
235};
236
237#define	isEndTag(s)	(s[0] == 0 && s[1] == 0 && s[2] == 0 && s[3] == 0)
238
239#define HD_TAG_MAG	"MAG#"
240#define HD_TAG_VER	"VER#"
241#define HD_TAG_TIME	"TIME"
242#define HD_TAG_REC	"#REC"
243#define HD_TAG_CAN	"#CAN"
244#define HD_TAG_L2P	"L2P#"
245#define HD_TAG_L2C	"L2C#"
246#define HD_TAG_PAG	"#PAG"
247#define HD_TAG_LND	"#LND"
248#define HD_TAG_SND	"#SND"
249#define HD_TAG_SIZ	"#SIZ"
250#define HD_TAG_HSZ	"#HSZ"
251#define HD_TAG_DROF	"DROF"
252#define HD_TAG_PGOF	"PGOF"
253#define HD_TAG_DMNM	"DMNM"
254#define HD_TAG_CODM	"CODM"
255#define HD_TAG_LANG	"LANG"
256#define HD_TAG_WWID	"WWID"
257#define HD_TAG_WTYP	"WTYP"
258#define HD_TAG_COPY	"(C) "
259#define HD_TAG_NOTE	"NOTE"
260#define HD_TAG_TYPE	"TYPE"
261
262#define JMWD	1
263#define JSWD	2
264#define JPRE	3
265#define JSUC	4
266
267#define BYTE2		2
268#define BYTE4		4
269
270#define DEF_WWID	2
271
272#define WORD_NODE		(0x80)
273#define LAST_NODE		(0x40)
274const unsigned int BIT_UNIT = 8;
275
276#define NOLOCALE	"NOLOCALE"
277#define DEF_WTYP	"W16 "
278#define DEF_TYPE	"jmwd"
279
280#define	RK_PG_LOADED		0x01
281#define	RK_PG_USED		0x02
282
283#define	isLoadedPage(p)		((p)->flags & RK_PG_LOADED)
284#define	isUsedPage(p)		((p)->flags & RK_PG_USED)
285
286#define	thisPWO(p)	(unsigned long)((((unsigned long ) *(p) << 6) & 0x3fc0) \
287				   | ((*((p)+1) >> 2) & 0x3f))
288#define	thisLVO(p)	(unsigned long)((((unsigned long) *((p)+1) << 13) & 0x6000) \
289				   | (((unsigned long) *((p)+2) << 5) & 0x1fe0) \
290				   | ((*((p)+3) >> 3) & 0x1f))
291#define	thisCSN(p)	(unsigned long)((((unsigned long) *((p)+3) << 8) & 0x700) | *((p)+4))
292
293struct NP {
294  unsigned	ndsz;
295  unsigned	lnksz;
296  unsigned long	lvo;
297  unsigned long	csn;
298  unsigned	flags;
299  int		count;
300  unsigned char	*buf;
301};
302
303/*
304 * definition of off_t added by Kenji Rikitake 27-MAR-1995
305 *
306 * Include necessary headers for lseek() here.
307 * note: sys/types.h only applies for BSD/OS 2.0.
308 * Use the appropriate files for other systems.
309 */
310
311#include <sys/types.h>
312
313struct ND {
314  unsigned long time;
315  unsigned long rec;
316  unsigned long can;
317  unsigned long sz;
318  off_t         doff;
319  unsigned long drsz;
320  unsigned long pgsz;
321  unsigned long ttlpg;
322  int           fd;
323  unsigned char *buf;
324  struct NP     *pgs;
325};
326
327/* HEADER:
328 *	unsigned char	magic[2];
329 *	unsigned char	pakeuc;		key ga asshuku sareteiru
330 *	unsigned char	name[];		jisho mei
331 *					xxx.mwd xxx.swd xxx.pre xxx.suc
332 *					\n de shuuryou
333 */
334#define		ND_HDMAGICSIZ		4
335#define		ND_HDRSIZ		256		/* header size */
336#if 0 /* iranai? */
337#define		ND_HDRMAG (('H'<<8)|'N')/* magic number */
338#endif
339/* jisho class */
340#define		ND_MWD		RK_MWD
341#define		ND_SWD		RK_SWD
342#define		ND_PRE		RK_PRE
343#define		ND_SUC		RK_SUC
344#define		ND_EMP		4		/* kuugo */
345#define		ND_OPN		5		/* hiraki kakko */
346#define		ND_CLS		6		/* toji kakko */
347#define		ND_PUN		7		/* kutouten */
348
349
350struct wcand {
351    unsigned char	*addr;
352    unsigned short	row;
353    unsigned char	klen;
354};
355
356struct RkXwrec {
357    unsigned		ncands, wrecsz;
358    unsigned char	*wrec;
359};
360
361/* DIRECTORY:
362 *	xxxx NODE....
363 *	    xxxx niha, DIRECTORY no ookisa ga byte de hairu.
364 *
365 *	4 byte no NODE kara kousei
366 *
367 *	+--+--+--+--+
368 *	|KY|X1 X2 X3|
369 *	+--+--+--+--+
370 *	 !  !
371 *	 !  +-------------	X1
372 *	 !			word record/directory offset
373 *	 !			 (X1<<16) | (X2<<8) | (X3)
374 *	 !
375 *	 +----------------	yomi (ascii/euc hiragara lower byte)
376 *				0
377 */
378#define	ND_NODSIZ	6		/* node size in byte */
379#define	ND_DSPENT	189		/* #entry in the dispatch table */
380/* mask values */
381#define	ND_OFFMASK	0x00ffffffL	/* offset mask (24 bit) */
382/* X1 bit flags */
383
384#define	ND_NULLOFF	ND_OFFMASK	/* tango ga sakujo sareta */
385#define	VMASK		0x7fffffL
386
387/* predicators */
388#define	ND_LAST		0x0080L	/* directory no saishuu node (entry) */
389#define	ND_WORD		0x0040L	/* offset ha tango joushou wo sasu */
390#define	ND_RFU		0x0020L	/* Mishiyou (offset ni tuika ?) */
391#define	ISLASTNOD(flag)	((flag)&ND_LAST)
392#define	ISWORDNOD(flag)	((flag)&ND_WORD)
393
394
395#define HN (unsigned long) 256
396#define HashFunc(key) (unsigned long)((key) % HN)
397
398struct WRT{
399       unsigned long sz;
400       unsigned long cs;
401       unsigned long frst;
402       unsigned long tm;
403       unsigned char *buf;
404};
405
406struct CTdata{
407       struct CTdata *next;
408       unsigned long ct[2];
409};
410
411struct RUT{
412       unsigned long sz;
413       unsigned long cs;
414       unsigned long frst;
415       unsigned long tm;
416       struct CTdata **dp;
417};
418
419#define a_csn(x)  (unsigned long) \
420(((((unsigned long)(x)[0] << 8) | (x)[1]) << 4) | (((unsigned long)(x)[2] & 0xf0) >> 4))
421
422#define a_tick(x) (unsigned long) \
423((((((unsigned long)(x)[2] & 0x0f) << 8) | (unsigned long)(x)[3]) << 8) | (x)[4])
424
425#define WriteVal(csn, tick, buf){\
426   (buf)[0] = (unsigned char)(((csn)>>12) & 0xff);\
427   (buf)[1] = (unsigned char)(((csn)>>4) & 0xff);\
428   (buf)[2] = (unsigned char)((((csn)<< 4) & 0xf0)|(((tick)>>16) & 0x0f));\
429   (buf)[3] = (unsigned char)(((tick)>>8) & 0xff);\
430   (buf)[4] = (unsigned char)((tick) & 0xff);\
431}
432
433#define WriteCT(csn, tick, arr){\
434   (arr)[0] = (unsigned long) (csn);\
435   (arr)[1] = (unsigned long) (tick);\
436}
437
438#define freeWRT(wruc) {\
439     free(wruc->buf);\
440     free(wruc);\
441}
442
443#define RKmaxDN (unsigned long) 0xff
444#define RKmaxCN (unsigned long) 0xffffff
445
446
447/* WORD:
448 *	xxxx {yomi nkouho {flags row col freq kouho}...}...
449 *	    xxxx niha, WORD no ookisa ga byte de hairu.
450 *
451 * tango:
452 *	unsigned char	yomi[];			yomigana
453 *	unsigned char	nkouho;			kouho no kazu
454 *		unsigned char	flags;		kouho no nagasa + flags
455 *		unsigned char	row;		kouho no row bangou
456 *		unsigned char	col;		kouho no col bangou
457 *		unsigned char	freq		kouho no shiyou hindo
458 *		unsigned char	kouho[];
459 *
460 */
461
462#define	NW_PREFIX	2	/* the length of kouho prefix in byte */
463
464/* flags */
465#define	NW_RC256	0x80	/* set when rowcol >= 256 */
466#define	NW_LEN		0x7f	/* kouho no nagasa ( zenkaku 31 moji) */
467#define	rowcol256(flag)	((flag) & NW_RC256)
468
469#define	candlen(flag)	((flag) & NW_LEN)
470#define wordlen(flag)	((candlen(flag) << 1) + NW_PREFIX)
471/* RkWcand
472 *	data structure used to handle the word record
473 */
474typedef struct RkWcand {
475    Wrec		*addr;		/* houho sentou address */
476    short		rcnum;		/* row column number */
477    unsigned char	klen;		/* kouho no nagasa */
478} Candidate;
479
480/* CONJUNCT:
481 *	xxxx rrcc
482		row_0  row_1  ... row_rr-1
483 *		name_0 name_1 ... name_rr-1
484 *	    xxxx niha, CONJUNCT no ookisa ga byte de hairu.
485 *	    rr, cc ha sorezore, row, col no kosuu wo simesu.
486 *	    row_i ha byte kyoukai kara hajimaru cc bit karanaru bit retu
487 *	    name_i ha EOS de owaru mojiretu
488 *
489 */
490
491#define		crpair(row, col)	((long)(row))
492/* ngram
493 *	tango kan no setuzoku wo simesu gyouretu
494 *	SWD ga open sareruto douji ni yomikomareru
495 */
496struct RkKxGram {
497/* setuzoku jouhou */
498    int		ng_rowcol;	/* row no kazu */
499    int		ng_rowbyte;	/* row atari no byte suu */
500    char	*ng_conj;	/* setuzoku gyouretu/code table */
501    char	**ng_strtab;
502};
503
504#define	GetGramRow(g, r) 	((g)->ng_conj + (r)*(g)->ng_rowbyte)
505#define	TestGram(cnj, col)	((cnj) && ((cnj)[((col)>>3)]&(0x80>>(col&7))))
506
507/* hinshi no bunrui
508 *	renbunsetu henkan de siyou sareru
509 */
510#define	IsShuutan(g, r)		TestGram(GetGramRow(g, r), 0)
511#ifdef BUNMATU
512#define	IsBunmatu(g, r)		TestGram(GetGramRow(g, r), 1)
513#endif
514#define	IsTaigen(g, r)		TestGram(GetGramRow(g, R_TAIGEN), r)
515#define	IsYougen(g, r)		TestGram(GetGramRow(g, R_YOUGEN), r)
516#define	IsKakujs(g, r)		TestGram(GetGramRow(g, R_KAKUJS), r)
517#define is_row_num(g, n)	((0 <= (n)) && ((n) < ((g)->ng_rowcol)))
518
519/* RkGram -- grammatical information
520 */
521
522struct RkGram {
523  int			refcount; /* reference counter */
524  struct RkKxGram	*gramdic; /* grammar dictionary */
525  int	 		P_BB, P_NN, P_T00, P_T30, P_T35; /* hinshi codes */
526#ifdef FUJIEDA_HACK
527  int			P_KJ; /* tankanji */
528#endif
529};
530
531extern struct RkGram SG;
532
533
534/* ncache
535 *	tango record no caching list
536 *  ncache ha, jisho kara itido yomikomareta tango record wo cache kanri suru
537 * tameno jouhou kouzou dearu.
538 *  tango record ha key (dicnum, address) de skibetu sareru.
539 *  taiou suru tango record ha nc_word ni yori simesareru HEAP ryouiki ni aru.
540 *	+------------+
541 *	| nc_dicnum  |	key part
542 *	| nc_address |
543 *	+------------+
544 *	|  nc_word   |	value part
545 *	+------------+
546 *  ncache ha 2tu no souhoukou list hash/free list ni tunagareru.
547 *  (* koreha UNIX i/o system no buffer cache kara hint wo eta *)
548 *  hash list ha key no kensaku wo kousoku ka suru tame ni shiyou sareru.
549 *  free list ha kaihou sareta cache ga tunagareru.
550 */
551struct ncache	{
552    struct ncache	*nc_hnext;	/* hash list */
553    struct ncache	*nc_hprev;
554    struct ncache	*nc_anext;	/* free list */
555    struct ncache	*nc_aprev;
556    Wrec		*nc_word;	/* heap jouno tango record */
557    struct DM		*nc_dic;	/* yomikomareta jisho */
558    unsigned short	nc_flags;
559    unsigned long	nc_count;	/* word karano sanshou dosuu */
560    long		nc_address;	/* word record no file address */
561};
562/* flags */
563#define	NC_DIRTY	1	/* word no naiyou ga henkou sareta */
564#define	NC_ERROR	2	/* cache no naiyou ga tadasiku nai */
565#define	NC_NHEAP	4	/* word ha heap wo sasite inai */
566
567struct nread {
568  struct ncache	*cache;
569  unsigned long	offset;
570  unsigned long	csn;
571  int		nk;
572};
573
574/* nword
575 *	bunsetsu kaiseki kekka
576 * 	jisho kara no tango yomidasi kekka
577 * nword ha, jisho kara search sareta tango record wo kirokusi,
578 * bunsetsu kaiseki ni yori sakusei sareru bunsetsu tree wo hyougen suru.
579 */
580struct nword {
581    struct ncache	*nw_cache;	/* tango record wo fukumu cache */
582    short		nw_rowcol;	/* setsuzoku  jouhou */
583    unsigned char	nw_ylen;	/* #chars in yomi */
584    unsigned char	nw_klen;	/* #chars in kanji */
585    unsigned char	nw_class;	/* word class */
586    unsigned char	nw_flags;	/* word flags (see below) */
587    unsigned char	nw_lit;		/* literal conversion */
588    unsigned long	nw_prio;	        /* kouzou ni yoru priority */  /* True ? by tamano */
589    unsigned long   nw_csn;
590    struct nword	*nw_left;	/* hidari ni tunagaru word */
591    struct nword	*nw_next;	/* onaji nw_len wo motu list */
592    unsigned char	*nw_kanji;	/* kanji kouho ichi/douteki na kouho */
593/* nw_klen ha fuyou ni naru kanousei ari */
594    struct DM		*nw_freq;	/* pointer to frequncy file */
595};
596/*
597 * word flags
598 */
599#define NW_MWD		0x80
600#define NW_SWD		0x40
601#define NW_PRE		0x20
602#define NW_SUC		0x10
603#ifdef FUJIEDA_HACK
604#define NW_DUMMY	0x08
605#endif
606#ifdef BUNMATU
607#define NW_BUNMATU	0x04
608#endif
609#define	NW_FOLLOW	0x02		/* has some words following to me */
610#define	NW_NEVER_SPLIT	0x01		/* cannot terminate here */
611/* accessor & predicates */
612#define	IsFollowed(w)	((w)->nw_flags&NW_FOLLOW)
613#define	DontSplitWord(w)	((w)->nw_flags |= NW_NEVER_SPLIT)
614#define	CanSplitWord(w)		(!((w)->nw_flags&NW_NEVER_SPLIT))
615#ifdef BUNMATU
616#define	OnlyBunmatu(w)		((w)->nw_flags & NW_BUNMATU)
617#endif
618
619/* conversion number */
620#define	LIT2GRP(cn)	((cn)>>4)
621#define	LIT2MEM(cn)	((cn)&15)
622#define	MAKELIT(g, w)	(((g)<<4)|(w))
623#define	MAXLIT		16
624
625#define	LIT_NONE	0
626#define	LIT_NUM		1
627#define	LIT_ALPHA	2
628#define	LIT_HIRA	3
629
630/* nbun
631 *	bunsetsu queue
632 * renbunsetsu henkan kekka wo kiroku
633 */
634struct nbun {
635    struct nword	*nb_cand;	/* kouho wo kousei suru word
636				         * nw_next niyori sort sareru */
637    unsigned short	nb_yoff;	/* yomigana offset in buffer  */
638    unsigned short	nb_curlen;	/* current candidate length in char */
639    unsigned short	nb_maxcand;	/* number of candidates */
640    unsigned short	nb_curcand;	/* current candidate */
641    unsigned short	nb_flags;	/* ?? */
642};
643
644/* DM/DF/DD
645 */
646/* MS1214
647 *	now DM supports frequency files as well
648 */
649typedef struct DM {
650/* pointers for the file structure */
651    struct DM		*dm_next;
652    struct DM		*dm_prev;
653    struct DF		*dm_file;	/* ptr to the file containing this */
654/* attributes */
655    char		*dm_dicname;
656    char		*dm_nickname;
657    unsigned		dm_class;	/* MWD/SWD/PRE/SUC */
658    unsigned		dm_flags;	/* flags */
659    unsigned char	dm_packbyte;	/* shouryaku sareta joui byte */
660/* reference  count from MD */
661    int			dm_rcount;
662/* setuzoku jouhou (SWD nomi) */
663    struct RkGram	*dm_gram;
664    RkUnion		dm_extdata;
665    unsigned char	*dm_qbits;	/* MS1214 gakushuu jouhou */
666/* */
667    struct DDT		*dm_line;	/* pointer to dd line */
668    long		dm_offset;
669    struct RUT		*dm_rut;
670    struct NV		*dm_nv;
671} DM;
672/* flag values */
673#define	DM_EXIST	0x01		/* member exists */
674#define	DM_WRITABLE	(DM_EXIST << 1)	/* jisho ga write dekiru */
675#define	DM_LOADWORD	(DM_EXIST << 2)	/* word rec wo memory ni yomi */
676#define	DM_UPDATED	(DM_EXIST << 4)	/* member changed */
677#define DM_READOK	(DM_EXIST << 5) /* jisho no read ken */
678#define DM_WRITEOK	(DM_EXIST << 6) /* jisho no write ken */
679
680typedef struct DF {
681/* DF doubly linked list */
682    struct DF	*df_next;
683    struct DF	*df_prev;
684    struct DD	*df_direct;	/* backward pointer to the directory */
685    struct DM	df_members;	/* the header of the dictionary */
686/* attributes */
687    char	*df_link; /* link name of the file */
688    unsigned	df_type;	/* type of file */
689    unsigned	df_flags;	/* access mode */
690    int		df_rcount;	/* # the mounted members */
691    RkUnion	df_extdata;
692    long	df_size;
693} DF;
694#define	DM2TYPE(dm)	((dm)->dm_file->df_type)
695/* jisho no shurui */
696#define	DF_PERMDIC	0	/* file ni aru jisho */
697#define	DF_TEMPDIC	1	/* zantei jisho */
698#define DF_FREQDIC 	2	/* gakushuu hindo jisho MS1214 */
699#define DF_RUCDIC 	3	/* gakushuu hindo jisho MS1214 */
700
701/* flag values */
702#define	DF_EXIST	1	/* file exists */
703#define	DF_WRITABLE	2	/* file is writable */
704
705/*
706 * DD
707 */
708struct DDT	{
709   struct DDT		*ddt_next;
710   struct DDT		*ddt_prev;
711   int			ddt_status;
712   char			*ddt_spec;
713};
714
715typedef struct DD {
716/* DD doubly linked list */
717    struct DD		*dd_next;
718    struct DD		*dd_prev;
719    char		*dd_path;	/* path name of the directory */
720    char		*dd_name;	/* unique name of the directory */
721    int			dd_rcount;	/* # opened files+reference from DDP */
722    struct DF		dd_files;	/* the header of the file list */
723    unsigned		dd_flags;	/* flag */
724/* dics.dir file */
725    struct DDT		dd_text;
726} DD, *DDP;
727
728#define	DD_WRITEOK	1	/* directory is allowed to write */
729#define DD_READOK	2
730
731/* MD ----------------------------------------------------------------
732 *  context ni mount sareta jisho/jisho wo mount siteiru jisho list no taiou
733 * ---------------------------------------------------------------- */
734typedef struct MD {
735    struct MD		*md_next;	/* dictionary list */
736    struct MD		*md_prev;
737    struct DM		*md_dic;	/* jisho heno pointer */
738    struct DM		*md_freq;	/* MS1214 gakushuu jisho heno pointer */
739    int			md_flags;	/* mount flags */
740} MD, *MDP;
741#define	MD_WRITE	1		/* gakushuu shitei */
742#define	MD_MPEND	2		/* mount pending */
743#define	MD_UPEND	4		/* unmount pending */
744
745/* RkParam
746 *	common parameter block
747 */
748struct RkParam {
749/* cache */
750    struct ncache	*cache;
751    int			maxcache;
752/* heap */
753    unsigned char	*heap;
754    int			maxheap;
755    unsigned char	*ham;
756    int			maxham;
757/* word */
758    struct nword	*word;		/* henkyaku sareta word wo tunageru */
759    struct nword	*page;		/* word page list */
760    int			word_in_use;
761    int			page_in_use;
762/* jisho */
763    struct DD		dd;
764    char        	*ddhome;	/* dictionary home directory */
765    struct DD		**ddpath;	/* system ddpath */
766/* flags */
767    unsigned		flag;		/* checks initialize */
768/* */
769};
770
771extern struct RkParam SX;
772
773#define SX_INITED	1
774
775#define RK_REARRANGED	0x01
776
777struct NVE {
778  unsigned char	*data;
779  struct NVE	*left;
780  struct NVE	*right;
781  struct NVE	*next;
782};
783
784struct NV {
785  unsigned long	sz;
786  unsigned long	tsz;
787  long		csz;
788  long		cnt;
789/* int		lst; delete by tamano(tajima) */
790  struct NVE	head;
791  struct NVE	**buf;
792};
793
794struct nstore {
795    WCHAR_T		*yomi;		/* yomigana buffer */
796    unsigned		nyomi;		/* number of yomigana chars */
797    unsigned		maxyomi;	/* maximum number of yomigana chars */
798    struct nbun		*bunq;		/* ʸÀᥭ¥å¡¼ */
799    unsigned		maxbunq;	/* saidai bunnsetu suu */
800    unsigned		maxbun;		/* saidai bunsetsu suu */
801    int			curbun;		/* ¥«¥ì¥ó¥ÈʸÀá */
802    int			maxxq;		/* saidai queue == bunsetu moji suu */
803    struct nqueue	*xq;		/* henkan queue */
804    struct nword	**xqh;		/* used in _RkparseBun() */
805    int			word_in_use;   	/* #words used in context */
806};
807
808/* context
809 *	ncontext ha rennbunnsetu hennkann client wo seigyo suru jouhou
810 *		jisho kankyou
811 *		renbunsetsu henkan sagyou ryouiki
812 */
813struct 	nqueue {
814    struct nword	*tree;
815    short		maxlen;
816    short		status;
817};
818
819typedef struct RkContext {
820    struct nstore	*store;
821    struct MD		*md[4];		/* mwd/swd/pre/suc */
822    struct DD   	**ddpath;	/* dictionary search path */
823    struct DM   	*dmprev;	/* dictionary search path : dic */
824    struct DM   	*qmprev;	/* dictionary search path : freq */
825    unsigned long	time;		/* tic */
826    unsigned		flags;		/* context control flags */
827    unsigned long	kouhomode;	/* kana kouho mode */
828    unsigned long	*litmode;	/* literal conversion table */
829    int			concmode;	/* connect words mode */
830    int			poss_cont;	/* */
831    RkUnion		cx_extdata;	/* etc data */
832    struct NV		*nv;
833    struct RkGram	*gram;
834} RkContext;
835
836/* Extension Data in DM */
837typedef struct TD {
838    struct TN   *td_node;	/* array of node TN */
839    unsigned	td_n;		/* # effective nodes */
840    unsigned	td_max;		/* # maximum nodes in the array */
841} TD;
842
843struct TW {
844  Wrec		*word;
845  unsigned long	lucks[2];
846};
847
848typedef struct TN {
849  unsigned char	tn_flags;	/* type of node (see blow) */
850  WCHAR_T		tn_key;
851  union {
852    struct TD	*tree;
853    struct TW	*word;
854  }	tn_value;				/* type specific data */
855  /* syntax sugar */
856#define tn_tree		tn_value.tree
857#define tn_word		tn_value.word
858} TN;
859/* flags  values */
860#define	TN_WORD		1		/* is a word */
861#define	TN_WDEF		2		/* wrec has been defined */
862#define	TN_WDEL		4		/* wrec has been deleted */
863#define	IsWordNode(tn)	((tn)->tn_flags&TN_WORD)
864
865/* td_and_n structure
866 *
867 * tupple of td and n for RkGetWordTextDic()
868 */
869struct td_n_tupple {
870  char               *td; /* in fact this type is (struct TD *) */
871  int                n;
872  struct td_n_tupple *next;
873};
874
875/* jishowo 1gyouzutu yomu tokino pointer :used in RkGetWordTextDic */
876typedef struct _rec {
877    int                 gwt_cx;
878    unsigned char       *gwt_dicname;
879    struct td_n_tupple  *tdn;
880} GWT;
881
882/* flag values */
883#define	CTX_LIVE		1	/* allocate sareta */
884#define	CTX_XFER		2	/* bunsetu henkann chuu */
885#define	CTX_XAUT		4	/* jidou henkan chuu */
886#define	CTX_XFSH	      010
887#define	CTX_NODIC	      020	/* have never tried to mount dic */
888
889#define	MAX_CONTEXT		256
890#define	INIT_CONTEXT		32
891#define	ADD_CONTEXT		32
892
893#ifndef SYSTEM_DDHOME_NAME
894#define SYSTEM_DDHOME_NAME	"canna"
895#endif
896
897#define USER_DIC_DIR		"user"
898#define GROUP_DIC_DIR		"group"
899
900#define	IS_LIVECTX(cx)	((cx)->flags & CTX_LIVE)
901#define IS_XFERCTX(cx)	(IS_LIVECTX(cx) && ((cx)->flags & CTX_XFER))
902#define IS_XAUTCTX(cx)	(IS_LIVECTX(cx) && ((cx)->flags & CTX_XAUT))
903#define RK_CONNECT_WORD	0x01
904#define	IsCxNum(cn) (0<=((unsigned long)cn)&&((unsigned long)cn)<now_context)
905#define	IsLiveCxNum(cn) (IsCxNum(cn) && IS_LIVECTX(&CX[cn]))
906#define	IsXferCxNum(cn) (IsLiveCxNum(cn) && IS_XFERCTX(&CX[cn]))
907#define Is_Word_Connect(cx)\
908    ((cx) && (((cx)->concmode & RK_CONNECT_WORD) == RK_CONNECT_WORD))
909#define Is_Word_Make(cx)\
910    ((cx) && (((cx)->concmode & RK_MAKE_WORD) == RK_MAKE_WORD))
911
912
913/* RkDST
914 *	dictionary switch table
915 */
916struct RkDST {
917  int (*d_open) /* jisho ga open sareta toki */
918    (struct DM *, char *, int, struct RkKxGram *);
919  int (*d_close) /* jisho ga close sareta toki */
920    (struct DM *, char *, struct RkKxGram *);
921  int (*d_search) /* jisho kara tango wo search suru */
922    (struct RkContext *, struct DM *, WCHAR_T *,
923	 int, struct nread *, int, int *);
924  int (*d_io) /* jisho he tango to cache no io */
925    (struct DM *, struct ncache *, int);
926  int (*d_ctl)	/* jisho koyuuno sousa */
927    (struct DM *, struct DM *, int, WCHAR_T *, struct RkKxGram *);
928  int (*d_sync) /* jisho sync suru */
929    (struct RkContext *, struct DM *, struct DM *);
930};
931extern struct RkDST	_RkDST[];
932
933#define	_RkEnrefCache(a)	((a)->nc_count++)
934#define	DST_PROC(dm)		_RkDST[DM2TYPE(dm)]
935#define	DST_OPEN(dm, file, mode, gram)\
936	(DST_PROC(dm).d_open)(dm, file, mode, gram)
937#define	DST_CLOSE(dm, file, gram)	(DST_PROC(dm).d_close)(dm, file, gram)
938#define	DST_SEARCH(cx, dm, k, n, cp, max, cf)\
939	(DST_PROC(dm).d_search)(cx, dm, k, n, cp, max, cf)
940#define	DST_IO(dm, cp, io)	(DST_PROC(dm).d_io)(dm, cp, io)
941#define	DST_READ(dm, cp)	DST_IO(dm, cp, 0)
942#define	DST_WRITE(dm, cp)	DST_IO(dm, cp, 1)
943#define	DST_CTL(dm, qm, what, arg, gram)\
944	(DST_PROC(dm).d_ctl)(dm, qm, what, arg, gram)
945#define	DST_SYNC(cx, dm, qm)	(DST_PROC(dm).d_sync)(cx, dm, qm)
946
947/* ctl command */
948#define DST_DoDefine		0	/* define words */
949#define DST_DoDelete		1	/* delete words */
950/* more commands (not implemented) */
951#define DST_DoQuery		2	/* query on the dictionary info */
952
953#define DST_DoPrint		9999	/* print debug information */
954
955/* Internal Functions */
956struct RkParam		*RkGetSystem();
957struct DD			*RkGetSystemDD();
958struct DD			*RkGetUserDD();
959struct RkContext	*RkGetContext(int cx_num);
960struct RkContext	*RkGetXContext(int cx_num);
961
962struct RkKxGram		*RkReadGram(int fd);
963struct RkKxGram		*RkOpenGram(char *mydic);
964struct RkKxGram		*RkDuplicateGram(struct RkKxGram *ogram);
965void				RkCloseGram(struct RkKxGram *gram);
966
967int					_RkInitializeCache(int size);
968void				_RkFinalizeCache(void);
969struct ncache 		*_RkFindCache(struct DM *dm, long addr);
970struct ncache 		*_RkReadCache(struct DM *dm, long addr);
971void 				_RkFreeCache();
972void 				_RkDerefCache(struct ncache *cache);
973void 				_RkPurgeCache(struct ncache *cache);
974void 				_RkKillCache(struct DM *dm);
975
976int 				_RkRenbun2(struct RkContext *cx, int firstlen);
977void 				_RkLearnBun(struct RkContext *cx, int cur, int mode);
978
979int 				RkScanWcand(Wrec *wrec, struct RkWcand *word, int maxword);
980int 				RkUniqWcand(struct RkWcand *wc, int nwc);
981int 				RkUnionWcand(struct RkWcand *wc1, int nc1, int wlen1, struct RkWcand *wc2, int nc2);
982int 				RkSubtractWcand(struct RkWcand *wc1, int nc1, struct RkWcand *wc2, int nc2, unsigned long *lucks);
983
984unsigned char 		*RkGetGramName(struct RkKxGram *gram, int row);
985int 				RkGetGramNum(struct RkKxGram *gram, char *name);
986WCHAR_T 			*RkUparseWrec();
987WCHAR_T 			*_RkUparseWrec(struct RkKxGram *gram, Wrec *src, WCHAR_T *dst, int maxdst, unsigned long *lucks, int add);
988Wrec 				*RkParseWrec(struct RkKxGram *gram, WCHAR_T *src, unsigned left, unsigned char *dst, unsigned maxdst);
989Wrec 				*RkParseOWrec(struct RkKxGram *gram, WCHAR_T *src, unsigned char *dst, unsigned maxdst, unsigned long *lucks);
990WCHAR_T 			*RkUparseGramNum(struct RkKxGram *gram, int row, WCHAR_T *dst, int maxdst);
991WCHAR_T 			*RkParseGramNum(struct RkKxGram *gram, WCHAR_T *src, int *row);
992
993/* Context */
994void 				_RkEndBun(struct RkContext *cx);
995void 				freeDF();
996
997int 				_RkCandNumber(unsigned char *wrec);
998int 				_RkWordLength(unsigned char *wrec);
999int 				_RkCalcLog2(int n);
1000int 				_RkCalcUnlog2(int x);
1001
1002/* etc. */
1003
1004
1005/* lang dep part */
1006#define IS_WC_G1_HYPHEN(wc)	((wc) == 0xa1bc)
1007#define IS_HYPHEN(wc)		(IS_WC_G1_HYPHEN(wc) || ((wc) == '-'))
1008/* space ¤â¸õÊä¤È¤·¤Æ»È¤¤¤¿¤¤¤¬º£¤Î½ê¤Ï space */
1009#define IS_DIC_PUNCT(euc)	isspace(euc)
1010
1011int				_RkRealizeDF();
1012
1013struct DM		*_RkSearchDDQ(struct DD	**dd, char *name, int type);
1014struct DM		*_RkSearchDDP(struct DD	**ddp, char	*name);
1015struct DM		*_RkSearchUDDP(struct DD **ddp, unsigned char *name);
1016struct DM		*_RkSearchDDMEM(struct DD **ddp, char *name);
1017
1018int				_RkIsinDDP();
1019struct DD		** _RkCopyDDP(struct DD	**ddp);
1020struct DD		**_RkCreateDDP(char		*ddpath);
1021void 			_RkFreeDDP(struct DD	**ddp);
1022
1023struct DM		*DMcreate(struct DD		*dd,char		*spec);
1024int 			DMremove(struct DM	*dm);
1025int 			DMrename(struct DM		*dm,unsigned char	*nickname);
1026
1027int 			_RkMountMD(struct RkContext	*cx,struct DM		*dm,struct DM		*qm,int		mode,int		firsttime);
1028void			_RkUmountMD( struct RkContext	*cx, struct MD		*md);
1029
1030char 			*_RkCreatePath(struct DD *dd, char *name);
1031char 			*_RkCreateUniquePath(struct DD *dd, char *proto);
1032char 			*_RkMakePath(struct DF *df);
1033
1034unsigned char	*_RkCreateHeader(struct HD *hd, unsigned *size);
1035int 			_RkReadHeader(int fd, struct HD *hd, off_t off_from_top);
1036void 			_RkClearHeader(struct HD *hd);
1037void 			_RkRehashCache(struct ncache *cache, long addr);
1038
1039/*
1040 * limits
1041 */
1042/*
1043 *   NOTE: The following number does not includes EOS at the end of string.
1044 *	RK_PATH_BMAX	maximum path name length
1045 *	RK_LINK_BMAX	maximum file name length
1046 *	RK_MEMBER_BMAX	maximum member name length
1047 *	RK_NICK_BMAX	maximum nickname length
1048 */
1049#ifdef PATH_MAX
1050#define	RK_PATH_BMAX	PATH_MAX
1051#else
1052#define RK_PATH_BMAX 1024
1053#endif
1054#ifdef  NAME_MAX
1055#define RK_LINK_BMAX	NAME_MAX
1056#else
1057#ifdef	MAXNAMLEN
1058#define RK_LINK_BMAX	MAXNAMLEN
1059#else
1060#define RK_LINK_BMAX	14
1061#endif
1062#endif
1063#define	RK_MEMBER_BMAX	255
1064#define	RK_NICK_BMAX	255
1065
1066#define RK_LINE_BMAX    1024
1067#define RK_BUFFER_SIZE  1024
1068
1069/*
1070 * RK_KEY_WMAX <= RK_LEN_WMAX
1071 */
1072#define	RK_KEY_WMAX		0x7f
1073#define	RK_LEFT_KEY_WMAX	0x3f
1074const unsigned long 	RK_LEN_WMAX=0x7f;
1075/*
1076 * RK_CAND_WMAX <= RK_LEN_WMAX
1077 */
1078/* ¸õÊä¿ô */
1079#define	NW_MAXCAND	0x07	/* 7 */
1080#define	EX_NW_MAXCAND	0xfff	/* 4096 */
1081
1082/* ¸õÊäĹ */
1083#define	NW_MAXCANDLEN	0x7f
1084#define RK_CAND_WMAX	0x7f
1085#define RK_CAND_NMAX    0xfff /* 4095 */
1086
1087/* wrec len */
1088#define NW_MAXWREC	0x3f	/* 63 */
1089#define EX_NW_MAXWREC	0x1fff	/* 8191 */
1090
1091#define RK_RCNAME_BMAX	16	/* essential ?! */
1092
1093#define	RK_DIV_NMAX	2048
1094#define	RK_WREC_BMAX	EX_NW_MAXWREC
1095#define	RK_MAX_TEXT_LEN	MAX_WREC_BMAX
1096
1097#define	RK_CONC_NMAX	16	/* Àܳ¤¹¤ëÉÕ°¸ì¤Î¿ô(¸ú¤¤¤Æ¤ë¤Î¤«¤Ê¡©) */
1098
1099#define RK_MAX_HDRSIZ	1024
1100
1101
1102/* bits.c */
1103long _RkPackBits(unsigned char *dst_bits, long dst_offset, int bit_size, unsigned *src_ints, int count);
1104long _RkUnpackBits(unsigned *dst_ints, unsigned char *src_bits, long src_offset, int bit_size, int count);
1105long _RkCopyBits(unsigned char *dst_bits, long dst_offset, int bit_size, unsigned char *src_bits, long src_offset, int count);
1106int _RkSetBitNum(unsigned char *dst_bits, unsigned long dst_offset, int bit_size, int n, int val);
1107int _RkCalcFqSize(int n);
1108int _RkPrintPackedBits(unsigned char *bits, int offset, int bit_size, int count);
1109
1110/* bun.c */
1111struct nstore *_RkReallocBunStorage(struct nstore *src, unsigned len);
1112int RkeResize (int cx_num, int len);
1113int RkeGetStat (int cx_num, RkStat *st);
1114int RkeGetLex (int cx_num, RkLex *dst, int maxdst);
1115int RkwStoreRange(int cx_num, WCHAR_T *yomi, int maxyomi);
1116int RkwSetLocale(int cx_num, unsigned char *locale);
1117
1118int _RkResize(int cx_num, int len, int t);
1119int _RkwSync(struct RkContext *cx, char *dicname);
1120
1121/* context.c */
1122struct RkParam *RkGetSystem(void);
1123struct DD *RkGetSystemDD(void);
1124struct RkContext *RkGetContext(int cx_num);
1125struct RkContext *RkGetXContext(int cx_num);
1126int RkwSetAppName(int Context, char *name);
1127int RkwGetProtocolVersion(int *majorp, int *minorp);
1128
1129/* dd.c */
1130int DMcheck(char *spec, char *name);
1131int DMchmod(struct DM *dm, int mode);
1132int DDchmod(struct DD *dd, int mode);
1133
1134int _RkRealizeDF(struct DF *df);
1135int _RkRealizeDD(struct DD	*dd);
1136struct DM *_RkSearchDicWithFreq (struct DD **, char *, struct DM **);
1137int _RkIsInDDP(struct DD	**ddp, struct DD	*dd);
1138
1139/* dic.c */
1140int copyFile(struct DM *src, struct DM *dst);
1141void freeTdn(struct RkContext *cx);
1142
1143/* fq.c */
1144struct RUT *allocRUT(unsigned long hn);
1145unsigned long searchRut(struct RUT *ruc, unsigned long csn);
1146int entryRut(struct RUT *ruc, unsigned long csn, unsigned long tick);
1147struct RUT *LoadRUC(int fr);
1148int FQopen(struct DM *dm, struct DM *qm, char *file, int mode);
1149void FQclose(struct RkContext *cx, struct DM *dm, struct DM *qm, char *file);
1150int FQsync(struct RkContext *cx, struct DM *dm, struct DM *qm, char *file);
1151
1152/* ncache.c */
1153int _RkRelease(void);
1154
1155/* ngram.c */
1156int RkGetGramNum(struct RkKxGram *gram, char *name);
1157unsigned char *RkGetGramName(struct RkKxGram *gram, int row);
1158WCHAR_T *RkUparseWrec(struct RkKxGram *gram, Wrec *src, WCHAR_T *dst, int maxdst, unsigned long *lucks);
1159struct TW *RkCopyWrec(struct TW *src);
1160struct TW *RkSubtractWrec(struct TW *tw1, struct TW *tw2);
1161struct TW *RkUnionWrec(struct TW *tw1, struct TW *tw2);
1162
1163int _RkRowNumber(unsigned char *wrec);
1164
1165/* nword.c */
1166void _RkFreeBunq(struct nstore *st);
1167void _RkFreeQue(struct nstore *st, int s, int e);
1168int _RkRegisterNV(struct NV *nv, Wrec *yomi, int len, int half);
1169WCHAR_T *_RkGetKanji(struct nword *cw, WCHAR_T *key, unsigned long mode);
1170int _RkSubstYomi(struct RkContext *cx, int ys, int ye, WCHAR_T *yomi, int newLen);
1171int _RkFlushYomi(struct RkContext *cx);
1172
1173/* permdic.c */
1174int _Rkpopen(struct DM *dm, char *dfnm, int mode, struct RkKxGram *gram);
1175int _Rkpclose(struct DM *dm, char *dfnm, struct RkKxGram *gram);
1176int _RkEql(WCHAR_T *a, unsigned char *b, int n);
1177int _Rkpsearch(struct RkContext *cx, struct DM *dm, WCHAR_T *key, int n, struct nread *nread, int mc, int *cf);
1178int _Rkpio(struct DM *dm, struct ncache *cp, int io);
1179int _Rkpctl(struct DM *dm, struct DM *qm, int what, WCHAR_T *arg, struct RkKxGram *gram);
1180int _Rkpsync(struct RkContext *cx, struct DM *dm, struct DM *qm);
1181int _Rktopen(struct DM	*dm,char	*file,int	mode,struct RkKxGram	*gram);
1182int	 _Rktclose(struct DM	*dm,char	*file,struct RkKxGram	*gram);
1183int _Rktsearch(struct RkContext	*cx,struct DM		*dm,WCHAR_T		*key,int		n,struct nread	*nread,int		maxcache,int		*cf);
1184int	 _Rktio( struct DM		*dm,struct ncache	*cp,int		io);
1185int _Rktctl(struct DM	*dm,struct DM	*qm,int	what,WCHAR_T	*arg,struct RkKxGram	*gram);
1186int _Rktsync(struct RkContext *cx, struct DM	*dm, struct DM	 *qm);
1187
1188/* util.c */
1189int uslen(WCHAR_T *us);
1190void usncopy(WCHAR_T *dst, WCHAR_T *src, int len);
1191unsigned char *ustoeuc(WCHAR_T *src, int srclen, unsigned char *dest, int destlen);
1192WCHAR_T *euctous(unsigned char *src, int srclen, WCHAR_T *dest, int destlen);
1193void _Rkpanic(char *fmt, int p, int q, int r);
1194WCHAR_T uniqAlnum(WCHAR_T c);
1195int set_hdr_var(struct HD *hd, int n, unsigned long var);
1196int HowManyChars(WCHAR_T *yomi, int len);
1197int HowManyBytes(WCHAR_T *yomi, int len);
1198int printWord(struct nword *w);
1199int showWord(struct nword *w);
1200
1201int _RkCalcLog2(int n);
1202unsigned char *_RkCreateHeader(struct HD *hd, unsigned *size);
1203unsigned long _RkGetTick(int mode);
1204int _RkGetLink(struct ND *dic, long pgno, unsigned long off, unsigned long *lvo, unsigned long *csn);
1205unsigned long _RkGetOffset(struct ND *dic, unsigned char *pos);
1206#endif /* _RKintern_h */
1207/* don't add stuff after this line */
1208