// file: $USFS/util/ppm_diff/v1.0/ppm_gp_0.cc
//
// a simple command line parser
//

// system include files
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// isip include files
//
#include <integral.h>
#include <integral_constants.h>

// local include files
//
#include "ppm_diff.h"

// function: get_parameters_cc
//
// arguments:
//
//  int argc: (input) argc from the main program
//  char** argv: (input) argv from the main program
//  float_4& alpha_a: (output) scale factor
//  float_4& beta_a: (output) scale factor
//  char_1* file0_a: (output) source file0
//  char_1* file1_a: (output) source file1
//  char_1* file2_a: (output) source file2
//
// return value: a logical_1 indicating status
//
// this function parses command line arguments
//
logical_1 get_parameters_cc(int argc, char** argv,
			    float_4& alpha_a, float_4& beta_a,
			    char_1* file0_a, char_1* file1_a,
			    char_1* file2_a) {

  // declare a variable for indexing arguments
  //
  int_4 last_index = argc;

  // if no arguments are given then print out a help message
  //
  if (last_index == (int)1) {
    char_1 tmp_string[ISIP_MAX_STRING_LENGTH];
    sprintf((char*)tmp_string,
	    (char*)ISIP_HELP_FORMAT, (char*)PPM_HELP_FILE);
    system((char*)tmp_string);

    // exit gracefully
    //
    exit (ISIP_NO_ERROR);
  }

  for (int_4 index=1; index<last_index; index++) {

    // check for help
    //
    if (strcmp((char*)ISIP_HELP_OPTION, argv[index]) == (int)0) {
      char_1 tmp_string[ISIP_MAX_STRING_LENGTH];
      sprintf((char*)tmp_string,
	      (char*)ISIP_HELP_FORMAT, (char*)PPM_HELP_FILE);
      system((char*)tmp_string);

      // exit gracefully
      //
      exit(ISIP_NO_ERROR);
    }

    // pick off alpha
    //
    else if (strcmp((char*)PPM_OPT_A, argv[index]) == (int)0) {
      alpha_a = atof(argv[index+(int)1]);
    }

    // pick off beta
    //
    else if (strcmp((char*)PPM_OPT_B, argv[index]) == (int)0) {
      beta_a = atof(argv[index+(int)1]);
    }
  }

  // pick off the filenames
  //
  strcpy((char*)file0_a, argv[argc-3]);
  strcpy((char*)file1_a, argv[argc-2]);
  strcpy((char*)file2_a, argv[argc-1]);
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
