nano-devel
[Top][All Lists]
Advanced

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

[Nano-devel] [PATCH 07/10] assume regex.h support is always available


From: Mike Frysinger
Subject: [Nano-devel] [PATCH 07/10] assume regex.h support is always available
Date: Mon, 20 Feb 2017 13:42:13 -0500

Now that we pull in the gnulib regex module, we can assume it exists.
---
 autogen.sh   |  1 +
 configure.ac | 12 ++----------
 src/global.c | 13 -------------
 src/nano.c   | 12 +-----------
 src/nano.h   |  2 --
 src/proto.h  | 12 ------------
 src/rcfile.c |  2 --
 src/search.c | 30 ++----------------------------
 src/text.c   | 16 +---------------
 src/utils.c  |  4 ----
 10 files changed, 7 insertions(+), 97 deletions(-)

diff --git a/autogen.sh b/autogen.sh
index c32b9b998ae6..ccc5878faa7c 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -9,6 +9,7 @@ modules="
        getline
        isblank
        iswblank
+       regex
        strcase
        strcasestr-simple
        strnlen
diff --git a/configure.ac b/configure.ac
index 6274b67c89f8..c3c06567f74a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,7 +54,7 @@ AC_DEFINE_DIR([PKGDATADIR], [pkgdatadir], [Where data are 
placed to.])
 
 dnl Checks for header files.
 
-AC_CHECK_HEADERS(getopt.h libintl.h limits.h regex.h sys/param.h wchar.h 
wctype.h stdarg.h)
+AC_CHECK_HEADERS(getopt.h libintl.h limits.h sys/param.h wchar.h wctype.h 
stdarg.h)
 
 dnl Checks for options.
 
@@ -77,15 +77,7 @@ fi
 if test "x$enable_color" = xno; then
     AC_DEFINE(DISABLE_COLOR, 1, [Define this to disable syntax highlighting.])
 else
