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