// file: pfil_token_0.cc
//

// isip include files
//
#include "param_file.h"
#include "param_file_constants.h"

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

// method: tokenize_cc
//
// arguments:
//  char_1** values: (output) array of strings of values
//  int_4& num_values: (output) size of array of values
//  char_1* string_to_tokenize: (input) string to tokenize
//  char_1 delimiter: (input) delimiter character
//
// return: a logical_1 indicating status
//
// this method tokenizes a string into an array of strings
//
// note that the memory of string_to_tokenize is destroyed by this
// call, and this must remain allocated as long as any of the strings
// are needed.
//
logical_1 Param_file::tokenize_cc(char_1** values_a, int_4& num_values_a,
				  char_1* string_to_tokenize_a,
				  char_1 delimiter_a) {

  // check arguments, allocate values_a if necessary
  //
  if (values_a == (char_1**)NULL) {
    error_handler_cc ((char_1*) "tokenize_cc",
		      (char_1*) "output memory is not allocated");
  }
  if (string_to_tokenize_a == (char_1*)NULL) {
    error_handler_cc ((char_1*) "tokenize_cc",
		      (char_1*) "input str/output memory is not allocated");
  }    
  
  num_values_a = 0;
  char_1* temp = string_to_tokenize_a;
  char_1* tmp_buf;

  char_1 delimiter[2] = {delimiter_a, (char_1)NULL};
  
  // tokenize the first time
  //
  tmp_buf = (char_1*) strtok((char*) temp, (char*) delimiter);
  values_a[num_values_a++] = tmp_buf;

  // tokenize the rest of the string
  //
  while ((tmp_buf = (char_1*) strtok(NULL, (char *)delimiter))
	 != (char_1*)NULL) {
    values_a[num_values_a++] = tmp_buf;
  }

  // exit gracefully
  //
  return ISIP_TRUE;  
}
