Ignore trailing white space and empty lines
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 13 Aug 2003 23:15:00 +0000 (23:15 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 13 Aug 2003 23:15:00 +0000 (23:15 +0000)
in files containing patterns to exclude.

lib/ChangeLog
lib/exclude.c
m4/ChangeLog
m4/exclude.m4

index faf7300..d4d0901 100644 (file)
@@ -1,5 +1,11 @@
 2003-08-13  Paul Eggert  <eggert@twinsun.com>
 
+       * exclude.c: Include <ctype.h>
+       (IN_CTYPE_DOMAIN): New macro.
+       (is_space): New fn.
+       (add_exclude_file): If LINE_END is a space, ignore trailing spaces
+       and empty lines.
+
        * argp-help.c, argp-parse.c, config.charset, getopt.h:
        Undo previous (whitespace-only) change.
 
index 75042cb..ffe136f 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <stdbool.h>
 
+#include <ctype.h>
 #include <errno.h>
 #ifndef errno
 extern int errno;
@@ -58,6 +59,18 @@ extern int errno;
 # define SIZE_MAX ((size_t) -1)
 #endif
 
+#if STDC_HEADERS || (! defined isascii && ! HAVE_ISASCII)
+# define IN_CTYPE_DOMAIN(c) true
+#else
+# define IN_CTYPE_DOMAIN(c) isascii (c)
+#endif
+
+static inline bool
+is_space (unsigned char c)
+{
+  return IN_CTYPE_DOMAIN (c) && isspace (c);
+}
+
 /* Verify a requirement at compile-time (unlike assert, which is runtime).  */
 #define verify(name, assertion) struct name { char a[(assertion) ? 1 : -1]; }
 
@@ -208,8 +221,9 @@ add_exclude (struct exclude *ex, char const *pattern, int options)
 }
 
 /* Use ADD_FUNC to append to EX the patterns in FILENAME, each with
-   OPTIONS.  LINE_END terminates each pattern in the file.  Return -1
-   on failure, 0 on success.  */
+   OPTIONS.  LINE_END terminates each pattern in the file.  If
+   LINE_END is a space character, ignore trailing spaces and empty
+   lines in FILE.  Return -1 on failure, 0 on success.  */
 
 int
 add_exclude_file (void (*add_func) (struct exclude *, char const *, int),
@@ -257,8 +271,20 @@ add_exclude_file (void (*add_func) (struct exclude *, char const *, int),
   for (pattern = p = buf, lim = buf + buf_count;  p <= lim;  p++)
     if (p < lim ? *p == line_end : buf < p && p[-1])
       {
-       *p = '\0';
+       if (is_space (line_end))
+         {
+           char *pattern_end = p;
+           for (; ; pattern_end--)
+             if (pattern_end == pattern)
+               goto next_pattern;
+             else if (! is_space (pattern_end[-1]))
+               break;
+           *pattern_end = '\0';
+         }
+
        (*add_func) (ex, pattern, options);
+
+      next_pattern:
        pattern = p + 1;
       }
 
index e8b9de1..da9e7e6 100644 (file)
@@ -1,5 +1,8 @@
 2003-08-13  Paul Eggert  <eggert@twinsun.com>
 
+       * exclude.m4 (gl_EXCLUDE): Require AC_C_INLINE, AC_HEADER_STDC.
+       Check for isascii.
+
        * gettext.m4, iconv.m4, intdiv0.m4, inttypes-pri.m4, lib-link.m4,
        lib-prefix.m4, longdouble.m4, po.m4, progtest.m4, signed.m4:
        Undo previous (whitespace-only) change.
index 0501fc4..88d2874 100644 (file)
@@ -1,5 +1,5 @@
-# exclude.m4 serial 1
-dnl Copyright (C) 2002 Free Software Foundation, Inc.
+# exclude.m4 serial 2
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
 dnl Public License, this file may be distributed as part of a program
@@ -9,5 +9,8 @@ dnl the same distribution terms as the rest of that program.
 AC_DEFUN([gl_EXCLUDE],
 [
   dnl Prerequisites of lib/exclude.c.
+  AC_REQUIRE([AC_C_INLINE])
+  AC_REQUIRE([AC_HEADER_STDC])
   AC_CHECK_HEADERS_ONCE(stdlib.h string.h strings.h)
+  AC_CHECK_FUNCS_ONCE(isascii)
 ])