comparison src/regex.c @ 44063:fd6c1f8ebd4e

(DISCARD_FAILURE_REG_OR_COUNT): New macro. (CHECK_INFINITE_LOOP): Use DISCARD_FAILURE_REG_OR_COUNT when jumping to `fail' to avoid undoing reg changes in the last iteration of the loop. (GET_UNSIGNED_NUMBER): Skip spaces around the number.
author Richard M. Stallman <rms@gnu.org>
date Thu, 21 Mar 2002 09:44:14 +0000
parents ded4aa3c81b2
children aad3682a49ba
comparison
equal deleted inserted replaced
44062:32211007711c 44063:fd6c1f8ebd4e
1516 DEBUG_PRINT4 (" Pop reg %d (spanning %p -> %p)\n", \ 1516 DEBUG_PRINT4 (" Pop reg %d (spanning %p -> %p)\n", \
1517 reg, regstart[reg], regend[reg]); \ 1517 reg, regstart[reg], regend[reg]); \
1518 } \ 1518 } \
1519 } while (0) 1519 } while (0)
1520 1520
1521 /* Discard a saved register off the stack. */
1522 #define DISCARD_FAILURE_REG_OR_COUNT() \
1523 do { \
1524 int reg = POP_FAILURE_INT (); \
1525 if (reg == -1) \
1526 { \
1527 /* It's a counter. */ \
1528 POP_FAILURE_POINTER (); \
1529 reg = POP_FAILURE_INT (); \
1530 DEBUG_PRINT3 (" Discard counter %p = %d\n", ptr, reg); \
1531 } \
1532 else \
1533 { \
1534 POP_FAILURE_POINTER (); \
1535 POP_FAILURE_POINTER (); \
1536 DEBUG_PRINT4 (" Discard reg %d (spanning %p -> %p)\n", \
1537 reg, regstart[reg], regend[reg]); \
1538 } \
1539 } while (0)
1540
1521 /* Check that we are not stuck in an infinite loop. */ 1541 /* Check that we are not stuck in an infinite loop. */
1522 #define CHECK_INFINITE_LOOP(pat_cur, string_place) \ 1542 #define CHECK_INFINITE_LOOP(pat_cur, string_place) \
1523 do { \ 1543 do { \
1524 int failure = TOP_FAILURE_HANDLE(); \ 1544 int failure = TOP_FAILURE_HANDLE (); \
1525 /* Check for infinite matching loops */ \ 1545 /* Check for infinite matching loops */ \
1526 while (failure > 0 && \ 1546 while (failure > 0 \
1527 (FAILURE_STR (failure) == string_place \ 1547 && (FAILURE_STR (failure) == string_place \
1528 || FAILURE_STR (failure) == NULL)) \ 1548 || FAILURE_STR (failure) == NULL)) \
1529 { \ 1549 { \
1530 assert (FAILURE_PAT (failure) >= bufp->buffer \ 1550 assert (FAILURE_PAT (failure) >= bufp->buffer \
1531 && FAILURE_PAT (failure) <= bufp->buffer + bufp->used); \ 1551 && FAILURE_PAT (failure) <= bufp->buffer + bufp->used); \
1532 if (FAILURE_PAT (failure) == pat_cur) \ 1552 if (FAILURE_PAT (failure) == pat_cur) \
1533 goto fail; \ 1553 { \
1554 while (fail_stack.frame < fail_stack.avail) \
1555 DISCARD_FAILURE_REG_OR_COUNT (); \
1556 goto fail; \
1557 } \
1534 DEBUG_PRINT2 (" Other pattern: %p\n", FAILURE_PAT (failure)); \ 1558 DEBUG_PRINT2 (" Other pattern: %p\n", FAILURE_PAT (failure)); \
1535 failure = NEXT_FAILURE_HANDLE(failure); \ 1559 failure = NEXT_FAILURE_HANDLE(failure); \
1536 } \ 1560 } \
1537 DEBUG_PRINT2 (" Other string: %p\n", FAILURE_STR (failure)); \ 1561 DEBUG_PRINT2 (" Other string: %p\n", FAILURE_STR (failure)); \
1538 } while (0) 1562 } while (0)
1918 /* Get the next unsigned number in the uncompiled pattern. */ 1942 /* Get the next unsigned number in the uncompiled pattern. */
1919 #define GET_UNSIGNED_NUMBER(num) \ 1943 #define GET_UNSIGNED_NUMBER(num) \
1920 do { if (p != pend) \ 1944 do { if (p != pend) \
1921 { \ 1945 { \
1922 PATFETCH (c); \ 1946 PATFETCH (c); \
1947 while (c == ' ') PATFETCH (c); \
1923 while ('0' <= c && c <= '9') \ 1948 while ('0' <= c && c <= '9') \
1924 { \ 1949 { \
1950 int prev; \
1925 if (num < 0) \ 1951 if (num < 0) \
1926 num = 0; \ 1952 num = 0; \
1953 prev = num; \
1927 num = num * 10 + c - '0'; \ 1954 num = num * 10 + c - '0'; \
1955 if (num / 10 != prev) \
1956 FREE_STACK_RETURN (REG_BADBR); \
1928 if (p == pend) \ 1957 if (p == pend) \
1929 break; \ 1958 break; \
1930 PATFETCH (c); \ 1959 PATFETCH (c); \
1931 } \ 1960 } \
1961 while (c == ' ') PATFETCH (c); \
1932 } \ 1962 } \
1933 } while (0) 1963 } while (0)
1934 1964
1935 #if WIDE_CHAR_SUPPORT 1965 #if WIDE_CHAR_SUPPORT
1936 /* The GNU C library provides support for user-defined character classes 1966 /* The GNU C library provides support for user-defined character classes