15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*************************************************************************
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * $Id$
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Copyright (C) 1998 Bjorn Reese and Daniel Stenberg.
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Permission to use, copy, modify, and distribute this software for any
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * purpose with or without fee is hereby granted, provided that the above
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * copyright notice and this permission notice appear in all copies.
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER.
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *************************************************************************
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * A note to trio contributors:
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Avoid heap allocation at all costs to ensure that the trio functions
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * are async-safe. The exceptions are the printf/fprintf functions, which
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * uses fputc, and the asprintf functions and the <alloc> modifier, which
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * by design are required to allocate form the heap.
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ************************************************************************/
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * TODO:
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *  - Scan is probably too permissive about its modifiers.
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *  - C escapes in %#[] ?
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *  - Multibyte characters (done for format parsing, except scan groups)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *  - Complex numbers? (C99 _Complex)
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *  - Boolean values? (C99 _Bool)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *  - C99 NaN(n-char-sequence) missing. The n-char-sequence can be used
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    to print the mantissa, e.g. NaN(0xc000000000000000)
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *  - Should we support the GNU %a alloc modifier? GNU has an ugly hack
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    for %a, because C99 used %a for other purposes. If specified as
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    %as or %a[ it is interpreted as the alloc modifier, otherwise as
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    the C99 hex-float. This means that you cannot scan %as as a hex-float
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    immediately followed by an 's'.
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *  - Scanning of collating symbols.
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*************************************************************************
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Trio include files
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "triodef.h"
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "trio.h"
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "triop.h"
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "trionan.h"
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(TRIO_MINIMAL)
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# include "triostr.h"
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**************************************************************************
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Definitions
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *************************************************************************/
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <math.h>
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <limits.h>
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <float.h>
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if (defined(__STDC_ISO_10646__) || defined(MB_LEN_MAX) \
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     || defined(USE_MULTIBYTE) || TRIO_WIDECHAR) \
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    && !defined(_WIN32_WCE)
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define TRIO_COMPILER_SUPPORTS_MULTIBYTE
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# if !defined(MB_LEN_MAX)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  define MB_LEN_MAX 6
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# endif
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if (defined(TRIO_COMPILER_MSVC) && (_MSC_VER >= 1100)) || defined(TRIO_COMPILER_BCB)
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define TRIO_COMPILER_SUPPORTS_MSVC_INT
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(_WIN32_WCE)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <wincecompat.h>
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*************************************************************************
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Generic definitions
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !(defined(DEBUG) || defined(NDEBUG))
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define NDEBUG
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <assert.h>
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <ctype.h>
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(TRIO_COMPILER_SUPPORTS_C99)
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define isblank(x) (((x)==32) || ((x)==9))
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(TRIO_COMPILER_ANCIENT)
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# include <varargs.h>
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# include <stdarg.h>
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <stddef.h>
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef HAVE_ERRNO_H
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <errno.h>
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NULL
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define NULL 0
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NIL ((char)0)
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef FALSE
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define FALSE (1 == 0)
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define TRUE (! FALSE)
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define BOOLEAN_T int
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* mincore() can be used for debugging purposes */
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define VALID(x) (NULL != (x))
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_ERRORS
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /*
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * Encode the error code and the position. This is decoded
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * with TRIO_ERROR_CODE and TRIO_ERROR_POSITION.
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   */
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define TRIO_ERROR_RETURN(x,y) (- ((x) + ((y) << 8)))
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define TRIO_ERROR_RETURN(x,y) (-1)
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef unsigned long trio_flags_t;
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*************************************************************************
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Platform specific definitions
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(TRIO_PLATFORM_UNIX)
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# include <unistd.h>
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# include <signal.h>
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# include <locale.h>
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define USE_LOCALE
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif /* TRIO_PLATFORM_UNIX */
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(TRIO_PLATFORM_VMS)
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# include <unistd.h>
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(TRIO_PLATFORM_WIN32)
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# if defined(_WIN32_WCE)
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  include <wincecompat.h>
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# else
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  include <io.h>
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  define read _read
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  define write _write
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# endif
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif /* TRIO_PLATFORM_WIN32 */
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_WIDECHAR
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# if defined(TRIO_COMPILER_SUPPORTS_ISO94)
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  include <wchar.h>
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  include <wctype.h>
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef wchar_t trio_wchar_t;
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef wint_t trio_wint_t;
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# else
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef char trio_wchar_t;
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef int trio_wint_t;
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  define WCONST(x) L ## x
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  define WEOF EOF
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  define iswalnum(x) isalnum(x)
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  define iswalpha(x) isalpha(x)
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  define iswblank(x) isblank(x)
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  define iswcntrl(x) iscntrl(x)
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  define iswdigit(x) isdigit(x)
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  define iswgraph(x) isgraph(x)
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  define iswlower(x) islower(x)
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  define iswprint(x) isprint(x)
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  define iswpunct(x) ispunct(x)
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  define iswspace(x) isspace(x)
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  define iswupper(x) isupper(x)
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  define iswxdigit(x) isxdigit(x)
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# endif
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*************************************************************************
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Compiler dependent definitions
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* Support for long long */
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef __cplusplus
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# if !defined(USE_LONGLONG)
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  if defined(TRIO_COMPILER_GCC) && !defined(__STRICT_ANSI__)
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#   define USE_LONGLONG
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  elif defined(TRIO_COMPILER_SUNPRO)
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#   define USE_LONGLONG
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  elif defined(_LONG_LONG) || defined(_LONGLONG)
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#   define USE_LONGLONG
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#  endif
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# endif
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* The extra long numbers */
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(USE_LONGLONG)
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef signed long long int trio_longlong_t;
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef unsigned long long int trio_ulonglong_t;
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#elif defined(TRIO_COMPILER_SUPPORTS_MSVC_INT)
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef signed __int64 trio_longlong_t;
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef unsigned __int64 trio_ulonglong_t;
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef TRIO_SIGNED long int trio_longlong_t;
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef unsigned long int trio_ulonglong_t;
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* Maximal and fixed integer types */
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(TRIO_COMPILER_SUPPORTS_C99)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# include <stdint.h>
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef intmax_t trio_intmax_t;
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef uintmax_t trio_uintmax_t;
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef int8_t trio_int8_t;
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef int16_t trio_int16_t;
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef int32_t trio_int32_t;
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef int64_t trio_int64_t;
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#elif defined(TRIO_COMPILER_SUPPORTS_UNIX98)
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# include <inttypes.h>
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef intmax_t trio_intmax_t;
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef uintmax_t trio_uintmax_t;
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef int8_t trio_int8_t;
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef int16_t trio_int16_t;
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef int32_t trio_int32_t;
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef int64_t trio_int64_t;
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#elif defined(TRIO_COMPILER_SUPPORTS_MSVC_INT)
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef trio_longlong_t trio_intmax_t;
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef trio_ulonglong_t trio_uintmax_t;
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef __int8 trio_int8_t;
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef __int16 trio_int16_t;
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef __int32 trio_int32_t;
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef __int64 trio_int64_t;
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef trio_longlong_t trio_intmax_t;
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef trio_ulonglong_t trio_uintmax_t;
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# if defined(TRIO_INT8_T)
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef TRIO_INT8_T trio_int8_t;
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# else
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef TRIO_SIGNED char trio_int8_t;
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# endif
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# if defined(TRIO_INT16_T)
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef TRIO_INT16_T trio_int16_t;
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# else
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef TRIO_SIGNED short trio_int16_t;
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# endif
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# if defined(TRIO_INT32_T)
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef TRIO_INT32_T trio_int32_t;
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# else
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef TRIO_SIGNED int trio_int32_t;
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# endif
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# if defined(TRIO_INT64_T)
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef TRIO_INT64_T trio_int64_t;
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# else
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef trio_longlong_t trio_int64_t;
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# endif
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if (!(defined(TRIO_COMPILER_SUPPORTS_C99) \
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) || defined(TRIO_COMPILER_SUPPORTS_UNIX01))) \
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) && !defined(_WIN32_WCE)
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define floorl(x) floor((double)(x))
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define fmodl(x,y) fmod((double)(x),(double)(y))
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define powl(x,y) pow((double)(x),(double)(y))
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define TRIO_FABS(x) (((x) < 0.0) ? -(x) : (x))
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*************************************************************************
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Internal Definitions
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef DECIMAL_DIG
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define DECIMAL_DIG DBL_DIG
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* Long double sizes */
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef LDBL_DIG
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define MAX_MANTISSA_DIGITS LDBL_DIG
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define MAX_EXPONENT_DIGITS 4
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define MAX_DOUBLE_DIGITS LDBL_MAX_10_EXP
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define MAX_MANTISSA_DIGITS DECIMAL_DIG
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define MAX_EXPONENT_DIGITS 3
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define MAX_DOUBLE_DIGITS DBL_MAX_10_EXP
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(TRIO_COMPILER_ANCIENT) || !defined(LDBL_DIG)
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# undef LDBL_DIG
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# undef LDBL_MANT_DIG
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# undef LDBL_EPSILON
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define LDBL_DIG DBL_DIG
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define LDBL_MANT_DIG DBL_MANT_DIG
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define LDBL_EPSILON DBL_EPSILON
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* The maximal number of digits is for base 2 */
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define MAX_CHARS_IN(x) (sizeof(x) * CHAR_BIT)
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* The width of a pointer. The number of bits in a hex digit is 4 */
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define POINTER_WIDTH ((sizeof("0x") - 1) + sizeof(trio_pointer_t) * CHAR_BIT / 4)
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* Infinite and Not-A-Number for floating-point */
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define INFINITE_LOWER "inf"
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define INFINITE_UPPER "INF"
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define LONG_INFINITE_LOWER "infinite"
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define LONG_INFINITE_UPPER "INFINITE"
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NAN_LOWER "nan"
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NAN_UPPER "NAN"
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* Various constants */
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum {
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TYPE_PRINT = 1,
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TYPE_SCAN  = 2,
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* Flags. FLAGS_LAST must be less than ULONG_MAX */
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_NEW                 = 0,
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_STICKY              = 1,
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_SPACE               = 2 * FLAGS_STICKY,
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_SHOWSIGN            = 2 * FLAGS_SPACE,
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_LEFTADJUST          = 2 * FLAGS_SHOWSIGN,
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_ALTERNATIVE         = 2 * FLAGS_LEFTADJUST,
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_SHORT               = 2 * FLAGS_ALTERNATIVE,
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_SHORTSHORT          = 2 * FLAGS_SHORT,
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_LONG                = 2 * FLAGS_SHORTSHORT,
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_QUAD                = 2 * FLAGS_LONG,
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_LONGDOUBLE          = 2 * FLAGS_QUAD,
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_SIZE_T              = 2 * FLAGS_LONGDOUBLE,
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_PTRDIFF_T           = 2 * FLAGS_SIZE_T,
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_INTMAX_T            = 2 * FLAGS_PTRDIFF_T,
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_NILPADDING          = 2 * FLAGS_INTMAX_T,
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_UNSIGNED            = 2 * FLAGS_NILPADDING,
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_UPPER               = 2 * FLAGS_UNSIGNED,
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_WIDTH               = 2 * FLAGS_UPPER,
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_WIDTH_PARAMETER     = 2 * FLAGS_WIDTH,
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_PRECISION           = 2 * FLAGS_WIDTH_PARAMETER,
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_PRECISION_PARAMETER = 2 * FLAGS_PRECISION,
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_BASE                = 2 * FLAGS_PRECISION_PARAMETER,
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_BASE_PARAMETER      = 2 * FLAGS_BASE,
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_FLOAT_E             = 2 * FLAGS_BASE_PARAMETER,
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_FLOAT_G             = 2 * FLAGS_FLOAT_E,
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_QUOTE               = 2 * FLAGS_FLOAT_G,
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_WIDECHAR            = 2 * FLAGS_QUOTE,
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_ALLOC               = 2 * FLAGS_WIDECHAR,
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_IGNORE              = 2 * FLAGS_ALLOC,
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_IGNORE_PARAMETER    = 2 * FLAGS_IGNORE,
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_VARSIZE_PARAMETER   = 2 * FLAGS_IGNORE_PARAMETER,
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_FIXED_SIZE          = 2 * FLAGS_VARSIZE_PARAMETER,
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_LAST                = FLAGS_FIXED_SIZE,
3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* Reused flags */
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_EXCLUDE             = FLAGS_SHORT,
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_USER_DEFINED        = FLAGS_IGNORE,
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_ROUNDING            = FLAGS_INTMAX_T,
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* Compounded flags */
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_ALL_VARSIZES        = FLAGS_LONG | FLAGS_QUAD | FLAGS_INTMAX_T | FLAGS_PTRDIFF_T | FLAGS_SIZE_T,
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FLAGS_ALL_SIZES           = FLAGS_ALL_VARSIZES | FLAGS_SHORTSHORT | FLAGS_SHORT,
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NO_POSITION  = -1,
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NO_WIDTH     =  0,
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NO_PRECISION = -1,
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NO_SIZE      = -1,
3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* Do not change these */
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NO_BASE      = -1,
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MIN_BASE     =  2,
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MAX_BASE     = 36,
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BASE_BINARY  =  2,
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BASE_OCTAL   =  8,
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BASE_DECIMAL = 10,
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BASE_HEX     = 16,
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* Maximal number of allowed parameters */
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MAX_PARAMETERS = 64,
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* Maximal number of characters in class */
3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MAX_CHARACTER_CLASS = UCHAR_MAX + 1,
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* Maximal string lengths for user-defined specifiers */
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MAX_USER_NAME = 64,
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MAX_USER_DATA = 256,
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* Maximal length of locale separator strings */
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MAX_LOCALE_SEPARATOR_LENGTH = MB_LEN_MAX,
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* Maximal number of integers in grouping */
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MAX_LOCALE_GROUPS = 64,
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* Initial size of asprintf buffer */
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DYNAMIC_START_SIZE = 32
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NO_GROUPING ((int)CHAR_MAX)
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* Fundamental formatting parameter types */
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define FORMAT_UNKNOWN   0
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define FORMAT_INT       1
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define FORMAT_DOUBLE    2
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define FORMAT_CHAR      3
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define FORMAT_STRING    4
3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define FORMAT_POINTER   5
3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define FORMAT_COUNT     6
3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define FORMAT_PARAMETER 7
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define FORMAT_GROUP     8
4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_GNU
4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define FORMAT_ERRNO    9
4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_EXTENSION
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define FORMAT_USER_DEFINED 10
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* Character constants */
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHAR_IDENTIFIER '%'
4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHAR_BACKSLASH '\\'
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHAR_QUOTE '\"'
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHAR_ADJUST ' '
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* Character class expressions */
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CLASS_ALNUM "[:alnum:]"
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CLASS_ALPHA "[:alpha:]"
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CLASS_BLANK "[:blank:]"
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CLASS_CNTRL "[:cntrl:]"
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CLASS_DIGIT "[:digit:]"
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CLASS_GRAPH "[:graph:]"
4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CLASS_LOWER "[:lower:]"
4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CLASS_PRINT "[:print:]"
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CLASS_PUNCT "[:punct:]"
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CLASS_SPACE "[:space:]"
4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CLASS_UPPER "[:upper:]"
4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CLASS_XDIGIT "[:xdigit:]"
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * SPECIFIERS:
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * a  Hex-float
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * A  Hex-float
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * c  Character
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * C  Widechar character (wint_t)
4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * d  Decimal
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * e  Float
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * E  Float
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * F  Float
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * F  Float
4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * g  Float
4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * G  Float
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * i  Integer
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * m  Error message
4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * n  Count
4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * o  Octal
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * p  Pointer
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * s  String
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * S  Widechar string (wchar_t *)
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * u  Unsigned
4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * x  Hex
4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * X  Hex
4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * [] Group
4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * <> User-defined
4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Reserved:
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * D  Binary Coded Decimal %D(length,precision) (OS/390)
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_CHAR 'c'
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_STRING 's'
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_DECIMAL 'd'
4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_INTEGER 'i'
4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_UNSIGNED 'u'
4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_OCTAL 'o'
4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_HEX 'x'
4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_HEX_UPPER 'X'
4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_FLOAT_E 'e'
4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_FLOAT_E_UPPER 'E'
4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_FLOAT_F 'f'
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_FLOAT_F_UPPER 'F'
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_FLOAT_G 'g'
4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_FLOAT_G_UPPER 'G'
4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_POINTER 'p'
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_GROUP '['
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_UNGROUP ']'
4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SPECIFIER_COUNT 'n'
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_UNIX98
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define SPECIFIER_CHAR_UPPER 'C'
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define SPECIFIER_STRING_UPPER 'S'
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_C99
4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define SPECIFIER_HEXFLOAT 'a'
4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define SPECIFIER_HEXFLOAT_UPPER 'A'
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_GNU
4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define SPECIFIER_ERRNO 'm'
4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_EXTENSION
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define SPECIFIER_BINARY 'b'
4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define SPECIFIER_BINARY_UPPER 'B'
4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define SPECIFIER_USER_DEFINED_BEGIN '<'
4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define SPECIFIER_USER_DEFINED_END '>'
4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define SPECIFIER_USER_DEFINED_SEPARATOR ':'
4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * QUALIFIERS:
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Numbers = d,i,o,u,x,X
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Float = a,A,e,E,f,F,g,G
5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * String = s
5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Char = c
5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 9$ Position
5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      Use the 9th parameter. 9 can be any number between 1 and
5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      the maximal argument
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 9 Width
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      Set width to 9. 9 can be any number, but must not be postfixed
5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      by '$'
5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * h  Short
5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    Numbers:
5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      (unsigned) short int
5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * hh Short short
5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    Numbers:
5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      (unsigned) char
5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * l  Long
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    Numbers:
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      (unsigned) long int
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    String:
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      as the S specifier
5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    Char:
5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      as the C specifier
5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * ll Long Long
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    Numbers:
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      (unsigned) long long int
5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * L  Long Double
5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    Float
5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      long double
5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * #  Alternative
5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    Float:
5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      Decimal-point is always present
5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    String:
5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      non-printable characters are handled as \number
5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    Spacing
5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * +  Sign
5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * -  Alignment
5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * .  Precision
5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * *  Parameter
5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    print: use parameter
5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    scan: no parameter (ignore)
5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * q  Quad
5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Z  size_t
5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * w  Widechar
5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * '  Thousands/quote
5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    Numbers:
5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      Integer part grouped in thousands
5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    Binary numbers:
5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      Number grouped in nibbles (4 bits)
5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    String:
5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      Quoted string
5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * j  intmax_t
5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * t  prtdiff_t
5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * z  size_t
5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * !  Sticky
5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @  Parameter (for both print and scan)
5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * I  n-bit Integer
5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *    Numbers:
5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *      The following options exists
5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *        I8  = 8-bit integer
5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *        I16 = 16-bit integer
5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *        I32 = 32-bit integer
5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *        I64 = 64-bit integer
5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define QUALIFIER_POSITION '$'
5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define QUALIFIER_SHORT 'h'
5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define QUALIFIER_LONG 'l'
5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define QUALIFIER_LONG_UPPER 'L'
5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define QUALIFIER_ALTERNATIVE '#'
5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define QUALIFIER_SPACE ' '
5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define QUALIFIER_PLUS '+'
5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define QUALIFIER_MINUS '-'
5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define QUALIFIER_DOT '.'
5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define QUALIFIER_STAR '*'
5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define QUALIFIER_CIRCUMFLEX '^' /* For scanlists */
5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_C99
5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define QUALIFIER_SIZE_T 'z'
5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define QUALIFIER_PTRDIFF_T 't'
6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define QUALIFIER_INTMAX_T 'j'
6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_BSD || TRIO_GNU
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define QUALIFIER_QUAD 'q'
6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_GNU
6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define QUALIFIER_SIZE_T_UPPER 'Z'
6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_MISC
6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define QUALIFIER_WIDECHAR 'w'
6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_MICROSOFT
6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define QUALIFIER_FIXED_SIZE 'I'
6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_EXTENSION
6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define QUALIFIER_QUOTE '\''
6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define QUALIFIER_STICKY '!'
6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define QUALIFIER_VARSIZE '&' /* This should remain undocumented */
6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define QUALIFIER_PARAM '@' /* Experimental */
6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define QUALIFIER_COLON ':' /* For scanlists */
6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define QUALIFIER_EQUAL '=' /* For scanlists */
6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define QUALIFIER_ROUNDING_UPPER 'R'
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*************************************************************************
6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Internal Structures
6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *************************************************************************/
6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* Parameters */
6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct {
6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* An indication of which entry in the data union is used */
6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int type;
6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* The flags */
6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  trio_flags_t flags;
6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* The width qualifier */
6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int width;
6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* The precision qualifier */
6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int precision;
6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* The base qualifier */
6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int base;
6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* The size for the variable size qualifier */
6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int varsize;
6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* The marker of the end of the specifier */
6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int indexAfterSpecifier;
6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* The data from the argument list */
6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  union {
6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    char *string;
6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_WIDECHAR
6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    trio_wchar_t *wstring;
6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    trio_pointer_t pointer;
6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    union {
6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      trio_intmax_t as_signed;
6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      trio_uintmax_t as_unsigned;
6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    } number;
6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    double doubleNumber;
6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    double *doublePointer;
6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    trio_long_double_t longdoubleNumber;
6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    trio_long_double_t *longdoublePointer;
6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int errorNumber;
6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } data;
6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* For the user-defined specifier */
6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  char user_name[MAX_USER_NAME];
6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  char user_data[MAX_USER_DATA];
6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} trio_parameter_t;
6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* Container for customized functions */
6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct {
6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  union {
6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    trio_outstream_t out;
6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    trio_instream_t in;
6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } stream;
6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  trio_pointer_t closure;
6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} trio_custom_t;
6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* General trio "class" */
6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct _trio_class_t {
6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /*
6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * The function to write characters to a stream.
6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   */
6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void (*OutStream) TRIO_PROTO((struct _trio_class_t *, int));
6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /*
6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * The function to read characters from a stream.
6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   */
6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void (*InStream) TRIO_PROTO((struct _trio_class_t *, int *));
6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /*
6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * The current location in the stream.
6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   */
6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  trio_pointer_t location;
6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /*
6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * The character currently being processed.
6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   */
6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int current;
6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /*
6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * The number of characters that would have been written/read
6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * if there had been sufficient space.
6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   */
7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int processed;
7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /*
7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * The number of characters that are actually written/read.
7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * Processed and committed will only differ for the *nprintf
7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * and *nscanf functions.
7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   */
7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int committed;
7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /*
7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * The upper limit of characters that may be written/read.
7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   */
7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int max;
7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /*
7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * The last output error that was detected.
7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   */
7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int error;
7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} trio_class_t;
7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* References (for user-defined callbacks) */
7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct _trio_reference_t {
7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  trio_class_t *data;
7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  trio_parameter_t *parameter;
7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} trio_reference_t;
7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* Registered entries (for user-defined callbacks) */
7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef struct _trio_userdef_t {
7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  struct _trio_userdef_t *next;
7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  trio_callback_t callback;
7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  char *name;
7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} trio_userdef_t;
7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*************************************************************************
7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Internal Variables
7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *************************************************************************/
7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static TRIO_CONST char rcsid[] = "@(#)$Id$";
7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*
7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Need this to workaround a parser bug in HP C/iX compiler that fails
7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * to resolves macro definitions that includes type 'long double',
7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * e.g: va_arg(arg_ptr, long double)
7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(TRIO_PLATFORM_MPEIX)
7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static TRIO_CONST trio_long_double_t ___dummy_long_double = 0;
7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static TRIO_CONST char internalNullString[] = "(nil)";
7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(USE_LOCALE)
7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static struct lconv *internalLocaleValues = NULL;
7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*
7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * UNIX98 says "in a locale where the radix character is not defined,
7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * the radix character defaults to a period (.)"
7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static int internalDecimalPointLength = 1;
7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static int internalThousandSeparatorLength = 1;
7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static char internalDecimalPoint = '.';
7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static char internalDecimalPointString[MAX_LOCALE_SEPARATOR_LENGTH + 1] = ".";
7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static char internalThousandSeparator[MAX_LOCALE_SEPARATOR_LENGTH + 1] = ",";
7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static char internalGrouping[MAX_LOCALE_GROUPS] = { (char)NO_GROUPING };
7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static TRIO_CONST char internalDigitsLower[] = "0123456789abcdefghijklmnopqrstuvwxyz";
7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static TRIO_CONST char internalDigitsUpper[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static BOOLEAN_T internalDigitsUnconverted = TRUE;
7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static int internalDigitArray[128];
7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_EXTENSION
7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static BOOLEAN_T internalCollationUnconverted = TRUE;
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static char internalCollationArray[MAX_CHARACTER_CLASS][MAX_CHARACTER_CLASS];
7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_EXTENSION
7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static TRIO_VOLATILE trio_callback_t internalEnterCriticalRegion = NULL;
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static TRIO_VOLATILE trio_callback_t internalLeaveCriticalRegion = NULL;
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static trio_userdef_t *internalUserDef = NULL;
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*************************************************************************
7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Internal Functions
7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ************************************************************************/
7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(TRIO_MINIMAL)
7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# define TRIO_STRING_PUBLIC static
7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)# include "triostr.c"
7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif /* defined(TRIO_MINIMAL) */
7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*************************************************************************
7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * TrioIsQualifier
7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Description:
7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *  Remember to add all new qualifiers to this function.
7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *  QUALIFIER_POSITION must not be added.
7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TRIO_PRIVATE BOOLEAN_T
7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TrioIsQualifier
8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TRIO_ARGS1((character),
8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	   TRIO_CONST char character)
8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles){
8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /* QUALIFIER_POSITION is not included */
8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  switch (character)
8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    {
8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case '0': case '1': case '2': case '3': case '4':
8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case '5': case '6': case '7': case '8': case '9':
8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_PLUS:
8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_MINUS:
8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_SPACE:
8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_DOT:
8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_STAR:
8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_ALTERNATIVE:
8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_SHORT:
8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_LONG:
8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_LONG_UPPER:
8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_CIRCUMFLEX:
8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(QUALIFIER_SIZE_T)
8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_SIZE_T:
8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(QUALIFIER_PTRDIFF_T)
8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_PTRDIFF_T:
8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(QUALIFIER_INTMAX_T)
8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_INTMAX_T:
8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(QUALIFIER_QUAD)
8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_QUAD:
8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(QUALIFIER_SIZE_T_UPPER)
8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_SIZE_T_UPPER:
8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(QUALIFIER_WIDECHAR)
8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_WIDECHAR:
8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(QUALIFIER_QUOTE)
8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_QUOTE:
8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(QUALIFIER_STICKY)
8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_STICKY:
8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(QUALIFIER_VARSIZE)
8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_VARSIZE:
8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(QUALIFIER_PARAM)
8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_PARAM:
8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(QUALIFIER_FIXED_SIZE)
8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_FIXED_SIZE:
8505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
8515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(QUALIFIER_ROUNDING_UPPER)
8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case QUALIFIER_ROUNDING_UPPER:
8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return TRUE;
8555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    default:
8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return FALSE;
8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*************************************************************************
8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * TrioSetLocale
8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(USE_LOCALE)
8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TRIO_PRIVATE void
8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TrioSetLocale(TRIO_NOARGS)
8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles){
8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  internalLocaleValues = (struct lconv *)localeconv();
8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (internalLocaleValues)
8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    {
8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if ((internalLocaleValues->decimal_point) &&
8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	  (internalLocaleValues->decimal_point[0] != NIL))
8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	{
8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	  internalDecimalPointLength = trio_length(internalLocaleValues->decimal_point);
8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	  if (internalDecimalPointLength == 1)
8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	    {
8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	      internalDecimalPoint = internalLocaleValues->decimal_point[0];
8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	    }
8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	  else
8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	    {
8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	      internalDecimalPoint = NIL;
8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	      trio_copy_max(internalDecimalPointString,
8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)			    sizeof(internalDecimalPointString),
8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)			    internalLocaleValues->decimal_point);
8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	    }
8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	}
8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if ((internalLocaleValues->thousands_sep) &&
8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	  (internalLocaleValues->thousands_sep[0] != NIL))
8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	{
8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	  trio_copy_max(internalThousandSeparator,
8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)			sizeof(internalThousandSeparator),
8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)			internalLocaleValues->thousands_sep);
8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	  internalThousandSeparatorLength = trio_length(internalThousandSeparator);
8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	}
8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if ((internalLocaleValues->grouping) &&
8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	  (internalLocaleValues->grouping[0] != NIL))
8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	{
8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	  trio_copy_max(internalGrouping,
8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)			sizeof(internalGrouping),
8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)			internalLocaleValues->grouping);
9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	}
9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
9025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif /* defined(USE_LOCALE) */
9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TRIO_PRIVATE int
9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TrioCalcThousandSeparatorLength
9075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TRIO_ARGS1((digits),
9085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	   int digits)
9095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles){
9105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_EXTENSION
9115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int count = 0;
9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int step = NO_GROUPING;
9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  char *groupingPointer = internalGrouping;
9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  while (digits > 0)
9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    {
9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (*groupingPointer == CHAR_MAX)
9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	{
9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	  /* Disable grouping */
9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	  break; /* while */
9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	}
9225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      else if (*groupingPointer == 0)
9235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	{
9245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	  /* Repeat last group */
9255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	  if (step == NO_GROUPING)
9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	    {
9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	      /* Error in locale */
9285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	      break; /* while */
9295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	    }
9305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	}
9315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      else
9325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	{
9335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	  step = *groupingPointer++;
9345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	}
9355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (digits > step)
9365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	count += internalThousandSeparatorLength;
9375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      digits -= step;
9385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
9395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return count;
9405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else
9415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return 0;
9425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
9435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TRIO_PRIVATE BOOLEAN_T
9465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TrioFollowedBySeparator
9475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TRIO_ARGS1((position),
9485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	   int position)
9495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles){
9505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_EXTENSION
9515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int step = 0;
9525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  char *groupingPointer = internalGrouping;
9535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  position--;
9555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (position == 0)
9565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return FALSE;
9575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  while (position > 0)
9585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    {
9595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (*groupingPointer == CHAR_MAX)
9605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	{
9615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	  /* Disable grouping */
9625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	  break; /* while */
9635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	}
9645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      else if (*groupingPointer != 0)
9655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	{
9665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	  step = *groupingPointer++;
9675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	}
9685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (step == 0)
9695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	break;
9705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      position -= step;
9715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
9725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return (position == 0);
9735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else
9745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return FALSE;
9755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
9765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*************************************************************************
9795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * TrioGetPosition
9805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
9815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Get the %n$ position.
9825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
9835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TRIO_PRIVATE int
9845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TrioGetPosition
9855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TRIO_ARGS2((format, indexPointer),
9865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	   TRIO_CONST char *format,
9875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	   int *indexPointer)
9885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles){
9895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_UNIX98
9905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  char *tmpformat;
9915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int number = 0;
9925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int index = *indexPointer;
9935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  number = (int)trio_to_long(&format[index], &tmpformat, BASE_DECIMAL);
9955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  index = (int)(tmpformat - format);
9965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if ((number != 0) && (QUALIFIER_POSITION == format[index++]))
9975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    {
9985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      *indexPointer = index;
9995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      /*
10005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       * number is decreased by 1, because n$ starts from 1, whereas
10015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       * the array it is indexing starts from 0.
10025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       */
10035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return number - 1;
10045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
10055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
10065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return NO_POSITION;
10075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
10085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if TRIO_EXTENSION
10105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*************************************************************************
10115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * TrioFindNamespace
10125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
10135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Find registered user-defined specifier.
10145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * The prev argument is used for optimization only.
10155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
10165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TRIO_PRIVATE trio_userdef_t *
10175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TrioFindNamespace
10185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TRIO_ARGS2((name, prev),
10195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	   TRIO_CONST char *name,
10205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	   trio_userdef_t **prev)
10215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles){
10225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  trio_userdef_t *def;
10235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (internalEnterCriticalRegion)
10255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    (void)internalEnterCriticalRegion(NULL);
10265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (def = internalUserDef; def; def = def->next)
10285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    {
10295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      /* Case-sensitive string comparison */
10305821806d5e7f356e8fa4b058a389a808ea183019