annotate lib/printf-parse.c @ 425:67815606c5d9 3.0-beta2

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