/*************************************************************************1*2* $Id$3*4* Copyright (C) 2000 Bjorn Reese and Daniel Stenberg.5*6* Permission to use, copy, modify, and distribute this software for any7* purpose with or without fee is hereby granted, provided that the above8* copyright notice and this permission notice appear in all copies.9*10* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED11* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF12* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND13* CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER.14*15************************************************************************16*17* Private functions, types, etc. used for callback functions.18*19* The ref pointer is an opaque type and should remain as such.20* Private data must only be accessible through the getter and21* setter functions.22*23************************************************************************/2425#ifndef TRIO_TRIOP_H26#define TRIO_TRIOP_H2728#include "triodef.h"2930#include <stdlib.h>31#if defined(TRIO_COMPILER_ANCIENT)32# include <varargs.h>33#else34# include <stdarg.h>35#endif3637#ifdef __cplusplus38extern "C" {39#endif4041/*************************************************************************42* Supported standards43*/4445/*46* TRIO_C99 (=0 or =1)47*48* Define this to 0 to disable C99 format specifier extensions, or49* define to 1 to enable them. The format specifiers that are50* disabled by this switch are labelled with [C99] in the format51* specifier documentation.52*/53#if !defined(TRIO_C99)54# define TRIO_C99 155#endif5657/*58* TRIO_BSD (=0 or =1)59*60* Define this to 0 to disable BSD format specifier extensions, or61* define to 1 to enable them. The format specifiers that are62* disabled by this switch are labelled with [BSD] in the format63* specifier documentation.64*/65#if !defined(TRIO_BSD)66# define TRIO_BSD 167#endif6869/*70* TRIO_GNU (=0 or =1)71*72* Define this to 0 to disable GNU format specifier extensions, or73* define to 1 to enable them. The format specifiers that are74* disabled by this switch are labelled with [GNU] in the format75* specifier documentation.76*/77#if !defined(TRIO_GNU)78# define TRIO_GNU 179#endif8081/*82* TRIO_MISC (=0 or =1)83*84* Define this to 0 to disable miscellaneous format specifier85* extensions, or define to 1 to enable them. The format specifiers86* that are disabled by this switch are labelled with [MISC] in the87* format specifier documentation.88*/89#if !defined(TRIO_MISC)90# define TRIO_MISC 191#endif9293/*94* TRIO_UNIX98 (=0 or =1)95*96* Define this to 0 to disable UNIX98 format specifier extensions,97* or define to 1 to enable them. The format specifiers that are98* disabled by this switch are labelled with [UNIX98] in the format99* specifier documentation.100*/101#if !defined(TRIO_UNIX98)102# define TRIO_UNIX98 1103#endif104105/*106* TRIO_MICROSOFT (=0 or =1)107*108* Define this to 0 to disable Microsoft Visual C format specifier109* extensions, or define to 1 to enable them. The format specifiers110* that are disabled by this switch are labelled with [MSVC] in the111* format specifier documentation.112*/113#if !defined(TRIO_MICROSOFT)114# define TRIO_MICROSOFT 1115#endif116117/*118* TRIO_EXTENSION (=0 or =1)119*120* Define this to 0 to disable Trio-specific extensions, or define121* to 1 to enable them. This has two effects: it controls whether122* or not the Trio user-defined formating mechanism123* (trio_register() etc) is supported, and it enables or disables124* Trio's own format specifier extensions. The format specifiers125* that are disabled by this switch are labelled with [TRIO] in126* the format specifier documentation.127*/128#if !defined(TRIO_EXTENSION)129# define TRIO_EXTENSION 1130#endif131132/*133* TRIO_DEPRECATED (=0 or =1)134*135* Define this to 0 to disable deprecated functionality, or define136* to 1 to enable them.137*/138#if !defined(TRIO_DEPRECATED)139# define TRIO_DEPRECATED 1140#endif141142/*************************************************************************143* Features144*/145146#if defined(TRIO_SNPRINTF_ONLY)147# define TRIO_FEATURE_SCANF 0148# define TRIO_FEATURE_FILE 0149# define TRIO_FEATURE_STDIO 0150# define TRIO_FEATURE_FD 0151# define TRIO_FEATURE_DYNAMICSTRING 0152# define TRIO_FEATURE_CLOSURE 0153# define TRIO_FEATURE_ARGFUNC 0154# define TRIO_FEATURE_STRERR 0155# define TRIO_FEATURE_LOCALE 0156# define TRIO_EMBED_NAN 1157# define TRIO_EMBED_STRING 1158#endif159160/*161* TRIO_FEATURE_SCANF (=0 or =1)162*163* Define this to 0 to disable all the scanf() variants, or define to 1164* to enable them.165*/166#if !defined(TRIO_FEATURE_SCANF)167# define TRIO_FEATURE_SCANF 1168#endif169170/*171* TRIO_FEATURE_FILE (=0 or =1)172*173* Define this to 0 to disable compilation of the trio_fprintf() and174* trio_fscanf() family of functions, or define to 1 to enable them.175*176* This may be useful on an embedded platform with no filesystem.177* Note that trio_printf() uses fwrite to write to stdout, so if you178* do not have an implementation of fwrite() at all then you must also179* define TRIO_FEATURE_STDIO to 0.180*/181#if !defined(TRIO_FEATURE_FILE)182# define TRIO_FEATURE_FILE 1183#endif184185/*186* TRIO_FEATURE_STDIO (=0 or =1)187*188* Define this to 0 to disable compilation of the trio_printf() and189* trio_scanf() family of functions, or define to 1 to enable them.190*191* This may be useful on an embedded platform with no standard I/O.192*/193#if !defined(TRIO_FEATURE_STDIO)194# define TRIO_FEATURE_STDIO 1195#endif196197/*198* TRIO_FEATURE_FD (=0 or =1)199*200* Define this to 0 to disable compilation of the trio_dprintf() and201* trio_dscanf() family of functions, or define to 1 to enable them.202*203* This may be useful on an embedded platform with no filesystem, or on204* a platform that supports file I/O using FILE* but not using raw file205* descriptors.206*/207#if !defined(TRIO_FEATURE_FD)208# define TRIO_FEATURE_FD 1209#endif210211/*212* TRIO_FEATURE_DYNAMICSTRING (=0 or =1)213*214* Define this to 0 to disable compilation of the trio_aprintf()215* family of functions, or define to 1 to enable them.216*217* If you define both this and TRIO_MINIMAL to 0, then Trio will never218* call malloc or free.219*/220#if !defined(TRIO_FEATURE_DYNAMICSTRING)221# define TRIO_FEATURE_DYNAMICSTRING 1222#endif223224/*225* TRIO_FEATURE_CLOSURE (=0 or =1)226*227* Define this to 0 to disable compilation of the trio_cprintf() and228* trio_cscanf() family of functions, or define to 1 to enable them.229*230* These functions are rarely needed. This saves a (small) amount of code.231*/232#if !defined(TRIO_FEATURE_CLOSURE)233# define TRIO_FEATURE_CLOSURE 1234#endif235236/*237* TRIO_FEATURE_ARGFUNC (=0 or =1)238*239* Define this to 0 to disable compilation of trio_cprintff() and240* trio_cscanff() functions and related code (might have a tiny241* performance gain), or define to 1 to enable them.242*243* This functionality is needed only if you have to fetch the arguments using244* a pull model instead of passing them all at once (for example if you plan245* to plug the library into a script interpreter or validate the types).246*247* Only the closure family of functions are available with this interface,248* because if you need this, you usually provide custom input/output249* handling too (and so this forces TRIO_FEATURE_CLOSURE to enabled).250*/251#if !defined(TRIO_FEATURE_ARGFUNC)252# define TRIO_FEATURE_ARGFUNC 1253#endif254#if TRIO_FEATURE_ARGFUNC255# undef TRIO_FEATURE_CLOSURE256# define TRIO_FEATURE_CLOSURE 1257#endif258259/*260* TRIO_FEATURE_ERRORCODE (=0 or =1)261*262* Define this to 0 to return -1 from the print and scan function on263* error, or define to 1 to return a negative number with debugging264* information as part of the return code.265*266* If enabled, the return code will be a negative number, which encodes267* an error code and an error location. These can be decoded with the268* TRIO_ERROR_CODE and TRIO_ERROR_POSITION macros.269*/270#if defined(TRIO_ERRORS)271# define TRIO_FEATURE_ERRORCODE TRIO_ERRORS272#endif273#if !defined(TRIO_FEATURE_ERRORCODE)274# define TRIO_FEATURE_ERRORCODE 1275#endif276277/*278* TRIO_FEATURE_STRERR (=0 or =1)279*280* Define this to 0 if you do not use trio_strerror(), or define to 1 if281* you do use it.282*283* This saves a (small) amount of code.284*/285#if !defined(TRIO_FEATURE_STRERR)286# define TRIO_FEATURE_STRERR 1287#endif288289/*290* TRIO_FEATURE_FLOAT (=0 or =1)291*292* Define this to 0 to disable all floating-point support, or define293* to 1 to enable it.294*295* This is useful in restricted embedded platforms that do not support296* floating-point. Obviously you cannot use floating-point format297* specifiers if you define this.298*299* Do not compile trionan.c if you disable this.300*/301#if !defined(TRIO_FEATURE_FLOAT)302# define TRIO_FEATURE_FLOAT 1303#endif304305/*306* TRIO_FEATURE_LOCALE (=0 or =1)307*308* Define this to 0 to disable customized locale support, or define309* to 1 to enable it.310*311* This saves a (small) amount of code.312*/313#if !defined(TRIO_FEATURE_LOCALE)314# define TRIO_FEATURE_LOCALE 1315#endif316317/*318* TRIO_MINIMAL319*320* Define this to disable building the public trionan.h and triostr.h.321* If you define this, then you must not compile trionan.c and triostr.c322* separately.323*/324#if defined(TRIO_MINIMAL)325# if !defined(TRIO_EMBED_NAN)326# define TRIO_EMBED_NAN327# endif328# if !defined(TRIO_EMBED_STRING)329# define TRIO_EMBED_STRING330# endif331#endif332333/* Does not work yet. Do not enable */334#ifndef TRIO_FEATURE_WIDECHAR335# define TRIO_FEATURE_WIDECHAR 0336#endif337338/*************************************************************************339* Mapping standards to internal features340*/341342#if !defined(TRIO_FEATURE_HEXFLOAT)343# define TRIO_FEATURE_HEXFLOAT (TRIO_C99 && TRIO_FEATURE_FLOAT)344#endif345346#if !defined(TRIO_FEATURE_LONGDOUBLE)347# define TRIO_FEATURE_LONGDOUBLE TRIO_FEATURE_FLOAT348#endif349350#if !defined(TRIO_FEATURE_ERRNO)351# define TRIO_FEATURE_ERRNO TRIO_GNU352#endif353354#if !defined(TRIO_FEATURE_QUAD)355# define TRIO_FEATURE_QUAD (TRIO_BSD || TRIO_GNU)356#endif357358#if !defined(TRIO_FEATURE_SIZE_T)359# define TRIO_FEATURE_SIZE_T TRIO_C99360#endif361362#if !defined(TRIO_FEATURE_SIZE_T_UPPER)363# define TRIO_FEATURE_SIZE_T_UPPER TRIO_GNU364#endif365366#if !defined(TRIO_FEATURE_PTRDIFF_T)367# define TRIO_FEATURE_PTRDIFF_T TRIO_C99368#endif369370#if !defined(TRIO_FEATURE_INTMAX_T)371# define TRIO_FEATURE_INTMAX_T TRIO_C99372#endif373374#if !defined(TRIO_FEATURE_FIXED_SIZE)375# define TRIO_FEATURE_FIXED_SIZE TRIO_MICROSOFT376#endif377378#if !defined(TRIO_FEATURE_POSITIONAL)379# define TRIO_FEATURE_POSITIONAL TRIO_UNIX98380#endif381382#if !defined(TRIO_FEATURE_USER_DEFINED)383# define TRIO_FEATURE_USER_DEFINED TRIO_EXTENSION384#endif385386#if !defined(TRIO_FEATURE_BINARY)387# define TRIO_FEATURE_BINARY TRIO_EXTENSION388#endif389390#if !defined(TRIO_FEATURE_QUOTE)391# define TRIO_FEATURE_QUOTE TRIO_EXTENSION392#endif393394#if !defined(TRIO_FEATURE_STICKY)395# define TRIO_FEATURE_STICKY TRIO_EXTENSION396#endif397398#if !defined(TRIO_FEATURE_VARSIZE)399# define TRIO_FEATURE_VARSIZE TRIO_EXTENSION400#endif401402#if !defined(TRIO_FEATURE_ROUNDING)403# define TRIO_FEATURE_ROUNDING TRIO_EXTENSION404#endif405406/*************************************************************************407* Memory handling408*/409#ifndef TRIO_MALLOC410# define TRIO_MALLOC(n) malloc(n)411#endif412#ifndef TRIO_REALLOC413# define TRIO_REALLOC(x,n) realloc((x),(n))414#endif415#ifndef TRIO_FREE416# define TRIO_FREE(x) free(x)417#endif418419420/*************************************************************************421* User-defined specifiers422*/423424typedef int (*trio_callback_t) TRIO_PROTO((trio_pointer_t));425426trio_pointer_t trio_register TRIO_PROTO((trio_callback_t callback, const char *name));427void trio_unregister TRIO_PROTO((trio_pointer_t handle));428429TRIO_CONST char *trio_get_format TRIO_PROTO((trio_pointer_t ref));430TRIO_CONST trio_pointer_t trio_get_argument TRIO_PROTO((trio_pointer_t ref));431432/* Modifiers */433int trio_get_width TRIO_PROTO((trio_pointer_t ref));434void trio_set_width TRIO_PROTO((trio_pointer_t ref, int width));435int trio_get_precision TRIO_PROTO((trio_pointer_t ref));436void trio_set_precision TRIO_PROTO((trio_pointer_t ref, int precision));437int trio_get_base TRIO_PROTO((trio_pointer_t ref));438void trio_set_base TRIO_PROTO((trio_pointer_t ref, int base));439int trio_get_padding TRIO_PROTO((trio_pointer_t ref));440void trio_set_padding TRIO_PROTO((trio_pointer_t ref, int is_padding));441int trio_get_short TRIO_PROTO((trio_pointer_t ref)); /* h */442void trio_set_shortshort TRIO_PROTO((trio_pointer_t ref, int is_shortshort));443int trio_get_shortshort TRIO_PROTO((trio_pointer_t ref)); /* hh */444void trio_set_short TRIO_PROTO((trio_pointer_t ref, int is_short));445int trio_get_long TRIO_PROTO((trio_pointer_t ref)); /* l */446void trio_set_long TRIO_PROTO((trio_pointer_t ref, int is_long));447int trio_get_longlong TRIO_PROTO((trio_pointer_t ref)); /* ll */448void trio_set_longlong TRIO_PROTO((trio_pointer_t ref, int is_longlong));449int trio_get_longdouble TRIO_PROTO((trio_pointer_t ref)); /* L */450void trio_set_longdouble TRIO_PROTO((trio_pointer_t ref, int is_longdouble));451int trio_get_alternative TRIO_PROTO((trio_pointer_t ref)); /* # */452void trio_set_alternative TRIO_PROTO((trio_pointer_t ref, int is_alternative));453int trio_get_alignment TRIO_PROTO((trio_pointer_t ref)); /* - */454void trio_set_alignment TRIO_PROTO((trio_pointer_t ref, int is_leftaligned));455int trio_get_spacing TRIO_PROTO((trio_pointer_t ref)); /* (space) */456void trio_set_spacing TRIO_PROTO((trio_pointer_t ref, int is_space));457int trio_get_sign TRIO_PROTO((trio_pointer_t ref)); /* + */458void trio_set_sign TRIO_PROTO((trio_pointer_t ref, int is_showsign));459#if TRIO_FEATURE_QUOTE460int trio_get_quote TRIO_PROTO((trio_pointer_t ref)); /* ' */461void trio_set_quote TRIO_PROTO((trio_pointer_t ref, int is_quote));462#endif463int trio_get_upper TRIO_PROTO((trio_pointer_t ref));464void trio_set_upper TRIO_PROTO((trio_pointer_t ref, int is_upper));465#if TRIO_FEATURE_INTMAX_T466int trio_get_largest TRIO_PROTO((trio_pointer_t ref)); /* j */467void trio_set_largest TRIO_PROTO((trio_pointer_t ref, int is_largest));468#endif469#if TRIO_FEATURE_PTRDIFF_T470int trio_get_ptrdiff TRIO_PROTO((trio_pointer_t ref)); /* t */471void trio_set_ptrdiff TRIO_PROTO((trio_pointer_t ref, int is_ptrdiff));472#endif473#if TRIO_FEATURE_SIZE_T474int trio_get_size TRIO_PROTO((trio_pointer_t ref)); /* z / Z */475void trio_set_size TRIO_PROTO((trio_pointer_t ref, int is_size));476#endif477478/* Printing */479int trio_print_ref TRIO_PROTO((trio_pointer_t ref, const char *format, ...));480int trio_vprint_ref TRIO_PROTO((trio_pointer_t ref, const char *format, va_list args));481int trio_printv_ref TRIO_PROTO((trio_pointer_t ref, const char *format, trio_pointer_t *args));482483void trio_print_int TRIO_PROTO((trio_pointer_t ref, int number));484void trio_print_uint TRIO_PROTO((trio_pointer_t ref, unsigned int number));485/* void trio_print_long TRIO_PROTO((trio_pointer_t ref, long number)); */486/* void trio_print_ulong TRIO_PROTO((trio_pointer_t ref, unsigned long number)); */487void trio_print_double TRIO_PROTO((trio_pointer_t ref, double number));488void trio_print_string TRIO_PROTO((trio_pointer_t ref, TRIO_CONST char *string));489void trio_print_pointer TRIO_PROTO((trio_pointer_t ref, trio_pointer_t pointer));490491#ifdef __cplusplus492} /* extern "C" */493#endif494495#endif /* TRIO_TRIOP_H */496497498