<commit_before>#include "graffiks/object/obj_loader.h"
#include "graffiks/object/mtl_loader.h"

#ifndef _WIN32
#include <libgen.h>
#endif

#ifdef _WIN32
#include <windows.h>
#define strtok_r strtok_s

char *dirname(const char *path) {
  char *out = malloc(strlen(path) + 1);
  _splitpath(path, NULL, out, NULL, NULL);
  if (out[0] == '\0') {
    out[0] = '.';
    out[1] = '\0';
  }
  return out;
}

#endif

int _gfks_string_starts_with(char *pre, char *str) {
  size_t lenpre = strlen(pre);
  size_t lenstr = strlen(str);
  return lenstr < lenpre ? 0 : strncmp(pre, str, lenpre) == 0;
}

int _gfks_resize_obj_data(char ***obj_data, int previous_size, int size) {
  if (previous_size > size) {
    int i;
    for (i = previous_size - 1; i >= size; i--) {
      free((*obj_data)[i]);
    }
  }

  *obj_data = realloc(*obj_data, size * sizeof(char *));

  if (size > previous_size) {
    int i;
    for (i = previous_size; i < size; i++) {
      (*obj_data)[i] = malloc(256 * sizeof(char));
    }
  }

  return size;
}

void _gfks_free_obj_data(char ***obj_data, int size) {
  int i;
  for (i = 0; i < size; i++) {
    free((*obj_data)[i]);
  }

  free(*obj_data);
}

char **_gfks_read_obj_data(char *filepath, int *line_count_output) {
  char **obj_data = NULL;
  int line_count = _gfks_resize_obj_data(&obj_data, 0, 64);

  FILE *obj_fp = fopen(filepath, "r");
  int current_line = 0;

  while (fgets(obj_data[current_line], sizeof(char) * 256, obj_fp)) {
    current_line++;

    if (current_line >= line_count) {
      line_count = _gfks_resize_obj_data(&obj_data, line_count, line_count + 64);
    }
  }

  fclose(obj_fp);

  line_count = _gfks_resize_obj_data(&obj_data, line_count, current_line);

  *line_count_output = line_count;
  return obj_data;
}

int _gfks_resize_2d_int_array(float ***array, int previous_size, int size, int size2) {
  if (previous_size > size) {
    // we're shrinking, so free stuff
    int i;
    for (i = previous_size - 1; i >= size; i--) {
      free((*array)[i]);
    }
  }

  *array = realloc(*array, size * sizeof(float *));

  if (size > previous_size) {
    // we're expanding, so allocate stuff
    int i;
    for (i = previous_size; i < size; i++) {
      (*array)[i] = malloc(size2 * sizeof(float));
    }
  }

  return size;
}

void _gfks_free_2d_int_array(float ***array, int size) {
  int i;
  for (i = 0; i < size; i++) {
    free((*array)[i]);
  }

  free(*array);
}

int _gfks_resize_faces(int ****faces, int previous_size, int size) {
  if (previous_size > size) {
    int i;
    for (i = previous_size - 1; i >= size; i--) {
      free((*faces)[i][0]);
      free((*faces)[i][1]);
      free((*faces)[i][2]);

      free((*faces)[i]);
    }
  }

  *faces = realloc(*faces, size * sizeof(int **));

  if (size > previous_size) {
    int i;
    for (i = previous_size; i < size; i++) {
      (*faces)[i] = malloc(3 * sizeof(int *));

      (*faces)[i][0] = malloc(3 * sizeof(int));
      (*faces)[i][1] = malloc(3 * sizeof(int));
      (*faces)[i][2] = malloc(3 * sizeof(int));
    }
  }

  return size;
}

void _gfks_free_faces(int ****faces, int size) {
  int i;
  for (i = 0; i < size; i++) {
    free((*faces)[i][0]);
    free((*faces)[i][1]);
    free((*faces)[i][2]);

    free((*faces)[i]);
  }

  free(*faces);
}

typedef struct {
  int ***faces;
  int face_count;
  int allocated_face_count;
  gfks_material *mat;
} face_group;

