/*  esecannaserver --- pseudo canna server that wraps another IME.
 *  Copyright (C) 1999-2000 Yasuhiro Take
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef __vje_h__
#define __vje_h__

#define ESECANNA_MODULE_VERSION "VJE-Delta 2.5 0.14.6"

#define MAX_BUNSETU_NUM 80
#define MAX_CHAR_NUM 80
#define MAX_DOUONGO_NUM 768

#define DIC_NAME_SIZE 256
#define DIC_BUF_SIZE 1024
#define DIC_YOMI_BUF_SIZE 32
#define DIC_TANGO_BUF_SIZE 32

#define IN_BUF_SIZE (MAX_CHAR_NUM * 2 + 2)
#define HIRA_BUF_SIZE (MAX_CHAR_NUM * 2 + 3)
#define KEY_BUF_SIZE (MAX_CHAR_NUM * 2 + 1)
#define YOMI_BUF_SIZE (DIC_YOMI_BUF_SIZE * 2 + 2)
#define HYOUKI_BUF_SIZE (DIC_TANGO_BUF_SIZE * 2)

#define SELECT_LEN 7168
#define FRAME_LEN 500

#define LEN_OF_OLDBUF(_buf) _buf[0]

typedef struct {
  uchar max_blk;
  uchar blk_cnt;
  ushort max_koho;
  ushort koho_cnt;
  uchar yomi_pnt;
  uchar yomi_len;
  uchar hyk_pnt;
  uchar hyk_len;
  ushort flg;
} vje_kouho25_t;

typedef struct {
  short error;
  short total_yomi;
  short max_bun;
  short bun_cnt;
  vje_kouho25_t kouho[MAX_BUNSETU_NUM];
} buninf25_t;

typedef struct {
  short cnt;
  short len;
  uchar buf[DIC_BUF_SIZE * 4];
  ushort flg[MAX_DOUONGO_NUM];
} doubufx_t;

/*
 * vje_send_*_t vje_recv_*_t ¤ÎÄêµÁ
 */


typedef struct {
  short funcno;
  short vje_id;
} vje_send_any_t;

typedef struct {
  short retvalue;
} vje_recv_any_t;

/* clear */
/* setmode */
typedef struct {
  short funcno;
  short vje_id;
  short cnvmode1;
  short cnvmode2;
  short rank;
  short loopcnt;
} vje_send_setmode_t;

/* sensemode */
typedef struct {
  short retvalue;
  short cnvmode1;
  short cnvmode2;
  short rank;
  short loopcnt;
} vje_recv_sensemode_t;

/* henkanb */
typedef struct {
  short funcno;
  short vje_id;
  short mode;
  short cnvted;
  uchar in_buf[IN_BUF_SIZE];
  uchar atrbuf[IN_BUF_SIZE * 2];
  uchar keybuf[IN_BUF_SIZE];
} vje_send_henkanb25_t;

typedef struct {
  short retvalue;
  uchar in_buf[IN_BUF_SIZE];
  uchar atrbuf[IN_BUF_SIZE * 2];
  uchar keybuf[IN_BUF_SIZE];
} vje_recv_henkanb25_t;

/* get_koho_all */
typedef struct {
  short funcno;
  short vje_id;
  uchar buninf[sizeof(buninf25_t)];
  uchar buf[IN_BUF_SIZE];
} vje_send_get_koho_all25_t;

typedef struct {
  short retvalue;
  uchar buninf[sizeof(buninf25_t)];
  uchar buf[IN_BUF_SIZE];
} vje_recv_get_koho_all25_t;

/* ji_bunsetu */
/* zen_bunsetu */
/* set_koho_bno */
typedef struct {
  short funcno;
  short vje_id;
  short bno;
} vje_send_set_koho_bno_t;

/* get_koho_bno */
typedef struct {
  short bno;
} vje_recv_get_koho_bno_t;

/* ji_block */
/* zen_block */
/* set_koho */
typedef struct {
  short funcno;
  short vje_id;
  short p;
} vje_send_set_koho_t;

/* get_douon_t */
typedef struct {
  short funcno;
  short vje_id;
  uchar doubufx[sizeof(doubufx_t)];
} vje_send_get_douon_t;

typedef struct {
  uchar doubufx[sizeof(doubufx_t)];
} vje_recv_get_douon_t;

/* saihenkan */
typedef struct {
  short funcno;
  short vje_id;
  uchar in_buf[IN_BUF_SIZE];
  short nbun;
  short len2;
  short len;
  short mode;
} vje_send_saihenkan25_t;

typedef struct {
  short retvalue;
  uchar in_buf[IN_BUF_SIZE];
} vje_recv_saihenkan25_t;

/* kakutei1 */
typedef struct {
  short funcno;
  short vje_id;
  uchar hira_buf[HIRA_BUF_SIZE];
  uchar key_buf[KEY_BUF_SIZE];
} vje_send_kakutei1_25_t;

typedef struct {
  short retvalue;
  uchar hira_buf[HIRA_BUF_SIZE];
  uchar key_buf[KEY_BUF_SIZE];
} vje_recv_kakutei1_25_t;

