assume regex.h support is always available

Now that we pull in the gnulib regex module, we can assume it exists.
master
Mike Frysinger 2017-02-21 17:04:39 -05:00 committed by Benno Schulenberg
parent 63cae0c199
commit 3deec4352b
10 changed files with 9 additions and 99 deletions

View File

@ -9,6 +9,7 @@ modules="
getline
isblank
iswblank
regex
strcase
strcasestr-simple
strnlen

View File

@ -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,

View File

@ -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. */
@ -605,10 +598,8 @@ void shortcut_init(void)
N_("Toggle the case sensitivity of the search");
const char *nano_reverse_msg =
N_("Reverse the direction of the search");
#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");
@ -765,10 +756,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

View File

@ -2421,14 +2421,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) {
@ -2441,9 +2434,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

View File

@ -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>

View File

@ -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
@ -513,10 +507,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);
@ -529,9 +521,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);
@ -646,9 +636,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

View File

@ -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

View File

@ -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? */
@ -72,7 +71,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. */
@ -102,9 +100,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
@ -156,10 +152,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. */
@ -189,11 +182,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. */
}
@ -207,15 +198,11 @@ int search_init(bool replacing, bool use_answer)
TOGGLE(BACKWARDS_SEARCH);
backupstring = mallocstrcpy(backupstring, answer);
return 1;
} else
#ifdef HAVE_REGEX_H
if (func == regexp_void) {
} else 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) {
@ -297,11 +284,9 @@ int findnextstr(const char *needle, bool whole_word_only, bool have_region,
}
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;
#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. */
@ -438,10 +423,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;
@ -479,7 +462,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. */
@ -522,7 +504,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)
@ -532,17 +513,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);
@ -551,11 +528,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));
@ -706,11 +681,10 @@ 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)))
skipone = TRUE;
#endif
/* When moving forward, put the cursor just after the replacement
* text, so that searching will continue there. */
if (!ISSET(BACKWARDS_SEARCH))

View File

@ -1864,13 +1864,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);
@ -1879,14 +1875,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
@ -2088,12 +2076,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);

View File

@ -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
@ -236,7 +234,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)) {
size_t last_find, ceiling, far_end;
@ -289,7 +286,6 @@ const char *strstrwrapper(const char *haystack, const char *needle,
else
return haystack + regmatches[0].rm_so;
}
#endif /* HAVE_REGEX_H */
if (ISSET(CASE_SENSITIVE)) {
if (ISSET(BACKWARDS_SEARCH))
return revstrstr(haystack, needle, start);