changeset 4537:940fdf291f5b

Ignore trailing white space and empty lines in files containing patterns to exclude.
author Paul Eggert <eggert@cs.ucla.edu>
date Wed, 13 Aug 2003 23:15:00 +0000
parents 3358eb550c86
children e05e3087e98a
files lib/ChangeLog lib/exclude.c m4/ChangeLog m4/exclude.m4
diffstat 4 files changed, 43 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -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.
 
--- a/lib/exclude.c
+++ b/lib/exclude.c
@@ -26,6 +26,7 @@
 
 #include <stdbool.h>
 
+#include <ctype.h>
 #include <errno.h>
 #ifndef errno
 extern int errno;
@@ -58,6 +59,18 @@
 # 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 @@
 }
 
 /* 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 @@
   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;
       }
 
--- a/m4/ChangeLog
+++ b/m4/ChangeLog
@@ -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.
--- a/m4/exclude.m4
+++ b/m4/exclude.m4
@@ -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 @@
 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)
 ])