Commit da9c55dd authored by Michal Nazarewicz's avatar Michal Nazarewicz

Get rid of re_set_whitespace_regexp

* src/regex.h (re_set_whitespace_regexp): Delete.
(re_compile_pattern): Add whitespace_regexp argument #ifdef emacs.

* src/regex.c (re_set_whitespace_regexp, whitespace_regexp): Delete.
(regex_compile): Add whitespace_regexp argument #ifdef emacs and wrap
whitespace_regexp-related code in an #ifdef emacs so it’s compiled out
unless building Emacs.
(re_compile_pattern): Pass whitespace_regexp argument to regex_compile

* src/search.c (compile_pattern_1): Don’t use re_set_whitespace_regexp,
pass the regex as argument to re_compile_pattern instead.
parent 04d96eca
...@@ -1177,16 +1177,6 @@ re_set_syntax (reg_syntax_t syntax) ...@@ -1177,16 +1177,6 @@ re_set_syntax (reg_syntax_t syntax)
WEAK_ALIAS (__re_set_syntax, re_set_syntax) WEAK_ALIAS (__re_set_syntax, re_set_syntax)
#endif #endif
/* Regexp to use to replace spaces, or NULL meaning don't. */
static const_re_char *whitespace_regexp;
void
re_set_whitespace_regexp (const char *regexp)
{
whitespace_regexp = (const_re_char *) regexp;
}
WEAK_ALIAS (__re_set_syntax, re_set_syntax)
/* This table gives an error message for each of the error codes listed /* This table gives an error message for each of the error codes listed
in regex.h. Obviously the order here has to be same as there. in regex.h. Obviously the order here has to be same as there.
...@@ -1569,6 +1559,9 @@ do { \ ...@@ -1569,6 +1559,9 @@ do { \
static reg_errcode_t regex_compile (re_char *pattern, size_t size, static reg_errcode_t regex_compile (re_char *pattern, size_t size,
reg_syntax_t syntax, reg_syntax_t syntax,
#ifdef emacs
const char *whitespace_regexp,
#endif
struct re_pattern_buffer *bufp); struct re_pattern_buffer *bufp);
static void store_op1 (re_opcode_t op, unsigned char *loc, int arg); static void store_op1 (re_opcode_t op, unsigned char *loc, int arg);
static void store_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2); static void store_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2);
...@@ -2398,6 +2391,9 @@ static boolean group_in_compile_stack (compile_stack_type compile_stack, ...@@ -2398,6 +2391,9 @@ static boolean group_in_compile_stack (compile_stack_type compile_stack,
/* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX. /* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX.
Returns one of error codes defined in `regex.h', or zero for success. Returns one of error codes defined in `regex.h', or zero for success.
If WHITESPACE_REGEXP is given (only #ifdef emacs), it is used instead of
a space character in PATTERN.
Assumes the `allocated' (and perhaps `buffer') and `translate' Assumes the `allocated' (and perhaps `buffer') and `translate'
fields are set in BUFP on entry. fields are set in BUFP on entry.
...@@ -2431,6 +2427,9 @@ do { \ ...@@ -2431,6 +2427,9 @@ do { \
static reg_errcode_t static reg_errcode_t
regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax, regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
#ifdef emacs
const char *whitespace_regexp,
#endif
struct re_pattern_buffer *bufp) struct re_pattern_buffer *bufp)
{ {
/* We fetch characters from PATTERN here. */ /* We fetch characters from PATTERN here. */
...@@ -2483,6 +2482,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax, ...@@ -2483,6 +2482,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
/* If the object matched can contain multibyte characters. */ /* If the object matched can contain multibyte characters. */
const boolean multibyte = RE_MULTIBYTE_P (bufp); const boolean multibyte = RE_MULTIBYTE_P (bufp);
#ifdef emacs
/* Nonzero if we have pushed down into a subpattern. */ /* Nonzero if we have pushed down into a subpattern. */
int in_subpattern = 0; int in_subpattern = 0;
...@@ -2491,6 +2491,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax, ...@@ -2491,6 +2491,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
re_char *main_p; re_char *main_p;
re_char *main_pattern; re_char *main_pattern;
re_char *main_pend; re_char *main_pend;
#endif
#ifdef DEBUG #ifdef DEBUG
debug++; debug++;
...@@ -2559,6 +2560,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax, ...@@ -2559,6 +2560,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
{ {
if (p == pend) if (p == pend)
{ {
#ifdef emacs
/* If this is the end of an included regexp, /* If this is the end of an included regexp,
pop back to the main regexp and try again. */ pop back to the main regexp and try again. */
if (in_subpattern) if (in_subpattern)
...@@ -2569,6 +2571,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax, ...@@ -2569,6 +2571,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
pend = main_pend; pend = main_pend;
continue; continue;
} }
#endif
/* If this is the end of the main regexp, we are done. */ /* If this is the end of the main regexp, we are done. */
break; break;
} }
...@@ -2577,6 +2580,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax, ...@@ -2577,6 +2580,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
switch (c) switch (c)
{ {
#ifdef emacs
case ' ': case ' ':
{ {
re_char *p1 = p; re_char *p1 = p;
...@@ -2609,6 +2613,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax, ...@@ -2609,6 +2613,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
pend = p + strlen ((const char *) p); pend = p + strlen ((const char *) p);
break; break;
} }
#endif
case '^': case '^':
{ {
...@@ -6276,13 +6281,10 @@ bcmp_translate (const_re_char *s1, const_re_char *s2, register ssize_t len, ...@@ -6276,13 +6281,10 @@ bcmp_translate (const_re_char *s1, const_re_char *s2, register ssize_t len,
const char * const char *
re_compile_pattern (const char *pattern, size_t length, re_compile_pattern (const char *pattern, size_t length,
#ifdef emacs #ifdef emacs
reg_syntax_t syntax, reg_syntax_t syntax, const char *whitespace_regexp,
#endif #endif
struct re_pattern_buffer *bufp) struct re_pattern_buffer *bufp)
{ {
#ifndef emacs
const reg_syntax_t syntax = re_syntax_options;
#endif
reg_errcode_t ret; reg_errcode_t ret;
/* GNU code is written to assume at least RE_NREGS registers will be set /* GNU code is written to assume at least RE_NREGS registers will be set
...@@ -6294,7 +6296,14 @@ re_compile_pattern (const char *pattern, size_t length, ...@@ -6294,7 +6296,14 @@ re_compile_pattern (const char *pattern, size_t length,
setting no_sub. */ setting no_sub. */
bufp->no_sub = 0; bufp->no_sub = 0;
ret = regex_compile ((re_char*) pattern, length, syntax, bufp); ret = regex_compile ((re_char*) pattern, length,
#ifdef emacs
syntax,
whitespace_regexp,
#else
re_syntax_options,
#endif
bufp);
if (!ret) if (!ret)
return NULL; return NULL;
......
...@@ -474,6 +474,7 @@ extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax); ...@@ -474,6 +474,7 @@ extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax);
extern const char *re_compile_pattern (const char *__pattern, size_t __length, extern const char *re_compile_pattern (const char *__pattern, size_t __length,
#ifdef emacs #ifdef emacs
reg_syntax_t syntax, reg_syntax_t syntax,
const char *whitespace_regexp,
#endif #endif
struct re_pattern_buffer *__buffer); struct re_pattern_buffer *__buffer);
...@@ -627,8 +628,6 @@ extern re_wctype_t re_wctype_parse (const unsigned char **strp, unsigned limit); ...@@ -627,8 +628,6 @@ extern re_wctype_t re_wctype_parse (const unsigned char **strp, unsigned limit);
typedef int re_wchar_t; typedef int re_wchar_t;
extern void re_set_whitespace_regexp (const char *regexp);
#endif /* not WIDE_CHAR_SUPPORT */ #endif /* not WIDE_CHAR_SUPPORT */
#endif /* regex.h */ #endif /* regex.h */
......
...@@ -113,6 +113,7 @@ static void ...@@ -113,6 +113,7 @@ static void
compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern,
Lisp_Object translate, bool posix) Lisp_Object translate, bool posix)
{ {
const char *whitespace_regexp;
reg_syntax_t syntax; reg_syntax_t syntax;
char *val; char *val;
...@@ -132,21 +133,17 @@ compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, ...@@ -132,21 +133,17 @@ compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern,
So let's turn it off. */ So let's turn it off. */
/* BLOCK_INPUT; */ /* BLOCK_INPUT; */
if (STRINGP (Vsearch_spaces_regexp))
re_set_whitespace_regexp (SSDATA (Vsearch_spaces_regexp));
else
re_set_whitespace_regexp (NULL);
syntax = RE_SYNTAX_EMACS | (posix ? 0 : RE_NO_POSIX_BACKTRACKING); syntax = RE_SYNTAX_EMACS | (posix ? 0 : RE_NO_POSIX_BACKTRACKING);
whitespace_regexp = STRINGP (Vsearch_spaces_regexp) ?
SSDATA (Vsearch_spaces_regexp) : NULL;
val = (char *) re_compile_pattern (SSDATA (pattern), SBYTES (pattern), val = (char *) re_compile_pattern (SSDATA (pattern), SBYTES (pattern),
syntax, &cp->buf); syntax, whitespace_regexp, &cp->buf);
/* If the compiled pattern hard codes some of the contents of the /* If the compiled pattern hard codes some of the contents of the
syntax-table, it can only be reused with *this* syntax table. */ syntax-table, it can only be reused with *this* syntax table. */
cp->syntax_table = cp->buf.used_syntax ? BVAR (current_buffer, syntax_table) : Qt; cp->syntax_table = cp->buf.used_syntax ? BVAR (current_buffer, syntax_table) : Qt;
re_set_whitespace_regexp (NULL);
/* unblock_input (); */ /* unblock_input (); */
if (val) if (val)
xsignal1 (Qinvalid_regexp, build_string (val)); xsignal1 (Qinvalid_regexp, build_string (val));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment