]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
doc: sync help2man to latest version
authorPádraig Brady <P@draigBrady.com>
Wed, 5 Feb 2025 12:00:22 +0000 (12:00 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 5 Feb 2025 12:41:36 +0000 (12:41 +0000)
* man/help2man: sync changes to commit 8fe02612
The main change here is to Use \f(CR for monospace text
when using groff in troff mode.
Previously \f(CW was used, but that's not portable.

man/help2man

index 331feb02d56bea6da0d568797a826c6c5e493433..960eebcae24218c25b4dde62afc94bdcb7a4fd68 100755 (executable)
@@ -2,8 +2,8 @@
 
 # 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
@@ -29,7 +29,7 @@ use Text::Tabs qw(expand);
 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
@@ -49,13 +49,14 @@ sub program_basename;
 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.
 
@@ -78,6 +79,7 @@ Usage: %s [OPTION]... EXECUTABLE
  -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
@@ -87,8 +89,8 @@ stdout although alternatives may be specified using:
 
  -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
@@ -98,6 +100,7 @@ my $manual = '';
 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);
@@ -114,6 +117,7 @@ my %opt_def = (
     '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 },
@@ -442,6 +446,7 @@ s/([^\n])\n($PAT_BUGS|$PAT_AUTHOR|$PAT_SEE_ALSO) /$1\n\n$2 /og;
 # character.
 s/^Copyright +(?:\xa9|\([Cc]\))/Copyright \\(co/mg;
 
+my $require_mono = 0;
 while (length)
 {
     # Convert some standard paragraph names.
@@ -500,15 +505,16 @@ while (length)
     }
 
     # 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';
        }
 
@@ -531,12 +537,12 @@ while (length)
     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,}/;
        }
     }
 
@@ -552,7 +558,7 @@ while (length)
     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";
     }
 
@@ -560,7 +566,7 @@ while (length)
     elsif (s/^( +)(\S.*)\n//)
     {
        $matched .= $& if %append_match;
-       $indent = length $1;
+       $indent = set_indent length $1;
        $content = ".IP\n\x84$2\n";
     }
 
@@ -681,7 +687,8 @@ EOT
 # Append additional text.
 while (my ($sect, $text) = each %append)
 {
-    $include{$sect} .= $append{$sect};
+    $require_mono++ if $text =~ /\\\*\[mono\]/;
+    $include{$sect} .= $text;
 }
 
 # Replace sections.
@@ -696,6 +703,15 @@ print enc <<EOT;
 .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'));
@@ -800,3 +816,15 @@ sub fix_italic_spacing
     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;
+}