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

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

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

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

// function: get_parameters_cc
//
// arguments:
//
//  int argc: (input) argc from the main program
//  char** argv: (input) argv from the main program
//  int_4& width_a: (output) width of sub-block in pixels
//  int_4& height_a: (output) height of sub-block in pixels
//  int_4& woff_a: (output) offset in pixels in the width direction
//  int_4& hoff_a: (output) offset in pixels in the height direction
//  char_1* file_a: (output) source file
//
// return value: a logical_1 indicating status
//
// this function parses command line arguments
//
logical_1 get_parameters_cc(int argc, char** argv,
			    int_4& width_a, int_4& height_a,
			    int_4& woff_a, int_4& hoff_a, char_1* file_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);
  }

  // pick off the filenames
  //
  strcpy((char*)file_a, argv[argc-1]);

  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(1);
    }

    // pick off width
    //
    else if (strcmp((char*)PPM_OPT_W, argv[index]) == (int)0) {
      width_a = atoi(argv[index+(int)1]);
    }

    // pick off height
    //
    else if (strcmp((char*)PPM_OPT_H, argv[index]) == (int)0) {
      height_a = atoi(argv[index+(int)1]);
    }

    // pick off width offset
    //
    else if (strcmp((char*)PPM_OPT_WOFF, argv[index]) == (int)0) {
      woff_a = atoi(argv[index+(int)1]);
    }

    // pick off height offset
    //
    else if (strcmp((char*)PPM_OPT_HOFF, argv[index]) == (int)0) {
      hoff_a = atoi(argv[index+(int)1]);
    }
  }

  // exit gracefully
  //
  return ISIP_TRUE;
}
