X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fargp-fmtstream.c;h=7e6d9c6982e9d336765ba998b039179781ae7c19;hb=deb58d481fc8dc345e463002c7087a08a4f1d5f0;hp=a97f20cbb141e5ab5f16b7bf9858c3d51e366d1c;hpb=267a39bafd249d7eb9c37df06dc6defcf41cb343;p=gnulib.git diff --git a/lib/argp-fmtstream.c b/lib/argp-fmtstream.c index a97f20cbb..7e6d9c698 100644 --- a/lib/argp-fmtstream.c +++ b/lib/argp-fmtstream.c @@ -1,27 +1,26 @@ /* Word-wrapping and line-truncating streams - Copyright (C) 1997,1998,1999,2001,2002,2003 Free Software Foundation, Inc. + Copyright (C) 1997-1999,2001,2002,2003,2005 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Miles Bader . - This program is free software; you can redistribute it and/or modify + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ /* This package emulates glibc `line_wrap_stream' semantics for systems that don't have that. */ #ifdef HAVE_CONFIG_H -#include +# include #endif #include @@ -101,11 +100,10 @@ __argp_fmtstream_free (argp_fmtstream_t fs) if (fs->p > fs->buf) { #ifdef USE_IN_LIBIO - if (_IO_fwide (fs->stream, 0) > 0) - __fwprintf (fs->stream, L"%.*s", (int) (fs->p - fs->buf), fs->buf); - else + __fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf); +#else + fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); #endif - fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); } free (fs->buf); free (fs); @@ -228,7 +226,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs) int i; p = buf + (r + 1 - fs->point_col); - while (p >= buf && !isblank (*p)) + while (p >= buf && !isblank ((unsigned char) *p)) --p; nextline = p + 1; /* This will begin the next line. */ @@ -238,7 +236,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs) if (p >= buf) do --p; - while (p >= buf && isblank (*p)); + while (p >= buf && isblank ((unsigned char) *p)); nl = p + 1; /* The newline will replace the first blank. */ } else @@ -247,9 +245,10 @@ __argp_fmtstream_update (argp_fmtstream_t fs) Oh well. Put it on an overlong line by itself. */ p = buf + (r + 1 - fs->point_col); /* Find the end of the long word. */ - do - ++p; - while (p < nl && !isblank (*p)); + if (p < nl) + do + ++p; + while (p < nl && !isblank ((unsigned char) *p)); if (p == nl) { /* It already ends a line. No fussing required. */ @@ -262,7 +261,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs) /* Swallow separating blanks. */ do ++p; - while (isblank (*p)); + while (isblank ((unsigned char) *p)); /* The next line will start here. */ nextline = p; } @@ -290,17 +289,15 @@ __argp_fmtstream_update (argp_fmtstream_t fs) else /* Output the first line so we can use the space. */ { -#ifdef USE_IN_LIBIO - if (_IO_fwide (fs->stream, 0) > 0) - __fwprintf (fs->stream, L"%.*s\n", - (int) (nl - fs->buf), fs->buf); - else +#ifdef _LIBC + __fxprintf (fs->stream, "%.*s\n", + (int) (nl - fs->buf), fs->buf); +#else + if (nl > fs->buf) + fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream); + putc_unlocked ('\n', fs->stream); #endif - { - if (nl > fs->buf) - fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream); - putc_unlocked ('\n', fs->stream); - } + len += buf - fs->buf; nl = buf = fs->buf; } @@ -359,15 +356,12 @@ __argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount) /* Flush FS's buffer. */ __argp_fmtstream_update (fs); -#ifdef USE_IN_LIBIO - if (_IO_fwide (fs->stream, 0) > 0) - { - __fwprintf (fs->stream, L"%.*s", (int) (fs->p - fs->buf), fs->buf); - wrote = fs->p - fs->buf; - } - else +#ifdef _LIBC + __fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf); + wrote = fs->p - fs->buf; +#else + wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); #endif - wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); if (wrote == fs->p - fs->buf) { fs->p = fs->buf;