bug-texinfo
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: texinfo-6.8.90 pretest


From: Gavin Smith
Subject: Re: texinfo-6.8.90 pretest
Date: Sat, 22 Oct 2022 21:36:20 +0100

On Sat, Oct 22, 2022 at 09:39:14PM +0300, Eli Zaretskii wrote:
> > If this works then we could switch to it and not use I18N::Langinfo at
> > all.
> 
> This works here, and produces the codepage number.  But (due to the
> Windows peculiarities which I won't go into), it isn't the same
> codepage number as the "current system ANSI codepage", which is
> retrieved by the GetACP call I showed in my previous message.  So from
> my POV, on Windows it is better to use the GetACP call via Win32::API
> module, as that produces a codepage that is more accurate in some
> cases.
> 
> In any case, both methods produce just a number, not an encoding
> identifier.  We will need to prepend something to it, like "CP" maybe,
> depending on how the codeset is used by texi2any.

Could you try the following?

diff --git a/tp/texi2any.pl b/tp/texi2any.pl
index d6061bd8f0..1e6b47acb6 100755
--- a/tp/texi2any.pl
+++ b/tp/texi2any.pl
@@ -25,8 +25,6 @@ require 5.00405;
 
 use strict;
 
-# to determine the locale encoding
-use I18N::Langinfo qw(langinfo CODESET);
 # to decode command line arguments
 use Encode qw(decode encode find_encoding);
 # for file names portability
@@ -297,8 +295,24 @@ if ($texinfo_dtd_version eq '@' . 'TEXINFO_DTD_VERSION@') {
 # the encoding used to decode command line arguments, and also for
 # file names encoding, perl is expecting sequences of bytes, not unicode
 # code points.
-my $locale_encoding = langinfo(CODESET);
-$locale_encoding = undef if ($locale_encoding eq '');
+my $locale_encoding;
+
+eval 'require I18N::Langinfo';
+if (!$@) {
+  $locale_encoding = I18N::Langinfo::langinfo(I18N::Langinfo::CODESET());
+  $locale_encoding = undef if ($locale_encoding eq '');
+}
+
+if (!defined($locale_encoding) and $^O eq 'MSWin32') {
+  eval 'require Win32::API';
+  if (!$@) {
+    Win32::API::More->Import("kernel32", "int GetACP()");
+    my $CP = GetACP();
+    if (defined($CP)) {
+      $locale_encoding = 'CP'.$CP;
+    }
+  }
+}
 
 # Used in case it is not hardcoded in configure and for standalone perl module
 $texinfo_dtd_version = $configured_version




reply via email to

[Prev in Thread] Current Thread [Next in Thread]