diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2022-01-08 16:18:16 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2022-01-08 18:38:55 +0200 |
commit | 18162030e6a484ec5bc4d0d4fd1771b494d0730b (patch) | |
tree | e97b2ed5f7c358ee65a609cf3c6e2db5f68f1681 | |
parent | b1d8981cc8e0845d1917c859356fa5ba458d17ad (diff) | |
download | gdbm-18162030e6a484ec5bc4d0d4fd1771b494d0730b.tar.gz |
Bugfixes in parseopt and wordwrap
* tools/parseopt.c (print_option): Add newlines around group header
text.
Insert a comma between the short and corresponding long option.
(parseopt_print_help): Don't use parseopt_program_args if it's NULL
or empty.
* tools/wordwrap.c (wordwrap_set_left_margin): Always force reindent
of the following line.
(flush_line): Fix the "full write" condition.
-rw-r--r-- | tools/parseopt.c | 22 | ||||
-rw-r--r-- | tools/wordwrap.c | 7 |
2 files changed, 21 insertions, 8 deletions
diff --git a/tools/parseopt.c b/tools/parseopt.c index f32b8e6..2d646ff 100644 --- a/tools/parseopt.c +++ b/tools/parseopt.c @@ -403,7 +403,11 @@ print_option (WORDWRAP_FILE wf, size_t num) wordwrap_set_left_margin (wf, header_col); wordwrap_set_right_margin (wf, rmargin); if (opt->opt_descr[0]) - wordwrap_puts (wf, gettext (opt->opt_descr)); + { + wordwrap_putc (wf, '\n'); + wordwrap_puts (wf, gettext (opt->opt_descr)); + wordwrap_putc (wf, '\n'); + } wordwrap_putc (wf, '\n'); return num + 1; } @@ -433,14 +437,23 @@ print_option (WORDWRAP_FILE wf, size_t num) } #ifdef HAVE_GETOPT_LONG - w = 0; - wordwrap_set_left_margin (wf, long_opt_col); for (i = num; i < next; i++) { if (IS_VALID_LONG_OPTION (&option_tab[i])) { if (w) wordwrap_write (wf, ", ", 2); + wordwrap_set_left_margin (wf, long_opt_col); + w = 0; + break; + } + } + for (; i < next; i++) + { + if (IS_VALID_LONG_OPTION (&option_tab[i])) + { + if (w) + wordwrap_write (wf, ", ", 2); wordwrap_printf (wf, "--%s", option_tab[i].opt_long); delim = '='; if (dup_args) @@ -474,7 +487,8 @@ parseopt_print_help (void) wordwrap_printf (wf, "%s %s [%s]... %s\n", _("Usage:"), parseopt_program_name ? parseopt_program_name : progname, _("OPTION"), - gettext (parseopt_program_args)); + (parseopt_program_args && parseopt_program_args[0]) + ? gettext (parseopt_program_args) : ""); wordwrap_set_right_margin (wf, rmargin); if (parseopt_program_doc && parseopt_program_doc[0]) diff --git a/tools/wordwrap.c b/tools/wordwrap.c index 226cb54..05dcff4 100644 --- a/tools/wordwrap.c +++ b/tools/wordwrap.c @@ -281,7 +281,7 @@ flush_line (WORDWRAP_FILE wf, size_t size) else len = size; - if (len > wf->left_margin) + if (len >= wf->left_margin) { n = full_write (wf, len); if (n == -1) @@ -365,16 +365,15 @@ wordwrap_set_left_margin (WORDWRAP_FILE wf, unsigned left) bol = wordwrap_at_bol (wf); wf->left_margin = left; + wf->indent = 1; if (left < wf->offset) { - wf->indent = 1; if (!bol) flush_line (wf, wf->offset);//FIXME: remove trailing ws } else { - wf->indent = left > wf->offset; - if (wf->indent) + if (left > wf->offset) memset (wf->buffer + wf->offset, ' ', wf->left_margin - wf->offset); } wordwrap_line_init (wf); |