1 /*************************************************************************
3 * $Id: triop.h,v 1.18 2009/07/05 10:14:07 breese Exp $
5 * Copyright (C) 2000 Bjorn Reese and Daniel Stenberg.
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
12 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
13 * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND
14 * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER.
16 ************************************************************************
18 * Private functions, types, etc. used for callback functions.
20 * The ref pointer is an opaque type and should remain as such.
21 * Private data must only be accessible through the getter and
24 ************************************************************************/
32 #if defined(TRIO_COMPILER_ANCIENT)
42 /*************************************************************************
49 * Define this to 0 to disable C99 format specifier extensions, or
50 * define to 1 to enable them. The format specifiers that are
51 * disabled by this switch are labelled with [C99] in the format
52 * specifier documentation.
54 #if !defined(TRIO_C99)
61 * Define this to 0 to disable BSD format specifier extensions, or
62 * define to 1 to enable them. The format specifiers that are
63 * disabled by this switch are labelled with [BSD] in the format
64 * specifier documentation.
66 #if !defined(TRIO_BSD)
73 * Define this to 0 to disable GNU format specifier extensions, or
74 * define to 1 to enable them. The format specifiers that are
75 * disabled by this switch are labelled with [GNU] in the format
76 * specifier documentation.
78 #if !defined(TRIO_GNU)
83 * TRIO_MISC (=0 or =1)
85 * Define this to 0 to disable miscellaneous format specifier
86 * extensions, or define to 1 to enable them. The format specifiers
87 * that are disabled by this switch are labelled with [MISC] in the
88 * format specifier documentation.
90 #if !defined(TRIO_MISC)
95 * TRIO_UNIX98 (=0 or =1)
97 * Define this to 0 to disable UNIX98 format specifier extensions,
98 * or define to 1 to enable them. The format specifiers that are
99 * disabled by this switch are labelled with [UNIX98] in the format
100 * specifier documentation.
102 #if !defined(TRIO_UNIX98)
103 # define TRIO_UNIX98 1
107 * TRIO_MICROSOFT (=0 or =1)
109 * Define this to 0 to disable Microsoft Visual C format specifier
110 * extensions, or define to 1 to enable them. The format specifiers
111 * that are disabled by this switch are labelled with [MSVC] in the
112 * format specifier documentation.
114 #if !defined(TRIO_MICROSOFT)
115 # define TRIO_MICROSOFT 1
119 * TRIO_EXTENSION (=0 or =1)
121 * Define this to 0 to disable Trio-specific extensions, or define
122 * to 1 to enable them. This has two effects: it controls whether
123 * or not the Trio user-defined formating mechanism
124 * (trio_register() etc) is supported, and it enables or disables
125 * Trio's own format specifier extensions. The format specifiers
126 * that are disabled by this switch are labelled with [TRIO] in
127 * the format specifier documentation.
129 #if !defined(TRIO_EXTENSION)
130 # define TRIO_EXTENSION 1
134 * TRIO_DEPRECATED (=0 or =1)
136 * Define this to 0 to disable deprecated functionality, or define
137 * to 1 to enable them.
139 #if !defined(TRIO_DEPRECATED)
140 # define TRIO_DEPRECATED 1
143 /*************************************************************************
147 #if defined(TRIO_SNPRINTF_ONLY)
148 # define TRIO_FEATURE_SCANF 0
149 # define TRIO_FEATURE_FILE 0
150 # define TRIO_FEATURE_STDIO 0
151 # define TRIO_FEATURE_FD 0
152 # define TRIO_FEATURE_DYNAMICSTRING 0
153 # define TRIO_FEATURE_CLOSURE 0
154 # define TRIO_FEATURE_STRERR 0
155 # define TRIO_FEATURE_LOCALE 0
156 # define TRIO_EMBED_NAN 1
157 # define TRIO_EMBED_STRING 1
161 * TRIO_FEATURE_SCANF (=0 or =1)
163 * Define this to 0 to disable all the scanf() variants, or define to 1
166 #if !defined(TRIO_FEATURE_SCANF)
167 # define TRIO_FEATURE_SCANF 1
171 * TRIO_FEATURE_FILE (=0 or =1)
173 * Define this to 0 to disable compilation of the trio_fprintf() and
174 * trio_fscanf() family of functions, or define to 1 to enable them.
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 you
178 * do not have an implementation of fwrite() at all then you must also
179 * define TRIO_FEATURE_STDIO to 0.
181 #if !defined(TRIO_FEATURE_FILE)
182 # define TRIO_FEATURE_FILE 1
186 * TRIO_FEATURE_STDIO (=0 or =1)
188 * Define this to 0 to disable compilation of the trio_printf() and
189 * trio_scanf() family of functions, or define to 1 to enable them.
191 * This may be useful on an embedded platform with no standard I/O.
193 #if !defined(TRIO_FEATURE_STDIO)
194 # define TRIO_FEATURE_STDIO 1
198 * TRIO_FEATURE_FD (=0 or =1)
200 * Define this to 0 to disable compilation of the trio_dprintf() and
201 * trio_dscanf() family of functions, or define to 1 to enable them.
203 * This may be useful on an embedded platform with no filesystem, or on
204 * a platform that supports file I/O using FILE* but not using raw file
207 #if !defined(TRIO_FEATURE_FD)
208 # define TRIO_FEATURE_FD 1
212 * TRIO_FEATURE_DYNAMICSTRING (=0 or =1)
214 * Define this to 0 to disable compilation of the trio_aprintf()
215 * family of functions, or define to 1 to enable them.
217 * If you define both this and TRIO_MINIMAL to 0, then Trio will never
218 * call malloc or free.
220 #if !defined(TRIO_FEATURE_DYNAMICSTRING)
221 # define TRIO_FEATURE_DYNAMICSTRING 1
225 * TRIO_FEATURE_CLOSURE (=0 or =1)
227 * Define this to 0 to disable compilation of the trio_cprintf() and
228 * trio_cscanf() family of functions, or define to 1 to enable them.
230 * These functions are rarely needed. This saves a (small) amount of code.
232 #if !defined(TRIO_FEATURE_CLOSURE)
233 # define TRIO_FEATURE_CLOSURE 1
237 * TRIO_FEATURE_ERRORCODE (=0 or =1)
239 * Define this to 0 to return -1 from the print and scan function on
240 * error, or define to 1 to return a negative number with debugging
241 * information as part of the return code.
243 * If enabled, the return code will be a negative number, which encodes
244 * an error code and an error location. These can be decoded with the
245 * TRIO_ERROR_CODE and TRIO_ERROR_POSITION macros.
247 #if defined(TRIO_ERRORS)
248 # define TRIO_FEATURE_ERRORCODE TRIO_ERRORS
250 #if !defined(TRIO_FEATURE_ERRORCODE)
251 # define TRIO_FEATURE_ERRORCODE 1
255 * TRIO_FEATURE_STRERR (=0 or =1)
257 * Define this to 0 if you do not use trio_strerror(), or define to 1 if
260 * This saves a (small) amount of code.
262 #if !defined(TRIO_FEATURE_STRERR)
263 # define TRIO_FEATURE_STRERR 1
267 * TRIO_FEATURE_FLOAT (=0 or =1)
269 * Define this to 0 to disable all floating-point support, or define
272 * This is useful in restricted embedded platforms that do not support
273 * floating-point. Obviously you cannot use floating-point format
274 * specifiers if you define this.
276 * Do not compile trionan.c if you disable this.
278 #if !defined(TRIO_FEATURE_FLOAT)
279 # define TRIO_FEATURE_FLOAT 1
283 * TRIO_FEATURE_LOCALE (=0 or =1)
285 * Define this to 0 to disable customized locale support, or define
288 * This saves a (small) amount of code.
290 #if !defined(TRIO_FEATURE_LOCALE)
291 # define TRIO_FEATURE_LOCALE 1
297 * Define this to disable building the public trionan.h and triostr.h.
298 * If you define this, then you must not compile trionan.c and triostr.c
301 #if defined(TRIO_MINIMAL)
302 # if !defined(TRIO_EMBED_NAN)
303 # define TRIO_EMBED_NAN
305 # if !defined(TRIO_EMBED_STRING)
306 # define TRIO_EMBED_STRING
310 /* Does not work yet. Do not enable */
311 #ifndef TRIO_FEATURE_WIDECHAR
312 # define TRIO_FEATURE_WIDECHAR 0
315 /*************************************************************************
316 * Mapping standards to internal features
319 #if !defined(TRIO_FEATURE_HEXFLOAT)
320 # define TRIO_FEATURE_HEXFLOAT (TRIO_C99 && TRIO_FEATURE_FLOAT)
323 #if !defined(TRIO_FEATURE_LONGDOUBLE)
324 # define TRIO_FEATURE_LONGDOUBLE TRIO_FEATURE_FLOAT
327 #if !defined(TRIO_FEATURE_ERRNO)
328 # define TRIO_FEATURE_ERRNO TRIO_GNU
331 #if !defined(TRIO_FEATURE_QUAD)
332 # define TRIO_FEATURE_QUAD (TRIO_BSD || TRIO_GNU)
335 #if !defined(TRIO_FEATURE_SIZE_T)
336 # define TRIO_FEATURE_SIZE_T TRIO_C99
339 #if !defined(TRIO_FEATURE_SIZE_T_UPPER)
340 # define TRIO_FEATURE_SIZE_T_UPPER TRIO_GNU
343 #if !defined(TRIO_FEATURE_PTRDIFF_T)
344 # define TRIO_FEATURE_PTRDIFF_T TRIO_C99
347 #if !defined(TRIO_FEATURE_INTMAX_T)
348 # define TRIO_FEATURE_INTMAX_T TRIO_C99
351 #if !defined(TRIO_FEATURE_FIXED_SIZE)
352 # define TRIO_FEATURE_FIXED_SIZE TRIO_MICROSOFT
355 #if !defined(TRIO_FEATURE_POSITIONAL)
356 # define TRIO_FEATURE_POSITIONAL TRIO_UNIX98
359 #if !defined(TRIO_FEATURE_USER_DEFINED)
360 # define TRIO_FEATURE_USER_DEFINED TRIO_EXTENSION
363 #if !defined(TRIO_FEATURE_BINARY)
364 # define TRIO_FEATURE_BINARY TRIO_EXTENSION
367 #if !defined(TRIO_FEATURE_QUOTE)
368 # define TRIO_FEATURE_QUOTE TRIO_EXTENSION
371 #if !defined(TRIO_FEATURE_STICKY)
372 # define TRIO_FEATURE_STICKY TRIO_EXTENSION
375 #if !defined(TRIO_FEATURE_VARSIZE)
376 # define TRIO_FEATURE_VARSIZE TRIO_EXTENSION
379 #if !defined(TRIO_FEATURE_ROUNDING)
380 # define TRIO_FEATURE_ROUNDING TRIO_EXTENSION
383 /*************************************************************************
387 # define TRIO_MALLOC(n) malloc(n)
390 # define TRIO_REALLOC(x,n) realloc((x),(n))
393 # define TRIO_FREE(x) free(x)
397 /*************************************************************************
398 * User-defined specifiers
401 typedef int (*trio_callback_t) TRIO_PROTO((trio_pointer_t));
403 trio_pointer_t trio_register TRIO_PROTO((trio_callback_t callback, const char *name));
404 void trio_unregister TRIO_PROTO((trio_pointer_t handle));
406 TRIO_CONST char *trio_get_format TRIO_PROTO((trio_pointer_t ref));
407 TRIO_CONST trio_pointer_t trio_get_argument TRIO_PROTO((trio_pointer_t ref));
410 int trio_get_width TRIO_PROTO((trio_pointer_t ref));
411 void trio_set_width TRIO_PROTO((trio_pointer_t ref, int width));
412 int trio_get_precision TRIO_PROTO((trio_pointer_t ref));
413 void trio_set_precision TRIO_PROTO((trio_pointer_t ref, int precision));
414 int trio_get_base TRIO_PROTO((trio_pointer_t ref));
415 void trio_set_base TRIO_PROTO((trio_pointer_t ref, int base));
416 int trio_get_padding TRIO_PROTO((trio_pointer_t ref));
417 void trio_set_padding TRIO_PROTO((trio_pointer_t ref, int is_padding));
418 int trio_get_short TRIO_PROTO((trio_pointer_t ref)); /* h */
419 void trio_set_shortshort TRIO_PROTO((trio_pointer_t ref, int is_shortshort));
420 int trio_get_shortshort TRIO_PROTO((trio_pointer_t ref)); /* hh */
421 void trio_set_short TRIO_PROTO((trio_pointer_t ref, int is_short));
422 int trio_get_long TRIO_PROTO((trio_pointer_t ref)); /* l */
423 void trio_set_long TRIO_PROTO((trio_pointer_t ref, int is_long));
424 int trio_get_longlong TRIO_PROTO((trio_pointer_t ref)); /* ll */
425 void trio_set_longlong TRIO_PROTO((trio_pointer_t ref, int is_longlong));
426 int trio_get_longdouble TRIO_PROTO((trio_pointer_t ref)); /* L */
427 void trio_set_longdouble TRIO_PROTO((trio_pointer_t ref, int is_longdouble));
428 int trio_get_alternative TRIO_PROTO((trio_pointer_t ref)); /* # */
429 void trio_set_alternative TRIO_PROTO((trio_pointer_t ref, int is_alternative));
430 int trio_get_alignment TRIO_PROTO((trio_pointer_t ref)); /* - */
431 void trio_set_alignment TRIO_PROTO((trio_pointer_t ref, int is_leftaligned));
432 int trio_get_spacing TRIO_PROTO((trio_pointer_t ref)); /* (space) */
433 void trio_set_spacing TRIO_PROTO((trio_pointer_t ref, int is_space));
434 int trio_get_sign TRIO_PROTO((trio_pointer_t ref)); /* + */
435 void trio_set_sign TRIO_PROTO((trio_pointer_t ref, int is_showsign));
436 #if TRIO_FEATURE_QUOTE
437 int trio_get_quote TRIO_PROTO((trio_pointer_t ref)); /* ' */
438 void trio_set_quote TRIO_PROTO((trio_pointer_t ref, int is_quote));
440 int trio_get_upper TRIO_PROTO((trio_pointer_t ref));
441 void trio_set_upper TRIO_PROTO((trio_pointer_t ref, int is_upper));
442 #if TRIO_FEATURE_INTMAX_T
443 int trio_get_largest TRIO_PROTO((trio_pointer_t ref)); /* j */
444 void trio_set_largest TRIO_PROTO((trio_pointer_t ref, int is_largest));
446 #if TRIO_FEATURE_PTRDIFF_T
447 int trio_get_ptrdiff TRIO_PROTO((trio_pointer_t ref)); /* t */
448 void trio_set_ptrdiff TRIO_PROTO((trio_pointer_t ref, int is_ptrdiff));
450 #if TRIO_FEATURE_SIZE_T
451 int trio_get_size TRIO_PROTO((trio_pointer_t ref)); /* z / Z */
452 void trio_set_size TRIO_PROTO((trio_pointer_t ref, int is_size));
456 int trio_print_ref TRIO_PROTO((trio_pointer_t ref, const char *format, ...));
457 int trio_vprint_ref TRIO_PROTO((trio_pointer_t ref, const char *format, va_list args));
458 int trio_printv_ref TRIO_PROTO((trio_pointer_t ref, const char *format, trio_pointer_t *args));
460 void trio_print_int TRIO_PROTO((trio_pointer_t ref, int number));
461 void trio_print_uint TRIO_PROTO((trio_pointer_t ref, unsigned int number));
462 /* void trio_print_long TRIO_PROTO((trio_pointer_t ref, long number)); */
463 /* void trio_print_ulong TRIO_PROTO((trio_pointer_t ref, unsigned long number)); */
464 void trio_print_double TRIO_PROTO((trio_pointer_t ref, double number));
465 void trio_print_string TRIO_PROTO((trio_pointer_t ref, TRIO_CONST char *string));
466 void trio_print_pointer TRIO_PROTO((trio_pointer_t ref, trio_pointer_t pointer));
472 #endif /* TRIO_TRIOP_H */