<commit_before>/*
  NrrdIO: stand-alone code for basic nrrd functionality
  Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah
 
  These source files have been copied and/or modified from teem,
  <NAME>'s research software; <http://teem.sourceforge.net>.
  Teem is licensed under the GNU Lesser Public License. The
  non-copyleft licensing defined here applies to only the source files
  in the NrrdIO distribution (not the rest of teem), and only to the
  files originating with NrrdIO (not analogous files in teem).
 
  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any
  damages arising from the use of this software.
 
  Permission is granted to anyone to use this software for any
  purpose, including commercial applications, and to alter it and
  redistribute it freely, subject to the following restrictions:
 
  1. The origin of this software must not be misrepresented; you must
     not claim that you wrote the original software. If you use this
     software in a product, an acknowledgment in the product
     documentation would be appreciated but is not required.
 
  2. Altered source versions must be plainly marked as such, and must
     not be misrepresented as being the original software.
 
  3. This notice may not be removed or altered from any source distribution.
*/

#include "NrrdIO.h"
#include "privateNrrd.h"

#include "teem32bit.h"
#include <limits.h>

const char *
nrrdBiffKey = "nrrd";

/*
******** nrrdPeripheralInit
**
** resets peripheral information
*/
int
nrrdPeripheralInit (Nrrd *nrrd) {

  if (!nrrd) 
    return 1;

  /* nrrd->min = nrrd->max = AIR_NAN; */
  nrrd->oldMin = nrrd->oldMax = AIR_NAN;
  /* nrrd->hasNonExist = nrrdNonExistUnknown; */
  return 0;
}

/*
******** nrrdPeripheralCopy
**
** copies peripheral information
*/
int
nrrdPeripheralCopy (Nrrd *nout, const Nrrd *nin) {

  if (!( nout && nin ))
    return 1;

  /* HEY: who copies the content? */
  /*
  nout->min = nin->min;
  nout->max = nin->max;
  */
  nout->oldMin = nin->oldMin;
  nout->oldMax = nin->oldMax;
  /* nout->hasNonExist = nin->hasNonExist; */
  return 0;
}

/*
** _nrrdContentGet
**
** ALLOCATES a string for the content of a given nrrd
** panics and exits if allocation failed
*/
char *
_nrrdContentGet(const Nrrd *nin) {
  char me[]="_nrrdContentGet";
  char *ret;
  
  ret = ((nin && nin->content) ? 
   airStrdup(nin->content) : 
   airStrdup(nrrdStateUnknownContent));
  if (!ret) {
    fprintf(stderr, "%s: PANIC: content strdup failed!\n", me);
    exit(1);
  }
  return ret;
}

int
_nrrdContentSet_nva (Nrrd *nout, const char *func,
         char *content, const char *format, va_list arg) {
  char me[]="_nrrdContentSet_nva", err[AIR_STRLEN_MED],
    *buff;

  buff = malloc(128*AIR_STRLEN_HUGE);
  if (!buff) {
    sprintf(err, "%s: couln't alloc buffer!", me);
    biffAdd(NRRD, err); return 1;
  }
  nout->content = airFree(nout->content);

  /* we are currently praying that this won't overflow the "buff" array */
  /* HEY: replace with vsnprintf or whatever when its available */
  vsprintf(buff, format, arg);

  nout->content = calloc(strlen("(,)")
       + airStrlen(func)
       + 1                      /* '(' */
       + airStrlen(content)
       + 1                      /* ',' */
       + airStrlen(buff)
       + 1                      /* ')' */
       + 1, sizeof(char));      /* '\0' */
  if (!nout->content) {
    sprintf(err, "%s: couln't alloc output content!", me);
    biffAdd(NRRD, err); buff = airFree(buff); return 1;
  }
  sprintf(nout->content, "%s(%s%s%s)", func, content,
    airStrlen(buff) ? "," : "", buff);
  airFree(buff);
  return 0;
}

