printf.h revision 154815
1153486Sphk/*-
2153486Sphk * Copyright (c) 2005 Poul-Henning Kamp
3153486Sphk * All rights reserved.
4153486Sphk *
5153486Sphk * Redistribution and use in source and binary forms, with or without
6153486Sphk * modification, are permitted provided that the following conditions
7153486Sphk * are met:
8153486Sphk * 1. Redistributions of source code must retain the above copyright
9153486Sphk *    notice, this list of conditions and the following disclaimer.
10153486Sphk * 2. Redistributions in binary form must reproduce the above copyright
11153486Sphk *    notice, this list of conditions and the following disclaimer in the
12153486Sphk *    documentation and/or other materials provided with the distribution.
13153486Sphk *
14153486Sphk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15153486Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16153486Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17153486Sphk * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18153486Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19153486Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20153486Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21153486Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22153486Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23153486Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24153486Sphk * SUCH DAMAGE.
25153486Sphk *
26153486Sphk * $FreeBSD: head/include/printf.h 154815 2006-01-25 12:45:24Z phk $
27153486Sphk */
28153486Sphk
29153486Sphk#ifndef _PRINTF_H_
30153486Sphk#define _PRINTF_H_
31153486Sphk
32153486Sphkunion arg;
33153486Sphk
34153486Sphk/*
35153486Sphk * The API defined by glibc allows a renderer to take multiple arguments
36153486Sphk * This is obviously usable for things like (ptr+len) pairs etc.
37153486Sphk * But the do not actually provide support for it at the end of the day,
38153486Sphk * they offer only one argument to the arginfo function, but do accept
39153486Sphk * >1 returns, although the do not check the types of those arguments
40153486Sphk * argument
41153486Sphk * Be compatible for now.
42153486Sphk */
43153486Sphk#define __PRINTFMAXARG		2
44153486Sphk
45153486Sphkstruct printf_info {
46153486Sphk	/* GLIBC compatible */
47153486Sphk	int		prec;
48153486Sphk	int		width;
49153486Sphk	wchar_t		spec;
50153486Sphk	unsigned 	is_long_double;
51153486Sphk	unsigned 	is_char;
52153486Sphk	unsigned	is_short;
53153486Sphk	unsigned	is_long;
54153486Sphk	unsigned	alt;
55153486Sphk	unsigned	space;
56153486Sphk	unsigned	left;
57153486Sphk	unsigned	showsign;
58153486Sphk	unsigned	group;
59153486Sphk	unsigned	extra;
60153486Sphk	unsigned	wide;
61153486Sphk	wchar_t		pad;
62153486Sphk
63153486Sphk	/* FreeBSD extensions */
64153486Sphk
65153486Sphk	unsigned	is_quad;
66153486Sphk	unsigned	is_intmax;
67153486Sphk	unsigned	is_ptrdiff;
68153486Sphk	unsigned	is_size;
69153486Sphk
70153486Sphk	/* private */
71153486Sphk	int		sofar;
72153486Sphk	unsigned	get_width;
73153486Sphk	unsigned	get_prec;
74153486Sphk	const char	*begin;
75153486Sphk	const char	*end;
76153486Sphk	void 		*arg[__PRINTFMAXARG];
77153486Sphk};
78153486Sphk
79153486Sphkenum {
80153486Sphk	PA_INT		= (1 << 0),	/* int */
81153486Sphk	PA_CHAR		= (1 << 1),	/* int, cast to char */
82153486Sphk	PA_WCHAR	= (1 << 2),	/* wide char */
83153486Sphk	PA_STRING	= (1 << 3),	/* const char * (with '\0') */
84153486Sphk	PA_WSTRING	= (1 << 4),	/* const wchar_t * */
85153486Sphk	PA_POINTER	= (1 << 5),	/* void * */
86153486Sphk	PA_FLOAT	= (1 << 6),	/* float */
87153486Sphk	PA_DOUBLE	= (1 << 7) 	/* double */
88153486Sphk};
89153486Sphk
90153486Sphk#define	PA_FLAG_MASK		0xff0000
91153486Sphk#define	PA_FLAG_LONG_LONG	(1 << 16)
92153486Sphk#define	PA_FLAG_LONG		(1 << 17)
93153486Sphk#define	PA_FLAG_SHORT		(1 << 18)
94153486Sphk#define	PA_FLAG_PTR		(1 << 19)
95153486Sphk#define	PA_FLAG_QUAD		(1 << 20)
96153486Sphk#define	PA_FLAG_INTMAX		(1 << 21)
97153486Sphk#define	PA_FLAG_SIZE		(1 << 22)
98153486Sphk#define	PA_FLAG_PTRDIFF		(1 << 23)
99153486Sphk#define	PA_FLAG_LONG_DOUBLE	PA_FLAG_LONG_LONG
100153486Sphk
101153486Sphktypedef int printf_arginfo_function(const struct printf_info *, size_t, int *);
102153486Sphktypedef int printf_function(FILE *, const struct printf_info *, const void *const *);
103153486Sphk
104153486Sphk/* FreeBSD extension */
105153486Sphkstruct __printf_io;
106153486Sphktypedef int printf_render(struct __printf_io *, const struct printf_info *, const void *const *);
107153486Sphk
108153486Sphk/* vprintf.c */
109153486Sphkextern const char __lowercase_hex[17];
110153486Sphkextern const char __uppercase_hex[17];
111153486Sphk
112153486Sphkvoid __printf_flush(struct __printf_io *io);
113153486Sphkint __printf_puts(struct __printf_io *io, const void *ptr, int len);
114153486Sphkint __printf_pad(struct __printf_io *io, int n, int zero);
115153486Sphkint __printf_out(struct __printf_io *io, const struct printf_info *pi, const void *ptr, int len);
116153486Sphk
117153486Sphkint __xvprintf(FILE *fp, const char *fmt0, va_list ap);
118153486Sphkextern int __use_xprintf;
119153486Sphk
120153486Sphk/* GLIBC compat */
121153486Sphkint register_printf_function(int spec, printf_function *render, printf_arginfo_function *arginfo);
122153486Sphk
123153486Sphk/* FreeBSD */
124153486Sphkint register_printf_render(int spec, printf_render *render, printf_arginfo_function *arginfo);
125153486Sphkint register_printf_render_std(const unsigned char *specs);
126153486Sphk
127154815Sphk/* vprintf_errno.c */
128154815Sphkprintf_arginfo_function		__printf_arginfo_errno;
129154815Sphkprintf_render			__printf_render_errno;
130154815Sphk
131153486Sphk/* vprintf_float.c */
132153486Sphkprintf_arginfo_function		__printf_arginfo_float;
133153486Sphkprintf_render			__printf_render_float;
134153486Sphk
135154815Sphk/* vprintf_hexdump.c */
136154815Sphkprintf_arginfo_function		__printf_arginfo_hexdump;
137154815Sphkprintf_render 			__printf_render_hexdump;
138154815Sphk
139153486Sphk/* vprintf_int.c */
140153486Sphkprintf_arginfo_function		__printf_arginfo_ptr;
141153486Sphkprintf_arginfo_function		__printf_arginfo_int;
142153486Sphkprintf_render			__printf_render_ptr;
143153486Sphkprintf_render			__printf_render_int;
144153486Sphk
145154815Sphk/* vprintf_quoute.c */
146154815Sphkprintf_arginfo_function		__printf_arginfo_quote;
147154815Sphkprintf_render 			__printf_render_quote;
148154815Sphk
149153486Sphk/* vprintf_str.c */
150153486Sphkprintf_arginfo_function		__printf_arginfo_chr;
151153486Sphkprintf_render			__printf_render_chr;
152153486Sphkprintf_arginfo_function		__printf_arginfo_str;
153153486Sphkprintf_render			__printf_render_str;
154153486Sphk
155153486Sphk/* vprintf_time.c */
156153486Sphkprintf_arginfo_function		__printf_arginfo_time;
157153486Sphkprintf_render			__printf_render_time;
158153486Sphk
159153486Sphk/* vprintf_vis.c */
160153486Sphkprintf_arginfo_function		__printf_arginfo_vis;
161153486Sphkprintf_render 			__printf_render_vis;
162153486Sphk
163153486Sphk#endif /* !_PRINTF_H */
164