From 18162030e6a484ec5bc4d0d4fd1771b494d0730b Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Sat, 8 Jan 2022 16:18:16 +0200 Subject: 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. --- tools/parseopt.c | 22 ++++++++++++++++++---- 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,9 +437,18 @@ 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])) { @@ -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); -- cgit v1.2.1