<commit_before>/* /% C %/ */
/***********************************************************************
 * cint (C/C++ interpreter)
 ************************************************************************
 * Source file disp.c
 ************************************************************************
 * Description:
 *  Display information
 ************************************************************************
 * Copyright(c) 1995~2004  <NAME> 
 *
 * For the licensing terms see the file COPYING
 *
 ************************************************************************/

#include "common.h"
#include "Dict.h"

using namespace Cint::Internal;

#ifndef __CINT__
#include <ctype.h>
#include <errno.h>

//______________________________________________________________________________
#ifndef ULONG_LONG_MAX
#define ULONG_LONG_MAX (~((G__uint64)0))
#endif

//______________________________________________________________________________
#ifndef LONG_LONG_MAX
#define LONG_LONG_MAX ((G__int64)(ULONG_LONG_MAX >> 1))
#endif

//______________________________________________________________________________
#ifndef LONG_LONG_MIN
#define LONG_LONG_MIN ((G__int64)(~LONG_LONG_MAX))
#endif

//______________________________________________________________________________
int Cint::Internal::G__browsing = 1;
 
//______________________________________________________________________________
extern "C" G__int64 G__expr_strtoll(const char *nptr, char **endptr, register int base)
{
   /*
    * Convert a string to a long long integer.
    *
    * Ignores `locale' stuff.  Assumes that the upper and lower case
    * alphabets and digits are each contiguous.
    */
   register const char *s = nptr;
   register G__uint64 acc;
   register G__int64 result;
   register int c;
   register G__uint64 cutoff;
   register int neg = 0, any, cutlim;

   /*
    * Skip white space and pick up leading +/- sign if any.
    * If base is 0, allow 0x for hex and 0 for octal, else
    * assume decimal; if base is already 16, allow 0x.
    */
   do {
      c = *s++;
   }
   while (isspace(c));
   if (c == '-') {
      neg = 1;
      c = *s++;
   }
   else if (c == '+')
      c = *s++;
   if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) {
      c = s[1];
      s += 2;
      base = 16;
   }
   if (base == 0)
      base = c == '0' ? 8 : 10;

   /*
    * Compute the cutoff value between legal numbers and illegal
    * numbers.  That is the largest legal value, divided by the
    * base.  An input number that is greater than this value, if
    * followed by a legal input character, is too big.  One that
    * is equal to this value may be valid or not; the limit
    * between valid and invalid numbers is then based on the last
    * digit.  For instance, if the range for long longs is
    * [-2147483648..2147483647] and the input base is 10,
    * cutoff will be set to 214748364 and cutlim to either
    * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
    * a value > 214748364, or equal but the next digit is > 7 (or 8),
    * the number is too big, and we will return a range error.
    *
    * Set any if any `digits' consumed; make it negative to indicate
    * overflow.
    */
   cutoff = neg ? - (G__uint64)(LONG_LONG_MIN) : LONG_LONG_MAX;
   cutlim = (int)(cutoff % (G__uint64) base);
   cutoff /= (G__uint64) base;
   for (acc = 0, any = 0;; c = *s++) {
      if (isdigit(c))
         c -= '0';
      else if (isalpha(c))
         c -= isupper(c) ? 'A' - 10 : 'a' - 10;
      else
         break;
      if (c >= base)
         break;
      if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
         any = -1;
      else {
         any = 1;
         acc *= base;
         acc += c;
      }
   }
   if (any < 0) {
      result = neg ? LONG_LONG_MIN : LONG_LONG_MAX;
      errno = ERANGE;
   }
   else {
      result = acc;
      if (neg) {
         result = acc;
      }
   }
   if (endptr != 0)
      *endptr = (char *)(any ? s - 1 : nptr);
   return (result);
}

//______________________________________________________________________________
extern "C" G__uint64 G__expr_strtoull(const char *nptr, char **endptr, register int base)
{
   /*
    * Convert a string to an unsigned long integer.
    *
    * Ignores `locale' stuff.  Assumes that the upper and lower case
    * alphabets and digits are each contiguous.
    */
   register const char *s = nptr;
   register G__uint64 acc;
   register int c;
   register G__uint64 cutoff;
   register int neg = 0, any, cutlim;

   /*
    * See strtoll for comments as to the logic used.
    */
   do {
      c = *s++;
   }
   while (isspace(c));
   if (c == '-') {
      neg = 1;
      c = *s++;
   }
   else if (c == '+')
      c = *s++;
   if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) {
      c = s[1];
      s += 2;
      base = 16;
   }
   if (base == 0)
      base = c == '0' ? 8 : 10;
   cutoff =
      (G__uint64) ULONG_LONG_MAX / (G__uint64) base;
   cutlim = (int)
            ((G__uint64) ULONG_LONG_MAX % (G__uint64) base);
   for (acc = 0, any = 0;; c = *s++) {
      if (isdigit(c))
         c -= '0';
      else if (isalpha(c))
         c -= isupper(c) ? 'A' - 10 : 'a' - 10;
      else
         break;
      if (c >= base)
         break;
      if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
         any = -1;
      else {
         any = 1;
         acc *= base;
         acc += c;
      }
   }
   if (any < 0) {
      acc = ULONG_LONG_MAX;
      errno = ERANGE;
   }
   else if (neg)
      acc = -acc;<commit_msg>Ignore unary - for ulonglong, improve cutoff calculation for -LONG_LONG_MIN. Gets rid of VC9 warnings. (r27209 for CINT7)<commit_after>/* /% C %/ */
