1 /* Parse printf format string.
2 Copyright (C) 1999, 2002-2003, 2005, 2007, 2009-2010 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. */
26 #include "printf-args.h"
30 #define FLAG_GROUP 1 /* ' flag */
31 #define FLAG_LEFT 2 /* - flag */
32 #define FLAG_SHOWSIGN 4 /* + flag */
33 #define FLAG_SPACE 8 /* space flag */
34 #define FLAG_ALT 16 /* # flag */
37 # define FLAG_LOCALIZED 64 /* I flag, uses localized digits */
40 /* arg_index value indicating that no argument is consumed. */
41 #define ARG_NONE (~(size_t)0)
43 /* xxx_directive: A parsed directive.
44 xxx_directives: A parsed format string. */
46 /* A parsed directive. */
49 const char* dir_start;
52 const char* width_start;
53 const char* width_end;
54 size_t width_arg_index;
55 const char* precision_start;
56 const char* precision_end;
57 size_t precision_arg_index;
58 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 */
63 /* A parsed format string. */
68 size_t max_width_length;
69 size_t max_precision_length;
75 /* A parsed directive. */
78 const uint8_t* dir_start;
79 const uint8_t* dir_end;
81 const uint8_t* width_start;
82 const uint8_t* width_end;
83 size_t width_arg_index;
84 const uint8_t* precision_start;
85 const uint8_t* precision_end;
86 size_t precision_arg_index;
87 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 */
92 /* A parsed format string. */
97 size_t max_width_length;
98 size_t max_precision_length;
102 /* A parsed directive. */
105 const uint16_t* dir_start;
106 const uint16_t* dir_end;
108 const uint16_t* width_start;
109 const uint16_t* width_end;
110 size_t width_arg_index;
111 const uint16_t* precision_start;
112 const uint16_t* precision_end;
113 size_t precision_arg_index;
114 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 */
119 /* A parsed format string. */
124 size_t max_width_length;
125 size_t max_precision_length;
129 /* A parsed directive. */
132 const uint32_t* dir_start;
133 const uint32_t* dir_end;
135 const uint32_t* width_start;
136 const uint32_t* width_end;
137 size_t width_arg_index;
138 const uint32_t* precision_start;
139 const uint32_t* precision_end;
140 size_t precision_arg_index;
141 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 */
146 /* A parsed format string. */
151 size_t max_width_length;
152 size_t max_precision_length;
159 /* Parses the format string. Fills in the number N of directives, and fills
160 in directives[0], ..., directives[N-1], and sets directives[N].dir_start
161 to the end of the format string. Also fills in the arg_type fields of the
162 arguments and the needed count of arguments. */
165 ulc_printf_parse (const char *format, char_directives *d, arguments *a);
167 u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a);
169 u16_printf_parse (const uint16_t *format, u16_directives *d,
172 u32_printf_parse (const uint32_t *format, u32_directives *d,
180 int printf_parse (const char *format, char_directives *d, arguments *a);
183 #endif /* _PRINTF_PARSE_H */