2 * Helper functions for formatting --help program output.
4 * Copyright © 2021, 2023-2024 Nick Bowler
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 * On some very old preprocessors (e.g., VAX C) -Dinline= defines inline to 1,
25 * so when not using a config header detect and work around the problem here.
27 #if !HAVE_CONFIG_H && (inline - 1 == 0)
35 * Print an option string describing the short option character (if any),
36 * the long option name, and the argument name (if applicable). The argument
37 * name is localized (if NLS is enabled). If the string width is more than
38 * l columns, a newline is printed and 0 is returned. Otherwise, a newline
39 * is not printed and the string width (in columns) is returned.
41 int help_print_optstring(const struct option
*opt
, const char *argname
, int l
);
44 * Print an option description with each line indented. If opt is not NULL,
45 * then the string is first localized (if NLS is enabled) via pgettext_expr
46 * with the context set to opt->name. The first line will be indented by
47 * i-w spaces (to account for the cursor being in some other column), all
48 * other lines are indented by i spaces.
50 * The output always ends with a newline, regardless of whether or not the
51 * input string ends with a newline.
53 void help_print_desc(const struct option
*opt
, const char *desc
, int i
, int w
);
55 static inline void help_print_option(const struct option
*opt
,
56 const char *argname
, const char *desc
,
62 help_print_desc(opt
, desc
, w
,
63 help_print_optstring(opt
, argname
, w
-2));