printf-args.h 3.8 KB

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