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 <mdef.h>
00057 #include <mmio.h>
00058 #include <cmd_ln.h>
00059
00060 #define BIN_MDEF_FORMAT_VERSION 1
00061
00062 #define BIN_MDEF_NATIVE_ENDIAN 0x46444d42
00063 #define BIN_MDEF_OTHER_ENDIAN 0x424d4446
00064 #ifdef __GNUC__
00065 #define ATTRIBUTE_PACKED __attribute__((packed))
00066 #else
00067 #define ATTRIBUTE_PACKED
00068 #endif
00069
00073 typedef struct mdef_entry_s mdef_entry_t;
00074 struct mdef_entry_s {
00075 int32 ssid;
00076 int32 tmat;
00077
00078 union {
00080 struct {
00081 uint8 filler;
00082 uint8 reserved[3];
00083 } ci;
00085 struct {
00086 uint8 wpos;
00087 uint8 ctx[3];
00088 } cd;
00089 } info;
00090 } ATTRIBUTE_PACKED;
00091
00095 typedef struct cd_tree_s cd_tree_t;
00096 struct cd_tree_s {
00097 int16 ctx;
00098 int16 n_down;
00099 union {
00100 int32 pid;
00101 int32 down;
00102 } c;
00103 };
00104
00108 typedef struct bin_mdef_s bin_mdef_t;
00109 struct bin_mdef_s {
00110 int32 n_ciphone;
00111 int32 n_phone;
00112 int32 n_emit_state;
00113 int32 n_ci_sen;
00114 int32 n_sen;
00115 int32 n_tmat;
00116 int32 n_sseq;
00117 int32 n_ctx;
00118 int32 n_cd_tree;
00119 int16 sil;
00121 mmio_file_t *filemap;
00122 char **ciname;
00123 cd_tree_t *cd_tree;
00124 mdef_entry_t *phone;
00125 int16 **sseq;
00126 uint8 *sseq_len;
00128
00129 int16 *cd2cisen;
00130 int16 *sen2cimap;
00133 enum { BIN_MDEF_FROM_TEXT, BIN_MDEF_IN_MEMORY, BIN_MDEF_ON_DISK } alloc_mode;
00134 };
00135
00136 #define bin_mdef_is_fillerphone(m,p) (((p) < (m)->n_ciphone) \
00137 ? (m)->phone[p].info.ci.filler \
00138 : (m)->phone[(m)->phone[p].info.cd.ctx[0]].info.ci.filler)
00139 #define bin_mdef_is_ciphone(m,p) ((p) < (m)->n_ciphone)
00140 #define bin_mdef_n_ciphone(m) ((m)->n_ciphone)
00141 #define bin_mdef_n_phone(m) ((m)->n_phone)
00142 #define bin_mdef_n_sseq(m) ((m)->n_sseq)
00143 #define bin_mdef_n_emit_state(m) ((m)->n_emit_state)
00144 #define bin_mdef_n_emit_state_phone(m,p) ((m)->n_emit_state ? (m)->n_emit_state \
00145 : (m)->sseq_len[(m)->phone[p].ssid])
00146 #define bin_mdef_n_sen(m) ((m)->n_sen)
00147 #define bin_mdef_n_tmat(m) ((m)->n_tmat)
00148 #define bin_mdef_pid2ssid(m,p) ((m)->phone[p].ssid)
00149 #define bin_mdef_pid2tmatid(m,p) ((m)->phone[p].tmat)
00150 #define bin_mdef_silphone(m) ((m)->sil)
00151 #define bin_mdef_sseq2sen(m,ss,pos) ((m)->sseq[ss][pos])
00152 #define bin_mdef_pid2ci(m,p) (((p) < (m)->n_ciphone) ? (p) \
00153 : (m)->phone[p].info.cd.ctx[0])
00154
00156 bin_mdef_t *bin_mdef_read(cmd_ln_t *config, const char *filename);
00158 bin_mdef_t *bin_mdef_read_text(cmd_ln_t *config, const char *filename);
00160 int bin_mdef_write(bin_mdef_t *m, const char *filename);
00162 int bin_mdef_write_text(bin_mdef_t *m, const char *filename);
00163
00165 void bin_mdef_free(bin_mdef_t *m);
00166
00171 int bin_mdef_ciphone_id (bin_mdef_t *m,
00172 const char *ciphone);
00173
00178 int bin_mdef_ciphone_id_nocase(bin_mdef_t *m,
00179 const char *ciphone);
00180
00181
00182 const char *bin_mdef_ciphone_str (bin_mdef_t *m,
00183 int32 ci);
00184
00185
00186 int bin_mdef_phone_id (bin_mdef_t *m,
00187 int32 b,
00188 int32 l,
00189 int32 r,
00190 int32 pos);
00191
00197 int bin_mdef_phone_str (bin_mdef_t *m,
00198 int pid,
00199 char *buf);
00200
00201 #ifdef __cplusplus
00202 };
00203 #endif
00204
00205 #endif