ReactOS 0.4.15-dev-8235-gcd88a97
trio.c File Reference
#include "triodef.h"
#include "trio.h"
#include "triop.h"
#include "trionan.h"
#include "triostr.h"
#include <math.h>
#include <limits.h>
#include <float.h>
#include <assert.h>
#include <ctype.h>
#include <varargs.h>
#include <stddef.h>
#include <errno.h>
Include dependency graph for trio.c:

Go to the source code of this file.

Classes

struct  trio_parameter_t
 
struct  trio_custom_t
 
struct  _trio_class_t
 
struct  _trio_reference_t
 
struct  _trio_userdef_t
 

Macros

#define NDEBUG
 
#define isblank(x)   (((x)==32) || ((x)==9))
 
#define NULL   0
 
#define NIL   ((char)0)
 
#define FALSE   (1 == 0)
 
#define TRUE   (! FALSE)
 
#define BOOLEAN_T   int
 
#define VALID(x)   (NULL != (x))
 
#define TRIO_ERROR_RETURN(x, y)   (- ((x) + ((y) << 8)))
 
#define TRIO_VA_LIST_PTR   va_list *
 
#define TRIO_VA_LIST_ADDR(l)   (&(l))
 
#define TRIO_VA_LIST_DEREF(l)   (*(l))
 
#define floorl(x)   floor((double)(x))
 
#define fmodl(x, y)   fmod((double)(x),(double)(y))
 
#define powl(x, y)   pow((double)(x),(double)(y))
 
#define TRIO_FABS(x)   (((x) < 0.0) ? -(x) : (x))
 
#define DECIMAL_DIG   DBL_DIG
 
#define MAX_MANTISSA_DIGITS   DECIMAL_DIG
 
#define MAX_EXPONENT_DIGITS   3
 
#define MAX_DOUBLE_DIGITS   DBL_MAX_10_EXP
 
#define LDBL_DIG   DBL_DIG
 
#define LDBL_MANT_DIG   DBL_MANT_DIG
 
#define LDBL_EPSILON   DBL_EPSILON
 
#define MAX_CHARS_IN(x)   (sizeof(x) * CHAR_BIT)
 
#define POINTER_WIDTH   ((sizeof("0x") - 1) + sizeof(trio_pointer_t) * CHAR_BIT / 4)
 
#define INFINITE_LOWER   "inf"
 
#define INFINITE_UPPER   "INF"
 
#define LONG_INFINITE_LOWER   "infinite"
 
#define LONG_INFINITE_UPPER   "INFINITE"
 
#define NAN_LOWER   "nan"
 
#define NAN_UPPER   "NAN"
 
#define isascii(x)   ((unsigned int)(x) < 128)
 
#define NO_GROUPING   ((int)CHAR_MAX)
 
#define FORMAT_UNKNOWN   0
 
#define FORMAT_INT   1
 
#define FORMAT_DOUBLE   2
 
#define FORMAT_CHAR   3
 
#define FORMAT_STRING   4
 
#define FORMAT_POINTER   5
 
#define FORMAT_COUNT   6
 
#define FORMAT_PARAMETER   7
 
#define FORMAT_GROUP   8
 
#define FORMAT_ERRNO   9
 
#define FORMAT_USER_DEFINED   10
 
#define CHAR_IDENTIFIER   '%'
 
#define CHAR_BACKSLASH   '\\'
 
#define CHAR_QUOTE   '\"'
 
#define CHAR_ADJUST   ' '
 
#define CLASS_ALNUM   "[:alnum:]"
 
#define CLASS_ALPHA   "[:alpha:]"
 
#define CLASS_BLANK   "[:blank:]"
 
#define CLASS_CNTRL   "[:cntrl:]"
 
#define CLASS_DIGIT   "[:digit:]"
 
#define CLASS_GRAPH   "[:graph:]"
 
#define CLASS_LOWER   "[:lower:]"
 
#define CLASS_PRINT   "[:print:]"
 
#define CLASS_PUNCT   "[:punct:]"
 
#define CLASS_SPACE   "[:space:]"
 
#define CLASS_UPPER   "[:upper:]"
 
#define CLASS_XDIGIT   "[:xdigit:]"
 
#define SPECIFIER_CHAR   'c'
 
#define SPECIFIER_STRING   's'
 
#define SPECIFIER_DECIMAL   'd'
 
#define SPECIFIER_INTEGER   'i'
 
#define SPECIFIER_UNSIGNED   'u'
 
#define SPECIFIER_OCTAL   'o'
 
#define SPECIFIER_HEX   'x'
 
#define SPECIFIER_HEX_UPPER   'X'
 
#define SPECIFIER_FLOAT_E   'e'
 
#define SPECIFIER_FLOAT_E_UPPER   'E'
 
#define SPECIFIER_FLOAT_F   'f'
 
#define SPECIFIER_FLOAT_F_UPPER   'F'
 
#define SPECIFIER_FLOAT_G   'g'
 
#define SPECIFIER_FLOAT_G_UPPER   'G'
 
#define SPECIFIER_POINTER   'p'
 
#define SPECIFIER_GROUP   '['
 
#define SPECIFIER_UNGROUP   ']'
 
#define SPECIFIER_COUNT   'n'
 
#define SPECIFIER_CHAR_UPPER   'C'
 
#define SPECIFIER_STRING_UPPER   'S'
 
#define SPECIFIER_HEXFLOAT   'a'
 
#define SPECIFIER_HEXFLOAT_UPPER   'A'
 
#define SPECIFIER_ERRNO   'm'
 
#define SPECIFIER_BINARY   'b'
 
#define SPECIFIER_BINARY_UPPER   'B'
 
#define SPECIFIER_USER_DEFINED_BEGIN   '<'
 
#define SPECIFIER_USER_DEFINED_END   '>'
 
#define SPECIFIER_USER_DEFINED_SEPARATOR   ':'
 
#define QUALIFIER_POSITION   '$'
 
#define QUALIFIER_SHORT   'h'
 
#define QUALIFIER_LONG   'l'
 
#define QUALIFIER_LONG_UPPER   'L'
 
#define QUALIFIER_ALTERNATIVE   '#'
 
#define QUALIFIER_SPACE   ' '
 
#define QUALIFIER_PLUS   '+'
 
#define QUALIFIER_MINUS   '-'
 
#define QUALIFIER_DOT   '.'
 
#define QUALIFIER_STAR   '*'
 
#define QUALIFIER_CIRCUMFLEX   '^' /* For scanlists */
 
#define QUALIFIER_SIZE_T   'z'
 
#define QUALIFIER_PTRDIFF_T   't'
 
#define QUALIFIER_INTMAX_T   'j'
 
#define QUALIFIER_QUAD   'q'
 
#define QUALIFIER_SIZE_T_UPPER   'Z'
 
#define QUALIFIER_WIDECHAR   'w'
 
#define QUALIFIER_FIXED_SIZE   'I'
 
#define QUALIFIER_QUOTE   '\''
 
#define QUALIFIER_STICKY   '!'
 
#define QUALIFIER_VARSIZE   '&' /* This should remain undocumented */
 
#define QUALIFIER_PARAM   '@' /* Experimental */
 
#define QUALIFIER_COLON   ':' /* For scanlists */
 
#define QUALIFIER_EQUAL   '=' /* For scanlists */
 
#define QUALIFIER_ROUNDING_UPPER   'R'
 

Typedefs

typedef unsigned long trio_flags_t
 
typedef TRIO_SIGNED long int trio_longlong_t
 
typedef unsigned long int trio_ulonglong_t
 
typedef trio_longlong_t trio_intmax_t
 
typedef trio_ulonglong_t trio_uintmax_t
 
typedef TRIO_SIGNED char trio_int8_t
 
typedef TRIO_SIGNED short trio_int16_t
 
typedef TRIO_SIGNED int trio_int32_t
 
typedef trio_longlong_t trio_int64_t
 
typedef struct _trio_class_t trio_class_t
 
typedef struct _trio_reference_t trio_reference_t
 
typedef struct _trio_userdef_t trio_userdef_t
 

Enumerations

enum  {
  TYPE_PRINT = 1 , TYPE_SCAN = 2 , FLAGS_NEW = 0 , FLAGS_STICKY = 1 ,
  FLAGS_SPACE = 2 * FLAGS_STICKY , FLAGS_SHOWSIGN = 2 * FLAGS_SPACE , FLAGS_LEFTADJUST = 2 * FLAGS_SHOWSIGN , FLAGS_ALTERNATIVE = 2 * FLAGS_LEFTADJUST ,
  FLAGS_SHORT = 2 * FLAGS_ALTERNATIVE , FLAGS_SHORTSHORT = 2 * FLAGS_SHORT , FLAGS_LONG = 2 * FLAGS_SHORTSHORT , FLAGS_QUAD = 2 * FLAGS_LONG ,
  FLAGS_LONGDOUBLE = 2 * FLAGS_QUAD , FLAGS_SIZE_T = 2 * FLAGS_LONGDOUBLE , FLAGS_PTRDIFF_T = 2 * FLAGS_SIZE_T , FLAGS_INTMAX_T = 2 * FLAGS_PTRDIFF_T ,
  FLAGS_NILPADDING = 2 * FLAGS_INTMAX_T , FLAGS_UNSIGNED = 2 * FLAGS_NILPADDING , FLAGS_UPPER = 2 * FLAGS_UNSIGNED , FLAGS_WIDTH = 2 * FLAGS_UPPER ,
  FLAGS_WIDTH_PARAMETER = 2 * FLAGS_WIDTH , FLAGS_PRECISION = 2 * FLAGS_WIDTH_PARAMETER , FLAGS_PRECISION_PARAMETER = 2 * FLAGS_PRECISION , FLAGS_BASE = 2 * FLAGS_PRECISION_PARAMETER ,
  FLAGS_BASE_PARAMETER = 2 * FLAGS_BASE , FLAGS_FLOAT_E = 2 * FLAGS_BASE_PARAMETER , FLAGS_FLOAT_G = 2 * FLAGS_FLOAT_E , FLAGS_QUOTE = 2 * FLAGS_FLOAT_G ,
  FLAGS_WIDECHAR = 2 * FLAGS_QUOTE , FLAGS_ALLOC = 2 * FLAGS_WIDECHAR , FLAGS_IGNORE = 2 * FLAGS_ALLOC , 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 , FLAGS_EXCLUDE = FLAGS_SHORT ,
  FLAGS_USER_DEFINED = FLAGS_IGNORE , FLAGS_ROUNDING = FLAGS_INTMAX_T , FLAGS_ALL_VARSIZES = FLAGS_LONG | FLAGS_QUAD | FLAGS_INTMAX_T | FLAGS_PTRDIFF_T | FLAGS_SIZE_T , FLAGS_ALL_SIZES = FLAGS_ALL_VARSIZES | FLAGS_SHORTSHORT | FLAGS_SHORT ,
  NO_POSITION = -1 , NO_WIDTH = 0 , NO_PRECISION = -1 , NO_SIZE = -1 ,
  NO_BASE = -1 , MIN_BASE = 2 , MAX_BASE = 36 , BASE_BINARY = 2 ,
  BASE_OCTAL = 8 , BASE_DECIMAL = 10 , BASE_HEX = 16 , MAX_PARAMETERS = 64 ,
  MAX_CHARACTER_CLASS = UCHAR_MAX + 1 , MAX_USER_NAME = 64 , MAX_USER_DATA = 256 , MAX_LOCALE_SEPARATOR_LENGTH = MB_LEN_MAX ,
  MAX_LOCALE_GROUPS = 64 , DYNAMIC_START_SIZE = 32
}
 

Functions

TRIO_PRIVATE BOOLEAN_T TrioIsQualifier TRIO_ARGS1 ((character), TRIO_CONST char character)
 
TRIO_PRIVATE int TrioCalcThousandSeparatorLength TRIO_ARGS1 ((digits), int digits)
 
TRIO_PRIVATE BOOLEAN_T TrioFollowedBySeparator TRIO_ARGS1 ((position), int position)
 
TRIO_PRIVATE int TrioGetPosition TRIO_ARGS2 ((format, indexPointer), TRIO_CONST char *format, int *indexPointer)
 
TRIO_PRIVATE trio_userdef_t *TrioFindNamespace TRIO_ARGS2 ((name, prev), TRIO_CONST char *name, trio_userdef_t **prev)
 
TRIO_PRIVATE trio_long_double_t TrioPower TRIO_ARGS2 ((number, exponent), int number, int exponent)
 
TRIO_PRIVATE double TrioLogarithm TRIO_ARGS2 ((number, base), double number, int base)
 
TRIO_PRIVATE double TrioLogarithmBase TRIO_ARGS1 ((base), int base)
 
TRIO_PRIVATE int TrioParse TRIO_ARGS5 ((type, format, parameters, arglist, argarray), int type, TRIO_CONST char *format, trio_parameter_t *parameters, TRIO_VA_LIST_PTR arglist, trio_pointer_t *argarray)
 
TRIO_PRIVATE void TrioWriteNumber TRIO_ARGS6 ((self, number, flags, width, precision, base), trio_class_t *self, trio_uintmax_t number, trio_flags_t flags, int width, int precision, int base)
 
TRIO_PRIVATE void TrioWriteStringCharacter TRIO_ARGS3 ((self, ch, flags), trio_class_t *self, int ch, trio_flags_t flags)
 
TRIO_PRIVATE void TrioWriteString TRIO_ARGS5 ((self, string, flags, width, precision), trio_class_t *self, TRIO_CONST char *string, trio_flags_t flags, int width, int precision)
 
TRIO_PRIVATE void TrioWriteDouble TRIO_ARGS6 ((self, number, flags, width, precision, base), trio_class_t *self, trio_long_double_t number, trio_flags_t flags, int width, int precision, int base)
 
TRIO_PRIVATE int TrioFormatProcess TRIO_ARGS3 ((data, format, parameters), trio_class_t *data, TRIO_CONST char *format, trio_parameter_t *parameters)
 
TRIO_PRIVATE int TrioFormatRef TRIO_ARGS4 ((reference, format, arglist, argarray), trio_reference_t *reference, TRIO_CONST char *format, TRIO_VA_LIST_PTR arglist, trio_pointer_t *argarray)
 
TRIO_PRIVATE int TrioFormat TRIO_ARGS6 ((destination, destinationSize, OutStream, format, arglist, argarray), trio_pointer_t destination, size_t destinationSize, void(*OutStream) TRIO_PROTO((trio_class_t *, int)), TRIO_CONST char *format, TRIO_VA_LIST_PTR arglist, trio_pointer_t *argarray)
 
TRIO_PRIVATE void TrioOutStreamFile TRIO_ARGS2 ((self, output), trio_class_t *self, int output)
 
TRIO_PUBLIC int trio_printf TRIO_VARGS2 ((format, va_alist), TRIO_CONST char *format, TRIO_VA_DECL)
 
TRIO_PUBLIC int trio_vprintf TRIO_ARGS2 ((format, args), TRIO_CONST char *format, va_list args)
 
TRIO_PUBLIC int trio_printfv TRIO_ARGS2 ((format, args), TRIO_CONST char *format, trio_pointer_t *args)
 
TRIO_PUBLIC int trio_fprintf TRIO_VARGS3 ((file, format, va_alist), FILE *file, TRIO_CONST char *format, TRIO_VA_DECL)
 
TRIO_PUBLIC int trio_vfprintf TRIO_ARGS3 ((file, format, args), FILE *file, TRIO_CONST char *format, va_list args)
 
TRIO_PUBLIC int trio_fprintfv TRIO_ARGS3 ((file, format, args), FILE *file, TRIO_CONST char *format, trio_pointer_t *args)
 
TRIO_PUBLIC int trio_dprintf TRIO_VARGS3 ((fd, format, va_alist), int fd, TRIO_CONST char *format, TRIO_VA_DECL)
 
TRIO_PUBLIC int trio_vdprintf TRIO_ARGS3 ((fd, format, args), int fd, TRIO_CONST char *format, va_list args)
 
TRIO_PUBLIC int trio_dprintfv TRIO_ARGS3 ((fd, format, args), int fd, TRIO_CONST char *format, trio_pointer_t *args)
 
TRIO_PUBLIC int trio_cprintf TRIO_VARGS4 ((stream, closure, format, va_alist), trio_outstream_t stream, trio_pointer_t closure, TRIO_CONST char *format, TRIO_VA_DECL)
 
TRIO_PUBLIC int trio_vcprintf TRIO_ARGS4 ((stream, closure, format, args), trio_outstream_t stream, trio_pointer_t closure, TRIO_CONST char *format, va_list args)
 
TRIO_PUBLIC int trio_cprintfv TRIO_ARGS4 ((stream, closure, format, args), trio_outstream_t stream, trio_pointer_t closure, TRIO_CONST char *format, void **args)
 
TRIO_PUBLIC int trio_sprintf TRIO_VARGS3 ((buffer, format, va_alist), char *buffer, TRIO_CONST char *format, TRIO_VA_DECL)
 
TRIO_PUBLIC int trio_vsprintf TRIO_ARGS3 ((buffer, format, args), char *buffer, TRIO_CONST char *format, va_list args)
 
TRIO_PUBLIC int trio_sprintfv TRIO_ARGS3 ((buffer, format, args), char *buffer, TRIO_CONST char *format, trio_pointer_t *args)
 
TRIO_PUBLIC int trio_snprintf TRIO_VARGS4 ((buffer, max, format, va_alist), char *buffer, size_t max, TRIO_CONST char *format, TRIO_VA_DECL)
 
TRIO_PUBLIC int trio_vsnprintf TRIO_ARGS4 ((buffer, max, format, args), char *buffer, size_t max, TRIO_CONST char *format, va_list args)
 
TRIO_PUBLIC int trio_snprintfv TRIO_ARGS4 ((buffer, max, format, args), char *buffer, size_t max, TRIO_CONST char *format, trio_pointer_t *args)
 
TRIO_PUBLIC int trio_asprintf TRIO_VARGS3 ((result, format, va_alist), char **result, TRIO_CONST char *format, TRIO_VA_DECL)
 
TRIO_PUBLIC int trio_vasprintf TRIO_ARGS3 ((result, format, args), char **result, TRIO_CONST char *format, va_list args)
 
TRIO_PUBLIC trio_pointer_t trio_register TRIO_ARGS2 ((callback, name), trio_callback_t callback, TRIO_CONST char *name)
 
void trio_unregister TRIO_ARGS1 ((handle), trio_pointer_t handle)
 
TRIO_CONST char *trio_get_format TRIO_ARGS1 ((ref), trio_pointer_t ref)
 
void trio_set_width TRIO_ARGS2 ((ref, width), trio_pointer_t ref, int width)
 
void trio_set_precision TRIO_ARGS2 ((ref, precision), trio_pointer_t ref, int precision)
 
