// file: ht_cmd_0.cc
//

// isip include files
//
#include "hmm_train.h"
#include "hmm_train_constants.h"

// method: read_cmdline_cc
//
// arguments:
//  int_4 argc : (input) number of arguments
//  char_1** argv : (input) argument variables
//  char_1* prm_file : (output) name of the parameters file
//  int_4& context_flag : (output) context flag for external or internal
//
// return: a logical_1 flag indicating success
//

// this method reads the commandline and deciphers the various
// arguments and options
//
logical_1 read_cmdline_cc(int_4 argc_a, char_1** argv_a,
			  char_1* prm_file_a, int_4& context_flag_a
			  ) {

  // create the help message
  //
  char_1* cmd_str = new char_1[ISIP_MAX_STRING_LENGTH];
  sprintf((char*)cmd_str, (char*)ISIP_HELP_FORMAT, (char*)HT_HELP_FILE);

   context_flag_a = 0 ;  // default value 0, for context dependent
  
  // decipher the commandline arguments
  //
  for (int_4 i = 0; i < argc_a; i++) {
 
    // check if the help message needs to be printed
    //
    if (argc_a < 5) {
      
      // print the help message
      //
      system((char*)cmd_str);

      // exit gracefully
      //
      exit(ISIP_PROTO_ERROR);
    }

    // decipher the commandline
    //
    if (i > 0) {
      
      // read the name of the parameter file
      //
      if (strcmp(HT_PARAMS_OPT, (char*)argv_a[i]) == 0) {
	strcpy((char*)prm_file_a, (char*)argv_a[++i]);
	expand_filename_cc(prm_file_a);
      }
      
      // read the name of the context dependent or independent flag
      //
      else if (strcmp(HT_CONTEXT_OPT, (char*)argv_a[i]) == 0) {
	if(strcmp((char*)HT_STR_OP_CI, (char*)argv_a[++i]) ==0){
	  context_flag_a = 0;
	}
	else if(strcmp((char*)HT_STR_OP_CD, (char*)argv_a[i]) ==0){
	  context_flag_a = 1;
	}
	else {
	  fprintf(stdout, "\nht_cmd_0.cc:  context mode error\n\n");

	  // exit gracefully 
	  //
	  exit(ISIP_PROTO_ERROR);
	}
      }

     
      // otherwise print the help message
      //
      else {
	
	system((char*)cmd_str);
	
	// exit gracefully
	//
	exit(ISIP_PROTO_ERROR);
      }
    }
  }


  
  // free memory
  //
  delete [] cmd_str;
  
  // exit gracefully
  //
  return ISIP_TRUE;
}


