Whitespace fixes.
[glibc.git] / stdio-common / printf-parse.h
blob555ad78f335284f4c611521c1aaeaaa432967d07
1 /* Internal header for parsing printf format strings.
2 Copyright (C) 1995-1999, 2000, 2002, 2003, 2007, 2009
3 Free Software Foundation, Inc.
4 This file is part of th GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include <printf.h>
22 #include <stdint.h>
23 #include <stddef.h>
24 #include <string.h>
25 #include <wchar.h>
28 struct printf_spec
30 /* Information parsed from the format spec. */
31 struct printf_info info;
33 /* Pointers into the format string for the end of this format
34 spec and the next (or to the end of the string if no more). */
35 const UCHAR_T *end_of_fmt, *next_fmt;
37 /* Position of arguments for precision and width, or -1 if `info' has
38 the constant value. */
39 int prec_arg, width_arg;
41 int data_arg; /* Position of data argument. */
42 int data_arg_type; /* Type of first argument. */
43 /* Number of arguments consumed by this format specifier. */
44 size_t ndata_args;
45 /* Size of the parameter for PA_USER type. */
46 int size;
50 /* The various kinds off arguments that can be passed to printf. */
51 union printf_arg
53 wchar_t pa_wchar;
54 int pa_int;
55 long int pa_long_int;
56 long long int pa_long_long_int;
57 unsigned int pa_u_int;
58 unsigned long int pa_u_long_int;
59 unsigned long long int pa_u_long_long_int;
60 double pa_double;
61 long double pa_long_double;
62 const char *pa_string;
63 const wchar_t *pa_wstring;
64 void *pa_pointer;
65 void *pa_user;
69 #ifndef DONT_NEED_READ_INT
70 /* Read a simple integer from a string and update the string pointer.
71 It is assumed that the first character is a digit. */
72 static unsigned int
73 read_int (const UCHAR_T * *pstr)
75 unsigned int retval = **pstr - L_('0');
77 while (ISDIGIT (*++(*pstr)))
79 retval *= 10;
80 retval += **pstr - L_('0');
83 return retval;
85 #endif
88 /* These are defined in reg-printf.c. */
89 extern printf_arginfo_size_function **__printf_arginfo_table attribute_hidden;
90 extern printf_function **__printf_function_table attribute_hidden;
91 extern printf_va_arg_function **__printf_va_arg_table attribute_hidden;
94 /* Find the next spec in FORMAT, or the end of the string. Returns
95 a pointer into FORMAT, to a '%' or a '\0'. */
96 __extern_always_inline const unsigned char *
97 __find_specmb (const unsigned char *format)
99 return (const unsigned char *) __strchrnul ((const char *) format, '%');
102 __extern_always_inline const unsigned int *
103 __find_specwc (const unsigned int *format)
105 return (const unsigned int *) __wcschrnul ((const wchar_t *) format, L'%');
109 /* FORMAT must point to a '%' at the beginning of a spec. Fills in *SPEC
110 with the parsed details. POSN is the number of arguments already
111 consumed. At most MAXTYPES - POSN types are filled in TYPES. Return
112 the number of args consumed by this spec; *MAX_REF_ARG is updated so it
113 remains the highest argument index used. */
114 extern size_t __parse_one_specmb (const unsigned char *format, size_t posn,
115 struct printf_spec *spec,
116 size_t *max_ref_arg) attribute_hidden;
118 extern size_t __parse_one_specwc (const unsigned int *format, size_t posn,
119 struct printf_spec *spec,
120 size_t *max_ref_arg) attribute_hidden;
124 /* This variable is defined in reg-modifier.c. */
125 struct printf_modifier_record;
126 extern struct printf_modifier_record **__printf_modifier_table
127 attribute_hidden;
129 /* Handle registered modifiers. */
130 extern int __handle_registered_modifier_mb (const unsigned char **format,
131 struct printf_info *info)
132 attribute_hidden;
133 extern int __handle_registered_modifier_wc (const unsigned int **format,
134 struct printf_info *info)
135 attribute_hidden;