maint: update all copyright year number ranges
[gnulib.git] / lib / printf-parse.h
1 /* Parse printf format string.
2    Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2012 Free Software
3    Foundation, Inc.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2, or (at your option)
8    any later version.
9
10    This program 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
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License along
16    with this program; if not, write to the Free Software Foundation,
17    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
18
19 #ifndef _PRINTF_PARSE_H
20 #define _PRINTF_PARSE_H
21
22 /* This file can be parametrized with the following macros:
23      ENABLE_UNISTDIO    Set to 1 to enable the unistdio extensions.
24      STATIC             Set to 'static' to declare the function static.  */
25
26 #if HAVE_FEATURES_H
27 # include <features.h> /* for __GLIBC__, __UCLIBC__ */
28 #endif
29
30 #include "printf-args.h"
31
32
33 /* Flags */
34 #define FLAG_GROUP       1      /* ' flag */
35 #define FLAG_LEFT        2      /* - flag */
36 #define FLAG_SHOWSIGN    4      /* + flag */
37 #define FLAG_SPACE       8      /* space flag */
38 #define FLAG_ALT        16      /* # flag */
39 #define FLAG_ZERO       32
40 #if __GLIBC__ >= 2 && !defined __UCLIBC__
41 # define FLAG_LOCALIZED 64      /* I flag, uses localized digits */
42 #endif
43
44 /* arg_index value indicating that no argument is consumed.  */
45 #define ARG_NONE        (~(size_t)0)
46
47 /* xxx_directive: A parsed directive.
48    xxx_directives: A parsed format string.  */
49
50 /* Number of directly allocated directives (no malloc() needed).  */
51 #define N_DIRECT_ALLOC_DIRECTIVES 7
52
53 /* A parsed directive.  */
54 typedef struct
55 {
56   const char* dir_start;
57   const char* dir_end;
58   int flags;
59   const char* width_start;
60   const char* width_end;
61   size_t width_arg_index;
62   const char* precision_start;
63   const char* precision_end;
64   size_t precision_arg_index;
65   char conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
66   size_t arg_index;
67 }
68 char_directive;
69
70 /* A parsed format string.  */
71 typedef struct
72 {
73   size_t count;
74   char_directive *dir;
75   size_t max_width_length;
76   size_t max_precision_length;
77   char_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
78 }
79 char_directives;
80
81 #if ENABLE_UNISTDIO
82
83 /* A parsed directive.  */
84 typedef struct
85 {
86   const uint8_t* dir_start;
87   const uint8_t* dir_end;
88   int flags;
89   const uint8_t* width_start;
90   const uint8_t* width_end;
91   size_t width_arg_index;
92   const uint8_t* precision_start;
93   const uint8_t* precision_end;
94   size_t precision_arg_index;
95   uint8_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
96   size_t arg_index;
97 }
98 u8_directive;
99
100 /* A parsed format string.  */
101 typedef struct
102 {
103   size_t count;
104   u8_directive *dir;
105   size_t max_width_length;
106   size_t max_precision_length;
107   u8_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
108 }
109 u8_directives;
110
111 /* A parsed directive.  */
112 typedef struct
113 {
114   const uint16_t* dir_start;
115   const uint16_t* dir_end;
116   int flags;
117   const uint16_t* width_start;
118   const uint16_t* width_end;
119   size_t width_arg_index;
120   const uint16_t* precision_start;
121   const uint16_t* precision_end;
122   size_t precision_arg_index;
123   uint16_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
124   size_t arg_index;
125 }
126 u16_directive;
127
128 /* A parsed format string.  */
129 typedef struct
130 {
131   size_t count;
132   u16_directive *dir;
133   size_t max_width_length;
134   size_t max_precision_length;
135   u16_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
136 }
137 u16_directives;
138
139 /* A parsed directive.  */
140 typedef struct
141 {
142   const uint32_t* dir_start;
143   const uint32_t* dir_end;
144   int flags;
145   const uint32_t* width_start;
146   const uint32_t* width_end;
147   size_t width_arg_index;
148   const uint32_t* precision_start;
149   const uint32_t* precision_end;
150   size_t precision_arg_index;
151   uint32_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
152   size_t arg_index;
153 }
154 u32_directive;
155
156 /* A parsed format string.  */
157 typedef struct
158 {
159   size_t count;
160   u32_directive *dir;
161   size_t max_width_length;
162   size_t max_precision_length;
163   u32_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
164 }
165 u32_directives;
166
167 #endif
168
169
170 /* Parses the format string.  Fills in the number N of directives, and fills
171    in directives[0], ..., directives[N-1], and sets directives[N].dir_start
172    to the end of the format string.  Also fills in the arg_type fields of the
173    arguments and the needed count of arguments.  */
174 #if ENABLE_UNISTDIO
175 extern int
176        ulc_printf_parse (const char *format, char_directives *d, arguments *a);
177 extern int
178        u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a);
179 extern int
180        u16_printf_parse (const uint16_t *format, u16_directives *d,
181                          arguments *a);
182 extern int
183        u32_printf_parse (const uint32_t *format, u32_directives *d,
184                          arguments *a);
185 #else
186 # ifdef STATIC
187 STATIC
188 # else
189 extern
190 # endif
191 int printf_parse (const char *format, char_directives *d, arguments *a);
192 #endif
193
194 #endif /* _PRINTF_PARSE_H */