1 /* Parse printf format string.
2 Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2011 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, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 #ifndef _PRINTF_PARSE_H
20 #define _PRINTF_PARSE_H
22 /* This file can be parametrized with the following macros:
23 ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
24 STATIC Set to 'static' to declare the function static. */
27 # include <features.h> /* for __GLIBC__, __UCLIBC__ */
30 #include "printf-args.h"
34 #define FLAG_GROUP 1 /* ' flag */
35 #define FLAG_LEFT 2 /* - flag */
36 #define FLAG_SHOWSIGN 4 /* + flag */
37 #define FLAG_SPACE 8 /* space flag */
38 #define FLAG_ALT 16 /* # flag */
40 #if __GLIBC__ >= 2 && !defined __UCLIBC__
41 # define FLAG_LOCALIZED 64 /* I flag, uses localized digits */
44 /* arg_index value indicating that no argument is consumed. */
45 #define ARG_NONE (~(size_t)0)
47 /* xxx_directive: A parsed directive.
48 xxx_directives: A parsed format string. */
50 /* Number of directly allocated directives (no malloc() needed). */
51 #define N_DIRECT_ALLOC_DIRECTIVES 7
53 /* A parsed directive. */
56 const char* dir_start;
59 const char* width_start;
60 const char* width_end;
61 size_t width_arg_index;
62 const char* precision_start;
63 const char* precision_end;
64 size_t precision_arg_index;
65 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 */
70 /* A parsed format string. */
75 size_t max_width_length;
76 size_t max_precision_length;
77 char_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
83 /* A parsed directive. */
86 const uint8_t* dir_start;
87 const uint8_t* dir_end;
89 const uint8_t* width_start;
90 const uint8_t* width_end;
91 size_t width_arg_index;
92 const uint8_t* precision_start;
93 const uint8_t* precision_end;
94 size_t precision_arg_index;
95 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 */
100 /* A parsed format string. */
105 size_t max_width_length;
106 size_t max_precision_length;
107 u8_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
111 /* A parsed directive. */
114 const uint16_t* dir_start;
115 const uint16_t* dir_end;
117 const uint16_t* width_start;
118 const uint16_t* width_end;
119 size_t width_arg_index;
120 const uint16_t* precision_start;
121 const uint16_t* precision_end;
122 size_t precision_arg_index;
123 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 */
128 /* A parsed format string. */
133 size_t max_width_length;
134 size_t max_precision_length;
135 u16_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
139 /* A parsed directive. */
142 const uint32_t* dir_start;
143 const uint32_t* dir_end;
145 const uint32_t* width_start;
146 const uint32_t* width_end;
147 size_t width_arg_index;
148 const uint32_t* precision_start;
149 const uint32_t* precision_end;
150 size_t precision_arg_index;
151 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 */
156 /* A parsed format string. */
161 size_t max_width_length;
162 size_t max_precision_length;
163 u32_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
170 /* Parses the format string. Fills in the number N of directives, and fills
171 in directives[0], ..., directives[N-1], and sets directives[N].dir_start
172 to the end of the format string. Also fills in the arg_type fields of the
173 arguments and the needed count of arguments. */
176 ulc_printf_parse (const char *format, char_directives *d, arguments *a);
178 u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a);
180 u16_printf_parse (const uint16_t *format, u16_directives *d,
183 u32_printf_parse (const uint32_t *format, u32_directives *d,
191 int printf_parse (const char *format, char_directives *d, arguments *a);
194 #endif /* _PRINTF_PARSE_H */