bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Patch] argp: fix line wrapping in --help output


From: Simon Reinhardt
Subject: [Patch] argp: fix line wrapping in --help output
Date: Tue, 9 Feb 2016 16:51:23 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.5.0

Hi,

Argp provides line wrapping of help and usage output. For this it
maintains a buffer in the struct argp_fmtstream_t. During line breaking
the buffer's contents grow due to the inserted spaces needed to indent
the lines (function __argp_fmtstream_update in lib/argp-fmtstream.c).
This breaks once the buffer is full and produces malformatted output.
Example program:

#include <config.h>
#include <argp.h>

static struct argp_option options[] = {
  {"test", 't', 0, 0, "1\n2\n3\n4\n5\n6"},
  {0}
};

static struct argp argp = {options};

int
main (int argc, char **argv)
{
  argp_parse(&argp, argc, argv, 0, 0, 0);
  return 0;
}

This gives
$ ./report --help
                             Usage: report [OPTION...]

  -t, --test                 1
                             2
                             3
                             4
                             5
6
  -?, --help                 give this help list
      --usage                give a short usage message

The indentation that should prefix the '6' erroneously prefixes the
'Usage' line.

The suggested fix to __argp_fmtstream_update works by making it flush
everything ASAP. This way no formatting of content inside the buffer is
needed.

This passes the existing tests (test-argp.c, test-argp-2.sh). In
addition it produces identical --help and --usage output for GNU tar's
large option table (see attached file tar.c).

Further Nitpicking:

before overlong words that exceed the line length one gets a spurious
newline before the word:

static struct argp_option options[] = {
  {"x", 'x', 0, 0,
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
   "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"},
  {0}
};

will produce the --help output
Usage: bigword [OPTION...]

  -x, --x
                             xxxxxxx(...)
  -?, --help                 give this help list
      --usage                give a short usage message

This is fixed by flushing at the end of indent_to in argp-help.c

Cheers,
Simon

Attachment: tar.c
Description: Text Data

Attachment: 0001-argp-Fix-line-wrapping-for-help-output.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]