[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, 18 Apr 2016 02:17:42 -0400 |
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 | 35 +++--------------------------------
src/text.c | 18 +-----------------
src/utils.c | 4 ----
10 files changed, 8 insertions(+), 103 deletions(-)
diff --git a/autogen.sh b/autogen.sh
index c32b9b9..ccc5878 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 3df1234..cb6473f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -56,7 +56,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.
@@ -79,15 +79,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 1c2f8af..0cfc732 100644
--- a/src/global.c
+++ b/src/global.c
@@ -105,17 +105,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;
@@ -192,13 +187,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. */
@@ -612,10 +605,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");
@@ -764,10 +755,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,
@@ -1633,11 +1622,9 @@ void thanks_for_all_the_fish(void)
#ifndef DISABLE_JUSTIFY
free(quotestr);
-#ifdef HAVE_REGEX_H
regfree("ereg);
free(quoteerr);
#endif
-#endif
#ifndef NANO_TINY
free(backup_dir);
#endif
diff --git a/src/nano.c b/src/nano.c
index d87dbc1..e6b3481 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("ereg, quotestr, NANO_REG_EXTENDED);
if (quoterc == 0) {
@@ -2436,9 +2429,6 @@ int main(int argc, char **argv)
quoteerr = charalloc(size);
regerror(quoterc, "ereg, 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 44c7c1f..97fc1b2 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -112,9 +112,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 2eec5ae..7f4a9b5 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -78,13 +78,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;
@@ -129,10 +125,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
@@ -556,10 +550,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);
@@ -579,9 +571,7 @@ void do_findnext(void);
void do_research(void);
#endif
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(
#ifndef DISABLE_SPELLER
@@ -689,9 +679,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 0812a5b..bb6af23 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -71,9 +71,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 5de296a..a801393 100644
--- a/src/search.c
+++ b/src/search.c
@@ -35,7 +35,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? */
@@ -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. */
@@ -110,9 +108,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
@@ -172,10 +168,7 @@ int search_init(bool replacing, bool use_answer)
ISSET(CASE_SENSITIVE) ? _(" [Case Sensitive]") :
#endif
"",
-#ifdef HAVE_REGEX_H
- ISSET(USE_REGEXP) ? _(" [Regexp]") :
-#endif
- "",
+ ISSET(USE_REGEXP) ? _(" [Regexp]") : "",
#ifndef NANO_TINY
ISSET(BACKWARDS_SEARCH) ? _(" [Backwards]") :
#endif
@@ -208,11 +201,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. */
}
@@ -229,14 +220,11 @@ int search_init(bool replacing, bool use_answer)
return 1;
} else
#endif
-#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) {
@@ -314,11 +302,8 @@ int findnextstr(
}
#endif
/* Remember 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
@@ -412,10 +397,8 @@ void do_search(void)
search_replace_abort();
else if (i == -2) /* Do a replace instead. */
do_replace();
-#if !defined(NANO_TINY) || defined(HAVE_REGEX_H)
else if (i == 1) /* Toggled something. */
do_search();
-#endif
if (i == 0)
go_looking();
@@ -464,10 +447,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;
@@ -501,7 +482,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. */
@@ -544,7 +524,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)
@@ -554,17 +533,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);
@@ -573,11 +548,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));
@@ -731,11 +704,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 8106a5d..e643d84 100644
--- a/src/text.c
+++ b/src/text.c
@@ -1628,13 +1628,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("ereg, line, 1, &matches, 0);
@@ -1643,14 +1639,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
@@ -1858,12 +1846,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);
@@ -2385,10 +2371,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 string, then set it to the misspelled word. */
save_search = last_search;
diff --git a/src/utils.c b/src/utils.c
index d515ab3..67eaa5e 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -152,7 +152,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)
@@ -188,7 +187,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? */
@@ -233,7 +231,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)) {
@@ -263,7 +260,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.7.4
- [Nano-devel] [PATCH 09/10] drop glib fallback for snprintf/vsnprintf, (continued)
- [Nano-devel] [PATCH 09/10] drop glib fallback for snprintf/vsnprintf, Mike Frysinger, 2016/04/18
- [Nano-devel] [PATCH 06/10] drop isblank/iswblank fallback functions, Mike Frysinger, 2016/04/18
- [Nano-devel] [PATCH 10/10] drop wchar.h/wctype.h/stdarg.h checks, Mike Frysinger, 2016/04/18
- [Nano-devel] [PATCH 08/10] assume getopt_long support is always available, Mike Frysinger, 2016/04/18
- [Nano-devel] [PATCH 04/10] drop various str fallback functions, Mike Frysinger, 2016/04/18
- [Nano-devel] [PATCH 03/10] add support for gnulib, Mike Frysinger, 2016/04/18
- [Nano-devel] [PATCH 02/10] gettext: update to 0.18.3 release, Mike Frysinger, 2016/04/18
- [Nano-devel] [PATCH 07/10] assume regex.h support is always available,
Mike Frysinger <=
- Re: [Nano-devel] [PATCH 00/10] update autotools & add gnulib support, Kamil Dudka, 2016/04/18