1 /* Copyright (C) 1991, 1992, 1995, 1996, 1999, 2000, 2002, 2003, 2004, 2005
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
;
70 const unsigned char *f
= (const unsigned char *) fmt
;
75 /* Search for format specifications. */
76 for (f
= __find_specmb (f
, &mbstate
); *f
!= '\0'; f
= spec
.next_fmt
)
78 /* Parse this spec. */
79 nargs
+= __parse_one_specmb (f
, nargs
, &spec
, &max_ref_arg
, &mbstate
);
81 /* If the width is determined by an argument this is an int. */
82 if (spec
.width_arg
!= -1 && (size_t) spec
.width_arg
< n
)
83 argtypes
[spec
.width_arg
] = PA_INT
;
85 /* If the precision is determined by an argument this is an int. */
86 if (spec
.prec_arg
!= -1 && (size_t) spec
.prec_arg
< n
)
87 argtypes
[spec
.prec_arg
] = PA_INT
;
89 if ((size_t) spec
.data_arg
< n
)
90 switch (spec
.ndata_args
)
92 case 0: /* No arguments. */
94 case 1: /* One argument; we already have the type. */
95 argtypes
[spec
.data_arg
] = spec
.data_arg_type
;
98 /* We have more than one argument for this format spec. We must
99 call the arginfo function again to determine all the types. */
100 (void) (*__printf_arginfo_table
[spec
.info
.spec
])
101 (&spec
.info
, n
- spec
.data_arg
, &argtypes
[spec
.data_arg
]);
106 return MAX (nargs
, max_ref_arg
);