1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-28 00:21:52 +03:00

* stdio-common/printf.h (struct printf_info): Add user element.

New types printf_arginfo_size_function, printf_va_arg_function.
	Declare register_printf_specifier, register_printf_modifier,
	register_printf_type.
	* stdio-common/printf-parse.h (struct printf_spec): Add size element.
	(union printf_arg): Add pa_user element.
	Adjust __printf_arginfo_table type.
	Add __printf_va_arg_table, __printf_modifier_table,
	__handle_registered_modifier_mb, and __handle_registered_modifier_wc
	declarations.
	* stdio-common/printf-parsemb.c: Recognize registered modifiers.
	If registered arginfo call failed try normal specifier.
	* stdio-common/printf-prs.c: Pass additional parameter to arginfo
	function.
	* stdio-common/Makefile (routines): Add reg-modifier and reg-type.
	* stdio-common/Versions: Export register_printf_modifier,
	register_printf_type, and register_printf_specifier for GLIBC_2.10.
	* stdio-common/reg-modifier.c: New file.
	* stdio-common/reg-type.c: New file.
	* stdio-common/reg-printf.c (__register_printf_specifier): New
	function.  Mostly the old __register_printf_function function but
	uses locking and type of third parameter changed.
	(__register_printf_function): Implement using
	__register_printf_specifier.
	* stdio-common/vfprintf.c (vfprintf): Collect argument sizes in
	calls to arginfo functions.  Allocate enough memory for user-defined
	types.  Call new va_arg functions to get user-defined types.
	Try installed handlers even for existing format specifiers first.
This commit is contained in:
Ulrich Drepper
2009-04-11 05:34:20 +00:00
parent f140a0d53d
commit 9d26efa90c
12 changed files with 542 additions and 104 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1991-1993,1995-1999,2000,2001,2006
/* Copyright (C) 1991-1993,1995-2001,2006,2009
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@ -29,6 +29,7 @@ __BEGIN_DECLS
#define __need_size_t
#define __need_wchar_t
#include <stddef.h>
#include <stdarg.h>
struct printf_info
@ -48,6 +49,8 @@ struct printf_info
unsigned int is_char:1; /* hh flag. */
unsigned int wide:1; /* Nonzero for wide character streams. */
unsigned int i18n:1; /* I flag. */
unsigned int __pad:4; /* Unused so far. */
unsigned short int user; /* Bits for user-installed modifiers. */
wchar_t pad; /* Padding character. */
};
@ -68,18 +71,55 @@ typedef int printf_function (FILE *__stream,
/* Type of a printf specifier-arginfo function.
INFO gives information about the format specification.
N, ARGTYPES, and return value are as for parse_printf_format. */
N, ARGTYPES, *SIZE has to contain the size of the parameter for
user-defined types, and return value are as for parse_printf_format
except that -1 should be returned if the handler cannot handle
this case. This allows to partially overwrite the functionality
of existing format specifiers. */
typedef int printf_arginfo_size_function (__const struct printf_info *__info,
size_t __n, int *__argtypes,
int *__size);
/* Old version of 'printf_arginfo_function' without a SIZE parameter. */
typedef int printf_arginfo_function (__const struct printf_info *__info,
size_t __n, int *__argtypes);
/* Type of a function to get a value of a user-defined from the
variable argument list. */
typedef void printf_va_arg_function (void *__mem, va_list *__ap);
/* Register FUNC to be called to format SPEC specifiers; ARGINFO must be
specified to determine how many arguments a SPEC conversion requires and
what their types are. */
extern int register_printf_specifier (int __spec, printf_function __func,
printf_arginfo_size_function __arginfo)
__THROW;
/* Obsolete interface similar to register_printf_specifier. It can only
handle basic data types because the ARGINFO callback does not return
information on the size of the user-defined type. */
extern int register_printf_function (int __spec, printf_function __func,
printf_arginfo_function __arginfo);
printf_arginfo_function __arginfo)
__THROW __attribute_deprecated__;
/* Register a new modifier character sequence. If the call succeeds
it returns a positive value representing the bit set in the USER
field in 'struct printf_info'. */
extern int register_printf_modifier (wchar_t *__str) __wur __THROW;
/* Register variable argument handler for user type. The return value
is to be used in ARGINFO functions to signal the use of the
type. */
extern int register_printf_type (printf_va_arg_function __fct) __wur __THROW;
/* Parse FMT, and fill in N elements of ARGTYPES with the
@ -100,7 +140,8 @@ extern size_t parse_printf_format (__const char *__restrict __fmt, size_t __n,
/* Codes returned by `parse_printf_format' for basic types.
These values cover all the standard format specifications.
Users can add new values after PA_LAST for their own types. */
Users can reserve new values after PA_LAST for their own types
using 'register_printf_type'. */
enum
{ /* C type: */