
#ifndef _CIN2TAB_H_
#define _CIN2TAB_H_

#define SUPPORT_ASSOCIATE

#define LINE_BUFFER_LEN 2048

#define SYSCODE_NOCHECK 0

#define SYSPH_MAP_STR       "%sysphrase"
#define USRPH_MAP_STR       "%usrphrase"
#define ENCODING_STR        "%encoding"
#define FORMAT_STR          "%format"

#define MSMB_DESC_STR	"[Description]"
#define MSMB_RULE_STR	"[Rule]"
#define MSMB_TEXT_STR	"[Text]"

#define CIN_KEYNAME_STR "%keyname"
#define CIN_CHARDEF_STR "%chardef"

#define MAX_ZHUYIN_NUMBER		9

#define PTR_CONTINUE 	NULL
#define PTR_BREAK 		((u_char*)-1)

extern int SysCoding;
extern char LineBuf[];
extern int lineno;
extern u_char *cmd, *arg;

#define PINYIN_FORMAT	1
#define ZHUYIN_FORMAT	2
extern int OldCoding; /* source encoding */
extern int NewCoding; /* target encoding  */
extern int YinFormat; /* 1 pinyin or 2 zhuyin(libtabe format) */

extern char CurCINPath[];

extern int gen_lx; /* generate lx file */
extern int charonly; /* for big5, put lots of single chars together, like cxterm's tit */

extern void print_error(char *fmt,...);
extern void get_line(FILE *fr, u_char *buf);
extern u_char *to_space(u_char *s);
extern u_char *skip_space(u_char *s);
extern void cmd_arg(FILE *fr, u_char *s, u_char **cmd, u_char **arg);

extern int identify_encoding(u_char *arg);
extern int VerifyMapping(char *key, char *str, int len);

extern void read_cin_options(FILE *fr, hz_input_table *table);
extern void read_cin_keyname(FILE *fr, hz_input_table *table);
extern void read_msmb_format(FILE *fr, hz_input_table *table);

extern u_char *FilterFormatOptions(u_char *p, u_char *str);
extern u_char *FilterFormatCharFreq(u_char *p, u_char *str, u_char **cp, int *lenp, int *freqp, int freqbytes);
extern int LoadFileSection( u_char *cmd, u_char *arg, u_char *section,
		        FILE *fr, int (*LoadFunc)(FILE *));

extern int ConvertGBPhraseFormat(int mode, char *filename);

int convert_to_zhuyins(int format, u_char *p, u_short yin[][MAX_ZHUYIN_NUMBER], int len);

extern int ConvertPinyinCIN(FILE *fr, hz_input_table *table, char *filename );
extern int ConvertZhuyinCIN(FILE *fr, hz_input_table *table, char *filename );
extern int  ConvertTableCIN(FILE *fr, hz_input_table *table, char *cinfname, 
		char *tabfname, char *lxfname );
extern int GenerateAssociateFile(FILE *fr, int gen_lx, char *fname);

extern PinYin PYMap[26][];
extern u_short ZYToPYMap[];

#endif
