Julius 4.1.5
libsent/src/hmminfo/write_binhmmlist.c
00001 
00019 /*
00020  * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University
00021  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00022  * Copyright (c) 2005-2007 Julius project team, Nagoya Institute of Technology
00023  * All rights reserved
00024  */
00025 
00026 #include <sent/stddefs.h>
00027 #include <sent/htk_hmm.h>
00028 #include <sent/ptree.h>
00029 
00030 static boolean
00031 save_hmmlist_callback(void *data, FILE *fp)
00032 {
00033   HMM_Logical *l = data;
00034   char *s;
00035   int len;
00036 
00037   if (myfwrite(&(l->is_pseudo), sizeof(boolean), 1, fp) < 1) return FALSE;
00038   len = strlen(l->name) + 1;
00039   if (myfwrite(&len, sizeof(int), 1, fp) < 1) return FALSE;
00040   if (myfwrite(l->name, len, 1, fp) < 1) return FALSE;
00041   if (l->is_pseudo) {
00042     s = l->body.pseudo->name;
00043   } else {
00044     s = l->body.defined->name;
00045   }
00046   len = strlen(s) + 1;
00047   if (myfwrite(&len, sizeof(int), 1, fp) < 1) return FALSE;
00048   if (myfwrite(s, len, 1, fp) < 1) return FALSE;
00049   
00050   return TRUE;
00051 }
00052 
00053 boolean
00054 save_hmmlist_bin(FILE *fp, HTK_HMM_INFO *hmminfo)
00055 {
00056   /* set mark */
00057   int x = 0;
00058   if (myfwrite(&x, sizeof(int), 1, fp) < 1) {
00059     jlog("Error: save_hmmlist_bin: failed to write hmmlist to binary file\n");
00060     return FALSE;
00061   }
00062   if (aptree_write(fp, hmminfo->logical_root, save_hmmlist_callback) == FALSE) {
00063     jlog("Error: save_hmmlist_bin: failed to write hmmlist to binary file\n");
00064     return FALSE;
00065   }
00066   return TRUE;
00067 }