1 /* Copyright (C) 1991, 1992, 1995, 1996, 1999, 2000, 2002-2005, 2007, 2009
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 #include <sys/param.h>
27 #include "../locale/localeinfo.h"
29 #ifndef COMPILE_WPRINTF
31 # define UCHAR_T unsigned char
34 # define ISDIGIT(Ch) isdigit (Ch)
35 # define ISASCII(Ch) isascii (Ch)
36 # define MBRLEN(Cp, L, St) __mbrlen (Cp, L, St)
38 # define PUT(F, S, N) _IO_sputn (F, S, N)
39 # define PAD(Padchar) \
41 done += INTUSE(_IO_padn) (s, Padchar, width)
43 # define vfprintf vfwprintf
44 # define CHAR_T wchar_t
45 # define UCHAR_T uwchar_t
47 # define L_(Str) L##Str
48 # define ISDIGIT(Ch) iswdigit (Ch)
50 # define PUT(F, S, N) _IO_sputn (F, S, N)
51 # define PAD(Padchar) \
53 done += _IO_wpadn (s, Padchar, width)
56 #define DONT_NEED_READ_INT
57 #include "printf-parse.h"
61 parse_printf_format (fmt
, n
, argtypes
)
66 size_t nargs
; /* Number of arguments. */
67 size_t max_ref_arg
; /* Highest index used in a positional arg. */
68 struct printf_spec spec
;
69 const unsigned char *f
= (const unsigned char *) fmt
;
74 /* Search for format specifications. */
75 for (f
= __find_specmb (f
); *f
!= '\0'; f
= spec
.next_fmt
)
77 /* Parse this spec. */
78 nargs
+= __parse_one_specmb (f
, nargs
, &spec
, &max_ref_arg
);
80 /* If the width is determined by an argument this is an int. */
81 if (spec
.width_arg
!= -1 && (size_t) spec
.width_arg
< n
)
82 argtypes
[spec
.width_arg
] = PA_INT
;
84 /* If the precision is determined by an argument this is an int. */
85 if (spec
.prec_arg
!= -1 && (size_t) spec
.prec_arg
< n
)
86 argtypes
[spec
.prec_arg
] = PA_INT
;
88 if ((size_t) spec
.data_arg
< n
)
89 switch (spec
.ndata_args
)
91 case 0: /* No arguments. */
93 case 1: /* One argument; we already have the type. */
94 argtypes
[spec
.data_arg
] = spec
.data_arg_type
;
97 /* We have more than one argument for this format spec. We must
98 call the arginfo function again to determine all the types. */
99 (void) (*__printf_arginfo_table
[spec
.info
.spec
])
100 (&spec
.info
, n
- spec
.data_arg
, &argtypes
[spec
.data_arg
],
106 return MAX (nargs
, max_ref_arg
);