Temporarily fix `unistr.in.h' to allow compilation with `-Wundef'.
[bpt/guile.git] / lib / printf-parse.h
1 /* Parse printf format string.
2 Copyright (C) 1999, 2002-2003, 2005, 2007, 2009-2010 Free Software
3 Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser 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. */
18
19 #ifndef _PRINTF_PARSE_H
20 #define _PRINTF_PARSE_H
21
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. */
25
26 #if HAVE_FEATURES_H
27 # include <features.h> /* for __GLIBC__, __UCLIBC__ */
28 #endif
29
30 #include "printf-args.h"
31
32
33 /* Flags */
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 */
39 #define FLAG_ZERO 32
40 #if __GLIBC__ >= 2 && !defined __UCLIBC__
41 # define FLAG_LOCALIZED 64 /* I flag, uses localized digits */
42 #endif
43
44 /* arg_index value indicating that no argument is consumed. */
45 #define ARG_NONE (~(size_t)0)
46
47 /* xxx_directive: A parsed directive.
48 xxx_directives: A parsed format string. */
49
50 /* A parsed directive. */
51 typedef struct
52 {
53 const char* dir_start;
54 const char* dir_end;
55 int flags;
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 */
63 size_t arg_index;
64 }
65 char_directive;
66
67 /* A parsed format string. */
68 typedef struct
69 {
70 size_t count;
71 char_directive *dir;
72 size_t max_width_length;
73 size_t max_precision_length;
74 }
75 char_directives;
76
77 #if ENABLE_UNISTDIO
78
79 /* A parsed directive. */
80 typedef struct
81 {
82 const uint8_t* dir_start;
83 const uint8_t* dir_end;
84 int flags;
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 */
92 size_t arg_index;
93 }
94 u8_directive;
95
96 /* A parsed format string. */
97 typedef struct
98 {
99 size_t count;
100 u8_directive *dir;
101 size_t max_width_length;
102 size_t max_precision_length;
103 }
104 u8_directives;
105
106 /* A parsed directive. */
107 typedef struct
108 {
109 const uint16_t* dir_start;
110 const uint16_t* dir_end;
111 int flags;
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 */
119 size_t arg_index;
120 }
121 u16_directive;
122
123 /* A parsed format string. */
124 typedef struct
125 {
126 size_t count;
127 u16_directive *dir;
128 size_t max_width_length;
129 size_t max_precision_length;
130 }
131 u16_directives;
132
133 /* A parsed directive. */
134 typedef struct
135 {
136 const uint32_t* dir_start;
137 const uint32_t* dir_end;
138 int flags;
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 */
146 size_t arg_index;
147 }
148 u32_directive;
149
150 /* A parsed format string. */
151 typedef struct
152 {
153 size_t count;
154 u32_directive *dir;
155 size_t max_width_length;
156 size_t max_precision_length;
157 }
158 u32_directives;
159
160 #endif
161
162
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. */
167 #if ENABLE_UNISTDIO
168 extern int
169 ulc_printf_parse (const char *format, char_directives *d, arguments *a);
170 extern int
171 u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a);
172 extern int
173 u16_printf_parse (const uint16_t *format, u16_directives *d,
174 arguments *a);
175 extern int
176 u32_printf_parse (const uint32_t *format, u32_directives *d,
177 arguments *a);
178 #else
179 # ifdef STATIC
180 STATIC
181 # else
182 extern
183 # endif
184 int printf_parse (const char *format, char_directives *d, arguments *a);
185 #endif
186
187 #endif /* _PRINTF_PARSE_H */