maint.mk: improve "can not" detection and generalize rule name
authorJim Meyering <meyering@redhat.com>
Wed, 11 May 2011 08:07:32 +0000 (10:07 +0200)
committerJim Meyering <meyering@redhat.com>
Wed, 11 May 2011 08:07:32 +0000 (10:07 +0200)
* top/maint.mk (sc_prohibit_misc): Renamed from sc_prohibit_can_not,
since we'll probably add a few more word pairs here.
Use the same technique as in sc_prohibit_doubled_word, so that
we recognize "can not" also when the words are separated by a newline.
Suggested by Eric Blake.
(perl_filename_lineno_text_): Define.  Factored out of...
(prohibit_doubled_word_): ...here.  Use the new definition.
(prohibit_misc_): New var.  Use it here, too.
(prohibit_misc_RE_): New overridable variable.

ChangeLog
top/maint.mk

index c4481838b34ea1192444e68feb3b21a7355626d6..00e42d5764515645a6f636b4b2715561141c1249 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2011-05-11  Jim Meyering  <meyering@redhat.com>
+
+       maint.mk: improve "can not" detection and generalize rule name
+       * top/maint.mk (sc_prohibit_misc): Renamed from sc_prohibit_can_not,
+       since we'll probably add a few more word pairs here.
+       Use the same technique as in sc_prohibit_doubled_word, so that
+       we recognize "can not" also when the words are separated by a newline.
+       Suggested by Eric Blake.
+       (perl_filename_lineno_text_): Define.  Factored out of...
+       (prohibit_doubled_word_): ...here.  Use the new definition.
+       (prohibit_misc_): New var.  Use it here, too.
+       (prohibit_misc_RE_): New overridable variable.
+
 2011-05-10  Eric Blake  <eblake@redhat.com>
 
        fclose: avoid double close race when possible
index 346fe0068c851f719d2fb1dc52125da2985f1b99..bb4354fa9b8b635a5cd6b62253f4b8d86eea01b1 100644 (file)
@@ -840,16 +840,21 @@ sc_prohibit_S_IS_definition:
        halt='do not define S_IS* macros; include <sys/stat.h>'         \
          $(_sc_search_regexp)
 
-prohibit_doubled_word_RE_ ?= \
-  /\b(then?|[iao]n|i[fst]|but|f?or|at|and|[dt]o)\s+\1\b/gims
-prohibit_doubled_word_ =                                               \
-    -e 'while ($(prohibit_doubled_word_RE_))'                          \
+# Perl block to convert a match to FILE_NAME:LINENO:TEST,
+# that is shared by two definitions below.
+perl_filename_lineno_text_ =                                           \
     -e '  {'                                                           \
     -e '    $$n = ($$` =~ tr/\n/\n/ + 1);'                             \
     -e '    ($$v = $$&) =~ s/\n/\\n/g;'                                        \
     -e '    print "$$ARGV:$$n:$$v\n";'                                 \
     -e '  }'
 
+prohibit_doubled_word_RE_ ?= \
+  /\b(then?|[iao]n|i[fst]|but|f?or|at|and|[dt]o)\s+\1\b/gims
+prohibit_doubled_word_ =                                               \
+    -e 'while ($(prohibit_doubled_word_RE_))'                          \
+    $(perl_filename_lineno_text_)
+
 # Define this to a regular expression that matches
 # any filename:dd:match lines you want to ignore.
 # The default is to ignore no matches.
@@ -860,10 +865,19 @@ sc_prohibit_doubled_word:
          | grep -vE '$(ignore_doubled_word_match_RE_)'                 \
          | grep . && { echo '$(ME): doubled words' 1>&2; exit 1; } || :
 
-sc_prohibit_can_not:
-       @prohibit='\<can[ ]not\>'                                       \
-       halt='use "cannot", not "can'' not"'                            \
-         $(_sc_search_regexp)
+# A regular expression matching undesirable combinations of words like
+# "can not"; this matches them even when the two words appear on different
+# lines, but not when there is an intervening delimiter like "#" or "*".
+prohibit_misc_RE_ ?= \
+  /\bcan\s+not\b/gims
+prohibit_misc_ =                                                       \
+    -e 'while ($(prohibit_misc_RE_))'                                  \
+    $(perl_filename_lineno_text_)
+
+sc_prohibit_misc:
+       @perl -n -0777 $(prohibit_misc_) $$($(VC_LIST_EXCEPT))          \
+         | grep -vE '$(prohibit_misc_RE_)'                             \
+         | grep . && { echo '$(ME): undesirable words' 1>&2; exit 1; } || :
 
 _ptm1 = use "test C1 && test C2", not "test C1 -''a C2"
 _ptm2 = use "test C1 || test C2", not "test C1 -''o C2"