// file: cmmf_gp_0.cc
//

// isip include files
//
#include "convert_mmf.h"
#include "convert_mmf_constants.h"

// method: get_params_cc
//
// arguments:
//  int_4 argc : (input) number of arguments
//  char_1** argv : (input) argument variables
//  int_4& input_mode_flag : (output) mode of the input file (ascii or bin)
//  int_4& output_mode_flag : (output) mode of the output file (ascii or bin)
//  char_1* input_file : (output) name of the input file
//  char_1* output_file : (output) name of the output file
//
// return: a logical_1 flag indicating success
//
// this method parses the command line
//
logical_1 get_params_cc(int_4 argc_a, char_1** argv_a,
			int_4& input_mode_flag_a, int_4& output_mode_flag_a,
			char_1* input_file, char_1* output_file) {

  // check if the help message needs to be printed
  //
  if (argc_a < CMMF_MIN_NUM_ARGS) {

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

    // clean up memory
    //
    delete [] cmd_str;
    
    // exit gracefully
    //
    exit(ISIP_PROTO_ERROR);
  }
  else {

    // grab the input and output files off of the command line
    //
    strcpy((char*)output_file, (char*)argv_a[argc_a - 1]);
    strcpy((char*)input_file, (char*)argv_a[argc_a - 2]);    
  
    // decipher the commandline arguments
    //
    for (int_4 i = 1; i < (argc_a - 2); i++) {

      // read the input mode
      //
      if (strcmp((char*)CMMF_INPUT_MODE_OPT, (char*)argv_a[i]) == 0) {
	if (strcmp((char*)CMMF_ASCII_STR, (char*)argv_a[i+1]) == 0) {
	  input_mode_flag_a = CMMF_ASCII;
	}
	else if (strcmp((char*)CMMF_BINARY_STR, (char*)argv_a[i+1]) == 0) {
	  input_mode_flag_a = CMMF_BINARY;
	}
	else {

	  // create the help message
	  //
	  char_1* cmd_str = new char_1[ISIP_MAX_STRING_LENGTH];
	  sprintf((char*)cmd_str, (char*)ISIP_HELP_FORMAT,
		  (char*)CMMF_HELP_FILE);
	  
	  // print the help message
	  //
	  system((char*)cmd_str);
	  
	  // clean up memory
	  //
	  delete [] cmd_str;
	  
	  // exit gracefully
	  //
	  exit(ISIP_PROTO_ERROR);
	}
      }

      // read the output mode
      //
      else if (strcmp((char*)CMMF_OUTPUT_MODE_OPT, (char*)argv_a[i]) == 0) {
	if (strcmp((char*)CMMF_ASCII_STR, (char*)argv_a[i+1]) == 0) {
	  output_mode_flag_a = CMMF_ASCII;
	}
	else if (strcmp((char*)CMMF_BINARY_STR, (char*)argv_a[i+1]) == 0) {
	  output_mode_flag_a = CMMF_BINARY;
	}	
	else {
	
	  // create the help message
	  //
	  char_1* cmd_str = new char_1[ISIP_MAX_STRING_LENGTH];
	  sprintf((char*)cmd_str, (char*)ISIP_HELP_FORMAT,
		  (char*)CMMF_HELP_FILE);
	  
	  // print the help message
	  //
	  system((char*)cmd_str);
	  
	  // clean up memory
	  //
	  delete [] cmd_str;
	  
	  // exit gracefully
	  //
	  exit(ISIP_PROTO_ERROR);
	}	
      }
    }
  }

  // exit gracefully
  //
  return(ISIP_TRUE);
}
