[PATCH -perfbook 2/9] periodcheck: Add script to check missing annotation of period

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

 



"make periodcheck" will do the check.

NOTE: Possible false negative/positive as of this commit:
o   A mid-sentence period is ignored when the line matches "\label{"
    or "\*ref{" pattern. It should be caught when it is outside a
    macro.
o   \cref{} can have comma-separated multiple labels as an argument.
    When one of the labels has a mid-sentence period and on a
    subsequent line in the input, it is not ignored.
o   \crefrange{}{} can also have a label string on a subsequent line.

Signed-off-by: Akira Yokosawa <akiyks@xxxxxxxxx>
---
 Makefile                 |  5 ++-
 utilities/periodcheck.pl | 76 ++++++++++++++++++++++++++++++++++++++++
 utilities/periodcheck.sh | 20 +++++++++++
 3 files changed, 100 insertions(+), 1 deletion(-)
 create mode 100755 utilities/periodcheck.pl
 create mode 100755 utilities/periodcheck.sh

diff --git a/Makefile b/Makefile
index 4beb2c17..ea264dc5 100644
--- a/Makefile
+++ b/Makefile
@@ -192,7 +192,7 @@ BASE_DEPENDS := perfbook.tex $(foreach v,tcb 1c msns mss mstx msr msn msnt sf nq
 .PHONY: qq perfbook-qq.pdf qqmsg
 .PHONY: help help-official help-full help-semiofficial help-paper help-draft
 .PHONY: help-experimental help-prefixed
-.PHONY: paper-clean
+.PHONY: paper-clean periodcheck
 
 all: $(targ)
 
@@ -611,5 +611,8 @@ ls-unused:
 neatfreak: distclean
 	find . -name '*.pdf' | xargs rm -f
 
+periodcheck:
+	utilities/periodcheck.sh
+
 .SECONDEXPANSION:
 $(ABBREVTARGETS): %: perfbook-$$@.pdf
diff --git a/utilities/periodcheck.pl b/utilities/periodcheck.pl
new file mode 100755
index 00000000..225391ff
--- /dev/null
+++ b/utilities/periodcheck.pl
@@ -0,0 +1,76 @@
+#!/usr/bin/perl
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Check LaTeX source of mid-sentence and end-of-sentence period
+#
+# Assumptions:
+#    End-of-sentence periods are at the end of input lines.
+#
+# Exceptions:
+#    LaTeX comments
+#    LaTeX labels: such as \cref{fig:xxx:foo vs. bar}
+#    Verbatim contents
+#    Table contents
+#
+# Copyright (C) Akira Yokosawa, 2021
+#
+# Authors: Akira Yokosawa <akiyks@xxxxxxxxx>
+
+use strict;
+use warnings;
+
+my $line;
+my $next_line;
+my $line_num = 0;
+my $skip = 0;
+my $safe = 0;
+my $Verbatim_begin = qr/\\begin\{Verbatim/ ;
+my $Verbatim_end = qr/\\end\{Verbatim/ ;
+my $tabular_begin = qr/\\begin\{tabula/ ;
+my $tabular_end = qr/\\end\{tabula/ ;
+
+sub check_line {
+    if ($line =~ /$Verbatim_begin/ ||
+	$line =~ /$tabular_begin/) {
+	$skip = 1;
+    }
+    unless ($skip) {
+	$safe = 1;
+	if ($line =~ /^(?=[\s]*+[^%])[^%]*[A-Z]\.$/ ||
+	    $line =~ /^(?=[\s]*+[^%])[^%]*[A-Z]\.\\footnote/ ||
+	    $line =~ /^(?=[\s]*+[^%])[^%]*[Aa]cr\{.+\}\.$/ ||
+	    $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/) {
+		$safe = 1;
+	    }
+	}
+	if ($line =~ /^(?=[\s]*+[^%])[^%]*[a-z\}]\.\s[^\\]+/) {
+	    $safe = 0;
+	    if ($line =~ /ref\{/ || $line =~ /label\{/) {
+		$safe = 1;
+	    }
+	}
+	unless ($safe) {
+	    print $ARGV[0], ':', $line_num, ':', $line;
+	}
+    }
+    if ($line =~ /$Verbatim_end/ ||
+	$line =~ /$tabular_end/) {
+	$skip = 0;
+    }
+}
+
+open(my $fh, '<:encoding(UTF-8)', $ARGV[0])
+    or die "Could not open file '$ARGV[0]' $!";
+
+$line = <$fh>;
+$line_num = 1;
+while($next_line = <$fh>) {
+    check_line();
+    $line = $next_line;
+    $line_num++ ;
+}
+check_line();
diff --git a/utilities/periodcheck.sh b/utilities/periodcheck.sh
new file mode 100755
index 00000000..a56657f3
--- /dev/null
+++ b/utilities/periodcheck.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+tex_sources_all=`find . -name "*.tex" -print`
+tex_sources=""
+
+for f in $tex_sources_all
+do
+	case $f in
+	./perfbook*) ;;
+	./qqz*) ;;
+	./future/HTMtable*) ;;
+	./appendix/styleguide*) ;;
+	*) tex_sources="$tex_sources $f" ;;
+        esac
+done
+
+for g in $tex_sources
+do
+	utilities/periodcheck.pl $g
+done
-- 
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