printf.h revision 154815
1/*-
2 * Copyright (c) 2005 Poul-Henning Kamp
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/include/printf.h 154815 2006-01-25 12:45:24Z phk $
27 */
28
29#ifndef _PRINTF_H_
30#define _PRINTF_H_
31
32union arg;
33
34/*
35 * The API defined by glibc allows a renderer to take multiple arguments
36 * This is obviously usable for things like (ptr+len) pairs etc.
37 * But the do not actually provide support for it at the end of the day,
38 * they offer only one argument to the arginfo function, but do accept
39 * >1 returns, although the do not check the types of those arguments
40 * argument
41 * Be compatible for now.
42 */
43#define __PRINTFMAXARG		2
44
45struct printf_info {
46	/* GLIBC compatible */
47	int		prec;
48	int		width;
49	wchar_t		spec;
50	unsigned 	is_long_double;
51	unsigned 	is_char;
52	unsigned	is_short;
53	unsigned	is_long;
54	unsigned	alt;
55	unsigned	space;
56	unsigned	left;
57	unsigned	showsign;
58	unsigned	group;
59	unsigned	extra;
60	unsigned	wide;
61	wchar_t		pad;
62
63	/* FreeBSD extensions */
64
65	unsigned	is_quad;
66	unsigned	is_intmax;
67	unsigned	is_ptrdiff;
68	unsigned	is_size;
69
70	/* private */
71	int		sofar;
72	unsigned	get_width;
73	unsigned	get_prec;
74	const char	*begin;
75	const char	*end;
76	void 		*arg[__PRINTFMAXARG];
77};
78
79enum {
80	PA_INT		= (1 << 0),	/* int */
81	PA_CHAR		= (1 << 1),	/* int, cast to char */
82	PA_WCHAR	= (1 << 2),	/* wide char */
83	PA_STRING	= (1 << 3),	/* const char * (with '\0') */
84	PA_WSTRING	= (1 << 4),	/* const wchar_t * */
85	PA_POINTER	= (1 << 5),	/* void * */
86	PA_FLOAT	= (1 << 6),	/* float */
87	PA_DOUBLE	= (1 << 7) 	/* double */
88};
89
90#define	PA_FLAG_MASK		0xff0000
91#define	PA_FLAG_LONG_LONG	(1 << 16)
92#define	PA_FLAG_LONG		(1 << 17)
93#define	PA_FLAG_SHORT		(1 << 18)
94#define	PA_FLAG_PTR		(1 << 19)
95#define	PA_FLAG_QUAD		(1 << 20)
96#define	PA_FLAG_INTMAX		(1 << 21)
97#define	PA_FLAG_SIZE		(1 << 22)
98#define	PA_FLAG_PTRDIFF		(1 << 23)
99#define	PA_FLAG_LONG_DOUBLE	PA_FLAG_LONG_LONG
100
101typedef int printf_arginfo_function(const struct printf_info *, size_t, int *);
102typedef int printf_function(FILE *, const struct printf_info *, const void *const *);
103
104/* FreeBSD extension */
105struct __printf_io;
106typedef int printf_render(struct __printf_io *, const struct printf_info *, const void *const *);
107
108/* vprintf.c */
109extern const char __lowercase_hex[17];
110extern const char __uppercase_hex[17];
111
112void __printf_flush(struct __printf_io *io);
113int __printf_puts(struct __printf_io *io, const void *ptr, int len);
114int __printf_pad(struct __printf_io *io, int n, int zero);
115int __printf_out(struct __printf_io *io, const struct printf_info *pi, const void *ptr, int len);
116
117int __xvprintf(FILE *fp, const char *fmt0, va_list ap);
118extern int __use_xprintf;
119
120/* GLIBC compat */
121int register_printf_function(int spec, printf_function *render, printf_arginfo_function *arginfo);
122
123/* FreeBSD */
124int register_printf_render(int spec, printf_render *render, printf_arginfo_function *arginfo);
125int register_printf_render_std(const unsigned char *specs);
126
127/* vprintf_errno.c */
128printf_arginfo_function		__printf_arginfo_errno;
129printf_render			__printf_render_errno;
130
131/* vprintf_float.c */
132printf_arginfo_function		__printf_arginfo_float;
133printf_render			__printf_render_float;
134
135/* vprintf_hexdump.c */
136printf_arginfo_function		__printf_arginfo_hexdump;
137printf_render 			__printf_render_hexdump;
138
139/* vprintf_int.c */
140printf_arginfo_function		__printf_arginfo_ptr;
141printf_arginfo_function		__printf_arginfo_int;
142printf_render			__printf_render_ptr;
143printf_render			__printf_render_int;
144
145/* vprintf_quoute.c */
146printf_arginfo_function		__printf_arginfo_quote;
147printf_render 			__printf_render_quote;
148
149/* vprintf_str.c */
150printf_arginfo_function		__printf_arginfo_chr;
151printf_render			__printf_render_chr;
152printf_arginfo_function		__printf_arginfo_str;
153printf_render			__printf_render_str;
154
155/* vprintf_time.c */
156printf_arginfo_function		__printf_arginfo_time;
157printf_render			__printf_render_time;
158
159/* vprintf_vis.c */
160printf_arginfo_function		__printf_arginfo_vis;
161printf_render 			__printf_render_vis;
162
163#endif /* !_PRINTF_H */
164