From: Raphael Hertzog Date: Fri, 11 Jan 2008 18:14:15 +0000 (+0100) Subject: Give some hints to Perl on the use of UTF-8 for output X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08499749543c2557649e8f558e138ea11986d1bb;p=dpkg Give some hints to Perl on the use of UTF-8 for output * scripts/dpkg-genchanges.pl, scripts/dpkg-gencontrol.pl, scripts/dpkg-source.pl: Hint Perl into using UTF-8 for output on *.dsc, *.changes and DEBIAN/control files. Updated some open() calls for more consistency and added binmode() calls for filehandles that handle only binary data. --- diff --git a/ChangeLog b/ChangeLog index 06799295..013594ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-01-14 Raphael Hertzog + + * scripts/dpkg-genchanges.pl, scripts/dpkg-gencontrol.pl, + scripts/dpkg-source.pl: Hint Perl into using UTF-8 for output + on *.dsc, *.changes and DEBIAN/control files. Updated some open() calls + for more consistency and added binmode() calls for filehandles that + handle only binary data. + 2008-01-13 Raphael Hertzog * scripts/Dpkg/Fields.pm: Drop public function diff --git a/scripts/dpkg-genchanges.pl b/scripts/dpkg-genchanges.pl index 9fb13fc0..f6ada091 100755 --- a/scripts/dpkg-genchanges.pl +++ b/scripts/dpkg-genchanges.pl @@ -480,6 +480,7 @@ for my $f (keys %remove) { delete $fields->{$f}; } +binmode(STDOUT, ":utf8"); $substvars->parse($varlistfile) if -e $varlistfile; tied(%{$fields})->set_field_importance(@changes_fields); tied(%{$fields})->output(\*STDOUT, $substvars); diff --git a/scripts/dpkg-gencontrol.pl b/scripts/dpkg-gencontrol.pl index 04e7fc36..6ae5c723 100755 --- a/scripts/dpkg-gencontrol.pl +++ b/scripts/dpkg-gencontrol.pl @@ -312,9 +312,9 @@ for my $f (keys %remove) { } $fileslistfile="./$fileslistfile" if $fileslistfile =~ m/^\s/; -open(Y,"> $fileslistfile.new") || &syserr(_g("open new files list file")); +open(Y, ">", "$fileslistfile.new") || &syserr(_g("open new files list file")); binmode(Y); -if (open(X,"< $fileslistfile")) { +if (open(X, "<", $fileslistfile)) { binmode(X); while () { chomp; @@ -342,18 +342,22 @@ close(Y) || &syserr(_g("close new files list file")); rename("$fileslistfile.new",$fileslistfile) || &syserr(_g("install new files list file")); my $cf; +my $fh_output; if (!$stdout) { $cf= "$packagebuilddir/DEBIAN/control"; $cf= "./$cf" if $cf =~ m/^\s/; - open(STDOUT,"> $cf.new") || + open($fh_output, ">:utf8", "$cf.new") || syserr(_g("cannot open new output control file \`%s'"), "$cf.new"); - binmode(STDOUT); +} else { + $fh_output = \*STDOUT; + binmode(STDOUT, ":utf8"); } tied(%{$fields})->set_field_importance(@control_fields); -tied(%{$fields})->output(\*STDOUT, $substvars); +tied(%{$fields})->output($fh_output, $substvars); if (!$stdout) { + close($fh_output); rename("$cf.new", "$cf") || syserr(_g("cannot install output control file \`%s'"), $cf); } diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl index af4cd575..8c956b09 100755 --- a/scripts/dpkg-source.pl +++ b/scripts/dpkg-source.pl @@ -766,12 +766,13 @@ if ($opmode eq 'build') { printf(_g("%s: building %s in %s")."\n", $progname, $sourcepackage, "$basenamerev.dsc") || &syserr(_g("write building message")); - open(STDOUT, "> $basenamerev.dsc") || + open(DSC, ">:utf8", "$basenamerev.dsc") || syserr(_g("create %s"), "$basenamerev.dsc"); $substvars->parse($varlistfile) if -e $varlistfile; tied(%{$fields})->set_field_importance(@dsc_fields); - tied(%{$fields})->output(\*STDOUT, $substvars); + tied(%{$fields})->output(\*DSC, $substvars); + close(DSC); if ($ur) { printf(STDERR _g("%s: unrepresentable changes to source")."\n", @@ -804,7 +805,7 @@ if ($opmode eq 'build') { } my $is_signed = 0; - open(DSC, "< $dsc") || error(_g("cannot open .dsc file %s: %s"), $dsc, $!); + open(DSC, "<", $dsc) || error(_g("cannot open .dsc file %s: %s"), $dsc, $!); while () { next if /^\s*$/o; $is_signed = 1 if /^-----BEGIN PGP SIGNED MESSAGE-----$/o; @@ -1128,7 +1129,7 @@ sub checkstats { my ($f) = @_; my @s; my $m; - open(STDIN, "< $dscdir/$f") || syserr(_g("cannot read %s"), "$dscdir/$f"); + open(STDIN, "<", "$dscdir/$f") || syserr(_g("cannot read %s"), "$dscdir/$f"); (@s = stat(STDIN)) || syserr(_g("cannot fstat %s"), "$dscdir/$f"); $s[7] == $size{$f} || error(_g("file %s has size %s instead of expected %s"), $f, $s[7], $size{$f}); @@ -1136,7 +1137,7 @@ sub checkstats { $m = readmd5sum( $m ); $m eq $md5sum{$f} || error(_g("file %s has md5sum %s instead of expected %s"), $f, $m, $md5sum{$f}); - open(STDIN,"", $_[0]) || syserr(_g("create file %s"), $_[0]); pipe(GZIPREAD,GZIP) || &syserr(_g("pipe for gzip")); + binmode(GZIP); defined($cgz= fork) || &syserr(_g("fork for gzip")); if (!$cgz) { open(STDIN,"<&",\*GZIPREAD) || &syserr(_g("reopen gzip pipe")); @@ -1611,6 +1613,7 @@ sub forkgzipread { open(GZIPFILE, "<", $_[0]) || syserr(_g("read file %s"), $_[0]); pipe(GZIP, GZIPWRITE) || syserr(_g("pipe for %s"), $prog); + binmode(GZIP); defined($cgz = fork) || syserr(_g("fork for %s"), $prog); if (!$cgz) { open(STDOUT, ">&", \*GZIPWRITE) || syserr(_g("reopen %s pipe"), $prog);