1*53ee8cc1Swenshuai.xi /* Copyright (C) 1991-1993,1995-1999,2000,2001,2006 2*53ee8cc1Swenshuai.xi Free Software Foundation, Inc. 3*53ee8cc1Swenshuai.xi This file is part of the GNU C Library. 4*53ee8cc1Swenshuai.xi 5*53ee8cc1Swenshuai.xi The GNU C Library is free software; you can redistribute it and/or 6*53ee8cc1Swenshuai.xi modify it under the terms of the GNU Lesser General Public 7*53ee8cc1Swenshuai.xi License as published by the Free Software Foundation; either 8*53ee8cc1Swenshuai.xi version 2.1 of the License, or (at your option) any later version. 9*53ee8cc1Swenshuai.xi 10*53ee8cc1Swenshuai.xi The GNU C Library is distributed in the hope that it will be useful, 11*53ee8cc1Swenshuai.xi but WITHOUT ANY WARRANTY; without even the implied warranty of 12*53ee8cc1Swenshuai.xi MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13*53ee8cc1Swenshuai.xi Lesser General Public License for more details. 14*53ee8cc1Swenshuai.xi 15*53ee8cc1Swenshuai.xi You should have received a copy of the GNU Lesser General Public 16*53ee8cc1Swenshuai.xi License along with the GNU C Library; if not, write to the Free 17*53ee8cc1Swenshuai.xi Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 18*53ee8cc1Swenshuai.xi 02111-1307 USA. */ 19*53ee8cc1Swenshuai.xi 20*53ee8cc1Swenshuai.xi #ifndef _PRINTF_H 21*53ee8cc1Swenshuai.xi 22*53ee8cc1Swenshuai.xi #define _PRINTF_H 1 23*53ee8cc1Swenshuai.xi #include <features.h> 24*53ee8cc1Swenshuai.xi 25*53ee8cc1Swenshuai.xi __BEGIN_DECLS 26*53ee8cc1Swenshuai.xi 27*53ee8cc1Swenshuai.xi #define __need_FILE 28*53ee8cc1Swenshuai.xi #include <stdio.h> 29*53ee8cc1Swenshuai.xi #define __need_size_t 30*53ee8cc1Swenshuai.xi #define __need_wchar_t 31*53ee8cc1Swenshuai.xi #include <stddef.h> 32*53ee8cc1Swenshuai.xi 33*53ee8cc1Swenshuai.xi 34*53ee8cc1Swenshuai.xi struct printf_info 35*53ee8cc1Swenshuai.xi { 36*53ee8cc1Swenshuai.xi int prec; /* Precision. */ 37*53ee8cc1Swenshuai.xi int width; /* Width. */ 38*53ee8cc1Swenshuai.xi wchar_t spec; /* Format letter. */ 39*53ee8cc1Swenshuai.xi unsigned int is_long_double:1;/* L flag. */ 40*53ee8cc1Swenshuai.xi unsigned int is_short:1; /* h flag. */ 41*53ee8cc1Swenshuai.xi unsigned int is_long:1; /* l flag. */ 42*53ee8cc1Swenshuai.xi unsigned int alt:1; /* # flag. */ 43*53ee8cc1Swenshuai.xi unsigned int space:1; /* Space flag. */ 44*53ee8cc1Swenshuai.xi unsigned int left:1; /* - flag. */ 45*53ee8cc1Swenshuai.xi unsigned int showsign:1; /* + flag. */ 46*53ee8cc1Swenshuai.xi unsigned int group:1; /* ' flag. */ 47*53ee8cc1Swenshuai.xi unsigned int extra:1; /* For special use. */ 48*53ee8cc1Swenshuai.xi unsigned int is_char:1; /* hh flag. */ 49*53ee8cc1Swenshuai.xi unsigned int wide:1; /* Nonzero for wide character streams. */ 50*53ee8cc1Swenshuai.xi unsigned int i18n:1; /* I flag. */ 51*53ee8cc1Swenshuai.xi wchar_t pad; /* Padding character. */ 52*53ee8cc1Swenshuai.xi }; 53*53ee8cc1Swenshuai.xi 54*53ee8cc1Swenshuai.xi 55*53ee8cc1Swenshuai.xi /* Type of a printf specifier-handler function. 56*53ee8cc1Swenshuai.xi STREAM is the FILE on which to write output. 57*53ee8cc1Swenshuai.xi INFO gives information about the format specification. 58*53ee8cc1Swenshuai.xi ARGS is a vector of pointers to the argument data; 59*53ee8cc1Swenshuai.xi the number of pointers will be the number returned 60*53ee8cc1Swenshuai.xi by the associated arginfo function for the same INFO. 61*53ee8cc1Swenshuai.xi 62*53ee8cc1Swenshuai.xi The function should return the number of characters written, 63*53ee8cc1Swenshuai.xi or -1 for errors. */ 64*53ee8cc1Swenshuai.xi 65*53ee8cc1Swenshuai.xi typedef int printf_function (FILE *__stream, 66*53ee8cc1Swenshuai.xi __const struct printf_info *__info, 67*53ee8cc1Swenshuai.xi __const void *__const *__args); 68*53ee8cc1Swenshuai.xi 69*53ee8cc1Swenshuai.xi /* Type of a printf specifier-arginfo function. 70*53ee8cc1Swenshuai.xi INFO gives information about the format specification. 71*53ee8cc1Swenshuai.xi N, ARGTYPES, and return value are as for parse_printf_format. */ 72*53ee8cc1Swenshuai.xi 73*53ee8cc1Swenshuai.xi typedef int printf_arginfo_function (__const struct printf_info *__info, 74*53ee8cc1Swenshuai.xi size_t __n, int *__argtypes); 75*53ee8cc1Swenshuai.xi 76*53ee8cc1Swenshuai.xi 77*53ee8cc1Swenshuai.xi /* Register FUNC to be called to format SPEC specifiers; ARGINFO must be 78*53ee8cc1Swenshuai.xi specified to determine how many arguments a SPEC conversion requires and 79*53ee8cc1Swenshuai.xi what their types are. */ 80*53ee8cc1Swenshuai.xi 81*53ee8cc1Swenshuai.xi extern int register_printf_function (int __spec, printf_function __func, 82*53ee8cc1Swenshuai.xi printf_arginfo_function __arginfo); 83*53ee8cc1Swenshuai.xi 84*53ee8cc1Swenshuai.xi 85*53ee8cc1Swenshuai.xi /* Parse FMT, and fill in N elements of ARGTYPES with the 86*53ee8cc1Swenshuai.xi types needed for the conversions FMT specifies. Returns 87*53ee8cc1Swenshuai.xi the number of arguments required by FMT. 88*53ee8cc1Swenshuai.xi 89*53ee8cc1Swenshuai.xi The ARGINFO function registered with a user-defined format is passed a 90*53ee8cc1Swenshuai.xi `struct printf_info' describing the format spec being parsed. A width 91*53ee8cc1Swenshuai.xi or precision of INT_MIN means a `*' was used to indicate that the 92*53ee8cc1Swenshuai.xi width/precision will come from an arg. The function should fill in the 93*53ee8cc1Swenshuai.xi array it is passed with the types of the arguments it wants, and return 94*53ee8cc1Swenshuai.xi the number of arguments it wants. */ 95*53ee8cc1Swenshuai.xi 96*53ee8cc1Swenshuai.xi extern size_t parse_printf_format (__const char *__restrict __fmt, size_t __n, 97*53ee8cc1Swenshuai.xi int *__restrict __argtypes) __THROW; 98*53ee8cc1Swenshuai.xi 99*53ee8cc1Swenshuai.xi 100*53ee8cc1Swenshuai.xi /* Codes returned by `parse_printf_format' for basic types. 101*53ee8cc1Swenshuai.xi 102*53ee8cc1Swenshuai.xi These values cover all the standard format specifications. 103*53ee8cc1Swenshuai.xi Users can add new values after PA_LAST for their own types. */ 104*53ee8cc1Swenshuai.xi 105*53ee8cc1Swenshuai.xi enum 106*53ee8cc1Swenshuai.xi { /* C type: */ 107*53ee8cc1Swenshuai.xi PA_INT, /* int */ 108*53ee8cc1Swenshuai.xi PA_CHAR, /* int, cast to char */ 109*53ee8cc1Swenshuai.xi PA_WCHAR, /* wide char */ 110*53ee8cc1Swenshuai.xi PA_STRING, /* const char *, a '\0'-terminated string */ 111*53ee8cc1Swenshuai.xi PA_WSTRING, /* const wchar_t *, wide character string */ 112*53ee8cc1Swenshuai.xi PA_POINTER, /* void * */ 113*53ee8cc1Swenshuai.xi PA_FLOAT, /* float */ 114*53ee8cc1Swenshuai.xi PA_DOUBLE, /* double */ 115*53ee8cc1Swenshuai.xi PA_LAST 116*53ee8cc1Swenshuai.xi }; 117*53ee8cc1Swenshuai.xi 118*53ee8cc1Swenshuai.xi /* Flag bits that can be set in a type returned by `parse_printf_format'. */ 119*53ee8cc1Swenshuai.xi #define PA_FLAG_MASK 0xff00 120*53ee8cc1Swenshuai.xi #define PA_FLAG_LONG_LONG (1 << 8) 121*53ee8cc1Swenshuai.xi #define PA_FLAG_LONG_DOUBLE PA_FLAG_LONG_LONG 122*53ee8cc1Swenshuai.xi #define PA_FLAG_LONG (1 << 9) 123*53ee8cc1Swenshuai.xi #define PA_FLAG_SHORT (1 << 10) 124*53ee8cc1Swenshuai.xi #define PA_FLAG_PTR (1 << 11) 125*53ee8cc1Swenshuai.xi 126*53ee8cc1Swenshuai.xi 127*53ee8cc1Swenshuai.xi 128*53ee8cc1Swenshuai.xi /* Function which can be registered as `printf'-handlers. */ 129*53ee8cc1Swenshuai.xi 130*53ee8cc1Swenshuai.xi /* Print floating point value using using abbreviations for the orders 131*53ee8cc1Swenshuai.xi of magnitude used for numbers ('k' for kilo, 'm' for mega etc). If 132*53ee8cc1Swenshuai.xi the format specifier is a uppercase character powers of 1000 are 133*53ee8cc1Swenshuai.xi used. Otherwise powers of 1024. */ 134*53ee8cc1Swenshuai.xi extern int printf_size (FILE *__restrict __fp, 135*53ee8cc1Swenshuai.xi __const struct printf_info *__info, 136*53ee8cc1Swenshuai.xi __const void *__const *__restrict __args) __THROW; 137*53ee8cc1Swenshuai.xi 138*53ee8cc1Swenshuai.xi /* This is the appropriate argument information function for `printf_size'. */ 139*53ee8cc1Swenshuai.xi extern int printf_size_info (__const struct printf_info *__restrict 140*53ee8cc1Swenshuai.xi __info, size_t __n, int *__restrict __argtypes) 141*53ee8cc1Swenshuai.xi __THROW; 142*53ee8cc1Swenshuai.xi 143*53ee8cc1Swenshuai.xi #ifdef __LDBL_COMPAT 144*53ee8cc1Swenshuai.xi # include <bits/printf-ldbl.h> 145*53ee8cc1Swenshuai.xi #endif 146*53ee8cc1Swenshuai.xi 147*53ee8cc1Swenshuai.xi __END_DECLS 148*53ee8cc1Swenshuai.xi 149*53ee8cc1Swenshuai.xi #endif /* printf.h */ 150