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