gnulib: fix argp --help formatting

This is a patch that was sent by Simon Reinhardt to gnulib and has
never been applied.  It fixes a several formatting issues in --help.
https://lists.gnu.org/archive/html/bug-gnulib/2016-02/msg00013.html

* lib/argp-fmtstream.c (__argp_fmtstream_update): Flush output as soon
as possible.
* lib/argp-fmtstream.h (struct argp_fmtstream): Member point_offs is
no longer needed.
* lib/argp-help.c (indent_to): Flush output to avoid a spurious
newline before an overlong word.
This commit is contained in:
Alexandre Duret-Lutz 2025-02-06 21:51:09 +01:00
parent 27fb175276
commit d0e404fec0
3 changed files with 56 additions and 157 deletions

View file

@ -95,9 +95,7 @@ struct argp_fmtstream
size_t lmargin, rmargin; /* Left and right margins. */
ssize_t wmargin; /* Margin to wrap to, or -1 to truncate. */
/* Point in buffer to which we've processed for wrapping, but not output. */
size_t point_offs;
/* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin. */
/* Output column at buf, or -1 meaning 0 but don't add lmargin. */
ssize_t point_col;
char *buf; /* Output buffer. */
@ -250,7 +248,7 @@ ARGP_FS_EI size_t
__argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin)
{
size_t __old;
if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
if (__fs->p > __fs->buf)
__argp_fmtstream_update (__fs);
__old = __fs->lmargin;
__fs->lmargin = __lmargin;
@ -262,7 +260,7 @@ ARGP_FS_EI size_t
__argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin)
{
size_t __old;
if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
if (__fs->p > __fs->buf)
__argp_fmtstream_update (__fs);
__old = __fs->rmargin;
__fs->rmargin = __rmargin;
@ -274,7 +272,7 @@ ARGP_FS_EI size_t
__argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin)
{
size_t __old;
if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
if (__fs->p > __fs->buf)
__argp_fmtstream_update (__fs);
__old = __fs->wmargin;
__fs->wmargin = __wmargin;
@ -285,7 +283,7 @@ __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin)
ARGP_FS_EI size_t
__argp_fmtstream_point (argp_fmtstream_t __fs)
{
if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
if (__fs->p > __fs->buf)
__argp_fmtstream_update (__fs);
return __fs->point_col >= 0 ? __fs->point_col : 0;
}