• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Parse printf format string.
2    Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2011 Free Software Foundation, Inc.
3 
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU Lesser General Public License as published by
6    the Free Software Foundation; either version 2.1 of the License, or
7    (at your option) any later version.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public License
15    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
16 
17 #ifndef _WPRINTF_PARSE_H
18 #define _WPRINTF_PARSE_H
19 
20 #if HAVE_FEATURES_H
21 # include <features.h> /* for __GLIBC__, __UCLIBC__ */
22 #endif
23 
24 #include "printf-args.h"
25 
26 
27 /* Flags */
28 #define FLAG_GROUP       1      /* ' flag */
29 #define FLAG_LEFT        2      /* - flag */
30 #define FLAG_SHOWSIGN    4      /* + flag */
31 #define FLAG_SPACE       8      /* space flag */
32 #define FLAG_ALT        16      /* # flag */
33 #define FLAG_ZERO       32
34 #if __GLIBC__ >= 2 && !defined __UCLIBC__
35 # define FLAG_LOCALIZED 64      /* I flag, uses localized digits */
36 #endif
37 
38 /* arg_index value indicating that no argument is consumed.  */
39 #define ARG_NONE        (~(size_t)0)
40 
41 /* Number of directly allocated directives (no malloc() needed).  */
42 #define N_DIRECT_ALLOC_DIRECTIVES 7
43 
44 /* A parsed directive.  */
45 typedef struct
46 {
47   const wchar_t* dir_start;
48   const wchar_t* dir_end;
49   int flags;
50   const wchar_t* width_start;
51   const wchar_t* width_end;
52   size_t width_arg_index;
53   const wchar_t* precision_start;
54   const wchar_t* precision_end;
55   size_t precision_arg_index;
56   wchar_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 */
57   size_t arg_index;
58 }
59 wchar_t_directive;
60 
61 /* A parsed format string.  */
62 typedef struct
63 {
64   size_t count;
65   wchar_t_directive *dir;
66   size_t max_width_length;
67   size_t max_precision_length;
68   wchar_t_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
69 }
70 wchar_t_directives;
71 
72 
73 /* Parses the format string.  Fills in the number N of directives, and fills
74    in directives[0], ..., directives[N-1], and sets directives[N].dir_start
75    to the end of the format string.  Also fills in the arg_type fields of the
76    arguments and the needed count of arguments.  */
77 #ifdef STATIC
78 STATIC
79 #else
80 extern
81 #endif
82 int wprintf_parse (const wchar_t *format, wchar_t_directives *d, arguments *a);
83 
84 #endif /* _WPRINTF_PARSE_H */
85