-    if test x$ac_cv_header_regex_h != xyes; then
-       AC_MSG_ERROR([
-*** The header file regex.h was not found.  If you wish to have
-*** color support, this header file is required.  Please either
-*** install C libraries that include the regex.h file, or call
-*** the configure script with --disable-color.])
-    else
-       color_support=yes
-    fi
+    color_support=yes
 fi
 
 AC_ARG_ENABLE(comment,
diff --git a/src/global.c b/src/global.c
index 690dfc6bc892..1663bcdbb626 100644
--- a/src/global.c
+++ b/src/global.c
@@ -124,17 +124,12 @@ char *brackets = NULL;
         * can end sentences. */
 char *quotestr = NULL;
        /* The quoting string.  The default value is set in main(). */
-#ifdef HAVE_REGEX_H
 regex_t quotereg;
        /* The compiled regular expression from the quoting string. */
 int quoterc;
        /* Whether it was compiled successfully. */
 char *quoteerr = NULL;
        /* The error message, if it didn't. */
-#else
-size_t quotelen;
-       /* The length of the quoting string in bytes. */
-#endif
 #endif /* !DISABLE_JUSTIFY */
 
 char *word_chars = NULL;
@@ -212,13 +207,11 @@ poshiststruct *position_history = NULL;
        /* The cursor position history list. */
 #endif
 
-#ifdef HAVE_REGEX_H
 regex_t search_regexp;
        /* The compiled regular expression to use in searches. */
 regmatch_t regmatches[10];
        /* The match positions for parenthetical subexpressions, 10
         * maximum, used in regular expression searches. */
-#endif
 
 int hilite_attribute = A_REVERSE;
        /* The curses attribute we use to highlight something. */
@@ -603,10 +596,8 @@ void shortcut_init(void)
     const char *nano_reverse_msg =
        N_("Reverse the direction of the search");
 #endif
-#ifdef HAVE_REGEX_H
     const char *nano_regexp_msg =
        N_("Toggle the use of regular expressions");
-#endif
 #ifndef DISABLE_HISTORIES
     const char *nano_prev_history_msg =
        N_("Recall the previous search/replace string");
@@ -763,10 +754,8 @@ void shortcut_init(void)
 
     add_to_funcs(case_sens_void, MWHEREIS|MREPLACE,
        N_("Case Sens"), IFSCHELP(nano_case_msg), TOGETHER, VIEW);
-#ifdef HAVE_REGEX_H
     add_to_funcs(regexp_void, MWHEREIS|MREPLACE,
        N_("Regexp"), IFSCHELP(nano_regexp_msg), TOGETHER, VIEW);
-#endif
     add_to_funcs(backwards_void, MWHEREIS|MREPLACE,
        N_("Backwards"), IFSCHELP(nano_reverse_msg), TOGETHER, VIEW);
 
@@ -1697,11 +1686,9 @@ void thanks_for_all_the_fish(void)
     free(word_chars);
 #ifndef DISABLE_JUSTIFY
     free(quotestr);
-#ifdef HAVE_REGEX_H
     regfree(&quotereg);
     free(quoteerr);
 #endif
-#endif
 #ifndef NANO_TINY
     free(backup_dir);
 #endif
diff --git a/src/nano.c b/src/nano.c
index d1dba354a57a..9f67f06d640a 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -2416,14 +2416,7 @@ int main(int argc, char **argv)
 
     /* If quotestr wasn't specified, set its default value. */
     if (quotestr == NULL)
-       quotestr = mallocstrcpy(NULL,
-#ifdef HAVE_REGEX_H
-               "^([ \t]*[#:>|}])+"
-#else
-               "> "
-#endif
-               );
-#ifdef HAVE_REGEX_H
+       quotestr = mallocstrcpy(NULL, "^([ \t]*[#:>|}])+");
     quoterc = regcomp(&quotereg, quotestr, NANO_REG_EXTENDED);
 
     if (quoterc == 0) {
@@ -2436,9 +2429,6 @@ int main(int argc, char **argv)
        quoteerr = charalloc(size);
        regerror(quoterc, &quotereg, quoteerr, size);
     }
-#else
-    quotelen = strlen(quotestr);
-#endif /* !HAVE_REGEX_H */
 #endif /* !DISABLE_JUSTIFY */
 
 #ifndef DISABLE_SPELLER
diff --git a/src/nano.h b/src/nano.h
index e7c09f25dc74..162f377d6f8a 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -116,9 +116,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <dirent.h>
-#ifdef HAVE_REGEX_H
 #include <regex.h>
-#endif
 #include <signal.h>
 #include <assert.h>
 
diff --git a/src/proto.h b/src/proto.h
index 9adc22a3fc51..fd1f22d09d24 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -100,13 +100,9 @@ extern const char *unjust_tag;
 extern char *punct;
 extern char *brackets;
 extern char *quotestr;
-#ifdef HAVE_REGEX_H
 extern regex_t quotereg;
 extern int quoterc;
 extern char *quoteerr;
-#else
-extern size_t quotelen;
-#endif
 #endif /* !DISABLE_JUSTIFY */
 
 extern char *word_chars;
@@ -154,10 +150,8 @@ extern filestruct *replacebot;
 extern poshiststruct *position_history;
 #endif
 
-#ifdef HAVE_REGEX_H
 extern regex_t search_regexp;
 extern regmatch_t regmatches[10];
-#endif
 
 extern int hilite_attribute;
 #ifndef DISABLE_COLOR
@@ -507,10 +501,8 @@ void do_rcfiles(void);
 #endif /* !DISABLE_NANORC */
 
 /* All functions in search.c. */
-#ifdef HAVE_REGEX_H
 bool regexp_init(const char *regexp);
 void regexp_cleanup(void);
-#endif
 void not_found_msg(const char *str);
 void search_replace_abort(void);
 int search_init(bool replacing, bool use_answer);
@@ -523,9 +515,7 @@ void do_findnext(void);
 #endif
 void do_research(void);
 void go_looking(void);
-#ifdef HAVE_REGEX_H
 int replace_regexp(char *string, bool create);
-#endif
 char *replace_line(const char *needle);
 ssize_t do_replace_loop(const char *needle, bool whole_word_only,
        const filestruct *real_current, size_t *real_current_x);
@@ -644,9 +634,7 @@ void snuggly_fit(char **str);
 void null_at(char **data, size_t index);
 void unsunder(char *str, size_t true_len);
 void sunder(char *str);
-#ifdef HAVE_REGEX_H
 const char *fixbounds(const char *r);
-#endif
 #ifndef DISABLE_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
index 372482c29d75..16c2025eade2 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -79,9 +79,7 @@ static const rcoption rcopts[] = {
 #endif
     {"rebinddelete", REBIND_DELETE},
     {"rebindkeypad", REBIND_KEYPAD},
-#ifdef HAVE_REGEX_H
     {"regexp", USE_REGEXP},
-#endif
 #ifndef DISABLE_SPELLER
     {"speller", 0},
 #endif
diff --git a/src/search.c b/src/search.c
index bf6fcd84c7c8..0a958d9785ad 100644
--- a/src/search.c
+++ b/src/search.c
@@ -35,7 +35,6 @@ static bool came_full_circle = FALSE;
 static bool history_changed = FALSE;
        /* Have any of the history lists changed? */
 #endif
-#ifdef HAVE_REGEX_H
 static bool regexp_compiled = FALSE;
        /* Have we compiled any regular expressions? */
 static bool bow_anchored = FALSE;
@@ -78,7 +77,6 @@ void regexp_cleanup(void)
        regfree(&search_regexp);
     }
 }
