nano-devel
[Top][All Lists]
Advanced

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

[Nano-devel] [PATCH 5/8] assume regex.h support is always available


From: Mike Frysinger
Subject: [Nano-devel] [PATCH 5/8] assume regex.h support is always available
Date: Sat, 6 Feb 2016 19:03:58 -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   | 18 +-----------------
 src/utils.c  |  4 ----
 10 files changed, 6 insertions(+), 100 deletions(-)

diff --git a/autogen.sh b/autogen.sh
index 4a42cd1..ecc134e 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -6,6 +6,7 @@ modules="
        getline
        isblank
        iswblank
+       regex
        strcase
        strcasestr-simple
        strnlen
diff --git a/configure.ac b/configure.ac
index 915e0b8..0da4150 100644
--- a/configure.ac
+++ b/configure.ac
@@ -58,7 +58,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.
 
@@ -81,15 +81,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(extra,
diff --git a/src/global.c b/src/global.c
index 596ab54..d624149 100644
--- a/src/global.c
+++ b/src/global.c
@@ -108,17 +108,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
 
 bool nodelay_mode = FALSE;
@@ -195,13 +190,11 @@ poshiststruct *position_history = NULL;
 #endif
 
 /* Regular expressions. */
-#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 for reverse video. */
@@ -615,10 +608,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");
@@ -767,10 +758,8 @@ void shortcut_init(void)
        N_("Case Sens"), IFSCHELP(nano_case_msg), TOGETHER, VIEW);
 #endif
 
-#ifdef HAVE_REGEX_H
     add_to_funcs(regexp_void, MWHEREIS|MREPLACE,
        N_("Regexp"), IFSCHELP(nano_regexp_msg), TOGETHER, VIEW);
