summaryrefslogtreecommitdiff
path: root/src/regex.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2013-05-05 21:31:16 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2013-05-05 21:31:16 -0700
commitdc4a2ee0efe25b03973ea5feb5de9e46560a8127 (patch)
tree47d0bac1b62e90be25687878e3319206c2a95925 /src/regex.c
parent8c13f3d62856ced64f25fbeedba5c121457d5e76 (diff)
* regex.c: Fix problems when DEBUG is defined.
(extract_number, extract_number_and_incr): Define regardless of whether DEBUG is defined; that's simpler and makes the code less likely to go stale in the normal case when DEBUG is not defined. Return int rather than taking an int * arg. All callers changed. (DEBUG_PRINT1, DEBUG_PRINT2, DEBUG_PRINT3, DEBUG_PRINT4): Remove, replacing with ... (DEBUG_PRINT): New macro. All callers changed. (DEBUG_COMPILES_ARGUMENTS): New macro. (print_fastmap, print_partial_compiled_pattern) [DEBUG]: (print_compiled_pattern, print_double_string) [DEBUG]: Use prototype rather than old-style definition. (print_partial_compiled_pattern, print_compiled_pattern) [DEBUG]: (ENSURE_FAIL_STACK, PUSH_FAILURE_REG) [DEBUG]: (POP_FAILURE_REG_OR_COUNT, PUSH_FAILURE_POINT) [DEBUG]: (POP_FAILURE_POINT, re_match_2_internal) [DEBUG]: Don't assume ptrdiff_t, size_t, and long are the same width as int. (POINTER_TO_OFFSET): Return ptrdiff_t, not regoff_t. This matters only when DEBUG is defined.
Diffstat (limited to 'src/regex.c')
-rw-r--r--src/regex.c378
1 files changed, 179 insertions, 199 deletions
diff --git a/src/regex.c b/src/regex.c
index 648f252964..83d80b5aaa 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -710,51 +710,27 @@ typedef enum
at SOURCE. */
#define EXTRACT_NUMBER(destination, source) \
- do { \
- (destination) = *(source) & 0377; \
- (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \
- } while (0)
+ ((destination) = extract_number (source))
-#ifdef DEBUG
-static void
-extract_number (int *dest, re_char *source)
+static int
+extract_number (re_char *source)
{
- int temp = SIGN_EXTEND_CHAR (*(source + 1));
- *dest = *source & 0377;
- *dest += temp << 8;
+ return (SIGN_EXTEND_CHAR (source[1]) << 8) + source[0];
}
-# ifndef EXTRACT_MACROS /* To debug the macros. */
-# undef EXTRACT_NUMBER
-# define EXTRACT_NUMBER(dest, src) extract_number (&dest, src)
-# endif /* not EXTRACT_MACROS */
-
-#endif /* DEBUG */
-
/* Same as EXTRACT_NUMBER, except increment SOURCE to after the number.
SOURCE must be an lvalue. */
#define EXTRACT_NUMBER_AND_INCR(destination, source) \
- do { \
- EXTRACT_NUMBER (destination, source); \
- (source) += 2; \
- } while (0)
+ ((destination) = extract_number_and_incr (&source))
-#ifdef DEBUG
-static void
-extract_number_and_incr (int *destination, re_char **source)
+static int
+extract_number_and_incr (re_char **source)
{
- extract_number (destination, *source);
+ int num = extract_number (*source);
*source += 2;
+ return num;
}
-
-# ifndef EXTRACT_MACROS
-# undef EXTRACT_NUMBER_AND_INCR
-# define EXTRACT_NUMBER_AND_INCR(dest, src) \
- extract_number_and_incr (&dest, &src)
-# endif /* not EXTRACT_MACROS */
-
-#endif /* DEBUG */
/* Store a multibyte character in three contiguous bytes starting
DESTINATION, and increment DESTINATION to the byte after where the
@@ -861,10 +837,8 @@ extract_number_and_incr (int *destination, re_char **source)
static int debug = -100000;
# define DEBUG_STATEMENT(e) e
-# define DEBUG_PRINT1(x) if (debug > 0) printf (x)
-# define DEBUG_PRINT2(x1, x2) if (debug > 0) printf (x1, x2)
-# define DEBUG_PRINT3(x1, x2, x3) if (debug > 0) printf (x1, x2, x3)
-# define DEBUG_PRINT4(x1, x2, x3, x4) if (debug > 0) printf (x1, x2, x3, x4)
+# define DEBUG_PRINT(...) if (debug > 0) printf (__VA_ARGS__)
+# define DEBUG_COMPILES_ARGUMENTS
# define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \
if (debug > 0) print_partial_compiled_pattern (s, e)
# define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \
@@ -873,9 +847,8 @@ static int debug = -100000;
/* Print the fastmap in human-readable form. */
-void
-print_fastmap (fastmap)
- char *fastmap;
+static void
+print_fastmap (char *fastmap)
{
unsigned was_a_range = 0;
unsigned i = 0;
@@ -905,10 +878,8 @@ print_fastmap (fastmap)
/* Print a compiled pattern string in human-readable form, starting at
the START pointer into it and ending just before the pointer END. */
-void
-print_partial_compiled_pattern (start, end)
- re_char *start;
- re_char *end;
+static void
+print_partial_compiled_pattern (re_char *start, re_char *end)
{
int mcnt, mcnt2;
re_char *p = start;
@@ -923,7 +894,7 @@ print_partial_compiled_pattern (start, end)
/* Loop over pattern commands. */
while (p < pend)
{
- fprintf (stderr, "%d:\t", p - start);
+ fprintf (stderr, "%td:\t", p - start);
switch ((re_opcode_t) *p++)
{
@@ -1027,51 +998,58 @@ print_partial_compiled_pattern (start, end)
break;
case on_failure_jump:
- extract_number_and_incr (&mcnt, &p);
- fprintf (stderr, "/on_failure_jump to %d", p + mcnt - start);
+ EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ fprintf (stderr, "/on_failure_jump to %td", p + mcnt - start);
break;
case on_failure_keep_string_jump:
- extract_number_and_incr (&mcnt, &p);
- fprintf (stderr, "/on_failure_keep_string_jump to %d", p + mcnt - start);
+ EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ fprintf (stderr, "/on_failure_keep_string_jump to %td",
+ p + mcnt - start);
break;
case on_failure_jump_nastyloop:
- extract_number_and_incr (&mcnt, &p);
- fprintf (stderr, "/on_failure_jump_nastyloop to %d", p + mcnt - start);
+ EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ fprintf (stderr, "/on_failure_jump_nastyloop to %td",
+ p + mcnt - start);
break;
case on_failure_jump_loop:
- extract_number_and_incr (&mcnt, &p);
- fprintf (stderr, "/on_failure_jump_loop to %d", p + mcnt - start);
+ EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ fprintf (stderr, "/on_failure_jump_loop to %td",
+ p + mcnt - start);
break;
case on_failure_jump_smart:
- extract_number_and_incr (&mcnt, &p);
- fprintf (stderr, "/on_failure_jump_smart to %d", p + mcnt - start);
+ EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ fprintf (stderr, "/on_failure_jump_smart to %td",
+ p + mcnt - start);
break;
case jump:
- extract_number_and_incr (&mcnt, &p);
- fprintf (stderr, "/jump to %d", p + mcnt - start);
+ EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ fprintf (stderr, "/jump to %td", p + mcnt - start);
break;
case succeed_n:
- extract_number_and_incr (&mcnt, &p);
- extract_number_and_incr (&mcnt2, &p);
- fprintf (stderr, "/succeed_n to %d, %d times", p - 2 + mcnt - start, mcnt2);
+ EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ EXTRACT_NUMBER_AND_INCR (mcnt2, p);
+ fprintf (stderr, "/succeed_n to %td, %d times",
+ p - 2 + mcnt - start, mcnt2);
break;
case jump_n:
- extract_number_and_incr (&mcnt, &p);
- extract_number_and_incr (&mcnt2, &p);
- fprintf (stderr, "/jump_n to %d, %d times", p - 2 + mcnt - start, mcnt2);
+ EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ EXTRACT_NUMBER_AND_INCR (mcnt2, p);
+ fprintf (stderr, "/jump_n to %td, %d times",
+ p - 2 + mcnt - start, mcnt2);
break;
case set_number_at:
- extract_number_and_incr (&mcnt, &p);
- extract_number_and_incr (&mcnt2, &p);
- fprintf (stderr, "/set_number_at location %d to %d", p - 2 + mcnt - start, mcnt2);
+ EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ EXTRACT_NUMBER_AND_INCR (mcnt2, p);
+ fprintf (stderr, "/set_number_at location %td to %d",
+ p - 2 + mcnt - start, mcnt2);
break;
case wordbound:
@@ -1151,13 +1129,12 @@ print_partial_compiled_pattern (start, end)
fprintf (stderr, "\n");
}
- fprintf (stderr, "%d:\tend of pattern.\n", p - start);
+ fprintf (stderr, "%td:\tend of pattern.\n", p - start);
}
-void
-print_compiled_pattern (bufp)
- struct re_pattern_buffer *bufp;
+static void
+print_compiled_pattern (struct re_pattern_buffer *bufp)
{
re_char *buffer = bufp->buffer;
@@ -1171,7 +1148,7 @@ print_compiled_pattern (bufp)
print_fastmap (bufp->fastmap);
}
- printf ("re_nsub: %d\t", bufp->re_nsub);
+ printf ("re_nsub: %zu\t", bufp->re_nsub);
printf ("regs_alloc: %d\t", bufp->regs_allocated);
printf ("can_be_null: %d\t", bufp->can_be_null);
printf ("no_sub: %d\t", bufp->no_sub);
@@ -1183,13 +1160,9 @@ print_compiled_pattern (bufp)
}
-void
-print_double_string (where, string1, size1, string2, size2)
- re_char *where;
- re_char *string1;
- re_char *string2;
- ssize_t size1;
- ssize_t size2;
+static void
+print_double_string (re_char *where, re_char *string1, ssize_t size1,
+ re_char *string2, ssize_t size2)
{
ssize_t this_char;
@@ -1216,10 +1189,12 @@ print_double_string (where, string1, size1, string2, size2)
# define assert(e)
# define DEBUG_STATEMENT(e)
-# define DEBUG_PRINT1(x)
-# define DEBUG_PRINT2(x1, x2)
-# define DEBUG_PRINT3(x1, x2, x3)
-# define DEBUG_PRINT4(x1, x2, x3, x4)
+# if __STDC_VERSION__ < 199901L
+# define DEBUG_COMPILES_ARGUMENTS
+# define DEBUG_PRINT /* 'DEBUG_PRINT (x, y)' discards X and Y. */ (void)
+# else
+# define DEBUG_PRINT(...)
+# endif
# define DEBUG_PRINT_COMPILED_PATTERN(p, s, e)
# define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2)
@@ -1469,20 +1444,21 @@ typedef struct
while (REMAINING_AVAIL_SLOTS <= space) { \
if (!GROW_FAIL_STACK (fail_stack)) \
return -2; \
- DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", (fail_stack).size);\
- DEBUG_PRINT2 (" slots available: %d\n", REMAINING_AVAIL_SLOTS);\
+ DEBUG_PRINT ("\n Doubled stack; size now: %zd\n", (fail_stack).size);\
+ DEBUG_PRINT (" slots available: %zd\n", REMAINING_AVAIL_SLOTS);\
}
/* Push register NUM onto the stack. */
#define PUSH_FAILURE_REG(num) \
do { \
char *destination; \
+ long n = num; \
ENSURE_FAIL_STACK(3); \
- DEBUG_PRINT4 (" Push reg %d (spanning %p -> %p)\n", \
- num, regstart[num], regend[num]); \
- PUSH_FAILURE_POINTER (regstart[num]); \
- PUSH_FAILURE_POINTER (regend[num]); \
- PUSH_FAILURE_INT (num); \
+ DEBUG_PRINT (" Push reg %ld (spanning %p -> %p)\n", \
+ n, regstart[n], regend[n]); \
+ PUSH_FAILURE_POINTER (regstart[n]); \
+ PUSH_FAILURE_POINTER (regend[n]); \
+ PUSH_FAILURE_INT (n); \
} while (0)
/* Change the counter's value to VAL, but make sure that it will
@@ -1493,7 +1469,7 @@ do { \
int c; \
ENSURE_FAIL_STACK(3); \
EXTRACT_NUMBER (c, ptr); \
- DEBUG_PRINT4 (" Push number %p = %d -> %d\n", ptr, c, val); \
+ DEBUG_PRINT (" Push number %p = %d -> %d\n", ptr, c, val); \
PUSH_FAILURE_INT (c); \
PUSH_FAILURE_POINTER (ptr); \
PUSH_FAILURE_INT (-1); \
@@ -1511,14 +1487,14 @@ do { \
unsigned char *ptr = (unsigned char*) POP_FAILURE_POINTER (); \
pfreg = POP_FAILURE_INT (); \
STORE_NUMBER (ptr, pfreg); \
- DEBUG_PRINT3 (" Pop counter %p = %d\n", ptr, pfreg); \
+ DEBUG_PRINT (" Pop counter %p = %ld\n", ptr, pfreg); \
} \
else \
{ \
regend[pfreg] = POP_FAILURE_POINTER (); \
regstart[pfreg] = POP_FAILURE_POINTER (); \
- DEBUG_PRINT4 (" Pop reg %d (spanning %p -> %p)\n", \
- pfreg, regstart[pfreg], regend[pfreg]); \
+ DEBUG_PRINT (" Pop reg %ld (spanning %p -> %p)\n", \
+ pfreg, regstart[pfreg], regend[pfreg]); \
} \
} while (0)
@@ -1538,10 +1514,10 @@ do { \
cycle = 1; \
break; \
} \
- DEBUG_PRINT2 (" Other pattern: %p\n", FAILURE_PAT (failure)); \
+ DEBUG_PRINT (" Other pattern: %p\n", FAILURE_PAT (failure)); \
failure = NEXT_FAILURE_HANDLE(failure); \
} \
- DEBUG_PRINT2 (" Other string: %p\n", FAILURE_STR (failure)); \
+ DEBUG_PRINT (" Other string: %p\n", FAILURE_STR (failure)); \
} while (0)
/* Push the information about the state we will need
@@ -1560,23 +1536,23 @@ do { \
of 0 + -1 isn't done as unsigned. */ \
\
DEBUG_STATEMENT (nfailure_points_pushed++); \
- DEBUG_PRINT1 ("\nPUSH_FAILURE_POINT:\n"); \
- DEBUG_PRINT2 (" Before push, next avail: %d\n", (fail_stack).avail); \
- DEBUG_PRINT2 (" size: %d\n", (fail_stack).size);\
+ DEBUG_PRINT ("\nPUSH_FAILURE_POINT:\n"); \
+ DEBUG_PRINT (" Before push, next avail: %zd\n", (fail_stack).avail); \
+ DEBUG_PRINT (" size: %zd\n", (fail_stack).size);\
\
ENSURE_FAIL_STACK (NUM_NONREG_ITEMS); \
\
- DEBUG_PRINT1 ("\n"); \
+ DEBUG_PRINT ("\n"); \
\
- DEBUG_PRINT2 (" Push frame index: %d\n", fail_stack.frame); \
+ DEBUG_PRINT (" Push frame index: %zd\n", fail_stack.frame); \
PUSH_FAILURE_INT (fail_stack.frame); \
\
- DEBUG_PRINT2 (" Push string %p: `", string_place); \
+ DEBUG_PRINT (" Push string %p: `", string_place); \
DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, size2);\
- DEBUG_PRINT1 ("'\n"); \
+ DEBUG_PRINT ("'\n"); \
PUSH_FAILURE_POINTER (string_place); \
\
- DEBUG_PRINT2 (" Push pattern %p: ", pattern); \
+ DEBUG_PRINT (" Push pattern %p: ", pattern); \
DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern, pend); \
PUSH_FAILURE_POINTER (pattern); \
\
@@ -1609,28 +1585,28 @@ do { \
assert (!FAIL_STACK_EMPTY ()); \
\
/* Remove failure points and point to how many regs pushed. */ \
- DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \
- DEBUG_PRINT2 (" Before pop, next avail: %d\n", fail_stack.avail); \
- DEBUG_PRINT2 (" size: %d\n", fail_stack.size); \
+ DEBUG_PRINT ("POP_FAILURE_POINT:\n"); \
+ DEBUG_PRINT (" Before pop, next avail: %zd\n", fail_stack.avail); \
+ DEBUG_PRINT (" size: %zd\n", fail_stack.size); \
\
/* Pop the saved registers. */ \
while (fail_stack.frame < fail_stack.avail) \
POP_FAILURE_REG_OR_COUNT (); \
\
- pat = POP_FAILURE_POINTER (); \
- DEBUG_PRINT2 (" Popping pattern %p: ", pat); \
+ pat = POP_FAILURE_POINTER (); \
+ DEBUG_PRINT (" Popping pattern %p: ", pat); \
DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \
\
/* If the saved string location is NULL, it came from an \
on_failure_keep_string_jump opcode, and we want to throw away the \
saved NULL, thus retaining our current position in the string. */ \
str = POP_FAILURE_POINTER (); \
- DEBUG_PRINT2 (" Popping string %p: `", str); \
+ DEBUG_PRINT (" Popping string %p: `", str); \
DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \
- DEBUG_PRINT1 ("'\n"); \
+ DEBUG_PRINT ("'\n"); \
\
fail_stack.frame = POP_FAILURE_INT (); \
- DEBUG_PRINT2 (" Popping frame index: %d\n", fail_stack.frame); \
+ DEBUG_PRINT (" Popping frame index: %zd\n", fail_stack.frame); \
\
assert (fail_stack.avail >= 0); \
assert (fail_stack.frame <= fail_stack.avail); \
@@ -2493,7 +2469,7 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct
#ifdef DEBUG
debug++;
- DEBUG_PRINT1 ("\nCompiling pattern: ");
+ DEBUG_PRINT ("\nCompiling pattern: ");
if (debug > 0)
{
unsigned debug_count;
@@ -3697,7 +3673,7 @@ regex_compile (const re_char *pattern, size_t size, reg_syntax_t syntax, struct
if (debug > 0)
{
re_compile_fastmap (bufp);
- DEBUG_PRINT1 ("\nCompiled pattern: \n");
+ DEBUG_PRINT ("\nCompiled pattern: \n");
print_compiled_pattern (bufp);
}
debug--;
@@ -4523,8 +4499,8 @@ static int bcmp_translate (re_char *s1, re_char *s2,
and `string2' into an offset from the beginning of that string. */
#define POINTER_TO_OFFSET(ptr) \
(FIRST_STRING_P (ptr) \
- ? ((regoff_t) ((ptr) - string1)) \
- : ((regoff_t) ((ptr) - string2 + size1)))
+ ? (ptr) - string1 \
+ : (ptr) - string2 + (ptrdiff_t) size1)
/* Call before fetching a character with *d. This switches over to
string2 if necessary.
@@ -4711,7 +4687,7 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r
/* If we're at the end of the pattern, we can change. */
if (skip_one_char (p1))
{
- DEBUG_PRINT1 (" End of pattern: fast loop.\n");
+ DEBUG_PRINT (" End of pattern: fast loop.\n");
return 1;
}
break;
@@ -4727,7 +4703,7 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r
{
if (c != RE_STRING_CHAR (p1 + 2, multibyte))
{
- DEBUG_PRINT3 (" '%c' != '%c' => fast loop.\n", c, p1[2]);
+ DEBUG_PRINT (" '%c' != '%c' => fast loop.\n", c, p1[2]);
return 1;
}
}
@@ -4752,14 +4728,14 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r
that we can't change to pop_failure_jump. */
if (!not)
{
- DEBUG_PRINT1 (" No match => fast loop.\n");
+ DEBUG_PRINT (" No match => fast loop.\n");
return 1;
}
}
else if ((re_opcode_t) *p1 == anychar
&& c == '\n')
{
- DEBUG_PRINT1 (" . != \\n => fast loop.\n");
+ DEBUG_PRINT (" . != \\n => fast loop.\n");
return 1;
}
}
@@ -4802,7 +4778,7 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r
if (idx == p2[1]
|| idx == CHARSET_BITMAP_SIZE (p1))
{
- DEBUG_PRINT1 (" No match => fast loop.\n");
+ DEBUG_PRINT (" No match => fast loop.\n");
return 1;
}
}
@@ -4819,7 +4795,7 @@ mutually_exclusive_p (struct re_pattern_buffer *bufp, const re_char *p1, const r
if (idx == p2[1])
{
- DEBUG_PRINT1 (" No match => fast loop.\n");
+ DEBUG_PRINT (" No match => fast loop.\n");
return 1;
}
}
@@ -4945,7 +4921,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
ssize_t pos, struct re_registers *regs, ssize_t stop)
{
/* General temporaries. */
- ssize_t mcnt;
+ int mcnt;
size_t reg;
/* Just past the end of the corresponding string. */
@@ -4987,7 +4963,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
#ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */
fail_stack_type fail_stack;
#endif
-#ifdef DEBUG
+#ifdef DEBUG_COMPILES_ARGUMENTS
unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0;
#endif
@@ -5032,12 +5008,12 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
and need to test it, it's not garbage. */
re_char *match_end = NULL;
-#ifdef DEBUG
+#ifdef DEBUG_COMPILES_ARGUMENTS
/* Counts the total number of registers pushed. */
unsigned num_regs_pushed = 0;
#endif
- DEBUG_PRINT1 ("\n\nEntering re_match_2.\n");
+ DEBUG_PRINT ("\n\nEntering re_match_2.\n");
INIT_FAIL_STACK ();
@@ -5133,22 +5109,25 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
dend = end_match_1;
}
- DEBUG_PRINT1 ("The compiled pattern is: ");
+ DEBUG_PRINT ("The compiled pattern is: ");
DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend);
- DEBUG_PRINT1 ("The string to match is: `");
+ DEBUG_PRINT ("The string to match is: `");
DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2);
- DEBUG_PRINT1 ("'\n");
+ DEBUG_PRINT ("'\n");
/* This loops over pattern commands. It exits by returning from the
function if the match is complete, or it drops through if the match
fails at this starting point in the input data. */
for (;;)
{
- DEBUG_PRINT2 ("\n%p: ", p);
+ DEBUG_PRINT ("\n%p: ", p);
if (p == pend)
- { /* End of pattern means we might have succeeded. */
- DEBUG_PRINT1 ("end of pattern ... ");
+ {
+ ptrdiff_t dcnt;
+
+ /* End of pattern means we might have succeeded. */
+ DEBUG_PRINT ("end of pattern ... ");
/* If we haven't matched the entire string, and we want the
longest match, try backtracking. */
@@ -5168,7 +5147,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
else
best_match_p = !FIRST_STRING_P (d);
- DEBUG_PRINT1 ("backtracking.\n");
+ DEBUG_PRINT ("backtracking.\n");
if (!FAIL_STACK_EMPTY ())
{ /* More failure points to try. */
@@ -5179,7 +5158,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
best_regs_set = true;
match_end = d;
- DEBUG_PRINT1 ("\nSAVING match as best so far.\n");
+ DEBUG_PRINT ("\nSAVING match as best so far.\n");
for (reg = 1; reg < num_regs; reg++)
{
@@ -5201,7 +5180,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
For example, the pattern `x.*y.*z' against the
strings `x-' and `y-z-', if the two strings are
not consecutive in memory. */
- DEBUG_PRINT1 ("Restoring best registers.\n");
+ DEBUG_PRINT ("Restoring best registers.\n");
d = match_end;
dend = ((d >= string1 && d <= end1)
@@ -5216,7 +5195,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
} /* d != end_match_2 */
succeed_label:
- DEBUG_PRINT1 ("Accepting match.\n");
+ DEBUG_PRINT ("Accepting match.\n");
/* If caller wants register contents data back, do it. */
if (regs && !bufp->no_sub)
@@ -5276,10 +5255,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
regs->start[reg] = regs->end[reg] = -1;
else
{
- regs->start[reg]
- = (regoff_t) POINTER_TO_OFFSET (regstart[reg]);
- regs->end[reg]
- = (regoff_t) POINTER_TO_OFFSET (regend[reg]);
+ regs->start[reg] = POINTER_TO_OFFSET (regstart[reg]);
+ regs->end[reg] = POINTER_TO_OFFSET (regend[reg]);
}
}
@@ -5292,17 +5269,17 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
regs->start[reg] = regs->end[reg] = -1;
} /* regs && !bufp->no_sub */
- DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n",
- nfailure_points_pushed, nfailure_points_popped,
- nfailure_points_pushed - nfailure_points_popped);
- DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed);
+ DEBUG_PRINT ("%u failure points pushed, %u popped (%u remain).\n",
+ nfailure_points_pushed, nfailure_points_popped,
+ nfailure_points_pushed - nfailure_points_popped);
+ DEBUG_PRINT ("%u registers pushed.\n", num_regs_pushed);
- mcnt = POINTER_TO_OFFSET (d) - pos;
+ dcnt = POINTER_TO_OFFSET (d) - pos;
- DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt);
+ DEBUG_PRINT ("Returning %td from re_match_2.\n", dcnt);
FREE_VARIABLES ();
- return mcnt;
+ return dcnt;
}
/* Otherwise match next pattern command. */
@@ -5311,11 +5288,11 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
/* Ignore these. Used to ignore the n of succeed_n's which
currently have n == 0. */
case no_op:
- DEBUG_PRINT1 ("EXECUTING no_op.\n");
+ DEBUG_PRINT ("EXECUTING no_op.\n");
break;
case succeed:
- DEBUG_PRINT1 ("EXECUTING succeed.\n");
+ DEBUG_PRINT ("EXECUTING succeed.\n");
goto succeed_label;
/* Match the next n pattern characters exactly. The following
@@ -5323,7 +5300,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
are the characters to match. */
case exactn:
mcnt = *p++;
- DEBUG_PRINT2 ("EXECUTING exactn %d.\n", mcnt);
+ DEBUG_PRINT ("EXECUTING exactn %d.\n", mcnt);
/* Remember the start point to rollback upon failure. */
dfail = d;
@@ -5429,7 +5406,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
int buf_charlen;
re_wchar_t buf_ch;
- DEBUG_PRINT1 ("EXECUTING anychar.\n");
+ DEBUG_PRINT ("EXECUTING anychar.\n");
PREFETCH ();
buf_ch = RE_STRING_CHAR_AND_LENGTH (d, buf_charlen,
@@ -5442,7 +5419,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
&& buf_ch == '\000'))
goto fail;
- DEBUG_PRINT2 (" Matched `%d'.\n", *d);
+ DEBUG_PRINT (" Matched `%d'.\n", *d);
d += buf_charlen;
}
break;
@@ -5469,7 +5446,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
/* Whether matching against a unibyte character. */
boolean unibyte_char = false;
- DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : "");
+ DEBUG_PRINT ("EXECUTING charset%s.\n", not ? "_not" : "");
range_table_exists = CHARSET_RANGE_TABLE_EXISTS_P (&p[-1]);
@@ -5553,14 +5530,14 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
matched within the group is recorded (in the internal
registers data structure) under the register number. */
case start_memory:
- DEBUG_PRINT2 ("EXECUTING start_memory %d:\n", *p);
+ DEBUG_PRINT ("EXECUTING start_memory %d:\n", *p);
/* In case we need to undo this operation (via backtracking). */
- PUSH_FAILURE_REG ((unsigned int)*p);
+ PUSH_FAILURE_REG (*p);
regstart[*p] = d;
regend[*p] = NULL; /* probably unnecessary. -sm */
- DEBUG_PRINT2 (" regstart: %d\n", POINTER_TO_OFFSET (regstart[*p]));
+ DEBUG_PRINT (" regstart: %td\n", POINTER_TO_OFFSET (regstart[*p]));
/* Move past the register number and inner group count. */
p += 1;
@@ -5570,7 +5547,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
/* The stop_memory opcode represents the end of a group. Its
argument is the same as start_memory's: the register number. */
case stop_memory:
- DEBUG_PRINT2 ("EXECUTING stop_memory %d:\n", *p);
+ DEBUG_PRINT ("EXECUTING stop_memory %d:\n", *p);
assert (!REG_UNSET (regstart[*p]));
/* Strictly speaking, there should be code such as:
@@ -5588,7 +5565,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
is *not* undone. */
regend[*p] = d;
- DEBUG_PRINT2 (" regend: %d\n", POINTER_TO_OFFSET (regend[*p]));
+ DEBUG_PRINT (" regend: %td\n", POINTER_TO_OFFSET (regend[*p]));
/* Move past the register number and the inner group count. */
p += 1;
@@ -5601,7 +5578,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
{
register re_char *d2, *dend2;
int regno = *p++; /* Get which register to match against. */
- DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno);
+ DEBUG_PRINT ("EXECUTING duplicate %d.\n", regno);
/* Can't back reference a group which we've never matched. */
if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno]))
@@ -5623,6 +5600,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
? regend[regno] : end_match_1);
for (;;)
{
+ ptrdiff_t dcnt;
+
/* If necessary, advance to next segment in register
contents. */
while (d2 == dend2)
@@ -5641,23 +5620,23 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
PREFETCH ();
/* How many characters left in this segment to match. */
- mcnt = dend - d;
+ dcnt = dend - d;
/* Want how many consecutive characters we can match in
one shot, so, if necessary, adjust the count. */
- if (mcnt > dend2 - d2)
- mcnt = dend2 - d2;
+ if (dcnt > dend2 - d2)
+ dcnt = dend2 - d2;
/* Compare that many; failure if mismatch, else move
past them. */
if (RE_TRANSLATE_P (translate)
- ? bcmp_translate (d, d2, mcnt, translate, target_multibyte)
- : memcmp (d, d2, mcnt))
+ ? bcmp_translate (d, d2, dcnt, translate, target_multibyte)
+ : memcmp (d, d2, dcnt))
{
d = dfail;
goto fail;
}
- d += mcnt, d2 += mcnt;
+ d += dcnt, d2 += dcnt;
}
}
break;
@@ -5666,7 +5645,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
/* begline matches the empty string at the beginning of the string
(unless `not_bol' is set in `bufp'), and after newlines. */
case begline:
- DEBUG_PRINT1 ("EXECUTING begline.\n");
+ DEBUG_PRINT ("EXECUTING begline.\n");
if (AT_STRINGS_BEG (d))
{
@@ -5685,7 +5664,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
/* endline is the dual of begline. */
case endline:
- DEBUG_PRINT1 ("EXECUTING endline.\n");
+ DEBUG_PRINT ("EXECUTING endline.\n");
if (AT_STRINGS_END (d))
{
@@ -5702,7 +5681,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
/* Match at the very beginning of the data. */
case begbuf:
- DEBUG_PRINT1 ("EXECUTING begbuf.\n");
+ DEBUG_PRINT ("EXECUTING begbuf.\n");
if (AT_STRINGS_BEG (d))
break;
goto fail;
@@ -5710,7 +5689,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
/* Match at the very end of the data. */
case endbuf:
- DEBUG_PRINT1 ("EXECUTING endbuf.\n");
+ DEBUG_PRINT ("EXECUTING endbuf.\n");
if (AT_STRINGS_END (d))
break;
goto fail;
@@ -5734,8 +5713,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
case; that seems worse than this. */
case on_failure_keep_string_jump:
EXTRACT_NUMBER_AND_INCR (mcnt, p);
- DEBUG_PRINT3 ("EXECUTING on_failure_keep_string_jump %d (to %p):\n",
- mcnt, p + mcnt);
+ DEBUG_PRINT ("EXECUTING on_failure_keep_string_jump %d (to %p):\n",
+ mcnt, p + mcnt);
PUSH_FAILURE_POINT (p - 3, NULL);
break;
@@ -5756,8 +5735,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
the loop. */
case on_failure_jump_nastyloop:
EXTRACT_NUMBER_AND_INCR (mcnt, p);
- DEBUG_PRINT3 ("EXECUTING on_failure_jump_nastyloop %d (to %p):\n",
- mcnt, p + mcnt);
+ DEBUG_PRINT ("EXECUTING on_failure_jump_nastyloop %d (to %p):\n",
+ mcnt, p + mcnt);
assert ((re_opcode_t)p[-4] == no_op);
{
@@ -5777,8 +5756,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
case on_failure_jump_loop:
on_failure:
EXTRACT_NUMBER_AND_INCR (mcnt, p);
- DEBUG_PRINT3 ("EXECUTING on_failure_jump_loop %d (to %p):\n",
- mcnt, p + mcnt);
+ DEBUG_PRINT ("EXECUTING on_failure_jump_loop %d (to %p):\n",
+ mcnt, p + mcnt);
{
int cycle = 0;
CHECK_INFINITE_LOOP (p - 3, d);
@@ -5809,8 +5788,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
pop_failure_jump back to this on_failure_jump. */
case on_failure_jump:
EXTRACT_NUMBER_AND_INCR (mcnt, p);
- DEBUG_PRINT3 ("EXECUTING on_failure_jump %d (to %p):\n",
- mcnt, p + mcnt);
+ DEBUG_PRINT ("EXECUTING on_failure_jump %d (to %p):\n",
+ mcnt, p + mcnt);
PUSH_FAILURE_POINT (p -3, d);
break;
@@ -5824,8 +5803,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
on_failure_keep_string_jump instead of on_failure_jump. */
case on_failure_jump_smart:
EXTRACT_NUMBER_AND_INCR (mcnt, p);
- DEBUG_PRINT3 ("EXECUTING on_failure_jump_smart %d (to %p).\n",
- mcnt, p + mcnt);
+ DEBUG_PRINT ("EXECUTING on_failure_jump_smart %d (to %p).\n",
+ mcnt, p + mcnt);
{
re_char *p1 = p; /* Next operation. */
/* Here, we discard `const', making re_match non-reentrant. */
@@ -5845,14 +5824,14 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
if (mutually_exclusive_p (bufp, p1, p2))
{
/* Use a fast `on_failure_keep_string_jump' loop. */
- DEBUG_PRINT1 (" smart exclusive => fast loop.\n");
+ DEBUG_PRINT (" smart exclusive => fast loop.\n");
*p3 = (unsigned char) on_failure_keep_string_jump;
STORE_NUMBER (p2 - 2, mcnt + 3);
}
else
{
/* Default to a safe `on_failure_jump' loop. */
- DEBUG_PRINT1 (" smart default => slow loop.\n");
+ DEBUG_PRINT (" smart default => slow loop.\n");
*p3 = (unsigned char) on_failure_jump;
}
DEBUG_STATEMENT (debug -= 2);
@@ -5864,9 +5843,9 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
unconditional_jump:
IMMEDIATE_QUIT_CHECK;
EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */
- DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt);
+ DEBUG_PRINT ("EXECUTING jump %d ", mcnt);
p += mcnt; /* Do the jump. */
- DEBUG_PRINT2 ("(to %p).\n", p);
+ DEBUG_PRINT ("(to %p).\n", p);
break;
@@ -5875,7 +5854,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
case succeed_n:
/* Signedness doesn't matter since we only compare MCNT to 0. */
EXTRACT_NUMBER (mcnt, p + 2);
- DEBUG_PRINT2 ("EXECUTING succeed_n %d.\n", mcnt);
+ DEBUG_PRINT ("EXECUTING succeed_n %d.\n", mcnt);
/* Originally, mcnt is how many times we HAVE to succeed. */
if (mcnt != 0)
@@ -5894,7 +5873,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
case jump_n:
/* Signedness doesn't matter since we only compare MCNT to 0. */
EXTRACT_NUMBER (mcnt, p + 2);
- DEBUG_PRINT2 ("EXECUTING jump_n %d.\n", mcnt);
+ DEBUG_PRINT ("EXECUTING jump_n %d.\n", mcnt);
/* Originally, this is how many times we CAN jump. */
if (mcnt != 0)
@@ -5913,14 +5892,14 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
case set_number_at:
{
unsigned char *p2; /* Location of the counter. */
- DEBUG_PRINT1 ("EXECUTING set_number_at.\n");
+ DEBUG_PRINT ("EXECUTING set_number_at.\n");
EXTRACT_NUMBER_AND_INCR (mcnt, p);
/* Here, we discard `const', making re_match non-reentrant. */
p2 = (unsigned char*) p + mcnt;
/* Signedness doesn't matter since we only copy MCNT's bits . */
EXTRACT_NUMBER_AND_INCR (mcnt, p);
- DEBUG_PRINT3 (" Setting %p to %d.\n", p2, mcnt);
+ DEBUG_PRINT (" Setting %p to %d.\n", p2, mcnt);
PUSH_NUMBER (p2, mcnt);
break;
}
@@ -5929,7 +5908,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
case notwordbound:
{
boolean not = (re_opcode_t) *(p - 1) == notwordbound;
- DEBUG_PRINT2 ("EXECUTING %swordbound.\n", not?"not":"");
+ DEBUG_PRINT ("EXECUTING %swordbound.\n", not ? "not" : "");
/* We SUCCEED (or FAIL) in one of the following cases: */
@@ -5971,7 +5950,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
}
case wordbeg:
- DEBUG_PRINT1 ("EXECUTING wordbeg.\n");
+ DEBUG_PRINT ("EXECUTING wordbeg.\n");
/* We FAIL in one of the following cases: */
@@ -6016,7 +5995,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
break;
case wordend:
- DEBUG_PRINT1 ("EXECUTING wordend.\n");
+ DEBUG_PRINT ("EXECUTING wordend.\n");
/* We FAIL in one of the following cases: */
@@ -6061,7 +6040,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
break;
case symbeg:
- DEBUG_PRINT1 ("EXECUTING symbeg.\n");
+ DEBUG_PRINT ("EXECUTING symbeg.\n");
/* We FAIL in one of the following cases: */
@@ -6104,7 +6083,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
break;
case symend:
- DEBUG_PRINT1 ("EXECUTING symend.\n");
+ DEBUG_PRINT ("EXECUTING symend.\n");
/* We FAIL in one of the following cases: */
@@ -6151,7 +6130,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
{
boolean not = (re_opcode_t) *(p - 1) == notsyntaxspec;
mcnt = *p++;
- DEBUG_PRINT3 ("EXECUTING %ssyntaxspec %d.\n", not?"not":"", mcnt);
+ DEBUG_PRINT ("EXECUTING %ssyntaxspec %d.\n", not ? "not" : "",
+ mcnt);
PREFETCH ();
#ifdef emacs
{
@@ -6174,19 +6154,19 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
#ifdef emacs
case before_dot:
- DEBUG_PRINT1 ("EXECUTING before_dot.\n");
+ DEBUG_PRINT ("EXECUTING before_dot.\n");
if (PTR_BYTE_POS (d) >= PT_BYTE)
goto fail;
break;
case at_dot:
- DEBUG_PRINT1 ("EXECUTING at_dot.\n");
+ DEBUG_PRINT ("EXECUTING at_dot.\n");
if (PTR_BYTE_POS (d) != PT_BYTE)
goto fail;
break;
case after_dot:
- DEBUG_PRINT1 ("EXECUTING after_dot.\n");
+ DEBUG_PRINT ("EXECUTING after_dot.\n");
if (PTR_BYTE_POS (d) <= PT_BYTE)
goto fail;
break;
@@ -6196,8 +6176,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
{
boolean not = (re_opcode_t) *(p - 1) == notcategoryspec;
mcnt = *p++;
- DEBUG_PRINT3 ("EXECUTING %scategoryspec %d.\n",
- not?"not":"", mcnt);
+ DEBUG_PRINT ("EXECUTING %scategoryspec %d.\n",
+ not ? "not" : "", mcnt);
PREFETCH ();
{
@@ -6226,7 +6206,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
{
re_char *str, *pat;
/* A restart point is known. Restore to that state. */
- DEBUG_PRINT1 ("\nFAIL:\n");
+ DEBUG_PRINT ("\nFAIL:\n");
POP_FAILURE_POINT (str, pat);
switch (*pat++)
{
@@ -6271,7 +6251,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const re_char *string1,
FREE_VARIABLES ();
return -1; /* Failure to match. */
-} /* re_match_2 */
+}
/* Subroutine definitions for re_match_2. */