1 /* Parse printf format string.
2 Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2011 Free Software Foundation, Inc.
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.
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.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 #ifndef _PRINTF_PARSE_H
18 #define _PRINTF_PARSE_H
21 # include <features.h> /* for __GLIBC__, __UCLIBC__ */
24 #include "printf-args.h"
28 #define FLAG_GROUP 1 /* ' flag */
29 #define FLAG_LEFT 2 /* - flag */
30 #define FLAG_SHOWSIGN 4 /* + flag */
31 #define FLAG_SPACE 8 /* space flag */
32 #define FLAG_ALT 16 /* # flag */
34 #if __GLIBC__ >= 2 && !defined __UCLIBC__
35 # define FLAG_LOCALIZED 64 /* I flag, uses localized digits */
38 /* arg_index value indicating that no argument is consumed. */
39 #define ARG_NONE (~(size_t)0)
41 /* Number of directly allocated directives (no malloc() needed). */
42 #define N_DIRECT_ALLOC_DIRECTIVES 7
44 /* A parsed directive. */
47 const char* dir_start;
50 const char* width_start;
51 const char* width_end;
52 size_t width_arg_index;
53 const char* precision_start;
54 const char* precision_end;
55 size_t precision_arg_index;
56 char conversion; /* d i o u x X f e E g G c s p n U % but not C S */
61 /* A parsed format string. */
66 size_t max_width_length;
67 size_t max_precision_length;
68 char_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
73 /* Parses the format string. Fills in the number N of directives, and fills
74 in directives[0], ..., directives[N-1], and sets directives[N].dir_start
75 to the end of the format string. Also fills in the arg_type fields of the
76 arguments and the needed count of arguments. */
82 int printf_parse (const char *format, char_directives *d, arguments *a);
84 #endif /* _PRINTF_PARSE_H */