[Pgp-tools-commit] r693 - in trunk: debian gpgsigs

Guilhem Moulin guilhem-guest at moszumanska.debian.org
Sun Aug 24 06:33:31 UTC 2014


Author: guilhem-guest
Date: 2014-08-24 06:33:28 +0000 (Sun, 24 Aug 2014)
New Revision: 693

Modified:
   trunk/debian/changelog
   trunk/debian/control
   trunk/gpgsigs/gpgsigs
Log:
Use Perl's "Encode" core module for charset conversion.

Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog	2014-08-24 06:32:29 UTC (rev 692)
+++ trunk/debian/changelog	2014-08-24 06:33:28 UTC (rev 693)
@@ -9,6 +9,10 @@
   * gpg-key2ps:
     + Replace ',' with '.' in paperconf's output, which is localized while
       Postscript understands only '.' as decimal mark. (Closes: #758991)
+  * gpgsigs:
+    + Use Perl's "Encode" core module for charset conversion. Also, change the
+      default 'from' charset to be the locale in use, as it was the case for
+      'to'. (Use -f/-t to select alternative from/to charsets.)
 
  -- Guilhem Moulin <guilhem at guilhem.org>  Wed, 16 Jul 2014 00:07:24 +0200
 

Modified: trunk/debian/control
===================================================================
--- trunk/debian/control	2014-08-24 06:32:29 UTC (rev 692)
+++ trunk/debian/control	2014-08-24 06:33:28 UTC (rev 693)
@@ -19,8 +19,7 @@
  libmime-tools-perl, libmailtools-perl, libterm-readkey-perl,
  libclass-methodmaker-perl, libnet-idn-encode-perl, qprint
 Recommends: default-mta | mail-transport-agent, libpaper-utils,
- libgd-gd2-noxpm-perl | libgd-gd2-perl,
- libtext-iconv-perl | libintl-perl | recode, dialog | whiptail
+ libgd-gd2-noxpm-perl | libgd-gd2-perl, dialog | whiptail
 # springraph
 Suggests: imagemagick | graphicsmagick-imagemagick-compat, wipe, mutt,
  texlive-latex-recommended, texlive-xetex, fonts-droid

Modified: trunk/gpgsigs/gpgsigs
===================================================================
--- trunk/gpgsigs/gpgsigs	2014-08-24 06:32:29 UTC (rev 692)
+++ trunk/gpgsigs/gpgsigs	2014-08-24 06:33:28 UTC (rev 693)
@@ -5,11 +5,6 @@
 # See the pod documentation at the end of this file for author,
 # copyright, and licence information.
 #
-# Depends: 
-# 	   libintl-perl (Locale::Recode)
-# 	OR libtext-iconv-perl (Text::Iconv),
-# 	OR the "recode" binary
-#
 # Changelog:
 # 0.1
 # 0.2 2005-05-14 cb:
@@ -23,6 +18,8 @@
 
 use strict;
 use warnings;
+use Encode ();
+use I18N::Langinfo 'langinfo';
 use English;
 use IPC::Open3;
 use Getopt::Long;
@@ -81,43 +78,10 @@
 
 
 # charset conversion
-$fromcharset ||= "ISO-8859-1";
-$charset ||= $ENV{LC_ALL} || $ENV{LC_CTYPE} || $ENV{LANG} || "ISO-8859-1";
-$charset = "ISO-8859-1" unless $charset =~ /[\.-]/;
-$charset =~ s/.*\.//;
-$charset =~ s/\@.*//;
+$fromcharset //= langinfo(I18N::Langinfo::CODESET());
+$charset //= langinfo(I18N::Langinfo::CODESET());
+my $locale = Encode::find_encoding($charset);
 
-
-sub myrecode($$$) {
-	my ($text, $from, $to) = @_;
-
-	if (eval "require Locale::Recode") {
-		my $rt = Locale::Recode->new (from => $from, to => $to);
-
-		my $orig = $text;
-		$rt->recode($text);
-		return $text;
-	} elsif (eval "require Text::Iconv") {
-		my $it = Text::Iconv->new($from, $to);
-
-		my $result = $it->convert($text);
-		warn ("Could not convert '$text'\n") unless defined $result;
-		return ($result // $text);
-	} else {
-		my $pid = open3(\*WTRFH, \*RDRFH, \*ERRFH, 'recode', "utf8..$charset");
-		print WTRFH $text;
-		close WTRFH;
-		local $/ = undef;
-		my $result = <RDRFH>;
-		close RDRFH;
-		close ERRFH;
-		waitpid $pid, 0;
-		warn ("'recode' failed, is it installed?\n") unless defined $result;
-		return ($result // $text);
-	}
-}
-
-
 # parse options
 my @mykeys = split /,/, uc(shift @ARGV);
 my $keytxt = (shift @ARGV) || usage(*STDERR, 1);
@@ -224,7 +188,8 @@
 					if ($1 eq 'uid') {
 						my $text = $4;
 						$text =~ s/\\x([0-9a-f][0-9a-f])/ chr(hex($1)) /gie;
-						$uids{$key}->{$uid} = { type => 'uid', text => myrecode($text, "UTF-8", $charset) };
+						# --with-colons always output UTF-8
+						$uids{$key}->{$uid} = { type => 'uid', text => $locale->encode(Encode::decode_utf8($text)) };
 					}
 					else {
 						# we can't rely on $4 for the size: get it from
@@ -414,7 +379,6 @@
 
 while (<TXT>) {
 	$line++;
-	$_ = myrecode($_, $fromcharset, $charset);
 	if (/^(\S+) Checksum:/) {
 		my $md = getChecksum(uc $1, $keytxt);
 		if ($md) {
@@ -482,7 +446,7 @@
 	}
 	if ( m/^uid +(.*)$/ ) {
 		next if $refresh or $latex;
-		my $uid = $1;
+		my $uid = $locale->encode( Encode::decode($fromcharset, $1) );
 		unless (defined $key) {
 			warn "key is undefined - input text is possibly malformed near line $line\n";
 			next;




More information about the Pgp-tools-commit mailing list