printf.h revision 154815
151974Smsmith/*-
265245Smsmith * Copyright (c) 2005 Poul-Henning Kamp
365245Smsmith * All rights reserved.
451974Smsmith *
551974Smsmith * Redistribution and use in source and binary forms, with or without
651974Smsmith * modification, are permitted provided that the following conditions
751974Smsmith * are met:
851974Smsmith * 1. Redistributions of source code must retain the above copyright
951974Smsmith *    notice, this list of conditions and the following disclaimer.
1051974Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1151974Smsmith *    notice, this list of conditions and the following disclaimer in the
1251974Smsmith *    documentation and/or other materials provided with the distribution.
1351974Smsmith *
1451974Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1551974Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1651974Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1751974Smsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1851974Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1951974Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2051974Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2151974Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2251974Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2351974Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2451974Smsmith * SUCH DAMAGE.
2551974Smsmith *
26119418Sobrien * $FreeBSD: head/include/printf.h 154815 2006-01-25 12:45:24Z phk $
27119418Sobrien */
28106225Semoore
29106225Semoore#ifndef _PRINTF_H_
30106225Semoore#define _PRINTF_H_
31106225Semoore
32106225Semooreunion arg;
33106225Semoore
34106225Semoore/*
35106225Semoore * The API defined by glibc allows a renderer to take multiple arguments
36106225Semoore * This is obviously usable for things like (ptr+len) pairs etc.
37106225Semoore * But the do not actually provide support for it at the end of the day,
38106225Semoore * they offer only one argument to the arginfo function, but do accept
39106225Semoore * >1 returns, although the do not check the types of those arguments
40105419Semoore * argument
41106225Semoore * Be compatible for now.
42105419Semoore */
43105419Semoore#define __PRINTFMAXARG		2
44106225Semoore
45106225Semoorestruct printf_info {
46106225Semoore	/* GLIBC compatible */
47106225Semoore	int		prec;
48106225Semoore	int		width;
49106225Semoore	wchar_t		spec;
50106225Semoore	unsigned 	is_long_double;
51106225Semoore	unsigned 	is_char;
52106225Semoore	unsigned	is_short;
53106225Semoore	unsigned	is_long;
54106225Semoore	unsigned	alt;
5551974Smsmith	unsigned	space;
5651974Smsmith	unsigned	left;
57119418Sobrien	unsigned	showsign;
58119418Sobrien	unsigned	group;
59119418Sobrien	unsigned	extra;
6051974Smsmith	unsigned	wide;
6165245Smsmith	wchar_t		pad;
6251974Smsmith
6351974Smsmith	/* FreeBSD extensions */
6451974Smsmith
6551974Smsmith	unsigned	is_quad;
6651974Smsmith	unsigned	is_intmax;
6751974Smsmith	unsigned	is_ptrdiff;
6851974Smsmith	unsigned	is_size;
6965245Smsmith
7051974Smsmith	/* private */
7151974Smsmith	int		sofar;
7265245Smsmith	unsigned	get_width;
7351974Smsmith	unsigned	get_prec;
7465245Smsmith	const char	*begin;
7565245Smsmith	const char	*end;
7665245Smsmith	void 		*arg[__PRINTFMAXARG];
7751974Smsmith};
7851974Smsmith
7951974Smsmithenum {
80119277Simp	PA_INT		= (1 << 0),	/* int */
81119277Simp	PA_CHAR		= (1 << 1),	/* int, cast to char */
8265245Smsmith	PA_WCHAR	= (1 << 2),	/* wide char */
8351974Smsmith	PA_STRING	= (1 << 3),	/* const char * (with '\0') */
8451974Smsmith	PA_WSTRING	= (1 << 4),	/* const wchar_t * */
8551974Smsmith	PA_POINTER	= (1 << 5),	/* void * */
8665245Smsmith	PA_FLOAT	= (1 << 6),	/* float */
8765245Smsmith	PA_DOUBLE	= (1 << 7) 	/* double */
8851974Smsmith};
8951974Smsmith
9051974Smsmith#define	PA_FLAG_MASK		0xff0000
9165245Smsmith#define	PA_FLAG_LONG_LONG	(1 << 16)
9265245Smsmith#define	PA_FLAG_LONG		(1 << 17)
9365245Smsmith#define	PA_FLAG_SHORT		(1 << 18)
9465245Smsmith#define	PA_FLAG_PTR		(1 << 19)
9551974Smsmith#define	PA_FLAG_QUAD		(1 << 20)
96111815Sphk#define	PA_FLAG_INTMAX		(1 << 21)
97111815Sphk#define	PA_FLAG_SIZE		(1 << 22)
98111815Sphk#define	PA_FLAG_PTRDIFF		(1 << 23)
99111815Sphk#define	PA_FLAG_LONG_DOUBLE	PA_FLAG_LONG_LONG
100111815Sphk
10151974Smsmithtypedef int printf_arginfo_function(const struct printf_info *, size_t, int *);
10251974Smsmithtypedef int printf_function(FILE *, const struct printf_info *, const void *const *);
10365245Smsmith
10465245Smsmith/* FreeBSD extension */
10565245Smsmithstruct __printf_io;
10665245Smsmithtypedef int printf_render(struct __printf_io *, const struct printf_info *, const void *const *);
10751974Smsmith
10851974Smsmith/* vprintf.c */
10951974Smsmithextern const char __lowercase_hex[17];
11051974Smsmithextern const char __uppercase_hex[17];
11165245Smsmith
11265245Smsmithvoid __printf_flush(struct __printf_io *io);
11365245Smsmithint __printf_puts(struct __printf_io *io, const void *ptr, int len);
11465245Smsmithint __printf_pad(struct __printf_io *io, int n, int zero);
115106225Semooreint __printf_out(struct __printf_io *io, const struct printf_info *pi, const void *ptr, int len);
11651974Smsmith
11751974Smsmithint __xvprintf(FILE *fp, const char *fmt0, va_list ap);
11865245Smsmithextern int __use_xprintf;
11951974Smsmith
12065245Smsmith/* GLIBC compat */
12165245Smsmithint register_printf_function(int spec, printf_function *render, printf_arginfo_function *arginfo);
12251974Smsmith
12351974Smsmith/* FreeBSD */
12465245Smsmithint register_printf_render(int spec, printf_render *render, printf_arginfo_function *arginfo);
12551974Smsmithint register_printf_render_std(const unsigned char *specs);
12665245Smsmith
12765245Smsmith/* vprintf_errno.c */
12865245Smsmithprintf_arginfo_function		__printf_arginfo_errno;
12965245Smsmithprintf_render			__printf_render_errno;
13065245Smsmith
13165245Smsmith/* vprintf_float.c */
13265245Smsmithprintf_arginfo_function		__printf_arginfo_float;
13351974Smsmithprintf_render			__printf_render_float;
13451974Smsmith
13558883Smsmith/* vprintf_hexdump.c */
13658883Smsmithprintf_arginfo_function		__printf_arginfo_hexdump;
13765245Smsmithprintf_render 			__printf_render_hexdump;
13858883Smsmith
13958883Smsmith/* vprintf_int.c */
14051974Smsmithprintf_arginfo_function		__printf_arginfo_ptr;
14151974Smsmithprintf_arginfo_function		__printf_arginfo_int;
14265245Smsmithprintf_render			__printf_render_ptr;
14365245Smsmithprintf_render			__printf_render_int;
144107756Semoore
14551974Smsmith/* vprintf_quoute.c */
14665245Smsmithprintf_arginfo_function		__printf_arginfo_quote;
14765245Smsmithprintf_render 			__printf_render_quote;
148107756Semoore
14965245Smsmith/* vprintf_str.c */
15051974Smsmithprintf_arginfo_function		__printf_arginfo_chr;
15165245Smsmithprintf_render			__printf_render_chr;
15265245Smsmithprintf_arginfo_function		__printf_arginfo_str;
15365245Smsmithprintf_render			__printf_render_str;
15465245Smsmith
15565245Smsmith/* vprintf_time.c */
15651974Smsmithprintf_arginfo_function		__printf_arginfo_time;
15751974Smsmithprintf_render			__printf_render_time;
15851974Smsmith
15965245Smsmith/* vprintf_vis.c */
16065245Smsmithprintf_arginfo_function		__printf_arginfo_vis;
161107756Semooreprintf_render 			__printf_render_vis;
16265245Smsmith
16365245Smsmith#endif /* !_PRINTF_H */
164107756Semoore