#endif /* not DEBUG */
\f
+#ifndef emacs
+
/* Set by `re_set_syntax' to the current regexp syntax to recognize. Can
also be assigned to arbitrarily: each pattern buffer stores its own
syntax, so it can be changed between regex compilations. */
}
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;
const char *
re_compile_pattern (const char *pattern, size_t length,
+#ifdef emacs
+ reg_syntax_t syntax,
+#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, re_syntax_options, bufp);
+ ret = regex_compile ((re_char*) pattern, length, syntax, bufp);
if (!ret)
return NULL;
#ifndef _REGEX_H
#define _REGEX_H 1
+#if defined emacs && (defined _REGEX_RE_COMP || defined _LIBC)
+/* We’re not defining re_set_syntax and using a different prototype of
+ re_compile_pattern when building Emacs so fail compilation early with
+ a (somewhat helpful) error message when conflict is detected. */
+# error "_REGEX_RE_COMP nor _LIBC can be defined if emacs is defined."
+#endif
+
/* Allow the use in C++ code. */
#ifdef __cplusplus
extern "C" {
\f
/* Declarations for routines. */
+#ifndef emacs
+
/* Sets the current default syntax to SYNTAX, and return the old syntax.
You can also simply assign to the `re_syntax_options' variable. */
extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax);
+#endif
+
/* Compile the regular expression PATTERN, with length LENGTH
and syntax given by the global `re_syntax_options', into the buffer
BUFFER. Return NULL if successful, and an error string if not. */
extern const char *re_compile_pattern (const char *__pattern, size_t __length,
+#ifdef emacs
+ reg_syntax_t syntax,
+#endif
struct re_pattern_buffer *__buffer);
compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern,
Lisp_Object translate, bool posix)
{
+ reg_syntax_t syntax;
char *val;
- reg_syntax_t old;
cp->regexp = Qnil;
cp->buf.translate = (! NILP (translate) ? translate : make_number (0));
Using BLOCK_INPUT here means the debugger won't run if an error occurs.
So let's turn it off. */
/* BLOCK_INPUT; */
- old = re_set_syntax (RE_SYNTAX_EMACS
- | (posix ? 0 : RE_NO_POSIX_BACKTRACKING));
if (STRINGP (Vsearch_spaces_regexp))
re_set_whitespace_regexp (SSDATA (Vsearch_spaces_regexp));
else
re_set_whitespace_regexp (NULL);
- val = (char *) re_compile_pattern (SSDATA (pattern),
- SBYTES (pattern), &cp->buf);
+ syntax = RE_SYNTAX_EMACS | (posix ? 0 : RE_NO_POSIX_BACKTRACKING);
+ val = (char *) re_compile_pattern (SSDATA (pattern), SBYTES (pattern),
+ syntax, &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. */
re_set_whitespace_regexp (NULL);
- re_set_syntax (old);
/* unblock_input (); */
if (val)
xsignal1 (Qinvalid_regexp, build_string (val));