blob: 14f2f52b0dd53f55d66f3da6dab04f2d6f4443f0 [file] [log] [blame]
Daniel Veillard92ad2102001-03-27 12:47:33 +00001/*************************************************************************
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 Reese70a9da52001-04-21 16:57:29 +000018#ifndef TRIO_TRIO_H
19#define TRIO_TRIO_H
Daniel Veillard92ad2102001-03-27 12:47:33 +000020
21#include <stdio.h>
22#include <stdarg.h>
23#include <stdlib.h>
24
25/*
Bjorn Reese70a9da52001-04-21 16:57:29 +000026 * 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 Reese906ec8a2001-06-05 12:46:33 +000035#ifdef __cplusplus
36extern "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 Reese70a9da52001-04-21 16:57:29 +000044/*
Daniel Veillard92ad2102001-03-27 12:47:33 +000045 * Error codes.
46 *
47 * Remember to add a textual description to trio_strerror.
48 */
49enum {
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 Reese906ec8a2001-06-05 12:46:33 +000056 TRIO_ERANGE = 7
Daniel Veillard92ad2102001-03-27 12:47:33 +000057};
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 Reese70a9da52001-04-21 16:57:29 +000064const char *trio_strerror(int);
65
66/*************************************************************************
67 * Print Functions
68 */
69
70int trio_printf(const char *format, ...);
71int trio_vprintf(const char *format, va_list args);
72int trio_printfv(const char *format, void **args);
73
74int trio_fprintf(FILE *file, const char *format, ...);
75int trio_vfprintf(FILE *file, const char *format, va_list args);
76int trio_fprintfv(FILE *file, const char *format, void **args);
77
78int trio_dprintf(int fd, const char *format, ...);
79int trio_vdprintf(int fd, const char *format, va_list args);
80int trio_dprintfv(int fd, const char *format, void **args);
81
82/* trio_sprintf(target, format, ...)
Daniel Veillard92ad2102001-03-27 12:47:33 +000083 * 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 Veillard92ad2102001-03-27 12:47:33 +000089int trio_sprintf(char *buffer, const char *format, ...);
Daniel Veillard92ad2102001-03-27 12:47:33 +000090int trio_vsprintf(char *buffer, const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +000091int trio_sprintfv(char *buffer, const char *format, void **args);
92
93int trio_snprintf(char *buffer, size_t max, const char *format, ...);
Daniel Veillard92ad2102001-03-27 12:47:33 +000094int trio_vsnprintf(char *buffer, size_t bufferSize, const char *format,
95 va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +000096int trio_snprintfv(char *buffer, size_t bufferSize, const char *format,
97 void **args);
98
99int trio_snprintfcat(char *buffer, size_t max, const char *format, ...);
Daniel Veillard92ad2102001-03-27 12:47:33 +0000100int trio_vsnprintfcat(char *buffer, size_t bufferSize, const char *format,
101 va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +0000102
Daniel Veillard92ad2102001-03-27 12:47:33 +0000103char *trio_aprintf(const char *format, ...);
104char *trio_vaprintf(const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +0000105
Daniel Veillard92ad2102001-03-27 12:47:33 +0000106int trio_asprintf(char **ret, const char *format, ...);
107int trio_vasprintf(char **ret, const char *format, va_list args);
108
Bjorn Reese70a9da52001-04-21 16:57:29 +0000109/*************************************************************************
110 * Scan Functions
111 */
Daniel Veillard92ad2102001-03-27 12:47:33 +0000112int trio_scanf(const char *format, ...);
113int trio_vscanf(const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +0000114int trio_scanfv(const char *format, void **args);
115
Daniel Veillard92ad2102001-03-27 12:47:33 +0000116int trio_fscanf(FILE *file, const char *format, ...);
117int trio_vfscanf(FILE *file, const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +0000118int trio_fscanfv(FILE *file, const char *format, void **args);
119
Daniel Veillard92ad2102001-03-27 12:47:33 +0000120int trio_dscanf(int fd, const char *format, ...);
121int trio_vdscanf(int fd, const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +0000122int trio_dscanfv(int fd, const char *format, void **args);
123
Daniel Veillard92ad2102001-03-27 12:47:33 +0000124int trio_sscanf(const char *buffer, const char *format, ...);
125int trio_vsscanf(const char *buffer, const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +0000126int trio_sscanfv(const char *buffer, const char *format, void **args);
Daniel Veillard92ad2102001-03-27 12:47:33 +0000127
Bjorn Reese70a9da52001-04-21 16:57:29 +0000128/*************************************************************************
129 * Renaming
130 */
Daniel Veillard92ad2102001-03-27 12:47:33 +0000131#ifdef TRIO_REPLACE_STDIO
132/* Replace the <stdio.h> functions */
Bjorn Reese70a9da52001-04-21 16:57:29 +0000133#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 Veillard92ad2102001-03-27 12:47:33 +0000175/* 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 Reese70a9da52001-04-21 16:57:29 +0000187#define StrScan trio_sscanf
Daniel Veillard92ad2102001-03-27 12:47:33 +0000188#define StrFormat trio_sprintf
189#define StrFormatMax trio_snprintf
190#define StrFormatAlloc trio_aprintf
191#define StrFormatAppendMax trio_snprintfcat
192
Bjorn Reese906ec8a2001-06-05 12:46:33 +0000193#ifdef __cplusplus
194} /* extern "C" */
195#endif
196
197#endif /* WITHOUT_TRIO */
Bjorn Reese70a9da52001-04-21 16:57:29 +0000198
199#endif /* TRIO_TRIO_H */