bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] maint.mk: detect missing-NL-at-EOF, too


From: Jim Meyering
Subject: [PATCH] maint.mk: detect missing-NL-at-EOF, too
Date: Fri, 25 Feb 2011 20:20:32 +0100

FYI,

>From 47824c7263f9a4e10fbc60a944de741e0ead73b2 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 25 Feb 2011 20:18:02 +0100
Subject: [PATCH] maint.mk: detect missing-NL-at-EOF, too

* top/maint.mk (sc_prohibit_empty_lines_at_EOF): Adjust so that
it also detects when a file lacks a newline at EOF.
(require_exactly_one_NL_at_EOF_): Renamed from
detect_empty_lines_at_EOF_.  I opted not to rename the rule,
since people may well have .x-sc_... file names tied to the
existing name.  Suggested by Eric Blake.
---
 ChangeLog    |   10 ++++++++++
 top/maint.mk |   17 ++++++++++++-----
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6cae638..b33e6fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-02-25  Jim Meyering  <address@hidden>
+
+       maint.mk: detect missing-NL-at-EOF, too
+       * top/maint.mk (sc_prohibit_empty_lines_at_EOF): Adjust so that
+       it also detects when a file lacks a newline at EOF.
+       (require_exactly_one_NL_at_EOF_): Renamed from
+       detect_empty_lines_at_EOF_.  I opted not to rename the rule,
+       since people may well have .x-sc_... file names tied to the
+       existing name.  Suggested by Eric Blake.
+
 2011-02-25  Paul Eggert  <address@hidden>

        dirname: move m4/dos.m4 functionality into lib/dosname.h
diff --git a/top/maint.mk b/top/maint.mk
index ff2fbbb..90c22cf 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -778,17 +778,22 @@ sc_prohibit_cvs_keyword:
 #   perl -ln -0777 -e '/\n(\n+)$/ and print "$ARGV: ".length $1' ...
 # but that would be far less efficient, reading the entire contents
 # of each file, rather than just the last two bytes of each.
+# In addition, while the code below detects both blank lines and a missing
+# newline at EOF, the above detects only the former.
 #
 # This is a perl script that is expected to be the single-quoted argument
 # to a command-line "-le".  The remaining arguments are file names.
-# Print the name of each file that ends in two or more newline bytes.
+# Print the name of each file that ends in exactly one newline byte.
+# I.e., warn if there are blank lines (2 or more newlines), or if the
+# last byte is not a newline.  However, currently we don't complain
+# about any file that contains exactly one byte.
 # Exit nonzero if at least one such file is found, otherwise, exit 0.
 # Warn about, but otherwise ignore open failure.  Ignore seek/read failure.
 #
 # Use this if you want to remove trailing empty lines from selected files:
 #   perl -pi -0777 -e 's/\n\n+$/\n/' files...
 #
-detect_empty_lines_at_EOF_ =                                           \
+require_exactly_one_NL_at_EOF_ =                                       \
   foreach my $$f (@ARGV)                                               \
     {                                                                  \
       open F, "<", $$f or (warn "failed to open $$f: $$!\n"), next;    \
@@ -798,12 +803,14 @@ detect_empty_lines_at_EOF_ =                              
                \
       defined $$p and $$p = sysread F, $$last_two_bytes, 2;            \
       close F;                                                         \
       $$c = "ignore read failure";                                     \
-      $$p && $$last_two_bytes eq "\n\n" and (print $$f), $$fail=1;     \
+      $$p && ($$last_two_bytes eq "\n\n"                               \
+              || substr ($$last_two_bytes,1) ne "\n")                  \
+          and (print $$f), $$fail=1;                                   \
     }                                                                  \
   END { exit defined $$fail }
 sc_prohibit_empty_lines_at_EOF:
-       @perl -le '$(detect_empty_lines_at_EOF_)' $$($(VC_LIST_EXCEPT)) \
-          || { echo '$(ME): the above files end with empty line(s)'     \
+       @perl -le '$(require_exactly_one_NL_at_EOF_)' $$($(VC_LIST_EXCEPT)) \
+          || { echo '$(ME): empty line(s) or no newline at EOF'        \
                1>&2; exit 1; } || :;                                   \

 # Make sure we don't use st_blocks.  Use ST_NBLOCKS instead.
--
1.7.4.1.21.g4cc62



reply via email to

[Prev in Thread] Current Thread [Next in Thread]