1 /*************************************************************************
2  *
3  * Copyright (C) 1998 Bjorn Reese and Daniel Stenberg.
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
10  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
11  * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND
12  * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER.
13  *
14  * Portion Copyright � 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
15  *
16  *************************************************************************
17  *
18  * http://ctrio.sourceforge.net/
19  *
20  ************************************************************************
21  */
22 
23 /** @file
24 @internalComponent
25 @released
26 */
27 
28 #ifndef TRIO_TRIO_H
29 #define TRIO_TRIO_H
30 
31 #if !defined(WITHOUT_TRIO)
32 
33 /*
34  * Use autoconf defines if present. Packages using trio must define
35  * HAVE_CONFIG_H as a compiler option themselves.
36  */
37 #if defined(HAVE_CONFIG_H)
38 # include <config.h>
39 #endif
40 
41 #include <xmlengtriodef.h>
42 
43 #include <stdio.h>
44 #include <stdlib.h>
45 #if defined(TRIO_COMPILER_ANCIENT)
46 # include <varargs.h>
47 #else
48 # include <stdarg.h>
49 #endif
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 /*
56  * Error codes.
57  *
58  * Remember to add a textual description to trio_strerror.
59  */
60 enum {
61   TRIO_EOF      = 1,
62   TRIO_EINVAL   = 2,
63   TRIO_ETOOMANY = 3,
64   TRIO_EDBLREF  = 4,
65   TRIO_EGAP     = 5,
66   TRIO_ENOMEM   = 6,
67   TRIO_ERANGE   = 7,
68   TRIO_ERRNO    = 8,
69   TRIO_ECUSTOM  = 9
70 };
71 
72 /* Error macros */
73 #define TRIO_ERROR_CODE(x) ((-(x)) & 0x00FF)
74 #define TRIO_ERROR_POSITION(x) ((-(x)) >> 8)
75 #define TRIO_ERROR_NAME(x) trio_strerror(x)
76 
77 typedef int (*trio_outstream_t) TRIO_PROTO((trio_pointer_t, int));
78 typedef int (*trio_instream_t) TRIO_PROTO((trio_pointer_t));
79 
80 TRIO_CONST char *trio_strerror TRIO_PROTO((int));
81 
82 /*************************************************************************
83  * Print Functions
84  */
85 
86 int trio_printf TRIO_PROTO((TRIO_CONST char *format, ...));
87 int trio_vprintf TRIO_PROTO((TRIO_CONST char *format, va_list args));
88 int trio_printfv TRIO_PROTO((TRIO_CONST char *format, void **args));
89 
90 #ifndef XMLENGINE_EXCLUDE_FILE_FUNC
91 int trio_fprintf TRIO_PROTO((FILE *file, TRIO_CONST char *format, ...));
92 int trio_vfprintf TRIO_PROTO((FILE *file, TRIO_CONST char *format, va_list args));
93 int trio_fprintfv TRIO_PROTO((FILE *file, TRIO_CONST char *format, void **args));
94 #endif
95 
96 int trio_dprintf TRIO_PROTO((int fd, TRIO_CONST char *format, ...));
97 int trio_vdprintf TRIO_PROTO((int fd, TRIO_CONST char *format, va_list args));
98 int trio_dprintfv TRIO_PROTO((int fd, TRIO_CONST char *format, void **args));
99 
100 int trio_cprintf TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure,
101                              TRIO_CONST char *format, ...));
102 int trio_vcprintf TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure,
103                               TRIO_CONST char *format, va_list args));
104 int trio_cprintfv TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure,
105                               TRIO_CONST char *format, void **args));
106 
107 int trio_sprintf TRIO_PROTO((char *buffer, TRIO_CONST char *format, ...));
108 int trio_vsprintf TRIO_PROTO((char *buffer, TRIO_CONST char *format, va_list args));
109 int trio_sprintfv TRIO_PROTO((char *buffer, TRIO_CONST char *format, void **args));
110 
111 int trio_snprintf TRIO_PROTO((char *buffer, size_t max, TRIO_CONST char *format, ...));
112 int trio_vsnprintf TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format,
113                    va_list args));
114 int trio_snprintfv TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format,
115                    void **args));
116 
117 int trio_snprintfcat TRIO_PROTO((char *buffer, size_t max, TRIO_CONST char *format, ...));
118 int trio_vsnprintfcat TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format,
119                       va_list args));
120 
121 char *trio_aprintf TRIO_PROTO((TRIO_CONST char *format, ...));
122 char *trio_vaprintf TRIO_PROTO((TRIO_CONST char *format, va_list args));
123 
124 int trio_asprintf TRIO_PROTO((char **ret, TRIO_CONST char *format, ...));
125 int trio_vasprintf TRIO_PROTO((char **ret, TRIO_CONST char *format, va_list args));
126 
127 /*************************************************************************
128  * Scan Functions
129  */
130 int trio_scanf TRIO_PROTO((TRIO_CONST char *format, ...));
131 int trio_vscanf TRIO_PROTO((TRIO_CONST char *format, va_list args));
132 int trio_scanfv TRIO_PROTO((TRIO_CONST char *format, void **args));
133 
134 #ifndef XMLENGINE_EXCLUDE_FILE_FUNC
135 int trio_fscanf TRIO_PROTO((FILE *file, TRIO_CONST char *format, ...));
136 int trio_vfscanf TRIO_PROTO((FILE *file, TRIO_CONST char *format, va_list args));
137 int trio_fscanfv TRIO_PROTO((FILE *file, TRIO_CONST char *format, void **args));
138 #endif
139 
140 int trio_dscanf TRIO_PROTO((int fd, TRIO_CONST char *format, ...));
141 int trio_vdscanf TRIO_PROTO((int fd, TRIO_CONST char *format, va_list args));
142 int trio_dscanfv TRIO_PROTO((int fd, TRIO_CONST char *format, void **args));
143 
144 int trio_cscanf TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure,
145                             TRIO_CONST char *format, ...));
146 int trio_vcscanf TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure,
147                              TRIO_CONST char *format, va_list args));
148 int trio_cscanfv TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure,
149                              TRIO_CONST char *format, void **args));
150 
151 int trio_sscanf TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, ...));
152 int trio_vsscanf TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, va_list args));
153 int trio_sscanfv TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, void **args));
154 
155 /*************************************************************************
156  * Locale Functions
157  */
158 void trio_locale_set_decimal_point TRIO_PROTO((char *decimalPoint));
159 void trio_locale_set_thousand_separator TRIO_PROTO((char *thousandSeparator));
160 void trio_locale_set_grouping TRIO_PROTO((char *grouping));
161 
162 /*************************************************************************
163  * Renaming
164  */
165 #ifdef TRIO_REPLACE_STDIO
166 /* Replace the <stdio.h> functions */
167 #ifndef HAVE_PRINTF
168 # define printf trio_printf
169 #endif
170 #ifndef HAVE_VPRINTF
171 # define vprintf trio_vprintf
172 #endif
173 #ifndef HAVE_FPRINTF
174 # define fprintf trio_fprintf
175 #endif
176 #ifndef HAVE_VFPRINTF
177 # define vfprintf trio_vfprintf
178 #endif
179 #ifndef HAVE_SPRINTF
180 # define sprintf trio_sprintf
181 #endif
182 #ifndef HAVE_VSPRINTF
183 # define vsprintf trio_vsprintf
184 #endif
185 #ifndef HAVE_SNPRINTF
186 # define snprintf trio_snprintf
187 #endif
188 #ifndef HAVE_VSNPRINTF
189 # define vsnprintf trio_vsnprintf
190 #endif
191 #ifndef HAVE_SCANF
192 # define scanf trio_scanf
193 #endif
194 #ifndef HAVE_VSCANF
195 # define vscanf trio_vscanf
196 #endif
197 #ifndef HAVE_FSCANF
198 # define fscanf trio_fscanf
199 #endif
200 #ifndef HAVE_VFSCANF
201 # define vfscanf trio_vfscanf
202 #endif
203 #ifndef HAVE_SSCANF
204 # define sscanf trio_sscanf
205 #endif
206 #ifndef HAVE_VSSCANF
207 # define vsscanf trio_vsscanf
208 #endif
209 /* These aren't stdio functions, but we make them look similar */
210 #define dprintf trio_dprintf
211 #define vdprintf trio_vdprintf
212 #define aprintf trio_aprintf
213 #define vaprintf trio_vaprintf
214 #define asprintf trio_asprintf
215 #define vasprintf trio_vasprintf
216 #define dscanf trio_dscanf
217 #define vdscanf trio_vdscanf
218 #endif
219 
220 #ifdef __cplusplus
221 } /* extern "C" */
222 #endif
223 
224 #endif /* WITHOUT_TRIO */
225 
226 #endif /* TRIO_TRIO_H */
227 
228