]> the.earth.li Git - htag.git/blobdiff - plugins/15merge
Import Debian changes 0.0.24-1
[htag.git] / plugins / 15merge
index 801bcf0986ab6133e36aeb05b365163ec7bf38ea..53f3b82e2d5e33b72641538e7d6f4276c24a32f5 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# Copyright (C) 2000-2003 Simon Huggins
+# Copyright (C) 2000-2008 Simon Huggins
 # merge merges the sig and the tag but also merges the sig and the new style
 # plugin things (i.e. all those silly files in $cfg{'tmpdir'}
 
 
 use strict;
 use Text::Wrap;
+use Encode;
 
 $Text::Wrap::columns=defined $cfg{'maxlinelen'} ? $cfg{'maxlinelen'} : 72;
 $cfg{'first'}  ||= "";
 $cfg{'leader'} ||= "";
 
+# Work out the correct locale to use if there is one otherwise we assume
+# UTF-8 which shouldn't kill ascii people and anyone else should have
+# correctly set locale.
+my $fromcharset = 'UTF-8';
+my $tocharset = 'UTF-8';
+
+my @all_encodings = Encode->encodings(":all");
+my $locale;
+if (defined $ENV{'LC_ALL'}) {
+       $locale = $ENV{'LC_ALL'};
+} elsif (defined $ENV{'LC_CTYPE'}) {
+       $locale = $ENV{'LC_CTYPE'};
+} elsif (defined $ENV{'LANG'}) {
+       $locale = $ENV{'LANG'};
+}
+if ($locale) {
+       $locale =~ s/.*\.//;
+       $locale = lc $locale;
+       foreach (@all_encodings) {
+               if ($locale eq lc $_) {
+                       $tocharset = $fromcharset = $_;
+                       last;
+               }
+       }
+}
+
 my $anal_merge_debug=0;
 
 sub remove_space($) {
@@ -163,7 +190,7 @@ sub getplugin($) {
 my ($tag,$sig,$newsig);
 open(SIG, "<$cfg{'tmpsigfile'}") or htagdie "$0: Could not open $cfg{'tmpsigfile'}: $!\n";
 while(<SIG>) {
-       $sig .= $_;
+       $sig .= decode($fromcharset, $_);
 }
 close(SIG);
 my $ret = 0;
@@ -174,7 +201,7 @@ if (grep { /\@NOTAG\@/ } $sig) {
 } else {
        open(TAG, "<$cfg{'tmptagfile'}") or htagdie "$1: Could not open $cfg{'tmptagfile'}: $!\n";
        while(<TAG>) {
-               $tag .= $_;
+               $tag .= decode($fromcharset, $_);
        }
        close(TAG);
 }
@@ -187,6 +214,7 @@ if (defined $sig and $sig =~ /@[A-Za-z]?\*|(?:[1-9][0-9]*)[RC]?@/) {
        $cfg{'notag'} = 0;
 }
 if (defined $sig) {
+       $sig = encode($tocharset, $sig);
        open(SIG, ">$cfg{'tmpsigfile'}") or htagdie "$0: Could not open $cfg{'tmpsigfile'}: $!\n";
        print SIG "\n" while $cfg{'newline'}--;
        print SIG $sig;