void trio_set_base TRIO_ARGS2 ((ref, base), trio_pointer_t ref, int base)
 
void trio_set_long TRIO_ARGS2 ((ref, is_long), trio_pointer_t ref, int is_long)
 
void trio_set_longlong TRIO_ARGS2 ((ref, is_longlong), trio_pointer_t ref, int is_longlong)
 
void trio_set_longdouble TRIO_ARGS2 ((ref, is_longdouble), trio_pointer_t ref, int is_longdouble)
 
void trio_set_short TRIO_ARGS2 ((ref, is_short), trio_pointer_t ref, int is_short)
 
void trio_set_shortshort TRIO_ARGS2 ((ref, is_shortshort), trio_pointer_t ref, int is_shortshort)
 
void trio_set_alternative TRIO_ARGS2 ((ref, is_alternative), trio_pointer_t ref, int is_alternative)
 
void trio_set_alignment TRIO_ARGS2 ((ref, is_leftaligned), trio_pointer_t ref, int is_leftaligned)
 
void trio_set_spacing TRIO_ARGS2 ((ref, is_space), trio_pointer_t ref, int is_space)
 
void trio_set_sign TRIO_ARGS2 ((ref, is_sign), trio_pointer_t ref, int is_sign)
 
void trio_set_padding TRIO_ARGS2 ((ref, is_padding), trio_pointer_t ref, int is_padding)
 
void trio_set_quote TRIO_ARGS2 ((ref, is_quote), trio_pointer_t ref, int is_quote)
 
void trio_set_upper TRIO_ARGS2 ((ref, is_upper), trio_pointer_t ref, int is_upper)
 
void trio_set_largest TRIO_ARGS2 ((ref, is_largest), trio_pointer_t ref, int is_largest)
 
void trio_set_ptrdiff TRIO_ARGS2 ((ref, is_ptrdiff), trio_pointer_t ref, int is_ptrdiff)
 
void trio_set_size TRIO_ARGS2 ((ref, is_size), trio_pointer_t ref, int is_size)
 
void trio_print_int TRIO_ARGS2 ((ref, number), trio_pointer_t ref, int number)
 
void trio_print_uint TRIO_ARGS2 ((ref, number), trio_pointer_t ref, unsigned int number)
 
void trio_print_double TRIO_ARGS2 ((ref, number), trio_pointer_t ref, double number)
 
void trio_print_string TRIO_ARGS2 ((ref, string), trio_pointer_t ref, char *string)
 
int trio_print_ref TRIO_VARGS3 ((ref, format, va_alist), trio_pointer_t ref, TRIO_CONST char *format, TRIO_VA_DECL)
 
int trio_vprint_ref TRIO_ARGS3 ((ref, format, arglist), trio_pointer_t ref, TRIO_CONST char *format, va_list arglist)
 
int trio_printv_ref TRIO_ARGS3 ((ref, format, argarray), trio_pointer_t ref, TRIO_CONST char *format, trio_pointer_t *argarray)
 
void trio_print_pointer TRIO_ARGS2 ((ref, pointer), trio_pointer_t ref, trio_pointer_t pointer)
 
TRIO_PUBLIC void trio_locale_set_decimal_point TRIO_ARGS1 ((decimalPoint), char *decimalPoint)
 
TRIO_PUBLIC void trio_locale_set_thousand_separator TRIO_ARGS1 ((thousandSeparator), char *thousandSeparator)
 
TRIO_PUBLIC void trio_locale_set_grouping TRIO_ARGS1 ((grouping), char *grouping)
 
TRIO_PRIVATE int TrioSkipWhitespaces TRIO_ARGS1 ((self), trio_class_t *self)
 
TRIO_PRIVATE void TrioGetCollation (TRIO_NOARGS)
 
TRIO_PRIVATE int TrioGetCharacterClass TRIO_ARGS4 ((format, indexPointer, flagsPointer, characterclass), TRIO_CONST char *format, int *indexPointer, trio_flags_t *flagsPointer, int *characterclass)
 
TRIO_PRIVATE BOOLEAN_T TrioReadNumber TRIO_ARGS5 ((self, target, flags, width, base), trio_class_t *self, trio_uintmax_t *target, trio_flags_t flags, int width, int base)
 
TRIO_PRIVATE int TrioReadChar TRIO_ARGS4 ((self, target, flags, width), trio_class_t *self, char *target, trio_flags_t flags, int width)
 
TRIO_PRIVATE BOOLEAN_T TrioReadGroup TRIO_ARGS5 ((self, target, characterclass, flags, width), trio_class_t *self, char *target, int *characterclass, trio_flags_t flags, int width)
 
TRIO_PRIVATE BOOLEAN_T TrioReadDouble TRIO_ARGS4 ((self, target, flags, width), trio_class_t *self, trio_pointer_t target, trio_flags_t flags, int width)
 
TRIO_PRIVATE BOOLEAN_T TrioReadPointer TRIO_ARGS3 ((self, target, flags), trio_class_t *self, trio_pointer_t *target, trio_flags_t flags)
 
TRIO_PRIVATE int TrioScan TRIO_ARGS6 ((source, sourceSize, InStream, format, arglist, argarray), trio_pointer_t source, size_t sourceSize, void(*InStream) TRIO_PROTO((trio_class_t *, int *)), TRIO_CONST char *format, TRIO_VA_LIST_PTR arglist, trio_pointer_t *argarray)
 
TRIO_PRIVATE void TrioInStreamFile TRIO_ARGS2 ((self, intPointer), trio_class_t *self, int *intPointer)
 
TRIO_PUBLIC int trio_cscanf TRIO_VARGS4 ((stream, closure, format, va_alist), trio_instream_t stream, trio_pointer_t closure, TRIO_CONST char *format, TRIO_VA_DECL)
 
TRIO_PUBLIC int trio_vcscanf TRIO_ARGS4 ((stream, closure, format, args), trio_instream_t stream, trio_pointer_t closure, TRIO_CONST char *format, va_list args)
 
TRIO_PUBLIC int trio_cscanfv TRIO_ARGS4 ((stream, closure, format, args), trio_instream_t stream, trio_pointer_t closure, TRIO_CONST char *format, trio_pointer_t *args)
 
TRIO_PUBLIC int trio_sscanf TRIO_VARGS3 ((buffer, format, va_alist), TRIO_CONST char *buffer, TRIO_CONST char *format, TRIO_VA_DECL)
 
TRIO_PUBLIC int trio_vsscanf TRIO_ARGS3 ((buffer, format, args), TRIO_CONST char *buffer, TRIO_CONST char *format, va_list args)
 
TRIO_PUBLIC int trio_sscanfv TRIO_ARGS3 ((buffer, format, args), TRIO_CONST char *buffer, TRIO_CONST char *format, trio_pointer_t *args)
 
TRIO_PUBLIC TRIO_CONST char *trio_strerror TRIO_ARGS1 ((errorcode), int errorcode)
 

Variables

static TRIO_CONST char rcsid [] = "@(#)$Id$"
 
static TRIO_CONST char internalNullString [] = "(nil)"
 
static int internalDecimalPointLength = 1
 
static int internalThousandSeparatorLength = 1
 
static char internalDecimalPoint = '.'
 
static char internalDecimalPointString [MAX_LOCALE_SEPARATOR_LENGTH+1] = "."
 
static char internalThousandSeparator [MAX_LOCALE_SEPARATOR_LENGTH+1] = ","
 
static char internalGrouping [MAX_LOCALE_GROUPS] = { (char)NO_GROUPING }
 
static TRIO_CONST char internalDigitsLower [] = "0123456789abcdefghijklmnopqrstuvwxyz"
 
static TRIO_CONST char internalDigitsUpper [] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 
static BOOLEAN_T internalDigitsUnconverted = TRUE
 
static int internalDigitArray [128]
 
static BOOLEAN_T internalCollationUnconverted = TRUE
 
static char internalCollationArray [MAX_CHARACTER_CLASS][MAX_CHARACTER_CLASS]
 
static TRIO_VOLATILE trio_callback_t internalEnterCriticalRegion = NULL
 
static TRIO_VOLATILE trio_callback_t internalLeaveCriticalRegion = NULL
 
static trio_userdef_tinternalUserDef = NULL
 

Macro Definition Documentation

◆ BOOLEAN_T

#define BOOLEAN_T   int

Definition at line 111 of file trio.c.

◆ CHAR_ADJUST

#define CHAR_ADJUST   ' '

Definition at line 429 of file trio.c.

◆ CHAR_BACKSLASH

#define CHAR_BACKSLASH   '\\'

Definition at line 427 of file trio.c.

◆ CHAR_IDENTIFIER

#define CHAR_IDENTIFIER   '%'

Definition at line 426 of file trio.c.

◆ CHAR_QUOTE

#define CHAR_QUOTE   '\"'

Definition at line 428 of file trio.c.

◆ CLASS_ALNUM

#define CLASS_ALNUM   "[:alnum:]"

Definition at line 432 of file trio.c.

◆ CLASS_ALPHA

#define CLASS_ALPHA   "[:alpha:]"

Definition at line 433 of file trio.c.

◆ CLASS_BLANK

#define CLASS_BLANK   "[:blank:]"

Definition at line 434 of file trio.c.

◆ CLASS_CNTRL

#define CLASS_CNTRL   "[:cntrl:]"

Definition at line 435 of file trio.c.

◆ CLASS_DIGIT

#define CLASS_DIGIT   "[:digit:]"

Definition at line 436 of file trio.c.

◆ CLASS_GRAPH

#define CLASS_GRAPH   "[:graph:]"

Definition at line 437 of file trio.c.

◆ CLASS_LOWER

#define CLASS_LOWER   "[:lower:]"

Definition at line 438 of file trio.c.

◆ CLASS_PRINT

#define CLASS_PRINT   "[:print:]"

Definition at line 439 of file trio.c.

◆ CLASS_PUNCT

#define CLASS_PUNCT   "[:punct:]"

Definition at line 440 of file trio.c.

◆ CLASS_SPACE

#define CLASS_SPACE   "[:space:]"

Definition at line 441 of file trio.c.

◆ CLASS_UPPER

#define CLASS_UPPER   "[:upper:]"

Definition at line 442 of file trio.c.

◆ CLASS_XDIGIT

#define CLASS_XDIGIT   "[:xdigit:]"

Definition at line 443 of file trio.c.

◆ DECIMAL_DIG

#define DECIMAL_DIG   DBL_DIG

Definition at line 285 of file trio.c.

◆ FALSE

#define FALSE   (1 == 0)

Definition at line 108 of file trio.c.

◆ floorl

#define floorl (   x)    floor((double)(x))

Definition at line 273 of file trio.c.

◆ fmodl

#define fmodl (   x,
  y 
)    fmod((double)(x),(double)(y))

Definition at line 274 of file trio.c.

◆ FORMAT_CHAR

#define FORMAT_CHAR   3

Definition at line 412 of file trio.c.

◆ FORMAT_COUNT

#define FORMAT_COUNT   6

Definition at line 415 of file trio.c.

◆ FORMAT_DOUBLE

#define FORMAT_DOUBLE   2

Definition at line 411 of file trio.c.

◆ FORMAT_ERRNO

#define FORMAT_ERRNO   9

Definition at line 419 of file trio.c.

◆ FORMAT_GROUP

#define FORMAT_GROUP   8

Definition at line 417 of file trio.c.

◆ FORMAT_INT

#define FORMAT_INT   1

Definition at line 410 of file trio.c.

◆ FORMAT_PARAMETER

#define FORMAT_PARAMETER   7

Definition at line 416 of file trio.c.

◆ FORMAT_POINTER

#define FORMAT_POINTER   5

Definition at line 414 of file trio.c.

◆ FORMAT_STRING

#define FORMAT_STRING   4

Definition at line 413 of file trio.c.

◆ FORMAT_UNKNOWN

#define FORMAT_UNKNOWN   0

Definition at line 409 of file trio.c.

◆ FORMAT_USER_DEFINED

#define FORMAT_USER_DEFINED   10

Definition at line 422 of file trio.c.

◆ INFINITE_LOWER

#define INFINITE_LOWER   "inf"

Definition at line 314 of file trio.c.

◆ INFINITE_UPPER

#define INFINITE_UPPER   "INF"

Definition at line 315 of file trio.c.

◆ isascii

#define isascii (   x)    ((unsigned int)(x) < 128)

Definition at line 323 of file trio.c.

◆ isblank

#define isblank (   x)    (((x)==32) || ((x)==9))

Definition at line 93 of file trio.c.

◆ LDBL_DIG

#define LDBL_DIG   DBL_DIG

Definition at line 303 of file trio.c.

◆ LDBL_EPSILON

#define LDBL_EPSILON   DBL_EPSILON

Definition at line 305 of file trio.c.

◆ LDBL_MANT_DIG

#define LDBL_MANT_DIG   DBL_MANT_DIG

Definition at line 304 of file trio.c.

◆ LONG_INFINITE_LOWER

#define LONG_INFINITE_LOWER   "infinite"

Definition at line 316 of file trio.c.

◆ LONG_INFINITE_UPPER

#define LONG_INFINITE_UPPER   "INFINITE"

Definition at line 317 of file trio.c.

◆ MAX_CHARS_IN

#define MAX_CHARS_IN (   x)    (sizeof(x) * CHAR_BIT)

Definition at line 309 of file trio.c.

◆ MAX_DOUBLE_DIGITS

#define MAX_DOUBLE_DIGITS   DBL_MAX_10_EXP

Definition at line 296 of file trio.c.

◆ MAX_EXPONENT_DIGITS

#define MAX_EXPONENT_DIGITS   3

Definition at line 295 of file trio.c.

◆ MAX_MANTISSA_DIGITS

#define MAX_MANTISSA_DIGITS   DECIMAL_DIG

Definition at line 294 of file trio.c.

◆ NAN_LOWER

#define NAN_LOWER   "nan"

Definition at line 318 of file trio.c.

◆ NAN_UPPER

#define NAN_UPPER   "NAN"

Definition at line 319 of file trio.c.

◆ NDEBUG

#define NDEBUG

Definition at line 87 of file trio.c.

◆ NIL

#define NIL   ((char)0)

Definition at line 106 of file trio.c.

◆ NO_GROUPING

#define NO_GROUPING   ((int)CHAR_MAX)

Definition at line 406 of file trio.c.

◆ NULL

#define NULL   0

Definition at line 104 of file trio.c.

◆ POINTER_WIDTH

#define POINTER_WIDTH   ((sizeof("0x") - 1) + sizeof(trio_pointer_t) * CHAR_BIT / 4)

Definition at line 311 of file trio.c.

◆ powl

#define powl (   x,
  y 
)    pow((double)(x),(double)(y))

Definition at line 275 of file trio.c.

◆ QUALIFIER_ALTERNATIVE

#define QUALIFIER_ALTERNATIVE   '#'

Definition at line 607 of file trio.c.

◆ QUALIFIER_CIRCUMFLEX

#define QUALIFIER_CIRCUMFLEX   '^' /* For scanlists */

Definition at line 613 of file trio.c.

◆ QUALIFIER_COLON

#define QUALIFIER_COLON   ':' /* For scanlists */

Definition at line 636 of file trio.c.

◆ QUALIFIER_DOT

#define QUALIFIER_DOT   '.'

Definition at line 611 of file trio.c.

◆ QUALIFIER_EQUAL

#define QUALIFIER_EQUAL   '=' /* For scanlists */

Definition at line 637 of file trio.c.

◆ QUALIFIER_FIXED_SIZE

#define QUALIFIER_FIXED_SIZE   'I'

Definition at line 629 of file trio.c.

◆ QUALIFIER_INTMAX_T

#define QUALIFIER_INTMAX_T   'j'

Definition at line 617 of file trio.c.

◆ QUALIFIER_LONG

#define QUALIFIER_LONG   'l'

Definition at line 605 of file trio.c.

◆ QUALIFIER_LONG_UPPER

#define QUALIFIER_LONG_UPPER   'L'

Definition at line 606 of file trio.c.

◆ QUALIFIER_MINUS

#define QUALIFIER_MINUS   '-'

Definition at line 610 of file trio.c.

◆ QUALIFIER_PARAM

#define QUALIFIER_PARAM   '@' /* Experimental */

Definition at line 635 of file trio.c.

◆ QUALIFIER_PLUS

#define QUALIFIER_PLUS   '+'

Definition at line 609 of file trio.c.

◆ QUALIFIER_POSITION

#define QUALIFIER_POSITION   '$'

Definition at line 603 of file trio.c.

◆ QUALIFIER_PTRDIFF_T

#define QUALIFIER_PTRDIFF_T   't'

Definition at line 616 of file trio.c.

◆ QUALIFIER_QUAD

#define QUALIFIER_QUAD   'q'

Definition at line 620 of file trio.c.

◆ QUALIFIER_QUOTE

#define QUALIFIER_QUOTE   '\''

Definition at line 632 of file trio.c.

◆ QUALIFIER_ROUNDING_UPPER

#define QUALIFIER_ROUNDING_UPPER   'R'

Definition at line 638 of file trio.c.

◆ QUALIFIER_SHORT

#define QUALIFIER_SHORT   'h'

Definition at line 604 of file trio.c.

◆ QUALIFIER_SIZE_T

#define QUALIFIER_SIZE_T   'z'

Definition at line 615 of file trio.c.

◆ QUALIFIER_SIZE_T_UPPER

#define QUALIFIER_SIZE_T_UPPER   'Z'

Definition at line 623 of file trio.c.

◆ QUALIFIER_SPACE

#define QUALIFIER_SPACE   ' '

Definition at line 608 of file trio.c.

◆ QUALIFIER_STAR

#define QUALIFIER_STAR   '*'

Definition at line 612 of file trio.c.

◆ QUALIFIER_STICKY

#define QUALIFIER_STICKY   '!'

Definition at line 633 of file trio.c.

◆ QUALIFIER_VARSIZE

#define QUALIFIER_VARSIZE   '&' /* This should remain undocumented */

Definition at line 634 of file trio.c.

◆ QUALIFIER_WIDECHAR

#define QUALIFIER_WIDECHAR   'w'

Definition at line 626 of file trio.c.

◆ SPECIFIER_BINARY

#define SPECIFIER_BINARY   'b'

Definition at line 507 of file trio.c.

◆ SPECIFIER_BINARY_UPPER

#define SPECIFIER_BINARY_UPPER   'B'

Definition at line 508 of file trio.c.

◆ SPECIFIER_CHAR

#define SPECIFIER_CHAR   'c'

Definition at line 477 of file trio.c.

◆ SPECIFIER_CHAR_UPPER

#define SPECIFIER_CHAR_UPPER   'C'

Definition at line 496 of file trio.c.

