1 /* Parse printf format string.
2 Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2015 Free Software
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, see <http://www.gnu.org/licenses/>. */
18 #ifndef _PRINTF_PARSE_H
19 #define _PRINTF_PARSE_H
21 /* This file can be parametrized with the following macros:
22 ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
23 STATIC Set to 'static' to declare the function static. */
26 # include <features.h> /* for __GLIBC__, __UCLIBC__ */
29 #include "printf-args.h"
33 #define FLAG_GROUP 1 /* ' flag */
34 #define FLAG_LEFT 2 /* - flag */
35 #define FLAG_SHOWSIGN 4 /* + flag */
36 #define FLAG_SPACE 8 /* space flag */
37 #define FLAG_ALT 16 /* # flag */
39 #if __GLIBC__ >= 2 && !defined __UCLIBC__
40 # define FLAG_LOCALIZED 64 /* I flag, uses localized digits */
43 /* arg_index value indicating that no argument is consumed. */
44 #define ARG_NONE (~(size_t)0)
46 /* xxx_directive: A parsed directive.
47 xxx_directives: A parsed format string. */
49 /* Number of directly allocated directives (no malloc() needed). */
50 #define N_DIRECT_ALLOC_DIRECTIVES 7
52 /* A parsed directive. */
55 const char* dir_start
;
58 const char* width_start
;
59 const char* width_end
;
60 size_t width_arg_index
;
61 const char* precision_start
;
62 const char* precision_end
;
63 size_t precision_arg_index
;
64 char conversion
; /* d i o u x X f F e E g G a A c s p n U % but not C S */
69 /* A parsed format string. */
74 size_t max_width_length
;
75 size_t max_precision_length
;
76 char_directive direct_alloc_dir
[N_DIRECT_ALLOC_DIRECTIVES
];
82 /* A parsed directive. */
85 const uint8_t* dir_start
;
86 const uint8_t* dir_end
;
88 const uint8_t* width_start
;
89 const uint8_t* width_end
;
90 size_t width_arg_index
;
91 const uint8_t* precision_start
;
92 const uint8_t* precision_end
;
93 size_t precision_arg_index
;
94 uint8_t conversion
; /* d i o u x X f F e E g G a A c s p n U % but not C S */
99 /* A parsed format string. */
104 size_t max_width_length
;
105 size_t max_precision_length
;
106 u8_directive direct_alloc_dir
[N_DIRECT_ALLOC_DIRECTIVES
];
110 /* A parsed directive. */
113 const uint16_t* dir_start
;
114 const uint16_t* dir_end
;
116 const uint16_t* width_start
;
117 const uint16_t* width_end
;
118 size_t width_arg_index
;
119 const uint16_t* precision_start
;
120 const uint16_t* precision_end
;
121 size_t precision_arg_index
;
122 uint16_t conversion
; /* d i o u x X f F e E g G a A c s p n U % but not C S */
127 /* A parsed format string. */
132 size_t max_width_length
;
133 size_t max_precision_length
;
134 u16_directive direct_alloc_dir
[N_DIRECT_ALLOC_DIRECTIVES
];
138 /* A parsed directive. */
141 const uint32_t* dir_start
;
142 const uint32_t* dir_end
;
144 const uint32_t* width_start
;
145 const uint32_t* width_end
;
146 size_t width_arg_index
;
147 const uint32_t* precision_start
;
148 const uint32_t* precision_end
;
149 size_t precision_arg_index
;
150 uint32_t conversion
; /* d i o u x X f F e E g G a A c s p n U % but not C S */
155 /* A parsed format string. */
160 size_t max_width_length
;
161 size_t max_precision_length
;
162 u32_directive direct_alloc_dir
[N_DIRECT_ALLOC_DIRECTIVES
];
169 /* Parses the format string. Fills in the number N of directives, and fills
170 in directives[0], ..., directives[N-1], and sets directives[N].dir_start
171 to the end of the format string. Also fills in the arg_type fields of the
172 arguments and the needed count of arguments. */
175 ulc_printf_parse (const char *format
, char_directives
*d
, arguments
*a
);
177 u8_printf_parse (const uint8_t *format
, u8_directives
*d
, arguments
*a
);
179 u16_printf_parse (const uint16_t *format
, u16_directives
*d
,
182 u32_printf_parse (const uint32_t *format
, u32_directives
*d
,
190 int printf_parse (const char *format
, char_directives
*d
, arguments
*a
);
193 #endif /* _PRINTF_PARSE_H */