// file: $isip/util/speech/isip_model_converter/imc_mono_0.cc
// version: $Id: imc_mono_0.cc 8977 2003-01-12 06:37:52Z jelinek $
//
// isip include files
//
#include "isip_model_converter.h"

// method: read_mono_cc
//
// arguments:
//  String& mono_filename : (input) file containing prototype monophones
//  File& mono_file : (output) file containing prototype monophones
//  Vector<SearchSymbol>& phone_syms : (output) phone symbols
//  HashTable<String, Ulong>& phone_hash : (input) phone hash table
//
// return: a logical flag to indicate success
//
// this method reads the input monophone file and stores the
// monophones as Vector<SearchSymbol>
//
boolean read_mono_cc(String& mono_filename_a, File& mono_file_a,
		     Vector<SearchSymbol>& phone_syms_a,
		     HashTable<String, Ulong>& phone_hash_a) {
  

  // declare local variables
  //
  boolean ready_to_read = false;
  ulong num_mono = 0;
  Ulong* index = (Ulong*)NULL;
    
  // check if the file exists
  //
  if (!mono_file_a.open(mono_filename_a)) {
    String out(L"error opening ");
    out.concat(mono_filename_a);
    Console::put(out);
    Integral::exit();
  }

  SearchSymbol tmp_str(L"");
  SearchSymbol tmp;

  
  // read the monophone file
  //
  while(!mono_file_a.eof()) {

    // get the next line
    //
    if(!mono_file_a.get(tmp_str)) {
      break;
    }

    // trim the line and check for empty lines and comment lines
    //
    tmp_str.trim();
    if (tmp_str.length() <= 0) {
      continue;
    }
    if (tmp_str(0) == IMC_COMMENT_CHAR) {
      continue;
    }

    // skip the first entry which is the num_monophones tag
    //
    if (!ready_to_read) {
      ready_to_read = true;
      continue;
    }
    
    index = new Ulong(num_mono);
    
    // make an entry to the hash table
    //
    phone_hash_a.insert((String)tmp_str, index);
    
    num_mono++;

    phone_syms_a.setLength(num_mono);
    phone_syms_a(num_mono-1).assign(tmp_str);
  }

  mono_file_a.close();

  return true;
}
