[PATCH -perfbook v2 5/9] periodcheck: Replace escaped percent symbol first

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

 



To prevent "\%" from being treated as a symbol of comment,
replace it with "pct" at the beginning of pattern matching.
(Source .tex files are not modified.)

Also improve regex of label string to cache "chp:foo bar".

Add some comments and do a couple of refactoring by using
(xxx|yyy) and "?" patterns.

Signed-off-by: Akira Yokosawa <akiyks@xxxxxxxxx>
---
 utilities/periodcheck.pl | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/utilities/periodcheck.pl b/utilities/periodcheck.pl
index 27871507..b1551c44 100755
--- a/utilities/periodcheck.pl
+++ b/utilities/periodcheck.pl
@@ -28,30 +28,30 @@ my $Verbatim_begin = qr/\\begin\{Verbatim/ ;
 my $Verbatim_end = qr/\\end\{Verbatim/ ;
 my $tabular_begin = qr/\\begin\{tabula/ ;
 my $tabular_end = qr/\\end\{tabula/ ;
-my $label_ptn = qr/(^|\{)(,?[a-z]{3}:[a-zMPS]+:[^\},]+)(\}|,)/ ;
+my $label_ptn = qr/(^\s*|\{)(,?[a-z]{3,4}:([a-zMPS]+:)?[^\},]+)(\}|,)/ ;
 
 sub check_line {
     my $line_raw = $line;
-    if ($line =~ /$label_ptn/) {
+    $line =~ s/\\%/pct/g ;	# replace \% to prevent false negative
+    if ($line =~ /$label_ptn/) {# remove label string
 	while ($line && $line =~ /$label_ptn/) {
 	    my $quoted_2 = quotemeta $2;
 	    $line =~ s/$quoted_2//;
 	}
     }
     if ($line =~ /$Verbatim_begin/ ||
-	$line =~ /$tabular_begin/) {
+	$line =~ /$tabular_begin/) {  # exception (verbatim and tabular)
 	$skip = 1;
     }
     unless ($skip) {
 	$safe = 1;
 	if ($line =~ /^(?=[\s]*+[^%])[^%]*[A-Z]\.$/ ||
 	    $line =~ /^(?=[\s]*+[^%])[^%]*[A-Z]\.\\footnote/ ||
-	    $line =~ /^(?=[\s]*+[^%])[^%]*[Aa]cr\{.+\}\.$/ ||
-	    $line =~ /^(?=[\s]*+[^%])[^%]*[Aa]crm\{.+\}\.$/) {
+	    $line =~ /^(?=[\s]*+[^%])[^%]*[Aa]crm?\{.+\}\.$/ ) {
 	    $safe = 0;
 	    if ($next_line =~ /^\s*$/ || $next_line =~ /^\s*%/ ||
-		$next_line =~ /\\item/ || $next_line =~ /\\end\{quot/ ||
-		$next_line =~ /\\end\{enum/ || $next_line =~ /\\end\{item/) {
+		$next_line =~ /\\item/ ||
+		$next_line =~ /\\end\{(quot|enum|item|sequ)/ ) {
 		$safe = 1;
 	    }
 	}
-- 
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