◆ SPECIFIER_COUNT

#define SPECIFIER_COUNT   'n'

Definition at line 494 of file trio.c.

◆ SPECIFIER_DECIMAL

#define SPECIFIER_DECIMAL   'd'

Definition at line 479 of file trio.c.

◆ SPECIFIER_ERRNO

#define SPECIFIER_ERRNO   'm'

Definition at line 504 of file trio.c.

◆ SPECIFIER_FLOAT_E

#define SPECIFIER_FLOAT_E   'e'

Definition at line 485 of file trio.c.

◆ SPECIFIER_FLOAT_E_UPPER

#define SPECIFIER_FLOAT_E_UPPER   'E'

Definition at line 486 of file trio.c.

◆ SPECIFIER_FLOAT_F

#define SPECIFIER_FLOAT_F   'f'

Definition at line 487 of file trio.c.

◆ SPECIFIER_FLOAT_F_UPPER

#define SPECIFIER_FLOAT_F_UPPER   'F'

Definition at line 488 of file trio.c.

◆ SPECIFIER_FLOAT_G

#define SPECIFIER_FLOAT_G   'g'

Definition at line 489 of file trio.c.

◆ SPECIFIER_FLOAT_G_UPPER

#define SPECIFIER_FLOAT_G_UPPER   'G'

Definition at line 490 of file trio.c.

◆ SPECIFIER_GROUP

#define SPECIFIER_GROUP   '['

Definition at line 492 of file trio.c.

◆ SPECIFIER_HEX

#define SPECIFIER_HEX   'x'

Definition at line 483 of file trio.c.

◆ SPECIFIER_HEX_UPPER

#define SPECIFIER_HEX_UPPER   'X'

Definition at line 484 of file trio.c.

◆ SPECIFIER_HEXFLOAT

#define SPECIFIER_HEXFLOAT   'a'

Definition at line 500 of file trio.c.

◆ SPECIFIER_HEXFLOAT_UPPER

#define SPECIFIER_HEXFLOAT_UPPER   'A'

Definition at line 501 of file trio.c.

◆ SPECIFIER_INTEGER

#define SPECIFIER_INTEGER   'i'

Definition at line 480 of file trio.c.

◆ SPECIFIER_OCTAL

#define SPECIFIER_OCTAL   'o'

Definition at line 482 of file trio.c.

◆ SPECIFIER_POINTER

#define SPECIFIER_POINTER   'p'

Definition at line 491 of file trio.c.

◆ SPECIFIER_STRING

#define SPECIFIER_STRING   's'

Definition at line 478 of file trio.c.

◆ SPECIFIER_STRING_UPPER

#define SPECIFIER_STRING_UPPER   'S'

Definition at line 497 of file trio.c.

◆ SPECIFIER_UNGROUP

#define SPECIFIER_UNGROUP   ']'

Definition at line 493 of file trio.c.

◆ SPECIFIER_UNSIGNED

#define SPECIFIER_UNSIGNED   'u'

Definition at line 481 of file trio.c.

◆ SPECIFIER_USER_DEFINED_BEGIN

#define SPECIFIER_USER_DEFINED_BEGIN   '<'

Definition at line 509 of file trio.c.

◆ SPECIFIER_USER_DEFINED_END

#define SPECIFIER_USER_DEFINED_END   '>'

Definition at line 510 of file trio.c.

◆ SPECIFIER_USER_DEFINED_SEPARATOR

#define SPECIFIER_USER_DEFINED_SEPARATOR   ':'

Definition at line 511 of file trio.c.

◆ TRIO_ERROR_RETURN

#define TRIO_ERROR_RETURN (   x,
  y 
)    (- ((x) + ((y) << 8)))

Definition at line 121 of file trio.c.

◆ TRIO_FABS

#define TRIO_FABS (   x)    (((x) < 0.0) ? -(x) : (x))

Definition at line 278 of file trio.c.

◆ TRIO_VA_LIST_ADDR

#define TRIO_VA_LIST_ADDR (   l)    (&(l))

Definition at line 128 of file trio.c.

◆ TRIO_VA_LIST_DEREF

#define TRIO_VA_LIST_DEREF (   l)    (*(l))

Definition at line 129 of file trio.c.

◆ TRIO_VA_LIST_PTR

#define TRIO_VA_LIST_PTR   va_list *

Definition at line 127 of file trio.c.

◆ TRUE

#define TRUE   (! FALSE)

Definition at line 109 of file trio.c.

◆ VALID

#define VALID (   x)    (NULL != (x))

Definition at line 114 of file trio.c.

Typedef Documentation

◆ trio_class_t

◆ trio_flags_t

Definition at line 136 of file trio.c.

◆ trio_int16_t

Definition at line 256 of file trio.c.

◆ trio_int32_t

Definition at line 261 of file trio.c.

◆ trio_int64_t

Definition at line 266 of file trio.c.

◆ trio_int8_t

Definition at line 251 of file trio.c.

◆ trio_intmax_t

Definition at line 246 of file trio.c.

◆ trio_longlong_t

Definition at line 213 of file trio.c.

◆ trio_reference_t

◆ trio_uintmax_t

Definition at line 247 of file trio.c.

◆ trio_ulonglong_t

Definition at line 214 of file trio.c.

◆ trio_userdef_t

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
TYPE_PRINT 
TYPE_SCAN 
FLAGS_NEW 
FLAGS_STICKY 
FLAGS_SPACE 
FLAGS_SHOWSIGN 
FLAGS_LEFTADJUST 
FLAGS_ALTERNATIVE 
FLAGS_SHORT 
FLAGS_SHORTSHORT 
FLAGS_LONG 
FLAGS_QUAD 
FLAGS_LONGDOUBLE 
FLAGS_SIZE_T 
FLAGS_PTRDIFF_T 
FLAGS_INTMAX_T 
FLAGS_NILPADDING 
FLAGS_UNSIGNED 
FLAGS_UPPER 
FLAGS_WIDTH 
FLAGS_WIDTH_PARAMETER 
FLAGS_PRECISION 
FLAGS_PRECISION_PARAMETER 
FLAGS_BASE 
FLAGS_BASE_PARAMETER 
FLAGS_FLOAT_E 
FLAGS_FLOAT_G 
FLAGS_QUOTE 
FLAGS_WIDECHAR 
FLAGS_ALLOC 
FLAGS_IGNORE 
FLAGS_IGNORE_PARAMETER 
FLAGS_VARSIZE_PARAMETER 
FLAGS_FIXED_SIZE 
FLAGS_LAST 
FLAGS_EXCLUDE 
FLAGS_USER_DEFINED 
FLAGS_ROUNDING 
FLAGS_ALL_VARSIZES 
FLAGS_ALL_SIZES 
NO_POSITION 
NO_WIDTH 
NO_PRECISION 
NO_SIZE 
NO_BASE 
MIN_BASE 
MAX_BASE 
BASE_BINARY 
BASE_OCTAL 
BASE_DECIMAL 
BASE_HEX 
MAX_PARAMETERS 
MAX_CHARACTER_CLASS 
MAX_USER_NAME 
MAX_USER_DATA 
MAX_LOCALE_SEPARATOR_LENGTH 
MAX_LOCALE_GROUPS 
DYNAMIC_START_SIZE 

Definition at line 328 of file trio.c.

328 {
329 TYPE_PRINT = 1,
330 TYPE_SCAN = 2,
331
332 /* Flags. FLAGS_LAST must be less than ULONG_MAX */
333 FLAGS_NEW = 0,
334 FLAGS_STICKY = 1,
366 /* Reused flags */
370 /* Compounded flags */
373
374 NO_POSITION = -1,
375 NO_WIDTH = 0,
376 NO_PRECISION = -1,
377 NO_SIZE = -1,
378
379 /* Do not change these */
380 NO_BASE = -1,
381 MIN_BASE = 2,
382 MAX_BASE = 36,
383 BASE_BINARY = 2,
384 BASE_OCTAL = 8,
385 BASE_DECIMAL = 10,
386 BASE_HEX = 16,
387
388 /* Maximal number of allowed parameters */
389 MAX_PARAMETERS = 64,
390 /* Maximal number of characters in class */
392
393 /* Maximal string lengths for user-defined specifiers */
394 MAX_USER_NAME = 64,
395 MAX_USER_DATA = 256,
396
397 /* Maximal length of locale separator strings */
399 /* Maximal number of integers in grouping */
401
402 /* Initial size of asprintf buffer */
404};
#define UCHAR_MAX
Definition: limits.h:25
#define MB_LEN_MAX
Definition: limits.h:35
@ FLAGS_FLOAT_G
Definition: trio.c:357
@ FLAGS_FIXED_SIZE
Definition: trio.c:364
@ FLAGS_FLOAT_E
Definition: trio.c:356
@ FLAGS_LEFTADJUST
Definition: trio.c:337
@ MAX_USER_NAME
Definition: trio.c:394
@ FLAGS_PRECISION_PARAMETER
Definition: trio.c:353
@ FLAGS_PTRDIFF_T
Definition: trio.c:345
@ TYPE_SCAN
Definition: trio.c:330
@ BASE_OCTAL
Definition: trio.c:384
@ FLAGS_LONGDOUBLE
Definition: trio.c:343
@ FLAGS_IGNORE
Definition: trio.c:361
@ TYPE_PRINT
Definition: trio.c:329
@ FLAGS_WIDTH
Definition: trio.c:350
@ MAX_CHARACTER_CLASS
Definition: trio.c:391
@ BASE_BINARY
Definition: trio.c:383
@ DYNAMIC_START_SIZE
Definition: trio.c:403
@ MAX_BASE
Definition: trio.c:382
@ BASE_HEX
Definition: trio.c:386
@ FLAGS_BASE
Definition: trio.c:354
@ MAX_LOCALE_SEPARATOR_LENGTH
Definition: trio.c:398
@ FLAGS_NEW
Definition: trio.c:333
@ FLAGS_ALL_VARSIZES
Definition: trio.c:371
@ FLAGS_EXCLUDE
Definition: trio.c:367
@ FLAGS_ALTERNATIVE
Definition: trio.c:338
@ FLAGS_NILPADDING
Definition: trio.c:347
@ FLAGS_BASE_PARAMETER
Definition: trio.c:355
@ FLAGS_VARSIZE_PARAMETER
Definition: trio.c:363
@ FLAGS_ROUNDING
Definition: trio.c:369
@ NO_BASE
Definition: trio.c:380
@ FLAGS_WIDTH_PARAMETER
Definition: trio.c:351
@ MIN_BASE
Definition: trio.c:381
@ NO_WIDTH
Definition: trio.c:375
@ FLAGS_IGNORE_PARAMETER
Definition: trio.c:362
@ MAX_PARAMETERS
Definition: trio.c:389
@ FLAGS_SHORTSHORT
Definition: trio.c:340
@ FLAGS_UNSIGNED
Definition: trio.c:348
@ NO_SIZE
Definition: trio.c:377
@ FLAGS_ALL_SIZES
Definition: trio.c:372
@ NO_PRECISION
Definition: trio.c:376
@ NO_POSITION
Definition: trio.c:374
@ FLAGS_SHORT
Definition: trio.c:339
@ FLAGS_QUOTE
Definition: trio.c:358
@ FLAGS_WIDECHAR
Definition: trio.c:359
@ FLAGS_INTMAX_T
Definition: trio.c:346
@ MAX_USER_DATA
Definition: trio.c:395
@ FLAGS_UPPER
Definition: trio.c:349
@ FLAGS_QUAD
Definition: trio.c:342
@ FLAGS_LONG
Definition: trio.c:341
@ FLAGS_PRECISION
Definition: trio.c:352
@ FLAGS_USER_DEFINED
Definition: trio.c:368
@ FLAGS_SHOWSIGN
Definition: trio.c:336
@ FLAGS_SPACE
Definition: trio.c:335
@ FLAGS_SIZE_T
Definition: trio.c:344
@ MAX_LOCALE_GROUPS
Definition: trio.c:400
@ FLAGS_LAST
Definition: trio.c:365
@ FLAGS_STICKY
Definition: trio.c:334
@ BASE_DECIMAL
Definition: trio.c:385
@ FLAGS_ALLOC
Definition: trio.c:360

Function Documentation

◆ TRIO_ARGS1() [1/9]

