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

lintian: r271 - in trunk: checks lib



Author: he
Date: 2004-05-13 17:05:27 +0200 (Thu, 13 May 2004)
New Revision: 271

Modified:
   trunk/checks/changelog-file
   trunk/checks/control-file
   trunk/lib/Util.pm
Log:
Don't duplicate code: Merge the utf8-checking and put it into Util.pm


Modified: trunk/checks/changelog-file
===================================================================
--- trunk/checks/changelog-file	2004-05-13 14:39:57 UTC (rev 270)
+++ trunk/checks/changelog-file	2004-05-13 15:05:27 UTC (rev 271)
@@ -21,6 +21,7 @@
 package Lintian::changelog_file;
 use strict;
 use Tags;
+use Util;
 
 sub run {
 
@@ -206,17 +207,10 @@
 }
 
 # check that changelog is UTF-8 encoded
-open ICONV, "env LANG=C iconv -f utf8 -t utf8 changelog 2>&1 |"
-    or fail("failure while checking encoding of changelog for $type package $pkg");
-my $line = 1;
-while (<ICONV>) {
-    if (m/iconv: illegal input sequence at position \d+$/) {
-	tag "debian-changelog-file-uses-obsolete-national-encoding", "at line $line";
-	last;
-    }
-    $line++;
+my $line = file_is_encoded_in_non_utf8("changelog", $type, $pkg);
+if ($line) {
+    tag "debian-changelog-file-uses-obsolete-national-encoding", "at line $line"
 }
-close ICONV;
 
 # read the changelog itself
 #

Modified: trunk/checks/control-file
===================================================================
--- trunk/checks/control-file	2004-05-13 14:39:57 UTC (rev 270)
+++ trunk/checks/control-file	2004-05-13 15:05:27 UTC (rev 271)
@@ -29,17 +29,10 @@
 my $type = shift;
 
 # check that control is UTF-8 encoded
-open ICONV, "env LANG=C iconv -f utf8 -t utf8 debfiles/control 2>&1 |"
-	or fail("failure while checking encoding of control for $type package $pkg");
-my $line = 1;
-while (<ICONV>) {
-	if (m/iconv: illegal input sequence at position \d+$/) {
-		tag "debian-control-file-uses-obsolete-national-encoding", "at line $line";
-		last;
-    }
-    $line++;
+my $line = file_is_encoded_in_non_utf8("debfiles/control", $type, $pkg);
+if ($line) {
+    tag "debian-control-file-uses-obsolete-national-encoding", "at line $line"
 }
-close ICONV;
 
 my ($header, @binary_controls) = read_dpkg_control("debfiles/control");
 

Modified: trunk/lib/Util.pm
===================================================================
--- trunk/lib/Util.pm	2004-05-13 14:39:57 UTC (rev 270)
+++ trunk/lib/Util.pm	2004-05-13 15:05:27 UTC (rev 271)
@@ -30,6 +30,7 @@
 	get_dsc_info
 	slurp_entire_file
 	get_file_md5
+	file_is_encoded_in_non_utf8
 	fail);
 
 use FileHandle;
@@ -185,6 +186,26 @@
 	return $md5->hexdigest;
 }
 
+sub file_is_encoded_in_non_utf8 {
+	my ($file, $type, $pkg) = @_;
+	my $non_utf8 = 0;
+	
+	open ICONV, "env LANG=C iconv -f utf8 -t utf8 $file 2>&1 |"
+	    or fail("failure while checking encoding of $file for $type package $pkg");
+	my $line = 1;
+	while (<ICONV>) {
+		if (m/iconv: illegal input sequence at position \d+$/) {
+			$non_utf8 = 1;
+			last;
+		}
+		$line++
+	}
+	close ICONV;
+
+	return $line if $non_utf8;
+	return 0;
+}
+
 # ------------------------
 
 sub fail {



Reply to: