<commit_before>/*
    memfiles.c:

    Copyright (C) 1991, 2001 <NAME>, <NAME>, <NAME>
              (C) 2005 <NAME>

    This file is part of Csound.

    The Csound Library is free software; you can redistribute it
    and/or modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    Csound is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with Csound; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA
*/

#include "csoundCore.h"     /*                              MEMFILES.C      */
#include "soundio.h"
#include "pvfileio.h"
#include "convolve.h"
#include "lpc.h"
#include "pstream.h"
#include "namedins.h"
#include <sndfile.h>
#include <string.h>

static int Load_Het_File_(CSOUND *csound, const char *filnam,
                          char **allocp, int32 *len)
{
    FILE *f;
    int length = 1024;
    int i = 0;
    int cc;
    int16 x;
    char *all;
    char buffer[10];
    f = fopen(filnam, "r");
    csoundNotifyFileOpened(csound, filnam, CSFTYPE_HETRO, 0, 0);
    all = (char *)mmalloc(csound, (size_t) length);
    for (i=0; i<6; i++) fgetc(f); /* Skip HETRO */
    fgets(buffer, 10, f);         /* number of partials */
    x = atoi(buffer);
    memcpy(&all[0], &x, sizeof(int16));
    /* Read data until end, pack as int16 */
    for (i=sizeof(int16);;i+=sizeof(int16)) {
      int p = 0;
      while ((cc=getc(f))!=',' && cc!='\n' && p<15) {
        if (cc == EOF) {
          goto out;
        }
        buffer[p++] = cc;
      }
      buffer[p]='\0';
      /* Expand as necessary */
      if (i>=length-4) all = mrealloc(csound, all, length+=1024);
      x = atoi(buffer);
      memcpy(&all[i], &x, sizeof(int16));
    }
 out:
    fclose(f);                                  /*   and close it      */
    *len = i;
    all = mrealloc(csound, all, i);
    *allocp = all;
    return 0;                                   /*   return 0 for OK   */
}

static MYFLT read_ieee(FILE* f, int *end)
{
    char buff[120];
    double x;
    char *p = fgets(buff, 120, f);
    locale_t c_locale = newlocale(0, "C", NULL);
    if (p==NULL || feof(f)) {
      *end = 1;
      return FL(0.0);
    }
    x = strtod_l(buff, NULL, c_locale);
    return (MYFLT)x;
    /* union { */
    /*   double d; */
    /*   struct {int  j,k;}  n; */
    /*   int64_t  i; */
    /* } x; */
    /* int sign=1, ex; */
    /* int64_t man; */
    /* int64_t bit = 1; */
    /* char buff[32]; */
    /* char *p; */
    /* bit <<= 62; */
    /* p = fgets(buff, 32, f); */
    /* printf("... %s", buff); */
    /* if (p==NULL || feof(f)) { */
    /*   printf("ending\n"); */
    /*   *end = 1; */
    /*   return FL(0.0); */
    /* } */
    /* if (strstr(p, "0x0p+0")) { */
    /*   return FL(0.0); */
    /* } */<commit_msg>fix for non locales on windows<commit_after>/*
    memfiles.c:

    Copyright (C) 1991, 2001 <NAME>, <NAME>, <NAME>
              (C) 2005 <NAME>

    This file is part of Csound.

    The Csound Library is free software; you can redistribute it
    and/or modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    Csound is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with Csound; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA
*/

#include "csoundCore.h"     /*                              MEMFILES.C      */
#include "soundio.h"
#include "pvfileio.h"
#include "convolve.h"
#include "lpc.h"
#include "pstream.h"
#include "namedins.h"
#include <sndfile.h>
#include <string.h>

static int Load_Het_File_(CSOUND *csound, const char *filnam,
                          char **allocp, int32 *len)
{
    FILE *f;
    int length = 1024;
    int i = 0;
    int cc;
    int16 x;
    char *all;
    char buffer[10];
    f = fopen(filnam, "r");
    csoundNotifyFileOpened(csound, filnam, CSFTYPE_HETRO, 0, 0);
    all = (char *)mmalloc(csound, (size_t) length);
    for (i=0; i<6; i++) fgetc(f); /* Skip HETRO */
    fgets(buffer, 10, f);         /* number of partials */
    x = atoi(buffer);
    memcpy(&all[0], &x, sizeof(int16));
    /* Read data until end, pack as int16 */
    for (i=sizeof(int16);;i+=sizeof(int16)) {
      int p = 0;
      while ((cc=getc(f))!=',' && cc!='\n' && p<15) {
        if (cc == EOF) {
          goto out;
        }
        buffer[p++] = cc;
      }
      buffer[p]='\0';
      /* Expand as necessary */
      if (i>=length-4) all = mrealloc(csound, all, length+=1024);
      x = atoi(buffer);
      memcpy(&all[i], &x, sizeof(int16));
    }
 out:
    fclose(f);                                  /*   and close it      */
    *len = i;
    all = mrealloc(csound, all, i);
    *allocp = all;
    return 0;                                   /*   return 0 for OK   */
}

static MYFLT read_ieee(FILE* f, int *end)
{
    char buff[120];
    double x;
    char *p = fgets(buff, 120, f);
#ifndef WIN32
    locale_t c_locale = newlocale(0, "C", NULL);
#endif
    if (p==NULL || feof(f)) {
      *end = 1;
      return FL(0.0);
    }
    x = strtod_l(buff, NULL, c_locale);
    return (MYFLT)x;
    /* union { */
    /*   double d; */
    /*   struct {int  j,k;}  n; */
    /*   int64_t  i; */
    /* } x; */
    /* int sign=1, ex; */
    /* int64_t man; */
    /* int64_t bit = 1; */
    /* char buff[32]; */
    /* char *p; */
    /* bit <<= 62; */
    /* p = fgets(buff, 32, f); */
    /* printf("... %s", buff); */
    /* if (p==NULL || feof(f)) { */
    /*   printf("ending\n"); */
    /*   *end = 1; */
    /*   return FL(0.0); */
    /* } */
    /* if (strstr(p, "0x0p+0")) { */
    /*   return FL(0.0); */
    /* } */
{'fraction_non_alphanumeric': 0.15868077162414437, 'fraction_numerical': 0.031113876789047916, 'mean_word_length': 1.969515011547344, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5064927', 'n_tokens_mistral': 2392, 'n_tokens_neox': 2244, 'n_words': 696}