<commit_before>
#include "ncsv.h"

#include <stdlib.h>
#include <string.h>

// returns 0 if the correct amount of data was parsed
bool parseNCSVLine(FILE *f, int columns, double *res) {
  char buf[1000];
  if (fgets(buf, 1000, f) == NULL) {
    return -2; // real error
  }
  
  char *strtok_buf = buf;
  char *p = buf;
  int resindex = 0;
  while ((p = strtok(strtok_buf, ",")) != NULL) {
    strtok_buf = NULL;
    if (resindex == columns) return 1; // no more space in res
    char *endptr;
    res[resindex++] = strtod(p, &endptr);
    if (endptr == p) {
      fprintf(stderr, "WARNING: unparseable number!\n");
    } else if (*endptr != 0) {
      fprintf(stderr, "WARNING: can't parse the whole number!\n");
    }
  }
  if (resindex == columns) {
    return true; // everything is fine
  } else {
    return false; // didn't parse at least `columns` columns
  }<commit_msg>allow crlf linebreaks in ncsv<commit_after>
#include "ncsv.h"

#include <stdlib.h>
#include <string.h>

// returns 0 if the correct amount of data was parsed
bool parseNCSVLine(FILE *f, int columns, double *res) {
  char buf[1000];
  if (fgets(buf, 1000, f) == NULL) {
    return -2; // real error
  }
  
  char *strtok_buf = buf;
  char *p = buf;
  int resindex = 0;
  while ((p = strtok(strtok_buf, ",")) != NULL) {
    strtok_buf = NULL;
    if (resindex == columns) return 1; // no more space in res
    char *endptr;
    res[resindex++] = strtod(p, &endptr);
    if (endptr == p) {
      fprintf(stderr, "WARNING: unparseable number!\n");
      exit(1);
    } else if (*endptr != 0 && *endptr != 10 && *endptr != 13) {
      fprintf(stderr, "WARNING: can't parse the whole number! hex code %x\n", (int)*endptr);
      exit(1);
    }
  }
  if (resindex == columns) {
    return true; // everything is fine
  } else {
    return false; // didn't parse at least `columns` columns
  }
{'fraction_non_alphanumeric': 0.15504291845493562, 'fraction_numerical': 0.017167381974248927, 'mean_word_length': 2.8773388773388775, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5672786', 'n_tokens_mistral': 693, 'n_tokens_neox': 662, 'n_words': 214}