<commit_before>#include <string.h>
#include "ImageFile.h"

#ifdef PNG_FOUND
#  include "ImageLoaderPNG.h"
#endif

ImageFile::ImageFile(const char *filename) : 
  m_PixelData(0),
  m_FileFormat(  DetectFileFormat(filename) )
{
  unsigned char *rawData = ReadFileData(filename);
  LoadImage(rawData);
  delete [] rawData;
}

ImageFile::ImageFile(const char *filename, EImageFileFormat format) :
  m_FileFormat(format),
  m_PixelData(0)
{
  unsigned char *rawData = ReadFileData(filename);
  LoadImage(rawData);
  delete [] rawData;
}

ImageFile::~ImageFile() {
  if(m_PixelData) {
    delete [] m_PixelData;
  }
}

EImageFileFormat ImageFile::DetectFileFormat(const char *filename) {

  int len = strlen(filename);
  if(len >= 256) {
    // !FIXME! Report Error...
    return kNumImageFileFormats;
  }

  int dotPos = len - 1;

  while(dotPos >= 0 && filename[dotPos--] != '.');

  if(dotPos < 0) {
    // !FIXME! Report Error.....
    return kNumImageFileFormats;
  }

  const char *ext = &filename[dotPos];

  if(strcmp(ext, ".png") == 0) {
    return eFileFormat_PNG;
  }
  return kNumImageFileFormats;
}

bool ImageFile::LoadImage(const unsigned char *rawImageData) {
  return false;
}

#ifdef _MSC_VER
unsigned char *ImageFile::ReadFileData(const char *filename) {

}
#else
unsigned char *ImageFile::ReadFileData(const char *filename) {

}
#endif<commit_msg>Added code to load the contents of a file to memory on not-windows.<commit_after>#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

#include "ImageFile.h"

#ifdef PNG_FOUND
#  include "ImageLoaderPNG.h"
#endif

ImageFile::ImageFile(const char *filename) : 
  m_PixelData(0),
  m_FileFormat(  DetectFileFormat(filename) )
{
  unsigned char *rawData = ReadFileData(filename);
  if(rawData) {
    LoadImage(rawData);
    delete [] rawData;
  }
}

ImageFile::ImageFile(const char *filename, EImageFileFormat format) :
  m_FileFormat(format),
  m_PixelData(0)
{
  unsigned char *rawData = ReadFileData(filename);
  if(rawData) {
    LoadImage(rawData);
    delete [] rawData;
  }
}

ImageFile::~ImageFile() {
  if(m_PixelData) {
    delete [] m_PixelData;
  }
}

EImageFileFormat ImageFile::DetectFileFormat(const char *filename) {

  int len = strlen(filename);
  if(len >= 256) {
    // !FIXME! Report Error...
    return kNumImageFileFormats;
  }

  int dotPos = len - 1;

  while(dotPos >= 0 && filename[dotPos--] != '.');

  if(dotPos < 0) {
    // !FIXME! Report Error.....
    return kNumImageFileFormats;
  }

  const char *ext = &filename[dotPos];

  if(strcmp(ext, ".png") == 0) {
    return eFileFormat_PNG;
  }
  return kNumImageFileFormats;
}

bool ImageFile::LoadImage(const unsigned char *rawImageData) {
  return false;
}

#ifdef _MSC_VER
unsigned char *ImageFile::ReadFileData(const char *filename) {
  //!FIXME! - Actually, implement me
  assert(!"Not implemented!");
}
#else
unsigned char *ImageFile::ReadFileData(const char *filename) {
  FILE *fp = fopen(filename, "rb");
  if(!fp) {
    fprintf(stderr, "Error opening file for reading: %s\n", filename);
    return 0;
  }

  // Check filesize
  long fileSize = 0;
  fseek(fp, 0, SEEK_END);
  fileSize = ftell(fp);

  // Allocate data for file contents
  unsigned char *rawData = new unsigned char[fileSize];

  // Return stream to beginning of file
  fseek(fp, 0, SEEK_SET);
  assert(ftell(fp) == 0);

  // Read all of the data
  size_t bytesRead = fread(rawData, 1, fileSize, fp);
  if(bytesRead != fileSize) {
    assert(!"We didn't read as much data as we thought we had!");
    fprintf(stderr, "Internal error: Incorrect file size assumption\n");
    return 0;
  }

  // Close the file pointer
  fclose(fp);

  // Return the data..
  return rawData;
}
#endif
{'fraction_non_alphanumeric': 0.13740252756117236, 'fraction_numerical': 0.006722237160527024, 'mean_word_length': 3.93368700265252, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, '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': '6911387', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1294, 'n_words': 315}