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