printf.h 6.6 KB

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