Beispiel #1
0
// CSV to Qucs conversion.
int csv2qucs (struct actionset_t * action, char * infile, char * outfile) {
  int ret = 0;
  csv_init ();
  if ((csv_in = open_file (infile, "r")) == NULL) {
    ret = -1;
  } else if (csv_parse () != 0) {
    ret = -1;
  } else if (csv_check () != 0) {
    ret = -1;
  }
  csv_lex_destroy ();
  if (csv_in)
    fclose (csv_in);
  if (ret) {
    csv_destroy ();
    return -1;
  }

  if (!strcmp (action->out, "qucsdata")) {
    csv_result->setFile (outfile);
    qucsdata_producer (csv_result);
  }
  csv_destroy ();
  return 0;
}
Beispiel #2
0
/* This static function read a full dataset from the given CSV file
   and returns it.  On failure the function emits appropriate error
   messages and returns NULL. */
dataset * dataset::load_csv (const char * file) {
  FILE * f;
  if ((f = fopen (file, "r")) == NULL) {
    logprint (LOG_ERROR, "error loading `%s': %s\n", file, strerror (errno));
    return NULL;
  }
  csv_in = f;
  csv_restart (csv_in);
  if (csv_parse () != 0) {
    fclose (f);
    return NULL;
  }
  if (csv_check () != 0) {
    fclose (f);
    return NULL;
  }
  fclose (f);
  csv_lex_destroy ();
  csv_result->setFile (file);
  return csv_result;
}