-#endif
 
 /* Indicate on the statusbar that the string at str was not found by the
  * last search. */
@@ -108,9 +106,7 @@ void search_replace_abort(void)
     if (openfile->mark_set)
        refresh_needed = TRUE;
 #endif
-#ifdef HAVE_REGEX_H
     regexp_cleanup();
-#endif
 }
 
 /* Set up the system variables for a search or replace.  If use_answer
@@ -162,10 +158,7 @@ int search_init(bool replacing, bool use_answer)
                edit_refresh, "%s%s%s%s%s%s", _("Search"),
                /* TRANSLATORS: The next three modify the search prompt. */
                ISSET(CASE_SENSITIVE) ? _(" [Case Sensitive]") : "",
-#ifdef HAVE_REGEX_H
-               ISSET(USE_REGEXP) ? _(" [Regexp]") :
-#endif
-               "",
+               ISSET(USE_REGEXP) ? _(" [Regexp]") : "",
                ISSET(BACKWARDS_SEARCH) ? _(" [Backwards]") : "", replacing ?
 #ifndef NANO_TINY
                /* TRANSLATORS: The next two modify the search prompt. */
@@ -195,11 +188,9 @@ int search_init(bool replacing, bool use_answer)
            update_history(&search_history, answer);
 #endif
        }
-#ifdef HAVE_REGEX_H
        if (ISSET(USE_REGEXP) && !regexp_init(last_search))
            return -1;
        else
-#endif
            return 0;   /* We have a valid string or regex. */
     }
 
@@ -214,14 +205,11 @@ int search_init(bool replacing, bool use_answer)
        backupstring = mallocstrcpy(backupstring, answer);
        return 1;
     } else
-#ifdef HAVE_REGEX_H
     if (func == regexp_void) {
        TOGGLE(USE_REGEXP);
        backupstring = mallocstrcpy(backupstring, answer);
        return 1;
-    } else
-#endif
-    if (func == do_replace || func == flip_replace_void) {
+    } else if (func == do_replace || func == flip_replace_void) {
        backupstring = mallocstrcpy(backupstring, answer);
        return -2;      /* Call the opposite search function. */
     } else if (func == do_gotolinecolumn_void) {
@@ -300,7 +288,6 @@ int findnextstr(const char *needle, bool whole_word_only, 
size_t *match_len,
        }
 
        if (found != NULL) {
-#ifdef HAVE_REGEX_H
            /* When doing a regex search, compute the length of the match. */
            if (ISSET(USE_REGEXP)) {
                found_len = regmatches[0].rm_eo - regmatches[0].rm_so;
@@ -320,7 +307,6 @@ int findnextstr(const char *needle, bool whole_word_only, 
size_t *match_len,
                    }
                }
            }
-#endif
 #ifndef DISABLE_SPELLER
            /* When we're spell checking, a match should be a separate word;
             * if it's not, continue looking in the rest of the line. */
@@ -458,10 +444,8 @@ void do_research(void)
        return;
     }
 
-#ifdef HAVE_REGEX_H
     if (ISSET(USE_REGEXP) && !regexp_init(last_search))
        return;
-#endif
 
     /* Use the search-menu key bindings, to allow cancelling. */
     currmenu = MWHEREIS;
@@ -499,7 +483,6 @@ void go_looking(void)
     search_replace_abort();
 }
 
-#ifdef HAVE_REGEX_H
 /* Calculate the size of the replacement text, taking possible
  * subexpressions \1 to \9 into account.  Return the replacement
  * text in the passed string only when create is TRUE. */
@@ -542,7 +525,6 @@ int replace_regexp(char *string, bool create)
 
     return replacement_size;
 }
-#endif /* HAVE_REGEX_H */
 
 /* Return a copy of the current line with one needle replaced. */
 char *replace_line(const char *needle)
@@ -552,17 +534,13 @@ char *replace_line(const char *needle)
     size_t new_line_size = strlen(openfile->current->data) + 1;
 
     /* First adjust the size of the new line for the change. */