int
_nrrdContentSet (Nrrd *nout, const char *func,
     char *content, const char *format, ...) {
  char me[]="_nrrdContentSet", err[AIR_STRLEN_MED];
  va_list ap;
  
  va_start(ap, format);
  if (_nrrdContentSet_nva(nout, func, content, format, ap)) {
    sprintf(err, "%s:", me);
    biffAdd(NRRD, err); free(content); return 1;
  }
  va_end(ap);

  /* free(content);  */
  return 0;<commit_msg>FIX: Warning fixes on Borland compiler<commit_after>/*
  NrrdIO: stand-alone code for basic nrrd functionality
  Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah
 
  These source files have been copied and/or modified from teem,
  <NAME>'s research software; <http://teem.sourceforge.net>.
  Teem is licensed under the GNU Lesser Public License. The
  non-copyleft licensing defined here applies to only the source files
  in the NrrdIO distribution (not the rest of teem), and only to the
  files originating with NrrdIO (not analogous files in teem).
 
  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any
  damages arising from the use of this software.
 
  Permission is granted to anyone to use this software for any
  purpose, including commercial applications, and to alter it and
  redistribute it freely, subject to the following restrictions:
 
  1. The origin of this software must not be misrepresented; you must
     not claim that you wrote the original software. If you use this
     software in a product, an acknowledgment in the product
     documentation would be appreciated but is not required.
 
  2. Altered source versions must be plainly marked as such, and must
     not be misrepresented as being the original software.
 
  3. This notice may not be removed or altered from any source distribution.
*/

#include "NrrdIO.h"
#include "privateNrrd.h"

#include "teem32bit.h"
#include <limits.h>

const char *
nrrdBiffKey = "nrrd";

/*
******** nrrdPeripheralInit
**
** resets peripheral information
*/
int
nrrdPeripheralInit (Nrrd *nrrd) {

  if (!nrrd) 
    return 1;

  /* nrrd->min = nrrd->max = AIR_NAN; */
  nrrd->oldMin = nrrd->oldMax = AIR_NAN;
  /* nrrd->hasNonExist = nrrdNonExistUnknown; */
  return 0;
}

/*
******** nrrdPeripheralCopy
**
** copies peripheral information
*/
int
nrrdPeripheralCopy (Nrrd *nout, const Nrrd *nin) {

  if (!( nout && nin ))
    return 1;

  /* HEY: who copies the content? */
  /*
  nout->min = nin->min;
  nout->max = nin->max;
  */
  nout->oldMin = nin->oldMin;
  nout->oldMax = nin->oldMax;
  /* nout->hasNonExist = nin->hasNonExist; */
  return 0;
}

/*
** _nrrdContentGet
**
** ALLOCATES a string for the content of a given nrrd
** panics and exits if allocation failed
*/
char *
_nrrdContentGet(const Nrrd *nin) {
  char me[]="_nrrdContentGet";
  char *ret;
  
  ret = ((nin && nin->content) ? 
   airStrdup(nin->content) : 
   airStrdup(nrrdStateUnknownContent));
  if (!ret) {
    fprintf(stderr, "%s: PANIC: content strdup failed!\n", me);
    exit(1);
  }
  return ret;
}

int
_nrrdContentSet_nva (Nrrd *nout, const char *func,
         char *content, const char *format, va_list arg) {
  char me[]="_nrrdContentSet_nva", err[AIR_STRLEN_MED],
    *buff;

  buff = malloc(128*AIR_STRLEN_HUGE);
  if (!buff) {
    sprintf(err, "%s: couln't alloc buffer!", me);
    biffAdd(NRRD, err); return 1;
  }
  nout->content = airFree(nout->content);

  /* we are currently praying that this won't overflow the "buff" array */
  /* HEY: replace with vsnprintf or whatever when its available */
  vsprintf(buff, format, arg);

  nout->content = calloc(strlen("(,)")
       + airStrlen(func)
       + 1                      /* '(' */
       + airStrlen(content)
       + 1                      /* ',' */
       + airStrlen(buff)
       + 1                      /* ')' */
       + 1, sizeof(char));      /* '\0' */
  if (!nout->content) {
    sprintf(err, "%s: couln't alloc output content!", me);
    biffAdd(NRRD, err); airFree(buff); return 1;
  }
  sprintf(nout->content, "%s(%s%s%s)", func, content,
    airStrlen(buff) ? "," : "", buff);
  airFree(buff);
  return 0;
}

int
_nrrdContentSet (Nrrd *nout, const char *func,
     char *content, const char *format, ...) {
  char me[]="_nrrdContentSet", err[AIR_STRLEN_MED];
  va_list ap;
  
  va_start(ap, format);
  if (_nrrdContentSet_nva(nout, func, content, format, ap)) {
    sprintf(err, "%s:", me);
    biffAdd(NRRD, err); free(content); return 1;
  }
  va_end(ap);

  /* free(content);  */
  return 0;
{'fraction_non_alphanumeric': 0.12821758135016997, 'fraction_numerical': 0.01238465274405051, 'mean_word_length': 3.1559031281533803, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5798637', 'n_tokens_mistral': 2960, 'n_tokens_neox': 2788, 'n_words': 895}