TRIO_PRIVATE double TrioLogarithmBase TRIO_ARGS1 ( (base ,
int  base 
)

Definition at line 1158 of file trio.c.

1160{
1161 switch (base)
1162 {
1163 case BASE_BINARY : return 1.0;
1164 case BASE_OCTAL : return 3.0;
1165 case BASE_DECIMAL: return 3.321928094887362345;
1166 case BASE_HEX : return 4.0;
1167 default : return TrioLogarithm((double)base, 2);
1168 }
1169}

◆ TRIO_ARGS1() [2/9]

TRIO_PRIVATE BOOLEAN_T TrioIsQualifier TRIO_ARGS1 ( (character)  ,
TRIO_CONST char  character 
)

Definition at line 817 of file trio.c.

819{
820 /* QUALIFIER_POSITION is not included */
821 switch (character)
822 {
823 case '0': case '1': case '2': case '3': case '4':
824 case '5': case '6': case '7': case '8': case '9':
825 case QUALIFIER_PLUS:
826 case QUALIFIER_MINUS:
827 case QUALIFIER_SPACE:
828 case QUALIFIER_DOT:
829 case QUALIFIER_STAR:
831 case QUALIFIER_SHORT:
832 case QUALIFIER_LONG:
835#if defined(QUALIFIER_SIZE_T)
836 case QUALIFIER_SIZE_T:
837#endif
838#if defined(QUALIFIER_PTRDIFF_T)
840#endif
841#if defined(QUALIFIER_INTMAX_T)
843#endif
844#if defined(QUALIFIER_QUAD)
845 case QUALIFIER_QUAD:
846#endif
847#if defined(QUALIFIER_SIZE_T_UPPER)
849#endif
850#if defined(QUALIFIER_WIDECHAR)
852#endif
853#if defined(QUALIFIER_QUOTE)
854 case QUALIFIER_QUOTE:
855#endif
856#if defined(QUALIFIER_STICKY)
857 case QUALIFIER_STICKY:
858#endif
859#if defined(QUALIFIER_VARSIZE)
861#endif
862#if defined(QUALIFIER_PARAM)
863 case QUALIFIER_PARAM:
864#endif
865#if defined(QUALIFIER_FIXED_SIZE)
867#endif
868#if defined(QUALIFIER_ROUNDING_UPPER)
870#endif
871 return TRUE;
872 default:
873 return FALSE;
874 }
875}
#define QUALIFIER_ROUNDING_UPPER
Definition: trio.c:638
#define QUALIFIER_DOT
Definition: trio.c:611
#define QUALIFIER_SPACE
Definition: trio.c:608
#define QUALIFIER_QUAD
Definition: trio.c:620
#define QUALIFIER_CIRCUMFLEX
Definition: trio.c:613
#define QUALIFIER_SIZE_T_UPPER
Definition: trio.c:623
#define QUALIFIER_STICKY
Definition: trio.c:633
#define QUALIFIER_PLUS
Definition: trio.c:609
#define QUALIFIER_MINUS
Definition: trio.c:610
#define QUALIFIER_ALTERNATIVE
Definition: trio.c:607
#define QUALIFIER_LONG_UPPER
Definition: trio.c:606
#define QUALIFIER_INTMAX_T
Definition: trio.c:617
#define QUALIFIER_SHORT
Definition: trio.c:604
#define TRUE
Definition: trio.c:109
#define FALSE
Definition: trio.c:108
#define QUALIFIER_SIZE_T
Definition: trio.c:615
#define QUALIFIER_VARSIZE
Definition: trio.c:634
#define QUALIFIER_WIDECHAR
Definition: trio.c:626
#define QUALIFIER_STAR
Definition: trio.c:612
#define QUALIFIER_PTRDIFF_T
Definition: trio.c:616
#define QUALIFIER_LONG
Definition: trio.c:605
#define QUALIFIER_PARAM
Definition: trio.c:635
#define QUALIFIER_QUOTE
Definition: trio.c:632
#define QUALIFIER_FIXED_SIZE
Definition: trio.c:629

◆ TRIO_ARGS1() [3/9]

TRIO_PUBLIC void trio_locale_set_decimal_point TRIO_ARGS1 ( (decimalPoint)  ,
char decimalPoint 
)

Definition at line 5043 of file trio.c.

5045{
5046#if defined(USE_LOCALE)
5047 if (NULL == internalLocaleValues)
5048 {
5049 TrioSetLocale();
5050 }
5051#endif
5052 internalDecimalPointLength = trio_length(decimalPoint);
5054 {
5055 internalDecimalPoint = *decimalPoint;
5056 }
5057 else
5058 {
5060 trio_copy_max(internalDecimalPointString,
5062 decimalPoint);
5063 }
5064}
#define NULL
Definition: trio.c:104
#define NIL
Definition: trio.c:106
static char internalDecimalPointString[MAX_LOCALE_SEPARATOR_LENGTH+1]
Definition: trio.c:777
static int internalDecimalPointLength
Definition: trio.c:774
static char internalDecimalPoint
Definition: trio.c:776

◆ TRIO_ARGS1() [4/9]

TRIO_PRIVATE int TrioCalcThousandSeparatorLength TRIO_ARGS1 ( (digits ,
int  digits 
)

Definition at line 924 of file trio.c.

926{
927#if TRIO_EXTENSION
928 int count = 0;
929 int step = NO_GROUPING;
930 char *groupingPointer = internalGrouping;
931
932 while (digits > 0)
933 {
934 if (*groupingPointer == CHAR_MAX)
935 {
936 /* Disable grouping */
937 break; /* while */
938 }
939 else if (*groupingPointer == 0)
940 {
941 /* Repeat last group */
942 if (step == NO_GROUPING)
943 {
944 /* Error in locale */
945 break; /* while */
946 }
947 }
948 else
949 {
950 step = *groupingPointer++;
951 }
952 if (digits > step)
954 digits -= step;
955 }
956 return count;
957#else
958 return 0;
959#endif
960}
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define CHAR_MAX
Definition: limits.h:32
static const int digits[]
Definition: decode.c:71
#define NO_GROUPING
Definition: trio.c:406
static char internalGrouping[MAX_LOCALE_GROUPS]
Definition: trio.c:779
static int internalThousandSeparatorLength
Definition: trio.c:775

◆ TRIO_ARGS1() [5/9]

TRIO_PUBLIC TRIO_CONST char *trio_strerror TRIO_ARGS1 ( (errorcode)  ,
int  errorcode 
)

Definition at line 6867 of file trio.c.

6869{
6870 /* Textual versions of the error codes */
6871 switch (TRIO_ERROR_CODE(errorcode))
6872 {
6873 case TRIO_EOF:
6874 return "End of file";
6875 case TRIO_EINVAL:
6876 return "Invalid argument";
6877 case TRIO_ETOOMANY:
6878 return "Too many arguments";
6879 case TRIO_EDBLREF:
6880 return "Double reference";
6881 case TRIO_EGAP:
6882 return "Reference gap";
6883 case TRIO_ENOMEM:
6884 return "Out of memory";
6885 case TRIO_ERANGE:
6886 return "Invalid range";
6887 case TRIO_ECUSTOM:
6888 return "Custom error";
6889 default:
6890 return "Unknown";
6891 }
6892}
#define TRIO_ERROR_CODE(x)
Definition: trio.h:67
@ TRIO_ERANGE
Definition: trio.h:61
@ TRIO_ETOOMANY
Definition: trio.h:57
@ TRIO_EDBLREF
Definition: trio.h:58
@ TRIO_EINVAL
Definition: trio.h:56
@ TRIO_EOF
Definition: trio.h:55
@ TRIO_ENOMEM
Definition: trio.h:60
@ TRIO_EGAP
Definition: trio.h:59
@ TRIO_ECUSTOM
Definition: trio.h:63

◆ TRIO_ARGS1() [6/9]

TRIO_PUBLIC void trio_locale_set_grouping TRIO_ARGS1 ( (grouping)  ,
char grouping 
)

Definition at line 5102 of file trio.c.

5104{
5105#if defined(USE_LOCALE)
5106 if (NULL == internalLocaleValues)
5107 {
5108 TrioSetLocale();
5109 }
5110#endif
5111 trio_copy_max(internalGrouping,
5112 sizeof(internalGrouping),
5113 grouping);
5114}

◆ TRIO_ARGS1() [7/9]

TRIO_PRIVATE BOOLEAN_T TrioFollowedBySeparator TRIO_ARGS1 ( (position)  ,
int  position 
)

Definition at line 964 of file trio.c.

966{
967#if TRIO_EXTENSION
968 int step = 0;
969 char *groupingPointer = internalGrouping;
970
971 position--;
972 if (position == 0)
973 return FALSE;
974 while (position > 0)
975 {
976 if (*groupingPointer == CHAR_MAX)
977 {
978 /* Disable grouping */
979 break; /* while */
980 }
981 else if (*groupingPointer != 0)
982 {
983 step = *groupingPointer++;
984 }
985 if (step == 0)
986 break;
987 position -= step;
988 }
989 return (position == 0);
990#else
991 return FALSE;
992#endif
993}

◆ TRIO_ARGS1() [8/9]

TRIO_PRIVATE int TrioSkipWhitespaces TRIO_ARGS1 ( (self)  ,
trio_class_t self 
)

Definition at line 5128 of file trio.c.

5130{
5131 int ch;
5132
5133 ch = self->current;
5134 while (isspace(ch))
5135 {
5136 self->InStream(self, &ch);
5137 }
5138 return ch;
5139}
#define isspace(c)
Definition: acclib.h:69
int current
Definition: trio.c:712

◆ TRIO_ARGS1() [9/9]

TRIO_PUBLIC void trio_locale_set_thousand_separator TRIO_ARGS1 ( (thousandSeparator)  ,
char thousandSeparator 
)

Definition at line 5073 of file trio.c.

5075{
5076#if defined(USE_LOCALE)
5077 if (NULL == internalLocaleValues)
5078 {
5079 TrioSetLocale();
5080 }
5081#endif
5082 trio_copy_max(internalThousandSeparator,
5084 thousandSeparator);
5086}
static char internalThousandSeparator[MAX_LOCALE_SEPARATOR_LENGTH+1]
Definition: trio.c:778

◆ TRIO_ARGS2() [1/6]

TRIO_PRIVATE int TrioGetPosition TRIO_ARGS2 ( (format, indexPointer)  ,
TRIO_CONST char format,
int indexPointer 
)

Definition at line 1002 of file trio.c.

1005{
1006#if TRIO_UNIX98
1007 char *tmpformat;
1008 int number = 0;
1009 int index = *indexPointer;
1010
1011 number = (int)trio_to_long(&format[index], &tmpformat, BASE_DECIMAL);
1012 index = (int)(tmpformat - format);
1013 if ((number != 0) && (QUALIFIER_POSITION == format[index++]))
1014 {
1015 *indexPointer = index;
1016 /*
1017 * number is decreased by 1, because n$ starts from 1, whereas
1018 * the array it is indexing starts from 0.
1019 */
1020 return number - 1;
1021 }
1022#endif
1023 return NO_POSITION;
1024}
#define index(s, c)
Definition: various.h:29
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLuint index
Definition: glext.h:6031
static unsigned int number
Definition: dsound.c:1479
#define QUALIFIER_POSITION
Definition: trio.c:603

◆ TRIO_ARGS2() [2/6]

TRIO_PRIVATE trio_userdef_t *TrioFindNamespace TRIO_ARGS2 ( (name, prev)  ,
TRIO_CONST char name,
trio_userdef_t **  prev 
)

Definition at line 1035 of file trio.c.

1038{
1039 trio_userdef_t *def;
1040
1043
1044 for (def = internalUserDef; def; def = def->next)
1045 {
1046 /* Case-sensitive string comparison */
1047 if (trio_equal_case(def->name, name))
1048 break;
1049
1050 if (prev)
1051 *prev = def;
1052 }
1053
1056
1057 return def;
1058}
char * name
Definition: trio.c:744
struct _trio_userdef_t * next
Definition: trio.c:742
Definition: name.c:39
static trio_userdef_t * internalUserDef
Definition: trio.c:793
static TRIO_VOLATILE trio_callback_t internalEnterCriticalRegion
Definition: trio.c:791
static TRIO_VOLATILE trio_callback_t internalLeaveCriticalRegion
Definition: trio.c:792

◆ TRIO_ARGS2() [3/6]

TRIO_PRIVATE double TrioLogarithm TRIO_ARGS2 ( (number, base ,
double  number,
int  base 
)

Definition at line 1128 of file trio.c.

1131{
1132 double result;
1133
1134 if (number <= 0.0)
1135 {
1136 /* xlC crashes on log(0) */
1137 result = (number == 0.0) ? trio_ninf() : trio_nan();
1138 }
1139 else
1140 {
1141 if (base == 10)
1142 {
1143 result = log10(number);
1144 }
1145 else
1146 {
1147 result = log10(number) / log10((double)base);
1148 }
1149 }
1150 return result;
1151}
double log10(double x)
Definition: freeldr.c:125
GLuint64EXT * result
Definition: glext.h:11304
TRIO_PUBLIC double trio_ninf(TRIO_NOARGS)
Definition: trionan.c:302
TRIO_PUBLIC double trio_nan(TRIO_NOARGS)
Definition: trionan.c:323

◆ TRIO_ARGS2() [4/6]

TRIO_PRIVATE trio_long_double_t TrioPower TRIO_ARGS2 ( (number, exponent)  ,
int  number,
int  exponent 
)

Definition at line 1069 of file trio.c.

1072{
1074
1075 if (number == 10)
1076 {
1077 switch (exponent)
1078 {
1079 /* Speed up calculation of common cases */
1080 case 0:
1082 break;
1083 case 1:
1085 break;
1086 case 2:
1088 break;
1089 case 3:
1091 break;
1092 case 4:
1094 break;
1095 case 5:
1097 break;
1098 case 6:
1100 break;
1101 case 7:
1103 break;
1104 case 8:
1106 break;
1107 case 9:
1109 break;
1110 default:
1112 (trio_long_double_t)exponent);
1113 break;
1114 }
1115 }
1116 else
1117 {
1119 }
1120 return result;
1121}
#define TRIO_SUFFIX_LONG(x)
Definition: triodef.h:134
double trio_long_double_t
Definition: triodef.h:132
static const WCHAR E[]
Definition: oid.c:1253
#define powl(x, y)
Definition: trio.c:275

◆ TRIO_ARGS2() [5/6]

TRIO_PRIVATE void TrioInStreamString TRIO_ARGS2 ( (self, intPointer)  ,
trio_class_t self,
int intPointer 
)

Definition at line 6430 of file trio.c.

6433{
6434 FILE *file;
6435
6436 assert(VALID(self));
6437 assert(VALID(self->location));
6438 assert(VALID(file));
6439
6440 file = (FILE *)self->location;
6441
6442 self->current = fgetc(file);
6443 if (self->current == EOF)
6444 {
6445 self->error = (ferror(file))
6448 }
6449 else
6450 {
6451 self->processed++;
6452 self->committed++;
6453 }
6454
6455 if (VALID(intPointer))
6456 {
6457 *intPointer = self->current;
6458 }
6459}
@ TRIO_ERRNO
Definition: trio.h:62
#define assert(x)
Definition: debug.h:53
_Check_return_opt_ _CRTIMP int __cdecl fgetc(_Inout_ FILE *_File)
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
#define EOF
Definition: stdio.h:24
trio_pointer_t location
Definition: trio.c:708
int error
Definition: trio.c:731
int processed
Definition: trio.c:717
int committed
Definition: trio.c:723
Definition: fci.c:127
#define TRIO_ERROR_RETURN(x, y)
Definition: trio.c:121
#define VALID(x)
Definition: trio.c:114

◆ TRIO_ARGS2() [6/6]

TRIO_PRIVATE void TrioOutStreamStringDynamic TRIO_ARGS2 ( (self, output)  ,
trio_class_t self,
int  output 
)

Definition at line 3468 of file trio.c.

3471{
3472 FILE *file;
3473
3474 assert(VALID(self));
3475 assert(VALID(self->location));
3476
3477 file = (FILE *)self->location;
3478 self->processed++;
3479 if (fputc(output, file) == EOF)
3480 {
3481 self->error = TRIO_ERROR_RETURN(TRIO_EOF, 0);
3482 }
3483 else
3484 {
3485 self->committed++;
3486 }
3487}
_Check_return_opt_ _CRTIMP int __cdecl fputc(_In_ int _Ch, _Inout_ FILE *_File)
if(dx< 0)
Definition: linetemp.h:194

◆ TRIO_ARGS3() [1/3]

TRIO_PRIVATE int TrioScanProcess TRIO_ARGS3 ( (data, format, parameters)  ,
trio_class_t data,
TRIO_CONST char format,
trio_parameter_t parameters 
)

Definition at line 3084 of file trio.c.

3088{
3089#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE)
3090 int charlen;
3091#endif
3092 int i;
3093 TRIO_CONST char *string;
3096 int width;
3097 int precision;
3098 int base;
3099 int index;
3100
3101 index = 0;
3102 i = 0;
3103#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE)
3104 (void)mblen(NULL, 0);
3105#endif
3106
3107 while (format[index])
3108 {
3109#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE)
3110 if (! isascii(format[index]))
3111 {
3112 charlen = mblen(&format[index], MB_LEN_MAX);
3113 /*
3114 * Only valid multibyte characters are handled here. Invalid
3115 * multibyte characters (charlen == -1) are handled as normal
3116 * characters.
3117 */
3118 if (charlen != -1)
3119 {
3120 while (charlen-- > 0)
3121 {
3122 data->OutStream(data, format[index++]);
3123 }
3124 continue; /* while characters left in formatting string */
3125 }
3126 }
3127#endif /* TRIO_COMPILER_SUPPORTS_MULTIBYTE */
3129 {
3130 if (CHAR_IDENTIFIER == format[index + 1])
3131 {
3132 data->OutStream(data, CHAR_IDENTIFIER);
3133 index += 2;
3134 }
3135 else
3136 {
3137 /* Skip the parameter entries */
3138 while (parameters[i].type == FORMAT_PARAMETER)
3139 i++;
3140
3141 flags = parameters[i].flags;
3142
3143 /* Find width */
3144 width = parameters[i].width;
3146 {
3147 /* Get width from parameter list */
3148 width = (int)parameters[width].data.number.as_signed;
3149 if (width < 0)
3150 {
3151 /*
3152 * A negative width is the same as the - flag and
3153 * a positive width.
3154 */
3156 flags &= ~FLAGS_NILPADDING;
3157 width = -width;
3158 }
3159 }
3160
3161 /* Find precision */
3162 if (flags & FLAGS_PRECISION)
3163 {
3164 precision = parameters[i].precision;
3166 {
3167 /* Get precision from parameter list */
3168 precision = (int)parameters[precision].data.number.as_signed;
3169 if (precision < 0)
3170 {
3171 /*
3172 * A negative precision is the same as no
3173 * precision
3174 */
3176 }
3177 }
3178 }
3179 else
3180 {
3182 }
3183
3184 /* Find base */
3185 base = parameters[i].base;
3187 {
3188 /* Get base from parameter list */
3189 base = (int)parameters[base].data.number.as_signed;
3190 }
3191
3192 switch (parameters[i].type)
3193 {
3194 case FORMAT_CHAR:
3195 if (flags & FLAGS_QUOTE)
3196 data->OutStream(data, CHAR_QUOTE);
3197 if (! (flags & FLAGS_LEFTADJUST))
3198 {
3199 while (--width > 0)
3200 data->OutStream(data, CHAR_ADJUST);
3201 }
3202#if TRIO_WIDECHAR
3203 if (flags & FLAGS_WIDECHAR)
3204 {
3205 TrioWriteWideStringCharacter(data,
3206 (trio_wchar_t)parameters[i].data.number.as_signed,
3207 flags,
3208 NO_WIDTH);
3209 }
3210 else
3211#endif
3212 {
3213 TrioWriteStringCharacter(data,
3214 (int)parameters[i].data.number.as_signed,
3215 flags);
3216 }
3217
3218 if (flags & FLAGS_LEFTADJUST)
3219 {
3220 while(--width > 0)
3221 data->OutStream(data, CHAR_ADJUST);
3222 }
3223 if (flags & FLAGS_QUOTE)
3224 data->OutStream(data, CHAR_QUOTE);
3225
3226 break; /* FORMAT_CHAR */
3227
3228 case FORMAT_INT:
3229 TrioWriteNumber(data,
3230 parameters[i].data.number.as_unsigned,
3231 flags,
3232 width,
3233 precision,
3234 base);
3235
3236 break; /* FORMAT_INT */
3237
3238 case FORMAT_DOUBLE:
3239 TrioWriteDouble(data,
3240 parameters[i].data.longdoubleNumber,
3241 flags,
3242 width,
3243 precision,
3244 base);
3245 break; /* FORMAT_DOUBLE */
3246
3247 case FORMAT_STRING:
3248#if TRIO_WIDECHAR
3249 if (flags & FLAGS_WIDECHAR)
3250 {
3251 TrioWriteWideString(data,
3252 parameters[i].data.wstring,
3253 flags,
3254 width,
3255 precision);
3256 }
3257 else
3258#endif
3259 {
3260 TrioWriteString(data,
3261 parameters[i].data.string,
3262 flags,
3263 width,
3264 precision);
3265 }
3266 break; /* FORMAT_STRING */
3267
3268 case FORMAT_POINTER:
3269 {
3271
3272 reference.data = data;
3273 reference.parameter = &parameters[i];
3274 trio_print_pointer(&reference, parameters[i].data.pointer);
3275 }
3276 break; /* FORMAT_POINTER */
3277
3278 case FORMAT_COUNT:
3279 pointer = parameters[i].data.pointer;
3280 if (NULL != pointer)
3281 {
3282 /*
3283 * C99 paragraph 7.19.6.1.8 says "the number of
3284 * characters written to the output stream so far by
3285 * this call", which is data->committed
3286 */
3287#if defined(QUALIFIER_SIZE_T) || defined(QUALIFIER_SIZE_T_UPPER)
3288 if (flags & FLAGS_SIZE_T)
3289 *(size_t *)pointer = (size_t)data->committed;
3290 else
3291#endif
3292#if defined(QUALIFIER_PTRDIFF_T)
3293 if (flags & FLAGS_PTRDIFF_T)
3294 *(ptrdiff_t *)pointer = (ptrdiff_t)data->committed;
3295 else
3296#endif
3297#if defined(QUALIFIER_INTMAX_T)
3298 if (flags & FLAGS_INTMAX_T)
3299 *(trio_intmax_t *)pointer = (trio_intmax_t)data->committed;
3300 else
3301#endif
3302 if (flags & FLAGS_QUAD)
3303 {
3305 }
3306 else if (flags & FLAGS_LONG)
3307 {
3308 *(long int *)pointer = (long int)data->committed;
3309 }
3310 else if (flags & FLAGS_SHORT)
3311 {
3312 *(short int *)pointer = (short int)data->committed;
3313 }
3314 else
3315 {
3316 *(int *)pointer = (int)data->committed;
3317 }
3318 }
3319 break; /* FORMAT_COUNT */
3320
3321 case FORMAT_PARAMETER:
3322 break; /* FORMAT_PARAMETER */
3323
3324#if defined(FORMAT_ERRNO)
3325 case FORMAT_ERRNO:
3326 string = trio_error(parameters[i].data.errorNumber);
3327 if (string)
3328 {
3329 TrioWriteString(data,
3330 string,
3331 flags,
3332 width,
3333 precision);
3334 }
3335 else
3336 {
3337 data->OutStream(data, '#');
3338 TrioWriteNumber(data,
3339 (trio_uintmax_t)parameters[i].data.errorNumber,
3340 flags,
3341 width,
3342 precision,
3343 BASE_DECIMAL);
3344 }
3345 break; /* FORMAT_ERRNO */
3346#endif /* defined(FORMAT_ERRNO) */
3347
3348#if defined(FORMAT_USER_DEFINED)
3350 {
3352 trio_userdef_t *def = NULL;
3353
3354 if (parameters[i].user_name[0] == NIL)
3355 {
3356 /* Use handle */
3357 if ((i > 0) ||
3358 (parameters[i - 1].type == FORMAT_PARAMETER))
3359 def = (trio_userdef_t *)parameters[i - 1].data.pointer;
3360 }
3361 else
3362 {
3363 /* Look up namespace */
3364 def = TrioFindNamespace(parameters[i].user_name, NULL);
3365 }
3366 if (def) {
3367 reference.data = data;
3368 reference.parameter = &parameters[i];
3369 def->callback(&reference);
3370 }
3371 }
3372 break;
3373#endif /* defined(FORMAT_USER_DEFINED) */
3374
3375 default:
3376 break;
3377 } /* switch parameter type */
3378
3379 /* Prepare for next */
3380 index = parameters[i].indexAfterSpecifier;
3381 i++;
3382 }
3383 }
3384 else /* not identifier */
3385 {
3386 data->OutStream(data, format[index++]);
3387 }
3388 }
3389 return data->processed;
3390}
char * trio_pointer_t
Definition: triodef.h:133
#define TRIO_CONST
Definition: triodef.h:129
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLint GLint GLsizei width
Definition: gl.h:1546
GLsizei const GLvoid * pointer
Definition: glext.h:5848
GLint reference
Definition: glext.h:11729
GLbitfield flags
Definition: glext.h:7161
GLenum GLint GLint * precision
Definition: glext.h:7539
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_ int __cdecl mblen(_In_reads_bytes_opt_(_MaxCount) _Pre_opt_z_ const char *_Ch, _In_ size_t _MaxCount)
char string[160]
Definition: util.h:11
static WCHAR user_name[UNLEN+1]
Definition: access.c:32
trio_callback_t callback
Definition: trio.c:743
int indexAfterSpecifier
Definition: trio.c:663
trio_flags_t flags
Definition: trio.c:653
int precision
Definition: trio.c:657
trio_pointer_t pointer
Definition: trio.c:670
union trio_parameter_t::@4278 data
#define CHAR_ADJUST
Definition: trio.c:429
#define FORMAT_STRING
Definition: trio.c:413
trio_longlong_t trio_intmax_t
Definition: trio.c:246
#define FORMAT_ERRNO
Definition: trio.c:419
trio_ulonglong_t trio_uintmax_t
Definition: trio.c:247
#define isascii(x)
Definition: trio.c:323
#define FORMAT_PARAMETER
Definition: trio.c:416
#define CHAR_QUOTE
Definition: trio.c:428
#define FORMAT_USER_DEFINED
Definition: trio.c:422
unsigned long int trio_ulonglong_t
Definition: trio.c:214
#define FORMAT_DOUBLE
Definition: trio.c:411
#define FORMAT_INT
Definition: trio.c:410
#define FORMAT_COUNT
Definition: trio.c:415
#define CHAR_IDENTIFIER
Definition: trio.c:426
#define FORMAT_POINTER
Definition: trio.c:414
#define FORMAT_CHAR
Definition: trio.c:412
unsigned long trio_flags_t
Definition: trio.c:136

◆ TRIO_ARGS3() [2/3]

TRIO_PRIVATE void TrioWriteStringCharacter TRIO_ARGS3 ( (self, ch, flags ,
trio_class_t self,
int  ch,
trio_flags_t  flags 
)

Definition at line 2379 of file trio.c.

2383{
2385 {
2386 if (! isprint(ch))
2387 {
2388 /*
2389 * Non-printable characters are converted to C escapes or
2390 * \number, if no C escape exists.
2391 */
2392 self->OutStream(self, CHAR_BACKSLASH);
2393 switch (ch)
2394 {
2395 case '\007': self->OutStream(self, 'a'); break;
2396 case '\b': self->OutStream(self, 'b'); break;
2397 case '\f': self->OutStream(self, 'f'); break;
2398 case '\n': self->OutStream(self, 'n'); break;
2399 case '\r': self->OutStream(self, 'r'); break;
2400 case '\t': self->OutStream(self, 't'); break;
2401 case '\v': self->OutStream(self, 'v'); break;
2402 case '\\': self->OutStream(self, '\\'); break;
2403 default:
2404 self->OutStream(self, 'x');
2405 TrioWriteNumber(self, (trio_uintmax_t)ch,
2407 2, 2, BASE_HEX);
2408 break;
2409 }
2410 }
2411 else if (ch == CHAR_BACKSLASH)
2412 {
2413 self->OutStream(self, CHAR_BACKSLASH);
2414 self->OutStream(self, CHAR_BACKSLASH);
2415 }
2416 else
2417 {
2418 self->OutStream(self, ch);
2419 }
2420 }
2421 else
2422 {
2423 self->OutStream(self, ch);
2424 }
2425}
#define isprint(c)
Definition: acclib.h:73
#define CHAR_BACKSLASH
Definition: trio.c:427

◆ TRIO_ARGS3() [3/3]

TRIO_PRIVATE BOOLEAN_T TrioReadPointer TRIO_ARGS3 ( (self, target, flags ,
trio_class_t self,
trio_pointer_t target,
trio_flags_t  flags 
)

Definition at line 6003 of file trio.c.

6007{
6009 char buffer[sizeof(internalNullString)];
6010
6012
6013 if (TrioReadNumber(self,
6014 &number,
6015 flags,
6017 BASE_HEX))
6018 {
6019 /*
6020 * The strange assignment of number is a workaround for a compiler
6021 * warning
6022 */
6023 if (target)
6024 *target = (char *)0 + number;
6025 return TRUE;
6026 }
6027 else if (TrioReadString(self,
6029 ? NULL
6030 : buffer,
6031 0,
6032 sizeof(internalNullString) - 1))
6033 {
6034 if (trio_equal_case(buffer, internalNullString))
6035 {
6036 if (target)
6037 *target = NULL;
6038 return TRUE;
6039 }
6040 }
6041 return FALSE;
6042}
GLuint buffer
Definition: glext.h:5915
GLenum target
Definition: glext.h:7315
static TRIO_CONST char internalNullString[]
Definition: trio.c:764
#define POINTER_WIDTH
Definition: trio.c:311

◆ TRIO_ARGS4() [1/4]

TRIO_PRIVATE int TrioGetCharacterClass TRIO_ARGS4 ( (format, indexPointer, flagsPointer, characterclass)  ,
TRIO_CONST char format,
int indexPointer,
trio_flags_t flagsPointer,
int characterclass 
)

Definition at line 5180 of file trio.c.

5185{
5186 int index = *indexPointer;
5187 int i;
5188 char ch;
5189 char range_begin;
5190 char range_end;
5191
5192 *flagsPointer &= ~FLAGS_EXCLUDE;
5193
5195 {
5196 *flagsPointer |= FLAGS_EXCLUDE;
5197 index++;
5198 }
5199 /*
5200 * If the ungroup character is at the beginning of the scanlist,
5201 * it will be part of the class, and a second ungroup character
5202 * must follow to end the group.
5203 */
5205 {
5206 characterclass[(int)SPECIFIER_UNGROUP]++;
5207 index++;
5208 }
5209 /*
5210 * Minus is used to specify ranges. To include minus in the class,
5211 * it must be at the beginning of the list
5212 */
5214 {
5215 characterclass[(int)QUALIFIER_MINUS]++;
5216 index++;
5217 }
5218 /* Collect characters */
5219 for (ch = format[index];
5220 (ch != SPECIFIER_UNGROUP) && (ch != NIL);
5221 ch = format[++index])
5222 {
5223 switch (ch)
5224 {
5225 case QUALIFIER_MINUS: /* Scanlist ranges */
5226
5227 /*
5228 * Both C99 and UNIX98 describes ranges as implementation-
5229 * defined.
5230 *
5231 * We support the following behaviour (although this may
5232 * change as we become wiser)
5233 * - only increasing ranges, ie. [a-b] but not [b-a]
5234 * - transitive ranges, ie. [a-b-c] == [a-c]
5235 * - trailing minus, ie. [a-] is interpreted as an 'a'
5236 * and a '-'
5237 * - duplicates (although we can easily convert these
5238 * into errors)
5239 */
5240 range_begin = format[index - 1];
5241 range_end = format[++index];
5242 if (range_end == SPECIFIER_UNGROUP)
5243 {
5244 /* Trailing minus is included */
5245 characterclass[(int)ch]++;
5246 ch = range_end;
5247 break; /* for */
5248 }
5249 if (range_end == NIL)
5251 if (range_begin > range_end)
5253
5254 for (i = (int)range_begin; i <= (int)range_end; i++)
5255 characterclass[i]++;
5256
5257 ch = range_end;
5258 break;
5259
5260#if TRIO_EXTENSION
5261
5262 case SPECIFIER_GROUP:
5263
5264 switch (format[index + 1])
5265 {
5266 case QUALIFIER_DOT: /* Collating symbol */
5267 /*
5268 * FIXME: This will be easier to implement when multibyte
5269 * characters have been implemented. Until now, we ignore
5270 * this feature.
5271 */
5272 for (i = index + 2; ; i++)
5273 {
5274 if (format[i] == NIL)
5275 /* Error in syntax */
5276 return -1;
5277 else if (format[i] == QUALIFIER_DOT)
5278 break; /* for */
5279 }
5280 if (format[++i] != SPECIFIER_UNGROUP)
5281 return -1;
5282
5283 index = i;
5284 break;
5285
5286 case QUALIFIER_EQUAL: /* Equivalence class expressions */
5287 {
5288 unsigned int j;
5289 unsigned int k;
5290
5292 {
5293 /* Lazy evaluation of collation array */
5296 }
5297 for (i = index + 2; ; i++)
5298 {
5299 if (format[i] == NIL)
5300 /* Error in syntax */
5301 return -1;
5302 else if (format[i] == QUALIFIER_EQUAL)
5303 break; /* for */
5304 else
5305 {
5306 /* Mark any equivalent character */
5307 k = (unsigned int)format[i];
5308 for (j = 0; internalCollationArray[k][j] != NIL; j++)
5309 characterclass[(int)internalCollationArray[k][j]]++;
5310 }
5311 }
5312 if (format[++i] != SPECIFIER_UNGROUP)
5313 return -1;
5314
5315 index = i;
5316 }
5317 break;
5318
5319 case QUALIFIER_COLON: /* Character class expressions */
5320
5321 if (trio_equal_max(CLASS_ALNUM, sizeof(CLASS_ALNUM) - 1,
5322 &format[index]))
5323 {
5324 for (i = 0; i < MAX_CHARACTER_CLASS; i++)
5325 if (isalnum(i))
5326 characterclass[i]++;
5327 index += sizeof(CLASS_ALNUM) - 1;
5328 }
5329 else if (trio_equal_max(CLASS_ALPHA, sizeof(CLASS_ALPHA) - 1,
5330 &format[index]))
5331 {
5332 for (i = 0; i < MAX_CHARACTER_CLASS; i++)
5333 if (isalpha(i))
5334 characterclass[i]++;
5335 index += sizeof(CLASS_ALPHA) - 1;
5336 }
5337 else if (trio_equal_max(CLASS_CNTRL, sizeof(CLASS_CNTRL) - 1,
5338 &format[index]))
5339 {
5340 for (i = 0; i < MAX_CHARACTER_CLASS; i++)
5341 if (iscntrl(i))
5342 characterclass[i]++;
5343 index += sizeof(CLASS_CNTRL) - 1;
5344 }
5345 else if (trio_equal_max(CLASS_DIGIT, sizeof(CLASS_DIGIT) - 1,
5346 &format[index]))
5347 {
5348 for (i = 0; i < MAX_CHARACTER_CLASS; i++)
5349 if (isdigit(i))
5350 characterclass[i]++;
5351 index += sizeof(CLASS_DIGIT) - 1;
5352 }
5353 else if (trio_equal_max(CLASS_GRAPH, sizeof(CLASS_GRAPH) - 1,
5354 &format[index]))
5355 {
5356 for (i = 0; i < MAX_CHARACTER_CLASS; i++)
5357 if (isgraph(i))
5358 characterclass[i]++;
5359 index += sizeof(CLASS_GRAPH) - 1;
5360 }
5361 else if (trio_equal_max(CLASS_LOWER, sizeof(CLASS_LOWER) - 1,
5362 &format[index]))
5363 {
5364 for (i = 0; i < MAX_CHARACTER_CLASS; i++)
5365 if (islower(i))
5366 characterclass[i]++;
5367 index += sizeof(CLASS_LOWER) - 1;
5368 }
5369 else if (trio_equal_max(CLASS_PRINT, sizeof(CLASS_PRINT) - 1,
5370 &format[index]))
5371 {
5372 for (i = 0; i < MAX_CHARACTER_CLASS; i++)
5373 if (isprint(i))
5374 characterclass[i]++;
5375 index += sizeof(CLASS_PRINT) - 1;
5376 }
5377 else if (trio_equal_max(CLASS_PUNCT, sizeof(CLASS_PUNCT) - 1,
5378 &format[index]))
5379 {
5380 for (i = 0; i < MAX_CHARACTER_CLASS; i++)
5381 if (ispunct(i))
5382 characterclass[i]++;
5383 index += sizeof(CLASS_PUNCT) - 1;
5384 }
5385 else if (trio_equal_max(CLASS_SPACE, sizeof(CLASS_SPACE) - 1,
5386 &format[index]))
5387 {
5388 for (i = 0; i < MAX_CHARACTER_CLASS; i++)
5389 if (isspace(i))
5390 characterclass[i]++;
5391 index += sizeof(CLASS_SPACE) - 1;
5392 }
5393 else if (trio_equal_max(CLASS_UPPER, sizeof(CLASS_UPPER) - 1,
5394 &format[index]))
5395 {
5396 for (i = 0; i < MAX_CHARACTER_CLASS; i++)
5397 if (isupper(i))
5398 characterclass[i]++;
5399 index += sizeof(CLASS_UPPER) - 1;
5400 }
5401 else if (trio_equal_max(CLASS_XDIGIT, sizeof(CLASS_XDIGIT) - 1,
5402 &format[index]))
5403 {
5404 for (i = 0; i < MAX_CHARACTER_CLASS; i++)
5405 if (isxdigit(i))
5406 characterclass[i]++;
5407 index += sizeof(CLASS_XDIGIT) - 1;
5408 }
5409 else
5410 {
5411 characterclass[(int)ch]++;
5412 }
5413 break;
5414
5415 default:
5416 characterclass[(int)ch]++;
5417 break;
5418 }
5419 break;
5420
5421#endif /* TRIO_EXTENSION */
5422
5423 default:
5424 characterclass[(int)ch]++;
5425 break;
5426 }
5427 }
5428 return 0;
5429}
#define islower(c)
Definition: acclib.h:72
#define isalpha(c)
Definition: acclib.h:74
#define isdigit(c)
Definition: acclib.h:68
#define isxdigit(c)
Definition: acclib.h:70
#define isupper(c)
Definition: acclib.h:71
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
_Check_return_ _CRTIMP int __cdecl ispunct(_In_ int _C)
_Check_return_ _CRTIMP int __cdecl isgraph(_In_ int _C)
_Check_return_ _CRTIMP int __cdecl iscntrl(_In_ int _C)
_Check_return_ _CRTIMP int __cdecl isalnum(_In_ int _C)
int k
Definition: mpi.c:3369
#define CLASS_UPPER
Definition: trio.c:442
#define CLASS_SPACE
Definition: trio.c:441
#define QUALIFIER_EQUAL
Definition: trio.c:637
static BOOLEAN_T internalCollationUnconverted
Definition: trio.c:786
#define CLASS_GRAPH
Definition: trio.c:437
#define CLASS_LOWER
Definition: trio.c:438
#define CLASS_PRINT
Definition: trio.c:439
TRIO_PRIVATE void TrioGetCollation(TRIO_NOARGS)
Definition: trio.c:5146
#define CLASS_DIGIT
Definition: trio.c:436
#define CLASS_ALPHA
Definition: trio.c:433
#define SPECIFIER_UNGROUP
Definition: trio.c:493
#define CLASS_XDIGIT
Definition: trio.c:443
#define CLASS_ALNUM
Definition: trio.c:432
#define CLASS_PUNCT
Definition: trio.c:440
#define SPECIFIER_GROUP
Definition: trio.c:492
static char internalCollationArray[MAX_CHARACTER_CLASS][MAX_CHARACTER_CLASS]
Definition: trio.c:787
#define QUALIFIER_COLON
Definition: trio.c:636
#define CLASS_CNTRL
Definition: trio.c:435

◆ TRIO_ARGS4() [2/4]

TRIO_PRIVATE int TrioFormatRef TRIO_ARGS4 ( (reference, format, arglist, argarray)  ,
trio_reference_t reference,
TRIO_CONST char format,
TRIO_VA_LIST_PTR  arglist,
trio_pointer_t argarray 
)

Definition at line 3397 of file trio.c.

3402{
3403 int status;
3404 trio_parameter_t parameters[MAX_PARAMETERS];
3405
3406 status = TrioParse(TYPE_PRINT, format, parameters, arglist, argarray);
3407 if (status < 0)
3408 return status;
3409
3410 status = TrioFormatProcess(reference->data, format, parameters);
3411 if (reference->data->error != 0)
3412 {
3413 status = reference->data->error;
3414 }
3415 return status;
3416}
va_lists_t arglist[FMT_ARGMAX+1]
Definition: format.c:284
Definition: ps.c:97

◆ TRIO_ARGS4() [3/4]

TRIO_PRIVATE BOOLEAN_T TrioReadString TRIO_ARGS4 ( (self, target, flags, width ,
trio_class_t self,
char target,
trio_flags_t  flags,
int  width 
)

Definition at line 5569 of file trio.c.

5574{
5575 int i;
5576 char ch;
5578
5579 assert(VALID(self));
5580 assert(VALID(self->InStream));
5581
5582 for (i = 0;
5583 (self->current != EOF) && (i < width);
5584 i++)
5585 {
5586 ch = (char)self->current;
5587 self->InStream(self, NULL);
5588 if ((flags & FLAGS_ALTERNATIVE) && (ch == CHAR_BACKSLASH))
5589 {
5590 switch (self->current)
5591 {
5592 case '\\': ch = '\\'; break;
5593 case 'a': ch = '\007'; break;
5594 case 'b': ch = '\b'; break;
5595 case 'f': ch = '\f'; break;
5596 case 'n': ch = '\n'; break;
5597 case 'r': ch = '\r'; break;
5598 case 't': ch = '\t'; break;
5599 case 'v': ch = '\v'; break;
5600 default:
5601 if (isdigit(self->current))
5602 {
5603 /* Read octal number */
5604 if (!TrioReadNumber(self, &number, 0, 3, BASE_OCTAL))
5605 return 0;
5606 ch = (char)number;
5607 }
5608 else if (trio_to_upper(self->current) == 'X')
5609 {
5610 /* Read hexadecimal number */
5611 self->InStream(self, NULL);
5612 if (!TrioReadNumber(self, &number, 0, 2, BASE_HEX))
5613 return 0;
5614 ch = (char)number;
5615 }
5616 else
5617 {
5618 ch = (char)self->current;
5619 }
5620 break;
5621 }
5622 }
5623
5624 if (target)
5625 target[i] = ch;
5626 }
5627 return i + 1;
5628}
unsigned char
Definition: typeof.h:29

◆ TRIO_ARGS4() [4/4]

TRIO_PRIVATE BOOLEAN_T TrioReadDouble TRIO_ARGS4 ( (self, target, flags, width ,
trio_class_t self,
trio_pointer_t  target,
trio_flags_t  flags,
int  width 
)

Definition at line 5817 of file trio.c.

5822{
5823 int ch;
5824 char doubleString[512];
5825 int index = 0;
5826 int start;
5827 int j;
5828 BOOLEAN_T isHex = FALSE;
5829
5830 doubleString[0] = 0;
5831
5832 if ((width == NO_WIDTH) || (width > (int)sizeof(doubleString) - 1))
5833 width = sizeof(doubleString) - 1;
5834
5835 TrioSkipWhitespaces(self);
5836
5837 /*
5838 * Read entire double number from stream. trio_to_double requires
5839 * a string as input, but InStream can be anything, so we have to
5840 * collect all characters.
5841 */
5842 ch = self->current;
5843 if ((ch == '+') || (ch == '-'))
5844 {
5845 doubleString[index++] = (char)ch;
5846 self->InStream(self, &ch);
5847 width--;
5848 }
5849
5850 start = index;
5851 switch (ch)
5852 {
5853 case 'n':
5854 case 'N':
5855 /* Not-a-number */
5856 if (index != 0)
5857 break;
5858 /* FALLTHROUGH */
5859 case 'i':
5860 case 'I':
5861 /* Infinity */
5862 while (isalpha(ch) && (index - start < width))
5863 {
5864 doubleString[index++] = (char)ch;
5865 self->InStream(self, &ch);
5866 }
5867 doubleString[index] = NIL;
5868
5869 /* Case insensitive string comparison */
5870 if (trio_equal(&doubleString[start], INFINITE_UPPER) ||
5871 trio_equal(&doubleString[start], LONG_INFINITE_UPPER))
5872 {
5873 if (flags & FLAGS_LONGDOUBLE)
5874 {
5875 if ((start == 1) && (doubleString[0] == '-'))
5876 {
5878 }
5879 else
5880 {
5882 }
5883 }
5884 else
5885 {
5886 if ((start == 1) && (doubleString[0] == '-'))
5887 {
5888 *((double *)target) = trio_ninf();
5889 }
5890 else
5891 {
5892 *((double *)target) = trio_pinf();
5893 }
5894 }
5895 return TRUE;
5896 }
5897 if (trio_equal(doubleString, NAN_UPPER))
5898 {
5899 /* NaN must not have a preceding + nor - */
5900 if (flags & FLAGS_LONGDOUBLE)
5901 {
5903 }
5904 else
5905 {
5906 *((double *)target) = trio_nan();
5907 }
5908 return TRUE;
5909 }
5910 return FALSE;
5911
5912 case '0':
5913 doubleString[index++] = (char)ch;
5914 self->InStream(self, &ch);
5915 if (trio_to_upper(ch) == 'X')
5916 {
5917 isHex = TRUE;
5918 doubleString[index++] = (char)ch;
5919 self->InStream(self, &ch);
5920 }
5921 break;
5922
5923 default:
5924 break;
5925 }
5926
5927 while ((ch != EOF) && (index - start < width))
5928 {
5929 /* Integer part */
5930 if (isHex ? isxdigit(ch) : isdigit(ch))
5931 {
5932 doubleString[index++] = (char)ch;
5933 self->InStream(self, &ch);
5934 }
5935 else if (flags & FLAGS_QUOTE)
5936 {
5937 /* Compare with thousands separator */
5938 for (j = 0; internalThousandSeparator[j] && self->current; j++)
5939 {
5940 if (internalThousandSeparator[j] != self->current)
5941 break;
5942
5943 self->InStream(self, &ch);
5944 }
5946 break; /* Mismatch */
5947 else
5948 continue; /* Match */
5949 }
5950 else
5951 break; /* while */
5952 }
5953 if (ch == '.')
5954 {
5955 /* Decimal part */
5956 doubleString[index++] = (char)ch;
5957 self->InStream(self, &ch);
5958 while ((isHex ? isxdigit(ch) : isdigit(ch)) &&
5959 (index - start < width))
5960 {
5961 doubleString[index++] = (char)ch;
5962 self->InStream(self, &ch);
5963 }
5964 if (isHex ? (trio_to_upper(ch) == 'P') : (trio_to_upper(ch) == 'E'))
5965 {
5966 /* Exponent */
5967 doubleString[index++] = (char)ch;
5968 self->InStream(self, &ch);
5969 if ((ch == '+') || (ch == '-'))
5970 {
5971 doubleString[index++] = (char)ch;
5972 self->InStream(self, &ch);
5973 }
5974 while (isdigit(ch) && (index - start < width))
5975 {
5976 doubleString[index++] = (char)ch;
5977 self->InStream(self, &ch);
5978 }
5979 }
5980 }
5981
5982 if ((index == start) || (*doubleString == NIL))
5983 return FALSE;
5984
5985 doubleString[index] = 0;
5986
5987 if (flags & FLAGS_LONGDOUBLE)
5988 {
5989 *((trio_long_double_t *)target) = trio_to_long_double(doubleString, NULL);
5990 }
5991 else
5992 {
5993 *((double *)target) = trio_to_double(doubleString, NULL);
5994 }
5995 return TRUE;
5996}
GLuint start
Definition: gl.h:1545
TRIO_PUBLIC double trio_pinf(TRIO_NOARGS)
Definition: trionan.c:258
#define LONG_INFINITE_UPPER
Definition: trio.c:317
#define INFINITE_UPPER
Definition: trio.c:315
#define BOOLEAN_T
Definition: trio.c:111
#define NAN_UPPER
Definition: trio.c:319

◆ TRIO_ARGS5() [1/4]

TRIO_PRIVATE void TrioWriteString TRIO_ARGS5 ( (self, string, flags, width, precision ,
trio_class_t self,
TRIO_CONST char string,
trio_flags_t  flags,
int  width,
int  precision 
)

Definition at line 2435 of file trio.c.

2441{
2442 int length;
2443 int ch;
2444
2445 assert(VALID(self));
2446 assert(VALID(self->OutStream));
2447
2448 if (string == NULL)
2449 {
2450 string = internalNullString;
2451 length = sizeof(internalNullString) - 1;
2452 /* Disable quoting for the null pointer */
2453 flags &= (~FLAGS_QUOTE);
2454 width = 0;
2455 }
2456 else
2457 {
2458 length = trio_length(string);
2459 }
2460 if ((NO_PRECISION != precision) &&
2461 (precision < length))
2462 {
2463 length = precision;
2464 }
2465 width -= length;
2466
2467 if (flags & FLAGS_QUOTE)
2468 self->OutStream(self, CHAR_QUOTE);
2469
2470 if (! (flags & FLAGS_LEFTADJUST))
2471 {
2472 while (width-- > 0)
2473 self->OutStream(self, CHAR_ADJUST);
2474 }
2475
2476 while (length-- > 0)
2477 {
2478 /* The ctype parameters must be an unsigned char (or EOF) */
2479 ch = (int)((unsigned char)(*string++));
2480 TrioWriteStringCharacter(self, ch, flags);
2481 }
2482
2483 if (flags & FLAGS_LEFTADJUST)
2484 {
2485 while (width-- > 0)
2486 self->OutStream(self, CHAR_ADJUST);
2487 }
2488 if (flags & FLAGS_QUOTE)
2489 self->OutStream(self, CHAR_QUOTE);
2490}
GLuint GLsizei GLsizei * length
Definition: glext.h:6040

◆ TRIO_ARGS5() [2/4]

TRIO_PRIVATE BOOLEAN_T TrioReadGroup TRIO_ARGS5 ( (self, target, characterclass, flags, width ,
trio_class_t self,
char target,
int characterclass,
trio_flags_t  flags,
int  width 
)

Definition at line 5778 of file trio.c.

5784{
5785 int ch;
5786 int i;
5787
5788 assert(VALID(self));
5789 assert(VALID(self->InStream));
5790
5791 ch = self->current;
5792 for (i = 0;
5793 ((width == NO_WIDTH) || (i < width)) &&
5794 (! ((ch == EOF) ||
5795 (((flags & FLAGS_EXCLUDE) != 0) ^ (characterclass[ch] == 0))));
5796 i++)
5797 {
5798 if (target)
5799 target[i] = (char)ch;
5800 self->InStream(self, &ch);
5801 }
5802
5803 if (target)
5804 target[i] = NIL;
5805 return TRUE;
5806}

◆ TRIO_ARGS5() [3/4]

TRIO_PRIVATE BOOLEAN_T TrioReadNumber TRIO_ARGS5 ( (self, target, flags, width, base ,
trio_class_t self,
trio_uintmax_t target,
trio_flags_t  flags,
int  width,
int  base 
)

Definition at line 5439 of file trio.c.

5445{
5447 int digit;
5448 int count;
5449 BOOLEAN_T isNegative = FALSE;
5450 BOOLEAN_T gotNumber = FALSE;
5451 int j;
5452
5453 assert(VALID(self));
5454 assert(VALID(self->InStream));
5455 assert((base >= MIN_BASE && base <= MAX_BASE) || (base == NO_BASE));
5456
5458 {
5459 /* Lazy evaluation of digits array */
5461 for (j = 0; j < (int)sizeof(internalDigitsLower) - 1; j++)
5462 {
5465 }
5467 }
5468
5469 TrioSkipWhitespaces(self);
5470
5471 if (!(flags & FLAGS_UNSIGNED))
5472 {
5473 /* Leading sign */
5474 if (self->current == '+')
5475 {
5476 self->InStream(self, NULL);
5477 }
5478 else if (self->current == '-')
5479 {
5480 self->InStream(self, NULL);
5481 isNegative = TRUE;
5482 }
5483 }
5484
5485 count = self->processed;
5486
5488 {
5489 switch (base)
5490 {
5491 case NO_BASE:
5492 case BASE_OCTAL:
5493 case BASE_HEX:
5494 case BASE_BINARY:
5495 if (self->current == '0')
5496 {
5497 self->InStream(self, NULL);
5498 if (self->current)
5499 {
5500 if ((base == BASE_HEX) &&
5501 (trio_to_upper(self->current) == 'X'))
5502 {
5503 self->InStream(self, NULL);
5504 }
5505 else if ((base == BASE_BINARY) &&
5506 (trio_to_upper(self->current) == 'B'))
5507 {
5508 self->InStream(self, NULL);
5509 }
5510 }
5511 }
5512 else
5513 return FALSE;
5514 break;
5515 default:
5516 break;
5517 }
5518 }
5519
5520 while (((width == NO_WIDTH) || (self->processed - count < width)) &&
5521 (! ((self->current == EOF) || isspace(self->current))))
5522 {
5523 if (isascii(self->current))
5524 {
5525 digit = internalDigitArray[self->current];
5526 /* Abort if digit is not allowed in the specified base */
5527 if ((digit == -1) || (digit >= base))
5528 break;
5529 }
5530 else if (flags & FLAGS_QUOTE)
5531 {
5532 /* Compare with thousands separator */
5533 for (j = 0; internalThousandSeparator[j] && self->current; j++)
5534 {
5535 if (internalThousandSeparator[j] != self->current)
5536 break;
5537
5538 self->InStream(self, NULL);
5539 }
5541 break; /* Mismatch */
5542 else
5543 continue; /* Match */
5544 }
5545 else
5546 break;
5547
5548 number *= base;
5549 number += digit;
5550 gotNumber = TRUE; /* we need at least one digit */
5551
5552 self->InStream(self, NULL);
5553 }
5554
5555 /* Was anything read at all? */
5556 if (!gotNumber)
5557 return FALSE;
5558
5559 if (target)
5560 *target = (isNegative) ? -((trio_intmax_t)number) : number;
5561 return TRUE;
5562}
#define memset(x, y, z)
Definition: compat.h:39
static int internalDigitArray[128]
Definition: trio.c:784
static BOOLEAN_T internalDigitsUnconverted
Definition: trio.c:783
static TRIO_CONST char internalDigitsLower[]
Definition: trio.c:781
static TRIO_CONST char internalDigitsUpper[]
Definition: trio.c:782

◆ TRIO_ARGS5() [4/4]

TRIO_PRIVATE int TrioParse TRIO_ARGS5 ( (type, format, parameters, arglist, argarray)  ,
int  type,
TRIO_CONST char format,
trio_parameter_t parameters,
TRIO_VA_LIST_PTR  arglist,
trio_pointer_t argarray 
)

Definition at line 1179 of file trio.c.

1185{
1186 /* Count the number of times a parameter is referenced */
1187 unsigned short usedEntries[MAX_PARAMETERS];
1188 /* Parameter counters */
1189 int parameterPosition;
1190 int currentParam;
1191 int maxParam = -1;
1192 /* Utility variables */
1194 int width;
1195 int precision;
1196 int varsize;
1197 int base;
1198 int index; /* Index into formatting string */
1199 int dots; /* Count number of dots in modifier part */
1200 BOOLEAN_T positional; /* Does the specifier have a positional? */
1201 BOOLEAN_T gotSticky = FALSE; /* Are there any sticky modifiers at all? */
1202 /*
1203 * indices specifies the order in which the parameters must be
1204 * read from the va_args (this is necessary to handle positionals)
1205 */
1207 int pos = 0;
1208 /* Various variables */
1209 char ch;
1210#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE)
1211 int charlen;
1212#endif
1213 int save_errno;
1214 int i = -1;
1215 int num;
1216 char *tmpformat;
1217
1218 /* One and only one of arglist and argarray must be used */
1219 assert((arglist != NULL) ^ (argarray != NULL));
1220
1221 /*
1222 * The 'parameters' array is not initialized, but we need to
1223 * know which entries we have used.
1224 */
1225 memset(usedEntries, 0, sizeof(usedEntries));
1226
1227 save_errno = errno;
1228 index = 0;
1229 parameterPosition = 0;
1230#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE)
1231 (void)mblen(NULL, 0);
1232#endif
1233
1234 while (format[index])
1235 {
1236#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE)
1237 if (! isascii(format[index]))
1238 {
1239 /*
1240 * Multibyte characters cannot be legal specifiers or
1241 * modifiers, so we skip over them.
1242 */
1243 charlen = mblen(&format[index], MB_LEN_MAX);
1244 index += (charlen > 0) ? charlen : 1;
1245 continue; /* while */
1246 }
1247#endif /* TRIO_COMPILER_SUPPORTS_MULTIBYTE */
1248 if (CHAR_IDENTIFIER == format[index++])
1249 {
1251 {
1252 index++;
1253 continue; /* while */
1254 }
1255
1256 flags = FLAGS_NEW;
1257 dots = 0;
1258 currentParam = TrioGetPosition(format, &index);
1259 positional = (NO_POSITION != currentParam);
1260 if (!positional)
1261 {
1262 /* We have no positional, get the next counter */
1263 currentParam = parameterPosition;
1264 }
1265 if(currentParam >= MAX_PARAMETERS)
1266 {
1267 /* Bail out completely to make the error more obvious */
1269 }
1270
1271 if (currentParam > maxParam)
1272 maxParam = currentParam;
1273
1274 /* Default values */
1275 width = NO_WIDTH;
1277 base = NO_BASE;
1278 varsize = NO_SIZE;
1279
1280 while (TrioIsQualifier(format[index]))
1281 {
1282 ch = format[index++];
1283
1284 switch (ch)
1285 {
1286 case QUALIFIER_SPACE:
1287 flags |= FLAGS_SPACE;
1288 break;
1289
1290 case QUALIFIER_PLUS:
1292 break;
1293
1294 case QUALIFIER_MINUS:
1296 flags &= ~FLAGS_NILPADDING;
1297 break;
1298
1301 break;
1302
1303 case QUALIFIER_DOT:
1304 if (dots == 0) /* Precision */
1305 {
1306 dots++;
1307
1308 /* Skip if no precision */
1309 if (QUALIFIER_DOT == format[index])
1310 break;
1311
1312 /* After the first dot we have the precision */
1314 if ((QUALIFIER_STAR == format[index])
1315#if defined(QUALIFIER_PARAM)
1317#endif
1318 )
1319 {
1320 index++;
1322
1323 precision = TrioGetPosition(format, &index);
1324 if (precision == NO_POSITION)
1325 {
1326 parameterPosition++;
1327 if (positional)
1328 precision = parameterPosition;
1329 else
1330 {
1331 precision = currentParam;
1332 currentParam = precision + 1;
1333 }
1334 }
1335 else
1336 {
1337 if (! positional)
1338 currentParam = precision + 1;
1339 if (width > maxParam)
1340 maxParam = precision;
1341 }
1342 if (currentParam > maxParam)
1343 maxParam = currentParam;
1344 }
1345 else
1346 {
1347 precision = trio_to_long(&format[index],
1348 &tmpformat,
1349 BASE_DECIMAL);
1350 index = (int)(tmpformat - format);
1351 }
1352 }
1353 else if (dots == 1) /* Base */
1354 {
1355 dots++;
1356
1357 /* After the second dot we have the base */
1358 flags |= FLAGS_BASE;
1359 if ((QUALIFIER_STAR == format[index])
1360#if defined(QUALIFIER_PARAM)
1362#endif
1363 )
1364 {
1365 index++;
1367 base = TrioGetPosition(format, &index);
1368 if (base == NO_POSITION)
1369 {
1370 parameterPosition++;
1371 if (positional)
1372 base = parameterPosition;
1373 else
1374 {
1375 base = currentParam;
1376 currentParam = base + 1;
1377 }
1378 }
1379 else
1380 {
1381 if (! positional)
1382 currentParam = base + 1;
1383 if (base > maxParam)
1384 maxParam = base;
1385 }
1386 if (currentParam > maxParam)
1387 maxParam = currentParam;
1388 }
1389 else
1390 {
1391 base = trio_to_long(&format[index],
1392 &tmpformat,
1393 BASE_DECIMAL);
1394 if (base > MAX_BASE)
1396 index = (int)(tmpformat - format);
1397 }
1398 }
1399 else
1400 {
1402 }
1403 break; /* QUALIFIER_DOT */
1404
1405#if defined(QUALIFIER_PARAM)
1406 case QUALIFIER_PARAM:
1407 type = TYPE_PRINT;
1408 /* FALLTHROUGH */
1409#endif
1410 case QUALIFIER_STAR:
1411 /* This has different meanings for print and scan */
1412 if (TYPE_PRINT == type)
1413 {
1414 /* Read with from parameter */
1416 width = TrioGetPosition(format, &index);
1417 if (width == NO_POSITION)
1418 {
1419 parameterPosition++;
1420 if (positional)
1421 width = parameterPosition;
1422 else
1423 {
1424 width = currentParam;
1425 currentParam = width + 1;
1426 }
1427 }
1428 else
1429 {
1430 if (! positional)
1431 currentParam = width + 1;
1432 if (width > maxParam)
1433 maxParam = width;
1434 }
1435 if (currentParam > maxParam)
1436 maxParam = currentParam;
1437 }
1438 else
1439 {
1440 /* Scan, but do not store result */
1442 }
1443
1444 break; /* QUALIFIER_STAR */
1445
1446 case '0':
1447 if (! (flags & FLAGS_LEFTADJUST))
1449 /* FALLTHROUGH */
1450 case '1': case '2': case '3': case '4':
1451 case '5': case '6': case '7': case '8': case '9':
1452 flags |= FLAGS_WIDTH;
1453 /* &format[index - 1] is used to "rewind" the read
1454 * character from format
1455 */
1456 width = trio_to_long(&format[index - 1],
1457 &tmpformat,
1458 BASE_DECIMAL);
1459 index = (int)(tmpformat - format);
1460 break;
1461
1462 case QUALIFIER_SHORT:
1463 if (flags & FLAGS_SHORTSHORT)
1465 else if (flags & FLAGS_SHORT)
1467 else
1468 flags |= FLAGS_SHORT;
1469 break;
1470
1471 case QUALIFIER_LONG:
1472 if (flags & FLAGS_QUAD)
1474 else if (flags & FLAGS_LONG)
1475 flags |= FLAGS_QUAD;
1476 else
1477 flags |= FLAGS_LONG;
1478 break;
1479
1482 break;
1483
1484#if defined(QUALIFIER_SIZE_T)
1485 case QUALIFIER_SIZE_T:
1487 /* Modify flags for later truncation of number */
1488 if (sizeof(size_t) == sizeof(trio_ulonglong_t))
1489 flags |= FLAGS_QUAD;
1490 else if (sizeof(size_t) == sizeof(long))
1491 flags |= FLAGS_LONG;
1492 break;
1493#endif
1494
1495#if defined(QUALIFIER_PTRDIFF_T)
1498 if (sizeof(ptrdiff_t) == sizeof(trio_ulonglong_t))
1499 flags |= FLAGS_QUAD;
1500 else if (sizeof(ptrdiff_t) == sizeof(long))
1501 flags |= FLAGS_LONG;
1502 break;
1503#endif
1504
1505#if defined(QUALIFIER_INTMAX_T)
1506 case QUALIFIER_INTMAX_T:
1508 if (sizeof(trio_intmax_t) == sizeof(trio_ulonglong_t))
1509 flags |= FLAGS_QUAD;
1510 else if (sizeof(trio_intmax_t) == sizeof(long))
1511 flags |= FLAGS_LONG;
1512 break;
1513#endif
1514
1515#if defined(QUALIFIER_QUAD)
1516 case QUALIFIER_QUAD:
1517 flags |= FLAGS_QUAD;
1518 break;
1519#endif
1520
1521#if defined(QUALIFIER_FIXED_SIZE)
1523 if (flags & FLAGS_FIXED_SIZE)
1525
1529
1530 if ((format[index] == '6') &&
1531 (format[index + 1] == '4'))
1532 {
1533 varsize = sizeof(trio_int64_t);
1534 index += 2;
1535 }
1536 else if ((format[index] == '3') &&
1537 (format[index + 1] == '2'))
1538 {
1539 varsize = sizeof(trio_int32_t);
1540 index += 2;
1541 }
1542 else if ((format[index] == '1') &&
1543 (format[index + 1] == '6'))
1544 {
1545 varsize = sizeof(trio_int16_t);
1546 index += 2;
1547 }
1548 else if (format[index] == '8')
1549 {
1550 varsize = sizeof(trio_int8_t);
1551 index++;
1552 }
1553 else
1555
1557 break;
1558#endif
1559
1560#if defined(QUALIFIER_WIDECHAR)
1561 case QUALIFIER_WIDECHAR:
1563 break;
1564#endif
1565
1566#if defined(QUALIFIER_SIZE_T_UPPER)
1568 break;
1569#endif
1570
1571#if defined(QUALIFIER_QUOTE)
1572 case QUALIFIER_QUOTE:
1573 flags |= FLAGS_QUOTE;
1574 break;
1575#endif
1576
1577#if defined(QUALIFIER_STICKY)
1578 case QUALIFIER_STICKY:
1580 gotSticky = TRUE;
1581 break;
1582#endif
1583
1584#if defined(QUALIFIER_VARSIZE)
1585 case QUALIFIER_VARSIZE:
1587 parameterPosition++;
1588 if (positional)
1589 varsize = parameterPosition;
1590 else
1591 {
1592 varsize = currentParam;
1593 currentParam = varsize + 1;
1594 }
1595 if (currentParam > maxParam)
1596 maxParam = currentParam;
1597 break;
1598#endif
1599
1600#if defined(QUALIFIER_ROUNDING_UPPER)
1603 break;
1604#endif
1605
1606 default:
1607 /* Bail out completely to make the error more obvious */
1609 }
1610 } /* while qualifier */
1611
1612 /*
1613 * Parameters only need the type and value. The value is
1614 * read later.
1615 */
1617 {
1618 usedEntries[width] += 1;
1619 parameters[pos].type = FORMAT_PARAMETER;
1620 parameters[pos].flags = 0;
1621 indices[width] = pos;
1622 width = pos++;
1623 }
1625 {
1626 usedEntries[precision] += 1;
1627 parameters[pos].type = FORMAT_PARAMETER;
1628 parameters[pos].flags = 0;
1630 precision = pos++;
1631 }
1633 {
1634 usedEntries[base] += 1;
1635 parameters[pos].type = FORMAT_PARAMETER;
1636 parameters[pos].flags = 0;
1637 indices[base] = pos;
1638 base = pos++;
1639 }
1641 {
1642 usedEntries[varsize] += 1;
1643 parameters[pos].type = FORMAT_PARAMETER;
1644 parameters[pos].flags = 0;
1645 indices[varsize] = pos;
1646 varsize = pos++;
1647 }
1648
1649 indices[currentParam] = pos;
1650
1651 switch (format[index++])
1652 {
1653#if defined(SPECIFIER_CHAR_UPPER)
1656 /* FALLTHROUGH */
1657#endif
1658 case SPECIFIER_CHAR:
1659 if (flags & FLAGS_LONG)
1661 else if (flags & FLAGS_SHORT)
1662 flags &= ~FLAGS_WIDECHAR;
1663 parameters[pos].type = FORMAT_CHAR;
1664 break;
1665
1666#if defined(SPECIFIER_STRING_UPPER)
1669 /* FALLTHROUGH */
1670#endif
1671 case SPECIFIER_STRING:
1672 if (flags & FLAGS_LONG)
1674 else if (flags & FLAGS_SHORT)
1675 flags &= ~FLAGS_WIDECHAR;
1676 parameters[pos].type = FORMAT_STRING;
1677 break;
1678
1679 case SPECIFIER_GROUP:
1680 if (TYPE_SCAN == type)
1681 {
1682 int depth = 1;
1683 parameters[pos].type = FORMAT_GROUP;
1685 index++;
1687 index++;
1689 index++;
1690 /* Skip nested brackets */
1691 while (format[index] != NIL)
1692 {
1694 {
1695 depth++;
1696 }
1697 else if (format[index] == SPECIFIER_UNGROUP)
1698 {
1699 if (--depth <= 0)
1700 {
1701 index++;
1702 break;
1703 }
1704 }
1705 index++;
1706 }
1707 }
1708 break;
1709
1710 case SPECIFIER_INTEGER:
1711 parameters[pos].type = FORMAT_INT;
1712 break;
1713
1714 case SPECIFIER_UNSIGNED:
1716 parameters[pos].type = FORMAT_INT;
1717 break;
1718
1719 case SPECIFIER_DECIMAL:
1720 /* Disable base modifier */
1721 flags &= ~FLAGS_BASE_PARAMETER;
1723 parameters[pos].type = FORMAT_INT;
1724 break;
1725
1726 case SPECIFIER_OCTAL:
1728 flags &= ~FLAGS_BASE_PARAMETER;
1729 base = BASE_OCTAL;
1730 parameters[pos].type = FORMAT_INT;
1731 break;
1732
1733#if defined(SPECIFIER_BINARY)
1735 flags |= FLAGS_UPPER;
1736 /* FALLTHROUGH */
1737 case SPECIFIER_BINARY:
1739 flags &= ~FLAGS_BASE_PARAMETER;
1740 base = BASE_BINARY;
1741 parameters[pos].type = FORMAT_INT;
1742 break;
1743#endif
1744
1746 flags |= FLAGS_UPPER;
1747 /* FALLTHROUGH */
1748 case SPECIFIER_HEX:
1750 flags &= ~FLAGS_BASE_PARAMETER;
1751 base = BASE_HEX;
1752 parameters[pos].type = FORMAT_INT;
1753 break;
1754
1756 flags |= FLAGS_UPPER;
1757 /* FALLTHROUGH */
1758 case SPECIFIER_FLOAT_E:
1760 parameters[pos].type = FORMAT_DOUBLE;
1761 break;
1762
1764 flags |= FLAGS_UPPER;
1765 /* FALLTHROUGH */
1766 case SPECIFIER_FLOAT_G:
1768 parameters[pos].type = FORMAT_DOUBLE;
1769 break;
1770
1772 flags |= FLAGS_UPPER;
1773 /* FALLTHROUGH */
1774 case SPECIFIER_FLOAT_F:
1775 parameters[pos].type = FORMAT_DOUBLE;
1776 break;
1777
1778 case SPECIFIER_POINTER:
1779 if (sizeof(trio_pointer_t) == sizeof(trio_ulonglong_t))
1780 flags |= FLAGS_QUAD;
1781 else if (sizeof(trio_pointer_t) == sizeof(long))
1782 flags |= FLAGS_LONG;
1783 parameters[pos].type = FORMAT_POINTER;
1784 break;
1785
1786 case SPECIFIER_COUNT:
1787 parameters[pos].type = FORMAT_COUNT;
1788 break;
1789
1790#if defined(SPECIFIER_HEXFLOAT)
1791# if defined(SPECIFIER_HEXFLOAT_UPPER)
1793 flags |= FLAGS_UPPER;
1794 /* FALLTHROUGH */
1795# endif
1796 case SPECIFIER_HEXFLOAT:
1797 base = BASE_HEX;
1798 parameters[pos].type = FORMAT_DOUBLE;
1799 break;
1800#endif
1801
1802#if defined(FORMAT_ERRNO)
1803 case SPECIFIER_ERRNO:
1804 parameters[pos].type = FORMAT_ERRNO;
1805 break;
1806#endif
1807
1808#if defined(SPECIFIER_USER_DEFINED_BEGIN)
1810 {
1811 unsigned int max;
1812 int without_namespace = TRUE;
1813
1814 parameters[pos].type = FORMAT_USER_DEFINED;
1815 parameters[pos].user_name[0] = NIL;
1816 tmpformat = (char *)&format[index];
1817
1818 while ((ch = format[index]))
1819 {
1820 index++;
1822 {
1823 if (without_namespace)
1824 {
1825 /* We must get the handle first */
1826 parameters[pos].type = FORMAT_PARAMETER;
1827 parameters[pos].indexAfterSpecifier = index;
1828 parameters[pos].flags = FLAGS_USER_DEFINED;
1829 /* Adjust parameters for insertion of new one */
1830 pos++;
1831 usedEntries[currentParam] += 1;
1832 parameters[pos].type = FORMAT_USER_DEFINED;
1833 currentParam++;
1834 indices[currentParam] = pos;
1835 if (currentParam > maxParam)
1836 maxParam = currentParam;
1837 }
1838 /* Copy the user data */
1839 max = (unsigned int)(&format[index] - tmpformat);
1840 if (max > MAX_USER_DATA)
1842 trio_copy_max(parameters[pos].user_data,
1843 max,
1844 tmpformat);
1845 break; /* while */
1846 }
1848 {
1849 without_namespace = FALSE;
1850 /* Copy the namespace for later looking-up */
1851 max = (int)(&format[index] - tmpformat);
1852 if (max > MAX_USER_NAME)
1854 trio_copy_max(parameters[pos].user_name,
1855 max,
1856 tmpformat);
1857 tmpformat = (char *)&format[index];
1858 }
1859 }
1862 }
1863 break;
1864#endif /* defined(SPECIFIER_USER_DEFINED_BEGIN) */
1865
1866 default:
1867 /* Bail out completely to make the error more obvious */
1869 }
1870
1871 /* Count the number of times this entry has been used */
1872 usedEntries[currentParam] += 1;
1873
1874 /* Find last sticky parameters */
1875 if (gotSticky && !(flags & FLAGS_STICKY))
1876 {
1877 for (i = pos - 1; i >= 0; i--)
1878 {
1879 if (parameters[i].type == FORMAT_PARAMETER)
1880 continue;
1881 if ((parameters[i].flags & FLAGS_STICKY) &&
1882 (parameters[i].type == parameters[pos].type))
1883 {
1884 /* Do not overwrite current qualifiers */
1885 flags |= (parameters[i].flags & (unsigned long)~FLAGS_STICKY);
1886 if (width == NO_WIDTH)
1887 width = parameters[i].width;
1888 if (precision == NO_PRECISION)
1889 precision = parameters[i].precision;
1890 if (base == NO_BASE)
1891 base = parameters[i].base;
1892 break;
1893 }
1894 }
1895 }
1896
1897 parameters[pos].indexAfterSpecifier = index;
1898 parameters[pos].flags = flags;
1899 parameters[pos].width = width;
1900 parameters[pos].precision = precision;
1901 parameters[pos].base = (base == NO_BASE) ? BASE_DECIMAL : base;
1902 parameters[pos].varsize = varsize;
1903 pos++;
1904
1905 if (! positional)
1906 parameterPosition++;
1907
1908 } /* if identifier */
1909
1910 } /* while format characters left */
1911
1912 for (num = 0; num <= maxParam; num++)
1913 {
1914 if (usedEntries[num] != 1)
1915 {
1916 if (usedEntries[num] == 0) /* gap detected */
1918 else /* double references detected */
1920 }
1921
1922 i = indices[num];
1923
1924 /*
1925 * FORMAT_PARAMETERS are only present if they must be read,
1926 * so it makes no sense to check the ignore flag (besides,
1927 * the flags variable is not set for that particular type)
1928 */
1929 if ((parameters[i].type != FORMAT_PARAMETER) &&
1930 (parameters[i].flags & FLAGS_IGNORE))
1931 continue; /* for all arguments */
1932
1933 /*
1934 * The stack arguments are read according to ANSI C89
1935 * default argument promotions:
1936 *
1937 * char = int
1938 * short = int
1939 * unsigned char = unsigned int
1940 * unsigned short = unsigned int
1941 * float = double
1942 *
1943 * In addition to the ANSI C89 these types are read (the
1944 * default argument promotions of C99 has not been
1945 * considered yet)
1946 *
1947 * long long
1948 * long double
1949 * size_t
1950 * ptrdiff_t
1951 * intmax_t
1952 */
1953 switch (parameters[i].type)
1954 {
1955 case FORMAT_GROUP:
1956 case FORMAT_STRING:
1957#if TRIO_WIDECHAR
1958 if (flags & FLAGS_WIDECHAR)
1959 {
1960 parameters[i].data.wstring = (argarray == NULL)
1961 ? va_arg(TRIO_VA_LIST_DEREF(arglist), trio_wchar_t *)
1962 : (trio_wchar_t *)(argarray[num]);
1963 }
1964 else
1965#endif
1966 {
1967 parameters[i].data.string = (argarray == NULL)
1969 : (char *)(argarray[num]);
1970 }
1971 break;
1972
1973#if defined(FORMAT_USER_DEFINED)
1975#endif
1976 case FORMAT_POINTER:
1977 case FORMAT_COUNT:
1978 case FORMAT_UNKNOWN:
1979 parameters[i].data.pointer = (argarray == NULL)
1981 : argarray[num];
1982 break;
1983
1984 case FORMAT_CHAR:
1985 case FORMAT_INT:
1986 if (TYPE_SCAN == type)
1987 {
1988 if (argarray == NULL)
1989 parameters[i].data.pointer =
1991 else
1992 {
1993 if (parameters[i].type == FORMAT_CHAR)
1994 parameters[i].data.pointer =
1995 (trio_pointer_t)((char *)argarray[num]);
1996 else if (parameters[i].flags & FLAGS_SHORT)
1997 parameters[i].data.pointer =
1998 (trio_pointer_t)((short *)argarray[num]);
1999 else
2000 parameters[i].data.pointer =
2001 (trio_pointer_t)((int *)argarray[num]);
2002 }
2003 }
2004 else
2005 {
2006#if defined(QUALIFIER_VARSIZE) || defined(QUALIFIER_FIXED_SIZE)
2007 if (parameters[i].flags
2009 {
2010 if (parameters[i].flags & FLAGS_VARSIZE_PARAMETER)
2011 {
2012 /*
2013 * Variable sizes are mapped onto the fixed sizes, in
2014 * accordance with integer promotion.
2015 *
2016 * Please note that this may not be portable, as we
2017 * only guess the size, not the layout of the numbers.
2018 * For example, if int is little-endian, and long is
2019 * big-endian, then this will fail.
2020 */
2021 varsize = (int)parameters[parameters[i].varsize].data.number.as_unsigned;
2022 }
2023 else
2024 {
2025 /* Used for the I<bits> modifiers */
2026 varsize = parameters[i].varsize;
2027 }
2028 parameters[i].flags &= ~FLAGS_ALL_VARSIZES;
2029
2030 if (varsize <= (int)sizeof(int))
2031 ;
2032 else if (varsize <= (int)sizeof(long))
2033 parameters[i].flags |= FLAGS_LONG;
2034#if defined(QUALIFIER_INTMAX_T)
2035 else if (varsize <= (int)sizeof(trio_longlong_t))
2036 parameters[i].flags |= FLAGS_QUAD;
2037 else
2038 parameters[i].flags |= FLAGS_INTMAX_T;
2039#else
2040 else
2041 parameters[i].flags |= FLAGS_QUAD;
2042#endif
2043 }
2044#endif /* defined(QUALIFIER_VARSIZE) */
2045#if defined(QUALIFIER_SIZE_T) || defined(QUALIFIER_SIZE_T_UPPER)
2046 if (parameters[i].flags & FLAGS_SIZE_T)
2047 parameters[i].data.number.as_unsigned = (argarray == NULL)
2049 : (trio_uintmax_t)(*((size_t *)argarray[num]));
2050 else
2051#endif
2052#if defined(QUALIFIER_PTRDIFF_T)
2053 if (parameters[i].flags & FLAGS_PTRDIFF_T)
2054 parameters[i].data.number.as_unsigned = (argarray == NULL)
2056 : (trio_uintmax_t)(*((ptrdiff_t *)argarray[num]));
2057 else
2058#endif
2059#if defined(QUALIFIER_INTMAX_T)
2060 if (parameters[i].flags & FLAGS_INTMAX_T)
2061 parameters[i].data.number.as_unsigned = (argarray == NULL)
2063 : (trio_uintmax_t)(*((trio_intmax_t *)argarray[num]));
2064 else
2065#endif
2066 if (parameters[i].flags & FLAGS_QUAD)
2067 parameters[i].data.number.as_unsigned = (argarray == NULL)
2069 : (trio_uintmax_t)(*((trio_ulonglong_t *)argarray[num]));
2070 else if (parameters[i].flags & FLAGS_LONG)
2071 parameters[i].data.number.as_unsigned = (argarray == NULL)
2073 : (trio_uintmax_t)(*((long *)argarray[num]));
2074 else
2075 {
2076 if (argarray == NULL)
2078 else
2079 {
2080 if (parameters[i].type == FORMAT_CHAR)
2081 parameters[i].data.number.as_unsigned = (trio_uintmax_t)(*((char *)argarray[num]));
2082 else if (parameters[i].flags & FLAGS_SHORT)
2083 parameters[i].data.number.as_unsigned = (trio_uintmax_t)(*((short *)argarray[num]));
2084 else
2085 parameters[i].data.number.as_unsigned = (trio_uintmax_t)(*((int *)argarray[num]));
2086 }
2087 }
2088 }
2089 break;
2090
2091 case FORMAT_PARAMETER:
2092 /*
2093 * The parameter for the user-defined specifier is a pointer,
2094 * whereas the rest (width, precision, base) uses an integer.
2095 */
2096 if (parameters[i].flags & FLAGS_USER_DEFINED)
2097 parameters[i].data.pointer = (argarray == NULL)
2099 : argarray[num];
2100 else
2101 parameters[i].data.number.as_unsigned = (argarray == NULL)
2103 : (trio_uintmax_t)(*((int *)argarray[num]));
2104 break;
2105
2106 case FORMAT_DOUBLE:
2107 if (TYPE_SCAN == type)
2108 {
2109 if (parameters[i].flags & FLAGS_LONGDOUBLE)
2110 parameters[i].data.longdoublePointer = (argarray == NULL)
2112 : (trio_long_double_t *)argarray[num];
2113 else
2114 {
2115 if (parameters[i].flags & FLAGS_LONG)
2116 parameters[i].data.doublePointer = (argarray == NULL)
2117 ? va_arg(TRIO_VA_LIST_DEREF(arglist), double *)
2118 : (double *)argarray[num];
2119 else
2120 parameters[i].data.doublePointer = (argarray == NULL)
2121 ? (double *)va_arg(TRIO_VA_LIST_DEREF(arglist), float *)
2122 : (double *)((float *)argarray[num]);
2123 }
2124 }
2125 else
2126 {
2127 if (parameters[i].flags & FLAGS_LONGDOUBLE)
2128 parameters[i].data.longdoubleNumber = (argarray == NULL)
2130 : (trio_long_double_t)(*((trio_long_double_t *)argarray[num]));
2131 else
2132 {
2133 if (argarray == NULL)
2134 parameters[i].data.longdoubleNumber =
2136 else
2137 {
2138 if (parameters[i].flags & FLAGS_SHORT)
2139 parameters[i].data.longdoubleNumber =
2140 (trio_long_double_t)(*((float *)argarray[num]));
2141 else
2142 parameters[i].data.longdoubleNumber =
2143 (trio_long_double_t)(*((double *)argarray[num]));
2144 }
2145 }
2146 }
2147 break;
2148
2149#if defined(FORMAT_ERRNO)
2150 case FORMAT_ERRNO:
2151 parameters[i].data.errorNumber = save_errno;
2152 break;
2153#endif
2154
2155 default:
2156 break;
2157 }
2158 } /* for all specifiers */
2159 return num;
2160}
#define va_arg(ap, T)
Definition: acmsvcex.h:89
unsigned long
Definition: typeof.h:102
__kernel_size_t size_t
Definition: linux.h:237
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLuint GLuint GLsizei GLenum const GLvoid * indices
Definition: gl.h:1545
GLuint GLuint num
Definition: glext.h:9618
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:80
static float(__cdecl *square_half_float)(float x
#define long
Definition: qsort.c:33
#define errno
Definition: errno.h:18
int errorNumber
Definition: trio.c:679
trio_long_double_t longdoubleNumber
Definition: trio.c:677
trio_long_double_t * longdoublePointer
Definition: trio.c:678
union trio_parameter_t::@4278::@4279 number
double * doublePointer
Definition: trio.c:676
char * string
Definition: trio.c:666
trio_uintmax_t as_unsigned
Definition: trio.c:673
char user_name[MAX_USER_NAME]
Definition: trio.c:682
#define max(a, b)
Definition: svc.c:63
#define SPECIFIER_USER_DEFINED_BEGIN
Definition: trio.c:509
#define SPECIFIER_DECIMAL
Definition: trio.c:479
#define SPECIFIER_BINARY_UPPER
Definition: trio.c:508
#define SPECIFIER_USER_DEFINED_SEPARATOR
Definition: trio.c:511
#define SPECIFIER_CHAR
Definition: trio.c:477
#define SPECIFIER_FLOAT_F_UPPER
Definition: trio.c:488
#define SPECIFIER_ERRNO
Definition: trio.c:504
#define SPECIFIER_FLOAT_G_UPPER
Definition: trio.c:490
#define SPECIFIER_STRING
Definition: trio.c:478
TRIO_SIGNED long int trio_longlong_t
Definition: trio.c:213
TRIO_SIGNED int trio_int32_t
Definition: trio.c:261
#define SPECIFIER_HEX
Definition: trio.c:483
#define TRIO_VA_LIST_DEREF(l)
Definition: trio.c:129
#define SPECIFIER_BINARY
Definition: trio.c:507
#define SPECIFIER_UNSIGNED
Definition: trio.c:481
#define SPECIFIER_INTEGER
Definition: trio.c:480
#define SPECIFIER_HEXFLOAT_UPPER
Definition: trio.c:501
#define SPECIFIER_USER_DEFINED_END
Definition: trio.c:510
#define SPECIFIER_FLOAT_F
Definition: trio.c:487
#define SPECIFIER_POINTER
Definition: trio.c:491
#define FORMAT_UNKNOWN
Definition: trio.c:409
#define SPECIFIER_FLOAT_E_UPPER
Definition: trio.c:486
#define SPECIFIER_FLOAT_E
Definition: trio.c:485
TRIO_SIGNED char trio_int8_t
Definition: trio.c:251
#define SPECIFIER_CHAR_UPPER
Definition: trio.c:496
#define SPECIFIER_HEXFLOAT
Definition: trio.c:500
#define SPECIFIER_FLOAT_G
Definition: trio.c:489
#define FORMAT_GROUP
Definition: trio.c:417
#define SPECIFIER_STRING_UPPER
Definition: trio.c:497
TRIO_SIGNED short trio_int16_t
Definition: trio.c:256
#define SPECIFIER_OCTAL
Definition: trio.c:482
#define SPECIFIER_HEX_UPPER
Definition: trio.c:484
#define SPECIFIER_COUNT
Definition: trio.c:494
trio_longlong_t trio_int64_t
Definition: trio.c:266

◆ TRIO_ARGS6() [1/4]

TRIO_PRIVATE int TrioFormat TRIO_ARGS6 ( (destination, destinationSize, OutStream, format, arglist, argarray)  ,
trio_pointer_t  destination,
size_t  destinationSize,
void *OutStream   TRIO_PROTO(trio_class_t *, int),
TRIO_CONST char format,
TRIO_VA_LIST_PTR  arglist,
trio_pointer_t argarray 
)

Definition at line 3423 of file trio.c.

3430{
3431 int status;
3433 trio_parameter_t parameters[MAX_PARAMETERS];
3434
3435 assert(VALID(OutStream));
3437
3438 memset(&data, 0, sizeof(data));
3439 data.OutStream = OutStream;
3440 data.location = destination;
3441 data.max = destinationSize;
3442 data.error = 0;
3443
3444#if defined(USE_LOCALE)
3445 if (NULL == internalLocaleValues)
3446 {
3447 TrioSetLocale();
3448 }
3449#endif
3450
3451 status = TrioParse(TYPE_PRINT, format, parameters, arglist, argarray);
3452 if (status < 0)
3453 return status;
3454
3455 status = TrioFormatProcess(&data, format, parameters);
3456 if (data.error != 0)
3457 {
3458 status = data.error;
3459 }
3460 return status;
3461}

◆ TRIO_ARGS6() [2/4]

TRIO_PRIVATE void TrioWriteDouble TRIO_ARGS6 ( (self, number, flags, width, precision, base ,
trio_class_t self,
trio_long_double_t  number,
trio_flags_t  flags,
int  width,
int  precision,
int  base 
)

Definition at line 2618 of file trio.c.

2625{
2626 trio_long_double_t integerNumber;
2627 trio_long_double_t fractionNumber;
2628 trio_long_double_t workNumber;
2629 int integerDigits;
2630 int fractionDigits;
2631 int exponentDigits;
2632 int baseDigits;
2633 int integerThreshold;
2634 int fractionThreshold;
2635 int expectedWidth;
2636 int exponent = 0;
2637 unsigned int uExponent = 0;
2638 int exponentBase;
2639 trio_long_double_t dblBase;
2640 trio_long_double_t dblIntegerBase;
2641 trio_long_double_t dblFractionBase;
2642 trio_long_double_t integerAdjust;
2643 trio_long_double_t fractionAdjust;
2644 BOOLEAN_T isNegative;
2645 BOOLEAN_T isExponentNegative = FALSE;
2646 BOOLEAN_T requireTwoDigitExponent;
2647 BOOLEAN_T isHex;
2648 TRIO_CONST char *digits;
2649 char *groupingPointer;
2650 int i;
2651 int index;
2652 BOOLEAN_T hasOnlyZeroes;
2653 int zeroes = 0;
2654 register int trailingZeroes;
2655 BOOLEAN_T keepTrailingZeroes;
2656 BOOLEAN_T keepDecimalPoint;
2657 trio_long_double_t epsilon;
2658
2659 assert(VALID(self));
2660 assert(VALID(self->OutStream));
2661 assert(((base >= MIN_BASE) && (base <= MAX_BASE)) || (base == NO_BASE));
2662
2663 /* Determine sign and look for special quantities */
2664 switch (trio_fpclassify_and_signbit(number, &isNegative))
2665 {
2666 case TRIO_FP_NAN:
2667 TrioWriteString(self,
2668 (flags & FLAGS_UPPER)
2669 ? NAN_UPPER
2670 : NAN_LOWER,
2672 return;
2673
2674 case TRIO_FP_INFINITE:
2675 if (isNegative)
2676 {
2677 /* Negative infinity */
2678 TrioWriteString(self,
2679 (flags & FLAGS_UPPER)
2680 ? "-" INFINITE_UPPER
2681 : "-" INFINITE_LOWER,
2683 return;
2684 }
2685 else
2686 {
2687 /* Positive infinity */
2688 TrioWriteString(self,
2689 (flags & FLAGS_UPPER)
2693 return;
2694 }
2695
2696 default:
2697 /* Finitude */
2698 break;
2699 }
2700
2701 /* Normal numbers */
2702 if (flags & FLAGS_LONGDOUBLE)
2703 {
2704 baseDigits = (base == 10)
2705 ? LDBL_DIG
2706 : (int)floor(LDBL_MANT_DIG / TrioLogarithmBase(base));
2707 epsilon = LDBL_EPSILON;
2708 }
2709 else if (flags & FLAGS_SHORT)
2710 {
2711 baseDigits = (base == BASE_DECIMAL)
2712 ? FLT_DIG
2713 : (int)floor(FLT_MANT_DIG / TrioLogarithmBase(base));
2714 epsilon = FLT_EPSILON;
2715 }
2716 else
2717 {
2718 baseDigits = (base == BASE_DECIMAL)
2719 ? DBL_DIG
2720 : (int)floor(DBL_MANT_DIG / TrioLogarithmBase(base));
2721 epsilon = DBL_EPSILON;
2722 }
2723
2725 isHex = (base == BASE_HEX);
2726 if (base == NO_BASE)
2728 dblBase = (trio_long_double_t)base;
2729 keepTrailingZeroes = !( (flags & FLAGS_ROUNDING) ||
2730 ( (flags & FLAGS_FLOAT_G) &&
2731 !(flags & FLAGS_ALTERNATIVE) ) );
2732
2733 if (flags & FLAGS_ROUNDING)
2734 precision = baseDigits;
2735
2736 if (precision == NO_PRECISION)
2737 {
2738 if (isHex)
2739 {
2740 keepTrailingZeroes = FALSE;
2742 }
2743 else
2744 {
2746 }
2747 }
2748
2749 if (isNegative)
2750 number = -number;
2751
2752 if (isHex)
2754
2755 if (flags & FLAGS_FLOAT_G)
2756 {
2757 if (precision == 0)
2758 precision = 1;
2759
2760 if ((number < 1.0E-4) || (number > powl(base,
2762 {
2763 /* Use scientific notation */
2765 }
2766 else if (number < 1.0)
2767 {
2768 /*
2769 * Use normal notation. If the integer part of the number is
2770 * zero, then adjust the precision to include leading fractional
2771 * zeros.
2772 */
2773 workNumber = TrioLogarithm(number, base);
2774 workNumber = TRIO_FABS(workNumber);
2775 if (workNumber - floorl(workNumber) < 0.001)
2776 workNumber--;
2777 zeroes = (int)floorl(workNumber);
2778 }
2779 }
2780
2781 if (flags & FLAGS_FLOAT_E)
2782 {
2783 /* Scale the number */
2784 workNumber = TrioLogarithm(number, base);
2785 if (trio_isinf(workNumber) == -1)
2786 {
2787 exponent = 0;
2788 /* Undo setting */
2789 if (flags & FLAGS_FLOAT_G)
2790 flags &= ~FLAGS_FLOAT_E;
2791 }
2792 else
2793 {
2794 exponent = (int)floorl(workNumber);
2795 number /= powl(dblBase, (trio_long_double_t)exponent);
2796 isExponentNegative = (exponent < 0);
2797 uExponent = (isExponentNegative) ? -exponent : exponent;
2798 if (isHex)
2799 uExponent *= 4; /* log16(2) */
2800 /* No thousand separators */
2801 flags &= ~FLAGS_QUOTE;
2802 }
2803 }
2804
2805 integerNumber = floorl(number);
2806 fractionNumber = number - integerNumber;
2807
2808 /*
2809 * Truncated number.
2810 *
2811 * Precision is number of significant digits for FLOAT_G
2812 * and number of fractional digits for others.
2813 */
2814 integerDigits = (integerNumber > epsilon)
2815 ? 1 + (int)TrioLogarithm(integerNumber, base)
2816 : 1;
2817 fractionDigits = ((flags & FLAGS_FLOAT_G) && (zeroes == 0))
2818 ? precision - integerDigits
2819 : zeroes + precision;
2820
2821 dblFractionBase = TrioPower(base, fractionDigits);
2822
2823 workNumber = number + 0.5 / dblFractionBase;
2824 if (floorl(number) != floorl(workNumber))
2825 {
2826 if (flags & FLAGS_FLOAT_E)
2827 {
2828 /* Adjust if number was rounded up one digit (ie. 0.99 to 1.00) */
2829 exponent++;
2830 isExponentNegative = (exponent < 0);
2831 uExponent = (isExponentNegative) ? -exponent : exponent;
2832 if (isHex)
2833 uExponent *= 4; /* log16(2) */
2834 workNumber = (number + 0.5 / dblFractionBase) / dblBase;
2835 integerNumber = floorl(workNumber);
2836 fractionNumber = workNumber - integerNumber;
2837 }
2838 else
2839 {
2840 /* Adjust if number was rounded up one digit (ie. 99 to 100) */
2841 integerNumber = floorl(number + 0.5);
2842 fractionNumber = 0.0;
2843 integerDigits = (integerNumber > epsilon)
2844 ? 1 + (int)TrioLogarithm(integerNumber, base)
2845 : 1;
2846 }
2847 }
2848
2849 /* Estimate accuracy */
2850 integerAdjust = fractionAdjust = 0.5;
2851 if (flags & FLAGS_ROUNDING)
2852 {
2853 if (integerDigits > baseDigits)
2854 {
2855 integerThreshold = baseDigits;
2856 fractionDigits = 0;
2857 dblFractionBase = 1.0;
2858 fractionThreshold = 0;
2859 precision = 0; /* Disable decimal-point */
2860 integerAdjust = TrioPower(base, integerDigits - integerThreshold - 1);
2861 fractionAdjust = 0.0;
2862 }
2863 else
2864 {
2865 integerThreshold = integerDigits;
2866 fractionThreshold = fractionDigits - integerThreshold;
2867 fractionAdjust = 1.0;
2868 }
2869 }
2870 else
2871 {
2872 integerThreshold = INT_MAX;
2873 fractionThreshold = INT_MAX;
2874 }
2875
2876 /*
2877 * Calculate expected width.
2878 * sign + integer part + thousands separators + decimal point
2879 * + fraction + exponent
2880 */
2881 fractionAdjust /= dblFractionBase;
2882 hasOnlyZeroes = (floorl((fractionNumber + fractionAdjust) * dblFractionBase) < epsilon);
2883 keepDecimalPoint = ( (flags & FLAGS_ALTERNATIVE) ||
2884 !((precision == 0) ||
2885 (!keepTrailingZeroes && hasOnlyZeroes)) );
2886 if (flags & FLAGS_FLOAT_E)
2887 {
2888 exponentDigits = (uExponent == 0)
2889 ? 1
2890 : (int)ceil(TrioLogarithm((double)(uExponent + 1),
2891 (isHex) ? 10.0 : base));
2892 }
2893 else
2894 exponentDigits = 0;
2895 requireTwoDigitExponent = ((base == BASE_DECIMAL) && (exponentDigits == 1));
2896
2897 expectedWidth = integerDigits + fractionDigits
2898 + (keepDecimalPoint
2900 : 0)
2901 + ((flags & FLAGS_QUOTE)
2902 ? TrioCalcThousandSeparatorLength(integerDigits)
2903 : 0);
2904 if (isNegative || (flags & FLAGS_SHOWSIGN) || (flags & FLAGS_SPACE))
2905 expectedWidth += sizeof("-") - 1;
2906 if (exponentDigits > 0)
2907 expectedWidth += exponentDigits +
2908 ((requireTwoDigitExponent ? sizeof("E+0") : sizeof("E+")) - 1);
2909 if (isHex)
2910 expectedWidth += sizeof("0X") - 1;
2911
2912 /* Output prefixing */
2913 if (flags & FLAGS_NILPADDING)
2914 {
2915 /* Leading zeros must be after sign */
2916 if (isNegative)
2917 self->OutStream(self, '-');
2918 else if (flags & FLAGS_SHOWSIGN)
2919 self->OutStream(self, '+');
2920 else if (flags & FLAGS_SPACE)
2921 self->OutStream(self, ' ');
2922 if