printf-args.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* Decomposed printf argument list.
  2. Copyright (C) 1999, 2002-2003, 2006-2007, 2011 Free Software
  3. Foundation, Inc.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program 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
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  15. #ifndef _PRINTF_ARGS_H
  16. #define _PRINTF_ARGS_H
  17. /* This file can be parametrized with the following macros:
  18. ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
  19. PRINTF_FETCHARGS Name of the function to be declared.
  20. STATIC Set to 'static' to declare the function static. */
  21. /* Default parameters. */
  22. #ifndef PRINTF_FETCHARGS
  23. # define PRINTF_FETCHARGS printf_fetchargs
  24. #endif
  25. /* Get size_t. */
  26. #include <stddef.h>
  27. /* Get wchar_t. */
  28. #if HAVE_WCHAR_T
  29. # include <stddef.h>
  30. #endif
  31. /* Get wint_t. */
  32. #if HAVE_WINT_T
  33. # include <wchar.h>
  34. #endif
  35. /* Get va_list. */
  36. #include <stdarg.h>
  37. /* Argument types */
  38. typedef enum
  39. {
  40. TYPE_NONE,
  41. TYPE_SCHAR,
  42. TYPE_UCHAR,
  43. TYPE_SHORT,
  44. TYPE_USHORT,
  45. TYPE_INT,
  46. TYPE_UINT,
  47. TYPE_LONGINT,
  48. TYPE_ULONGINT,
  49. #if HAVE_LONG_LONG_INT
  50. TYPE_LONGLONGINT,
  51. TYPE_ULONGLONGINT,
  52. #endif
  53. TYPE_DOUBLE,
  54. TYPE_LONGDOUBLE,
  55. TYPE_CHAR,
  56. #if HAVE_WINT_T
  57. TYPE_WIDE_CHAR,
  58. #endif
  59. TYPE_STRING,
  60. #if HAVE_WCHAR_T
  61. TYPE_WIDE_STRING,
  62. #endif
  63. TYPE_POINTER,
  64. TYPE_COUNT_SCHAR_POINTER,
  65. TYPE_COUNT_SHORT_POINTER,
  66. TYPE_COUNT_INT_POINTER,
  67. TYPE_COUNT_LONGINT_POINTER
  68. #if HAVE_LONG_LONG_INT
  69. , TYPE_COUNT_LONGLONGINT_POINTER
  70. #endif
  71. #if ENABLE_UNISTDIO
  72. /* The unistdio extensions. */
  73. , TYPE_U8_STRING
  74. , TYPE_U16_STRING
  75. , TYPE_U32_STRING
  76. #endif
  77. } arg_type;
  78. /* Polymorphic argument */
  79. typedef struct
  80. {
  81. arg_type type;
  82. union
  83. {
  84. signed char a_schar;
  85. unsigned char a_uchar;
  86. short a_short;
  87. unsigned short a_ushort;
  88. int a_int;
  89. unsigned int a_uint;
  90. long int a_longint;
  91. unsigned long int a_ulongint;
  92. #if HAVE_LONG_LONG_INT
  93. long long int a_longlongint;
  94. unsigned long long int a_ulonglongint;
  95. #endif
  96. float a_float;
  97. double a_double;
  98. long double a_longdouble;
  99. int a_char;
  100. #if HAVE_WINT_T
  101. wint_t a_wide_char;
  102. #endif
  103. const char* a_string;
  104. #if HAVE_WCHAR_T
  105. const wchar_t* a_wide_string;
  106. #endif
  107. void* a_pointer;
  108. signed char * a_count_schar_pointer;
  109. short * a_count_short_pointer;
  110. int * a_count_int_pointer;
  111. long int * a_count_longint_pointer;
  112. #if HAVE_LONG_LONG_INT
  113. long long int * a_count_longlongint_pointer;
  114. #endif
  115. #if ENABLE_UNISTDIO
  116. /* The unistdio extensions. */
  117. const uint8_t * a_u8_string;
  118. const uint16_t * a_u16_string;
  119. const uint32_t * a_u32_string;
  120. #endif
  121. }
  122. a;
  123. }
  124. argument;
  125. /* Number of directly allocated arguments (no malloc() needed). */
  126. #define N_DIRECT_ALLOC_ARGUMENTS 7
  127. typedef struct
  128. {
  129. size_t count;
  130. argument *arg;
  131. argument direct_alloc_arg[N_DIRECT_ALLOC_ARGUMENTS];
  132. }
  133. arguments;
  134. /* Fetch the arguments, putting them into a. */
  135. #ifdef STATIC
  136. STATIC
  137. #else
  138. extern
  139. #endif
  140. int PRINTF_FETCHARGS (va_list args, arguments *a);
  141. #endif /* _PRINTF_ARGS_H */