xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1 | /* Copyright (C) 1991-2016 Free Software Foundation, Inc. |
| 2 | This file is part of the GNU C Library. |
| 3 | |
| 4 | The GNU C Library is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU Lesser General Public |
| 6 | License as published by the Free Software Foundation; either |
| 7 | version 2.1 of the License, or (at your option) any later version. |
| 8 | |
| 9 | The GNU C Library is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | Lesser General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Lesser General Public |
| 15 | License along with the GNU C Library; if not, see |
| 16 | <http://www.gnu.org/licenses/>. */ |
| 17 | |
| 18 | #ifndef _PRINTF_H |
| 19 | |
| 20 | #define _PRINTF_H 1 |
| 21 | #include <features.h> |
| 22 | |
| 23 | __BEGIN_DECLS |
| 24 | |
| 25 | #define __need_FILE |
| 26 | #include <stdio.h> |
| 27 | #define __need_size_t |
| 28 | #define __need_wchar_t |
| 29 | #include <stddef.h> |
| 30 | #include <stdarg.h> |
| 31 | |
| 32 | |
| 33 | struct printf_info |
| 34 | { |
| 35 | int prec; /* Precision. */ |
| 36 | int width; /* Width. */ |
| 37 | wchar_t spec; /* Format letter. */ |
| 38 | unsigned int is_long_double:1;/* L flag. */ |
| 39 | unsigned int is_short:1; /* h flag. */ |
| 40 | unsigned int is_long:1; /* l flag. */ |
| 41 | unsigned int alt:1; /* # flag. */ |
| 42 | unsigned int space:1; /* Space flag. */ |
| 43 | unsigned int left:1; /* - flag. */ |
| 44 | unsigned int showsign:1; /* + flag. */ |
| 45 | unsigned int group:1; /* ' flag. */ |
| 46 | unsigned int extra:1; /* For special use. */ |
| 47 | unsigned int is_char:1; /* hh flag. */ |
| 48 | unsigned int wide:1; /* Nonzero for wide character streams. */ |
| 49 | unsigned int i18n:1; /* I flag. */ |
| 50 | unsigned int __pad:4; /* Unused so far. */ |
| 51 | unsigned short int user; /* Bits for user-installed modifiers. */ |
| 52 | wchar_t pad; /* Padding character. */ |
| 53 | }; |
| 54 | |
| 55 | |
| 56 | /* Type of a printf specifier-handler function. |
| 57 | STREAM is the FILE on which to write output. |
| 58 | INFO gives information about the format specification. |
| 59 | ARGS is a vector of pointers to the argument data; |
| 60 | the number of pointers will be the number returned |
| 61 | by the associated arginfo function for the same INFO. |
| 62 | |
| 63 | The function should return the number of characters written, |
| 64 | or -1 for errors. */ |
| 65 | |
| 66 | typedef int printf_function (FILE *__stream, |
| 67 | const struct printf_info *__info, |
| 68 | const void *const *__args); |
| 69 | |
| 70 | /* Type of a printf specifier-arginfo function. |
| 71 | INFO gives information about the format specification. |
| 72 | N, ARGTYPES, *SIZE has to contain the size of the parameter for |
| 73 | user-defined types, and return value are as for parse_printf_format |
| 74 | except that -1 should be returned if the handler cannot handle |
| 75 | this case. This allows to partially overwrite the functionality |
| 76 | of existing format specifiers. */ |
| 77 | |
| 78 | typedef int printf_arginfo_size_function (const struct printf_info *__info, |
| 79 | size_t __n, int *__argtypes, |
| 80 | int *__size); |
| 81 | |
| 82 | /* Old version of 'printf_arginfo_function' without a SIZE parameter. */ |
| 83 | |
| 84 | typedef int printf_arginfo_function (const struct printf_info *__info, |
| 85 | size_t __n, int *__argtypes); |
| 86 | |
| 87 | /* Type of a function to get a value of a user-defined from the |
| 88 | variable argument list. */ |
| 89 | typedef void printf_va_arg_function (void *__mem, va_list *__ap); |
| 90 | |
| 91 | |
| 92 | /* Register FUNC to be called to format SPEC specifiers; ARGINFO must be |
| 93 | specified to determine how many arguments a SPEC conversion requires and |
| 94 | what their types are. */ |
| 95 | |
| 96 | extern int register_printf_specifier (int __spec, printf_function __func, |
| 97 | printf_arginfo_size_function __arginfo) |
| 98 | __THROW; |
| 99 | |
| 100 | |
| 101 | /* Obsolete interface similar to register_printf_specifier. It can only |
| 102 | handle basic data types because the ARGINFO callback does not return |
| 103 | information on the size of the user-defined type. */ |
| 104 | |
| 105 | extern int register_printf_function (int __spec, printf_function __func, |
| 106 | printf_arginfo_function __arginfo) |
| 107 | __THROW __attribute_deprecated__; |
| 108 | |
| 109 | |
| 110 | /* Register a new modifier character sequence. If the call succeeds |
| 111 | it returns a positive value representing the bit set in the USER |
| 112 | field in 'struct printf_info'. */ |
| 113 | |
| 114 | extern int register_printf_modifier (const wchar_t *__str) __wur __THROW; |
| 115 | |
| 116 | |
| 117 | /* Register variable argument handler for user type. The return value |
| 118 | is to be used in ARGINFO functions to signal the use of the |
| 119 | type. */ |
| 120 | extern int register_printf_type (printf_va_arg_function __fct) __wur __THROW; |
| 121 | |
| 122 | |
| 123 | /* Parse FMT, and fill in N elements of ARGTYPES with the |
| 124 | types needed for the conversions FMT specifies. Returns |
| 125 | the number of arguments required by FMT. |
| 126 | |
| 127 | The ARGINFO function registered with a user-defined format is passed a |
| 128 | `struct printf_info' describing the format spec being parsed. A width |
| 129 | or precision of INT_MIN means a `*' was used to indicate that the |
| 130 | width/precision will come from an arg. The function should fill in the |
| 131 | array it is passed with the types of the arguments it wants, and return |
| 132 | the number of arguments it wants. */ |
| 133 | |
| 134 | extern size_t parse_printf_format (const char *__restrict __fmt, size_t __n, |
| 135 | int *__restrict __argtypes) __THROW; |
| 136 | |
| 137 | |
| 138 | /* Codes returned by `parse_printf_format' for basic types. |
| 139 | |
| 140 | These values cover all the standard format specifications. |
| 141 | Users can reserve new values after PA_LAST for their own types |
| 142 | using 'register_printf_type'. */ |
| 143 | |
| 144 | enum |
| 145 | { /* C type: */ |
| 146 | PA_INT, /* int */ |
| 147 | PA_CHAR, /* int, cast to char */ |
| 148 | PA_WCHAR, /* wide char */ |
| 149 | PA_STRING, /* const char *, a '\0'-terminated string */ |
| 150 | PA_WSTRING, /* const wchar_t *, wide character string */ |
| 151 | PA_POINTER, /* void * */ |
| 152 | PA_FLOAT, /* float */ |
| 153 | PA_DOUBLE, /* double */ |
| 154 | PA_LAST |
| 155 | }; |
| 156 | |
| 157 | /* Flag bits that can be set in a type returned by `parse_printf_format'. */ |
| 158 | #define PA_FLAG_MASK 0xff00 |
| 159 | #define PA_FLAG_LONG_LONG (1 << 8) |
| 160 | #define PA_FLAG_LONG_DOUBLE PA_FLAG_LONG_LONG |
| 161 | #define PA_FLAG_LONG (1 << 9) |
| 162 | #define PA_FLAG_SHORT (1 << 10) |
| 163 | #define PA_FLAG_PTR (1 << 11) |
| 164 | |
| 165 | |
| 166 | |
| 167 | /* Function which can be registered as `printf'-handlers. */ |
| 168 | |
| 169 | /* Print floating point value using using abbreviations for the orders |
| 170 | of magnitude used for numbers ('k' for kilo, 'm' for mega etc). If |
| 171 | the format specifier is a uppercase character powers of 1000 are |
| 172 | used. Otherwise powers of 1024. */ |
| 173 | extern int printf_size (FILE *__restrict __fp, |
| 174 | const struct printf_info *__info, |
| 175 | const void *const *__restrict __args) __THROW; |
| 176 | |
| 177 | /* This is the appropriate argument information function for `printf_size'. */ |
| 178 | extern int printf_size_info (const struct printf_info *__restrict |
| 179 | __info, size_t __n, int *__restrict __argtypes) |
| 180 | __THROW; |
| 181 | |
| 182 | #ifdef __LDBL_COMPAT |
| 183 | # include <bits/printf-ldbl.h> |
| 184 | #endif |
| 185 | |
| 186 | __END_DECLS |
| 187 | |
| 188 | #endif /* printf.h */ |