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