/include/printf.h

https://bitbucket.org/freebsd/freebsd-head/ · C Header · 164 lines · 88 code · 25 blank · 51 comment · 0 complexity · 83ddb1533cba6c05b79384d44aef8d54 MD5 · raw file

  1. /*-
  2. * Copyright (c) 2005 Poul-Henning Kamp
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  18. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  20. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  23. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. * SUCH DAMAGE.
  25. *
  26. * $FreeBSD$
  27. */
  28. #ifndef _PRINTF_H_
  29. #define _PRINTF_H_
  30. #include <stdio.h>
  31. #include <wchar.h>
  32. /*
  33. * The API defined by glibc allows a renderer to take multiple arguments
  34. * This is obviously usable for things like (ptr+len) pairs etc.
  35. * But the do not actually provide support for it at the end of the day,
  36. * they offer only one argument to the arginfo function, but do accept
  37. * >1 returns, although the do not check the types of those arguments
  38. * argument
  39. * Be compatible for now.
  40. */
  41. #define __PRINTFMAXARG 2
  42. struct printf_info {
  43. /* GLIBC compatible */
  44. int prec;
  45. int width;
  46. wchar_t spec;
  47. unsigned is_long_double;
  48. unsigned is_char;
  49. unsigned is_short;
  50. unsigned is_long;
  51. unsigned alt;
  52. unsigned space;
  53. unsigned left;
  54. unsigned showsign;
  55. unsigned group;
  56. unsigned extra;
  57. unsigned wide;
  58. wchar_t pad;
  59. /* FreeBSD extensions */
  60. unsigned is_quad;
  61. unsigned is_intmax;
  62. unsigned is_ptrdiff;
  63. unsigned is_size;
  64. /* private */
  65. int sofar;
  66. unsigned get_width;
  67. unsigned get_prec;
  68. const char *begin;
  69. const char *end;
  70. void *arg[__PRINTFMAXARG];
  71. };
  72. enum {
  73. PA_INT = (1 << 0), /* int */
  74. PA_CHAR = (1 << 1), /* int, cast to char */
  75. PA_WCHAR = (1 << 2), /* wide char */
  76. PA_STRING = (1 << 3), /* const char * (with '\0') */
  77. PA_WSTRING = (1 << 4), /* const wchar_t * */
  78. PA_POINTER = (1 << 5), /* void * */
  79. PA_FLOAT = (1 << 6), /* float */
  80. PA_DOUBLE = (1 << 7) /* double */
  81. };
  82. #define PA_FLAG_MASK 0xff0000
  83. #define PA_FLAG_LONG_LONG (1 << 16)
  84. #define PA_FLAG_LONG (1 << 17)
  85. #define PA_FLAG_SHORT (1 << 18)
  86. #define PA_FLAG_PTR (1 << 19)
  87. #define PA_FLAG_QUAD (1 << 20)
  88. #define PA_FLAG_INTMAX (1 << 21)
  89. #define PA_FLAG_SIZE (1 << 22)
  90. #define PA_FLAG_PTRDIFF (1 << 23)
  91. #define PA_FLAG_LONG_DOUBLE PA_FLAG_LONG_LONG
  92. typedef int printf_arginfo_function(const struct printf_info *, size_t, int *);
  93. typedef int printf_function(FILE *, const struct printf_info *, const void *const *);
  94. /* FreeBSD extension */
  95. struct __printf_io;
  96. typedef int printf_render(struct __printf_io *, const struct printf_info *, const void *const *);
  97. /* vprintf.c */
  98. extern const char __lowercase_hex[17];
  99. extern const char __uppercase_hex[17];
  100. void __printf_flush(struct __printf_io *io);
  101. int __printf_puts(struct __printf_io *io, const void *ptr, int len);
  102. int __printf_pad(struct __printf_io *io, int n, int zero);
  103. int __printf_out(struct __printf_io *io, const struct printf_info *pi, const void *ptr, int len);
  104. int __xvprintf(FILE *fp, const char *fmt0, va_list ap);
  105. extern int __use_xprintf;
  106. /* GLIBC compat */
  107. int register_printf_function(int spec, printf_function *render, printf_arginfo_function *arginfo);
  108. /* FreeBSD */
  109. int register_printf_render(int spec, printf_render *render, printf_arginfo_function *arginfo);
  110. int register_printf_render_std(const char *specs);
  111. /* vprintf_errno.c */
  112. printf_arginfo_function __printf_arginfo_errno;
  113. printf_render __printf_render_errno;
  114. /* vprintf_float.c */
  115. printf_arginfo_function __printf_arginfo_float;
  116. printf_render __printf_render_float;
  117. /* vprintf_hexdump.c */
  118. printf_arginfo_function __printf_arginfo_hexdump;
  119. printf_render __printf_render_hexdump;
  120. /* vprintf_int.c */
  121. printf_arginfo_function __printf_arginfo_ptr;
  122. printf_arginfo_function __printf_arginfo_int;
  123. printf_render __printf_render_ptr;
  124. printf_render __printf_render_int;
  125. /* vprintf_quoute.c */
  126. printf_arginfo_function __printf_arginfo_quote;
  127. printf_render __printf_render_quote;
  128. /* vprintf_str.c */
  129. printf_arginfo_function __printf_arginfo_chr;
  130. printf_render __printf_render_chr;
  131. printf_arginfo_function __printf_arginfo_str;
  132. printf_render __printf_render_str;
  133. /* vprintf_time.c */
  134. printf_arginfo_function __printf_arginfo_time;
  135. printf_render __printf_render_time;
  136. /* vprintf_vis.c */
  137. printf_arginfo_function __printf_arginfo_vis;
  138. printf_render __printf_render_vis;
  139. #endif /* !_PRINTF_H */