Blame stdio-common/printf.h

Packit 6c4009
/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef	_PRINTF_H
Packit 6c4009
Packit 6c4009
#define	_PRINTF_H	1
Packit 6c4009
#include <features.h>
Packit 6c4009
Packit 6c4009
__BEGIN_DECLS
Packit 6c4009
Packit 6c4009
#include <bits/types/FILE.h>
Packit 6c4009
Packit 6c4009
#define	__need_size_t
Packit 6c4009
#define __need_wchar_t
Packit 6c4009
#include <stddef.h>
Packit 6c4009
Packit 6c4009
#include <stdarg.h>
Packit 6c4009
Packit 6c4009
Packit 6c4009
struct printf_info
Packit 6c4009
{
Packit 6c4009
  int prec;			/* Precision.  */
Packit 6c4009
  int width;			/* Width.  */
Packit 6c4009
  wchar_t spec;			/* Format letter.  */
Packit 6c4009
  unsigned int is_long_double:1;/* L flag.  */
Packit 6c4009
  unsigned int is_short:1;	/* h flag.  */
Packit 6c4009
  unsigned int is_long:1;	/* l flag.  */
Packit 6c4009
  unsigned int alt:1;		/* # flag.  */
Packit 6c4009
  unsigned int space:1;		/* Space flag.  */
Packit 6c4009
  unsigned int left:1;		/* - flag.  */
Packit 6c4009
  unsigned int showsign:1;	/* + flag.  */
Packit 6c4009
  unsigned int group:1;		/* ' flag.  */
Packit 6c4009
  unsigned int extra:1;		/* For special use.  */
Packit 6c4009
  unsigned int is_char:1;	/* hh flag.  */
Packit 6c4009
  unsigned int wide:1;		/* Nonzero for wide character streams.  */
Packit 6c4009
  unsigned int i18n:1;		/* I flag.  */
Packit 6c4009
  unsigned int is_binary128:1;	/* Floating-point argument is ABI-compatible
Packit 6c4009
				   with IEC 60559 binary128.  */
Packit 6c4009
  unsigned int __pad:3;		/* Unused so far.  */
Packit 6c4009
  unsigned short int user;	/* Bits for user-installed modifiers.  */
Packit 6c4009
  wchar_t pad;			/* Padding character.  */
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Type of a printf specifier-handler function.
Packit 6c4009
   STREAM is the FILE on which to write output.
Packit 6c4009
   INFO gives information about the format specification.
Packit 6c4009
   ARGS is a vector of pointers to the argument data;
Packit 6c4009
   the number of pointers will be the number returned
Packit 6c4009
   by the associated arginfo function for the same INFO.
Packit 6c4009
Packit 6c4009
   The function should return the number of characters written,
Packit 6c4009
   or -1 for errors.  */
Packit 6c4009
Packit 6c4009
typedef int printf_function (FILE *__stream,
Packit 6c4009
			     const struct printf_info *__info,
Packit 6c4009
			     const void *const *__args);
Packit 6c4009
Packit 6c4009
/* Type of a printf specifier-arginfo function.
Packit 6c4009
   INFO gives information about the format specification.
Packit 6c4009
   N, ARGTYPES, *SIZE has to contain the size of the parameter for
Packit 6c4009
   user-defined types, and return value are as for parse_printf_format
Packit 6c4009
   except that -1 should be returned if the handler cannot handle
Packit 6c4009
   this case.  This allows to partially overwrite the functionality
Packit 6c4009
   of existing format specifiers.  */
Packit 6c4009
Packit 6c4009
typedef int printf_arginfo_size_function (const struct printf_info *__info,
Packit 6c4009
					  size_t __n, int *__argtypes,
Packit 6c4009
					  int *__size);
Packit 6c4009
Packit 6c4009
/* Old version of 'printf_arginfo_function' without a SIZE parameter.  */
Packit 6c4009
Packit 6c4009
typedef int printf_arginfo_function (const struct printf_info *__info,
Packit 6c4009
				     size_t __n, int *__argtypes);
Packit 6c4009
Packit 6c4009
/* Type of a function to get a value of a user-defined from the
Packit 6c4009
   variable argument list.  */
Packit 6c4009
typedef void printf_va_arg_function (void *__mem, va_list *__ap);
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Register FUNC to be called to format SPEC specifiers; ARGINFO must be
Packit 6c4009
   specified to determine how many arguments a SPEC conversion requires and
Packit 6c4009
   what their types are.  */
Packit 6c4009
Packit 6c4009
extern int register_printf_specifier (int __spec, printf_function __func,
Packit 6c4009
				      printf_arginfo_size_function __arginfo)
Packit 6c4009
  __THROW;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Obsolete interface similar to register_printf_specifier.  It can only
Packit 6c4009
   handle basic data types because the ARGINFO callback does not return
Packit 6c4009
   information on the size of the user-defined type.  */
Packit 6c4009
Packit 6c4009
extern int register_printf_function (int __spec, printf_function __func,
Packit 6c4009
				     printf_arginfo_function __arginfo)
Packit 6c4009
  __THROW __attribute_deprecated__;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Register a new modifier character sequence.  If the call succeeds
Packit 6c4009
   it returns a positive value representing the bit set in the USER
Packit 6c4009
   field in 'struct printf_info'.  */
Packit 6c4009
Packit 6c4009
extern int register_printf_modifier (const wchar_t *__str) __THROW __wur;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Register variable argument handler for user type.  The return value
Packit 6c4009
   is to be used in ARGINFO functions to signal the use of the
Packit 6c4009
   type.  */
Packit 6c4009
extern int register_printf_type (printf_va_arg_function __fct) __THROW __wur;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Parse FMT, and fill in N elements of ARGTYPES with the
Packit 6c4009
   types needed for the conversions FMT specifies.  Returns
Packit 6c4009
   the number of arguments required by FMT.
Packit 6c4009
Packit 6c4009
   The ARGINFO function registered with a user-defined format is passed a
Packit 6c4009
   `struct printf_info' describing the format spec being parsed.  A width
Packit 6c4009
   or precision of INT_MIN means a `*' was used to indicate that the
Packit 6c4009
   width/precision will come from an arg.  The function should fill in the
Packit 6c4009
   array it is passed with the types of the arguments it wants, and return
Packit 6c4009
   the number of arguments it wants.  */
Packit 6c4009
Packit 6c4009
extern size_t parse_printf_format (const char *__restrict __fmt, size_t __n,
Packit 6c4009
				   int *__restrict __argtypes) __THROW;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Codes returned by `parse_printf_format' for basic types.
Packit 6c4009
Packit 6c4009
   These values cover all the standard format specifications.
Packit 6c4009
   Users can reserve new values after PA_LAST for their own types
Packit 6c4009
   using 'register_printf_type'.  */
Packit 6c4009
Packit 6c4009
enum
Packit 6c4009
{				/* C type: */
Packit 6c4009
  PA_INT,			/* int */
Packit 6c4009
  PA_CHAR,			/* int, cast to char */
Packit 6c4009
  PA_WCHAR,			/* wide char */
Packit 6c4009
  PA_STRING,			/* const char *, a '\0'-terminated string */
Packit 6c4009
  PA_WSTRING,			/* const wchar_t *, wide character string */
Packit 6c4009
  PA_POINTER,			/* void * */
Packit 6c4009
  PA_FLOAT,			/* float */
Packit 6c4009
  PA_DOUBLE,			/* double */
Packit 6c4009
  PA_LAST
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
/* Flag bits that can be set in a type returned by `parse_printf_format'.  */
Packit 6c4009
#define	PA_FLAG_MASK		0xff00
Packit 6c4009
#define	PA_FLAG_LONG_LONG	(1 << 8)
Packit 6c4009
#define	PA_FLAG_LONG_DOUBLE	PA_FLAG_LONG_LONG
Packit 6c4009
#define	PA_FLAG_LONG		(1 << 9)
Packit 6c4009
#define	PA_FLAG_SHORT		(1 << 10)
Packit 6c4009
#define	PA_FLAG_PTR		(1 << 11)
Packit 6c4009
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Function which can be registered as `printf'-handlers.  */
Packit 6c4009
Packit 6c4009
/* Print floating point value using using abbreviations for the orders
Packit 6c4009
   of magnitude used for numbers ('k' for kilo, 'm' for mega etc).  If
Packit 6c4009
   the format specifier is a uppercase character powers of 1000 are
Packit 6c4009
   used.  Otherwise powers of 1024.  */
Packit 6c4009
extern int printf_size (FILE *__restrict __fp,
Packit 6c4009
			const struct printf_info *__info,
Packit 6c4009
			const void *const *__restrict __args) __THROW;
Packit 6c4009
Packit 6c4009
/* This is the appropriate argument information function for `printf_size'.  */
Packit 6c4009
extern int printf_size_info (const struct printf_info *__restrict
Packit 6c4009
			     __info, size_t __n, int *__restrict __argtypes)
Packit 6c4009
     __THROW;
Packit 6c4009
Packit 6c4009
#ifdef __LDBL_COMPAT
Packit 6c4009
# include <bits/printf-ldbl.h>
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
__END_DECLS
Packit 6c4009
Packit 6c4009
#endif /* printf.h  */