Mercurial > hg > octave-shane > gnulib-hg
comparison lib/argp-fmtstream.c @ 6000:741f5ae99cfd
autoupdate
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Thu, 21 Jul 2005 13:04:29 +0000 |
parents | a48fb0e98c8c |
children | 41c42e1f6734 |
comparison
equal
deleted
inserted
replaced
5999:9887c4adbd89 | 6000:741f5ae99cfd |
---|---|
1 /* Word-wrapping and line-truncating streams | 1 /* Word-wrapping and line-truncating streams |
2 Copyright (C) 1997,1998,1999,2001,2002,2003 Free Software Foundation, Inc. | 2 Copyright (C) 1997-1999,2001,2002,2003,2005 Free Software Foundation, Inc. |
3 This file is part of the GNU C Library. | 3 This file is part of the GNU C Library. |
4 Written by Miles Bader <miles@gnu.ai.mit.edu>. | 4 Written by Miles Bader <miles@gnu.ai.mit.edu>. |
5 | 5 |
6 This program is free software; you can redistribute it and/or modify | 6 This program is free software; you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 GNU General Public License for more details. | 14 GNU General Public License for more details. |
15 | 15 |
16 You should have received a copy of the GNU General Public License along | 16 You should have received a copy of the GNU General Public License along |
17 with this program; if not, write to the Free Software Foundation, | 17 with this program; if not, write to the Free Software Foundation, |
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | 18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
19 | 19 |
20 /* This package emulates glibc `line_wrap_stream' semantics for systems that | 20 /* This package emulates glibc `line_wrap_stream' semantics for systems that |
21 don't have that. */ | 21 don't have that. */ |
22 | 22 |
23 #ifdef HAVE_CONFIG_H | 23 #ifdef HAVE_CONFIG_H |
99 { | 99 { |
100 __argp_fmtstream_update (fs); | 100 __argp_fmtstream_update (fs); |
101 if (fs->p > fs->buf) | 101 if (fs->p > fs->buf) |
102 { | 102 { |
103 #ifdef USE_IN_LIBIO | 103 #ifdef USE_IN_LIBIO |
104 if (_IO_fwide (fs->stream, 0) > 0) | 104 __fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf); |
105 __fwprintf (fs->stream, L"%.*s", (int) (fs->p - fs->buf), fs->buf); | 105 #else |
106 else | 106 fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); |
107 #endif | 107 #endif |
108 fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); | |
109 } | 108 } |
110 free (fs->buf); | 109 free (fs->buf); |
111 free (fs); | 110 free (fs); |
112 } | 111 } |
113 #if 0 | 112 #if 0 |
288 *nl++ = '\n'; | 287 *nl++ = '\n'; |
289 } | 288 } |
290 else | 289 else |
291 /* Output the first line so we can use the space. */ | 290 /* Output the first line so we can use the space. */ |
292 { | 291 { |
293 #ifdef USE_IN_LIBIO | 292 #ifdef _LIBC |
294 if (_IO_fwide (fs->stream, 0) > 0) | 293 __fxprintf (fs->stream, "%.*s\n", |
295 __fwprintf (fs->stream, L"%.*s\n", | 294 (int) (nl - fs->buf), fs->buf); |
296 (int) (nl - fs->buf), fs->buf); | 295 #else |
297 else | 296 if (nl > fs->buf) |
298 #endif | 297 fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream); |
299 { | 298 putc_unlocked ('\n', fs->stream); |
300 if (nl > fs->buf) | 299 #endif |
301 fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream); | 300 |
302 putc_unlocked ('\n', fs->stream); | |
303 } | |
304 len += buf - fs->buf; | 301 len += buf - fs->buf; |
305 nl = buf = fs->buf; | 302 nl = buf = fs->buf; |
306 } | 303 } |
307 } | 304 } |
308 else | 305 else |
357 ssize_t wrote; | 354 ssize_t wrote; |
358 | 355 |
359 /* Flush FS's buffer. */ | 356 /* Flush FS's buffer. */ |
360 __argp_fmtstream_update (fs); | 357 __argp_fmtstream_update (fs); |
361 | 358 |
362 #ifdef USE_IN_LIBIO | 359 #ifdef _LIBC |
363 if (_IO_fwide (fs->stream, 0) > 0) | 360 __fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf); |
364 { | 361 wrote = fs->p - fs->buf; |
365 __fwprintf (fs->stream, L"%.*s", (int) (fs->p - fs->buf), fs->buf); | 362 #else |
366 wrote = fs->p - fs->buf; | 363 wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); |
367 } | 364 #endif |
368 else | |
369 #endif | |
370 wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); | |
371 if (wrote == fs->p - fs->buf) | 365 if (wrote == fs->p - fs->buf) |
372 { | 366 { |
373 fs->p = fs->buf; | 367 fs->p = fs->buf; |
374 fs->point_offs = 0; | 368 fs->point_offs = 0; |
375 } | 369 } |