-#endif
 
 #ifndef NANO_TINY
     add_to_funcs(backwards_void, MWHEREIS|MREPLACE,
@@ -1636,11 +1625,9 @@ void thanks_for_all_the_fish(void)
 
 #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 164b40d..6dcfc91 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -2450,14 +2450,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, REG_EXTENDED);
 
     if (quoterc == 0) {
@@ -2470,9 +2463,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 d6ea261..1c93cc5 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -113,9 +113,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 553aec6..8fcc754 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -80,13 +80,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 bool nodelay_mode;
@@ -131,10 +127,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
@@ -566,10 +560,8 @@ void do_rcfile(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);
@@ -588,9 +580,7 @@ void do_findnext(void);
 #if !defined(NANO_TINY) || !defined(DISABLE_BROWSER)
 void do_research(void);
 #endif
-#ifdef HAVE_REGEX_H
 int replace_regexp(char *string, bool create);
-#endif
 char *replace_line(const char *needle);
 ssize_t do_replace_loop(
 #ifndef DISABLE_SPELLER
@@ -698,9 +688,7 @@ void align(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_whole_word(size_t pos, const char *buf, const char *word);
 #endif
diff --git a/src/rcfile.c b/src/rcfile.c
index 05bf90a..ac5f518 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -72,9 +72,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 45164b2..8ccd5f7 100644
--- a/src/search.c
+++ b/src/search.c
@@ -36,7 +36,6 @@ static bool search_last_line = 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? */
 
@@ -79,7 +78,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. */
@@ -111,9 +109,7 @@ void search_replace_abort(void)
     if (openfile->mark_set)
        edit_refresh();
 #endif
-#ifdef HAVE_REGEX_H
     regexp_cleanup();
-#endif
 }
 
 /* Set up the system variables for a search or replace.  If use_answer
@@ -176,9 +172,7 @@ int search_init(bool replacing, bool use_answer)
        ISSET(CASE_SENSITIVE) ? _(" [Case Sensitive]") :
 #endif
        "",
-#ifdef HAVE_REGEX_H
        ISSET(USE_REGEXP) ? _(" [Regexp]") :
-#endif
        "",
 #ifndef NANO_TINY
        ISSET(BACKWARDS_SEARCH) ? _(" [Backwards]") :
@@ -207,14 +201,11 @@ int search_init(bool replacing, bool use_answer)
        functionptrtype func = func_from_key(&i);
 
        if (i == -2 || i == 0 ) {
-#ifdef HAVE_REGEX_H
                /* Use last_search if answer is an empty string, or
                 * answer if it isn't. */
                if (ISSET(USE_REGEXP) && !regexp_init((i == -2) ?
                        last_search : answer))
                    return -1;
-#endif
-               ;
 #ifndef NANO_TINY
        } else if (func == case_sens_void) {
                TOGGLE(CASE_SENSITIVE);
@@ -225,12 +216,10 @@ int search_init(bool replacing, bool use_answer)
                backupstring = mallocstrcpy(backupstring, answer);
                return 1;
 #endif
-#ifdef HAVE_REGEX_H
        } else if (func == regexp_void) {
                TOGGLE(USE_REGEXP);
                backupstring = mallocstrcpy(backupstring, answer);
                return 1;
-#endif
        } else if (func == do_replace || func == flip_replace_void) {
                backupstring = mallocstrcpy(backupstring, answer);
                return -2;      /* Call the opposite search function. */
@@ -304,11 +293,8 @@ bool findnextstr(
 #endif
 
            /* Set found_len to the length of the potential match. */
-           found_len =
-#ifdef HAVE_REGEX_H
-               ISSET(USE_REGEXP) ?
+           found_len = ISSET(USE_REGEXP) ?
                regmatches[0].rm_eo - regmatches[0].rm_so :
-#endif
                strlen(needle);
 
 #ifndef DISABLE_SPELLER
@@ -432,11 +418,9 @@ void do_search(void)
     else if (i == -2)
        /* Replace. */
        do_replace();
-#if !defined(NANO_TINY) || defined(HAVE_REGEX_H)
     else if (i == 1)
        /* Case Sensitive, Backwards, or Regexp search toggle. */
        do_search();
-#endif
 
     if (i != 0)
        return;
@@ -518,11 +502,9 @@ void do_research(void)
     if (last_search[0] == '\0')
        statusbar(_("No current search pattern"));
     else {
-#ifdef HAVE_REGEX_H
        /* Since answer is "", use last_search! */
        if (ISSET(USE_REGEXP) && !regexp_init(last_search))
            return;
-#endif
 
        findnextstr_wrap_reset();
        didfind = findnextstr(
@@ -544,7 +526,6 @@ void do_research(void)
 }
 #endif /* !NANO_TINY */
 
-#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. */
@@ -588,7 +569,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)
@@ -598,17 +578,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);
@@ -617,11 +593,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));
@@ -773,11 +747,9 @@ ssize_t do_replace_loop(
 #endif
            }
 
-#ifdef HAVE_REGEX_H
            /* Don't find the same zero-length match again. */
            if (match_len == 0)
                match_len++;
-#endif
 
            /* Set the cursor at the last character of the replacement
             * text, so searching will resume after the replacement
diff --git a/src/text.c b/src/text.c
index 8c6601a..4043446 100644
--- a/src/text.c
+++ b/src/text.c
@@ -1617,13 +1617,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);
 
@@ -1632,14 +1628,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
@@ -1847,12 +1835,10 @@ bool find_paragraph(size_t *const quote, size_t *const 
par)
        /* The y-coordinate at the beginning of the paragraph we search
         * for. */
 
-#ifdef HAVE_REGEX_H
     if (quoterc != 0) {
        statusbar(_("Bad quote string %s: %s"), quotestr, quoteerr);
        return FALSE;
     }
-#endif
 
     assert(openfile->current != NULL);
 
@@ -2364,10 +2350,8 @@ bool do_int_spell_fix(const char *word)
     /* Make sure spell-check goes forward only. */
     UNSET(BACKWARDS_SEARCH);
 #endif
-#ifdef HAVE_REGEX_H
     /* Make sure spell-check doesn't use regular expressions. */
     UNSET(USE_REGEXP);
-#endif
 
     /* Save the current search/replace strings. */
     save_search = last_search;
diff --git a/src/utils.c b/src/utils.c
index 9cad6b9..9520782 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -153,7 +153,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)
@@ -189,7 +188,6 @@ const char *fixbounds(const char *r)
 
     return r;
 }
-#endif /* HAVE_REGEX_H */
 
 #ifndef DISABLE_SPELLER
 /* Is the word starting at position pos in buf a whole word? */
@@ -234,7 +232,6 @@ const char *strstrwrapper(const char *haystack, const char 
*needle,
 
     assert(haystack != NULL && needle != NULL && start != NULL);
 
-#ifdef HAVE_REGEX_H
     if (ISSET(USE_REGEXP)) {
 #ifndef NANO_TINY
        if (ISSET(BACKWARDS_SEARCH)) {
@@ -264,7 +261,6 @@ const char *strstrwrapper(const char *haystack, const char 
*needle,
        }
        return NULL;
     }
-#endif /* HAVE_REGEX_H */
 #if !defined(NANO_TINY) || !defined(DISABLE_SPELLER)
     if (ISSET(CASE_SENSITIVE)) {
 #ifndef NANO_TINY
-- 
2.6.2




reply via email to

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