WEAK_ALIAS (__re_set_syntax, re_set_syntax)
#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)
\f
/* 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.
static reg_errcode_t regex_compile (re_char *pattern, size_t size,
reg_syntax_t syntax,
+#ifdef emacs
+ const char *whitespace_regexp,
+#endif
struct re_pattern_buffer *bufp);
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);
/* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX.
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'
fields are set in BUFP on entry.
static reg_errcode_t
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)
{
/* We fetch characters from PATTERN here. */
/* If the object matched can contain multibyte characters. */
const boolean multibyte = RE_MULTIBYTE_P (bufp);
+#ifdef emacs
/* Nonzero if we have pushed down into a subpattern. */
int in_subpattern = 0;
re_char *main_p;
re_char *main_pattern;
re_char *main_pend;
+#endif
#ifdef DEBUG
debug++;
{
if (p == pend)
{
+#ifdef emacs
/* If this is the end of an included regexp,
pop back to the main regexp and try again. */
if (in_subpattern)
pend = main_pend;
continue;
}
+#endif
/* If this is the end of the main regexp, we are done. */
break;
}
switch (c)
{
+#ifdef emacs
case ' ':
{
re_char *p1 = p;
pend = p + strlen ((const char *) p);
break;
}
+#endif
case '^':
{
const char *
re_compile_pattern (const char *pattern, size_t length,
#ifdef emacs
- reg_syntax_t syntax,
+ reg_syntax_t syntax, const char *whitespace_regexp,
#endif
struct re_pattern_buffer *bufp)
{
-#ifndef emacs
- const reg_syntax_t syntax = re_syntax_options;
-#endif
reg_errcode_t ret;
/* GNU code is written to assume at least RE_NREGS registers will be set
setting no_sub. */
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)
return NULL;
compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern,
Lisp_Object translate, bool posix)
{
+ const char *whitespace_regexp;
reg_syntax_t syntax;
char *val;
So let's turn it off. */
/* 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);
+ whitespace_regexp = STRINGP (Vsearch_spaces_regexp) ?
+ SSDATA (Vsearch_spaces_regexp) : NULL;
+
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
syntax-table, it can only be reused with *this* syntax table. */
cp->syntax_table = cp->buf.used_syntax ? BVAR (current_buffer, syntax_table) : Qt;
- re_set_whitespace_regexp (NULL);
-
/* unblock_input (); */
if (val)
xsignal1 (Qinvalid_regexp, build_string (val));