printf-args.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* Decomposed printf argument list.
  2. Copyright (C) 1999, 2002-2003, 2006-2007, 2011-2021 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, see <https://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. TYPE_LONGLONGINT,
  49. TYPE_ULONGLONGINT,
  50. TYPE_DOUBLE,
  51. TYPE_LONGDOUBLE,
  52. TYPE_CHAR,
  53. #if HAVE_WINT_T
  54. TYPE_WIDE_CHAR,
  55. #endif
  56. TYPE_STRING,
  57. #if HAVE_WCHAR_T
  58. TYPE_WIDE_STRING,
  59. #endif
  60. TYPE_POINTER,
  61. TYPE_COUNT_SCHAR_POINTER,
  62. TYPE_COUNT_SHORT_POINTER,
  63. TYPE_COUNT_INT_POINTER,
  64. TYPE_COUNT_LONGINT_POINTER,
  65. TYPE_COUNT_LONGLONGINT_POINTER
  66. #if ENABLE_UNISTDIO
  67. /* The unistdio extensions. */
  68. , TYPE_U8_STRING
  69. , TYPE_U16_STRING
  70. , TYPE_U32_STRING
  71. #endif
  72. } arg_type;
  73. /* Polymorphic argument */
  74. typedef struct
  75. {
  76. arg_type type;
  77. union
  78. {
  79. signed char a_schar;
  80. unsigned char a_uchar;
  81. short a_short;
  82. unsigned short a_ushort;
  83. int a_int;
  84. unsigned int a_uint;
  85. long int a_longint;
  86. unsigned long int a_ulongint;
  87. long long int a_longlongint;
  88. unsigned long long int a_ulonglongint;
  89. float a_float;
  90. double a_double;
  91. long double a_longdouble;
  92. int a_char;
  93. #if HAVE_WINT_T
  94. wint_t a_wide_char;
  95. #endif
  96. const char* a_string;
  97. #if HAVE_WCHAR_T
  98. const wchar_t* a_wide_string;
  99. #endif
  100. void* a_pointer;
  101. signed char * a_count_schar_pointer;
  102. short * a_count_short_pointer;
  103. int * a_count_int_pointer;
  104. long int * a_count_longint_pointer;
  105. long long int * a_count_longlongint_pointer;
  106. #if ENABLE_UNISTDIO
  107. /* The unistdio extensions. */
  108. const uint8_t * a_u8_string;
  109. const uint16_t * a_u16_string;
  110. const uint32_t * a_u32_string;
  111. #endif
  112. }
  113. a;
  114. }
  115. argument;
  116. /* Number of directly allocated arguments (no malloc() needed). */
  117. #define N_DIRECT_ALLOC_ARGUMENTS 7
  118. typedef struct
  119. {
  120. size_t count;
  121. argument *arg;
  122. argument direct_alloc_arg[N_DIRECT_ALLOC_ARGUMENTS];
  123. }
  124. arguments;
  125. /* Fetch the arguments, putting them into a. */
  126. #ifdef STATIC
  127. STATIC
  128. #else
  129. extern
  130. #endif
  131. int PRINTF_FETCHARGS (va_list args, arguments *a);
  132. #endif /* _PRINTF_ARGS_H */