aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/regex.c39
-rw-r--r--src/regex.h3
-rw-r--r--src/search.c13
3 files changed, 30 insertions, 25 deletions
diff --git a/src/regex.c b/src/regex.c
index 4edc064d6b8..c32a62f89af 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -1177,16 +1177,6 @@ re_set_syntax (reg_syntax_t syntax)
1177WEAK_ALIAS (__re_set_syntax, re_set_syntax) 1177WEAK_ALIAS (__re_set_syntax, re_set_syntax)
1178 1178
1179#endif 1179#endif
1180
1181/* Regexp to use to replace spaces, or NULL meaning don't. */
1182static const_re_char *whitespace_regexp;
1183
1184void
1185re_set_whitespace_regexp (const char *regexp)
1186{
1187 whitespace_regexp = (const_re_char *) regexp;
1188}
1189WEAK_ALIAS (__re_set_syntax, re_set_syntax)
1190 1180
1191/* This table gives an error message for each of the error codes listed 1181/* This table gives an error message for each of the error codes listed
1192 in regex.h. Obviously the order here has to be same as there. 1182 in regex.h. Obviously the order here has to be same as there.
@@ -1569,6 +1559,9 @@ do { \
1569 1559
1570static reg_errcode_t regex_compile (re_char *pattern, size_t size, 1560static reg_errcode_t regex_compile (re_char *pattern, size_t size,
1571 reg_syntax_t syntax, 1561 reg_syntax_t syntax,
1562#ifdef emacs
1563 const char *whitespace_regexp,
1564#endif
1572 struct re_pattern_buffer *bufp); 1565 struct re_pattern_buffer *bufp);
1573static void store_op1 (re_opcode_t op, unsigned char *loc, int arg); 1566static void store_op1 (re_opcode_t op, unsigned char *loc, int arg);
1574static void store_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2); 1567static 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/* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX. 2391/* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX.
2399 Returns one of error codes defined in `regex.h', or zero for success. 2392 Returns one of error codes defined in `regex.h', or zero for success.
2400 2393
2394 If WHITESPACE_REGEXP is given (only #ifdef emacs), it is used instead of
2395 a space character in PATTERN.
2396
2401 Assumes the `allocated' (and perhaps `buffer') and `translate' 2397 Assumes the `allocated' (and perhaps `buffer') and `translate'
2402 fields are set in BUFP on entry. 2398 fields are set in BUFP on entry.
2403 2399
@@ -2431,6 +2427,9 @@ do { \
2431 2427
2432static reg_errcode_t 2428static reg_errcode_t
2433regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax, 2429regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
2430#ifdef emacs
2431 const char *whitespace_regexp,
2432#endif
2434 struct re_pattern_buffer *bufp) 2433 struct re_pattern_buffer *bufp)
2435{ 2434{
2436 /* We fetch characters from PATTERN here. */ 2435 /* We fetch characters from PATTERN here. */
@@ -2483,6 +2482,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
2483 /* If the object matched can contain multibyte characters. */ 2482 /* If the object matched can contain multibyte characters. */
2484 const boolean multibyte = RE_MULTIBYTE_P (bufp); 2483 const boolean multibyte = RE_MULTIBYTE_P (bufp);
2485 2484
2485#ifdef emacs
2486 /* Nonzero if we have pushed down into a subpattern. */ 2486 /* Nonzero if we have pushed down into a subpattern. */
2487 int in_subpattern = 0; 2487 int in_subpattern = 0;
2488 2488
@@ -2491,6 +2491,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
2491 re_char *main_p; 2491 re_char *main_p;
2492 re_char *main_pattern; 2492 re_char *main_pattern;
2493 re_char *main_pend; 2493 re_char *main_pend;
2494#endif
2494 2495
2495#ifdef DEBUG 2496#ifdef DEBUG
2496 debug++; 2497 debug++;
@@ -2559,6 +2560,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
2559 { 2560 {
2560 if (p == pend) 2561 if (p == pend)
2561 { 2562 {
2563#ifdef emacs
2562 /* If this is the end of an included regexp, 2564 /* If this is the end of an included regexp,
2563 pop back to the main regexp and try again. */ 2565 pop back to the main regexp and try again. */
2564 if (in_subpattern) 2566 if (in_subpattern)
@@ -2569,6 +2571,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
2569 pend = main_pend; 2571 pend = main_pend;
2570 continue; 2572 continue;
2571 } 2573 }
2574#endif
2572 /* If this is the end of the main regexp, we are done. */ 2575 /* If this is the end of the main regexp, we are done. */
2573 break; 2576 break;
2574 } 2577 }
@@ -2577,6 +2580,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
2577 2580
2578 switch (c) 2581 switch (c)
2579 { 2582 {
2583#ifdef emacs
2580 case ' ': 2584 case ' ':
2581 { 2585 {
2582 re_char *p1 = p; 2586 re_char *p1 = p;
@@ -2609,6 +2613,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax,
2609 pend = p + strlen ((const char *) p); 2613 pend = p + strlen ((const char *) p);
2610 break; 2614 break;
2611 } 2615 }
2616#endif
2612 2617
2613 case '^': 2618 case '^':
2614 { 2619 {
@@ -6276,13 +6281,10 @@ bcmp_translate (const_re_char *s1, const_re_char *s2, register ssize_t len,
6276const char * 6281const char *
6277re_compile_pattern (const char *pattern, size_t length, 6282re_compile_pattern (const char *pattern, size_t length,
6278#ifdef emacs 6283#ifdef emacs
6279 reg_syntax_t syntax, 6284 reg_syntax_t syntax, const char *whitespace_regexp,
6280#endif 6285#endif
6281 struct re_pattern_buffer *bufp) 6286 struct re_pattern_buffer *bufp)
6282{ 6287{
6283#ifndef emacs
6284 const reg_syntax_t syntax = re_syntax_options;
6285#endif
6286 reg_errcode_t ret; 6288 reg_errcode_t ret;
6287 6289
6288 /* GNU code is written to assume at least RE_NREGS registers will be set 6290 /* 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 setting no_sub. */ 6296 setting no_sub. */
6295 bufp->no_sub = 0; 6297 bufp->no_sub = 0;
6296 6298
6297 ret = regex_compile ((re_char*) pattern, length, syntax, bufp); 6299 ret = regex_compile ((re_char*) pattern, length,
6300#ifdef emacs
6301 syntax,
6302 whitespace_regexp,
6303#else
6304 re_syntax_options,
6305#endif
6306 bufp);
6298 6307
6299 if (!ret) 6308 if (!ret)
6300 return NULL; 6309 return NULL;
diff --git a/src/regex.h b/src/regex.h
index 4497333500a..af9480d583c 100644
--- a/src/regex.h
+++ b/src/regex.h
@@ -474,6 +474,7 @@ extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax);
474extern const char *re_compile_pattern (const char *__pattern, size_t __length, 474extern const char *re_compile_pattern (const char *__pattern, size_t __length,
475#ifdef emacs 475#ifdef emacs
476 reg_syntax_t syntax, 476 reg_syntax_t syntax,
477 const char *whitespace_regexp,
477#endif 478#endif
478 struct re_pattern_buffer *__buffer); 479 struct re_pattern_buffer *__buffer);
479 480
@@ -627,8 +628,6 @@ extern re_wctype_t re_wctype_parse (const unsigned char **strp, unsigned limit);
627 628
628typedef int re_wchar_t; 629typedef int re_wchar_t;
629 630
630extern void re_set_whitespace_regexp (const char *regexp);
631
632#endif /* not WIDE_CHAR_SUPPORT */ 631#endif /* not WIDE_CHAR_SUPPORT */
633 632
634#endif /* regex.h */ 633#endif /* regex.h */
diff --git a/src/search.c b/src/search.c
index f0419522df2..c7556a90cb4 100644
--- a/src/search.c
+++ b/src/search.c
@@ -113,6 +113,7 @@ static void
113compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, 113compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern,
114 Lisp_Object translate, bool posix) 114 Lisp_Object translate, bool posix)
115{ 115{
116 const char *whitespace_regexp;
116 reg_syntax_t syntax; 117 reg_syntax_t syntax;
117 char *val; 118 char *val;
118 119
@@ -132,21 +133,17 @@ compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern,
132 So let's turn it off. */ 133 So let's turn it off. */
133 /* BLOCK_INPUT; */ 134 /* BLOCK_INPUT; */
134 135
135 if (STRINGP (Vsearch_spaces_regexp))
136 re_set_whitespace_regexp (SSDATA (Vsearch_spaces_regexp));
137 else
138 re_set_whitespace_regexp (NULL);
139
140 syntax = RE_SYNTAX_EMACS | (posix ? 0 : RE_NO_POSIX_BACKTRACKING); 136 syntax = RE_SYNTAX_EMACS | (posix ? 0 : RE_NO_POSIX_BACKTRACKING);
137 whitespace_regexp = STRINGP (Vsearch_spaces_regexp) ?
138 SSDATA (Vsearch_spaces_regexp) : NULL;
139
141 val = (char *) re_compile_pattern (SSDATA (pattern), SBYTES (pattern), 140 val = (char *) re_compile_pattern (SSDATA (pattern), SBYTES (pattern),
142 syntax, &cp->buf); 141 syntax, whitespace_regexp, &cp->buf);
143 142
144 /* If the compiled pattern hard codes some of the contents of the 143 /* If the compiled pattern hard codes some of the contents of the
145 syntax-table, it can only be reused with *this* syntax table. */ 144 syntax-table, it can only be reused with *this* syntax table. */
146 cp->syntax_table = cp->buf.used_syntax ? BVAR (current_buffer, syntax_table) : Qt; 145 cp->syntax_table = cp->buf.used_syntax ? BVAR (current_buffer, syntax_table) : Qt;
147 146
148 re_set_whitespace_regexp (NULL);
149
150 /* unblock_input (); */ 147 /* unblock_input (); */
151 if (val) 148 if (val)
152 xsignal1 (Qinvalid_regexp, build_string (val)); 149 xsignal1 (Qinvalid_regexp, build_string (val));