]> Pileus Git - ~andy/fetchmail/blob - trio/triop.h
Credit John Beck's fixes.
[~andy/fetchmail] / trio / triop.h
1 /*************************************************************************
2  *
3  * $Id: triop.h,v 1.18 2009/07/05 10:14:07 breese Exp $
4  *
5  * Copyright (C) 2000 Bjorn Reese and Daniel Stenberg.
6  *
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.
10  *
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.
15  *
16  ************************************************************************
17  *
18  * Private functions, types, etc. used for callback functions.
19  *
20  * The ref pointer is an opaque type and should remain as such.
21  * Private data must only be accessible through the getter and
22  * setter functions.
23  *
24  ************************************************************************/
25
26 #ifndef TRIO_TRIOP_H
27 #define TRIO_TRIOP_H
28
29 #include "triodef.h"
30
31 #include <stdlib.h>
32 #if defined(TRIO_COMPILER_ANCIENT)
33 # include <varargs.h>
34 #else
35 # include <stdarg.h>
36 #endif
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 /*************************************************************************
43  * Supported standards
44  */
45
46 /*
47  * TRIO_C99 (=0 or =1)
48  *
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.
53  */
54 #if !defined(TRIO_C99)
55 # define TRIO_C99 1
56 #endif
57
58 /*
59  * TRIO_BSD (=0 or =1)
60  *
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.
65  */
66 #if !defined(TRIO_BSD)
67 # define TRIO_BSD 1
68 #endif
69
70 /*
71  * TRIO_GNU (=0 or =1)
72  *
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.
77  */
78 #if !defined(TRIO_GNU)
79 # define TRIO_GNU 1
80 #endif
81
82 /*
83  * TRIO_MISC (=0 or =1)
84  *
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.
89  */
90 #if !defined(TRIO_MISC)
91 # define TRIO_MISC 1
92 #endif
93
94 /*
95  * TRIO_UNIX98 (=0 or =1)
96  *
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.
101  */
102 #if !defined(TRIO_UNIX98)
103 # define TRIO_UNIX98 1
104 #endif
105   
106 /*
107  * TRIO_MICROSOFT (=0 or =1)
108  *
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.
113  */
114 #if !defined(TRIO_MICROSOFT)
115 # define TRIO_MICROSOFT 1
116 #endif
117
118 /*
119  * TRIO_EXTENSION (=0 or =1)
120  *
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.
128  */
129 #if !defined(TRIO_EXTENSION)
130 # define TRIO_EXTENSION 1
131 #endif
132
133 /*
134  * TRIO_DEPRECATED (=0 or =1)
135  *
136  * Define this to 0 to disable deprecated functionality, or define
137  * to 1 to enable them.
138  */
139 #if !defined(TRIO_DEPRECATED)
140 # define TRIO_DEPRECATED 1
141 #endif
142
143 /*************************************************************************
144  * Features
145  */
146
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
158 #endif
159   
160 /*
161  * TRIO_FEATURE_SCANF (=0 or =1)
162  *
163  * Define this to 0 to disable all the scanf() variants, or define to 1
164  * to enable them.
165  */
166 #if !defined(TRIO_FEATURE_SCANF)
167 # define TRIO_FEATURE_SCANF 1
168 #endif
169   
170 /*
171  * TRIO_FEATURE_FILE (=0 or =1)
172  *
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.
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 you
178  * do not have an implementation of fwrite() at all then you must also
179  * define TRIO_FEATURE_STDIO to 0.
180  */
181 #if !defined(TRIO_FEATURE_FILE)
182 # define TRIO_FEATURE_FILE 1
183 #endif
184
185 /*
186  * TRIO_FEATURE_STDIO (=0 or =1)
187  *
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.
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 1
195 #endif
196
197 /*
198  * TRIO_FEATURE_FD (=0 or =1)
199  *
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.
202  *
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
205  * descriptors.
206  */
207 #if !defined(TRIO_FEATURE_FD)
208 # define TRIO_FEATURE_FD 1
209 #endif
210
211 /*
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 never
218  * call malloc or free.
219  */
220 #if !defined(TRIO_FEATURE_DYNAMICSTRING)
221 # define TRIO_FEATURE_DYNAMICSTRING 1
222 #endif
223
224 /*
225  * TRIO_FEATURE_CLOSURE (=0 or =1)
226  *
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.
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 1
234 #endif
235
236 /*
237  * TRIO_FEATURE_ERRORCODE (=0 or =1)
238  *
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.
242  *
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.
246  */
247 #if defined(TRIO_ERRORS)
248 # define TRIO_FEATURE_ERRORCODE TRIO_ERRORS
249 #endif
250 #if !defined(TRIO_FEATURE_ERRORCODE)
251 # define TRIO_FEATURE_ERRORCODE 1
252 #endif
253
254 /*
255  * TRIO_FEATURE_STRERR (=0 or =1)
256  *
257  * Define this to 0 if you do not use trio_strerror(), or define to 1 if
258  * you do use it.
259  *
260  * This saves a (small) amount of code.
261  */
262 #if !defined(TRIO_FEATURE_STRERR)
263 # define TRIO_FEATURE_STRERR 1
264 #endif
265
266 /*
267  * TRIO_FEATURE_FLOAT (=0 or =1)
268  *
269  * Define this to 0 to disable all floating-point support, or define
270  * to 1 to enable it.
271  *
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.
275  *
276  * Do not compile trionan.c if you disable this.
277  */
278 #if !defined(TRIO_FEATURE_FLOAT)
279 # define TRIO_FEATURE_FLOAT 1
280 #endif
281
282 /*
283  * TRIO_FEATURE_LOCALE (=0 or =1)
284  *
285  * Define this to 0 to disable customized locale support, or define
286  * to 1 to enable it.
287  *
288  * This saves a (small) amount of code.
289  */
290 #if !defined(TRIO_FEATURE_LOCALE)
291 # define TRIO_FEATURE_LOCALE 1
292 #endif
293
294 /*
295  * TRIO_MINIMAL
296  *
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
299  * separately.
300  */
301 #if defined(TRIO_MINIMAL)
302 # if !defined(TRIO_EMBED_NAN)
303 #  define TRIO_EMBED_NAN
304 # endif
305 # if !defined(TRIO_EMBED_STRING)
306 #  define TRIO_EMBED_STRING
307 # endif
308 #endif
309   
310 /* Does not work yet. Do not enable */
311 #ifndef TRIO_FEATURE_WIDECHAR
312 # define TRIO_FEATURE_WIDECHAR 0
313 #endif
314
315 /*************************************************************************
316  * Mapping standards to internal features
317  */
318
319 #if !defined(TRIO_FEATURE_HEXFLOAT)
320 # define TRIO_FEATURE_HEXFLOAT (TRIO_C99 && TRIO_FEATURE_FLOAT)
321 #endif
322
323 #if !defined(TRIO_FEATURE_LONGDOUBLE)
324 # define TRIO_FEATURE_LONGDOUBLE TRIO_FEATURE_FLOAT
325 #endif
326
327 #if !defined(TRIO_FEATURE_ERRNO)
328 # define TRIO_FEATURE_ERRNO TRIO_GNU
329 #endif
330
331 #if !defined(TRIO_FEATURE_QUAD)
332 # define TRIO_FEATURE_QUAD (TRIO_BSD || TRIO_GNU)
333 #endif
334
335 #if !defined(TRIO_FEATURE_SIZE_T)
336 # define TRIO_FEATURE_SIZE_T TRIO_C99
337 #endif
338
339 #if !defined(TRIO_FEATURE_SIZE_T_UPPER)
340 # define TRIO_FEATURE_SIZE_T_UPPER TRIO_GNU
341 #endif
342   
343 #if !defined(TRIO_FEATURE_PTRDIFF_T)
344 # define TRIO_FEATURE_PTRDIFF_T TRIO_C99
345 #endif
346
347 #if !defined(TRIO_FEATURE_INTMAX_T)
348 # define TRIO_FEATURE_INTMAX_T TRIO_C99
349 #endif
350
351 #if !defined(TRIO_FEATURE_FIXED_SIZE)
352 # define TRIO_FEATURE_FIXED_SIZE TRIO_MICROSOFT
353 #endif
354
355 #if !defined(TRIO_FEATURE_POSITIONAL)
356 # define TRIO_FEATURE_POSITIONAL TRIO_UNIX98
357 #endif
358
359 #if !defined(TRIO_FEATURE_USER_DEFINED)
360 # define TRIO_FEATURE_USER_DEFINED TRIO_EXTENSION
361 #endif
362
363 #if !defined(TRIO_FEATURE_BINARY)
364 # define TRIO_FEATURE_BINARY TRIO_EXTENSION
365 #endif
366
367 #if !defined(TRIO_FEATURE_QUOTE)
368 # define TRIO_FEATURE_QUOTE TRIO_EXTENSION
369 #endif
370   
371 #if !defined(TRIO_FEATURE_STICKY)
372 # define TRIO_FEATURE_STICKY TRIO_EXTENSION
373 #endif
374   
375 #if !defined(TRIO_FEATURE_VARSIZE)
376 # define TRIO_FEATURE_VARSIZE TRIO_EXTENSION
377 #endif
378
379 #if !defined(TRIO_FEATURE_ROUNDING)
380 # define TRIO_FEATURE_ROUNDING TRIO_EXTENSION
381 #endif
382   
383 /*************************************************************************
384  * Memory handling
385  */
386 #ifndef TRIO_MALLOC
387 # define TRIO_MALLOC(n) malloc(n)
388 #endif
389 #ifndef TRIO_REALLOC
390 # define TRIO_REALLOC(x,n) realloc((x),(n))
391 #endif
392 #ifndef TRIO_FREE
393 # define TRIO_FREE(x) free(x)
394 #endif
395
396
397 /*************************************************************************
398  * User-defined specifiers
399  */
400
401 typedef int (*trio_callback_t) TRIO_PROTO((trio_pointer_t));
402
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));
405
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));
408
409 /* Modifiers */
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));
439 #endif
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));
445 #endif
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));
449 #endif
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));
453 #endif
454
455 /* Printing */
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));
459
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));
467
468 #ifdef __cplusplus
469 } /* extern "C" */
470 #endif
471
472 #endif /* TRIO_TRIOP_H */