1997-02-15 04:31:36 +00:00
|
|
|
|
/* Word-wrapping and line-truncating streams
|
2016-01-04 16:05:18 +00:00
|
|
|
|
Copyright (C) 1997-2016 Free Software Foundation, Inc.
|
1997-02-15 04:31:36 +00:00
|
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
Written by Miles Bader <miles@gnu.ai.mit.edu>.
|
|
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1997-02-15 04:31:36 +00:00
|
|
|
|
|
|
|
|
|
The GNU C Library 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
|
2001-07-06 04:58:11 +00:00
|
|
|
|
Lesser General Public License for more details.
|
1997-02-15 04:31:36 +00:00
|
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
1997-02-15 04:31:36 +00:00
|
|
|
|
|
|
|
|
|
/* This package emulates glibc `line_wrap_stream' semantics for systems that
|
|
|
|
|
don't have that. */
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2005-09-27 21:45:41 +00:00
|
|
|
|
# include <config.h>
|
1997-02-15 04:31:36 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
|
|
#include "argp-fmtstream.h"
|
|
|
|
|
#include "argp-namefrob.h"
|
|
|
|
|
|
|
|
|
|
#ifndef ARGP_FMTSTREAM_USE_LINEWRAP
|
|
|
|
|
|
|
|
|
|
#ifndef isblank
|
|
|
|
|
#define isblank(ch) ((ch)==' ' || (ch)=='\t')
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-09-10 18:34:15 +00:00
|
|
|
|
#ifdef _LIBC
|
2001-08-17 04:49:12 +00:00
|
|
|
|
# include <wchar.h>
|
1998-07-16 13:49:59 +00:00
|
|
|
|
# include <libio/libioP.h>
|
1998-07-16 11:44:36 +00:00
|
|
|
|
# define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a)
|
|
|
|
|
#endif
|
|
|
|
|
|
1997-02-15 04:31:36 +00:00
|
|
|
|
#define INIT_BUF_SIZE 200
|
|
|
|
|
#define PRINTF_SIZE_GUESS 150
|
|
|
|
|
|
|
|
|
|
/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
|
|
|
|
|
written on it with LMARGIN spaces and limits them to RMARGIN columns
|
|
|
|
|
total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
|
|
|
|
|
replacing the whitespace before them with a newline and WMARGIN spaces.
|
|
|
|
|
Otherwise, chars beyond RMARGIN are simply dropped until a newline.
|
|
|
|
|
Returns NULL if there was an error. */
|
|
|
|
|
argp_fmtstream_t
|
|
|
|
|
__argp_make_fmtstream (FILE *stream,
|
|
|
|
|
size_t lmargin, size_t rmargin, ssize_t wmargin)
|
|
|
|
|
{
|
2001-08-17 04:49:12 +00:00
|
|
|
|
argp_fmtstream_t fs;
|
|
|
|
|
|
|
|
|
|
fs = (struct argp_fmtstream *) malloc (sizeof (struct argp_fmtstream));
|
|
|
|
|
if (fs != NULL)
|
1997-02-15 04:31:36 +00:00
|
|
|
|
{
|
|
|
|
|
fs->stream = stream;
|
|
|
|
|
|
|
|
|
|
fs->lmargin = lmargin;
|
|
|
|
|
fs->rmargin = rmargin;
|
|
|
|
|
fs->wmargin = wmargin;
|
|
|
|
|
fs->point_col = 0;
|
|
|
|
|
fs->point_offs = 0;
|
|
|
|
|
|
2001-08-17 04:49:12 +00:00
|
|
|
|
fs->buf = (char *) malloc (INIT_BUF_SIZE);
|
1997-02-15 04:31:36 +00:00
|
|
|
|
if (! fs->buf)
|
|
|
|
|
{
|
|
|
|
|
free (fs);
|
|
|
|
|
fs = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fs->p = fs->buf;
|
|
|
|
|
fs->end = fs->buf + INIT_BUF_SIZE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fs;
|
|
|
|
|
}
|
2003-01-08 06:49:39 +00:00
|
|
|
|
#if 0
|
|
|
|
|
/* Not exported. */
|
1997-02-15 04:31:36 +00:00
|
|
|
|
#ifdef weak_alias
|
|
|
|
|
weak_alias (__argp_make_fmtstream, argp_make_fmtstream)
|
|
|
|
|
#endif
|
2003-01-08 06:49:39 +00:00
|
|
|
|
#endif
|
1997-02-15 04:31:36 +00:00
|
|
|
|
|
|
|
|
|
/* Flush FS to its stream, and free it (but don't close the stream). */
|
|
|
|
|
void
|
|
|
|
|
__argp_fmtstream_free (argp_fmtstream_t fs)
|
|
|
|
|
{
|
|
|
|
|
__argp_fmtstream_update (fs);
|
|
|
|
|
if (fs->p > fs->buf)
|
2001-08-17 04:49:12 +00:00
|
|
|
|
{
|
2016-01-01 20:20:26 +00:00
|
|
|
|
#ifdef _LIBC
|
2005-07-20 17:51:14 +00:00
|
|
|
|
__fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf);
|
2016-01-01 20:20:26 +00:00
|
|
|
|
#else
|
|
|
|
|
fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream);
|
|
|
|
|
#endif
|
2001-08-17 04:49:12 +00:00
|
|
|
|
}
|
1997-02-15 04:31:36 +00:00
|
|
|
|
free (fs->buf);
|
|
|
|
|
free (fs);
|
|
|
|
|
}
|
2003-01-08 06:49:39 +00:00
|
|
|
|
#if 0
|
|
|
|
|
/* Not exported. */
|
1997-02-15 04:31:36 +00:00
|
|
|
|
#ifdef weak_alias
|
|
|
|
|
weak_alias (__argp_fmtstream_free, argp_fmtstream_free)
|
|
|
|
|
#endif
|
2003-01-08 06:49:39 +00:00
|
|
|
|
#endif
|
1997-02-15 04:31:36 +00:00
|
|
|
|
|
|
|
|
|
/* Process FS's buffer so that line wrapping is done from POINT_OFFS to the
|
|
|
|
|
end of its buffer. This code is mostly from glibc stdio/linewrap.c. */
|
|
|
|
|
void
|
|
|
|
|
__argp_fmtstream_update (argp_fmtstream_t fs)
|
|
|
|
|
{
|
|
|
|
|
char *buf, *nl;
|
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
|
|
/* Scan the buffer for newlines. */
|
|
|
|
|
buf = fs->buf + fs->point_offs;
|
|
|
|
|
while (buf < fs->p)
|
|
|
|
|
{
|
|
|
|
|
size_t r;
|
|
|
|
|
|
|
|
|
|
if (fs->point_col == 0 && fs->lmargin != 0)
|
|
|
|
|
{
|
|
|
|
|
/* We are starting a new line. Print spaces to the left margin. */
|
|
|
|
|
const size_t pad = fs->lmargin;
|
|
|
|
|
if (fs->p + pad < fs->end)
|
|
|
|
|
{
|
|
|
|
|
/* We can fit in them in the buffer by moving the
|
|
|
|
|
buffer text up and filling in the beginning. */
|
|
|
|
|
memmove (buf + pad, buf, fs->p - buf);
|
|
|
|
|
fs->p += pad; /* Compensate for bigger buffer. */
|
|
|
|
|
memset (buf, ' ', pad); /* Fill in the spaces. */
|
|
|
|
|
buf += pad; /* Don't bother searching them. */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* No buffer space for spaces. Must flush. */
|
|
|
|
|
size_t i;
|
|
|
|
|
for (i = 0; i < pad; i++)
|
2001-08-17 04:49:12 +00:00
|
|
|
|
{
|
|
|
|
|
if (_IO_fwide (fs->stream, 0) > 0)
|
|
|
|
|
putwc_unlocked (L' ', fs->stream);
|
|
|
|
|
else
|
|
|
|
|
putc_unlocked (' ', fs->stream);
|
|
|
|
|
}
|
1997-02-15 04:31:36 +00:00
|
|
|
|
}
|
|
|
|
|
fs->point_col = pad;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
len = fs->p - buf;
|
|
|
|
|
nl = memchr (buf, '\n', len);
|
|
|
|
|
|
|
|
|
|
if (fs->point_col < 0)
|
|
|
|
|
fs->point_col = 0;
|
|
|
|
|
|
|
|
|
|
if (!nl)
|
|
|
|
|
{
|
|
|
|
|
/* The buffer ends in a partial line. */
|
|
|
|
|
|
|
|
|
|
if (fs->point_col + len < fs->rmargin)
|
|
|
|
|
{
|
|
|
|
|
/* The remaining buffer text is a partial line and fits
|
|
|
|
|
within the maximum line width. Advance point for the
|
|
|
|
|
characters to be written and stop scanning. */
|
|
|
|
|
fs->point_col += len;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
/* Set the end-of-line pointer for the code below to
|
|
|
|
|
the end of the buffer. */
|
|
|
|
|
nl = fs->p;
|
|
|
|
|
}
|
1997-04-08 23:42:08 +00:00
|
|
|
|
else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin)
|
1997-02-15 04:31:36 +00:00
|
|
|
|
{
|
|
|
|
|
/* The buffer contains a full line that fits within the maximum
|
|
|
|
|
line width. Reset point and scan the next line. */
|
|
|
|
|
fs->point_col = 0;
|
|
|
|
|
buf = nl + 1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This line is too long. */
|
|
|
|
|
r = fs->rmargin - 1;
|
|
|
|
|
|
|
|
|
|
if (fs->wmargin < 0)
|
|
|
|
|
{
|
|
|
|
|
/* Truncate the line by overwriting the excess with the
|
|
|
|
|
newline and anything after it in the buffer. */
|
|
|
|
|
if (nl < fs->p)
|
|
|
|
|
{
|
|
|
|
|
memmove (buf + (r - fs->point_col), nl, fs->p - nl);
|
|
|
|
|
fs->p -= buf + (r - fs->point_col) - nl;
|
|
|
|
|
/* Reset point for the next line and start scanning it. */
|
|
|
|
|
fs->point_col = 0;
|
|
|
|
|
buf += r + 1; /* Skip full line plus \n. */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* The buffer ends with a partial line that is beyond the
|
|
|
|
|
maximum line width. Advance point for the characters
|
|
|
|
|
written, and discard those past the max from the buffer. */
|
|
|
|
|
fs->point_col += len;
|
|
|
|
|
fs->p -= fs->point_col - r;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Do word wrap. Go to the column just past the maximum line
|
|
|
|
|
width and scan back for the beginning of the word there.
|
|
|
|
|
Then insert a line break. */
|
|
|
|
|
|
|
|
|
|
char *p, *nextline;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
p = buf + (r + 1 - fs->point_col);
|
|
|
|
|
while (p >= buf && !isblank (*p))
|
|
|
|
|
--p;
|
|
|
|
|
nextline = p + 1; /* This will begin the next line. */
|
|
|
|
|
|
|
|
|
|
if (nextline > buf)
|
|
|
|
|
{
|
|
|
|
|
/* Swallow separating blanks. */
|
1998-07-31 18:02:14 +00:00
|
|
|
|
if (p >= buf)
|
1997-02-15 04:31:36 +00:00
|
|
|
|
do
|
|
|
|
|
--p;
|
1998-07-31 18:02:14 +00:00
|
|
|
|
while (p >= buf && isblank (*p));
|
1997-02-15 04:31:36 +00:00
|
|
|
|
nl = p + 1; /* The newline will replace the first blank. */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* A single word that is greater than the maximum line width.
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
/* It already ends a line. No fussing required. */
|
|
|
|
|
fs->point_col = 0;
|
|
|
|
|
buf = nl + 1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
/* We will move the newline to replace the first blank. */
|
|
|
|
|
nl = p;
|
|
|
|
|
/* Swallow separating blanks. */
|
|
|
|
|
do
|
|
|
|
|
++p;
|
|
|
|
|
while (isblank (*p));
|
|
|
|
|
/* The next line will start here. */
|
|
|
|
|
nextline = p;
|
|
|
|
|
}
|
|
|
|
|
|
update from main archive 970221
1997-02-22 00:17 Ulrich Drepper <drepper@cygnus.com>
* catgets/gencat.c: Change to use argp.
* db/makedb: Likewise.
* locale/programs/localedef.c: Likewise.
* locale/programs/locale.c: Little adjustment for better usage of
argp.
1997-02-20 20:07 Greg McGary <gkm@eng.ascend.com>
* Makeconfig: Add rules for libc with bounded pointers.
* Makerules: Likewise.
* config.make.in: Likewise.
* configure.in: Likewise.
1997-02-21 10:41 Miles Bader <miles@gnu.ai.mit.edu>
* argp.h (OPTION_NO_USAGE): New macro.
* argp-help.c (usage_long_opt, usage_argful_short_opt,
add_argless_short_opt): Implement OPTION_NO_USAGE.
1997-02-20 16:41 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* malloc/obstack.h: Fix typo.
1997-02-20 15:56 Miles Bader <miles@gnu.ai.mit.edu>
* argp-fmtstream.c (__argp_fmtstream_update): Account for case
where NEXTLINE points one past the end of the active buffer.
* argp-help.c <stddef.h>: New include.
(__argp_failure): Only exit if STATE says it's ok.
(print_header, hol_entry_help): Use UPARAMS fields rather than
constants.
(_help): Call fill_in_uparams if necessary.
(struct hol_help_state): New type.
(struct pentry_state): Add hhstate field. Remove prev_entry &
sep_groups fields.
(hol_entry_help): Add HHSTATE parameter. Remove prev_entry &
sep_groups parameters.
Suppress duplicate arguments if requested, and note the fact.
(print_header, comma): Use PEST->hhstate fields.
(hol_help): Add HHSTATE variable & pass to hol_entry_help.
Remove LAST_ENTRY & SEP_GROUPS variables.
If any suplicate arguments were suppressed, print explanatory note.
(filter_doc): Replace PEST parameter with STATE.
(struct uparams): New type.
(uparams): New variable.
(struct uparam_name): New type.
(uparam_names): New variable.
(fill_in_uparams): New function.
(__argp_failure, __argp_error, __argp_state_help): Make STATE
parameter const.
* argp.h (argp_state_help, __argp_state_help, argp_usage,
__argp_usage, argp_error, __argp_error, argp_failure,
__argp_failure): Make STATE parameter const.
(ARGP_KEY_HELP_DUP_ARGS_NOTE): New macro.
* argp.h (argp_program_bug_address): Make const.
1997-02-20 19:20 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/unix/mman/syscalls.list: Explain msync interface.
1997-02-19 01:37 Erik Troan <ewt@redhat.com>
* shadow/sgetspent_r.c: Accept empty third, fourth and fifth fields.
1997-02-20 14:44 Andreas Jaeger <aj@arthur.pfalz.de>
* stdio-common/test-fseek.c: Remove temporary file, add
copyright.
1997-02-20 17:51 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/generic/netinet/in.h: Protect contents using
__BEGIN/END_DECLS. Reported by a sun <asun@zoology.washington.edu>.
* inet/net/ethernet.h: Move to sysdeps/unix/sysv/linux/net.
* inet/Makefile (headers): Remove net/ethernet.h.
* sysdeps/unix/sysv/linux/Makefile: Install net/ethernet.h.
* sysdeps/unix/sysv/linux/Dist: Distribute net/ethernet.h.
1997-02-20 15:23 Thorsten Kukuk <kukuk@weber.uni-paderborn.de>
* nss/nsswitch.c (__nss_configure_lookup): Use correct test when
searching in sorted array.
1997-02-20 01:24 Philip Blundell <pjb27@cam.ac.uk>
* inet/getnameinfo.c: Change to use reentrant getXXbyYY functions
and protect modification of global data.
1997-02-19 18:48 Miles Bader <miles@gnu.ai.mit.edu>
* argp-parse.c (argp_default_parser): Set STATE->name for OPT_PROGNAME.
(parser_init): Use the basename for PARSER->state.name.
* argp-help.c (__argp_error, __argp_failure, __argp_state_help):
Use PROGRAM_INVOCATION_SHORT_NAME instead of PROGRAM_INVOCATION_NAME.
* argp-parse.c (parser_init): Set PARSER->state.flags.
Make check whether PARSER has the prog name in argv[0] at the
proper place.
1997-02-19 23:34 Ulrich Drepper <drepper@cygnus.com>
* locale/programs/ld-time.c (time_finish): t_fmt_ampm is optional.
Use default value instead of printing a warning.
* nss/XXX-lookup.c: Add misssing explanation.
1997-02-19 19:14 Andreas Jaeger <aj@arthur.pfalz.de>
* inet/in6_addr.c: Add missing braces.
* inet/getnameinfo.c: Include <arpa/inet.h>.
* sysdeps/posix/getaddrinfo.c: Include <arpa/inet.h>.
1997-02-19 11:46 Ulrich Drepper <drepper@cygnus.com>
* string/strxfrm.c (STRCOLL): Correct handling of `position'
levels with no non-IGNOREd element and handling of NUL byte.
* string/strcoll.c (STRXFRM): Likewise.
* locale/weight.h: Likewise.
* shadow/sgetspent_r.c (LINE_PARSER): Add missing ')'.
1997-02-22 01:20:46 +00:00
|
|
|
|
/* Note: There are a bunch of tests below for
|
|
|
|
|
NEXTLINE == BUF + LEN + 1; this case is where NL happens to fall
|
|
|
|
|
at the end of the buffer, and NEXTLINE is in fact empty (and so
|
|
|
|
|
we need not be careful to maintain its contents). */
|
|
|
|
|
|
2002-06-25 18:16:11 +00:00
|
|
|
|
if ((nextline == buf + len + 1
|
|
|
|
|
? fs->end - nl < fs->wmargin + 1
|
|
|
|
|
: nextline - (nl + 1) < fs->wmargin)
|
|
|
|
|
&& fs->p > nextline)
|
1998-09-09 11:53:19 +00:00
|
|
|
|
{
|
|
|
|
|
/* The margin needs more blanks than we removed. */
|
|
|
|
|
if (fs->end - fs->p > fs->wmargin + 1)
|
|
|
|
|
/* Make some space for them. */
|
|
|
|
|
{
|
|
|
|
|
size_t mv = fs->p - nextline;
|
|
|
|
|
memmove (nl + 1 + fs->wmargin, nextline, mv);
|
|
|
|
|
nextline = nl + 1 + fs->wmargin;
|
|
|
|
|
len = nextline + mv - buf;
|
|
|
|
|
*nl++ = '\n';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
/* Output the first line so we can use the space. */
|
|
|
|
|
{
|
* wcsmbs/bits/wchar2.h: Add definitions for wcrtomb, mbsrtowcs,
wcsrtombs, mbsnrtowcs, and wcsnrtombs.
* debug/Makefile (routines): Add wcrtomb_chk, mbsrtowcs_chk,
wcsrtombs_chk, mbsnrtowcs_chk, and wcsnrtombs_chk.
* debug/Versions: Add __wcrtomb_chk, __mbsrtowcs_chk,
__wcsrtombs_chk, __mbsnrtowcs_chk, and __wcsnrtombs_chk.
* debug/tst-chk1.c: Add tests for new functions.
* debug/mbsnrtowcs_chk.c: New file.
* debug/mbsrtowcs_chk.c: New file.
* debug/wcrtomb_chk.c: New file.
* debug/wcsnrtombs_chk.c: New file.
* debug/wcsrtombs_chk.c: New file.
* include/stdio.h: Add declaration for __fxprintf.
2005-07-20 07:43:27 +00:00
|
|
|
|
#ifdef _LIBC
|
2005-07-20 17:51:14 +00:00
|
|
|
|
__fxprintf (fs->stream, "%.*s\n",
|
* wcsmbs/bits/wchar2.h: Add definitions for wcrtomb, mbsrtowcs,
wcsrtombs, mbsnrtowcs, and wcsnrtombs.
* debug/Makefile (routines): Add wcrtomb_chk, mbsrtowcs_chk,
wcsrtombs_chk, mbsnrtowcs_chk, and wcsnrtombs_chk.
* debug/Versions: Add __wcrtomb_chk, __mbsrtowcs_chk,
__wcsrtombs_chk, __mbsnrtowcs_chk, and __wcsnrtombs_chk.
* debug/tst-chk1.c: Add tests for new functions.
* debug/mbsnrtowcs_chk.c: New file.
* debug/mbsrtowcs_chk.c: New file.
* debug/wcrtomb_chk.c: New file.
* debug/wcsnrtombs_chk.c: New file.
* debug/wcsrtombs_chk.c: New file.
* include/stdio.h: Add declaration for __fxprintf.
2005-07-20 07:43:27 +00:00
|
|
|
|
(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);
|
2001-08-17 04:49:12 +00:00
|
|
|
|
#endif
|
* wcsmbs/bits/wchar2.h: Add definitions for wcrtomb, mbsrtowcs,
wcsrtombs, mbsnrtowcs, and wcsnrtombs.
* debug/Makefile (routines): Add wcrtomb_chk, mbsrtowcs_chk,
wcsrtombs_chk, mbsnrtowcs_chk, and wcsnrtombs_chk.
* debug/Versions: Add __wcrtomb_chk, __mbsrtowcs_chk,
__wcsrtombs_chk, __mbsnrtowcs_chk, and __wcsnrtombs_chk.
* debug/tst-chk1.c: Add tests for new functions.
* debug/mbsnrtowcs_chk.c: New file.
* debug/mbsrtowcs_chk.c: New file.
* debug/wcrtomb_chk.c: New file.
* debug/wcsnrtombs_chk.c: New file.
* debug/wcsrtombs_chk.c: New file.
* include/stdio.h: Add declaration for __fxprintf.
2005-07-20 07:43:27 +00:00
|
|
|
|
|
1998-09-09 11:53:19 +00:00
|
|
|
|
len += buf - fs->buf;
|
|
|
|
|
nl = buf = fs->buf;
|
|
|
|
|
}
|
|
|
|
|
}
|
1997-02-15 04:31:36 +00:00
|
|
|
|
else
|
|
|
|
|
/* We can fit the newline and blanks in before
|
|
|
|
|
the next word. */
|
|
|
|
|
*nl++ = '\n';
|
|
|
|
|
|
update from main archive 970221
1997-02-22 00:17 Ulrich Drepper <drepper@cygnus.com>
* catgets/gencat.c: Change to use argp.
* db/makedb: Likewise.
* locale/programs/localedef.c: Likewise.
* locale/programs/locale.c: Little adjustment for better usage of
argp.
1997-02-20 20:07 Greg McGary <gkm@eng.ascend.com>
* Makeconfig: Add rules for libc with bounded pointers.
* Makerules: Likewise.
* config.make.in: Likewise.
* configure.in: Likewise.
1997-02-21 10:41 Miles Bader <miles@gnu.ai.mit.edu>
* argp.h (OPTION_NO_USAGE): New macro.
* argp-help.c (usage_long_opt, usage_argful_short_opt,
add_argless_short_opt): Implement OPTION_NO_USAGE.
1997-02-20 16:41 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* malloc/obstack.h: Fix typo.
1997-02-20 15:56 Miles Bader <miles@gnu.ai.mit.edu>
* argp-fmtstream.c (__argp_fmtstream_update): Account for case
where NEXTLINE points one past the end of the active buffer.
* argp-help.c <stddef.h>: New include.
(__argp_failure): Only exit if STATE says it's ok.
(print_header, hol_entry_help): Use UPARAMS fields rather than
constants.
(_help): Call fill_in_uparams if necessary.
(struct hol_help_state): New type.
(struct pentry_state): Add hhstate field. Remove prev_entry &
sep_groups fields.
(hol_entry_help): Add HHSTATE parameter. Remove prev_entry &
sep_groups parameters.
Suppress duplicate arguments if requested, and note the fact.
(print_header, comma): Use PEST->hhstate fields.
(hol_help): Add HHSTATE variable & pass to hol_entry_help.
Remove LAST_ENTRY & SEP_GROUPS variables.
If any suplicate arguments were suppressed, print explanatory note.
(filter_doc): Replace PEST parameter with STATE.
(struct uparams): New type.
(uparams): New variable.
(struct uparam_name): New type.
(uparam_names): New variable.
(fill_in_uparams): New function.
(__argp_failure, __argp_error, __argp_state_help): Make STATE
parameter const.
* argp.h (argp_state_help, __argp_state_help, argp_usage,
__argp_usage, argp_error, __argp_error, argp_failure,
__argp_failure): Make STATE parameter const.
(ARGP_KEY_HELP_DUP_ARGS_NOTE): New macro.
* argp.h (argp_program_bug_address): Make const.
1997-02-20 19:20 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/unix/mman/syscalls.list: Explain msync interface.
1997-02-19 01:37 Erik Troan <ewt@redhat.com>
* shadow/sgetspent_r.c: Accept empty third, fourth and fifth fields.
1997-02-20 14:44 Andreas Jaeger <aj@arthur.pfalz.de>
* stdio-common/test-fseek.c: Remove temporary file, add
copyright.
1997-02-20 17:51 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/generic/netinet/in.h: Protect contents using
__BEGIN/END_DECLS. Reported by a sun <asun@zoology.washington.edu>.
* inet/net/ethernet.h: Move to sysdeps/unix/sysv/linux/net.
* inet/Makefile (headers): Remove net/ethernet.h.
* sysdeps/unix/sysv/linux/Makefile: Install net/ethernet.h.
* sysdeps/unix/sysv/linux/Dist: Distribute net/ethernet.h.
1997-02-20 15:23 Thorsten Kukuk <kukuk@weber.uni-paderborn.de>
* nss/nsswitch.c (__nss_configure_lookup): Use correct test when
searching in sorted array.
1997-02-20 01:24 Philip Blundell <pjb27@cam.ac.uk>
* inet/getnameinfo.c: Change to use reentrant getXXbyYY functions
and protect modification of global data.
1997-02-19 18:48 Miles Bader <miles@gnu.ai.mit.edu>
* argp-parse.c (argp_default_parser): Set STATE->name for OPT_PROGNAME.
(parser_init): Use the basename for PARSER->state.name.
* argp-help.c (__argp_error, __argp_failure, __argp_state_help):
Use PROGRAM_INVOCATION_SHORT_NAME instead of PROGRAM_INVOCATION_NAME.
* argp-parse.c (parser_init): Set PARSER->state.flags.
Make check whether PARSER has the prog name in argv[0] at the
proper place.
1997-02-19 23:34 Ulrich Drepper <drepper@cygnus.com>
* locale/programs/ld-time.c (time_finish): t_fmt_ampm is optional.
Use default value instead of printing a warning.
* nss/XXX-lookup.c: Add misssing explanation.
1997-02-19 19:14 Andreas Jaeger <aj@arthur.pfalz.de>
* inet/in6_addr.c: Add missing braces.
* inet/getnameinfo.c: Include <arpa/inet.h>.
* sysdeps/posix/getaddrinfo.c: Include <arpa/inet.h>.
1997-02-19 11:46 Ulrich Drepper <drepper@cygnus.com>
* string/strxfrm.c (STRCOLL): Correct handling of `position'
levels with no non-IGNOREd element and handling of NUL byte.
* string/strcoll.c (STRXFRM): Likewise.
* locale/weight.h: Likewise.
* shadow/sgetspent_r.c (LINE_PARSER): Add missing ')'.
1997-02-22 01:20:46 +00:00
|
|
|
|
if (nextline - nl >= fs->wmargin
|
|
|
|
|
|| (nextline == buf + len + 1 && fs->end - nextline >= fs->wmargin))
|
1997-02-15 04:31:36 +00:00
|
|
|
|
/* Add blanks up to the wrap margin column. */
|
|
|
|
|
for (i = 0; i < fs->wmargin; ++i)
|
|
|
|
|
*nl++ = ' ';
|
|
|
|
|
else
|
|
|
|
|
for (i = 0; i < fs->wmargin; ++i)
|
2001-08-17 04:49:12 +00:00
|
|
|
|
if (_IO_fwide (fs->stream, 0) > 0)
|
|
|
|
|
putwc_unlocked (L' ', fs->stream);
|
|
|
|
|
else
|
|
|
|
|
putc_unlocked (' ', fs->stream);
|
1997-02-15 04:31:36 +00:00
|
|
|
|
|
|
|
|
|
/* Copy the tail of the original buffer into the current buffer
|
|
|
|
|
position. */
|
update from main archive 970221
1997-02-22 00:17 Ulrich Drepper <drepper@cygnus.com>
* catgets/gencat.c: Change to use argp.
* db/makedb: Likewise.
* locale/programs/localedef.c: Likewise.
* locale/programs/locale.c: Little adjustment for better usage of
argp.
1997-02-20 20:07 Greg McGary <gkm@eng.ascend.com>
* Makeconfig: Add rules for libc with bounded pointers.
* Makerules: Likewise.
* config.make.in: Likewise.
* configure.in: Likewise.
1997-02-21 10:41 Miles Bader <miles@gnu.ai.mit.edu>
* argp.h (OPTION_NO_USAGE): New macro.
* argp-help.c (usage_long_opt, usage_argful_short_opt,
add_argless_short_opt): Implement OPTION_NO_USAGE.
1997-02-20 16:41 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* malloc/obstack.h: Fix typo.
1997-02-20 15:56 Miles Bader <miles@gnu.ai.mit.edu>
* argp-fmtstream.c (__argp_fmtstream_update): Account for case
where NEXTLINE points one past the end of the active buffer.
* argp-help.c <stddef.h>: New include.
(__argp_failure): Only exit if STATE says it's ok.
(print_header, hol_entry_help): Use UPARAMS fields rather than
constants.
(_help): Call fill_in_uparams if necessary.
(struct hol_help_state): New type.
(struct pentry_state): Add hhstate field. Remove prev_entry &
sep_groups fields.
(hol_entry_help): Add HHSTATE parameter. Remove prev_entry &
sep_groups parameters.
Suppress duplicate arguments if requested, and note the fact.
(print_header, comma): Use PEST->hhstate fields.
(hol_help): Add HHSTATE variable & pass to hol_entry_help.
Remove LAST_ENTRY & SEP_GROUPS variables.
If any suplicate arguments were suppressed, print explanatory note.
(filter_doc): Replace PEST parameter with STATE.
(struct uparams): New type.
(uparams): New variable.
(struct uparam_name): New type.
(uparam_names): New variable.
(fill_in_uparams): New function.
(__argp_failure, __argp_error, __argp_state_help): Make STATE
parameter const.
* argp.h (argp_state_help, __argp_state_help, argp_usage,
__argp_usage, argp_error, __argp_error, argp_failure,
__argp_failure): Make STATE parameter const.
(ARGP_KEY_HELP_DUP_ARGS_NOTE): New macro.
* argp.h (argp_program_bug_address): Make const.
1997-02-20 19:20 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/unix/mman/syscalls.list: Explain msync interface.
1997-02-19 01:37 Erik Troan <ewt@redhat.com>
* shadow/sgetspent_r.c: Accept empty third, fourth and fifth fields.
1997-02-20 14:44 Andreas Jaeger <aj@arthur.pfalz.de>
* stdio-common/test-fseek.c: Remove temporary file, add
copyright.
1997-02-20 17:51 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/generic/netinet/in.h: Protect contents using
__BEGIN/END_DECLS. Reported by a sun <asun@zoology.washington.edu>.
* inet/net/ethernet.h: Move to sysdeps/unix/sysv/linux/net.
* inet/Makefile (headers): Remove net/ethernet.h.
* sysdeps/unix/sysv/linux/Makefile: Install net/ethernet.h.
* sysdeps/unix/sysv/linux/Dist: Distribute net/ethernet.h.
1997-02-20 15:23 Thorsten Kukuk <kukuk@weber.uni-paderborn.de>
* nss/nsswitch.c (__nss_configure_lookup): Use correct test when
searching in sorted array.
1997-02-20 01:24 Philip Blundell <pjb27@cam.ac.uk>
* inet/getnameinfo.c: Change to use reentrant getXXbyYY functions
and protect modification of global data.
1997-02-19 18:48 Miles Bader <miles@gnu.ai.mit.edu>
* argp-parse.c (argp_default_parser): Set STATE->name for OPT_PROGNAME.
(parser_init): Use the basename for PARSER->state.name.
* argp-help.c (__argp_error, __argp_failure, __argp_state_help):
Use PROGRAM_INVOCATION_SHORT_NAME instead of PROGRAM_INVOCATION_NAME.
* argp-parse.c (parser_init): Set PARSER->state.flags.
Make check whether PARSER has the prog name in argv[0] at the
proper place.
1997-02-19 23:34 Ulrich Drepper <drepper@cygnus.com>
* locale/programs/ld-time.c (time_finish): t_fmt_ampm is optional.
Use default value instead of printing a warning.
* nss/XXX-lookup.c: Add misssing explanation.
1997-02-19 19:14 Andreas Jaeger <aj@arthur.pfalz.de>
* inet/in6_addr.c: Add missing braces.
* inet/getnameinfo.c: Include <arpa/inet.h>.
* sysdeps/posix/getaddrinfo.c: Include <arpa/inet.h>.
1997-02-19 11:46 Ulrich Drepper <drepper@cygnus.com>
* string/strxfrm.c (STRCOLL): Correct handling of `position'
levels with no non-IGNOREd element and handling of NUL byte.
* string/strcoll.c (STRXFRM): Likewise.
* locale/weight.h: Likewise.
* shadow/sgetspent_r.c (LINE_PARSER): Add missing ')'.
1997-02-22 01:20:46 +00:00
|
|
|
|
if (nl < nextline)
|
1997-02-15 04:31:36 +00:00
|
|
|
|
memmove (nl, nextline, buf + len - nextline);
|
|
|
|
|
len -= nextline - buf;
|
|
|
|
|
|
|
|
|
|
/* Continue the scan on the remaining lines in the buffer. */
|
|
|
|
|
buf = nl;
|
|
|
|
|
|
|
|
|
|
/* Restore bufp to include all the remaining text. */
|
|
|
|
|
fs->p = nl + len;
|
|
|
|
|
|
|
|
|
|
/* Reset the counter of what has been output this line. If wmargin
|
|
|
|
|
is 0, we want to avoid the lmargin getting added, so we set
|
|
|
|
|
point_col to a magic value of -1 in that case. */
|
|
|
|
|
fs->point_col = fs->wmargin ? fs->wmargin : -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Remember that we've scanned as far as the end of the buffer. */
|
|
|
|
|
fs->point_offs = fs->p - fs->buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Ensure that FS has space for AMOUNT more bytes in its buffer, either by
|
|
|
|
|
growing the buffer, or by flushing it. True is returned iff we succeed. */
|
|
|
|
|
int
|
|
|
|
|
__argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount)
|
|
|
|
|
{
|
1997-04-08 23:42:08 +00:00
|
|
|
|
if ((size_t) (fs->end - fs->p) < amount)
|
1997-02-15 04:31:36 +00:00
|
|
|
|
{
|
|
|
|
|
ssize_t wrote;
|
|
|
|
|
|
|
|
|
|
/* Flush FS's buffer. */
|
|
|
|
|
__argp_fmtstream_update (fs);
|
|
|
|
|
|
* wcsmbs/bits/wchar2.h: Add definitions for wcrtomb, mbsrtowcs,
wcsrtombs, mbsnrtowcs, and wcsnrtombs.
* debug/Makefile (routines): Add wcrtomb_chk, mbsrtowcs_chk,
wcsrtombs_chk, mbsnrtowcs_chk, and wcsnrtombs_chk.
* debug/Versions: Add __wcrtomb_chk, __mbsrtowcs_chk,
__wcsrtombs_chk, __mbsnrtowcs_chk, and __wcsnrtombs_chk.
* debug/tst-chk1.c: Add tests for new functions.
* debug/mbsnrtowcs_chk.c: New file.
* debug/mbsrtowcs_chk.c: New file.
* debug/wcrtomb_chk.c: New file.
* debug/wcsnrtombs_chk.c: New file.
* debug/wcsrtombs_chk.c: New file.
* include/stdio.h: Add declaration for __fxprintf.
2005-07-20 07:43:27 +00:00
|
|
|
|
#ifdef _LIBC
|
2005-07-20 17:51:14 +00:00
|
|
|
|
__fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf);
|
* wcsmbs/bits/wchar2.h: Add definitions for wcrtomb, mbsrtowcs,
wcsrtombs, mbsnrtowcs, and wcsnrtombs.
* debug/Makefile (routines): Add wcrtomb_chk, mbsrtowcs_chk,
wcsrtombs_chk, mbsnrtowcs_chk, and wcsnrtombs_chk.
* debug/Versions: Add __wcrtomb_chk, __mbsrtowcs_chk,
__wcsrtombs_chk, __mbsnrtowcs_chk, and __wcsnrtombs_chk.
* debug/tst-chk1.c: Add tests for new functions.
* debug/mbsnrtowcs_chk.c: New file.
* debug/mbsrtowcs_chk.c: New file.
* debug/wcrtomb_chk.c: New file.
* debug/wcsnrtombs_chk.c: New file.
* debug/wcsrtombs_chk.c: New file.
* include/stdio.h: Add declaration for __fxprintf.
2005-07-20 07:43:27 +00:00
|
|
|
|
wrote = fs->p - fs->buf;
|
|
|
|
|
#else
|
|
|
|
|
wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream);
|
2001-08-17 04:49:12 +00:00
|
|
|
|
#endif
|
1997-02-15 04:31:36 +00:00
|
|
|
|
if (wrote == fs->p - fs->buf)
|
|
|
|
|
{
|
|
|
|
|
fs->p = fs->buf;
|
|
|
|
|
fs->point_offs = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fs->p -= wrote;
|
|
|
|
|
fs->point_offs -= wrote;
|
|
|
|
|
memmove (fs->buf, fs->buf + wrote, fs->p - fs->buf);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1997-04-08 23:42:08 +00:00
|
|
|
|
if ((size_t) (fs->end - fs->buf) < amount)
|
1997-02-15 04:31:36 +00:00
|
|
|
|
/* Gotta grow the buffer. */
|
|
|
|
|
{
|
2003-09-25 05:34:28 +00:00
|
|
|
|
size_t old_size = fs->end - fs->buf;
|
|
|
|
|
size_t new_size = old_size + amount;
|
|
|
|
|
char *new_buf;
|
1997-02-15 04:31:36 +00:00
|
|
|
|
|
2003-09-25 05:34:28 +00:00
|
|
|
|
if (new_size < old_size || ! (new_buf = realloc (fs->buf, new_size)))
|
1997-02-15 04:31:36 +00:00
|
|
|
|
{
|
|
|
|
|
__set_errno (ENOMEM);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs->buf = new_buf;
|
|
|
|
|
fs->end = new_buf + new_size;
|
|
|
|
|
fs->p = fs->buf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
|
__argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...)
|
|
|
|
|
{
|
1997-04-08 23:42:08 +00:00
|
|
|
|
int out;
|
1999-11-10 08:15:19 +00:00
|
|
|
|
size_t avail;
|
1997-02-15 04:31:36 +00:00
|
|
|
|
size_t size_guess = PRINTF_SIZE_GUESS; /* How much space to reserve. */
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
if (! __argp_fmtstream_ensure (fs, size_guess))
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
va_start (args, fmt);
|
1999-11-10 08:15:19 +00:00
|
|
|
|
avail = fs->end - fs->p;
|
|
|
|
|
out = __vsnprintf (fs->p, avail, fmt, args);
|
1997-02-15 04:31:36 +00:00
|
|
|
|
va_end (args);
|
2002-09-24 04:24:25 +00:00
|
|
|
|
if ((size_t) out >= avail)
|
1999-11-10 08:15:19 +00:00
|
|
|
|
size_guess = out + 1;
|
1997-02-15 04:31:36 +00:00
|
|
|
|
}
|
2002-09-24 04:24:25 +00:00
|
|
|
|
while ((size_t) out >= avail);
|
1997-02-15 04:31:36 +00:00
|
|
|
|
|
|
|
|
|
fs->p += out;
|
|
|
|
|
|
|
|
|
|
return out;
|
|
|
|
|
}
|
2003-01-08 06:49:39 +00:00
|
|
|
|
#if 0
|
|
|
|
|
/* Not exported. */
|
1997-02-15 04:31:36 +00:00
|
|
|
|
#ifdef weak_alias
|
|
|
|
|
weak_alias (__argp_fmtstream_printf, argp_fmtstream_printf)
|
|
|
|
|
#endif
|
2003-01-08 06:49:39 +00:00
|
|
|
|
#endif
|
1997-02-15 04:31:36 +00:00
|
|
|
|
|
|
|
|
|
#endif /* !ARGP_FMTSTREAM_USE_LINEWRAP */
|