41 # define PRINTF_PARSE printf_parse
43 # define DIRECTIVE char_directive
44 # define DIRECTIVES char_directives
51 #if defined IN_LIBINTL || defined IN_LIBASPRINTF
52 # if HAVE_STDINT_H_WITH_UINTMAX
55 # if HAVE_INTTYPES_H_WITH_UINTMAX
56 # include <inttypes.h>
89 size_t max_width_length = 0;
90 size_t max_precision_length = 0;
94 d->dir = d->direct_alloc_dir;
100 #define REGISTER_ARG(_index_,_type_) \
102 size_t n = (_index_); \
103 if (n >= a_allocated) \
105 size_t memory_size; \
108 a_allocated = xtimes (a_allocated, 2); \
109 if (a_allocated <= n) \
110 a_allocated = xsum (n, 1); \
111 memory_size = xtimes (a_allocated, sizeof (argument)); \
112 if (size_overflow_p (memory_size)) \
114 goto out_of_memory; \
115 memory = (argument *) (a->arg != a->direct_alloc_arg \
116 ? realloc (a->arg, memory_size) \
117 : malloc (memory_size)); \
118 if (memory == NULL) \
120 goto out_of_memory; \
121 if (a->arg == a->direct_alloc_arg) \
122 memcpy (memory, a->arg, a->count * sizeof (argument)); \
125 while (a->count <= n) \
126 a->arg[a->count++].type = TYPE_NONE; \
127 if (a->arg[n].type == TYPE_NONE) \
128 a->arg[n].type = (_type_); \
129 else if (a->arg[n].type != (_type_)) \
143 dp->dir_start =
cp - 1;
145 dp->width_start = NULL;
146 dp->width_end = NULL;
148 dp->precision_start = NULL;
149 dp->precision_end = NULL;
154 if (*
cp >=
'0' && *
cp <=
'9')
158 for (np =
cp; *np >=
'0' && *np <=
'9'; np++)
164 for (np =
cp; *np >=
'0' && *np <=
'9'; np++)
210 #if __GLIBC__ >= 2 && !defined __UCLIBC__
213 dp->flags |= FLAG_LOCALIZED;
224 dp->width_start =
cp;
227 if (max_width_length < 1)
228 max_width_length = 1;
231 if (*
cp >=
'0' && *
cp <=
'9')
235 for (np =
cp; *np >=
'0' && *np <=
'9'; np++)
241 for (np =
cp; *np >=
'0' && *np <=
'9'; np++)
249 dp->width_arg_index = n - 1;
253 if (dp->width_arg_index ==
ARG_NONE)
255 dp->width_arg_index = arg_posn++;
256 if (dp->width_arg_index ==
ARG_NONE)
262 else if (*
cp >=
'0' && *
cp <=
'9')
266 dp->width_start =
cp;
267 for (; *
cp >=
'0' && *
cp <=
'9';
cp++)
270 width_length = dp->width_end - dp->width_start;
271 if (max_width_length < width_length)
272 max_width_length = width_length;
281 dp->precision_start =
cp - 1;
283 dp->precision_end =
cp;
284 if (max_precision_length < 2)
285 max_precision_length = 2;
288 if (*
cp >=
'0' && *
cp <=
'9')
292 for (np =
cp; *np >=
'0' && *np <=
'9'; np++)
298 for (np =
cp; *np >=
'0' && *np <=
'9'; np++)
307 dp->precision_arg_index = n - 1;
311 if (dp->precision_arg_index ==
ARG_NONE)
313 dp->precision_arg_index = arg_posn++;
314 if (dp->precision_arg_index ==
ARG_NONE)
322 size_t precision_length;
324 dp->precision_start =
cp - 1;
325 for (; *
cp >=
'0' && *
cp <=
'9';
cp++)
327 dp->precision_end =
cp;
328 precision_length = dp->precision_end - dp->precision_start;
329 if (max_precision_length < precision_length)
330 max_precision_length = precision_length;
345 flags |= (1 << (flags & 1));
360 if (
sizeof (
intmax_t) >
sizeof (long))
372 else if (*
cp ==
'z' || *
cp ==
'Z')
377 if (
sizeof (
size_t) >
sizeof (long))
382 else if (
sizeof (
size_t) >
sizeof (
int))
391 if (
sizeof (ptrdiff_t) >
sizeof (long))
396 else if (
sizeof (ptrdiff_t) >
sizeof (
int))
403 #if defined __APPLE__ && defined __MACH__
409 if (64 / 8 >
sizeof (
long))
422 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
426 else if (*
cp ==
'I' &&
cp[1] ==
'6' &&
cp[2] ==
'4')
428 if (64 / 8 >
sizeof (
long))
450 #if HAVE_LONG_LONG_INT
452 if (flags >= 16 || (flags & 4))
453 type = TYPE_LONGLONGINT;
467 case 'o':
case 'u':
case 'x':
case 'X':
468 #if HAVE_LONG_LONG_INT
470 if (flags >= 16 || (flags & 4))
471 type = TYPE_ULONGLONGINT;
485 case 'f':
case 'F':
case 'e':
case 'E':
case 'g':
case 'G':
487 if (flags >= 16 || (flags & 4))
495 type = TYPE_WIDE_CHAR;
504 type = TYPE_WIDE_CHAR;
511 type = TYPE_WIDE_STRING;
520 type = TYPE_WIDE_STRING;
528 #if HAVE_LONG_LONG_INT
530 if (flags >= 16 || (flags & 4))
531 type = TYPE_COUNT_LONGLONGINT_POINTER;
549 type = TYPE_U32_STRING;
551 type = TYPE_U16_STRING;
553 type = TYPE_U8_STRING;
567 dp->arg_index = arg_index;
570 dp->arg_index = arg_posn++;
582 if (d->count >= d_allocated)
587 d_allocated =
xtimes (d_allocated, 2);
592 memory = (
DIRECTIVE *) (d->dir != d->direct_alloc_dir
593 ? realloc (d->dir, memory_size)
598 if (d->dir == d->direct_alloc_dir)
599 memcpy (memory, d->dir, d->count * sizeof (
DIRECTIVE));
603 #if CHAR_T_ONLY_ASCII
604 else if (!c_isascii (c))
611 d->dir[d->count].dir_start =
cp;
613 d->max_width_length = max_width_length;
614 d->max_precision_length = max_precision_length;
620 if (d->dir != d->direct_alloc_dir)
628 if (d->dir != d->direct_alloc_dir)
637 #undef CHAR_T_ONLY_ASCII
#define error(fun, msg)
NewGen interface with C3 type Psysteme for PIPS project.
void const char const char const int
struct _newgen_struct_type_ * type
#define N_DIRECT_ALLOC_ARGUMENTS
Number of directly allocated arguments (no malloc() needed).
@ TYPE_COUNT_SCHAR_POINTER
@ TYPE_COUNT_SHORT_POINTER
@ TYPE_COUNT_LONGINT_POINTER
#define REGISTER_ARG(_index_, _type_)
#define PRINTF_PARSE
Formatted output to strings.
#define FLAG_GROUP
Parse printf format string.
#define ARG_NONE
arg_index value indicating that no argument is consumed.
#define N_DIRECT_ALLOC_DIRECTIVES
xxx_directive: A parsed directive.
Pvecteur cp
pointeur sur l'egalite ou l'inegalite courante
argument direct_alloc_arg[N_DIRECT_ALLOC_ARGUMENTS]
#define size_overflow_p(SIZE)
Check for overflow.
#define xtimes(N, ELSIZE)
Multiplication of a count with an element size, with overflow check.
XSIZE_INLINE size_t xsum(size_t size1, size_t size2)
Sum of two sizes, with overflow check.