summaryrefslogtreecommitdiffstats
path: root/gl/printf-parse.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/printf-parse.h')
-rw-r--r--gl/printf-parse.h117
1 files changed, 111 insertions, 6 deletions
diff --git a/gl/printf-parse.h b/gl/printf-parse.h
index 82a0d37..e5d68d7 100644
--- a/gl/printf-parse.h
+++ b/gl/printf-parse.h
@@ -1,9 +1,9 @@
1/* Parse printf format string. 1/* Parse printf format string.
2 Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2002-2003, 2005, 2007 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 3, or (at your option)
7 any later version. 7 any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
@@ -18,6 +18,10 @@
18#ifndef _PRINTF_PARSE_H 18#ifndef _PRINTF_PARSE_H
19#define _PRINTF_PARSE_H 19#define _PRINTF_PARSE_H
20 20
21/* This file can be parametrized with the following macros:
22 ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
23 STATIC Set to 'static' to declare the function static. */
24
21#include "printf-args.h" 25#include "printf-args.h"
22 26
23 27
@@ -32,6 +36,9 @@
32/* arg_index value indicating that no argument is consumed. */ 36/* arg_index value indicating that no argument is consumed. */
33#define ARG_NONE (~(size_t)0) 37#define ARG_NONE (~(size_t)0)
34 38
39/* xxx_directive: A parsed directive.
40 xxx_directives: A parsed format string. */
41
35/* A parsed directive. */ 42/* A parsed directive. */
36typedef struct 43typedef struct
37{ 44{
@@ -44,7 +51,7 @@ typedef struct
44 const char* precision_start; 51 const char* precision_start;
45 const char* precision_end; 52 const char* precision_end;
46 size_t precision_arg_index; 53 size_t precision_arg_index;
47 char conversion; /* d i o u x X f e E g G c s p n U % but not C S */ 54 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 */
48 size_t arg_index; 55 size_t arg_index;
49} 56}
50char_directive; 57char_directive;
@@ -59,16 +66,114 @@ typedef struct
59} 66}
60char_directives; 67char_directives;
61 68
69#if ENABLE_UNISTDIO
70
71/* A parsed directive. */
72typedef struct
73{
74 const uint8_t* dir_start;
75 const uint8_t* dir_end;
76 int flags;
77 const uint8_t* width_start;
78 const uint8_t* width_end;
79 size_t width_arg_index;
80 const uint8_t* precision_start;
81 const uint8_t* precision_end;
82 size_t precision_arg_index;
83 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 */
84 size_t arg_index;
85}
86u8_directive;
87
88/* A parsed format string. */
89typedef struct
90{
91 size_t count;
92 u8_directive *dir;
93 size_t max_width_length;
94 size_t max_precision_length;
95}
96u8_directives;
97
98/* A parsed directive. */
99typedef struct
100{
101 const uint16_t* dir_start;
102 const uint16_t* dir_end;
103 int flags;
104 const uint16_t* width_start;
105 const uint16_t* width_end;
106 size_t width_arg_index;
107 const uint16_t* precision_start;
108 const uint16_t* precision_end;
109 size_t precision_arg_index;
110 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 */
111 size_t arg_index;
112}
113u16_directive;
114
115/* A parsed format string. */
116typedef struct
117{
118 size_t count;
119 u16_directive *dir;
120 size_t max_width_length;
121 size_t max_precision_length;
122}
123u16_directives;
124
125/* A parsed directive. */
126typedef struct
127{
128 const uint32_t* dir_start;
129 const uint32_t* dir_end;
130 int flags;
131 const uint32_t* width_start;
132 const uint32_t* width_end;
133 size_t width_arg_index;
134 const uint32_t* precision_start;
135 const uint32_t* precision_end;
136 size_t precision_arg_index;
137 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 */
138 size_t arg_index;
139}
140u32_directive;
141
142/* A parsed format string. */
143typedef struct
144{
145 size_t count;
146 u32_directive *dir;
147 size_t max_width_length;
148 size_t max_precision_length;
149}
150u32_directives;
151
152#endif
153
62 154
63/* Parses the format string. Fills in the number N of directives, and fills 155/* Parses the format string. Fills in the number N of directives, and fills
64 in directives[0], ..., directives[N-1], and sets directives[N].dir_start 156 in directives[0], ..., directives[N-1], and sets directives[N].dir_start
65 to the end of the format string. Also fills in the arg_type fields of the 157 to the end of the format string. Also fills in the arg_type fields of the
66 arguments and the needed count of arguments. */ 158 arguments and the needed count of arguments. */
67#ifdef STATIC 159#if ENABLE_UNISTDIO
68STATIC 160extern int
161 ulc_printf_parse (const char *format, char_directives *d, arguments *a);
162extern int
163 u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a);
164extern int
165 u16_printf_parse (const uint16_t *format, u16_directives *d,
166 arguments *a);
167extern int
168 u32_printf_parse (const uint32_t *format, u32_directives *d,
169 arguments *a);
69#else 170#else
171# ifdef STATIC
172STATIC
173# else
70extern 174extern
71#endif 175# endif
72int printf_parse (const char *format, char_directives *d, arguments *a); 176int printf_parse (const char *format, char_directives *d, arguments *a);
177#endif
73 178
74#endif /* _PRINTF_PARSE_H */ 179#endif /* _PRINTF_PARSE_H */