# Generate a short man page from --help and --version output.
# Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009,
-# 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2020, 2021, 2022 Free Software
-# Foundation, Inc.
+# 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2020, 2021, 2022, 2025
+# Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
use POSIX qw(strftime setlocale LC_ALL);
my $this_program = 'help2man';
-my $this_version = '1.49.3';
+my $this_version = '1.50.1';
sub _ { $_[0] }
sub configure_locale
sub get_option_value;
sub convert_option;
sub fix_italic_spacing;
+sub set_indent;
my $version_info = enc_user sprintf _(<<'EOT'), $this_program, $this_version;
GNU %s %s
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009,
-2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2020, 2021, 2022 Free Software
-Foundation, Inc.
+2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2020, 2021, 2022, 2025 Free
+Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-p, --info-page=TEXT name of Texinfo manual
-N, --no-info suppress pointer to Texinfo manual
-l, --libtool exclude the `lt-' from the program name
+ --loose-indent relax matching of indented continuation lines
-b, --bold-refs apply bold style to references
--help print this help, then exit
--version print version number, then exit
-h, --help-option=STRING help option string
-v, --version-option=STRING version option string
- --version-string=STRING version string
- --no-discard-stderr include stderr when parsing option output
+ --version-string=STRING version string
+ --no-discard-stderr include stderr when parsing option output
Report bugs to <bug-help2man@gnu.org>.
EOT
my $source = '';
my $help_option = '--help';
my $version_option = '--version';
+my $loose_indent = 0;
my $discard_stderr = 1;
my ($opt_name, @opt_include, $opt_output, $opt_info, $opt_no_info, $opt_libtool,
$opt_bold_refs, $version_text);
'p|info-page=s' => \$opt_info,
'N|no-info' => \$opt_no_info,
'l|libtool' => \$opt_libtool,
+ 'loose-indent!' => \$loose_indent,
'b|bold-refs' => \$opt_bold_refs,
'help' => sub { print $help_info; exit },
'version' => sub { print $version_info; exit },
# character.
s/^Copyright +(?:\xa9|\([Cc]\))/Copyright \\(co/mg;
+my $require_mono = 0;
while (length)
{
# Convert some standard paragraph names.
}
# Examples, indicated by an indented leading $, % or > are
- # rendered in a constant width font.
+ # rendered in a monospace font when using groff in troff mode.
if (/^( +)([\$\%>] )\S/)
{
- my $indent = $1;
+ my $spaces = $1;
my $prefix = $2;
my $break = '.IP';
- while (s/^$indent\Q$prefix\E(\S.*)\n*//)
+ while (s/^$spaces\Q$prefix\E(\S.*)\n*//)
{
- $include{$sect} .= "$break\n\\f(CW$prefix$1\\fR\n";
+ $include{$sect} .= "$break\n\\*[mono]$prefix$1\\*[/mono]\n";
+ $require_mono++;
$break = '.br';
}
if (s/^( {1,10}([+-]\S.*?))(?:( +(?!-))|\n( {20,}))(\S.*)\n//)
{
$matched .= $& if %append_match;
- $indent = length ($4 || "$1$3");
+ $indent = set_indent length ($4 || "$1$3");
$content = ".TP\n\x84$2\n\x84$5\n";
unless ($4)
{
# Indent may be different on second line.
- $indent = length $& if /^ {20,}/;
+ $indent = set_indent length $& if /^ {20,}/;
}
}
elsif (s/^( +(\S.*?) +)(\S.*)\n//)
{
$matched .= $& if %append_match;
- $indent = length $1;
+ $indent = set_indent length $1;
$content = ".TP\n\x84$2\n\x84$3\n";
}
elsif (s/^( +)(\S.*)\n//)
{
$matched .= $& if %append_match;
- $indent = length $1;
+ $indent = set_indent length $1;
$content = ".IP\n\x84$2\n";
}
# Append additional text.
while (my ($sect, $text) = each %append)
{
- $include{$sect} .= $append{$sect};
+ $require_mono++ if $text =~ /\\\*\[mono\]/;
+ $include{$sect} .= $text;
}
# Replace sections.
.TH $PROGRAM "$section" "$date" "$source" "$manual"
EOT
+# If monospace was used emit macros for groff.
+print enc <<'EOT' if $require_mono;
+.\" Define monospaced roman font for groff in troff mode.
+.if t .if \n(.g \{\
+. ds mono \f(CR
+. ds /mono \fP
+.\}
+EOT
+
# Section ordering.
my @pre = (_('NAME'), _('SYNOPSIS'), _('DESCRIPTION'), _('OPTIONS'),
_('EXAMPLES'));
s!\\fI(.*?)\\f([BRP])!\\fI\\,$1\\/\\f$2!g;
return $_;
}
+
+# Return indent to use: either the value passed in, or $v,$v+4 if
+# loose index matching is used. The resulting string is used in a
+# regex as " {$indent}", so will match either the exact number of
+# spaces passed in, or up to four more. See the --loose-indent
+# option.
+sub set_indent
+{
+ my $i = $_[0];
+ $i .= ',' . ($_[0] + 4) if $loose_indent;
+ return $i;
+}