Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 1 | /************************************************************************* |
| 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 Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 16 | ************************************************************************* |
| 17 | * |
| 18 | * http://ctrio.sourceforge.net/ |
| 19 | * |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 20 | ************************************************************************/ |
| 21 | |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 22 | #ifndef TRIO_TRIO_H |
| 23 | #define TRIO_TRIO_H |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 24 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 25 | #if !defined(WITHOUT_TRIO) |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 26 | |
| 27 | /* |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 28 | * Use autoconf defines if present. Packages using trio must define |
| 29 | * HAVE_CONFIG_H as a compiler option themselves. |
| 30 | */ |
| 31 | #if defined(HAVE_CONFIG_H) |
William M. Brack | ec5b1fd | 2009-03-03 06:31:43 +0000 | [diff] [blame] | 32 | # include "config.h" |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 33 | #endif |
| 34 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 35 | #include "triodef.h" |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 36 | |
Daniel Veillard | a48ed3d | 2003-04-03 15:28:28 +0000 | [diff] [blame] | 37 | #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 Reese | 906ec8a | 2001-06-05 12:46:33 +0000 | [diff] [blame] | 45 | #ifdef __cplusplus |
| 46 | extern "C" { |
| 47 | #endif |
| 48 | |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 49 | /* |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 50 | * Error codes. |
| 51 | * |
| 52 | * Remember to add a textual description to trio_strerror. |
| 53 | */ |
| 54 | enum { |
| 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 Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 61 | TRIO_ERANGE = 7, |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 62 | TRIO_ERRNO = 8, |
| 63 | TRIO_ECUSTOM = 9 |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 66 | /* 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 | |
| 71 | typedef int (*trio_outstream_t) TRIO_PROTO((trio_pointer_t, int)); |
| 72 | typedef int (*trio_instream_t) TRIO_PROTO((trio_pointer_t)); |
| 73 | |
| 74 | TRIO_CONST char *trio_strerror TRIO_PROTO((int)); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 75 | |
| 76 | /************************************************************************* |
| 77 | * Print Functions |
| 78 | */ |
| 79 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 80 | int trio_printf TRIO_PROTO((TRIO_CONST char *format, ...)); |
| 81 | int trio_vprintf TRIO_PROTO((TRIO_CONST char *format, va_list args)); |
| 82 | int trio_printfv TRIO_PROTO((TRIO_CONST char *format, void **args)); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 83 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 84 | int trio_fprintf TRIO_PROTO((FILE *file, TRIO_CONST char *format, ...)); |
| 85 | int trio_vfprintf TRIO_PROTO((FILE *file, TRIO_CONST char *format, va_list args)); |
| 86 | int trio_fprintfv TRIO_PROTO((FILE *file, TRIO_CONST char *format, void **args)); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 87 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 88 | int trio_dprintf TRIO_PROTO((int fd, TRIO_CONST char *format, ...)); |
| 89 | int trio_vdprintf TRIO_PROTO((int fd, TRIO_CONST char *format, va_list args)); |
| 90 | int trio_dprintfv TRIO_PROTO((int fd, TRIO_CONST char *format, void **args)); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 91 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 92 | int trio_cprintf TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure, |
| 93 | TRIO_CONST char *format, ...)); |
| 94 | int trio_vcprintf TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure, |
| 95 | TRIO_CONST char *format, va_list args)); |
| 96 | int trio_cprintfv TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure, |
| 97 | TRIO_CONST char *format, void **args)); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 98 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 99 | int trio_sprintf TRIO_PROTO((char *buffer, TRIO_CONST char *format, ...)); |
| 100 | int trio_vsprintf TRIO_PROTO((char *buffer, TRIO_CONST char *format, va_list args)); |
| 101 | int trio_sprintfv TRIO_PROTO((char *buffer, TRIO_CONST char *format, void **args)); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 102 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 103 | int trio_snprintf TRIO_PROTO((char *buffer, size_t max, TRIO_CONST char *format, ...)); |
| 104 | int trio_vsnprintf TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format, |
| 105 | va_list args)); |
| 106 | int trio_snprintfv TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format, |
| 107 | void **args)); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 108 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 109 | int trio_snprintfcat TRIO_PROTO((char *buffer, size_t max, TRIO_CONST char *format, ...)); |
| 110 | int trio_vsnprintfcat TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format, |
| 111 | va_list args)); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 112 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 113 | char *trio_aprintf TRIO_PROTO((TRIO_CONST char *format, ...)); |
| 114 | char *trio_vaprintf TRIO_PROTO((TRIO_CONST char *format, va_list args)); |
| 115 | |
| 116 | int trio_asprintf TRIO_PROTO((char **ret, TRIO_CONST char *format, ...)); |
| 117 | int trio_vasprintf TRIO_PROTO((char **ret, TRIO_CONST char *format, va_list args)); |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 118 | |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 119 | /************************************************************************* |
| 120 | * Scan Functions |
| 121 | */ |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 122 | int trio_scanf TRIO_PROTO((TRIO_CONST char *format, ...)); |
| 123 | int trio_vscanf TRIO_PROTO((TRIO_CONST char *format, va_list args)); |
| 124 | int trio_scanfv TRIO_PROTO((TRIO_CONST char *format, void **args)); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 125 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 126 | int trio_fscanf TRIO_PROTO((FILE *file, TRIO_CONST char *format, ...)); |
| 127 | int trio_vfscanf TRIO_PROTO((FILE *file, TRIO_CONST char *format, va_list args)); |
| 128 | int trio_fscanfv TRIO_PROTO((FILE *file, TRIO_CONST char *format, void **args)); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 129 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 130 | int trio_dscanf TRIO_PROTO((int fd, TRIO_CONST char *format, ...)); |
| 131 | int trio_vdscanf TRIO_PROTO((int fd, TRIO_CONST char *format, va_list args)); |
| 132 | int trio_dscanfv TRIO_PROTO((int fd, TRIO_CONST char *format, void **args)); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 133 | |
Daniel Veillard | b7c29c3 | 2002-09-25 22:44:43 +0000 | [diff] [blame] | 134 | int trio_cscanf TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure, |
| 135 | TRIO_CONST char *format, ...)); |
| 136 | int trio_vcscanf TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure, |
| 137 | TRIO_CONST char *format, va_list args)); |
| 138 | int trio_cscanfv TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure, |
| 139 | TRIO_CONST char *format, void **args)); |
| 140 | |
| 141 | int trio_sscanf TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, ...)); |
| 142 | int trio_vsscanf TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, va_list args)); |
| 143 | int trio_sscanfv TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, void **args)); |
| 144 | |
| 145 | /************************************************************************* |
| 146 | * Locale Functions |
| 147 | */ |
| 148 | void trio_locale_set_decimal_point TRIO_PROTO((char *decimalPoint)); |
| 149 | void trio_locale_set_thousand_separator TRIO_PROTO((char *thousandSeparator)); |
| 150 | void trio_locale_set_grouping TRIO_PROTO((char *grouping)); |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 151 | |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 152 | /************************************************************************* |
| 153 | * Renaming |
| 154 | */ |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 155 | #ifdef TRIO_REPLACE_STDIO |
| 156 | /* Replace the <stdio.h> functions */ |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 157 | #ifndef HAVE_PRINTF |
| 158 | # define printf trio_printf |
| 159 | #endif |
| 160 | #ifndef HAVE_VPRINTF |
| 161 | # define vprintf trio_vprintf |
| 162 | #endif |
| 163 | #ifndef HAVE_FPRINTF |
| 164 | # define fprintf trio_fprintf |
| 165 | #endif |
| 166 | #ifndef HAVE_VFPRINTF |
| 167 | # define vfprintf trio_vfprintf |
| 168 | #endif |
| 169 | #ifndef HAVE_SPRINTF |
| 170 | # define sprintf trio_sprintf |
| 171 | #endif |
| 172 | #ifndef HAVE_VSPRINTF |
| 173 | # define vsprintf trio_vsprintf |
| 174 | #endif |
| 175 | #ifndef HAVE_SNPRINTF |
| 176 | # define snprintf trio_snprintf |
| 177 | #endif |
| 178 | #ifndef HAVE_VSNPRINTF |
| 179 | # define vsnprintf trio_vsnprintf |
| 180 | #endif |
| 181 | #ifndef HAVE_SCANF |
| 182 | # define scanf trio_scanf |
| 183 | #endif |
| 184 | #ifndef HAVE_VSCANF |
| 185 | # define vscanf trio_vscanf |
| 186 | #endif |
| 187 | #ifndef HAVE_FSCANF |
| 188 | # define fscanf trio_fscanf |
| 189 | #endif |
| 190 | #ifndef HAVE_VFSCANF |
| 191 | # define vfscanf trio_vfscanf |
| 192 | #endif |
| 193 | #ifndef HAVE_SSCANF |
| 194 | # define sscanf trio_sscanf |
| 195 | #endif |
| 196 | #ifndef HAVE_VSSCANF |
| 197 | # define vsscanf trio_vsscanf |
| 198 | #endif |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 199 | /* These aren't stdio functions, but we make them look similar */ |
| 200 | #define dprintf trio_dprintf |
| 201 | #define vdprintf trio_vdprintf |
| 202 | #define aprintf trio_aprintf |
| 203 | #define vaprintf trio_vaprintf |
| 204 | #define asprintf trio_asprintf |
| 205 | #define vasprintf trio_vasprintf |
| 206 | #define dscanf trio_dscanf |
| 207 | #define vdscanf trio_vdscanf |
| 208 | #endif |
| 209 | |
Bjorn Reese | 906ec8a | 2001-06-05 12:46:33 +0000 | [diff] [blame] | 210 | #ifdef __cplusplus |
| 211 | } /* extern "C" */ |
| 212 | #endif |
| 213 | |
| 214 | #endif /* WITHOUT_TRIO */ |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 215 | |
| 216 | #endif /* TRIO_TRIO_H */ |