This source file includes following definitions.
- __argp_fmtstream_write
- __argp_fmtstream_puts
- __argp_fmtstream_putc
- __argp_fmtstream_set_lmargin
- __argp_fmtstream_set_rmargin
- __argp_fmtstream_set_wmargin
- __argp_fmtstream_point
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #ifndef _ARGP_FMTSTREAM_H
25 #define _ARGP_FMTSTREAM_H
26
27 #include <stdio.h>
28 #include <string.h>
29 #include <unistd.h>
30
31 #if defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H)
32
33 #define ARGP_FMTSTREAM_USE_LINEWRAP
34 #endif
35
36 #ifdef ARGP_FMTSTREAM_USE_LINEWRAP
37
38
39
40
41
42 #include <linewrap.h>
43
44 typedef FILE *argp_fmtstream_t;
45
46 #define argp_make_fmtstream line_wrap_stream
47 #define __argp_make_fmtstream line_wrap_stream
48 #define argp_fmtstream_free line_unwrap_stream
49 #define __argp_fmtstream_free line_unwrap_stream
50
51 #define __argp_fmtstream_putc(fs,ch) putc(ch,fs)
52 #define argp_fmtstream_putc(fs,ch) putc(ch,fs)
53 #define __argp_fmtstream_puts(fs,str) fputs(str,fs)
54 #define argp_fmtstream_puts(fs,str) fputs(str,fs)
55 #define __argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
56 #define argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
57 #define __argp_fmtstream_printf fprintf
58 #define argp_fmtstream_printf fprintf
59
60 #define __argp_fmtstream_lmargin line_wrap_lmargin
61 #define argp_fmtstream_lmargin line_wrap_lmargin
62 #define __argp_fmtstream_set_lmargin line_wrap_set_lmargin
63 #define argp_fmtstream_set_lmargin line_wrap_set_lmargin
64 #define __argp_fmtstream_rmargin line_wrap_rmargin
65 #define argp_fmtstream_rmargin line_wrap_rmargin
66 #define __argp_fmtstream_set_rmargin line_wrap_set_rmargin
67 #define argp_fmtstream_set_rmargin line_wrap_set_rmargin
68 #define __argp_fmtstream_wmargin line_wrap_wmargin
69 #define argp_fmtstream_wmargin line_wrap_wmargin
70 #define __argp_fmtstream_set_wmargin line_wrap_set_wmargin
71 #define argp_fmtstream_set_wmargin line_wrap_set_wmargin
72 #define __argp_fmtstream_point line_wrap_point
73 #define argp_fmtstream_point line_wrap_point
74
75 #else
76
77
78
79 struct argp_fmtstream
80 {
81 FILE *stream;
82
83 size_t lmargin, rmargin;
84 ssize_t wmargin;
85
86
87 size_t point_offs;
88
89 ssize_t point_col;
90
91 char *buf;
92 char *p;
93 char *end;
94 };
95
96 typedef struct argp_fmtstream *argp_fmtstream_t;
97
98
99 extern void __argp_fmtstream_free (argp_fmtstream_t __fs);
100 extern void argp_fmtstream_free (argp_fmtstream_t __fs);
101
102
103
104
105
106
107
108 extern argp_fmtstream_t __argp_make_fmtstream (FILE *__stream,
109 size_t __lmargin,
110 size_t __rmargin,
111 ssize_t __wmargin)
112 _GL_ATTRIBUTE_DEALLOC (__argp_fmtstream_free, 1);
113 extern argp_fmtstream_t argp_make_fmtstream (FILE *__stream,
114 size_t __lmargin,
115 size_t __rmargin,
116 ssize_t __wmargin)
117 _GL_ATTRIBUTE_DEALLOC (argp_fmtstream_free, 1);
118
119 extern ssize_t __argp_fmtstream_printf (argp_fmtstream_t __fs,
120 const char *__fmt, ...)
121 _GL_ATTRIBUTE_FORMAT ((printf, 2, 3));
122 extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs,
123 const char *__fmt, ...)
124 _GL_ATTRIBUTE_FORMAT ((printf, 2, 3));
125
126 #if _LIBC
127 extern int __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
128 extern int argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
129
130 extern int __argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str);
131 extern int argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str);
132
133 extern size_t __argp_fmtstream_write (argp_fmtstream_t __fs,
134 const char *__str, size_t __len);
135 extern size_t argp_fmtstream_write (argp_fmtstream_t __fs,
136 const char *__str, size_t __len);
137 #endif
138
139
140 #define argp_fmtstream_lmargin(__fs) ((__fs)->lmargin)
141 #define argp_fmtstream_rmargin(__fs) ((__fs)->rmargin)
142 #define argp_fmtstream_wmargin(__fs) ((__fs)->wmargin)
143 #define __argp_fmtstream_lmargin argp_fmtstream_lmargin
144 #define __argp_fmtstream_rmargin argp_fmtstream_rmargin
145 #define __argp_fmtstream_wmargin argp_fmtstream_wmargin
146
147 #if _LIBC
148
149 extern size_t argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
150 size_t __lmargin);
151 extern size_t __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
152 size_t __lmargin);
153
154
155 extern size_t argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
156 size_t __rmargin);
157 extern size_t __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
158 size_t __rmargin);
159
160
161 extern size_t argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
162 size_t __wmargin);
163 extern size_t __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
164 size_t __wmargin);
165
166
167 extern size_t argp_fmtstream_point (argp_fmtstream_t __fs);
168 extern size_t __argp_fmtstream_point (argp_fmtstream_t __fs);
169 #endif
170
171
172 extern void _argp_fmtstream_update (argp_fmtstream_t __fs);
173 extern void __argp_fmtstream_update (argp_fmtstream_t __fs);
174 extern int _argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
175 extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
176
177 #if !_LIBC || defined __OPTIMIZE__
178
179
180 #if !_LIBC
181 #define __argp_fmtstream_putc argp_fmtstream_putc
182 #define __argp_fmtstream_puts argp_fmtstream_puts
183 #define __argp_fmtstream_write argp_fmtstream_write
184 #define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin
185 #define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin
186 #define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin
187 #define __argp_fmtstream_point argp_fmtstream_point
188 #define __argp_fmtstream_update _argp_fmtstream_update
189 #define __argp_fmtstream_ensure _argp_fmtstream_ensure
190 #ifndef _GL_INLINE_HEADER_BEGIN
191 #error "Please include config.h first."
192 #endif
193 _GL_INLINE_HEADER_BEGIN
194 #ifndef ARGP_FS_EI
195 # define ARGP_FS_EI _GL_INLINE
196 #endif
197 #endif
198
199 #ifndef ARGP_FS_EI
200 #define ARGP_FS_EI extern inline
201 #endif
202
203 ARGP_FS_EI size_t
204 __argp_fmtstream_write (argp_fmtstream_t __fs, const char *__str, size_t __len)
205 {
206 if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len))
207 {
208 memcpy (__fs->p, __str, __len);
209 __fs->p += __len;
210 return __len;
211 }
212 else
213 return 0;
214 }
215
216 ARGP_FS_EI int
217 __argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str)
218 {
219 size_t __len = strlen (__str);
220 if (__len)
221 {
222 size_t __wrote = __argp_fmtstream_write (__fs, __str, __len);
223 return __wrote == __len ? 0 : -1;
224 }
225 else
226 return 0;
227 }
228
229 ARGP_FS_EI int
230 __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch)
231 {
232 if (__fs->p < __fs->end || __argp_fmtstream_ensure (__fs, 1))
233 return *__fs->p++ = __ch;
234 else
235 return EOF;
236 }
237
238
239 ARGP_FS_EI size_t
240 __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin)
241 {
242 size_t __old;
243 if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
244 __argp_fmtstream_update (__fs);
245 __old = __fs->lmargin;
246 __fs->lmargin = __lmargin;
247 return __old;
248 }
249
250
251 ARGP_FS_EI size_t
252 __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin)
253 {
254 size_t __old;
255 if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
256 __argp_fmtstream_update (__fs);
257 __old = __fs->rmargin;
258 __fs->rmargin = __rmargin;
259 return __old;
260 }
261
262
263 ARGP_FS_EI size_t
264 __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin)
265 {
266 size_t __old;
267 if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
268 __argp_fmtstream_update (__fs);
269 __old = __fs->wmargin;
270 __fs->wmargin = __wmargin;
271 return __old;
272 }
273
274
275 ARGP_FS_EI size_t
276 __argp_fmtstream_point (argp_fmtstream_t __fs)
277 {
278 if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
279 __argp_fmtstream_update (__fs);
280 return __fs->point_col >= 0 ? __fs->point_col : 0;
281 }
282
283 #if !_LIBC
284 #undef __argp_fmtstream_putc
285 #undef __argp_fmtstream_puts
286 #undef __argp_fmtstream_write
287 #undef __argp_fmtstream_set_lmargin
288 #undef __argp_fmtstream_set_rmargin
289 #undef __argp_fmtstream_set_wmargin
290 #undef __argp_fmtstream_point
291 #undef __argp_fmtstream_update
292 #undef __argp_fmtstream_ensure
293 _GL_INLINE_HEADER_END
294 #endif
295
296 #endif
297
298 #endif
299
300 #endif