// file: gc_cmd_0.cc
//

// isip include files
//
#include "grammar_compiler.h"
#include "grammar_compiler_constants.h"

// method: read_cmdline_cc
//
// arguments:
//  int_4 argc : (input) number of arguments
//  char_1** argv : (input) argument variables
//  logical_1& probablistic_flag : (output) probablistic flag
//  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 reads the commandline and deciphers the various
// arguments and options
//
logical_1 read_cmdline_cc(int_4 argc_a, char_1** argv_a,
			  logical_1& probablistic_flag_a,
			  char_1* input_file_a, char_1* output_file_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*)GC_HELP_FILE);
  
  if (argc_a < 5) {
    
    // print the help message
    //
    system((char*)cmd_str);
    fprintf(stdout, "\n");
    
    // exit gracefully
    //
    exit(ISIP_PROTO_ERROR);
  }
  
  // decipher the commandline arguments
  //
  for (int_4 i = 1; i < argc_a; i++) {
    
    // read the name of the probable flag
    //
    if (strcmp(GC_PROBABLISTIC_OPT, (char*)argv_a[i]) == 0) {
    probablistic_flag_a = ISIP_TRUE;
    }
    
    // read the name of the input file
    //
    else if (strcmp(GC_INPUT_OPT, (char*)argv_a[i]) == 0) {
      strcpy((char*)input_file_a, (char*)argv_a[++i]);
    }
    
    // read the name of the output file
    //
    else if (strcmp(GC_OUTPUT_OPT, (char*)argv_a[i]) == 0) {
      strcpy((char*)output_file_a, (char*)argv_a[++i]);
    }
    
    // otherwise print the help message and exit with error
    //
    else {
      
      // exit very ungracefully
      //
      system((char*)cmd_str);
      exit(ISIP_PROTO_ERROR);
    }
  }
  
  // free memory
  //
  delete [] cmd_str;

  // exit gracefully
  //
  return ISIP_TRUE;
}
