comparison bins_edit @ 6:3021deef1599

Encoding related fixes * chomp encoding string * reformat else (seems someone hacked it in) * debug print encoding * do not use :utf8 binmode ("re-encode") on written file if the input is _already_ UTF-8
author Peter Gervai <grin@grin.hu>
date Thu, 16 Oct 2008 00:02:14 +0200
parents a84c32f131df
children 69923c621cfe
comparison
equal deleted inserted replaced
5:e8a9408780ff 6:3021deef1599
42 my $verbose = 1; 42 my $verbose = 1;
43 my $html=0; 43 my $html=0;
44 44
45 my $localEncoding; 45 my $localEncoding;
46 $localEncoding = `locale charmap`; 46 $localEncoding = `locale charmap`;
47 chomp $localEncoding;
47 if ($? != 0 ) { 48 if ($? != 0 ) {
48 $localEncoding = "LATIN1"; 49 $localEncoding = "LATIN1";
49 } 50 } else {
50 else { 51 if (! $localEncoding or ($localEncoding eq "ANSI_X3.4-1968")) {
51 if (! $localEncoding or ($localEncoding eq "ANSI_X3.4-1968")) { 52 chop($localEncoding);
52 chop($localEncoding); 53 # ANSI is unspeakably primitive, promote it.
53 # ANSI is unspeakably primitive, promote it. 54 $localEncoding = "LATIN1";
54 $localEncoding = "LATIN1"; 55 print "Forcing encoding to $localEncoding\n" if ($verbose >=2);
55 print "Forcing encoding to $localEncoding\n" if ($verbose >=2); 56 }
56 }
57 } 57 }
58 my $converter = Text::Iconv->new($localEncoding, "UTF-8"); 58 my $converter = Text::Iconv->new($localEncoding, "UTF-8");
59 print "Using $localEncoding encoding on input\n" if ($verbose >=2);
59 60
60 # decode HTML entites which doesn't exist in XML 61 # decode HTML entites which doesn't exist in XML
61 sub decodeEntites{ 62 sub decodeEntites{
62 my $s = shift; 63 my $s = shift;
63 64
281 print " Writing file '$file'... " if ($verbose >= 2); 282 print " Writing file '$file'... " if ($verbose >= 2);
282 # Write the Grove to the desc file 283 # Write the Grove to the desc file
283 my $fileHandler = new IO::File; 284 my $fileHandler = new IO::File;
284 open($fileHandler, '>', $file) 285 open($fileHandler, '>', $file)
285 or die("Cannot open file $file to write Exif tag ($!)"); 286 or die("Cannot open file $file to write Exif tag ($!)");
286 binmode($fileHandler, ":utf8") if $^V ge v5.8.0; 287 if( $localEncoding !~ /utf-?8/i ) {
288 # if input is UTF-8 do not re-convert it again
289 binmode($fileHandler, ":utf8") if $^V ge v5.8.0;
290 }
287 291
288 my $my_handler = new XML::Handler::YAWriter( 'Output' => $fileHandler, 292 my $my_handler = new XML::Handler::YAWriter( 'Output' => $fileHandler,
289 # 'Escape' => { 293 # 'Escape' => {
290 # '--' => '&mdash;', 294 # '--' => '&mdash;',
291 #'&' => '&amp;', 295 #'&' => '&amp;',