/* get_koho2 */
typedef struct {
  short funcno;
  short vje_id;
  uchar yomi[YOMI_BUF_SIZE];
  uchar hyouki[HYOUKI_BUF_SIZE];
} vje_send_get_koho2_t;
  
typedef struct {
  short retvalue;
  uchar yomi[YOMI_BUF_SIZE];
  uchar hyouki[HYOUKI_BUF_SIZE];
} vje_recv_get_koho2_t;

/* vjelibopen */
/* vjelibclose */
/* open_sdic */
typedef struct {
  short funcno;
  short vje_id;
  short dic_id;
  short mode;
  uchar dicname[DIC_NAME_SIZE];
} vje_send_open_sdic_t;

/* close_sdic */
typedef struct {
  short funcno;
  short vje_id;
  short dic_id;
} vje_send_close_sdic_t;

/* chg_sdic */
typedef struct {
  short funcno;
  short vje_id;
  short dic_id;
} vje_send_chg_sdic_t;

/* set_clienthostname */
typedef struct {
  short funcno;
  uchar hostname[128 + 2];
} vje_send_set_clienthostname_t;

typedef struct {
  short funcno;
  short vje_id;
  uchar in_buf[IN_BUF_SIZE];
  uchar atrbuf[IN_BUF_SIZE * 2];
  uchar keybuf[IN_BUF_SIZE];
} vje_send_set_kihonbuff25_t;

typedef union {
  uchar byte[SELECT_LEN];
  vje_send_any_t s_any;
  vje_recv_any_t r_any;
  vje_send_setmode_t s_setmode;
  vje_recv_sensemode_t r_sensemode;
  vje_send_henkanb25_t s_henkanb25;
  vje_recv_henkanb25_t r_henkanb25;
  vje_send_get_koho_all25_t s_get_koho_all25;
  vje_recv_get_koho_all25_t r_get_koho_all25;
  vje_send_set_koho_bno_t s_set_koho_bno;
  vje_recv_get_koho_bno_t r_get_koho_bno;
  vje_send_set_koho_t s_set_koho;
  vje_send_get_douon_t s_get_douon;
  vje_recv_get_douon_t r_get_douon;
  vje_send_saihenkan25_t s_saihenkan25;
  vje_recv_saihenkan25_t r_saihenkan25;
  vje_send_kakutei1_25_t s_kakutei1_25;
  vje_recv_kakutei1_25_t r_kakutei1_25;
  vje_send_get_koho2_t s_get_koho2;
  vje_recv_get_koho2_t r_get_koho2;
  vje_send_open_sdic_t s_open_sdic;
  vje_send_close_sdic_t s_close_sdic;
  vje_send_chg_sdic_t s_chg_sdic;
  vje_send_set_clienthostname_t s_set_clienthostname;
  vje_send_set_kihonbuff25_t s_set_kihonbuff25;
} vje_request_t;

void vje_proto_clear(short vje_id);
void vje_proto_setmode(short vje_id, short cnvmode1,
		       short cnvmode2, short rank, short loop_cnt);
int vje_proto_sensemode(short vje_id, short *cnvmode1, short *cnvmode2,
			short *rank, short *loop_cnt);
int vje_proto25_henkanb(short vje_id, uchar *in_buf,
			ushort *atr_buf, uchar *key_buf, short *mode,
			short cnvted);
int vje_proto_toku_henkan();
int vje_proto25_get_koho_all(short vje_id, buninf25_t *buninf, uchar *buf);
int vje_proto_ji_bunsetu(short vje_id);
int vje_proto_zen_bunsetu(short vje_id);
void vje_proto_set_koho_bno(short vje_fd, short bno);
short vje_proto_get_koho_bno(short vje_id);
short vje_proto_ji_block(short vje_id);
short vje_proto_zen_block(short vje_id);
void vje_proto_set_koho(short vje_id, short p);
void vje_proto_get_douon(short vje_id, doubufx_t *douon);
short vje_proto25_saihenkan(short vje_id, uchar *in_buf,
			    short nbun, short len2, short len, short mode);
short vje_proto25_kakutei1(short vje_id, uchar *hira_buf,
			   uchar *key_buf);
short vje_proto25_kakutei2(short vje_id, uchar *hira_buf, uchar *key_buf);
void vje_proto_finish_session();
short vje_proto_get_koho2(short vje_id, uchar *yomi, uchar *hyouki);
short vje_proto_vjelibopen();
short vje_proto_vjelibclose(short vje_id);
short vje_proto_open_sdic(short vje_id, short dic_id, uchar *dicname,
			  short mode);
short vje_proto_close_sdic(short vje_id, short dic_id);
short vje_proto_chg_sdic(short vje_id, short dic_id);
void vje_proto_loadcoderange();
int vje_proto_set_clienthostname(char *name);
void vje_proto25_set_kihonbuff(short vje_id, uchar *in_buf, ushort *atrbuf,
			       uchar *keybuf);

#endif
