All of lore.kernel.org
 help / color / mirror / Atom feed
From: Akira Yokosawa <akiyks@gmail.com>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: perfbook@vger.kernel.org, Akira Yokosawa <akiyks@gmail.com>
Subject: [PATCH -perfbook 2/9] periodcheck: Add script to check missing annotation of period
Date: Wed, 28 Apr 2021 00:08:15 +0900	[thread overview]
Message-ID: <e7e89d77-6dd5-ae0c-31fb-5e202ae1eccb@gmail.com> (raw)
In-Reply-To: <c298d82f-dc09-6b59-2b4b-3bedd5c48cec@gmail.com>

"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@gmail.com>
---
 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@gmail.com>
+
+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



  parent reply	other threads:[~2021-04-27 15:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-27 15:03 [PATCH -perfbook 0/9] Add script to check period spacing Akira Yokosawa
2021-04-27 15:05 ` [PATCH -perfbook 1/9] Annotate mid-sentence and end-of-sentence periods Akira Yokosawa
2021-04-27 15:08 ` Akira Yokosawa [this message]
2021-04-27 15:11 ` [PATCH -perfbook 0/9] Add script to check period spacing Akira Yokosawa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e7e89d77-6dd5-ae0c-31fb-5e202ae1eccb@gmail.com \
    --to=akiyks@gmail.com \
    --cc=paulmck@kernel.org \
    --cc=perfbook@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.