mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-03-27 18:50:07 +03:00
Bjorn sent an update for the TRIO portability layer. Daniel
* trio.c trio.h triodef.h trionan.c trionan.h triop.h triostr.c triostr.h: Bjorn sent an update for the TRIO portability layer. Daniel
This commit is contained in:
parent
d6c8650b5a
commit
a48ed3d6de
@ -1,3 +1,8 @@
|
||||
Thu Apr 3 17:24:44 CEST 2003 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* trio.c trio.h triodef.h trionan.c trionan.h triop.h triostr.c
|
||||
triostr.h: Bjorn sent an update for the TRIO portability layer.
|
||||
|
||||
Tue Apr 1 21:57:26 CEST 2003 Igor Zlatkovic <igor@zlatkovic.com>
|
||||
|
||||
* win32/libxml2.def.src: exported new functions
|
||||
|
247
trio.c
247
trio.c
@ -31,7 +31,8 @@
|
||||
* - Multibyte characters (done for format parsing, except scan groups)
|
||||
* - Complex numbers? (C99 _Complex)
|
||||
* - Boolean values? (C99 _Bool)
|
||||
* - C99 NaN(n-char-sequence) missing
|
||||
* - C99 NaN(n-char-sequence) missing. The n-char-sequence can be used
|
||||
* to print the mantissa, e.g. NaN(0xc000000000000000)
|
||||
* - Should we support the GNU %a alloc modifier? GNU has an ugly hack
|
||||
* for %a, because C99 used %a for other purposes. If specified as
|
||||
* %as or %a[ it is interpreted as the alloc modifier, otherwise as
|
||||
@ -57,6 +58,10 @@
|
||||
*
|
||||
*************************************************************************/
|
||||
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
#include <float.h>
|
||||
|
||||
#if defined(__STDC_ISO_10646__) || defined(MB_LEN_MAX) || defined(USE_MULTIBYTE) || TRIO_WIDECHAR
|
||||
# define TRIO_COMPILER_SUPPORTS_MULTIBYTE
|
||||
# if !defined(MB_LEN_MAX)
|
||||
@ -64,6 +69,10 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if (defined(TRIO_COMPILER_MSVC) && (_MSC_VER >= 1100)) || defined(TRIO_COMPILER_BCB)
|
||||
# define TRIO_COMPILER_SUPPORTS_MSVC_INT
|
||||
#endif
|
||||
|
||||
/*************************************************************************
|
||||
* Generic definitions
|
||||
*/
|
||||
@ -71,14 +80,12 @@
|
||||
#if !(defined(DEBUG) || defined(NDEBUG))
|
||||
# define NDEBUG
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#if !defined(TRIO_COMPILER_SUPPORTS_C99)
|
||||
# define isblank(x) (((x)==32) || ((x)==9))
|
||||
#endif
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
#include <float.h>
|
||||
#if defined(TRIO_COMPILER_ANCIENT)
|
||||
# include <varargs.h>
|
||||
#else
|
||||
@ -110,6 +117,8 @@
|
||||
# define TRIO_ERROR_RETURN(x,y) (-1)
|
||||
#endif
|
||||
|
||||
typedef unsigned long trio_flags_t;
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Platform specific definitions
|
||||
@ -129,8 +138,6 @@
|
||||
# define write _write
|
||||
#endif /* TRIO_PLATFORM_WIN32 */
|
||||
|
||||
#define TRIO_MSVC_VERSION_5 1100
|
||||
|
||||
#if TRIO_WIDECHAR
|
||||
# if defined(TRIO_COMPILER_SUPPORTS_ISO94)
|
||||
# include <wchar.h>
|
||||
@ -179,14 +186,9 @@ typedef int trio_wint_t;
|
||||
#if defined(USE_LONGLONG)
|
||||
typedef signed long long int trio_longlong_t;
|
||||
typedef unsigned long long int trio_ulonglong_t;
|
||||
#elif defined(TRIO_COMPILER_MSVC)
|
||||
# if (_MSC_VER >= TRIO_MSVC_VERSION_5)
|
||||
#elif defined(TRIO_COMPILER_SUPPORTS_MSVC_INT)
|
||||
typedef signed __int64 trio_longlong_t;
|
||||
typedef unsigned __int64 trio_ulonglong_t;
|
||||
# else
|
||||
typedef signed long int trio_longlong_t;
|
||||
typedef unsigned long int trio_ulonglong_t;
|
||||
# endif
|
||||
#else
|
||||
typedef TRIO_SIGNED long int trio_longlong_t;
|
||||
typedef unsigned long int trio_ulonglong_t;
|
||||
@ -209,7 +211,7 @@ typedef int8_t trio_int8_t;
|
||||
typedef int16_t trio_int16_t;
|
||||
typedef int32_t trio_int32_t;
|
||||
typedef int64_t trio_int64_t;
|
||||
#elif defined(TRIO_COMPILER_MSVC) && (_MSC_VER >= TRIO_MSVC_VERSION_5)
|
||||
#elif defined(TRIO_COMPILER_SUPPORTS_MSVC_INT)
|
||||
typedef trio_longlong_t trio_intmax_t;
|
||||
typedef trio_ulonglong_t trio_uintmax_t;
|
||||
typedef __int8 trio_int8_t;
|
||||
@ -296,7 +298,7 @@ enum {
|
||||
TYPE_PRINT = 1,
|
||||
TYPE_SCAN = 2,
|
||||
|
||||
/* Flags. Use maximum 32 */
|
||||
/* Flags. FLAGS_LAST must be less than ULONG_MAX */
|
||||
FLAGS_NEW = 0,
|
||||
FLAGS_STICKY = 1,
|
||||
FLAGS_SPACE = 2 * FLAGS_STICKY,
|
||||
@ -329,6 +331,7 @@ enum {
|
||||
FLAGS_IGNORE_PARAMETER = 2 * FLAGS_IGNORE,
|
||||
FLAGS_VARSIZE_PARAMETER = 2 * FLAGS_IGNORE_PARAMETER,
|
||||
FLAGS_FIXED_SIZE = 2 * FLAGS_VARSIZE_PARAMETER,
|
||||
FLAGS_LAST = FLAGS_FIXED_SIZE,
|
||||
/* Reused flags */
|
||||
FLAGS_EXCLUDE = FLAGS_SHORT,
|
||||
FLAGS_USER_DEFINED = FLAGS_IGNORE,
|
||||
@ -616,7 +619,7 @@ typedef struct {
|
||||
/* An indication of which entry in the data union is used */
|
||||
int type;
|
||||
/* The flags */
|
||||
unsigned long flags;
|
||||
trio_flags_t flags;
|
||||
/* The width qualifier */
|
||||
int width;
|
||||
/* The precision qualifier */
|
||||
@ -710,7 +713,6 @@ typedef struct _trio_userdef_t {
|
||||
char *name;
|
||||
} trio_userdef_t;
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
*
|
||||
* Internal Variables
|
||||
@ -1157,7 +1159,7 @@ TRIO_ARGS5((type, format, parameters, arglist, argarray),
|
||||
int currentParam;
|
||||
int maxParam = -1;
|
||||
/* Utility variables */
|
||||
unsigned long flags;
|
||||
trio_flags_t flags;
|
||||
int width;
|
||||
int precision;
|
||||
int varsize;
|
||||
@ -1691,6 +1693,7 @@ TRIO_ARGS5((type, format, parameters, arglist, argarray),
|
||||
break;
|
||||
|
||||
case SPECIFIER_OCTAL:
|
||||
flags |= FLAGS_UNSIGNED;
|
||||
flags &= ~FLAGS_BASE_PARAMETER;
|
||||
base = BASE_OCTAL;
|
||||
parameters[pos].type = FORMAT_INT;
|
||||
@ -2146,12 +2149,15 @@ TrioWriteNumber
|
||||
TRIO_ARGS6((self, number, flags, width, precision, base),
|
||||
trio_class_t *self,
|
||||
trio_uintmax_t number,
|
||||
unsigned long flags,
|
||||
trio_flags_t flags,
|
||||
int width,
|
||||
int precision,
|
||||
int base)
|
||||
{
|
||||
BOOLEAN_T isNegative;
|
||||
BOOLEAN_T isNumberZero;
|
||||
BOOLEAN_T isPrecisionZero;
|
||||
BOOLEAN_T ignoreNumber;
|
||||
char buffer[MAX_CHARS_IN(trio_uintmax_t) * (1 + MAX_LOCALE_SEPARATOR_LENGTH) + 1];
|
||||
char *bufferend;
|
||||
char *pointer;
|
||||
@ -2169,11 +2175,23 @@ TRIO_ARGS6((self, number, flags, width, precision, base),
|
||||
if (base == NO_BASE)
|
||||
base = BASE_DECIMAL;
|
||||
|
||||
isNegative = (flags & FLAGS_UNSIGNED)
|
||||
? FALSE
|
||||
: ((trio_intmax_t)number < 0);
|
||||
if (isNegative)
|
||||
number = -((trio_intmax_t)number);
|
||||
isNumberZero = (number == 0);
|
||||
isPrecisionZero = (precision == 0);
|
||||
ignoreNumber = (isNumberZero
|
||||
&& isPrecisionZero
|
||||
&& !((flags & FLAGS_ALTERNATIVE) && (base == BASE_OCTAL)));
|
||||
|
||||
if (flags & FLAGS_UNSIGNED)
|
||||
{
|
||||
isNegative = FALSE;
|
||||
flags &= ~FLAGS_SHOWSIGN;
|
||||
}
|
||||
else
|
||||
{
|
||||
isNegative = ((trio_intmax_t)number < 0);
|
||||
if (isNegative)
|
||||
number = -((trio_intmax_t)number);
|
||||
}
|
||||
|
||||
if (flags & FLAGS_QUAD)
|
||||
number &= (trio_ulonglong_t)-1;
|
||||
@ -2209,8 +2227,11 @@ TRIO_ARGS6((self, number, flags, width, precision, base),
|
||||
}
|
||||
}
|
||||
|
||||
/* Adjust width */
|
||||
width -= (bufferend - pointer) - 1;
|
||||
if (! ignoreNumber)
|
||||
{
|
||||
/* Adjust width */
|
||||
width -= (bufferend - pointer) - 1;
|
||||
}
|
||||
|
||||
/* Adjust precision */
|
||||
if (NO_PRECISION != precision)
|
||||
@ -2221,10 +2242,15 @@ TRIO_ARGS6((self, number, flags, width, precision, base),
|
||||
flags |= FLAGS_NILPADDING;
|
||||
}
|
||||
|
||||
/* Calculate padding */
|
||||
count = (! ((flags & FLAGS_LEFTADJUST) || (precision == NO_PRECISION)))
|
||||
? precision
|
||||
: 0;
|
||||
|
||||
/* Adjust width further */
|
||||
if (isNegative || (flags & FLAGS_SHOWSIGN) || (flags & FLAGS_SPACE))
|
||||
width--;
|
||||
if (flags & FLAGS_ALTERNATIVE)
|
||||
if ((flags & FLAGS_ALTERNATIVE) && !isNumberZero)
|
||||
{
|
||||
switch (base)
|
||||
{
|
||||
@ -2233,7 +2259,8 @@ TRIO_ARGS6((self, number, flags, width, precision, base),
|
||||
width -= 2;
|
||||
break;
|
||||
case BASE_OCTAL:
|
||||
width--;
|
||||
if (!(flags & FLAGS_NILPADDING) || (count == 0))
|
||||
width--;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -2244,7 +2271,6 @@ TRIO_ARGS6((self, number, flags, width, precision, base),
|
||||
if (! ((flags & FLAGS_LEFTADJUST) ||
|
||||
((flags & FLAGS_NILPADDING) && (precision == NO_PRECISION))))
|
||||
{
|
||||
count = (precision == NO_PRECISION) ? 0 : precision;
|
||||
while (width-- > count)
|
||||
self->OutStream(self, CHAR_ADJUST);
|
||||
}
|
||||
@ -2257,7 +2283,8 @@ TRIO_ARGS6((self, number, flags, width, precision, base),
|
||||
else if (flags & FLAGS_SPACE)
|
||||
self->OutStream(self, ' ');
|
||||
|
||||
if (flags & FLAGS_ALTERNATIVE)
|
||||
/* Prefix is not written when the value is zero */
|
||||
if ((flags & FLAGS_ALTERNATIVE) && !isNumberZero)
|
||||
{
|
||||
switch (base)
|
||||
{
|
||||
@ -2267,7 +2294,8 @@ TRIO_ARGS6((self, number, flags, width, precision, base),
|
||||
break;
|
||||
|
||||
case BASE_OCTAL:
|
||||
self->OutStream(self, '0');
|
||||
if (!(flags & FLAGS_NILPADDING) || (count == 0))
|
||||
self->OutStream(self, '0');
|
||||
break;
|
||||
|
||||
case BASE_HEX:
|
||||
@ -2292,10 +2320,13 @@ TRIO_ARGS6((self, number, flags, width, precision, base),
|
||||
}
|
||||
}
|
||||
|
||||
/* Output the number itself */
|
||||
while (*(++pointer))
|
||||
if (! ignoreNumber)
|
||||
{
|
||||
self->OutStream(self, *pointer);
|
||||
/* Output the number itself */
|
||||
while (*(++pointer))
|
||||
{
|
||||
self->OutStream(self, *pointer);
|
||||
}
|
||||
}
|
||||
|
||||
/* Output trailing spaces if needed */
|
||||
@ -2317,7 +2348,7 @@ TrioWriteStringCharacter
|
||||
TRIO_ARGS3((self, ch, flags),
|
||||
trio_class_t *self,
|
||||
int ch,
|
||||
unsigned long flags)
|
||||
trio_flags_t flags)
|
||||
{
|
||||
if (flags & FLAGS_ALTERNATIVE)
|
||||
{
|
||||
@ -2373,7 +2404,7 @@ TrioWriteString
|
||||
TRIO_ARGS5((self, string, flags, width, precision),
|
||||
trio_class_t *self,
|
||||
TRIO_CONST char *string,
|
||||
unsigned long flags,
|
||||
trio_flags_t flags,
|
||||
int width,
|
||||
int precision)
|
||||
{
|
||||
@ -2439,7 +2470,7 @@ TrioWriteWideStringCharacter
|
||||
TRIO_ARGS4((self, wch, flags, width),
|
||||
trio_class_t *self,
|
||||
trio_wchar_t wch,
|
||||
unsigned long flags,
|
||||
trio_flags_t flags,
|
||||
int width)
|
||||
{
|
||||
int size;
|
||||
@ -2479,7 +2510,7 @@ TrioWriteWideString
|
||||
TRIO_ARGS5((self, wstring, flags, width, precision),
|
||||
trio_class_t *self,
|
||||
TRIO_CONST trio_wchar_t *wstring,
|
||||
unsigned long flags,
|
||||
trio_flags_t flags,
|
||||
int width,
|
||||
int precision)
|
||||
{
|
||||
@ -2556,7 +2587,7 @@ TrioWriteDouble
|
||||
TRIO_ARGS6((self, number, flags, width, precision, base),
|
||||
trio_class_t *self,
|
||||
trio_long_double_t number,
|
||||
unsigned long flags,
|
||||
trio_flags_t flags,
|
||||
int width,
|
||||
int precision,
|
||||
int base)
|
||||
@ -2670,9 +2701,19 @@ TRIO_ARGS6((self, number, flags, width, precision, base),
|
||||
|
||||
if (flags & FLAGS_ROUNDING)
|
||||
precision = baseDigits;
|
||||
|
||||
|
||||
if (precision == NO_PRECISION)
|
||||
precision = FLT_DIG;
|
||||
{
|
||||
if (isHex)
|
||||
{
|
||||
keepTrailingZeroes = FALSE;
|
||||
precision = FLT_MANT_DIG;
|
||||
}
|
||||
else
|
||||
{
|
||||
precision = FLT_DIG;
|
||||
}
|
||||
}
|
||||
|
||||
if (isNegative)
|
||||
number = -number;
|
||||
@ -2723,6 +2764,8 @@ TRIO_ARGS6((self, number, flags, width, precision, base),
|
||||
number /= powl(dblBase, (trio_long_double_t)exponent);
|
||||
isExponentNegative = (exponent < 0);
|
||||
uExponent = (isExponentNegative) ? -exponent : exponent;
|
||||
if (isHex)
|
||||
uExponent *= 4; /* log16(2) */
|
||||
/* No thousand separators */
|
||||
flags &= ~FLAGS_QUOTE;
|
||||
}
|
||||
@ -2755,6 +2798,8 @@ TRIO_ARGS6((self, number, flags, width, precision, base),
|
||||
exponent++;
|
||||
isExponentNegative = (exponent < 0);
|
||||
uExponent = (isExponentNegative) ? -exponent : exponent;
|
||||
if (isHex)
|
||||
uExponent *= 4; /* log16(2) */
|
||||
workNumber = (number + 0.5 / dblFractionBase) / dblBase;
|
||||
integerNumber = floorl(workNumber);
|
||||
fractionNumber = workNumber - integerNumber;
|
||||
@ -2811,7 +2856,8 @@ TRIO_ARGS6((self, number, flags, width, precision, base),
|
||||
{
|
||||
exponentDigits = (uExponent == 0)
|
||||
? 1
|
||||
: (int)ceil(TrioLogarithm((double)(uExponent + 1), base));
|
||||
: (int)ceil(TrioLogarithm((double)(uExponent + 1),
|
||||
(isHex) ? 10.0 : base));
|
||||
}
|
||||
else
|
||||
exponentDigits = 0;
|
||||
@ -2977,6 +3023,8 @@ TRIO_ARGS6((self, number, flags, width, precision, base),
|
||||
if (requireTwoDigitExponent)
|
||||
self->OutStream(self, '0');
|
||||
|
||||
if (isHex)
|
||||
base = 10.0;
|
||||
exponentBase = (int)TrioPower(base, exponentDigits - 1);
|
||||
for (i = 0; i < exponentDigits; i++)
|
||||
{
|
||||
@ -3013,7 +3061,7 @@ TRIO_ARGS3((data, format, parameters),
|
||||
int i;
|
||||
TRIO_CONST char *string;
|
||||
trio_pointer_t pointer;
|
||||
unsigned long flags;
|
||||
trio_flags_t flags;
|
||||
int width;
|
||||
int precision;
|
||||
int base;
|
||||
@ -3067,6 +3115,16 @@ TRIO_ARGS3((data, format, parameters),
|
||||
{
|
||||
/* Get width from parameter list */
|
||||
width = (int)parameters[width].data.number.as_signed;
|
||||
if (width < 0)
|
||||
{
|
||||
/*
|
||||
* A negative width is the same as the - flag and
|
||||
* a positive width.
|
||||
*/
|
||||
flags |= FLAGS_LEFTADJUST;
|
||||
flags &= ~FLAGS_NILPADDING;
|
||||
width = -width;
|
||||
}
|
||||
}
|
||||
|
||||
/* Find precision */
|
||||
@ -3077,6 +3135,14 @@ TRIO_ARGS3((data, format, parameters),
|
||||
{
|
||||
/* Get precision from parameter list */
|
||||
precision = (int)parameters[precision].data.number.as_signed;
|
||||
if (precision < 0)
|
||||
{
|
||||
/*
|
||||
* A negative precision is the same as no
|
||||
* precision
|
||||
*/
|
||||
precision = NO_PRECISION;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -4384,7 +4450,9 @@ trio_get_long
|
||||
TRIO_ARGS1((ref),
|
||||
trio_pointer_t ref)
|
||||
{
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_LONG);
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_LONG)
|
||||
? TRUE
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@ -4407,7 +4475,9 @@ trio_get_longlong
|
||||
TRIO_ARGS1((ref),
|
||||
trio_pointer_t ref)
|
||||
{
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_QUAD);
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_QUAD)
|
||||
? TRUE
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@ -4430,7 +4500,9 @@ trio_get_longdouble
|
||||
TRIO_ARGS1((ref),
|
||||
trio_pointer_t ref)
|
||||
{
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_LONGDOUBLE);
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_LONGDOUBLE)
|
||||
? TRUE
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@ -4453,7 +4525,9 @@ trio_get_short
|
||||
TRIO_ARGS1((ref),
|
||||
trio_pointer_t ref)
|
||||
{
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_SHORT);
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_SHORT)
|
||||
? TRUE
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@ -4476,7 +4550,9 @@ trio_get_shortshort
|
||||
TRIO_ARGS1((ref),
|
||||
trio_pointer_t ref)
|
||||
{
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_SHORTSHORT);
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_SHORTSHORT)
|
||||
? TRUE
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@ -4499,7 +4575,9 @@ trio_get_alternative
|
||||
TRIO_ARGS1((ref),
|
||||
trio_pointer_t ref)
|
||||
{
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_ALTERNATIVE);
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_ALTERNATIVE)
|
||||
? TRUE
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@ -4522,7 +4600,9 @@ trio_get_alignment
|
||||
TRIO_ARGS1((ref),
|
||||
trio_pointer_t ref)
|
||||
{
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_LEFTADJUST);
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_LEFTADJUST)
|
||||
? TRUE
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@ -4545,7 +4625,9 @@ trio_get_spacing
|
||||
TRIO_ARGS1((ref),
|
||||
trio_pointer_t ref)
|
||||
{
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_SPACE);
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_SPACE)
|
||||
? TRUE
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@ -4568,7 +4650,9 @@ trio_get_sign
|
||||
TRIO_ARGS1((ref),
|
||||
trio_pointer_t ref)
|
||||
{
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_SHOWSIGN);
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_SHOWSIGN)
|
||||
? TRUE
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@ -4591,7 +4675,9 @@ trio_get_padding
|
||||
TRIO_ARGS1((ref),
|
||||
trio_pointer_t ref)
|
||||
{
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_NILPADDING);
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_NILPADDING)
|
||||
? TRUE
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@ -4614,7 +4700,9 @@ trio_get_quote
|
||||
TRIO_ARGS1((ref),
|
||||
trio_pointer_t ref)
|
||||
{
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_QUOTE);
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_QUOTE)
|
||||
? TRUE
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@ -4637,7 +4725,9 @@ trio_get_upper
|
||||
TRIO_ARGS1((ref),
|
||||
trio_pointer_t ref)
|
||||
{
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_UPPER);
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_UPPER)
|
||||
? TRUE
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@ -4661,7 +4751,9 @@ trio_get_largest
|
||||
TRIO_ARGS1((ref),
|
||||
trio_pointer_t ref)
|
||||
{
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_INTMAX_T);
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_INTMAX_T)
|
||||
? TRUE
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@ -4685,7 +4777,9 @@ trio_get_ptrdiff
|
||||
TRIO_ARGS1((ref),
|
||||
trio_pointer_t ref)
|
||||
{
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_PTRDIFF_T);
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_PTRDIFF_T)
|
||||
? TRUE
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@ -4709,7 +4803,9 @@ trio_get_size
|
||||
TRIO_ARGS1((ref),
|
||||
trio_pointer_t ref)
|
||||
{
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_SIZE_T);
|
||||
return (((trio_reference_t *)ref)->parameter->flags & FLAGS_SIZE_T)
|
||||
? TRUE
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@ -4863,7 +4959,7 @@ TRIO_ARGS2((ref, pointer),
|
||||
trio_pointer_t pointer)
|
||||
{
|
||||
trio_reference_t *self = (trio_reference_t *)ref;
|
||||
unsigned long flags;
|
||||
trio_flags_t flags;
|
||||
trio_uintmax_t number;
|
||||
|
||||
if (NULL == pointer)
|
||||
@ -5024,7 +5120,7 @@ TrioGetCollation(TRIO_NOARGS)
|
||||
char first[2];
|
||||
char second[2];
|
||||
|
||||
/* This is computational expensive */
|
||||
/* This is computationally expensive */
|
||||
first[1] = NIL;
|
||||
second[1] = NIL;
|
||||
for (i = 0; i < MAX_CHARACTER_CLASS; i++)
|
||||
@ -5053,7 +5149,7 @@ TrioGetCharacterClass
|
||||
TRIO_ARGS4((format, indexPointer, flagsPointer, characterclass),
|
||||
TRIO_CONST char *format,
|
||||
int *indexPointer,
|
||||
unsigned long *flagsPointer,
|
||||
trio_flags_t *flagsPointer,
|
||||
int *characterclass)
|
||||
{
|
||||
int index = *indexPointer;
|
||||
@ -5312,7 +5408,7 @@ TrioReadNumber
|
||||
TRIO_ARGS5((self, target, flags, width, base),
|
||||
trio_class_t *self,
|
||||
trio_uintmax_t *target,
|
||||
unsigned long flags,
|
||||
trio_flags_t flags,
|
||||
int width,
|
||||
int base)
|
||||
{
|
||||
@ -5371,12 +5467,12 @@ TRIO_ARGS5((self, target, flags, width, base),
|
||||
if (self->current)
|
||||
{
|
||||
if ((base == BASE_HEX) &&
|
||||
(toupper(self->current) == 'X'))
|
||||
(trio_to_upper(self->current) == 'X'))
|
||||
{
|
||||
self->InStream(self, NULL);
|
||||
}
|
||||
else if ((base == BASE_BINARY) &&
|
||||
(toupper(self->current) == 'B'))
|
||||
(trio_to_upper(self->current) == 'B'))
|
||||
{
|
||||
self->InStream(self, NULL);
|
||||
}
|
||||
@ -5442,7 +5538,7 @@ TrioReadChar
|
||||
TRIO_ARGS4((self, target, flags, width),
|
||||
trio_class_t *self,
|
||||
char *target,
|
||||
unsigned long flags,
|
||||
trio_flags_t flags,
|
||||
int width)
|
||||
{
|
||||
int i;
|
||||
@ -5478,7 +5574,7 @@ TRIO_ARGS4((self, target, flags, width),
|
||||
return 0;
|
||||
ch = (char)number;
|
||||
}
|
||||
else if (toupper(self->current) == 'X')
|
||||
else if (trio_to_upper(self->current) == 'X')
|
||||
{
|
||||
/* Read hexadecimal number */
|
||||
self->InStream(self, NULL);
|
||||
@ -5508,7 +5604,7 @@ TrioReadString
|
||||
TRIO_ARGS4((self, target, flags, width),
|
||||
trio_class_t *self,
|
||||
char *target,
|
||||
unsigned long flags,
|
||||
trio_flags_t flags,
|
||||
int width)
|
||||
{
|
||||
int i;
|
||||
@ -5544,7 +5640,7 @@ TrioReadWideChar
|
||||
TRIO_ARGS4((self, target, flags, width),
|
||||
trio_class_t *self,
|
||||
trio_wchar_t *target,
|
||||
unsigned long flags,
|
||||
trio_flags_t flags,
|
||||
int width)
|
||||
{
|
||||
int i;
|
||||
@ -5605,7 +5701,7 @@ TrioReadWideString
|
||||
TRIO_ARGS4((self, target, flags, width),
|
||||
trio_class_t *self,
|
||||
trio_wchar_t *target,
|
||||
unsigned long flags,
|
||||
trio_flags_t flags,
|
||||
int width)
|
||||
{
|
||||
int i;
|
||||
@ -5652,7 +5748,7 @@ TRIO_ARGS5((self, target, characterclass, flags, width),
|
||||
trio_class_t *self,
|
||||
char *target,
|
||||
int *characterclass,
|
||||
unsigned long flags,
|
||||
trio_flags_t flags,
|
||||
int width)
|
||||
{
|
||||
int ch;
|
||||
@ -5690,7 +5786,7 @@ TrioReadDouble
|
||||
TRIO_ARGS4((self, target, flags, width),
|
||||
trio_class_t *self,
|
||||
trio_pointer_t target,
|
||||
unsigned long flags,
|
||||
trio_flags_t flags,
|
||||
int width)
|
||||
{
|
||||
int ch;
|
||||
@ -5785,7 +5881,7 @@ TRIO_ARGS4((self, target, flags, width),
|
||||
case '0':
|
||||
doubleString[index++] = (char)ch;
|
||||
self->InStream(self, &ch);
|
||||
if (toupper(ch) == 'X')
|
||||
if (trio_to_upper(ch) == 'X')
|
||||
{
|
||||
isHex = TRUE;
|
||||
doubleString[index++] = (char)ch;
|
||||
@ -5834,7 +5930,7 @@ TRIO_ARGS4((self, target, flags, width),
|
||||
doubleString[index++] = (char)ch;
|
||||
self->InStream(self, &ch);
|
||||
}
|
||||
if (isHex ? (toupper(ch) == 'P') : (toupper(ch) == 'E'))
|
||||
if (isHex ? (trio_to_upper(ch) == 'P') : (trio_to_upper(ch) == 'E'))
|
||||
{
|
||||
/* Exponent */
|
||||
doubleString[index++] = (char)ch;
|
||||
@ -5844,8 +5940,7 @@ TRIO_ARGS4((self, target, flags, width),
|
||||
doubleString[index++] = (char)ch;
|
||||
self->InStream(self, &ch);
|
||||
}
|
||||
while ((isHex ? isxdigit(ch) : isdigit(ch)) &&
|
||||
(index - start < width))
|
||||
while (isdigit(ch) && (index - start < width))
|
||||
{
|
||||
doubleString[index++] = (char)ch;
|
||||
self->InStream(self, &ch);
|
||||
@ -5877,7 +5972,7 @@ TrioReadPointer
|
||||
TRIO_ARGS3((self, target, flags),
|
||||
trio_class_t *self,
|
||||
trio_pointer_t *target,
|
||||
unsigned long flags)
|
||||
trio_flags_t flags)
|
||||
{
|
||||
trio_uintmax_t number;
|
||||
char buffer[sizeof(internalNullString)];
|
||||
@ -5933,7 +6028,7 @@ TRIO_ARGS3((data, format, parameters),
|
||||
int ch;
|
||||
int index; /* Index of format string */
|
||||
int i; /* Index of current parameter */
|
||||
unsigned long flags;
|
||||
trio_flags_t flags;
|
||||
int width;
|
||||
int base;
|
||||
trio_pointer_t pointer;
|
||||
|
16
trio.h
16
trio.h
@ -22,14 +22,6 @@
|
||||
#ifndef TRIO_TRIO_H
|
||||
#define TRIO_TRIO_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if defined(TRIO_COMPILER_ANCIENT)
|
||||
# include <varargs.h>
|
||||
#else
|
||||
# include <stdarg.h>
|
||||
#endif
|
||||
|
||||
#if !defined(WITHOUT_TRIO)
|
||||
|
||||
/*
|
||||
@ -42,6 +34,14 @@
|
||||
|
||||
#include "triodef.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if defined(TRIO_COMPILER_ANCIENT)
|
||||
# include <varargs.h>
|
||||
#else
|
||||
# include <stdarg.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
76
triodef.h
76
triodef.h
@ -42,11 +42,17 @@
|
||||
# define TRIO_COMPILER_BCB
|
||||
#endif
|
||||
|
||||
#if defined(unix) || defined(__unix) || defined(__unix__)
|
||||
#if defined(VMS) || defined(__VMS)
|
||||
/*
|
||||
* VMS is placed first to avoid identifying the platform as Unix
|
||||
* based on the DECC compiler later on.
|
||||
*/
|
||||
# define TRIO_PLATFORM_VMS
|
||||
#elif defined(unix) || defined(__unix) || defined(__unix__)
|
||||
# define TRIO_PLATFORM_UNIX
|
||||
#elif defined(TRIO_COMPILER_XLC) || defined(_AIX)
|
||||
# define TRIO_PLATFORM_UNIX
|
||||
#elif ( defined(TRIO_COMPILER_DECC) && !defined(__VMS) ) || defined(__osf__)
|
||||
#elif defined(TRIO_COMPILER_DECC) || defined(__osf___)
|
||||
# define TRIO_PLATFORM_UNIX
|
||||
#elif defined(__NetBSD__)
|
||||
# define TRIO_PLATFORM_UNIX
|
||||
@ -59,13 +65,23 @@
|
||||
# define TRIO_PLATFORM_UNIX
|
||||
#elif defined(TRIO_COMPILER_MSVC) || defined(WIN32) || defined(_WIN32)
|
||||
# define TRIO_PLATFORM_WIN32
|
||||
#elif defined(VMS) || defined(__VMS)
|
||||
# define TRIO_PLATFORM_VMS
|
||||
#elif defined(mpeix) || defined(__mpexl)
|
||||
# define TRIO_PLATFORM_MPEIX
|
||||
#endif
|
||||
|
||||
#if defined(__STDC__) || defined(TRIO_COMPILER_MSVC)
|
||||
#if defined(_AIX)
|
||||
# define TRIO_PLATFORM_AIX
|
||||
#elif defined(__hpux)
|
||||
# define TRIO_PLATFORM_HPUX
|
||||
#elif defined(sun) || defined(__sun__)
|
||||
# if defined(__SVR4) || defined(__svr4__)
|
||||
# define TRIO_PLATFORM_SOLARIS
|
||||
# else
|
||||
# define TRIO_PLATFORM_SUNOS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__STDC__) || defined(TRIO_COMPILER_MSVC) || defined(TRIO_COMPILER_BCB)
|
||||
# define TRIO_COMPILER_SUPPORTS_C89
|
||||
# if defined(__STDC_VERSION__)
|
||||
# define TRIO_COMPILER_SUPPORTS_C90
|
||||
@ -82,18 +98,6 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(TRIO_PLATFORM_VMS)
|
||||
/* The compiler does support C99 but the library still does not have things
|
||||
* the standard requires (like nan() and strtof()) as of __CRTL_VER 70300022.
|
||||
*/
|
||||
# undef TRIO_COMPILER_SUPPORTS_C99
|
||||
|
||||
/* Computations done with constants at compile time can trigger these
|
||||
* even when compiling with IEEE enabled.
|
||||
*/
|
||||
# pragma message disable (UNDERFLOW,FLOATOVERFL)
|
||||
#endif /* TRIO_PLATFORM_VMS */
|
||||
|
||||
#if defined(_XOPEN_SOURCE)
|
||||
# if defined(_XOPEN_SOURCE_EXTENDED)
|
||||
# define TRIO_COMPILER_SUPPORTS_UNIX95
|
||||
@ -141,7 +145,7 @@ typedef char * trio_pointer_t;
|
||||
# define TRIO_VARGS4(list,a1,a2,a3,a4) list a1; a2; a3; a4
|
||||
# define TRIO_VARGS5(list,a1,a2,a3,a4,a5) list a1; a2; a3; a4; a5
|
||||
# define TRIO_VA_DECL va_dcl
|
||||
# define TRIO_VA_START(x,y) va_start((x))
|
||||
# define TRIO_VA_START(x,y) va_start(x)
|
||||
# define TRIO_VA_END(x) va_end(x)
|
||||
#else /* ANSI C */
|
||||
# define TRIO_CONST const
|
||||
@ -163,7 +167,7 @@ typedef void * trio_pointer_t;
|
||||
# define TRIO_VARGS4 TRIO_ARGS4
|
||||
# define TRIO_VARGS5 TRIO_ARGS5
|
||||
# define TRIO_VA_DECL ...
|
||||
# define TRIO_VA_START(x,y) va_start((x),(y))
|
||||
# define TRIO_VA_START(x,y) va_start(x,y)
|
||||
# define TRIO_VA_END(x) va_end(x)
|
||||
#endif
|
||||
|
||||
@ -179,4 +183,38 @@ typedef void * trio_pointer_t;
|
||||
# define TRIO_INLINE
|
||||
#endif
|
||||
|
||||
/*************************************************************************
|
||||
* Workarounds
|
||||
*/
|
||||
|
||||
#if defined(TRIO_PLATFORM_VMS)
|
||||
/*
|
||||
* Computations done with constants at compile time can trigger these
|
||||
* even when compiling with IEEE enabled.
|
||||
*/
|
||||
# pragma message disable (UNDERFLOW, FLOATOVERFL)
|
||||
|
||||
# if (__CRTL_VER > 80000000)
|
||||
/*
|
||||
* Although the compiler supports C99 language constructs, the C
|
||||
* run-time library does not contain all C99 functions.
|
||||
*
|
||||
* This was the case for 70300022. Update the 80000000 value when
|
||||
* it has been accurately determined what version of the library
|
||||
* supports C99.
|
||||
*/
|
||||
# if defined(TRIO_COMPILER_SUPPORTS_C99)
|
||||
# undef TRIO_COMPILER_SUPPORTS_C99
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Not all preprocessors supports the LL token.
|
||||
*/
|
||||
#if defined(TRIO_COMPILER_BCB)
|
||||
#else
|
||||
# define TRIO_COMPILER_SUPPORTS_LL
|
||||
#endif
|
||||
|
||||
#endif /* TRIO_TRIODEF_H */
|
||||
|
192
trionan.c
192
trionan.c
@ -69,7 +69,9 @@
|
||||
#define TRIO_TRUE (1 == 1)
|
||||
#define TRIO_FALSE (0 == 1)
|
||||
|
||||
/* We must enable IEEE floating-point on Alpha */
|
||||
/*
|
||||
* We must enable IEEE floating-point on Alpha
|
||||
*/
|
||||
#if defined(__alpha) && !defined(_IEEE_FP)
|
||||
# if defined(TRIO_COMPILER_DECC)
|
||||
# if defined(TRIO_PLATFORM_VMS)
|
||||
@ -372,11 +374,12 @@ TRIO_ARGS1((number),
|
||||
*/
|
||||
return isnan(number);
|
||||
|
||||
#elif defined(TRIO_COMPILER_MSVC)
|
||||
#elif defined(TRIO_COMPILER_MSVC) || defined(TRIO_COMPILER_BCB)
|
||||
/*
|
||||
* MSVC has an _isnan() function
|
||||
* Microsoft Visual C++ and Borland C++ Builder have an _isnan()
|
||||
* function.
|
||||
*/
|
||||
return _isnan(number);
|
||||
return _isnan(number) ? TRIO_TRUE : TRIO_FALSE;
|
||||
|
||||
#elif defined(USE_IEEE_754)
|
||||
/*
|
||||
@ -449,9 +452,10 @@ TRIO_ARGS1((number),
|
||||
? ((number > 0.0) ? 1 : -1)
|
||||
: 0;
|
||||
|
||||
#elif defined(TRIO_COMPILER_MSVC)
|
||||
#elif defined(TRIO_COMPILER_MSVC) || defined(TRIO_COMPILER_BCB)
|
||||
/*
|
||||
* MSVC has an _fpclass() function that can be used to detect infinity.
|
||||
* Microsoft Visual C++ and Borland C++ Builder have an _fpclass()
|
||||
* function that can be used to detect infinity.
|
||||
*/
|
||||
return ((_fpclass(number) == _FPCLASS_PINF)
|
||||
? 1
|
||||
@ -514,9 +518,9 @@ TRIO_ARGS1((number),
|
||||
*/
|
||||
return isfinite(number);
|
||||
|
||||
#elif defined(TRIO_COMPILER_MSVC)
|
||||
#elif defined(TRIO_COMPILER_MSVC) || defined(TRIO_COMPILER_BCB)
|
||||
/*
|
||||
* MSVC uses _finite().
|
||||
* Microsoft Visual C++ and Borland C++ Builder use _finite().
|
||||
*/
|
||||
return _finite(number);
|
||||
|
||||
@ -538,6 +542,7 @@ TRIO_ARGS1((number),
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The sign of NaN is always false
|
||||
*/
|
||||
@ -565,124 +570,106 @@ TRIO_ARGS2((number, is_negative),
|
||||
return TRIO_FP_NORMAL;
|
||||
}
|
||||
|
||||
#elif defined(TRIO_COMPILER_DECC)
|
||||
#else
|
||||
# if defined(TRIO_COMPILER_DECC)
|
||||
/*
|
||||
* DECC has an fp_class() function.
|
||||
*/
|
||||
switch (fp_class(number)) {
|
||||
case FP_QNAN:
|
||||
case FP_SNAN:
|
||||
*is_negative = TRIO_FALSE; /* NaN has no sign */
|
||||
return TRIO_FP_NAN;
|
||||
case FP_POS_INF:
|
||||
*is_negative = TRIO_FALSE;
|
||||
return TRIO_FP_INFINITE;
|
||||
case FP_NEG_INF:
|
||||
*is_negative = TRIO_TRUE;
|
||||
return TRIO_FP_INFINITE;
|
||||
case FP_POS_DENORM:
|
||||
*is_negative = TRIO_FALSE;
|
||||
return TRIO_FP_SUBNORMAL;
|
||||
case FP_NEG_DENORM:
|
||||
*is_negative = TRIO_TRUE;
|
||||
return TRIO_FP_SUBNORMAL;
|
||||
case FP_POS_ZERO:
|
||||
*is_negative = TRIO_FALSE;
|
||||
return TRIO_FP_ZERO;
|
||||
case FP_NEG_ZERO:
|
||||
*is_negative = TRIO_TRUE;
|
||||
return TRIO_FP_ZERO;
|
||||
case FP_POS_NORM:
|
||||
*is_negative = TRIO_FALSE;
|
||||
return TRIO_FP_NORMAL;
|
||||
case FP_NEG_NORM:
|
||||
*is_negative = TRIO_TRUE;
|
||||
return TRIO_FP_NORMAL;
|
||||
default:
|
||||
/* Just in case... */
|
||||
*is_negative = (number < 0.0);
|
||||
return TRIO_FP_NORMAL;
|
||||
}
|
||||
|
||||
#elif defined(TRIO_COMPILER_MSVC)
|
||||
# define TRIO_FPCLASSIFY(n) fp_class(n)
|
||||
# define TRIO_QUIET_NAN FP_QNAN
|
||||
# define TRIO_SIGNALLING_NAN FP_SNAN
|
||||
# define TRIO_POSITIVE_INFINITY FP_POS_INF
|
||||
# define TRIO_NEGATIVE_INFINITY FP_NEG_INF
|
||||
# define TRIO_POSITIVE_SUBNORMAL FP_POS_DENORM
|
||||
# define TRIO_NEGATIVE_SUBNORMAL FP_NEG_DENORM
|
||||
# define TRIO_POSITIVE_ZERO FP_POS_ZERO
|
||||
# define TRIO_NEGATIVE_ZERO FP_NEG_ZERO
|
||||
# define TRIO_POSITIVE_NORMAL FP_POS_NORM
|
||||
# define TRIO_NEGATIVE_NORMAL FP_NEG_NORM
|
||||
|
||||
# elif defined(TRIO_COMPILER_MSVC) || defined(TRIO_COMPILER_BCB)
|
||||
/*
|
||||
* MSVC has an _fpclass() function.
|
||||
* Microsoft Visual C++ and Borland C++ Builder have an _fpclass()
|
||||
* function.
|
||||
*/
|
||||
switch (_fpclass(number)) {
|
||||
case _FPCLASS_QNAN:
|
||||
case _FPCLASS_SNAN:
|
||||
*is_negative = TRIO_FALSE;
|
||||
return TRIO_FP_NAN;
|
||||
case _FPCLASS_PINF:
|
||||
*is_negative = TRIO_FALSE;
|
||||
return TRIO_FP_INFINITE;
|
||||
case _FPCLASS_NINF:
|
||||
*is_negative = TRIO_TRUE;
|
||||
return TRIO_FP_INFINITE;
|
||||
case _FPCLASS_PD:
|
||||
*is_negative = TRIO_FALSE;
|
||||
return TRIO_FP_SUBNORMAL;
|
||||
case _FPCLASS_ND:
|
||||
*is_negative = TRIO_TRUE;
|
||||
return TRIO_FP_SUBNORMAL;
|
||||
case _FPCLASS_PZ:
|
||||
*is_negative = TRIO_FALSE;
|
||||
return TRIO_FP_ZERO;
|
||||
case _FPCLASS_NZ:
|
||||
*is_negative = TRIO_TRUE;
|
||||
return TRIO_FP_ZERO;
|
||||
case _FPCLASS_PN:
|
||||
*is_negative = TRIO_FALSE;
|
||||
return TRIO_FP_NORMAL;
|
||||
case _FPCLASS_NN:
|
||||
*is_negative = TRIO_TRUE;
|
||||
return TRIO_FP_NORMAL;
|
||||
default:
|
||||
/* Just in case... */
|
||||
*is_negative = (number < 0.0);
|
||||
return TRIO_FP_NORMAL;
|
||||
}
|
||||
|
||||
#elif defined(FP_PLUS_NORM) || defined(__hpux)
|
||||
|
||||
# define TRIO_FPCLASSIFY(n) _fpclass(n)
|
||||
# define TRIO_QUIET_NAN _FPCLASS_QNAN
|
||||
# define TRIO_SIGNALLING_NAN _FPCLASS_SNAN
|
||||
# define TRIO_POSITIVE_INFINITY _FPCLASS_PINF
|
||||
# define TRIO_NEGATIVE_INFINITY _FPCLASS_NINF
|
||||
# define TRIO_POSITIVE_SUBNORMAL _FPCLASS_PD
|
||||
# define TRIO_NEGATIVE_SUBNORMAL _FPCLASS_ND
|
||||
# define TRIO_POSITIVE_ZERO _FPCLASS_PZ
|
||||
# define TRIO_NEGATIVE_ZERO _FPCLASS_NZ
|
||||
# define TRIO_POSITIVE_NORMAL _FPCLASS_PN
|
||||
# define TRIO_NEGATIVE_NORMAL _FPCLASS_NN
|
||||
|
||||
# elif defined(FP_PLUS_NORM)
|
||||
/*
|
||||
* HP-UX 9.x and 10.x have an fpclassify() function, that is different
|
||||
* from the C99 fpclassify() macro supported on HP-UX 11.x.
|
||||
*
|
||||
* AIX has class() for C, and _class() for C++, which returns the
|
||||
* same values as the HP-UX fpclassify() function.
|
||||
*/
|
||||
switch (fpclassify(number)) {
|
||||
case FP_QNAN:
|
||||
case FP_SNAN:
|
||||
*is_negative = TRIO_FALSE;
|
||||
# if defined(TRIO_PLATFORM_AIX)
|
||||
# if defined(__cplusplus)
|
||||
# define TRIO_FPCLASSIFY(n) _class(n)
|
||||
# else
|
||||
# define TRIO_FPCLASSIFY(n) class(n)
|
||||
# endif
|
||||
# else
|
||||
# define TRIO_FPCLASSIFY(n) fpclassify(n)
|
||||
# endif
|
||||
# define TRIO_QUIET_NAN FP_QNAN
|
||||
# define TRIO_SIGNALLING_NAN FP_SNAN
|
||||
# define TRIO_POSITIVE_INFINITY FP_PLUS_INF
|
||||
# define TRIO_NEGATIVE_INFINITY FP_MINUS_INF
|
||||
# define TRIO_POSITIVE_SUBNORMAL FP_PLUS_DENORM
|
||||
# define TRIO_NEGATIVE_SUBNORMAL FP_MINUS_DENORM
|
||||
# define TRIO_POSITIVE_ZERO FP_PLUS_ZERO
|
||||
# define TRIO_NEGATIVE_ZERO FP_MINUS_ZERO
|
||||
# define TRIO_POSITIVE_NORMAL FP_PLUS_NORM
|
||||
# define TRIO_NEGATIVE_NORMAL FP_MINUS_NORM
|
||||
# endif
|
||||
|
||||
# if defined(TRIO_FPCLASSIFY)
|
||||
switch (TRIO_FPCLASSIFY(number)) {
|
||||
case TRIO_QUIET_NAN:
|
||||
case TRIO_SIGNALLING_NAN:
|
||||
*is_negative = TRIO_FALSE; /* NaN has no sign */
|
||||
return TRIO_FP_NAN;
|
||||
case FP_PLUS_INF:
|
||||
case TRIO_POSITIVE_INFINITY:
|
||||
*is_negative = TRIO_FALSE;
|
||||
return TRIO_FP_INFINITE;
|
||||
case FP_MINUS_INF:
|
||||
case TRIO_NEGATIVE_INFINITY:
|
||||
*is_negative = TRIO_TRUE;
|
||||
return TRIO_FP_INFINITE;
|
||||
case FP_PLUS_DENORM:
|
||||
case TRIO_POSITIVE_SUBNORMAL:
|
||||
*is_negative = TRIO_FALSE;
|
||||
return TRIO_FP_SUBNORMAL;
|
||||
case FP_MINUS_DENORM:
|
||||
case TRIO_NEGATIVE_SUBNORMAL:
|
||||
*is_negative = TRIO_TRUE;
|
||||
return TRIO_FP_SUBNORMAL;
|
||||
case FP_PLUS_ZERO:
|
||||
case TRIO_POSITIVE_ZERO:
|
||||
*is_negative = TRIO_FALSE;
|
||||
return TRIO_FP_ZERO;
|
||||
case FP_MINUS_ZERO:
|
||||
case TRIO_NEGATIVE_ZERO:
|
||||
*is_negative = TRIO_TRUE;
|
||||
return TRIO_FP_ZERO;
|
||||
case FP_PLUS_NORM:
|
||||
case TRIO_POSITIVE_NORMAL:
|
||||
*is_negative = TRIO_FALSE;
|
||||
return TRIO_FP_NORMAL;
|
||||
case FP_MINUS_NORM:
|
||||
case TRIO_NEGATIVE_NORMAL:
|
||||
*is_negative = TRIO_TRUE;
|
||||
return TRIO_FP_NORMAL;
|
||||
default:
|
||||
assert(0);
|
||||
/* Just in case... */
|
||||
*is_negative = (number < 0.0);
|
||||
return TRIO_FP_NORMAL;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
# else
|
||||
/*
|
||||
* Fallback solution.
|
||||
*/
|
||||
@ -694,11 +681,11 @@ TRIO_ARGS2((number, is_negative),
|
||||
* have to handle this as a special case by examining the sign bit
|
||||
* directly.
|
||||
*/
|
||||
#if defined(USE_IEEE_754)
|
||||
# if defined(USE_IEEE_754)
|
||||
*is_negative = trio_is_negative(number);
|
||||
#else
|
||||
# else
|
||||
*is_negative = TRIO_FALSE; /* FIXME */
|
||||
#endif
|
||||
# endif
|
||||
return TRIO_FP_ZERO;
|
||||
}
|
||||
if (trio_isnan(number)) {
|
||||
@ -720,6 +707,7 @@ TRIO_ARGS2((number, is_negative),
|
||||
*is_negative = (number < 0.0);
|
||||
return TRIO_FP_NORMAL;
|
||||
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -907,7 +895,7 @@ int main(TRIO_NOARGS)
|
||||
((unsigned char *)&my_ninf)[6],
|
||||
((unsigned char *)&my_ninf)[7],
|
||||
trio_isnan(my_ninf), trio_isinf(my_ninf));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
96
triostr.c
96
triostr.c
@ -62,7 +62,11 @@
|
||||
#if defined(TRIO_PLATFORM_UNIX)
|
||||
# define USE_STRCASECMP
|
||||
# define USE_STRNCASECMP
|
||||
# define USE_STRERROR
|
||||
# if defined(TRIO_PLATFORM_SUNOS)
|
||||
# define USE_SYS_ERRLIST
|
||||
# else
|
||||
# define USE_STRERROR
|
||||
# endif
|
||||
# if defined(TRIO_PLATFORM_QNX)
|
||||
# define strcasecmp(x,y) stricmp(x,y)
|
||||
# define strncasecmp(x,y,n) strnicmp(x,y,n)
|
||||
@ -72,6 +76,11 @@
|
||||
# define strcasecmp(x,y) strcmpi(x,y)
|
||||
#endif
|
||||
|
||||
#if !(defined(TRIO_PLATFORM_SUNOS))
|
||||
# define USE_TOLOWER
|
||||
# define USE_TOUPPER
|
||||
#endif
|
||||
|
||||
/*************************************************************************
|
||||
* Structures
|
||||
*/
|
||||
@ -393,7 +402,7 @@ TRIO_ARGS2((first, second),
|
||||
#else
|
||||
while ((*first != NIL) && (*second != NIL))
|
||||
{
|
||||
if (toupper(*first) != toupper(*second))
|
||||
if (trio_to_upper(*first) != trio_to_upper(*second))
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -518,7 +527,7 @@ TRIO_ARGS3((first, max, second),
|
||||
size_t cnt = 0;
|
||||
while ((*first != NIL) && (*second != NIL) && (cnt <= max))
|
||||
{
|
||||
if (toupper(*first) != toupper(*second))
|
||||
if (trio_to_upper(*first) != trio_to_upper(*second))
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -545,9 +554,22 @@ TRIO_ARGS1((error_number),
|
||||
int error_number)
|
||||
{
|
||||
#if defined(USE_STRERROR)
|
||||
|
||||
return strerror(error_number);
|
||||
|
||||
#elif defined(USE_SYS_ERRLIST)
|
||||
|
||||
extern char *sys_errlist[];
|
||||
extern int sys_nerr;
|
||||
|
||||
return ((error_number < 0) || (error_number >= sys_nerr))
|
||||
? "unknown"
|
||||
: sys_errlist[error_number];
|
||||
|
||||
#else
|
||||
|
||||
return "unknown";
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -679,7 +701,7 @@ TRIO_ARGS1((target),
|
||||
{
|
||||
assert(target);
|
||||
|
||||
return trio_span_function(target, target, tolower);
|
||||
return trio_span_function(target, target, trio_to_lower);
|
||||
}
|
||||
#endif /* !defined(TRIO_MINIMAL) */
|
||||
|
||||
@ -713,7 +735,7 @@ TRIO_ARGS2((string, pattern),
|
||||
{
|
||||
return (NIL == *pattern);
|
||||
}
|
||||
if ((toupper((int)*string) != toupper((int)*pattern))
|
||||
if ((trio_to_upper((int)*string) != trio_to_upper((int)*pattern))
|
||||
&& ('?' != *pattern))
|
||||
{
|
||||
return FALSE;
|
||||
@ -959,7 +981,7 @@ TRIO_ARGS2((source, endp),
|
||||
integer *= base;
|
||||
integer += (isdigit((int)*source)
|
||||
? (*source - '0')
|
||||
: 10 + (toupper((int)*source) - 'A'));
|
||||
: 10 + (trio_to_upper((int)*source) - 'A'));
|
||||
source++;
|
||||
}
|
||||
if (*source == '.')
|
||||
@ -970,7 +992,7 @@ TRIO_ARGS2((source, endp),
|
||||
fracdiv /= base;
|
||||
fraction += fracdiv * (isdigit((int)*source)
|
||||
? (*source - '0')
|
||||
: 10 + (toupper((int)*source) - 'A'));
|
||||
: 10 + (trio_to_upper((int)*source) - 'A'));
|
||||
source++;
|
||||
}
|
||||
if ((*source == 'p') || (*source == 'P'))
|
||||
@ -983,12 +1005,14 @@ TRIO_ARGS2((source, endp),
|
||||
}
|
||||
while (isdigit((int)*source))
|
||||
{
|
||||
exponent *= (int)base;
|
||||
exponent *= 10;
|
||||
exponent += (*source - '0');
|
||||
source++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* For later use with exponent */
|
||||
base = 2.0;
|
||||
}
|
||||
else /* Then try normal decimal floats */
|
||||
{
|
||||
@ -1123,6 +1147,33 @@ TRIO_ARGS3((string, endp, base),
|
||||
}
|
||||
|
||||
|
||||
#if !defined(TRIO_MINIMAL)
|
||||
/**
|
||||
Convert one alphabetic letter to lower-case.
|
||||
|
||||
@param source The letter to be converted.
|
||||
@return The converted letter.
|
||||
*/
|
||||
TRIO_STRING_PUBLIC int
|
||||
trio_to_lower
|
||||
TRIO_ARGS1((source),
|
||||
int source)
|
||||
{
|
||||
#if defined(USE_TOLOWER)
|
||||
|
||||
return tolower(source);
|
||||
|
||||
#else
|
||||
|
||||
/* Does not handle locales or non-contiguous alphabetic characters */
|
||||
return ((source >= (int)'A') && (source <= (int)'Z'))
|
||||
? source - 'A' + 'a'
|
||||
: source;
|
||||
|
||||
#endif
|
||||
}
|
||||
#endif /* !defined(TRIO_MINIMAL) */
|
||||
|
||||
#if !defined(TRIO_MINIMAL)
|
||||
/**
|
||||
Convert string to unsigned integer.
|
||||
@ -1146,6 +1197,31 @@ TRIO_ARGS3((string, endp, base),
|
||||
#endif /* !defined(TRIO_MINIMAL) */
|
||||
|
||||
|
||||
/**
|
||||
Convert one alphabetic letter to upper-case.
|
||||
|
||||
@param source The letter to be converted.
|
||||
@return The converted letter.
|
||||
*/
|
||||
TRIO_STRING_PUBLIC int
|
||||
trio_to_upper
|
||||
TRIO_ARGS1((source),
|
||||
int source)
|
||||
{
|
||||
#if defined(USE_TOUPPER)
|
||||
|
||||
return toupper(source);
|
||||
|
||||
#else
|
||||
|
||||
/* Does not handle locales or non-contiguous alphabetic characters */
|
||||
return ((source >= (int)'a') && (source <= (int)'z'))
|
||||
? source - 'a' + 'A'
|
||||
: source;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(TRIO_MINIMAL)
|
||||
/**
|
||||
Convert the alphabetic letters in the string to upper-case.
|
||||
@ -1160,7 +1236,7 @@ TRIO_ARGS1((target),
|
||||
{
|
||||
assert(target);
|
||||
|
||||
return trio_span_function(target, target, toupper);
|
||||
return trio_span_function(target, target, trio_to_upper);
|
||||
}
|
||||
#endif /* !defined(TRIO_MINIMAL) */
|
||||
|
||||
@ -1229,6 +1305,7 @@ TRIO_ARGS2((self, delta),
|
||||
}
|
||||
|
||||
|
||||
#if !defined(TRIO_MINIMAL)
|
||||
/*
|
||||
* TrioStringGrowTo
|
||||
*
|
||||
@ -1247,6 +1324,7 @@ TRIO_ARGS2((self, length),
|
||||
? TrioStringGrow(self, length - self->allocated)
|
||||
: TRUE;
|
||||
}
|
||||
#endif /* !defined(TRIO_MINIMAL) */
|
||||
|
||||
|
||||
#if !defined(TRIO_MINIMAL)
|
||||
|
43
triostr.h
43
triostr.h
@ -42,40 +42,47 @@ enum {
|
||||
* String functions
|
||||
*/
|
||||
|
||||
TRIO_STRING_PUBLIC int trio_append TRIO_PROTO((char *target, const char *source));
|
||||
TRIO_STRING_PUBLIC int trio_append_max TRIO_PROTO((char *target, size_t max, const char *source));
|
||||
TRIO_STRING_PUBLIC int trio_contains TRIO_PROTO((const char *string, const char *substring));
|
||||
TRIO_STRING_PUBLIC int trio_copy TRIO_PROTO((char *target, const char *source));
|
||||
TRIO_STRING_PUBLIC int trio_copy_max TRIO_PROTO((char *target, size_t max, const char *source));
|
||||
TRIO_STRING_PUBLIC char *trio_create TRIO_PROTO((size_t size));
|
||||
TRIO_STRING_PUBLIC void trio_destroy TRIO_PROTO((char *string));
|
||||
TRIO_STRING_PUBLIC char *trio_duplicate TRIO_PROTO((const char *source));
|
||||
TRIO_STRING_PUBLIC char *trio_duplicate_max TRIO_PROTO((const char *source, size_t max));
|
||||
TRIO_STRING_PUBLIC int trio_equal TRIO_PROTO((const char *first, const char *second));
|
||||
TRIO_STRING_PUBLIC int trio_equal_case TRIO_PROTO((const char *first, const char *second));
|
||||
TRIO_STRING_PUBLIC int trio_equal_case_max TRIO_PROTO((const char *first, size_t max, const char *second));
|
||||
TRIO_STRING_PUBLIC int trio_equal_locale TRIO_PROTO((const char *first, const char *second));
|
||||
TRIO_STRING_PUBLIC int trio_equal_max TRIO_PROTO((const char *first, size_t max, const char *second));
|
||||
TRIO_STRING_PUBLIC TRIO_CONST char *trio_error TRIO_PROTO((int));
|
||||
TRIO_STRING_PUBLIC size_t trio_length TRIO_PROTO((const char *string));
|
||||
TRIO_STRING_PUBLIC double trio_to_double TRIO_PROTO((const char *source, char **endp));
|
||||
TRIO_STRING_PUBLIC long trio_to_long TRIO_PROTO((const char *source, char **endp, int base));
|
||||
TRIO_STRING_PUBLIC trio_long_double_t trio_to_long_double TRIO_PROTO((const char *source, char **endp));
|
||||
TRIO_STRING_PUBLIC int trio_to_upper TRIO_PROTO((int source));
|
||||
|
||||
#if !defined(TRIO_MINIMAL)
|
||||
|
||||
TRIO_STRING_PUBLIC int trio_append TRIO_PROTO((char *target, const char *source));
|
||||
TRIO_STRING_PUBLIC int trio_append_max TRIO_PROTO((char *target, size_t max, const char *source));
|
||||
TRIO_STRING_PUBLIC int trio_contains TRIO_PROTO((const char *string, const char *substring));
|
||||
TRIO_STRING_PUBLIC int trio_copy TRIO_PROTO((char *target, const char *source));
|
||||
TRIO_STRING_PUBLIC char *trio_duplicate_max TRIO_PROTO((const char *source, size_t max));
|
||||
TRIO_STRING_PUBLIC int trio_equal_case_max TRIO_PROTO((const char *first, size_t max, const char *second));
|
||||
TRIO_STRING_PUBLIC size_t trio_format_date_max TRIO_PROTO((char *target, size_t max, const char *format, const struct tm *datetime));
|
||||
TRIO_STRING_PUBLIC unsigned long trio_hash TRIO_PROTO((const char *string, int type));
|
||||
TRIO_STRING_PUBLIC char *trio_index TRIO_PROTO((const char *string, int character));
|
||||
TRIO_STRING_PUBLIC char *trio_index_last TRIO_PROTO((const char *string, int character));
|
||||
TRIO_STRING_PUBLIC size_t trio_length TRIO_PROTO((const char *string));
|
||||
TRIO_STRING_PUBLIC int trio_lower TRIO_PROTO((char *target));
|
||||
TRIO_STRING_PUBLIC int trio_match TRIO_PROTO((const char *string, const char *pattern));
|
||||
TRIO_STRING_PUBLIC int trio_match_case TRIO_PROTO((const char *string, const char *pattern));
|
||||
TRIO_STRING_PUBLIC size_t trio_span_function TRIO_PROTO((char *target, const char *source, int (*Function) TRIO_PROTO((int))));
|
||||
TRIO_STRING_PUBLIC char *trio_substring TRIO_PROTO((const char *string, const char *substring));
|
||||
TRIO_STRING_PUBLIC char *trio_substring_max TRIO_PROTO((const char *string, size_t max, const char *substring));
|
||||
TRIO_STRING_PUBLIC double trio_to_double TRIO_PROTO((const char *source, char **endp));
|
||||
TRIO_STRING_PUBLIC float trio_to_float TRIO_PROTO((const char *source, char **endp));
|
||||
TRIO_STRING_PUBLIC trio_long_double_t trio_to_long_double TRIO_PROTO((const char *source, char **endp));
|
||||
TRIO_STRING_PUBLIC long trio_to_long TRIO_PROTO((const char *source, char **endp, int base));
|
||||
TRIO_STRING_PUBLIC int trio_to_lower TRIO_PROTO((int source));
|
||||
TRIO_STRING_PUBLIC unsigned long trio_to_unsigned_long TRIO_PROTO((const char *source, char **endp, int base));
|
||||
TRIO_STRING_PUBLIC char *trio_tokenize TRIO_PROTO((char *string, const char *delimiters));
|
||||
TRIO_STRING_PUBLIC int trio_upper TRIO_PROTO((char *target));
|
||||
|
||||
#endif /* !defined(TRIO_MINIMAL) */
|
||||
|
||||
/*************************************************************************
|
||||
* Dynamic string functions
|
||||
*/
|
||||
@ -83,15 +90,21 @@ TRIO_STRING_PUBLIC int trio_upper TRIO_PROTO((char *target));
|
||||
/*
|
||||
* Opaque type for dynamic strings
|
||||
*/
|
||||
|
||||
typedef struct _trio_string_t trio_string_t;
|
||||
|
||||
TRIO_STRING_PUBLIC trio_string_t *trio_string_create TRIO_PROTO((int initial_size));
|
||||
TRIO_STRING_PUBLIC void trio_string_destroy TRIO_PROTO((trio_string_t *self));
|
||||
TRIO_STRING_PUBLIC char *trio_string_get TRIO_PROTO((trio_string_t *self, int offset));
|
||||
TRIO_STRING_PUBLIC void trio_xstring_set TRIO_PROTO((trio_string_t *self, char *buffer));
|
||||
TRIO_STRING_PUBLIC char *trio_string_extract TRIO_PROTO((trio_string_t *self));
|
||||
TRIO_STRING_PUBLIC int trio_string_size TRIO_PROTO((trio_string_t *self));
|
||||
TRIO_STRING_PUBLIC void trio_string_terminate TRIO_PROTO((trio_string_t *self));
|
||||
TRIO_STRING_PUBLIC int trio_xstring_append_char TRIO_PROTO((trio_string_t *self, char character));
|
||||
TRIO_STRING_PUBLIC trio_string_t *trio_xstring_duplicate TRIO_PROTO((const char *other));
|
||||
|
||||
#if !defined(TRIO_MINIMAL)
|
||||
|
||||
TRIO_STRING_PUBLIC trio_string_t *trio_string_create TRIO_PROTO((int initial_size));
|
||||
TRIO_STRING_PUBLIC char *trio_string_get TRIO_PROTO((trio_string_t *self, int offset));
|
||||
TRIO_STRING_PUBLIC void trio_xstring_set TRIO_PROTO((trio_string_t *self, char *buffer));
|
||||
|
||||
TRIO_STRING_PUBLIC int trio_string_append TRIO_PROTO((trio_string_t *self, trio_string_t *other));
|
||||
TRIO_STRING_PUBLIC int trio_string_contains TRIO_PROTO((trio_string_t *self, trio_string_t *other));
|
||||
@ -111,11 +124,9 @@ TRIO_STRING_PUBLIC int trio_string_match_case TRIO_PROTO((trio_string_t *self, t
|
||||
TRIO_STRING_PUBLIC char *trio_string_substring TRIO_PROTO((trio_string_t *self, trio_string_t *other));
|
||||
TRIO_STRING_PUBLIC int trio_string_upper TRIO_PROTO((trio_string_t *self));
|
||||
|
||||
TRIO_STRING_PUBLIC int trio_xstring_append_char TRIO_PROTO((trio_string_t *self, char character));
|
||||
TRIO_STRING_PUBLIC int trio_xstring_append TRIO_PROTO((trio_string_t *self, const char *other));
|
||||
TRIO_STRING_PUBLIC int trio_xstring_contains TRIO_PROTO((trio_string_t *self, const char *other));
|
||||
TRIO_STRING_PUBLIC int trio_xstring_copy TRIO_PROTO((trio_string_t *self, const char *other));
|
||||
TRIO_STRING_PUBLIC trio_string_t *trio_xstring_duplicate TRIO_PROTO((const char *other));
|
||||
TRIO_STRING_PUBLIC int trio_xstring_equal TRIO_PROTO((trio_string_t *self, const char *other));
|
||||
TRIO_STRING_PUBLIC int trio_xstring_equal_max TRIO_PROTO((trio_string_t *self, size_t max, const char *other));
|
||||
TRIO_STRING_PUBLIC int trio_xstring_equal_case TRIO_PROTO((trio_string_t *self, const char *other));
|
||||
@ -124,4 +135,6 @@ TRIO_STRING_PUBLIC int trio_xstring_match TRIO_PROTO((trio_string_t *self, const
|
||||
TRIO_STRING_PUBLIC int trio_xstring_match_case TRIO_PROTO((trio_string_t *self, const char *other));
|
||||
TRIO_STRING_PUBLIC char *trio_xstring_substring TRIO_PROTO((trio_string_t *self, const char *other));
|
||||
|
||||
#endif /* !defined(TRIO_MINIMAL) */
|
||||
|
||||
#endif /* TRIO_TRIOSTR_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user