commit 798695ff1ec0bec2605eb490008f2968a5e8c264
parent 15320d3b9639d838d0c480c9cdebbbde6d6780b4
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Mon, 24 Dec 2018 20:28:46 +0100
utils: retire the fixbounds() function -- it is no longer needed
All tested systems (FreeBSD, NetBSD, OpenBSD, Alpine, and Ubuntu)
support the GNU-style word boundaries (\< and \>), either natively
or through using the regex module from gnulib.
If this change breaks regexes containing \< or \> on your system,
please report a bug: https://savannah.gnu.org/bugs/?group=nano
This addresses https://savannah.gnu.org/bugs/?55207.
Diffstat:
6 files changed, 6 insertions(+), 88 deletions(-)
diff --git a/configure.ac b/configure.ac
@@ -665,55 +665,6 @@ fi
AC_DEFINE_UNQUOTED(NANO_REG_EXTENDED, $nano_reg_extended,
[Flag(s) to use to get the full range of extended regular expressions])
-# Check for word-boundary support (/< and />).
-AC_MSG_CHECKING([for GNU-style word boundary regex support])
-AC_ARG_WITH(wordbounds,
-AS_HELP_STRING([--with-wordbounds], [Use GNU-style word boundary delimiters]),
- [with_wordbounds=$withval], [with_wordbounds=auto])
-if test "$with_wordbounds" != "no"; then
- dnl If we're using the bundled gnulib regex module, we know it's supported.
- if test "$ac_use_included_regex" = "yes"; then
- with_wordbounds="yes"
- fi
-
- dnl We explicitly don't check if the user forced the option, because
- dnl this is needed for cross compilers and we can't test the target.
- if test "$with_wordbounds" != "yes"; then
- AC_TRY_RUN([
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#include <regex.h>
-int main(void)
-{
- regex_t r;
- size_t nmatch;
- regmatch_t pmatch;
-
- if (regcomp(&r, "\\\\>", $nano_reg_extended|REG_NOSUB))
- return 1;
- if (regexec(&r, "word boundary", nmatch, &pmatch, 0))
- return 1;
- return 0;
-}],
- with_wordbounds="yes",
- with_wordbounds="no",
- with_wordbounds="cross")
- fi
-fi
-case $with_wordbounds in
-yes)
- AC_MSG_RESULT(yes)
- AC_DEFINE(GNU_WORDBOUNDS, 1, [Define this if the system supports GNU-style word boundaries in regexes.])
- ;;
-no)
- AC_MSG_RESULT(no)
- ;;
-cross)
- AC_MSG_WARN([*** Can't check for GNU-style word boundary support when cross-compiling])
- ;;
-esac
-
if test x$color_support = xyes; then
# if test x$CURSES_LIB_NAME = xcurses; then
AC_MSG_CHECKING([whether _XOPEN_SOURCE_EXTENDED is needed])
diff --git a/src/color.c b/src/color.c
@@ -144,7 +144,7 @@ bool found_in_list(regexlisttype *head, const char *shibboleth)
regex_t rgx;
for (item = head; item != NULL; item = item->next) {
- regcomp(&rgx, fixbounds(item->full_regex), NANO_REG_EXTENDED);
+ regcomp(&rgx, item->full_regex, NANO_REG_EXTENDED);
if (regexec(&rgx, shibboleth, 0, NULL, 0) == 0) {
regfree(&rgx);
@@ -273,12 +273,12 @@ void color_update(void)
for (ink = openfile->colorstrings; ink != NULL; ink = ink->next) {
if (ink->start == NULL) {
ink->start = (regex_t *)nmalloc(sizeof(regex_t));
- regcomp(ink->start, fixbounds(ink->start_regex), ink->rex_flags);
+ regcomp(ink->start, ink->start_regex, ink->rex_flags);
}
if (ink->end_regex != NULL && ink->end == NULL) {
ink->end = (regex_t *)nmalloc(sizeof(regex_t));
- regcomp(ink->end, fixbounds(ink->end_regex), ink->rex_flags);
+ regcomp(ink->end, ink->end_regex, ink->rex_flags);
}
}
}
diff --git a/src/proto.h b/src/proto.h
@@ -563,7 +563,6 @@ void sunder(char *str);
#if !defined(ENABLE_TINY) || defined(ENABLE_TABCOMP) || defined(ENABLE_BROWSER)
void free_chararray(char **array, size_t len);
#endif
-const char *fixbounds(const char *r);
#ifdef ENABLE_SPELLER
bool is_separate_word(size_t position, size_t length, const char *buf);
#endif
diff --git a/src/rcfile.c b/src/rcfile.c
@@ -240,15 +240,14 @@ char *parse_next_regex(char *ptr)
bool nregcomp(const char *regex, int compile_flags)
{
regex_t preg;
- const char *r = fixbounds(regex);
- int rc = regcomp(&preg, r, compile_flags);
+ int rc = regcomp(&preg, regex, compile_flags);
if (rc != 0) {
size_t len = regerror(rc, &preg, NULL, 0);
char *str = charalloc(len);
regerror(rc, &preg, str, len);
- rcfile_error(N_("Bad regex \"%s\": %s"), r, str);
+ rcfile_error(N_("Bad regex \"%s\": %s"), regex, str);
free(str);
}
diff --git a/src/search.c b/src/search.c
@@ -35,7 +35,7 @@ static bool have_compiled_regexp = FALSE;
* Return TRUE if the expression is valid, and FALSE otherwise. */
bool regexp_init(const char *regexp)
{
- int value = regcomp(&search_regexp, fixbounds(regexp),
+ int value = regcomp(&search_regexp, regexp,
NANO_REG_EXTENDED | (ISSET(CASE_SENSITIVE) ? 0 : REG_ICASE));
/* If regex compilation failed, show the error message. */
diff --git a/src/utils.c b/src/utils.c
@@ -200,37 +200,6 @@ void free_chararray(char **array, size_t len)
}
#endif
-/* Fix the regex if we're on platforms which require an adjustment
- * from GNU-style to BSD-style word boundaries. */
-const char *fixbounds(const char *r)
-{
-#ifndef GNU_WORDBOUNDS
- int i, j = 0;
- char *r2 = charalloc(strlen(r) * 5);
- char *r3;
-
- for (i = 0; i < strlen(r); i++) {
- if (r[i] != '\0' && r[i] == '\\' && (r[i + 1] == '>' || r[i + 1] == '<')) {
- strcpy(&r2[j], "[[:");
- r2[j + 3] = r[i + 1];
- strcpy(&r2[j + 4], ":]]");
- i++;
- j += 6;
- } else
- r2[j] = r[i];
- j++;
- }
-
- r2[j] = '\0';
- r3 = mallocstrcpy(NULL, r2);
- free(r2);
-
- return (const char *) r3;
-#endif /* !GNU_WORDBOUNDS */
-
- return r;
-}
-
#ifdef ENABLE_SPELLER
/* Is the word starting at the given position in buf and of the given length
* a separate word? That is: is it not part of a longer word?*/