-#ifdef HAVE_REGEX_H
     if (ISSET(USE_REGEXP)) {
        match_len = regmatches[0].rm_eo - regmatches[0].rm_so;
        new_line_size += replace_regexp(NULL, FALSE) - match_len;
     } else {
-#endif
        match_len = strlen(needle);
        new_line_size += strlen(answer) - match_len;
-#ifdef HAVE_REGEX_H
     }
-#endif
 
     /* Create the buffer. */
     copy = charalloc(new_line_size);
@@ -571,11 +549,9 @@ char *replace_line(const char *needle)
     strncpy(copy, openfile->current->data, openfile->current_x);
 
     /* Add the replacement text. */
-#ifdef HAVE_REGEX_H
     if (ISSET(USE_REGEXP))
        replace_regexp(copy + openfile->current_x, TRUE);
     else
-#endif
        strcpy(copy + openfile->current_x, answer);
 
     assert(openfile->current_x + match_len <= strlen(openfile->current->data));
@@ -720,11 +696,9 @@ ssize_t do_replace_loop(const char *needle, bool 
whole_word_only,
 #endif
            }
 
-#ifdef HAVE_REGEX_H
            /* Don't find the same zero-length or BOL match again. */
            if (match_len == 0 || (*needle == '^' && ISSET(USE_REGEXP)))
                match_len++;
-#endif
            /* Set the cursor at the last character of the replacement
             * text, so that searching will continue /after/ it.  Note
             * that current_x might be set to (size_t)-1 here. */
diff --git a/src/text.c b/src/text.c
index 9ec43b070329..e7045853f642 100644
--- a/src/text.c
+++ b/src/text.c
@@ -1903,13 +1903,9 @@ void justify_format(filestruct *paragraph, size_t skip)
 
 /* The "quote part" of a line is the largest initial substring matching
  * the quote string.  This function returns the length of the quote part
- * of the given line.
- *
- * Note that if !HAVE_REGEX_H then we match concatenated copies of
- * quotestr. */
+ * of the given line. */
 size_t quote_length(const char *line)
 {
-#ifdef HAVE_REGEX_H
     regmatch_t matches;
     int rc = regexec(&quotereg, line, 1, &matches, 0);
 
@@ -1918,14 +1914,6 @@ size_t quote_length(const char *line)
     /* matches.rm_so should be 0, since the quote string should start
      * with the caret ^. */
     return matches.rm_eo;
-#else  /* !HAVE_REGEX_H */
-    size_t qdepth = 0;
-
-    /* Compute quote depth level. */
-    while (strncmp(line + qdepth, quotestr, quotelen) == 0)
-       qdepth += quotelen;
-    return qdepth;
-#endif /* !HAVE_REGEX_H */
 }
 
 /* a_line and b_line are lines of text.  The quotation part of a_line is
@@ -2127,12 +2115,10 @@ bool find_paragraph(size_t *const quote, size_t *const 
par)
     filestruct *current_save;
        /* The line at the beginning of the paragraph we search for. */
 
-#ifdef HAVE_REGEX_H
     if (quoterc != 0) {
        statusline(ALERT, _("Bad quote string %s: %s"), quotestr, quoteerr);
        return FALSE;
     }
-#endif
 
     assert(openfile->current != NULL);
 
diff --git a/src/utils.c b/src/utils.c
index 812940ac43eb..24fea45d4cad 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -170,7 +170,6 @@ void sunder(char *str)
     }
 }
 
-#ifdef HAVE_REGEX_H
 /* 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)
@@ -206,7 +205,6 @@ const char *fixbounds(const char *r)
 
     return r;
 }
-#endif /* HAVE_REGEX_H */
 
 #ifndef DISABLE_SPELLER
 /* Is the word starting at the given position in buf and of the given length
@@ -237,7 +235,6 @@ bool is_separate_word(size_t position, size_t length, const 
char *buf)
 const char *strstrwrapper(const char *haystack, const char *needle,
        const char *start)
 {
-#ifdef HAVE_REGEX_H
     if (ISSET(USE_REGEXP)) {
        if (ISSET(BACKWARDS_SEARCH)) {
            if (regexec(&search_regexp, haystack, 1, regmatches, 0) == 0 &&
@@ -264,7 +261,6 @@ const char *strstrwrapper(const char *haystack, const char 
*needle,
        }
        return NULL;
     }
-#endif /* HAVE_REGEX_H */
     if (ISSET(CASE_SENSITIVE)) {
        if (ISSET(BACKWARDS_SEARCH))
            return revstrstr(haystack, needle, start);
-- 
2.11.1




reply via email to

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