Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00045 #ifndef __BIN_MDEF_H__
00046 #define __BIN_MDEF_H__
00047
00048 #ifdef __cplusplus
00049 extern "C" {
00050 #if 0
00051 };
00052 #endif
00053 #endif
00054
00055
00056 #include <mmio.h>
00057 #include <cmd_ln.h>
00058
00059 #include "mdef.h"
00060
00061 #define BIN_MDEF_FORMAT_VERSION 1
00062
00063 #define BIN_MDEF_NATIVE_ENDIAN 0x46444d42
00064 #define BIN_MDEF_OTHER_ENDIAN 0x424d4446
00065 #ifdef __GNUC__
00066 #define ATTRIBUTE_PACKED __attribute__((packed))
00067 #else
00068 #define ATTRIBUTE_PACKED
00069 #endif
00070
00074 typedef struct mdef_entry_s mdef_entry_t;
00075 struct mdef_entry_s {
00076 int32 ssid;
00077 int32 tmat;
00078
00079 union {
00081 struct {
00082 int8 filler;
00083 int8 reserved[3];
00084 } ci;
00086 struct {
00087 int8 wpos;
00088 int8 ctx[3];
00089 } cd;
00090 } info;
00091 } ATTRIBUTE_PACKED;
00092
00096 #define BAD_SSID 0xffff
00097
00100 #define BAD_SENID 0xffff
00101
00105 typedef struct cd_tree_s cd_tree_t;
00106 struct cd_tree_s {
00107 int16 ctx;
00108 int16 n_down;
00109 union {
00110 int32 pid;
00111 int32 down;
00112 } c;
00113 };
00114
00118 typedef struct bin_mdef_s bin_mdef_t;
00119 struct bin_mdef_s {
00120 int refcnt;
00121 int32 n_ciphone;
00122 int32 n_phone;
00123 int32 n_emit_state;
00124 int32 n_ci_sen;
00125 int32 n_sen;
00126 int32 n_tmat;
00127 int32 n_sseq;
00128 int32 n_ctx;
00129 int32 n_cd_tree;
00130 int16 sil;
00132 mmio_file_t *filemap;
00133 char **ciname;
00134 cd_tree_t *cd_tree;
00135 mdef_entry_t *phone;
00136 uint16 **sseq;
00137 uint8 *sseq_len;
00139
00140 int16 *cd2cisen;
00141 int16 *sen2cimap;
00144 enum { BIN_MDEF_FROM_TEXT, BIN_MDEF_IN_MEMORY, BIN_MDEF_ON_DISK } alloc_mode;
00145 };
00146
00147 #define bin_mdef_is_fillerphone(m,p) (((p) < (m)->n_ciphone) \
00148 ? (m)->phone[p].info.ci.filler \
00149 : (m)->phone[(m)->phone[p].info.cd.ctx[0]].info.ci.filler)
00150 #define bin_mdef_is_ciphone(m,p) ((p) < (m)->n_ciphone)
00151 #define bin_mdef_n_ciphone(m) ((m)->n_ciphone)
00152 #define bin_mdef_n_phone(m) ((m)->n_phone)
00153 #define bin_mdef_n_sseq(m) ((m)->n_sseq)
00154 #define bin_mdef_n_emit_state(m) ((m)->n_emit_state)
00155 #define bin_mdef_n_emit_state_phone(m,p) ((m)->n_emit_state ? (m)->n_emit_state \
00156 : (m)->sseq_len[(m)->phone[p].ssid])
00157 #define bin_mdef_n_sen(m) ((m)->n_sen)
00158 #define bin_mdef_n_tmat(m) ((m)->n_tmat)
00159 #define bin_mdef_pid2ssid(m,p) ((m)->phone[p].ssid)
00160 #define bin_mdef_pid2tmatid(m,p) ((m)->phone[p].tmat)
00161 #define bin_mdef_silphone(m) ((m)->sil)
00162 #define bin_mdef_sen2cimap(m,s) ((m)->sen2cimap[s])
00163 #define bin_mdef_sseq2sen(m,ss,pos) ((m)->sseq[ss][pos])
00164 #define bin_mdef_pid2ci(m,p) (((p) < (m)->n_ciphone) ? (p) \
00165 : (m)->phone[p].info.cd.ctx[0])
00166
00170 bin_mdef_t *bin_mdef_read(cmd_ln_t *config, const char *filename);
00174 bin_mdef_t *bin_mdef_read_text(cmd_ln_t *config, const char *filename);
00178 int bin_mdef_write(bin_mdef_t *m, const char *filename);
00182 int bin_mdef_write_text(bin_mdef_t *m, const char *filename);
00186 bin_mdef_t *bin_mdef_retain(bin_mdef_t *m);
00190 int bin_mdef_free(bin_mdef_t *m);
00191
00196 int bin_mdef_ciphone_id(bin_mdef_t *m,
00197 const char *ciphone);
00203 int bin_mdef_ciphone_id_nocase(bin_mdef_t *m,
00204 const char *ciphone);
00206
00207 const char *bin_mdef_ciphone_str(bin_mdef_t *m,
00208 int32 ci);
00210
00211 int bin_mdef_phone_id(bin_mdef_t *m,
00212 int32 b,
00213 int32 l,
00214 int32 r,
00215 int32 pos);
00217
00218 int bin_mdef_phone_id_nearest(bin_mdef_t * m, int32 b,
00219 int32 l, int32 r, int32 pos);
00220
00226 int bin_mdef_phone_str(bin_mdef_t *m,
00227 int pid,
00228 char *buf);
00230 #ifdef __cplusplus
00231 };
00232 #endif
00233
00234 #endif