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