diff options
author | Brendan O'Dea <bod@debian.org> | 2022-02-14 21:17:39 +1100 |
---|---|---|
committer | Brendan O'Dea <bod@debian.org> | 2022-02-15 10:37:46 +1100 |
commit | 70a16e75c0d6f0b7ca74540f2ffb9eccce2dba5e (patch) | |
tree | fd2baca16706c98f4aa9241420dc0cd9b33d4147 | |
parent | 74cdfaa08d30392610454ba2d40e7eb71f1a1d23 (diff) | |
download | help2man-70a16e75c0d6f0b7ca74540f2ffb9eccce2dba5e.tar.gz |
Fallback to iconv for encodings not supported by Perl's Encode
-rw-r--r-- | NEWS | 8 | ||||
-rw-r--r-- | debian/changelog | 7 | ||||
-rw-r--r-- | debian/copyright | 2 | ||||
-rwxr-xr-x | help2man.PL | 53 |
4 files changed, 59 insertions, 11 deletions
@@ -1,3 +1,11 @@ +Version 1.49 February 14, 2022 + + * Use @samp{} around the option in the menu description for "--help + recommendations" to avoid rendering the -- as endash. + * Don't translate @documentencoding. + * Fall back to forking iconv for encodings which are not supported by + Perl's Encode module. + Version 1.48 February 6, 2021 * Add Serbian, Swedish, Brazilian Portuguese and Chinese (simplified) diff --git a/debian/changelog b/debian/changelog index 86e0e70..96453a4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +help2man (1.49.1) unstable; urgency=medium + + * Fall back to forking iconv for encodings which are not supported by + Perl's Encode module (closes: #894126). + + -- Brendan O'Dea <bod@debian.org> Mon, 14 Feb 2022 11:44:16 +1100 + help2man (1.48.5) unstable; urgency=medium * Use @samp{} around the option in the menu description for "--help diff --git a/debian/copyright b/debian/copyright index d190b45..f740192 100644 --- a/debian/copyright +++ b/debian/copyright @@ -7,7 +7,7 @@ Source: Files: * Copyright: 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009, 2010, - 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020, 2021 Free Software + 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020, 2021, 2022 Free Software Foundation, Inc. License: GPL-3+ This program is free software: you can redistribute it and/or modify diff --git a/help2man.PL b/help2man.PL index 3f09e2a..8463a9f 100755 --- a/help2man.PL +++ b/help2man.PL @@ -16,7 +16,7 @@ use 5.008; use Config; use Getopt::Long; -my ($program, $version) = ('help2man', '1.48.5'); +my ($program, $version) = ('help2man', '1.49.1'); my %opts; die "Usage: $0 [--quiet] [--stdout] [--with-gettext] [--name] [--version]\n" @@ -62,7 +62,7 @@ print OUT <<'!NO!SUBS!'; # 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 Free Software +# 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2020, 2021, 2022 Free Software # Foundation, Inc. # This program is free software; you can redistribute it and/or modify @@ -91,7 +91,7 @@ use POSIX qw(strftime setlocale LC_ALL); print OUT <<'!NO!SUBS!' if $opts{'with-gettext'}; use Locale::gettext qw(gettext); -use Encode qw(decode encode); +use Encode qw(find_encoding decode encode); use I18N::Langinfo qw(langinfo CODESET); !NO!SUBS! @@ -104,9 +104,37 @@ my \$this_version = '$version'; # Conditionally include gettext support: print OUT $opts{'with-gettext'} ? <<'!WITH!GETTEXT!' : <<'!NO!GETTEXT!'; -my $encoding; +my $encoder; { + # Fallback to running iconv for encodings which are not supported + # by the Encode module. + sub run_iconv + { + my ($from, $to, $str) = @_; + return $str if $from eq $to; # no-op + + my $pid = open C, '-|'; + die "can't fork: $!" unless defined $pid; + unless ($pid) + { + open STDERR, '>/dev/null'; + open ICONV, '|-', 'iconv', '-f', $from, '-t', $to + or die "can't fork: $!"; + print ICONV $str; + exit 0; + } + + local $/; + my $enc = <C>; + close C; + return $? ? $str : $enc; + } + + sub fallback::new { bless \(my $self = $_[1]), $_[0] } + sub fallback::decode { decode 'UTF-8', run_iconv ${$_[0]}, 'UTF-8', $_[1] } + sub fallback::encode { run_iconv 'UTF-8', ${$_[0]}, encode 'UTF-8', $_[1] } + my $gettext = Locale::gettext->domain($this_program); sub _ { $gettext->get($_[0]) } @@ -114,19 +142,24 @@ my $encoding; (map $ENV{$_}, qw(LANGUAGE LC_ALL LC_MESSAGES LANG)), 'C'; my $user_encoding = langinfo CODESET; + my $user_encoder = (find_encoding $user_encoding) || + fallback->new($user_encoding); # Set localisation of date and executable's output. sub configure_locale { delete @ENV{qw(LANGUAGE LC_MESSAGES LANG)}; setlocale LC_ALL, $ENV{LC_ALL} = shift || 'C'; - $encoding = langinfo CODESET; + my $encoding = langinfo CODESET; + $encoder = (find_encoding $encoding) || fallback->new($encoding); } - sub dec { $encoding ? decode $encoding, $_[0] : $_[0] } - sub enc { $encoding ? encode $encoding, $_[0] : $_[0] } - sub enc_user { encode $user_encoding, $_[0] } - sub kark # die with message formatted in the invoking user's locale + sub dec { $encoder ? $encoder->decode($_[0]) : $_[0] } + sub enc { $encoder ? $encoder->encode($_[0]) : $_[0] } + sub enc_user { $user_encoder->encode($_[0]) } + + # Die with message formatted in the invoking user's locale. + sub kark { setlocale LC_ALL, $user_locale; my $fmt = $gettext->get(shift); @@ -238,7 +271,7 @@ die $help_info unless GetOptions %opt_def and @ARGV == 1; !NO!SUBS! print OUT <<'!NO!SUBS!' if $opts{'with-gettext'}; -configure_locale unless $encoding; +configure_locale unless $encoder; !NO!SUBS! |