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 3, 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 /* A parsed directive. */
53 const char* dir_start
;
56 const char* width_start
;
57 const char* width_end
;
58 size_t width_arg_index
;
59 const char* precision_start
;
60 const char* precision_end
;
61 size_t precision_arg_index
;
62 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 */
67 /* A parsed format string. */
72 size_t max_width_length
;
73 size_t max_precision_length
;
79 /* A parsed directive. */
82 const uint8_t* dir_start
;
83 const uint8_t* dir_end
;
85 const uint8_t* width_start
;
86 const uint8_t* width_end
;
87 size_t width_arg_index
;
88 const uint8_t* precision_start
;
89 const uint8_t* precision_end
;
90 size_t precision_arg_index
;
91 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 */
96 /* A parsed format string. */
101 size_t max_width_length
;
102 size_t max_precision_length
;
106 /* A parsed directive. */
109 const uint16_t* dir_start
;
110 const uint16_t* dir_end
;
112 const uint16_t* width_start
;
113 const uint16_t* width_end
;
114 size_t width_arg_index
;
115 const uint16_t* precision_start
;
116 const uint16_t* precision_end
;
117 size_t precision_arg_index
;
118 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 */
123 /* A parsed format string. */
128 size_t max_width_length
;
129 size_t max_precision_length
;
133 /* A parsed directive. */
136 const uint32_t* dir_start
;
137 const uint32_t* dir_end
;
139 const uint32_t* width_start
;
140 const uint32_t* width_end
;
141 size_t width_arg_index
;
142 const uint32_t* precision_start
;
143 const uint32_t* precision_end
;
144 size_t precision_arg_index
;
145 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 */
150 /* A parsed format string. */
155 size_t max_width_length
;
156 size_t max_precision_length
;
163 /* Parses the format string. Fills in the number N of directives, and fills
164 in directives[0], ..., directives[N-1], and sets directives[N].dir_start
165 to the end of the format string. Also fills in the arg_type fields of the
166 arguments and the needed count of arguments. */
169 ulc_printf_parse (const char *format
, char_directives
*d
, arguments
*a
);
171 u8_printf_parse (const uint8_t *format
, u8_directives
*d
, arguments
*a
);
173 u16_printf_parse (const uint16_t *format
, u16_directives
*d
,
176 u32_printf_parse (const uint32_t *format
, u32_directives
*d
,
184 int printf_parse (const char *format
, char_directives
*d
, arguments
*a
);
187 #endif /* _PRINTF_PARSE_H */