bug-gnulib
[Top][All Lists]
Advanced

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

[Bug-gnulib] add_exclude_patch to ignore trailing white space and empty


From: Paul Eggert
Subject: [Bug-gnulib] add_exclude_patch to ignore trailing white space and empty lines
Date: Wed, 13 Aug 2003 16:48:27 -0700
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.2 (gnu/linux)

In response to a recent bug report about GNU diff I added the
following patch to add_exclude_file, so that it ignores trailing
spaces and empty lines in the pattern file.  I think it's the expected
behavior but if it causes problems in other applications I can add an
option to disable the new behavior.

Index: lib/ChangeLog
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/ChangeLog,v
retrieving revision 1.530
diff -p -u -r1.530 ChangeLog
--- lib/ChangeLog       13 Aug 2003 20:23:14 -0000      1.530
+++ lib/ChangeLog       13 Aug 2003 23:13:13 -0000
@@ -1,5 +1,11 @@
 2003-08-13  Paul Eggert  <address@hidden>
 
+       * 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: lib/exclude.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/exclude.c,v
retrieving revision 1.15
retrieving revision 1.17
diff -p -u -r1.15 -r1.17
--- lib/exclude.c       4 Jun 2003 23:35:46 -0000       1.15
+++ lib/exclude.c       13 Aug 2003 23:44:25 -0000      1.17
@@ -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 co
 }
 
 /* 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),
@@ -253,12 +267,28 @@ add_exclude_file (void (*add_func) (stru
     e = errno;
 
   buf = xrealloc (buf, buf_count + 1);
+  buf[buf_count] = line_end;
+  lim = buf + buf_count + ! (buf_count == 0 || buf[buf_count - 1] == line_end);
+  pattern = buf;
 
-  for (pattern = p = buf, lim = buf + buf_count;  p <= lim;  p++)
-    if (p < lim ? *p == line_end : buf < p && p[-1])
+  for (p = buf; p < lim; p++)
+    if (*p == line_end)
       {
-       *p = '\0';
+       char *pattern_end = p;
+
+       if (is_space (line_end))
+         {
+           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: m4/ChangeLog
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/ChangeLog,v
retrieving revision 1.477
diff -p -u -r1.477 ChangeLog
--- m4/ChangeLog        13 Aug 2003 20:23:14 -0000      1.477
+++ m4/ChangeLog        13 Aug 2003 23:13:14 -0000
@@ -1,5 +1,8 @@
 2003-08-13  Paul Eggert  <address@hidden>
 
+       * 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: m4/exclude.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/exclude.m4,v
retrieving revision 1.2
diff -p -u -r1.2 exclude.m4
--- m4/exclude.m4       4 Jun 2003 19:22:30 -0000       1.2
+++ m4/exclude.m4       13 Aug 2003 23:13:14 -0000
@@ -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 r
 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)
 ])




reply via email to

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