blob: 99d212734a67aca29f0f27a76348fbb0baea8417 [file] [log] [blame]
Daniel Veillard92ad2102001-03-27 12:47:33 +00001/*************************************************************************
2 *
3 * $Id$
4 *
5 * Copyright (C) 1998 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 *
Bjorn Reese026d29f2002-01-19 15:40:18 +000016 *************************************************************************
17 *
18 * http://ctrio.sourceforge.net/
19 *
Daniel Veillard92ad2102001-03-27 12:47:33 +000020 ************************************************************************/
21
Bjorn Reese70a9da52001-04-21 16:57:29 +000022#ifndef TRIO_TRIO_H
23#define TRIO_TRIO_H
Daniel Veillard92ad2102001-03-27 12:47:33 +000024
Daniel Veillardb7c29c32002-09-25 22:44:43 +000025#if !defined(WITHOUT_TRIO)
Daniel Veillard92ad2102001-03-27 12:47:33 +000026
27/*
Bjorn Reese70a9da52001-04-21 16:57:29 +000028 * Use autoconf defines if present. Packages using trio must define
29 * HAVE_CONFIG_H as a compiler option themselves.
30 */
Daniel Richard G5706b6d2012-08-06 11:32:54 +080031#if defined(TRIO_HAVE_CONFIG_H)
William M. Brackec5b1fd2009-03-03 06:31:43 +000032# include "config.h"
Bjorn Reese70a9da52001-04-21 16:57:29 +000033#endif
34
Daniel Veillardb7c29c32002-09-25 22:44:43 +000035#include "triodef.h"
Bjorn Reese70a9da52001-04-21 16:57:29 +000036
Daniel Veillarda48ed3d2003-04-03 15:28:28 +000037#include <stdio.h>
38#include <stdlib.h>
39#if defined(TRIO_COMPILER_ANCIENT)
40# include <varargs.h>
41#else
42# include <stdarg.h>
43#endif
44
Bjorn Reese906ec8a2001-06-05 12:46:33 +000045#ifdef __cplusplus
46extern "C" {
47#endif
48
Bjorn Reese70a9da52001-04-21 16:57:29 +000049/*
Daniel Veillard92ad2102001-03-27 12:47:33 +000050 * Error codes.
51 *
52 * Remember to add a textual description to trio_strerror.
53 */
54enum {
55 TRIO_EOF = 1,
56 TRIO_EINVAL = 2,
57 TRIO_ETOOMANY = 3,
58 TRIO_EDBLREF = 4,
59 TRIO_EGAP = 5,
60 TRIO_ENOMEM = 6,
Bjorn Reese026d29f2002-01-19 15:40:18 +000061 TRIO_ERANGE = 7,
Daniel Veillardb7c29c32002-09-25 22:44:43 +000062 TRIO_ERRNO = 8,
63 TRIO_ECUSTOM = 9
Daniel Veillard92ad2102001-03-27 12:47:33 +000064};
65
Daniel Veillardb7c29c32002-09-25 22:44:43 +000066/* Error macros */
67#define TRIO_ERROR_CODE(x) ((-(x)) & 0x00FF)
68#define TRIO_ERROR_POSITION(x) ((-(x)) >> 8)
69#define TRIO_ERROR_NAME(x) trio_strerror(x)
70
71typedef int (*trio_outstream_t) TRIO_PROTO((trio_pointer_t, int));
72typedef int (*trio_instream_t) TRIO_PROTO((trio_pointer_t));
73
74TRIO_CONST char *trio_strerror TRIO_PROTO((int));
Bjorn Reese70a9da52001-04-21 16:57:29 +000075
76/*************************************************************************
77 * Print Functions
78 */
79
Daniel Veillardb7c29c32002-09-25 22:44:43 +000080int trio_printf TRIO_PROTO((TRIO_CONST char *format, ...));
81int trio_vprintf TRIO_PROTO((TRIO_CONST char *format, va_list args));
82int trio_printfv TRIO_PROTO((TRIO_CONST char *format, void **args));
Bjorn Reese70a9da52001-04-21 16:57:29 +000083
Daniel Veillardb7c29c32002-09-25 22:44:43 +000084int trio_fprintf TRIO_PROTO((FILE *file, TRIO_CONST char *format, ...));
85int trio_vfprintf TRIO_PROTO((FILE *file, TRIO_CONST char *format, va_list args));
86int trio_fprintfv TRIO_PROTO((FILE *file, TRIO_CONST char *format, void **args));
Bjorn Reese70a9da52001-04-21 16:57:29 +000087
Daniel Veillardb7c29c32002-09-25 22:44:43 +000088int trio_dprintf TRIO_PROTO((int fd, TRIO_CONST char *format, ...));
89int trio_vdprintf TRIO_PROTO((int fd, TRIO_CONST char *format, va_list args));
90int trio_dprintfv TRIO_PROTO((int fd, TRIO_CONST char *format, void **args));
Bjorn Reese70a9da52001-04-21 16:57:29 +000091
Daniel Veillardb7c29c32002-09-25 22:44:43 +000092int trio_cprintf TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure,
93 TRIO_CONST char *format, ...));
94int trio_vcprintf TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure,
95 TRIO_CONST char *format, va_list args));
96int trio_cprintfv TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure,
97 TRIO_CONST char *format, void **args));
Bjorn Reese70a9da52001-04-21 16:57:29 +000098
Daniel Veillardb7c29c32002-09-25 22:44:43 +000099int trio_sprintf TRIO_PROTO((char *buffer, TRIO_CONST char *format, ...));
100int trio_vsprintf TRIO_PROTO((char *buffer, TRIO_CONST char *format, va_list args));
101int trio_sprintfv TRIO_PROTO((char *buffer, TRIO_CONST char *format, void **args));
Bjorn Reese70a9da52001-04-21 16:57:29 +0000102
Daniel Veillardb7c29c32002-09-25 22:44:43 +0000103int trio_snprintf TRIO_PROTO((char *buffer, size_t max, TRIO_CONST char *format, ...));
104int trio_vsnprintf TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format,
105 va_list args));
106int trio_snprintfv TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format,
107 void **args));
Bjorn Reese70a9da52001-04-21 16:57:29 +0000108
Daniel Veillardb7c29c32002-09-25 22:44:43 +0000109int trio_snprintfcat TRIO_PROTO((char *buffer, size_t max, TRIO_CONST char *format, ...));
110int trio_vsnprintfcat TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format,
111 va_list args));
Bjorn Reese70a9da52001-04-21 16:57:29 +0000112
Daniel Veillardb7c29c32002-09-25 22:44:43 +0000113char *trio_aprintf TRIO_PROTO((TRIO_CONST char *format, ...));
114char *trio_vaprintf TRIO_PROTO((TRIO_CONST char *format, va_list args));
115
116int trio_asprintf TRIO_PROTO((char **ret, TRIO_CONST char *format, ...));
117int trio_vasprintf TRIO_PROTO((char **ret, TRIO_CONST char *format, va_list args));
Daniel Veillard92ad2102001-03-27 12:47:33 +0000118
Bjorn Reese70a9da52001-04-21 16:57:29 +0000119/*************************************************************************
120 * Scan Functions
121 */
Daniel Veillardb7c29c32002-09-25 22:44:43 +0000122int trio_scanf TRIO_PROTO((TRIO_CONST char *format, ...));
123int trio_vscanf TRIO_PROTO((TRIO_CONST char *format, va_list args));
124int trio_scanfv TRIO_PROTO((TRIO_CONST char *format, void **args));
Bjorn Reese70a9da52001-04-21 16:57:29 +0000125
Daniel Veillardb7c29c32002-09-25 22:44:43 +0000126int trio_fscanf TRIO_PROTO((FILE *file, TRIO_CONST char *format, ...));
127int trio_vfscanf TRIO_PROTO((FILE *file, TRIO_CONST char *format, va_list args));
128int trio_fscanfv TRIO_PROTO((FILE *file, TRIO_CONST char *format, void **args));
Bjorn Reese70a9da52001-04-21 16:57:29 +0000129
Daniel Veillardb7c29c32002-09-25 22:44:43 +0000130int trio_dscanf TRIO_PROTO((int fd, TRIO_CONST char *format, ...));
131int trio_vdscanf TRIO_PROTO((int fd, TRIO_CONST char *format, va_list args));
132int trio_dscanfv TRIO_PROTO((int fd, TRIO_CONST char *format, void **args));
Bjorn Reese70a9da52001-04-21 16:57:29 +0000133
Daniel Veillardb7c29c32002-09-25 22:44:43 +0000134int trio_cscanf TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure,
135 TRIO_CONST char *format, ...));
136int trio_vcscanf TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure,
137 TRIO_CONST char *format, va_list args));
138int trio_cscanfv TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure,
139 TRIO_CONST char *format, void **args));
140
141int trio_sscanf TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, ...));
142int trio_vsscanf TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, va_list args));
143int trio_sscanfv TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, void **args));
144
145/*************************************************************************
146 * Locale Functions
147 */
148void trio_locale_set_decimal_point TRIO_PROTO((char *decimalPoint));
149void trio_locale_set_thousand_separator TRIO_PROTO((char *thousandSeparator));
150void trio_locale_set_grouping TRIO_PROTO((char *grouping));
Daniel Veillard92ad2102001-03-27 12:47:33 +0000151
Bjorn Reese70a9da52001-04-21 16:57:29 +0000152/*************************************************************************
153 * Renaming
154 */
Daniel Veillard92ad2102001-03-27 12:47:33 +0000155#ifdef TRIO_REPLACE_STDIO
156/* Replace the <stdio.h> functions */
Bjorn Reese70a9da52001-04-21 16:57:29 +0000157#ifndef HAVE_PRINTF
Patrick Monnerat66693ce2013-12-12 15:00:46 +0800158# undef printf
Bjorn Reese70a9da52001-04-21 16:57:29 +0000159# define printf trio_printf
160#endif
161#ifndef HAVE_VPRINTF
Patrick Monnerat66693ce2013-12-12 15:00:46 +0800162# undef vprintf
Bjorn Reese70a9da52001-04-21 16:57:29 +0000163# define vprintf trio_vprintf
164#endif
165#ifndef HAVE_FPRINTF
Patrick Monnerat66693ce2013-12-12 15:00:46 +0800166# undef fprintf
Bjorn Reese70a9da52001-04-21 16:57:29 +0000167# define fprintf trio_fprintf
168#endif
169#ifndef HAVE_VFPRINTF
Patrick Monnerat66693ce2013-12-12 15:00:46 +0800170# undef vfprintf
Bjorn Reese70a9da52001-04-21 16:57:29 +0000171# define vfprintf trio_vfprintf
172#endif
173#ifndef HAVE_SPRINTF
Patrick Monnerat66693ce2013-12-12 15:00:46 +0800174# undef sprintf
Bjorn Reese70a9da52001-04-21 16:57:29 +0000175# define sprintf trio_sprintf
176#endif
177#ifndef HAVE_VSPRINTF
Patrick Monnerat66693ce2013-12-12 15:00:46 +0800178# undef vsprintf
Bjorn Reese70a9da52001-04-21 16:57:29 +0000179# define vsprintf trio_vsprintf
180#endif
181#ifndef HAVE_SNPRINTF
Patrick Monnerat66693ce2013-12-12 15:00:46 +0800182# undef snprintf
Bjorn Reese70a9da52001-04-21 16:57:29 +0000183# define snprintf trio_snprintf
184#endif
185#ifndef HAVE_VSNPRINTF
Patrick Monnerat66693ce2013-12-12 15:00:46 +0800186# undef vsnprintf
Bjorn Reese70a9da52001-04-21 16:57:29 +0000187# define vsnprintf trio_vsnprintf
188#endif
189#ifndef HAVE_SCANF
Patrick Monnerat66693ce2013-12-12 15:00:46 +0800190# undef scanf
Bjorn Reese70a9da52001-04-21 16:57:29 +0000191# define scanf trio_scanf
192#endif
193#ifndef HAVE_VSCANF
Patrick Monnerat66693ce2013-12-12 15:00:46 +0800194# undef vscanf
Bjorn Reese70a9da52001-04-21 16:57:29 +0000195# define vscanf trio_vscanf
196#endif
197#ifndef HAVE_FSCANF
Patrick Monnerat66693ce2013-12-12 15:00:46 +0800198# undef fscanf
Bjorn Reese70a9da52001-04-21 16:57:29 +0000199# define fscanf trio_fscanf
200#endif
201#ifndef HAVE_VFSCANF
Patrick Monnerat66693ce2013-12-12 15:00:46 +0800202# undef vfscanf
Bjorn Reese70a9da52001-04-21 16:57:29 +0000203# define vfscanf trio_vfscanf
204#endif
205#ifndef HAVE_SSCANF
Patrick Monnerat66693ce2013-12-12 15:00:46 +0800206# undef sscanf
Bjorn Reese70a9da52001-04-21 16:57:29 +0000207# define sscanf trio_sscanf
208#endif
209#ifndef HAVE_VSSCANF
Patrick Monnerat66693ce2013-12-12 15:00:46 +0800210# undef vsscanf
Bjorn Reese70a9da52001-04-21 16:57:29 +0000211# define vsscanf trio_vsscanf
212#endif
Daniel Veillard92ad2102001-03-27 12:47:33 +0000213/* These aren't stdio functions, but we make them look similar */
214#define dprintf trio_dprintf
215#define vdprintf trio_vdprintf
216#define aprintf trio_aprintf
217#define vaprintf trio_vaprintf
218#define asprintf trio_asprintf
219#define vasprintf trio_vasprintf
220#define dscanf trio_dscanf
221#define vdscanf trio_vdscanf
222#endif
223
Bjorn Reese906ec8a2001-06-05 12:46:33 +0000224#ifdef __cplusplus
225} /* extern "C" */
226#endif
227
228#endif /* WITHOUT_TRIO */
Bjorn Reese70a9da52001-04-21 16:57:29 +0000229
230#endif /* TRIO_TRIO_H */