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 | |
| 25 | #include <stdio.h> |
| 26 | #include <stdarg.h> |
| 27 | #include <stdlib.h> |
| 28 | |
| 29 | /* |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 30 | * Use autoconf defines if present. Packages using trio must define |
| 31 | * HAVE_CONFIG_H as a compiler option themselves. |
| 32 | */ |
| 33 | #if defined(HAVE_CONFIG_H) |
| 34 | # include <config.h> |
| 35 | #endif |
| 36 | |
| 37 | #if !defined(WITHOUT_TRIO) |
| 38 | |
Bjorn Reese | 906ec8a | 2001-06-05 12:46:33 +0000 | [diff] [blame] | 39 | #ifdef __cplusplus |
| 40 | extern "C" { |
| 41 | #endif |
| 42 | |
| 43 | /* make utility and C++ compiler in Windows NT fails to find this symbol */ |
| 44 | #if defined(WIN32) && !defined(isascii) |
| 45 | # define isascii ((unsigned)(x) < 0x80) |
| 46 | #endif |
| 47 | |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 48 | /* Error macros */ |
| 49 | #define TRIO_ERROR_CODE(x) ((-(x)) & 0x00FF) |
| 50 | #define TRIO_ERROR_POSITION(x) ((-(x)) >> 8) |
| 51 | #define TRIO_ERROR_NAME(x) trio_strerror(x) |
| 52 | |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 53 | /* |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 54 | * Error codes. |
| 55 | * |
| 56 | * Remember to add a textual description to trio_strerror. |
| 57 | */ |
| 58 | enum { |
| 59 | TRIO_EOF = 1, |
| 60 | TRIO_EINVAL = 2, |
| 61 | TRIO_ETOOMANY = 3, |
| 62 | TRIO_EDBLREF = 4, |
| 63 | TRIO_EGAP = 5, |
| 64 | TRIO_ENOMEM = 6, |
Bjorn Reese | 026d29f | 2002-01-19 15:40:18 +0000 | [diff] [blame] | 65 | TRIO_ERANGE = 7, |
| 66 | TRIO_ERRNO = 8 |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 69 | const char *trio_strerror(int); |
| 70 | |
| 71 | /************************************************************************* |
| 72 | * Print Functions |
| 73 | */ |
| 74 | |
| 75 | int trio_printf(const char *format, ...); |
| 76 | int trio_vprintf(const char *format, va_list args); |
| 77 | int trio_printfv(const char *format, void **args); |
| 78 | |
| 79 | int trio_fprintf(FILE *file, const char *format, ...); |
| 80 | int trio_vfprintf(FILE *file, const char *format, va_list args); |
| 81 | int trio_fprintfv(FILE *file, const char *format, void **args); |
| 82 | |
| 83 | int trio_dprintf(int fd, const char *format, ...); |
| 84 | int trio_vdprintf(int fd, const char *format, va_list args); |
| 85 | int trio_dprintfv(int fd, const char *format, void **args); |
| 86 | |
| 87 | /* trio_sprintf(target, format, ...) |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 88 | * trio_snprintf(target, maxsize, format, ...) |
| 89 | * |
| 90 | * Build 'target' according to 'format' and succesive |
| 91 | * arguments. This is equal to the sprintf() and |
| 92 | * snprintf() functions. |
| 93 | */ |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 94 | int trio_sprintf(char *buffer, const char *format, ...); |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 95 | int trio_vsprintf(char *buffer, const char *format, va_list args); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 96 | int trio_sprintfv(char *buffer, const char *format, void **args); |
| 97 | |
| 98 | int trio_snprintf(char *buffer, size_t max, const char *format, ...); |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 99 | int trio_vsnprintf(char *buffer, size_t bufferSize, const char *format, |
| 100 | va_list args); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 101 | int trio_snprintfv(char *buffer, size_t bufferSize, const char *format, |
| 102 | void **args); |
| 103 | |
| 104 | int trio_snprintfcat(char *buffer, size_t max, const char *format, ...); |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 105 | int trio_vsnprintfcat(char *buffer, size_t bufferSize, const char *format, |
| 106 | va_list args); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 107 | |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 108 | char *trio_aprintf(const char *format, ...); |
| 109 | char *trio_vaprintf(const char *format, va_list args); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 110 | |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 111 | int trio_asprintf(char **ret, const char *format, ...); |
| 112 | int trio_vasprintf(char **ret, const char *format, va_list args); |
| 113 | |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 114 | /************************************************************************* |
| 115 | * Scan Functions |
| 116 | */ |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 117 | int trio_scanf(const char *format, ...); |
| 118 | int trio_vscanf(const char *format, va_list args); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 119 | int trio_scanfv(const char *format, void **args); |
| 120 | |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 121 | int trio_fscanf(FILE *file, const char *format, ...); |
| 122 | int trio_vfscanf(FILE *file, const char *format, va_list args); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 123 | int trio_fscanfv(FILE *file, const char *format, void **args); |
| 124 | |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 125 | int trio_dscanf(int fd, const char *format, ...); |
| 126 | int trio_vdscanf(int fd, const char *format, va_list args); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 127 | int trio_dscanfv(int fd, const char *format, void **args); |
| 128 | |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 129 | int trio_sscanf(const char *buffer, const char *format, ...); |
| 130 | int trio_vsscanf(const char *buffer, const char *format, va_list args); |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 131 | int trio_sscanfv(const char *buffer, const char *format, void **args); |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 132 | |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 133 | /************************************************************************* |
| 134 | * Renaming |
| 135 | */ |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 136 | #ifdef TRIO_REPLACE_STDIO |
| 137 | /* Replace the <stdio.h> functions */ |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 138 | #ifndef HAVE_PRINTF |
| 139 | # define printf trio_printf |
| 140 | #endif |
| 141 | #ifndef HAVE_VPRINTF |
| 142 | # define vprintf trio_vprintf |
| 143 | #endif |
| 144 | #ifndef HAVE_FPRINTF |
| 145 | # define fprintf trio_fprintf |
| 146 | #endif |
| 147 | #ifndef HAVE_VFPRINTF |
| 148 | # define vfprintf trio_vfprintf |
| 149 | #endif |
| 150 | #ifndef HAVE_SPRINTF |
| 151 | # define sprintf trio_sprintf |
| 152 | #endif |
| 153 | #ifndef HAVE_VSPRINTF |
| 154 | # define vsprintf trio_vsprintf |
| 155 | #endif |
| 156 | #ifndef HAVE_SNPRINTF |
| 157 | # define snprintf trio_snprintf |
| 158 | #endif |
| 159 | #ifndef HAVE_VSNPRINTF |
| 160 | # define vsnprintf trio_vsnprintf |
| 161 | #endif |
| 162 | #ifndef HAVE_SCANF |
| 163 | # define scanf trio_scanf |
| 164 | #endif |
| 165 | #ifndef HAVE_VSCANF |
| 166 | # define vscanf trio_vscanf |
| 167 | #endif |
| 168 | #ifndef HAVE_FSCANF |
| 169 | # define fscanf trio_fscanf |
| 170 | #endif |
| 171 | #ifndef HAVE_VFSCANF |
| 172 | # define vfscanf trio_vfscanf |
| 173 | #endif |
| 174 | #ifndef HAVE_SSCANF |
| 175 | # define sscanf trio_sscanf |
| 176 | #endif |
| 177 | #ifndef HAVE_VSSCANF |
| 178 | # define vsscanf trio_vsscanf |
| 179 | #endif |
Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame] | 180 | /* These aren't stdio functions, but we make them look similar */ |
| 181 | #define dprintf trio_dprintf |
| 182 | #define vdprintf trio_vdprintf |
| 183 | #define aprintf trio_aprintf |
| 184 | #define vaprintf trio_vaprintf |
| 185 | #define asprintf trio_asprintf |
| 186 | #define vasprintf trio_vasprintf |
| 187 | #define dscanf trio_dscanf |
| 188 | #define vdscanf trio_vdscanf |
| 189 | #endif |
| 190 | |
Bjorn Reese | 906ec8a | 2001-06-05 12:46:33 +0000 | [diff] [blame] | 191 | #ifdef __cplusplus |
| 192 | } /* extern "C" */ |
| 193 | #endif |
| 194 | |
| 195 | #endif /* WITHOUT_TRIO */ |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 196 | |
| 197 | #endif /* TRIO_TRIO_H */ |