annotate lib/printf-parse.c @ 266:5f25e7afac21 2.6

Bumped version to 2.6
author lost
date Tue, 22 Dec 2009 05:32:28 +0000
parents 68fbca173508
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
265
68fbca173508 Added generated files for release
lost
parents:
diff changeset
1 /* Formatted output to strings.
68fbca173508 Added generated files for release
lost
parents:
diff changeset
2 Copyright (C) 1999-2000, 2002-2003, 2006-2008 Free Software Foundation, Inc.
68fbca173508 Added generated files for release
lost
parents:
diff changeset
3
68fbca173508 Added generated files for release
lost
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
68fbca173508 Added generated files for release
lost
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
68fbca173508 Added generated files for release
lost
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
7 any later version.
68fbca173508 Added generated files for release
lost
parents:
diff changeset
8
68fbca173508 Added generated files for release
lost
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
68fbca173508 Added generated files for release
lost
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
68fbca173508 Added generated files for release
lost
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68fbca173508 Added generated files for release
lost
parents:
diff changeset
12 GNU General Public License for more details.
68fbca173508 Added generated files for release
lost
parents:
diff changeset
13
68fbca173508 Added generated files for release
lost
parents:
diff changeset
14 You should have received a copy of the GNU General Public License along
68fbca173508 Added generated files for release
lost
parents:
diff changeset
15 with this program; if not, write to the Free Software Foundation,
68fbca173508 Added generated files for release
lost
parents:
diff changeset
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
17
68fbca173508 Added generated files for release
lost
parents:
diff changeset
18 /* This file can be parametrized with the following macros:
68fbca173508 Added generated files for release
lost
parents:
diff changeset
19 CHAR_T The element type of the format string.
68fbca173508 Added generated files for release
lost
parents:
diff changeset
20 CHAR_T_ONLY_ASCII Set to 1 to enable verification that all characters
68fbca173508 Added generated files for release
lost
parents:
diff changeset
21 in the format string are ASCII.
68fbca173508 Added generated files for release
lost
parents:
diff changeset
22 DIRECTIVE Structure denoting a format directive.
68fbca173508 Added generated files for release
lost
parents:
diff changeset
23 Depends on CHAR_T.
68fbca173508 Added generated files for release
lost
parents:
diff changeset
24 DIRECTIVES Structure denoting the set of format directives of a
68fbca173508 Added generated files for release
lost
parents:
diff changeset
25 format string. Depends on CHAR_T.
68fbca173508 Added generated files for release
lost
parents:
diff changeset
26 PRINTF_PARSE Function that parses a format string.
68fbca173508 Added generated files for release
lost
parents:
diff changeset
27 Depends on CHAR_T.
68fbca173508 Added generated files for release
lost
parents:
diff changeset
28 STATIC Set to 'static' to declare the function static.
68fbca173508 Added generated files for release
lost
parents:
diff changeset
29 ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
30
68fbca173508 Added generated files for release
lost
parents:
diff changeset
31 #ifndef PRINTF_PARSE
68fbca173508 Added generated files for release
lost
parents:
diff changeset
32 # include <config.h>
68fbca173508 Added generated files for release
lost
parents:
diff changeset
33 #endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
34
68fbca173508 Added generated files for release
lost
parents:
diff changeset
35 /* Specification. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
36 #ifndef PRINTF_PARSE
68fbca173508 Added generated files for release
lost
parents:
diff changeset
37 # include "printf-parse.h"
68fbca173508 Added generated files for release
lost
parents:
diff changeset
38 #endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
39
68fbca173508 Added generated files for release
lost
parents:
diff changeset
40 /* Default parameters. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
41 #ifndef PRINTF_PARSE
68fbca173508 Added generated files for release
lost
parents:
diff changeset
42 # define PRINTF_PARSE printf_parse
68fbca173508 Added generated files for release
lost
parents:
diff changeset
43 # define CHAR_T char
68fbca173508 Added generated files for release
lost
parents:
diff changeset
44 # define DIRECTIVE char_directive
68fbca173508 Added generated files for release
lost
parents:
diff changeset
45 # define DIRECTIVES char_directives
68fbca173508 Added generated files for release
lost
parents:
diff changeset
46 #endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
47
68fbca173508 Added generated files for release
lost
parents:
diff changeset
48 /* Get size_t, NULL. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
49 #include <stddef.h>
68fbca173508 Added generated files for release
lost
parents:
diff changeset
50
68fbca173508 Added generated files for release
lost
parents:
diff changeset
51 /* Get intmax_t. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
52 #if defined IN_LIBINTL || defined IN_LIBASPRINTF
68fbca173508 Added generated files for release
lost
parents:
diff changeset
53 # if HAVE_STDINT_H_WITH_UINTMAX
68fbca173508 Added generated files for release
lost
parents:
diff changeset
54 # include <stdint.h>
68fbca173508 Added generated files for release
lost
parents:
diff changeset
55 # endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
56 # if HAVE_INTTYPES_H_WITH_UINTMAX
68fbca173508 Added generated files for release
lost
parents:
diff changeset
57 # include <inttypes.h>
68fbca173508 Added generated files for release
lost
parents:
diff changeset
58 # endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
59 #else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
60 # include <stdint.h>
68fbca173508 Added generated files for release
lost
parents:
diff changeset
61 #endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
62
68fbca173508 Added generated files for release
lost
parents:
diff changeset
63 /* malloc(), realloc(), free(). */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
64 #include <stdlib.h>
68fbca173508 Added generated files for release
lost
parents:
diff changeset
65
68fbca173508 Added generated files for release
lost
parents:
diff changeset
66 /* errno. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
67 #include <errno.h>
68fbca173508 Added generated files for release
lost
parents:
diff changeset
68
68fbca173508 Added generated files for release
lost
parents:
diff changeset
69 /* Checked size_t computations. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
70 #include "xsize.h"
68fbca173508 Added generated files for release
lost
parents:
diff changeset
71
68fbca173508 Added generated files for release
lost
parents:
diff changeset
72 #if CHAR_T_ONLY_ASCII
68fbca173508 Added generated files for release
lost
parents:
diff changeset
73 /* c_isascii(). */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
74 # include "c-ctype.h"
68fbca173508 Added generated files for release
lost
parents:
diff changeset
75 #endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
76
68fbca173508 Added generated files for release
lost
parents:
diff changeset
77 #ifdef STATIC
68fbca173508 Added generated files for release
lost
parents:
diff changeset
78 STATIC
68fbca173508 Added generated files for release
lost
parents:
diff changeset
79 #endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
80 int
68fbca173508 Added generated files for release
lost
parents:
diff changeset
81 PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
82 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
83 const CHAR_T *cp = format; /* pointer into format */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
84 size_t arg_posn = 0; /* number of regular arguments consumed */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
85 size_t d_allocated; /* allocated elements of d->dir */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
86 size_t a_allocated; /* allocated elements of a->arg */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
87 size_t max_width_length = 0;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
88 size_t max_precision_length = 0;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
89
68fbca173508 Added generated files for release
lost
parents:
diff changeset
90 d->count = 0;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
91 d_allocated = 1;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
92 d->dir = (DIRECTIVE *) malloc (d_allocated * sizeof (DIRECTIVE));
68fbca173508 Added generated files for release
lost
parents:
diff changeset
93 if (d->dir == NULL)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
94 /* Out of memory. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
95 goto out_of_memory_1;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
96
68fbca173508 Added generated files for release
lost
parents:
diff changeset
97 a->count = 0;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
98 a_allocated = 0;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
99 a->arg = NULL;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
100
68fbca173508 Added generated files for release
lost
parents:
diff changeset
101 #define REGISTER_ARG(_index_,_type_) \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
102 { \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
103 size_t n = (_index_); \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
104 if (n >= a_allocated) \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
105 { \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
106 size_t memory_size; \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
107 argument *memory; \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
108 \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
109 a_allocated = xtimes (a_allocated, 2); \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
110 if (a_allocated <= n) \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
111 a_allocated = xsum (n, 1); \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
112 memory_size = xtimes (a_allocated, sizeof (argument)); \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
113 if (size_overflow_p (memory_size)) \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
114 /* Overflow, would lead to out of memory. */ \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
115 goto out_of_memory; \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
116 memory = (argument *) (a->arg \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
117 ? realloc (a->arg, memory_size) \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
118 : malloc (memory_size)); \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
119 if (memory == NULL) \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
120 /* Out of memory. */ \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
121 goto out_of_memory; \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
122 a->arg = memory; \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
123 } \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
124 while (a->count <= n) \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
125 a->arg[a->count++].type = TYPE_NONE; \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
126 if (a->arg[n].type == TYPE_NONE) \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
127 a->arg[n].type = (_type_); \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
128 else if (a->arg[n].type != (_type_)) \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
129 /* Ambiguous type for positional argument. */ \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
130 goto error; \
68fbca173508 Added generated files for release
lost
parents:
diff changeset
131 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
132
68fbca173508 Added generated files for release
lost
parents:
diff changeset
133 while (*cp != '\0')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
134 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
135 CHAR_T c = *cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
136 if (c == '%')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
137 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
138 size_t arg_index = ARG_NONE;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
139 DIRECTIVE *dp = &d->dir[d->count]; /* pointer to next directive */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
140
68fbca173508 Added generated files for release
lost
parents:
diff changeset
141 /* Initialize the next directive. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
142 dp->dir_start = cp - 1;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
143 dp->flags = 0;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
144 dp->width_start = NULL;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
145 dp->width_end = NULL;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
146 dp->width_arg_index = ARG_NONE;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
147 dp->precision_start = NULL;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
148 dp->precision_end = NULL;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
149 dp->precision_arg_index = ARG_NONE;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
150 dp->arg_index = ARG_NONE;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
151
68fbca173508 Added generated files for release
lost
parents:
diff changeset
152 /* Test for positional argument. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
153 if (*cp >= '0' && *cp <= '9')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
154 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
155 const CHAR_T *np;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
156
68fbca173508 Added generated files for release
lost
parents:
diff changeset
157 for (np = cp; *np >= '0' && *np <= '9'; np++)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
158 ;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
159 if (*np == '$')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
160 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
161 size_t n = 0;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
162
68fbca173508 Added generated files for release
lost
parents:
diff changeset
163 for (np = cp; *np >= '0' && *np <= '9'; np++)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
164 n = xsum (xtimes (n, 10), *np - '0');
68fbca173508 Added generated files for release
lost
parents:
diff changeset
165 if (n == 0)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
166 /* Positional argument 0. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
167 goto error;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
168 if (size_overflow_p (n))
68fbca173508 Added generated files for release
lost
parents:
diff changeset
169 /* n too large, would lead to out of memory later. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
170 goto error;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
171 arg_index = n - 1;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
172 cp = np + 1;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
173 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
174 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
175
68fbca173508 Added generated files for release
lost
parents:
diff changeset
176 /* Read the flags. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
177 for (;;)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
178 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
179 if (*cp == '\'')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
180 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
181 dp->flags |= FLAG_GROUP;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
182 cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
183 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
184 else if (*cp == '-')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
185 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
186 dp->flags |= FLAG_LEFT;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
187 cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
188 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
189 else if (*cp == '+')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
190 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
191 dp->flags |= FLAG_SHOWSIGN;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
192 cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
193 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
194 else if (*cp == ' ')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
195 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
196 dp->flags |= FLAG_SPACE;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
197 cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
198 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
199 else if (*cp == '#')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
200 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
201 dp->flags |= FLAG_ALT;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
202 cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
203 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
204 else if (*cp == '0')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
205 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
206 dp->flags |= FLAG_ZERO;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
207 cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
208 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
209 else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
210 break;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
211 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
212
68fbca173508 Added generated files for release
lost
parents:
diff changeset
213 /* Parse the field width. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
214 if (*cp == '*')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
215 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
216 dp->width_start = cp;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
217 cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
218 dp->width_end = cp;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
219 if (max_width_length < 1)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
220 max_width_length = 1;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
221
68fbca173508 Added generated files for release
lost
parents:
diff changeset
222 /* Test for positional argument. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
223 if (*cp >= '0' && *cp <= '9')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
224 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
225 const CHAR_T *np;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
226
68fbca173508 Added generated files for release
lost
parents:
diff changeset
227 for (np = cp; *np >= '0' && *np <= '9'; np++)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
228 ;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
229 if (*np == '$')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
230 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
231 size_t n = 0;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
232
68fbca173508 Added generated files for release
lost
parents:
diff changeset
233 for (np = cp; *np >= '0' && *np <= '9'; np++)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
234 n = xsum (xtimes (n, 10), *np - '0');
68fbca173508 Added generated files for release
lost
parents:
diff changeset
235 if (n == 0)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
236 /* Positional argument 0. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
237 goto error;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
238 if (size_overflow_p (n))
68fbca173508 Added generated files for release
lost
parents:
diff changeset
239 /* n too large, would lead to out of memory later. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
240 goto error;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
241 dp->width_arg_index = n - 1;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
242 cp = np + 1;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
243 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
244 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
245 if (dp->width_arg_index == ARG_NONE)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
246 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
247 dp->width_arg_index = arg_posn++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
248 if (dp->width_arg_index == ARG_NONE)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
249 /* arg_posn wrapped around. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
250 goto error;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
251 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
252 REGISTER_ARG (dp->width_arg_index, TYPE_INT);
68fbca173508 Added generated files for release
lost
parents:
diff changeset
253 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
254 else if (*cp >= '0' && *cp <= '9')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
255 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
256 size_t width_length;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
257
68fbca173508 Added generated files for release
lost
parents:
diff changeset
258 dp->width_start = cp;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
259 for (; *cp >= '0' && *cp <= '9'; cp++)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
260 ;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
261 dp->width_end = cp;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
262 width_length = dp->width_end - dp->width_start;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
263 if (max_width_length < width_length)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
264 max_width_length = width_length;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
265 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
266
68fbca173508 Added generated files for release
lost
parents:
diff changeset
267 /* Parse the precision. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
268 if (*cp == '.')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
269 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
270 cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
271 if (*cp == '*')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
272 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
273 dp->precision_start = cp - 1;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
274 cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
275 dp->precision_end = cp;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
276 if (max_precision_length < 2)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
277 max_precision_length = 2;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
278
68fbca173508 Added generated files for release
lost
parents:
diff changeset
279 /* Test for positional argument. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
280 if (*cp >= '0' && *cp <= '9')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
281 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
282 const CHAR_T *np;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
283
68fbca173508 Added generated files for release
lost
parents:
diff changeset
284 for (np = cp; *np >= '0' && *np <= '9'; np++)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
285 ;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
286 if (*np == '$')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
287 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
288 size_t n = 0;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
289
68fbca173508 Added generated files for release
lost
parents:
diff changeset
290 for (np = cp; *np >= '0' && *np <= '9'; np++)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
291 n = xsum (xtimes (n, 10), *np - '0');
68fbca173508 Added generated files for release
lost
parents:
diff changeset
292 if (n == 0)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
293 /* Positional argument 0. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
294 goto error;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
295 if (size_overflow_p (n))
68fbca173508 Added generated files for release
lost
parents:
diff changeset
296 /* n too large, would lead to out of memory
68fbca173508 Added generated files for release
lost
parents:
diff changeset
297 later. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
298 goto error;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
299 dp->precision_arg_index = n - 1;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
300 cp = np + 1;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
301 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
302 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
303 if (dp->precision_arg_index == ARG_NONE)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
304 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
305 dp->precision_arg_index = arg_posn++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
306 if (dp->precision_arg_index == ARG_NONE)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
307 /* arg_posn wrapped around. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
308 goto error;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
309 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
310 REGISTER_ARG (dp->precision_arg_index, TYPE_INT);
68fbca173508 Added generated files for release
lost
parents:
diff changeset
311 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
312 else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
313 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
314 size_t precision_length;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
315
68fbca173508 Added generated files for release
lost
parents:
diff changeset
316 dp->precision_start = cp - 1;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
317 for (; *cp >= '0' && *cp <= '9'; cp++)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
318 ;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
319 dp->precision_end = cp;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
320 precision_length = dp->precision_end - dp->precision_start;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
321 if (max_precision_length < precision_length)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
322 max_precision_length = precision_length;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
323 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
324 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
325
68fbca173508 Added generated files for release
lost
parents:
diff changeset
326 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
327 arg_type type;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
328
68fbca173508 Added generated files for release
lost
parents:
diff changeset
329 /* Parse argument type/size specifiers. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
330 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
331 int flags = 0;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
332
68fbca173508 Added generated files for release
lost
parents:
diff changeset
333 for (;;)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
334 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
335 if (*cp == 'h')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
336 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
337 flags |= (1 << (flags & 1));
68fbca173508 Added generated files for release
lost
parents:
diff changeset
338 cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
339 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
340 else if (*cp == 'L')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
341 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
342 flags |= 4;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
343 cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
344 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
345 else if (*cp == 'l')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
346 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
347 flags += 8;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
348 cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
349 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
350 else if (*cp == 'j')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
351 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
352 if (sizeof (intmax_t) > sizeof (long))
68fbca173508 Added generated files for release
lost
parents:
diff changeset
353 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
354 /* intmax_t = long long */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
355 flags += 16;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
356 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
357 else if (sizeof (intmax_t) > sizeof (int))
68fbca173508 Added generated files for release
lost
parents:
diff changeset
358 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
359 /* intmax_t = long */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
360 flags += 8;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
361 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
362 cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
363 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
364 else if (*cp == 'z' || *cp == 'Z')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
365 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
366 /* 'z' is standardized in ISO C 99, but glibc uses 'Z'
68fbca173508 Added generated files for release
lost
parents:
diff changeset
367 because the warning facility in gcc-2.95.2 understands
68fbca173508 Added generated files for release
lost
parents:
diff changeset
368 only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
369 if (sizeof (size_t) > sizeof (long))
68fbca173508 Added generated files for release
lost
parents:
diff changeset
370 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
371 /* size_t = long long */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
372 flags += 16;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
373 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
374 else if (sizeof (size_t) > sizeof (int))
68fbca173508 Added generated files for release
lost
parents:
diff changeset
375 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
376 /* size_t = long */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
377 flags += 8;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
378 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
379 cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
380 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
381 else if (*cp == 't')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
382 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
383 if (sizeof (ptrdiff_t) > sizeof (long))
68fbca173508 Added generated files for release
lost
parents:
diff changeset
384 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
385 /* ptrdiff_t = long long */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
386 flags += 16;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
387 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
388 else if (sizeof (ptrdiff_t) > sizeof (int))
68fbca173508 Added generated files for release
lost
parents:
diff changeset
389 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
390 /* ptrdiff_t = long */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
391 flags += 8;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
392 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
393 cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
394 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
395 #if defined __APPLE__ && defined __MACH__
68fbca173508 Added generated files for release
lost
parents:
diff changeset
396 /* On MacOS X 10.3, PRIdMAX is defined as "qd".
68fbca173508 Added generated files for release
lost
parents:
diff changeset
397 We cannot change it to "lld" because PRIdMAX must also
68fbca173508 Added generated files for release
lost
parents:
diff changeset
398 be understood by the system's printf routines. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
399 else if (*cp == 'q')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
400 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
401 if (64 / 8 > sizeof (long))
68fbca173508 Added generated files for release
lost
parents:
diff changeset
402 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
403 /* int64_t = long long */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
404 flags += 16;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
405 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
406 else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
407 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
408 /* int64_t = long */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
409 flags += 8;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
410 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
411 cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
412 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
413 #endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
414 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
68fbca173508 Added generated files for release
lost
parents:
diff changeset
415 /* On native Win32, PRIdMAX is defined as "I64d".
68fbca173508 Added generated files for release
lost
parents:
diff changeset
416 We cannot change it to "lld" because PRIdMAX must also
68fbca173508 Added generated files for release
lost
parents:
diff changeset
417 be understood by the system's printf routines. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
418 else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4')
68fbca173508 Added generated files for release
lost
parents:
diff changeset
419 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
420 if (64 / 8 > sizeof (long))
68fbca173508 Added generated files for release
lost
parents:
diff changeset
421 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
422 /* __int64 = long long */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
423 flags += 16;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
424 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
425 else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
426 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
427 /* __int64 = long */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
428 flags += 8;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
429 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
430 cp += 3;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
431 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
432 #endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
433 else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
434 break;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
435 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
436
68fbca173508 Added generated files for release
lost
parents:
diff changeset
437 /* Read the conversion character. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
438 c = *cp++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
439 switch (c)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
440 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
441 case 'd': case 'i':
68fbca173508 Added generated files for release
lost
parents:
diff changeset
442 #if HAVE_LONG_LONG_INT
68fbca173508 Added generated files for release
lost
parents:
diff changeset
443 /* If 'long long' exists and is larger than 'long': */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
444 if (flags >= 16 || (flags & 4))
68fbca173508 Added generated files for release
lost
parents:
diff changeset
445 type = TYPE_LONGLONGINT;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
446 else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
447 #endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
448 /* If 'long long' exists and is the same as 'long', we parse
68fbca173508 Added generated files for release
lost
parents:
diff changeset
449 "lld" into TYPE_LONGINT. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
450 if (flags >= 8)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
451 type = TYPE_LONGINT;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
452 else if (flags & 2)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
453 type = TYPE_SCHAR;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
454 else if (flags & 1)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
455 type = TYPE_SHORT;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
456 else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
457 type = TYPE_INT;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
458 break;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
459 case 'o': case 'u': case 'x': case 'X':
68fbca173508 Added generated files for release
lost
parents:
diff changeset
460 #if HAVE_LONG_LONG_INT
68fbca173508 Added generated files for release
lost
parents:
diff changeset
461 /* If 'long long' exists and is larger than 'long': */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
462 if (flags >= 16 || (flags & 4))
68fbca173508 Added generated files for release
lost
parents:
diff changeset
463 type = TYPE_ULONGLONGINT;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
464 else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
465 #endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
466 /* If 'unsigned long long' exists and is the same as
68fbca173508 Added generated files for release
lost
parents:
diff changeset
467 'unsigned long', we parse "llu" into TYPE_ULONGINT. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
468 if (flags >= 8)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
469 type = TYPE_ULONGINT;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
470 else if (flags & 2)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
471 type = TYPE_UCHAR;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
472 else if (flags & 1)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
473 type = TYPE_USHORT;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
474 else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
475 type = TYPE_UINT;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
476 break;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
477 case 'f': case 'F': case 'e': case 'E': case 'g': case 'G':
68fbca173508 Added generated files for release
lost
parents:
diff changeset
478 case 'a': case 'A':
68fbca173508 Added generated files for release
lost
parents:
diff changeset
479 if (flags >= 16 || (flags & 4))
68fbca173508 Added generated files for release
lost
parents:
diff changeset
480 type = TYPE_LONGDOUBLE;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
481 else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
482 type = TYPE_DOUBLE;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
483 break;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
484 case 'c':
68fbca173508 Added generated files for release
lost
parents:
diff changeset
485 if (flags >= 8)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
486 #if HAVE_WINT_T
68fbca173508 Added generated files for release
lost
parents:
diff changeset
487 type = TYPE_WIDE_CHAR;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
488 #else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
489 goto error;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
490 #endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
491 else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
492 type = TYPE_CHAR;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
493 break;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
494 #if HAVE_WINT_T
68fbca173508 Added generated files for release
lost
parents:
diff changeset
495 case 'C':
68fbca173508 Added generated files for release
lost
parents:
diff changeset
496 type = TYPE_WIDE_CHAR;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
497 c = 'c';
68fbca173508 Added generated files for release
lost
parents:
diff changeset
498 break;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
499 #endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
500 case 's':
68fbca173508 Added generated files for release
lost
parents:
diff changeset
501 if (flags >= 8)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
502 #if HAVE_WCHAR_T
68fbca173508 Added generated files for release
lost
parents:
diff changeset
503 type = TYPE_WIDE_STRING;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
504 #else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
505 goto error;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
506 #endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
507 else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
508 type = TYPE_STRING;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
509 break;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
510 #if HAVE_WCHAR_T
68fbca173508 Added generated files for release
lost
parents:
diff changeset
511 case 'S':
68fbca173508 Added generated files for release
lost
parents:
diff changeset
512 type = TYPE_WIDE_STRING;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
513 c = 's';
68fbca173508 Added generated files for release
lost
parents:
diff changeset
514 break;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
515 #endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
516 case 'p':
68fbca173508 Added generated files for release
lost
parents:
diff changeset
517 type = TYPE_POINTER;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
518 break;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
519 case 'n':
68fbca173508 Added generated files for release
lost
parents:
diff changeset
520 #if HAVE_LONG_LONG_INT
68fbca173508 Added generated files for release
lost
parents:
diff changeset
521 /* If 'long long' exists and is larger than 'long': */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
522 if (flags >= 16 || (flags & 4))
68fbca173508 Added generated files for release
lost
parents:
diff changeset
523 type = TYPE_COUNT_LONGLONGINT_POINTER;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
524 else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
525 #endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
526 /* If 'long long' exists and is the same as 'long', we parse
68fbca173508 Added generated files for release
lost
parents:
diff changeset
527 "lln" into TYPE_COUNT_LONGINT_POINTER. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
528 if (flags >= 8)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
529 type = TYPE_COUNT_LONGINT_POINTER;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
530 else if (flags & 2)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
531 type = TYPE_COUNT_SCHAR_POINTER;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
532 else if (flags & 1)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
533 type = TYPE_COUNT_SHORT_POINTER;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
534 else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
535 type = TYPE_COUNT_INT_POINTER;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
536 break;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
537 #if ENABLE_UNISTDIO
68fbca173508 Added generated files for release
lost
parents:
diff changeset
538 /* The unistdio extensions. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
539 case 'U':
68fbca173508 Added generated files for release
lost
parents:
diff changeset
540 if (flags >= 16)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
541 type = TYPE_U32_STRING;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
542 else if (flags >= 8)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
543 type = TYPE_U16_STRING;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
544 else
68fbca173508 Added generated files for release
lost
parents:
diff changeset
545 type = TYPE_U8_STRING;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
546 break;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
547 #endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
548 case '%':
68fbca173508 Added generated files for release
lost
parents:
diff changeset
549 type = TYPE_NONE;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
550 break;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
551 default:
68fbca173508 Added generated files for release
lost
parents:
diff changeset
552 /* Unknown conversion character. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
553 goto error;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
554 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
555 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
556
68fbca173508 Added generated files for release
lost
parents:
diff changeset
557 if (type != TYPE_NONE)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
558 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
559 dp->arg_index = arg_index;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
560 if (dp->arg_index == ARG_NONE)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
561 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
562 dp->arg_index = arg_posn++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
563 if (dp->arg_index == ARG_NONE)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
564 /* arg_posn wrapped around. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
565 goto error;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
566 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
567 REGISTER_ARG (dp->arg_index, type);
68fbca173508 Added generated files for release
lost
parents:
diff changeset
568 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
569 dp->conversion = c;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
570 dp->dir_end = cp;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
571 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
572
68fbca173508 Added generated files for release
lost
parents:
diff changeset
573 d->count++;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
574 if (d->count >= d_allocated)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
575 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
576 size_t memory_size;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
577 DIRECTIVE *memory;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
578
68fbca173508 Added generated files for release
lost
parents:
diff changeset
579 d_allocated = xtimes (d_allocated, 2);
68fbca173508 Added generated files for release
lost
parents:
diff changeset
580 memory_size = xtimes (d_allocated, sizeof (DIRECTIVE));
68fbca173508 Added generated files for release
lost
parents:
diff changeset
581 if (size_overflow_p (memory_size))
68fbca173508 Added generated files for release
lost
parents:
diff changeset
582 /* Overflow, would lead to out of memory. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
583 goto out_of_memory;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
584 memory = (DIRECTIVE *) realloc (d->dir, memory_size);
68fbca173508 Added generated files for release
lost
parents:
diff changeset
585 if (memory == NULL)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
586 /* Out of memory. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
587 goto out_of_memory;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
588 d->dir = memory;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
589 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
590 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
591 #if CHAR_T_ONLY_ASCII
68fbca173508 Added generated files for release
lost
parents:
diff changeset
592 else if (!c_isascii (c))
68fbca173508 Added generated files for release
lost
parents:
diff changeset
593 {
68fbca173508 Added generated files for release
lost
parents:
diff changeset
594 /* Non-ASCII character. Not supported. */
68fbca173508 Added generated files for release
lost
parents:
diff changeset
595 goto error;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
596 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
597 #endif
68fbca173508 Added generated files for release
lost
parents:
diff changeset
598 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
599 d->dir[d->count].dir_start = cp;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
600
68fbca173508 Added generated files for release
lost
parents:
diff changeset
601 d->max_width_length = max_width_length;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
602 d->max_precision_length = max_precision_length;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
603 return 0;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
604
68fbca173508 Added generated files for release
lost
parents:
diff changeset
605 error:
68fbca173508 Added generated files for release
lost
parents:
diff changeset
606 if (a->arg)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
607 free (a->arg);
68fbca173508 Added generated files for release
lost
parents:
diff changeset
608 if (d->dir)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
609 free (d->dir);
68fbca173508 Added generated files for release
lost
parents:
diff changeset
610 errno = EINVAL;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
611 return -1;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
612
68fbca173508 Added generated files for release
lost
parents:
diff changeset
613 out_of_memory:
68fbca173508 Added generated files for release
lost
parents:
diff changeset
614 if (a->arg)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
615 free (a->arg);
68fbca173508 Added generated files for release
lost
parents:
diff changeset
616 if (d->dir)
68fbca173508 Added generated files for release
lost
parents:
diff changeset
617 free (d->dir);
68fbca173508 Added generated files for release
lost
parents:
diff changeset
618 out_of_memory_1:
68fbca173508 Added generated files for release
lost
parents:
diff changeset
619 errno = ENOMEM;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
620 return -1;
68fbca173508 Added generated files for release
lost
parents:
diff changeset
621 }
68fbca173508 Added generated files for release
lost
parents:
diff changeset
622
68fbca173508 Added generated files for release
lost
parents:
diff changeset
623 #undef PRINTF_PARSE
68fbca173508 Added generated files for release
lost
parents:
diff changeset
624 #undef DIRECTIVES
68fbca173508 Added generated files for release
lost
parents:
diff changeset
625 #undef DIRECTIVE
68fbca173508 Added generated files for release
lost
parents:
diff changeset
626 #undef CHAR_T_ONLY_ASCII
68fbca173508 Added generated files for release
lost
parents:
diff changeset
627 #undef CHAR_T