From d3edff3b15e3194c1c8739934002ea10427bdeab Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 13 Aug 2003 23:15:00 +0000 Subject: [PATCH] Ignore trailing white space and empty lines in files containing patterns to exclude. --- lib/ChangeLog | 6 ++++++ lib/exclude.c | 32 +++++++++++++++++++++++++++++--- m4/ChangeLog | 3 +++ m4/exclude.m4 | 7 +++++-- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index faf730094..d4d09012b 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,5 +1,11 @@ 2003-08-13 Paul Eggert + * exclude.c: Include + (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. diff --git a/lib/exclude.c b/lib/exclude.c index 75042cbd8..ffe136f87 100644 --- a/lib/exclude.c +++ b/lib/exclude.c @@ -26,6 +26,7 @@ #include +#include #include #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; } diff --git a/m4/ChangeLog b/m4/ChangeLog index e8b9de1d0..da9e7e6d5 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,5 +1,8 @@ 2003-08-13 Paul Eggert + * 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. diff --git a/m4/exclude.m4 b/m4/exclude.m4 index 0501fc426..88d2874fa 100644 --- 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 @@ 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) ]) -- 2.11.0