Beispiel #1
0
/* ==================================================================
 * Parser for comma-separated argument  list
 * ================================================================== */
void ParseVarList(int nLn, FILE *flp, char *dataName, char *leftPart, char *argString)	
{

  struct csv_parser p;
  unsigned char options = 0;
  LIST_DATA ldata;

  // fill in data for the callback
  memset(&ldata, '\x0', sizeof(LIST_DATA));
  ldata.nLn = nLn;
  ldata.flp = flp;
  ldata.cnt = 0;
  strcpy(ldata.dataName, dataName);
  strcpy(ldata.lp, leftPart);


  // Initialize csv parser
  if (csv_init(&p, options) != 0)
  {
  	fprintf(stderr, "Failed to initialize csv parser\n");
  	return;
  }
  
  // set white space, eol and delimiter
  csv_set_space_func(&p, is_space_list);
  csv_set_term_func(&p, is_term_list);
  
  csv_set_delim(&p, ',');
  
  unsigned int agrLen = strlen(argString);

  fprintf(stderr, "ParseVarList: argString = %s argLen - %d\n", argString, agrLen);

  memset(inputsLst, '\x0', sizeof(inputsLst));								
  InpCnt = 0;
  
  if (csv_parse(&p, argString, strlen(argString), cbProcessListElement, NULL, &ldata) != agrLen)
  {
  	fprintf(stderr, "ParseVarList: %s\n", csv_strerror(csv_error(&p)));
  	return;
  }
  
  csv_fini(&p, cbProcessListElement, NULL, &ldata);
  csv_free(&p);
  
  return;
  
}
Beispiel #2
0
void csv_init_parser(csv_file_t &csvin)
{
#if CSV_MAJOR >= 3
#define PARSER_OPTIONS CSV_APPEND_NULL
#else
#define PARSER_OPTIONS 0
#endif
	unsigned char parser_options = PARSER_OPTIONS;

	if (csv_init(&csvin.csv_file_parser, parser_options) != 0)
	{
		fprintf(stderr, "Failed to initialize csv parser\n");
		exit(EXIT_FAILURE);
	}

	csv_set_space_func(&csvin.csv_file_parser, csv_is_space);

	csv_set_term_func(&csvin.csv_file_parser, csv_is_term);

	csv_set_delim(&csvin.csv_file_parser, csvin.tab_delimter);
}/* ----- end of function csv_init_parser ----- */