[PATCH -perfbook 09/11] periodcheck: Use counter to prevent false negatives

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

 



Assigning 1 to $safe in one rule can cause a false negative when there
is earlier match(es) to violation pattern(s) on the same input line.

By using a counter and incrementing/decrementing it on a particular
pattern-match, such false negatives can be prevented.

Signed-off-by: Akira Yokosawa <akiyks@xxxxxxxxx>
---
 utilities/cleverefcheck.pl | 37 +++++++++++++++++--------------------
 utilities/periodcheck.pl   | 22 +++++++++++-----------
 2 files changed, 28 insertions(+), 31 deletions(-)

diff --git a/utilities/cleverefcheck.pl b/utilities/cleverefcheck.pl
index 06d4928a..69497893 100755
--- a/utilities/cleverefcheck.pl
+++ b/utilities/cleverefcheck.pl
@@ -17,7 +17,7 @@ my $line;
 my $new_sentence = 1;
 my $line_num = 0;
 my $skip = 0;
-my $safe = 0;
+my $ng = 0;
 my $Verbatim_begin = qr/\\begin\{(Verbatim|tabula|equation|SaveVerb|verbbox)/ ;
 my $Verbatim_end = qr/\\end\{(Verbatim|tabula|equation|SaveVerb|verbbox)/ ;
 my $label_ptn = qr/(^\s*|\{)(,?[a-z]{3,4}:([a-zMPS]+:)?[^\},]+)(\}|,)/ ;
@@ -44,56 +44,53 @@ sub check_line {
 	}
     }
     unless ($skip) {
-	$safe = 1;
+	$ng = 0;
 	if ($line =~ /^(?=[\s]*+[^%])[^%]*\\ref\{/ ||
 	    $line =~ /^(?=[\s]*+[^%])[^%]*\\pageref\{/ ||
 	    $line =~ /^(?=[\s]*+[^%])[^%]*\\lnref\{/) {
-	    $safe = 0;
+	    $ng += 1;
 	    if ($line =~ /or~\\lnref\{/ ||
 		$line =~ /item~\\ref\{/) {
-		$safe = 1;
+		$ng -= 1;
 	    }
 	}
-	if ($new_sentence == 1 &&
+	if ($new_sentence != 0 &&
 	    ($line =~ /^\s*\\cref/ || $line =~ /^\s*\\cpageref/ ||
 	     $line =~ /^\s*\\clnref/)) {
-	    $safe = 0;
+	    $ng += 1;
 	}
-	if ($line =~ /^\s*\\Cref/ || $line =~ /^\s*\\Cpageref/ ||
-	    $line =~ /^\s*\\Clnref/) {
-	    if ($new_sentence == 1) {
-		$safe = 1;
-	    } elsif ($new_sentence == 0) {
-		$safe = 0;
-	    }
+	if ($new_sentence == 0 &&
+	    ($line =~ /^\s*\\Cref/ || $line =~ /^\s*\\Cpageref/ ||
+	     $line =~ /^\s*\\Clnref/)) {
+	    $ng += 1;
 	}
 	if ($line =~ /^(?=[\s]*+[^%])[^%]*[^\s]+\s*\\Cref/ ||
 	    $line =~ /^(?=[\s]*+[^%])[^%]*[^\s]+\s*\\Cpageref/ ||
 	    $line =~ /^(?=[\s]*+[^%])[^%]*[^\s]+\s*\\Clnref/) {
-	    $safe = 0;
+	    $ng += 1;
 	    if ($line =~ /^(?=[\s]*+[^%])[^%]*^\s*\\item\s+\\C/ ) {
-		$safe = 1;
+		$ng -= 1;
 	    }
 	}
 	if ($line =~ /^(?=[\s]*+[^%])[^%]*^\s*\\item\s+[a-z]/ ) {
-	    $safe = 0;
+	    $ng += 1;
 	}
 	if ($new_sentence) {
 	    if ($line =~ /^\s*`*[a-z]/ || $line =~ /^\s*\\acr/ ||
 		$line =~ /^\s*\\IX[^A\{]*\{[a-z]/ ) {
-		$safe = 0;
+		$ng += 1;
 	    }
 	}
 	if ($new_sentence == 2) { # after colon
 	    if ($line =~ /^\s*\([0-9a-z]+\)/ ) {
-		$safe = 0;
+		$ng += 1;
 	    }
 	}
 	if ($line =~ /^[ ]{8}/ ||  # indent by white speces (should be TAB)
 	    $line =~ /^(?=[\s]*+[^%])[^%][ ]+\t/) { # TAB after white space
-	    $safe = 0;
+	    $ng += 1;
 	}
-	unless ($safe) {
+	if ($ng) {
 	    print $ARGV[0], ':', $line_num, ':', $raw_line;
 	}
     }
diff --git a/utilities/periodcheck.pl b/utilities/periodcheck.pl
index 9d1985d1..88fd59c0 100755
--- a/utilities/periodcheck.pl
+++ b/utilities/periodcheck.pl
@@ -26,7 +26,7 @@ my $line;
 my $next_line;
 my $line_num = 0;
 my $skip = 0;
-my $safe = 0;
+my $ng;
 my $Verbatim_begin = qr/\\begin\{(Verbatim|tabula|equation)/ ;
 my $Verbatim_end = qr/\\end\{(Verbatim|tabular|equation)/ ;
 my $label_ptn = qr/(^\s*|\{)(,?[a-z]{3,4}:([a-zMPS]+:)?[^\},]+)(\}|,)/ ;
@@ -59,38 +59,38 @@ sub check_line {
 	$skip = 1;
     }
     unless ($skip) {
-	$safe = 1;
+	$ng = 0;
 	if ($line =~ /^(?=[\s]*+[^%])[^%]*[A-Z][\)\']*[\.\?\!\:][\)\}\']*$/ ||
 	    $line =~ /^(?=[\s]*+[^%])[^%]*[A-Z][\)\']*[\.\?\!\:]\\footnote/ ||
-	    $line =~ /^(?=[\s]*+[^%])[^%]*[Aa]crm?\{.+\}[\)\']*[\.\?\!\:][\)\}\']*$/ ) {
-	    $safe = 0;
+	    $line =~ /^(?=[\s]*+[^%])[^%]*[Aa]crm?(f|fst)?\{.+\}[\)\']*[\.\?\!\:][\)\}\']*$/ ) {
+	    $ng += 1;
 	    if ($next_line =~ /^\s*$/ || $next_line =~ /^\s*%/ ||
 		$next_line =~ /\\item/ ||
 		$next_line =~ /\\E?QuickQuizAnswer[BEM]?\{/ ||
 		$next_line =~ /\\E?QuickQuizEnd[BEM]?/ ||
 		$next_line =~ /\\end\{(quot|enum|item|sequ)/ ) {
-		$safe = 1;
+		$ng -= 1;
 	    }
 	}
 	if ($line =~ /^(?=[\s]*+[^%])[^%]*[a-z][\)\}\']*[\.\?\!][\)\}\']*\s+[^%]/ ||
 #	    $line =~ /^(?=[\s]*+[^%])[^%]*.*\.[\)\}\']*\s+[^%]/ ||  # Uncomment for full check
 	    $line =~ /^(?=[\s]*+[^%])[^%]*.*:[\)\}\']*\s+[^%]/ ) {
-	    $safe = 0;
+	    $ng += 1;
 	    if ($line =~ /^(?=[\s]*+[^%])[^%]*[a-z][\)\}\']*[\.\?\!][\)\}\']*\s+\\\\/ ||
 		$line =~ /^(?=[\s]*+[^%])[^%]*.*[\.:][\)\}\']*\s+\\\\/ ) {
-		$safe = 1;
+		$ng -= 1;
 	    }
 	}
 	if ($line =~ /^(?=[\s]*+[^%])[^%]*[^~]\\cite/) {
-	    $safe = 0;
+	    $ng += 1;
 	    if ($line =~ /^(?=[\s]*+[^%])[^%]*~\(\\cite/) {
-		$safe = 1;
+		$ng -= 1;
 	    }
 	}
 	if ($line =~ /^(?=[\s]*+[^%])[^%]*\\\@[\.\?\!\:][\)\}\']*\s+[^%]/){
-	    $safe = 0;
+	    $ng += 1;
 	}
-	unless ($safe) {
+	if ($ng) {
 	    print $ARGV[0], ':', $line_num, ':', $line_raw;
 	}
     }
-- 
2.17.1





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux