summaryrefslogtreecommitdiff
path: root/man
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-07-23 07:00:29 +0000
committerJim Meyering <jim@meyering.net>2003-07-23 07:00:29 +0000
commit1725e8a642a06ed84238d1bed2314b126243237c (patch)
tree169b43e3a8205e683d06dc996be268d7bbd830bb /man
parent9efbdbc75b80e7b269df05fe3fe89d6b2836011f (diff)
downloadcoreutils-1725e8a642a06ed84238d1bed2314b126243237c.tar.xz
Update to version 1.33.
Diffstat (limited to 'man')
-rwxr-xr-xman/help2man203
1 files changed, 120 insertions, 83 deletions
diff --git a/man/help2man b/man/help2man
index a589f8ec3..228635c0b 100755
--- a/man/help2man
+++ b/man/help2man
@@ -1,7 +1,7 @@
#!/usr/bin/perl -w
# Generate a short man page from --help and --version output.
-# Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Free Software
+# Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
# Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
@@ -25,29 +25,64 @@ use 5.005;
use strict;
use Getopt::Long;
use Text::Tabs qw(expand);
-use POSIX qw(strftime setlocale LC_TIME);
+use POSIX qw(strftime setlocale LC_ALL);
+use locale;
my $this_program = 'help2man';
-my $this_version = '1.29';
-my $version_info = <<EOT;
-GNU $this_program $this_version
+my $this_version = '1.33';
-Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+my $have_gettext;
+BEGIN {
+ eval {
+ require Locale::gettext;
+ Locale::gettext->import;
+ $have_gettext = 1;
+ };
+
+ unless ($have_gettext)
+ {
+ *gettext = sub { $_[0] };
+ *textdomain = sub {};
+ }
+}
+
+sub _ { gettext @_ }
+sub N_ { $_[0] }
+
+textdomain $this_program;
+{
+ my ($user_locale) = grep defined && length,
+ (map $ENV{$_}, qw(LANGUAGE LC_ALL LC_MESSAGES LANG)), 'C';
+
+ sub kark # die with message formatted in the invoking user's locale
+ {
+ setlocale LC_ALL, $user_locale;
+ my $fmt = gettext shift;
+ die +(sprintf $fmt, @_), "\n";
+ }
+}
+
+my $version_info = sprintf _(<<'EOT'), $this_program, $this_version;
+GNU %s %s
+
+Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 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.
-Written by Brendan O'Dea <bod\@debian.org>
+Written by Brendan O'Dea <bod@debian.org>
EOT
-my $help_info = <<EOT;
-`$this_program' generates a man page out of `--help' and `--version' output.
+my $help_info = sprintf _(<<'EOT'), $this_program, $this_program;
+`%s' generates a man page out of `--help' and `--version' output.
-Usage: $this_program [OPTION]... EXECUTABLE
+Usage: %s [OPTION]... EXECUTABLE
-n, --name=STRING description for the NAME paragraph
-s, --section=SECTION section number for manual page (1, 6, 8)
-m, --manual=TEXT name of manual (User Commands, ...)
-S, --source=TEXT source of program (FSF, Debian, ...)
+ -L, --locale=STRING select locale (default "C")
-i, --include=FILE include material from `FILE'
-I, --opt-include=FILE include material from `FILE' if it exists
-o, --output=FILE send output to `FILE'
@@ -62,12 +97,13 @@ alternatives may be specified using:
-h, --help-option=STRING help option string
-v, --version-option=STRING version option string
-Report bugs to <bug-help2man\@gnu.org>.
+Report bugs to <bug-help2man@gnu.org>.
EOT
my $section = 1;
my $manual = '';
my $source = '';
+my $locale = 'C';
my $help_option = '--help';
my $version_option = '--version';
my ($opt_name, @opt_include, $opt_output, $opt_info, $opt_no_info);
@@ -77,6 +113,7 @@ my %opt_def = (
's|section=s' => \$section,
'm|manual=s' => \$manual,
'S|source=s' => \$source,
+ 'L|locale=s' => \$locale,
'i|include=s' => sub { push @opt_include, [ pop, 1 ] },
'I|opt-include=s' => sub { push @opt_include, [ pop, 0 ] },
'o|output=s' => \$opt_output,
@@ -86,31 +123,6 @@ my %opt_def = (
'v|version-option=s' => \$version_option,
);
-END
-{
- # Nobody ever checks the status of print()s. That's okay, because
- # if any do fail, we're guaranteed to get an indicator when we close()
- # the filehandle.
- #
- # Close stdout now, and if there were no errors, return happy status.
- # If stdout has already been closed by the script, though, do nothing.
- defined fileno STDOUT
- or return;
- close STDOUT
- and return;
-
- # Errors closing stdout. Indicate that, and hope stderr is OK.
- warn "$this_program: closing standard output: $!\n";
-
- # Don't be so arrogant as to assume that we're the first END handler
- # defined, and thus the last one invoked. There may be others yet
- # to come. $? will be passed on to them, and to the final _exit().
- #
- # If it isn't already an error, make it one (and if it _is_ an error,
- # preserve the value: it might be important).
- $? ||= 1;
-}
-
# Parse options.
Getopt::Long::config('bundling');
GetOptions (%opt_def,
@@ -120,6 +132,13 @@ GetOptions (%opt_def,
die $help_info unless @ARGV == 1;
+die "$this_program: no locale support (Locale::gettext required)\n"
+ unless $locale eq 'C' or $have_gettext;
+
+# Set localisation of date and executable's ouput.
+delete @ENV{qw(LANGUAGE LC_MESSAGES LANG)};
+setlocale LC_ALL, $ENV{LC_ALL} = $locale;
+
my %include = ();
my %append = ();
my @include = (); # retain order given in include file
@@ -140,7 +159,7 @@ while (@opt_include)
my ($inc, $required) = @{shift @opt_include};
next unless -f $inc or $required;
- die "$this_program: can't open `$inc' ($!)\n"
+ kark N_("%s: can't open `%s' (%s)"), $this_program, $inc, $!
unless open INC, $inc;
my $key;
@@ -197,8 +216,8 @@ while (@opt_include)
close INC;
- die "$this_program: no valid information found in `$inc'\n"
- unless $key;
+ kark N_("%s: no valid information found in `%s'"), $this_program, $inc
+ unless $key;
}
# Compress trailing blank lines.
@@ -207,16 +226,11 @@ for my $hash (\(%include, %append))
for (keys %$hash) { $hash->{$_} =~ s/\n+$/\n/ }
}
-# Turn off localisation of executable's ouput.
-@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
-
-# Turn off localisation of date (for strftime).
-setlocale LC_TIME, 'C';
-
# Grab help and version info from executable.
my ($help_text, $version_text) = map {
join '', map { s/ +$//; expand $_ } `$ARGV[0] $_ 2>/dev/null`
- or die "$this_program: can't get `$_' info from $ARGV[0]\n"
+ or kark N_("%s: can't get `%s' info from %s"), $this_program,
+ $_, $ARGV[0]
} $help_option, $version_option;
my $date = strftime "%B %Y", localtime;
@@ -226,12 +240,11 @@ my $version;
if ($opt_output)
{
- unlink $opt_output
- or die "$this_program: can't unlink $opt_output ($!)\n"
- if -e $opt_output;
+ unlink $opt_output or kark N_("%s: can't unlink %s (%s)"),
+ $this_program, $opt_output, $! if -e $opt_output;
open STDOUT, ">$opt_output"
- or die "$this_program: can't create $opt_output ($!)\n";
+ or kark N_("%s: can't create %s (%s)"), $this_program, $opt_output, $!;
}
# The first line of the --version information is assumed to be in one
@@ -271,10 +284,11 @@ $program =~ s!.*/!!;
$opt_no_info = 1 if $program eq 'info';
# --name overrides --include contents.
-$include{NAME} = "$program \\- $opt_name\n" if $opt_name;
+$include{_('NAME')} = "$program \\- $opt_name\n" if $opt_name;
# Default (useless) NAME paragraph.
-$include{NAME} ||= "$program \\- manual page for $program $version\n";
+$include{_('NAME')} ||= sprintf _("%s \\- manual page for %s %s") . "\n",
+ $program, $program, $version;
# Man pages traditionally have the page title in caps.
my $PROGRAM = uc $program;
@@ -285,21 +299,23 @@ unless ($manual)
{
for ($section)
{
- if (/^(1[Mm]|8)/) { $manual = 'System Administration Utilities' }
- elsif (/^6/) { $manual = 'Games' }
- else { $manual = 'User Commands' }
+ if (/^(1[Mm]|8)/) { $manual = _('System Administration Utilities') }
+ elsif (/^6/) { $manual = _('Games') }
+ else { $manual = _('User Commands') }
}
}
# Extract usage clause(s) [if any] for SYNOPSIS.
-if ($help_text =~ s/^Usage:( +(\S+))(.*)((?:\n(?: {6}\1| *or: +\S).*)*)//m)
+my $PAT_USAGE = _('Usage');
+my $PAT_USAGE_CONT = _('or');
+if ($help_text =~ s/^($PAT_USAGE):( +(\S+))(.*)((?:\n(?: {6}\1| *($PAT_USAGE_CONT): +\S).*)*)//om)
{
- my @syn = $2 . $3;
+ my @syn = $3 . $4;
- if ($_ = $4)
+ if ($_ = $5)
{
s/^\n//;
- for (split /\n/) { s/^ *(or: +)?//; push @syn, $_ }
+ for (split /\n/) { s/^ *(($PAT_USAGE_CONT): +)?//o; push @syn, $_ }
}
my $synopsis = '';
@@ -322,11 +338,11 @@ if ($help_text =~ s/^Usage:( +(\S+))(.*)((?:\n(?: {6}\1| *or: +\S).*)*)//m)
$synopsis .= "$_\n";
}
- $include{SYNOPSIS} ||= $synopsis;
+ $include{_('SYNOPSIS')} ||= $synopsis;
}
# Process text, initial section is DESCRIPTION.
-my $sect = 'DESCRIPTION';
+my $sect = _('DESCRIPTION');
$_ = "$help_text\n\n$version_text";
# Normalise paragraph breaks.
@@ -340,24 +356,35 @@ s/^\./\x80/mg;
s/^'/\x81/mg;
s/\\/\x82/g;
+my $PAT_BUGS = _('Report +bugs|Email +bug +reports +to');
+my $PAT_AUTHOR = _('Written +by');
+my $PAT_OPTIONS = _('Options');
+my $PAT_EXAMPLES = _('Examples');
+my $PAT_FREE_SOFTWARE = _('This +is +free +software');
+
# Start a new paragraph (if required) for these.
-s/([^\n])\n(Report +bugs|Email +bug +reports +to|Written +by)/$1\n\n$2/g;
+s/([^\n])\n($PAT_BUGS|$PAT_AUTHOR)/$1\n\n$2/og;
sub convert_option;
while (length)
{
# Convert some standard paragraph names.
- if (s/^(Options|Examples): *\n//)
+ if (s/^($PAT_OPTIONS): *\n//o)
{
- $sect = uc $1;
+ $sect = _('OPTIONS');
+ next;
+ }
+ elsif (s/^($PAT_EXAMPLES): *\n//o)
+ {
+ $sect = _('EXAMPLES');
next;
}
# Copyright section
if (/^Copyright +[(\xa9]/)
{
- $sect = 'COPYRIGHT';
+ $sect = _('COPYRIGHT');
$include{$sect} ||= '';
$include{$sect} .= ".PP\n" if $include{$sect};
@@ -375,7 +402,7 @@ while (length)
# Insert line breaks before additional copyright messages
# and the disclaimer.
- s/(.)\n(Copyright |This +is +free +software)/$1\n.br\n$2/g;
+ s/(.)\n(Copyright |$PAT_FREE_SOFTWARE)/$1\n.br\n$2/og;
# Join hyphenated lines.
s/([A-Za-z])-\n */$1/g;
@@ -387,15 +414,15 @@ while (length)
}
# Catch bug report text.
- if (/^(Report +bugs|Email +bug +reports +to) /)
+ if (/^($PAT_BUGS) /o)
{
- $sect = 'REPORTING BUGS';
+ $sect = _('REPORTING BUGS');
}
# Author section.
- elsif (/^Written +by/)
+ elsif (/^($PAT_AUTHOR)/o)
{
- $sect = 'AUTHOR';
+ $sect = _('AUTHOR');
}
# Examples, indicated by an indented leading $, % or > are
@@ -475,7 +502,7 @@ while (length)
}
# Append continuations.
- while (s/^ {$indent}(\S.*)\n//)
+ while ($indent ? s/^ {$indent}(\S.*)\n// : s/^(\S.*)\n//)
{
$matched .= $& if %append;
$content .= "\x83$1\n"
@@ -516,19 +543,19 @@ unless ($opt_no_info)
{
my $info_page = $opt_info || $program;
- $sect = 'SEE ALSO';
+ $sect = _('SEE ALSO');
$include{$sect} ||= '';
$include{$sect} .= ".PP\n" if $include{$sect};
- $include{$sect} .= <<EOT;
+ $include{$sect} .= sprintf _(<<'EOT'), $program, $info_page, $info_page;
The full documentation for
-.B $program
+.B %s
is maintained as a Texinfo manual. If the
.B info
and
-.B $program
+.B %s
programs are properly installed at your site, the command
.IP
-.B info $info_page
+.B info %s
.PP
should give you access to the complete manual.
EOT
@@ -541,29 +568,39 @@ print <<EOT;
EOT
# Section ordering.
-my @pre = qw(NAME SYNOPSIS DESCRIPTION OPTIONS EXAMPLES);
-my @post = ('AUTHOR', 'REPORTING BUGS', 'COPYRIGHT', 'SEE ALSO');
+my @pre = (_('NAME'), _('SYNOPSIS'), _('DESCRIPTION'), _('OPTIONS'),
+ _('EXAMPLES'));
+
+my @post = (_('AUTHOR'), _('REPORTING BUGS'), _('COPYRIGHT'), _('SEE ALSO'));
my $filter = join '|', @pre, @post;
# Output content.
-for (@pre, (grep ! /^($filter)$/o, @include), @post)
+for my $sect (@pre, (grep ! /^($filter)$/o, @include), @post)
{
- if ($include{$_})
+ if ($include{$sect})
{
- my $quote = /\W/ ? '"' : '';
- print ".SH $quote$_$quote\n";
+ my $lsect = gettext $sect;
+ my $quote = $lsect =~ /\W/ ? '"' : '';
+ print ".SH $quote$lsect$quote\n";
- for ($include{$_})
+ for ($include{$sect})
{
# Replace leading dot, apostrophe and backslash tokens.
s/\x80/\\&./g;
s/\x81/\\&'/g;
s/\x82/\\e/g;
+
+ # Convert some latin1 chars to troff equivalents
+ s/\xa0/\\ /g; # non-breaking space
+
print;
}
}
}
+close STDOUT or kark N_("%s: error writing to %s (%s)"), $this_program,
+ $opt_output || 'stdout', $!;
+
exit;
# Convert option dashes to \- to stop nroff from hyphenating 'em, and