int _gfks_resize_face_groups(face_group ***f, int previous_size, int size) {
  if (previous_size > size) {
    int i;
    for (i = previous_size - 1; i >= size; i--) {
      free((*f)[i]);
    }
  }
<commit_msg>hide internal<commit_after>#include "graffiks/object/obj_loader.h"
#include "graffiks/object/mtl_loader.h"

#ifndef _WIN32
#include <libgen.h>
#endif

#ifdef _WIN32
#include <windows.h>
#define strtok_r strtok_s

char *dirname(const char *path) {
  char *out = malloc(strlen(path) + 1);
  _splitpath(path, NULL, out, NULL, NULL);
  if (out[0] == '\0') {
    out[0] = '.';
    out[1] = '\0';
  }
  return out;
}

#endif

int _gfks_string_starts_with(char *pre, char *str) {
  size_t lenpre = strlen(pre);
  size_t lenstr = strlen(str);
  return lenstr < lenpre ? 0 : strncmp(pre, str, lenpre) == 0;
}

int _gfks_resize_obj_data(char ***obj_data, int previous_size, int size) {
  if (previous_size > size) {
    int i;
    for (i = previous_size - 1; i >= size; i--) {
      free((*obj_data)[i]);
    }
  }

  *obj_data = realloc(*obj_data, size * sizeof(char *));

  if (size > previous_size) {
    int i;
    for (i = previous_size; i < size; i++) {
      (*obj_data)[i] = malloc(256 * sizeof(char));
    }
  }

  return size;
}

void _gfks_free_obj_data(char ***obj_data, int size) {
  int i;
  for (i = 0; i < size; i++) {
    free((*obj_data)[i]);
  }

  free(*obj_data);
}

char **_gfks_read_obj_data(char *filepath, int *line_count_output) {
  char **obj_data = NULL;
  int line_count = _gfks_resize_obj_data(&obj_data, 0, 64);

  FILE *obj_fp = fopen(filepath, "r");
  int current_line = 0;

  while (fgets(obj_data[current_line], sizeof(char) * 256, obj_fp)) {
    current_line++;

    if (current_line >= line_count) {
      line_count = _gfks_resize_obj_data(&obj_data, line_count, line_count + 64);
    }
  }

  fclose(obj_fp);

  line_count = _gfks_resize_obj_data(&obj_data, line_count, current_line);

  *line_count_output = line_count;
  return obj_data;
}

int _gfks_resize_2d_int_array(float ***array, int previous_size, int size, int size2) {
  if (previous_size > size) {
    // we're shrinking, so free stuff
    int i;
    for (i = previous_size - 1; i >= size; i--) {
      free((*array)[i]);
    }
  }

  *array = realloc(*array, size * sizeof(float *));

  if (size > previous_size) {
    // we're expanding, so allocate stuff
    int i;
    for (i = previous_size; i < size; i++) {
      (*array)[i] = malloc(size2 * sizeof(float));
    }
  }

  return size;
}

void _gfks_free_2d_int_array(float ***array, int size) {
  int i;
  for (i = 0; i < size; i++) {
    free((*array)[i]);
  }

  free(*array);
}

int _gfks_resize_faces(int ****faces, int previous_size, int size) {
  if (previous_size > size) {
    int i;
    for (i = previous_size - 1; i >= size; i--) {
      free((*faces)[i][0]);
      free((*faces)[i][1]);
      free((*faces)[i][2]);

      free((*faces)[i]);
    }
  }

  *faces = realloc(*faces, size * sizeof(int **));

  if (size > previous_size) {
    int i;
    for (i = previous_size; i < size; i++) {
      (*faces)[i] = malloc(3 * sizeof(int *));

      (*faces)[i][0] = malloc(3 * sizeof(int));
      (*faces)[i][1] = malloc(3 * sizeof(int));
      (*faces)[i][2] = malloc(3 * sizeof(int));
    }
  }

  return size;
}

void _gfks_free_faces(int ****faces, int size) {
  int i;
  for (i = 0; i < size; i++) {
    free((*faces)[i][0]);
    free((*faces)[i][1]);
    free((*faces)[i][2]);

    free((*faces)[i]);
  }

  free(*faces);
}

/// \cond INTERNAL
typedef struct {
  int ***faces;
  int face_count;
  int allocated_face_count;
  gfks_material *mat;
} face_group;
/// \endcond

int _gfks_resize_face_groups(face_group ***f, int previous_size, int size) {
  if (previous_size > size) {
    int i;
    for (i = previous_size - 1; i >= size; i--) {
      free((*f)[i]);
    }
  }

{'fraction_non_alphanumeric': 0.18141592920353983, 'fraction_numerical': 0.01327433628318584, 'mean_word_length': 3.2125800815375656, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 31, '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': '7213632', 'n_tokens_mistral': 2980, 'n_tokens_neox': 2848, 'n_words': 650}