/***********************************************************************
 * cint (C/C++ interpreter)
 ************************************************************************
 * Source file disp.c
 ************************************************************************
 * Description:
 *  Display information
 ************************************************************************
 * Copyright(c) 1995~2004  <NAME> 
 *
 * For the licensing terms see the file COPYING
 *
 ************************************************************************/

#include "common.h"
#include "Dict.h"

using namespace Cint::Internal;

#ifndef __CINT__
#include <ctype.h>
#include <errno.h>

//______________________________________________________________________________
#ifndef ULONG_LONG_MAX
#define ULONG_LONG_MAX (~((G__uint64)0))
#endif

//______________________________________________________________________________
#ifndef LONG_LONG_MAX
#define LONG_LONG_MAX ((G__int64)(ULONG_LONG_MAX >> 1))
#endif

//______________________________________________________________________________
#ifndef LONG_LONG_MIN
#define LONG_LONG_MIN ((G__int64)(~LONG_LONG_MAX))
#endif

//______________________________________________________________________________
int Cint::Internal::G__browsing = 1;
 
//______________________________________________________________________________
extern "C" G__int64 G__expr_strtoll(const char *nptr, char **endptr, register int base)
{
   /*
    * Convert a string to a long long integer.
    *
    * Ignores `locale' stuff.  Assumes that the upper and lower case
    * alphabets and digits are each contiguous.
    */
   register const char *s = nptr;
   register G__uint64 acc;
   register G__int64 result;
   register int c;
   register G__uint64 cutoff;
   register int neg = 0, any, cutlim;

   /*
    * Skip white space and pick up leading +/- sign if any.
    * If base is 0, allow 0x for hex and 0 for octal, else
    * assume decimal; if base is already 16, allow 0x.
    */
   do {
      c = *s++;
   }
   while (isspace(c));
   if (c == '-') {
      neg = 1;
      c = *s++;
   }
   else if (c == '+')
      c = *s++;
   if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) {
      c = s[1];
      s += 2;
      base = 16;
   }
   if (base == 0)
      base = c == '0' ? 8 : 10;

   /*
    * Compute the cutoff value between legal numbers and illegal
    * numbers.  That is the largest legal value, divided by the
    * base.  An input number that is greater than this value, if
    * followed by a legal input character, is too big.  One that
    * is equal to this value may be valid or not; the limit
    * between valid and invalid numbers is then based on the last
    * digit.  For instance, if the range for long longs is
    * [-2147483648..2147483647] and the input base is 10,
    * cutoff will be set to 214748364 and cutlim to either
    * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
    * a value > 214748364, or equal but the next digit is > 7 (or 8),
    * the number is too big, and we will return a range error.
    *
    * Set any if any `digits' consumed; make it negative to indicate
    * overflow.
    */
   if (neg) {
      // -(-2147483648) is not a valid long long, but -(-2147483648 + 42) is!
      cutoff = -(LONG_LONG_MIN + 42);
      cutoff += 42; // fixup offset for unary -
   } else {
      cutoff = LONG_LONG_MAX;
   }
   cutlim = (int)(cutoff % (G__uint64) base);
   cutoff /= (G__uint64) base;
   for (acc = 0, any = 0;; c = *s++) {
      if (isdigit(c))
         c -= '0';
      else if (isalpha(c))
         c -= isupper(c) ? 'A' - 10 : 'a' - 10;
      else
         break;
      if (c >= base)
         break;
      if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
         any = -1;
      else {
         any = 1;
         acc *= base;
         acc += c;
      }
   }
   if (any < 0) {
      result = neg ? LONG_LONG_MIN : LONG_LONG_MAX;
      errno = ERANGE;
   }
   else {
      result = acc;
      if (neg) {
         result = acc;
      }
   }
   if (endptr != 0)
      *endptr = (char *)(any ? s - 1 : nptr);
   return (result);
}

//______________________________________________________________________________
extern "C" G__uint64 G__expr_strtoull(const char *nptr, char **endptr, register int base)
{
   /*
    * Convert a string to an unsigned long integer.
    *
    * Ignores `locale' stuff.  Assumes that the upper and lower case
    * alphabets and digits are each contiguous.
    */
   register const char *s = nptr;
   register G__uint64 acc;
   register int c;
   register G__uint64 cutoff;
   register int neg = 0, any, cutlim;

   /*
    * See strtoll for comments as to the logic used.
    */
   do {
      c = *s++;
   }
   while (isspace(c));
   if (c == '-') {
      neg = 1;
      c = *s++;
   }
   else if (c == '+')
      c = *s++;
   if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) {
      c = s[1];
      s += 2;
      base = 16;
   }
   if (base == 0)
      base = c == '0' ? 8 : 10;
   cutoff =
      (G__uint64) ULONG_LONG_MAX / (G__uint64) base;
   cutlim = (int)
            ((G__uint64) ULONG_LONG_MAX % (G__uint64) base);
   for (acc = 0, any = 0;; c = *s++) {
      if (isdigit(c))
         c -= '0';
      else if (isalpha(c))
         c -= isupper(c) ? 'A' - 10 : 'a' - 10;
      else
         break;
      if (c >= base)
         break;
      if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
         any = -1;
      else {
         any = 1;
         acc *= base;
         acc += c;
      }
   }
   if (any < 0) {
      acc = ULONG_LONG_MAX;
      errno = ERANGE;
   }
   else if (neg) {
      // IGNORE - we're unsigned!
      // acc = -acc;
   }
{'fraction_non_alphanumeric': 0.1843414506415292, 'fraction_numerical': 0.029065200314218383, 'mean_word_length': 2.4763349514563107, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, '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': '7521626', 'n_tokens_mistral': 3888, 'n_tokens_neox': 3524, 'n_words': 1201}