[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] Changes to emacs/src/regex.c
From: |
Richard M . Stallman |
Subject: |
[Emacs-diffs] Changes to emacs/src/regex.c |
Date: |
Fri, 19 Nov 2004 14:42:29 -0500 |
Index: emacs/src/regex.c
diff -c emacs/src/regex.c:1.194 emacs/src/regex.c:1.195
*** emacs/src/regex.c:1.194 Sun Oct 24 03:56:51 2004
--- emacs/src/regex.c Fri Nov 19 19:36:09 2004
***************
*** 1250,1256 ****
reg_syntax_t
re_set_syntax (syntax)
! reg_syntax_t syntax;
{
reg_syntax_t ret = re_syntax_options;
--- 1250,1256 ----
reg_syntax_t
re_set_syntax (syntax)
! reg_syntax_t syntax;
{
reg_syntax_t ret = re_syntax_options;
***************
*** 1258,1263 ****
--- 1258,1274 ----
return ret;
}
WEAK_ALIAS (__re_set_syntax, re_set_syntax)
+
+ /* Regexp to use to replace spaces, or NULL meaning don't. */
+ static re_char *whitespace_regexp;
+
+ void
+ re_set_whitespace_regexp (regexp)
+ re_char *regexp;
+ {
+ whitespace_regexp = regexp;
+ }
+ WEAK_ALIAS (__re_set_syntax, re_set_syntax)
/* 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.
***************
*** 2436,2441 ****
--- 2447,2461 ----
/* If the object matched can contain multibyte characters. */
const boolean multibyte = RE_MULTIBYTE_P (bufp);
+ /* Nonzero if we have pushed down into a subpattern. */
+ int in_subpattern = 0;
+
+ /* These hold the values of p, pattern, and pend from the main
+ pattern when we have pushed into a subpattern. */
+ re_char *main_p;
+ re_char *main_pattern;
+ re_char *main_pend;
+
#ifdef DEBUG
debug++;
DEBUG_PRINT1 ("\nCompiling pattern: ");
***************
*** 2498,2509 ****
begalt = b = bufp->buffer;
/* Loop through the uncompiled pattern until we're at the end. */
! while (p != pend)
{
PATFETCH (c);
switch (c)
{
case '^':
{
if ( /* If at start of pattern, it's an operator. */
--- 2518,2578 ----
begalt = b = bufp->buffer;
/* Loop through the uncompiled pattern until we're at the end. */
! while (1)
{
+ if (p == pend)
+ {
+ /* If this is the end of an included regexp,
+ pop back to the main regexp and try again. */
+ if (in_subpattern)
+ {
+ in_subpattern = 0;
+ pattern = main_pattern;
+ p = main_p;
+ pend = main_pend;
+ continue;
+ }
+ /* If this is the end of the main regexp, we are done. */
+ break;
+ }
+
PATFETCH (c);
switch (c)
{
+ case ' ':
+ {
+ re_char *p1 = p;
+
+ /* If there's no special whitespace regexp, treat
+ spaces normally. */
+ if (!whitespace_regexp)
+ goto normal_char;
+
+ /* Peek past following spaces. */
+ while (p1 != pend)
+ {
+ if (*p1 != ' ')
+ break;
+ p1++;
+ }
+ /* If the spaces are followed by a repetition op,
+ treat them normally. */
+ if (p1 == pend
+ || (*p1 == '*' || *p1 == '+' || *p1 == '?'
+ || (*p1 == '\\' && p1 + 1 != pend && p1[1] == '{')))
+ goto normal_char;
+
+ /* Replace the spaces with the whitespace regexp. */
+ in_subpattern = 1;
+ main_p = p1;
+ main_pend = pend;
+ main_pattern = pattern;
+ p = pattern = whitespace_regexp;
+ pend = p + strlen (p);
+ break;
+ }
+
case '^':
{
if ( /* If at start of pattern, it's an operator. */
- [Emacs-diffs] Changes to emacs/src/regex.c,
Richard M . Stallman <=