diff options
Diffstat (limited to 'src/regex.c')
| -rw-r--r-- | src/regex.c | 39 |
1 files changed, 24 insertions, 15 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) | |||
| 1177 | WEAK_ALIAS (__re_set_syntax, re_set_syntax) | 1177 | WEAK_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. */ | ||
| 1182 | static const_re_char *whitespace_regexp; | ||
| 1183 | |||
| 1184 | void | ||
| 1185 | re_set_whitespace_regexp (const char *regexp) | ||
| 1186 | { | ||
| 1187 | whitespace_regexp = (const_re_char *) regexp; | ||
| 1188 | } | ||
| 1189 | WEAK_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 | ||
| 1570 | static reg_errcode_t regex_compile (re_char *pattern, size_t size, | 1560 | static 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); |
| 1573 | static void store_op1 (re_opcode_t op, unsigned char *loc, int arg); | 1566 | static void store_op1 (re_opcode_t op, unsigned char *loc, int arg); |
| 1574 | static void store_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2); | 1567 | 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 | /* `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 | ||
| 2432 | static reg_errcode_t | 2428 | static reg_errcode_t |
| 2433 | regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax, | 2429 | regex_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, | |||
| 6276 | const char * | 6281 | const char * |
| 6277 | re_compile_pattern (const char *pattern, size_t length, | 6282 | re_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; |