diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2010-07-16 12:49:45 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2010-07-16 12:49:45 +0300 |
commit | 6607eb3d5e40b98d2acc8f6b0d6a0b5a4b0f56bd (patch) | |
tree | c1eb39be8cc5c19101385e171ec0c58f95d521cc /regex.c | |
parent | 6719bb6e1c5576e857ab6fc121ec31a75161a3e7 (diff) | |
download | egawk-6607eb3d5e40b98d2acc8f6b0d6a0b5a4b0f56bd.tar.gz egawk-6607eb3d5e40b98d2acc8f6b0d6a0b5a4b0f56bd.tar.bz2 egawk-6607eb3d5e40b98d2acc8f6b0d6a0b5a4b0f56bd.zip |
Move to gawk-3.0.3.
Diffstat (limited to 'regex.c')
-rw-r--r-- | regex.c | 296 |
1 files changed, 201 insertions, 95 deletions
@@ -1,9 +1,9 @@ /* Extended regular expression matching and search library, version 0.12. - (Implements POSIX draft P10003.2/D11.2, except for + (Implements POSIX draft P1003.2/D11.2, except for some of the internationalization features.) - Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc. + Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,9 +16,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - USA. */ + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* AIX requires this to be the first thing in the file. */ #if defined (_AIX) && !defined (REGEX_MALLOC) @@ -39,6 +38,13 @@ #include <sys/types.h> #endif +/* For platform which support the ISO C amendement 1 functionality we + support user defined character classes. */ +#if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H) +# include <wctype.h> +# include <wchar.h> +#endif + /* This is for other GNU distributions with internationalized messages. */ #if HAVE_LIBINTL_H || defined (_LIBC) # include <libintl.h> @@ -501,7 +507,7 @@ typedef enum } while (0) #ifdef DEBUG -static void extract_number _RE_ARGS((int *dest, unsigned char *source)); +static void extract_number _RE_ARGS ((int *dest, unsigned char *source)); static void extract_number (dest, source) int *dest; @@ -529,8 +535,8 @@ extract_number (dest, source) } while (0) #ifdef DEBUG -static void extract_number_and_incr _RE_ARGS((int *destination, - unsigned char **source)); +static void extract_number_and_incr _RE_ARGS ((int *destination, + unsigned char **source)); static void extract_number_and_incr (destination, source) int *destination; @@ -615,6 +621,7 @@ print_partial_compiled_pattern (start, end) unsigned char *end; { int mcnt, mcnt2; + unsigned char *p1; unsigned char *p = start; unsigned char *pend = end; @@ -756,20 +763,23 @@ print_partial_compiled_pattern (start, end) case succeed_n: extract_number_and_incr (&mcnt, &p); + p1 = p + mcnt; extract_number_and_incr (&mcnt2, &p); - printf ("/succeed_n to %d, %d times", p + mcnt - start, mcnt2); + printf ("/succeed_n to %d, %d times", p1 - start, mcnt2); break; case jump_n: extract_number_and_incr (&mcnt, &p); + p1 = p + mcnt; extract_number_and_incr (&mcnt2, &p); - printf ("/jump_n to %d, %d times", p + mcnt - start, mcnt2); + printf ("/jump_n to %d, %d times", p1 - start, mcnt2); break; case set_number_at: extract_number_and_incr (&mcnt, &p); + p1 = p + mcnt; extract_number_and_incr (&mcnt2, &p); - printf ("/set_number_at location %d to %d", p + mcnt - start, mcnt2); + printf ("/set_number_at location %d to %d", p1 - start, mcnt2); break; case wordbound: @@ -847,7 +857,8 @@ print_compiled_pattern (bufp) unsigned char *buffer = bufp->buffer; print_partial_compiled_pattern (buffer, buffer + bufp->used); - printf ("%d bytes used/%d bytes allocated.\n", bufp->used, bufp->allocated); + printf ("%ld bytes used/%ld bytes allocated.\n", + bufp->used, bufp->allocated); if (bufp->fastmap_accurate && bufp->fastmap) { @@ -862,7 +873,7 @@ print_compiled_pattern (bufp) printf ("no_sub: %d\t", bufp->no_sub); printf ("not_bol: %d\t", bufp->not_bol); printf ("not_eol: %d\t", bufp->not_eol); - printf ("syntax: %d\n", bufp->syntax); + printf ("syntax: %lx\n", bufp->syntax); /* Perhaps we should print the translate table? */ } @@ -875,7 +886,7 @@ print_double_string (where, string1, size1, string2, size2) int size1; int size2; { - unsigned this_char; + int this_char; if (where == NULL) printf ("(null)"); @@ -896,9 +907,9 @@ print_double_string (where, string1, size1, string2, size2) void printchar (c) - int c; + int c; { - putc(c, stderr); + putc (c, stderr); } #else /* not DEBUG */ @@ -1031,15 +1042,17 @@ static const char *re_error_msgid[] = #ifdef INT_IS_16BIT #if defined (MATCH_MAY_ALLOCATE) -long re_max_failures = 20000; +/* 4400 was enough to cause a crash on Alpha OSF/1, + whose default stack limit is 2mb. */ +long int re_max_failures = 4000; #else -long re_max_failures = 2000; +long int re_max_failures = 2000; #endif union fail_stack_elt { unsigned char *pointer; - long integer; + long int integer; }; typedef union fail_stack_elt fail_stack_elt_t; @@ -1047,8 +1060,8 @@ typedef union fail_stack_elt fail_stack_elt_t; typedef struct { fail_stack_elt_t *stack; - unsigned long size; - unsigned long avail; /* Offset of next open position. */ + unsigned long int size; + unsigned long int avail; /* Offset of next open position. */ } fail_stack_type; #else /* not INT_IS_16BIT */ @@ -1118,7 +1131,7 @@ typedef struct REGEX_REALLOCATE_STACK requires `destination' be declared. */ #define DOUBLE_FAIL_STACK(fail_stack) \ - ((fail_stack).size > re_max_failures * MAX_FAILURE_ITEMS \ + ((fail_stack).size > (unsigned) (re_max_failures * MAX_FAILURE_ITEMS) \ ? 0 \ : ((fail_stack).stack = (fail_stack_elt_t *) \ REGEX_REALLOCATE_STACK ((fail_stack).stack, \ @@ -1189,8 +1202,8 @@ typedef struct char *destination; \ /* Must be int, so when we don't save any registers, the arithmetic \ of 0 + -1 isn't done as unsigned. */ \ - /* Can't be int, since there is not a shred of a guarantee that int \ - is wide enough to hold a value of something to which pointer can \ + /* Can't be int, since there is not a shred of a guarantee that int \ + is wide enough to hold a value of something to which pointer can \ be assigned */ \ s_reg_t this_reg; \ \ @@ -1248,7 +1261,7 @@ typedef struct DEBUG_PRINT2 (" Pushing high active reg: %d\n", highest_active_reg);\ PUSH_FAILURE_INT (highest_active_reg); \ \ - DEBUG_PRINT2 (" Pushing pattern 0x%x: ", pattern_place); \ + DEBUG_PRINT2 (" Pushing pattern 0x%x:\n", pattern_place); \ DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend); \ PUSH_FAILURE_POINTER (pattern_place); \ \ @@ -1332,7 +1345,7 @@ typedef struct DEBUG_PRINT1 ("'\n"); \ \ pat = (unsigned char *) POP_FAILURE_POINTER (); \ - DEBUG_PRINT2 (" Popping pattern 0x%x: ", pat); \ + DEBUG_PRINT2 (" Popping pattern 0x%x:\n", pat); \ DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \ \ /* Restore register info. */ \ @@ -1435,25 +1448,25 @@ static char reg_unset_dummy; /* Subroutine declarations and macros for regex_compile. */ -static reg_errcode_t regex_compile _RE_ARGS((const char *pattern, size_t size, - reg_syntax_t syntax, - struct re_pattern_buffer *bufp)); -static void store_op1 _RE_ARGS((re_opcode_t op, unsigned char *loc, int arg)); -static void store_op2 _RE_ARGS((re_opcode_t op, unsigned char *loc, - int arg1, int arg2)); -static void insert_op1 _RE_ARGS((re_opcode_t op, unsigned char *loc, - int arg, unsigned char *end)); -static void insert_op2 _RE_ARGS((re_opcode_t op, unsigned char *loc, - int arg1, int arg2, unsigned char *end)); -static boolean at_begline_loc_p _RE_ARGS((const char *pattern, const char *p, - reg_syntax_t syntax)); -static boolean at_endline_loc_p _RE_ARGS((const char *p, const char *pend, - reg_syntax_t syntax)); -static reg_errcode_t compile_range _RE_ARGS((const char **p_ptr, - const char *pend, - char *translate, - reg_syntax_t syntax, - unsigned char *b)); +static reg_errcode_t regex_compile _RE_ARGS ((const char *pattern, size_t size, + reg_syntax_t syntax, + struct re_pattern_buffer *bufp)); +static void store_op1 _RE_ARGS ((re_opcode_t op, unsigned char *loc, int arg)); +static void store_op2 _RE_ARGS ((re_opcode_t op, unsigned char *loc, + int arg1, int arg2)); +static void insert_op1 _RE_ARGS ((re_opcode_t op, unsigned char *loc, + int arg, unsigned char *end)); +static void insert_op2 _RE_ARGS ((re_opcode_t op, unsigned char *loc, + int arg1, int arg2, unsigned char *end)); +static boolean at_begline_loc_p _RE_ARGS ((const char *pattern, const char *p, + reg_syntax_t syntax)); +static boolean at_endline_loc_p _RE_ARGS ((const char *p, const char *pend, + reg_syntax_t syntax)); +static reg_errcode_t compile_range _RE_ARGS ((const char **p_ptr, + const char *pend, + char *translate, + reg_syntax_t syntax, + unsigned char *b)); /* Fetch the next character in the uncompiled pattern---translating it if necessary. Also cast from a signed character in the constant @@ -1495,7 +1508,7 @@ static reg_errcode_t compile_range _RE_ARGS((const char **p_ptr, /* Make sure we have at least N more bytes of space in buffer. */ #define GET_BUFFER_SPACE(n) \ - while (b - bufp->buffer + (n) > bufp->allocated) \ + while ((unsigned long) (b - bufp->buffer + (n)) > bufp->allocated) \ EXTEND_BUFFER () /* Make sure we have one more byte of buffer space and then add C to it. */ @@ -1528,19 +1541,19 @@ static reg_errcode_t compile_range _RE_ARGS((const char **p_ptr, /* Store a jump with opcode OP at LOC to location TO. We store a relative address offset by the three bytes the jump itself occupies. */ #define STORE_JUMP(op, loc, to) \ - store_op1 (op, loc, (int)((to) - (loc) - 3)) + store_op1 (op, loc, (int) ((to) - (loc) - 3)) /* Likewise, for a two-argument jump. */ #define STORE_JUMP2(op, loc, to, arg) \ - store_op2 (op, loc, (int)((to) - (loc) - 3), arg) + store_op2 (op, loc, (int) ((to) - (loc) - 3), arg) /* Like `STORE_JUMP', but for inserting. Assume `b' is the buffer end. */ #define INSERT_JUMP(op, loc, to) \ - insert_op1 (op, loc, (int)((to) - (loc) - 3), b) + insert_op1 (op, loc, (int) ((to) - (loc) - 3), b) /* Like `STORE_JUMP2', but for inserting. Assume `b' is the buffer end. */ #define INSERT_JUMP2(op, loc, to, arg) \ - insert_op2 (op, loc, (int)((to) - (loc) - 3), arg, b) + insert_op2 (op, loc, (int) ((to) - (loc) - 3), arg, b) /* This is not an arbitrary limit: the arguments which represent offsets @@ -1551,15 +1564,15 @@ static reg_errcode_t compile_range _RE_ARGS((const char **p_ptr, MSC and drop MAX_BUF_SIZE a bit. Otherwise you may end up reallocating to 0 bytes. Such thing is not going to work too well. You have been warned!! */ -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(WIN32) /* Microsoft C 16-bit versions limit malloc to approx 65512 bytes. The REALLOC define eliminates a flurry of conversion warnings, but is not required. */ #define MAX_BUF_SIZE 65500L -#define REALLOC(p,s) realloc((p), (size_t) (s)) +#define REALLOC(p,s) realloc ((p), (size_t) (s)) #else #define MAX_BUF_SIZE (1L << 16) -#define REALLOC realloc +#define REALLOC(p,s) realloc ((p), (s)) #endif /* Extend the buffer by twice its current size via realloc and @@ -1574,7 +1587,7 @@ static reg_errcode_t compile_range _RE_ARGS((const char **p_ptr, bufp->allocated <<= 1; \ if (bufp->allocated > MAX_BUF_SIZE) \ bufp->allocated = MAX_BUF_SIZE; \ - bufp->buffer = (unsigned char *) REALLOC(bufp->buffer, bufp->allocated);\ + bufp->buffer = (unsigned char *) REALLOC (bufp->buffer, bufp->allocated);\ if (bufp->buffer == NULL) \ return REG_ESPACE; \ /* If the buffer moved, move all the pointers into it. */ \ @@ -1606,7 +1619,7 @@ typedef unsigned regnum_t; /* Since offsets can go either forwards or backwards, this type needs to be able to hold values from -(MAX_BUF_SIZE - 1) to MAX_BUF_SIZE - 1. */ -/* int may be not enough when sizeof(int) == 2 */ +/* int may be not enough when sizeof(int) == 2. */ typedef long pattern_offset_t; typedef struct @@ -1659,15 +1672,29 @@ typedef struct } \ } -#define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */ +#if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H) +/* The GNU C library provides support for user-defined character classes + and the functions from ISO C amendement 1. */ +# ifdef CHARCLASS_NAME_MAX +# define CHAR_CLASS_MAX_LENGTH CHARCLASS_NAME_MAX +# else +/* This shouldn't happen but some implementation might still have this + problem. Use a reasonable default value. */ +# define CHAR_CLASS_MAX_LENGTH 256 +# endif + +# define IS_CHAR_CLASS(string) wctype (string) +#else +# define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */ -#define IS_CHAR_CLASS(string) \ +# define IS_CHAR_CLASS(string) \ (STREQ (string, "alpha") || STREQ (string, "upper") \ || STREQ (string, "lower") || STREQ (string, "digit") \ || STREQ (string, "alnum") || STREQ (string, "xdigit") \ || STREQ (string, "space") || STREQ (string, "print") \ || STREQ (string, "punct") || STREQ (string, "graph") \ || STREQ (string, "cntrl") || STREQ (string, "blank")) +#endif #ifndef MATCH_MAY_ALLOCATE @@ -1717,9 +1744,9 @@ regex_grow_registers (num_regs) #endif /* not MATCH_MAY_ALLOCATE */ -static boolean group_in_compile_stack _RE_ARGS((compile_stack_type - compile_stack, - regnum_t regnum)); +static boolean group_in_compile_stack _RE_ARGS ((compile_stack_type + compile_stack, + regnum_t regnum)); /* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX. Returns one of error codes defined in `regex.h', or zero for success. @@ -2145,6 +2172,34 @@ regex_compile (pattern, size, syntax, bufp) the leading `:' and `[' (but set bits for them). */ if (c == ':' && *p == ']') { +#if defined _LIBC || (defined HAVE_WCTYPE_H && defined HAVE_WCHAR_H) + boolean is_lower = STREQ (str, "lower"); + boolean is_upper = STREQ (str, "upper"); + wctype_t wt; + int ch; + + wt = wctype (str); + if (wt == 0) + FREE_STACK_RETURN (REG_ECTYPE); + + /* Throw away the ] at the end of the character + class. */ + PATFETCH (c); + + if (p == pend) FREE_STACK_RETURN (REG_EBRACK); + + for (ch = 0; ch < 1 << BYTEWIDTH; ++ch) + { + if (iswctype (btowc (ch), wt)) + SET_LIST_BIT (ch); + + if (translate && (is_upper || is_lower) + && (ISUPPER (ch) || ISLOWER (ch))) + SET_LIST_BIT (ch); + } + + had_char_class = true; +#else int ch; boolean is_alnum = STREQ (str, "alnum"); boolean is_alpha = STREQ (str, "alpha"); @@ -2187,11 +2242,12 @@ regex_compile (pattern, size, syntax, bufp) || (is_upper && ISUPPER (ch)) || (is_xdigit && ISXDIGIT (ch))) SET_LIST_BIT (ch); - if ( translate && (is_upper || is_lower) - && (ISUPPER(ch) || ISLOWER(ch))) + if ( translate && (is_upper || is_lower) + && (ISUPPER (ch) || ISLOWER (ch))) SET_LIST_BIT (ch); } had_char_class = true; +#endif /* libc || wctype.h */ } else { @@ -2616,7 +2672,7 @@ regex_compile (pattern, size, syntax, bufp) case 'w': if (re_syntax_options & RE_NO_GNU_OPS) - goto normal_char; + goto normal_char; laststart = b; BUF_PUSH (wordchar); break; @@ -2624,7 +2680,7 @@ regex_compile (pattern, size, syntax, bufp) case 'W': if (re_syntax_options & RE_NO_GNU_OPS) - goto normal_char; + goto normal_char; laststart = b; BUF_PUSH (notwordchar); break; @@ -2632,37 +2688,37 @@ regex_compile (pattern, size, syntax, bufp) case '<': if (re_syntax_options & RE_NO_GNU_OPS) - goto normal_char; + goto normal_char; BUF_PUSH (wordbeg); break; case '>': if (re_syntax_options & RE_NO_GNU_OPS) - goto normal_char; + goto normal_char; BUF_PUSH (wordend); break; case 'b': if (re_syntax_options & RE_NO_GNU_OPS) - goto normal_char; + goto normal_char; BUF_PUSH (wordbound); break; case 'B': if (re_syntax_options & RE_NO_GNU_OPS) - goto normal_char; + goto normal_char; BUF_PUSH (notwordbound); break; case '`': if (re_syntax_options & RE_NO_GNU_OPS) - goto normal_char; + goto normal_char; BUF_PUSH (begbuf); break; case '\'': if (re_syntax_options & RE_NO_GNU_OPS) - goto normal_char; + goto normal_char; BUF_PUSH (endbuf); break; @@ -2677,7 +2733,7 @@ regex_compile (pattern, size, syntax, bufp) FREE_STACK_RETURN (REG_ESUBREG); /* Can't back reference to a subexpression if inside of it. */ - if (group_in_compile_stack (compile_stack, (regnum_t)c1)) + if (group_in_compile_stack (compile_stack, (regnum_t) c1)) goto normal_char; laststart = b; @@ -2961,7 +3017,7 @@ compile_range (p_ptr, pend, translate, syntax, b) unsigned this_char; const char *p = *p_ptr; - int range_start, range_end; + unsigned int range_start, range_end; if (p == pend) return REG_ERANGE; @@ -3611,17 +3667,17 @@ re_match (bufp, string, size, pos, regs) } #endif /* not emacs */ -static boolean group_match_null_string_p _RE_ARGS((unsigned char **p, - unsigned char *end, - register_info_type *reg_info)); -static boolean alt_match_null_string_p _RE_ARGS((unsigned char *p, - unsigned char *end, - register_info_type *reg_info)); -static boolean common_op_match_null_string_p _RE_ARGS((unsigned char **p, - unsigned char *end, +static boolean group_match_null_string_p _RE_ARGS ((unsigned char **p, + unsigned char *end, + register_info_type *reg_info)); +static boolean alt_match_null_string_p _RE_ARGS ((unsigned char *p, + unsigned char *end, + register_info_type *reg_info)); +static boolean common_op_match_null_string_p _RE_ARGS ((unsigned char **p, + unsigned char *end, register_info_type *reg_info)); -static int bcmp_translate _RE_ARGS((const char *s1, const char *s2, - int len, char *translate)); +static int bcmp_translate _RE_ARGS ((const char *s1, const char *s2, + int len, char *translate)); /* re_match_2 matches the compiled pattern in BUFP against the the (virtual) concatenation of STRING1 and STRING2 (of length SIZE1 @@ -3835,7 +3891,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) /* Initialize subexpression text positions to -1 to mark ones that no start_memory/stop_memory has been seen for. Also initialize the register information struct. */ - for (mcnt = 1; mcnt < num_regs; mcnt++) + for (mcnt = 1; (unsigned) mcnt < num_regs; mcnt++) { regstart[mcnt] = regend[mcnt] = old_regstart[mcnt] = old_regend[mcnt] = REG_UNSET_VALUE; @@ -3887,7 +3943,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) dend = end_match_2; } - DEBUG_PRINT1 ("The compiled pattern is: "); + DEBUG_PRINT1 ("The compiled pattern is:\n"); DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend); DEBUG_PRINT1 ("The string to match is: `"); DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2); @@ -3898,7 +3954,11 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) fails at this starting point in the input data. */ for (;;) { +#ifdef _LIBC + DEBUG_PRINT2 ("\n%p: ", p); +#else DEBUG_PRINT2 ("\n0x%x: ", p); +#endif if (p == pend) { /* End of pattern means we might have succeeded. */ @@ -3935,7 +3995,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) DEBUG_PRINT1 ("\nSAVING match as best so far.\n"); - for (mcnt = 1; mcnt < num_regs; mcnt++) + for (mcnt = 1; (unsigned) mcnt < num_regs; mcnt++) { best_regstart[mcnt] = regstart[mcnt]; best_regend[mcnt] = regend[mcnt]; @@ -3961,7 +4021,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) dend = ((d >= string1 && d <= end1) ? end_match_1 : end_match_2); - for (mcnt = 1; mcnt < num_regs; mcnt++) + for (mcnt = 1; (unsigned) mcnt < num_regs; mcnt++) { regstart[mcnt] = best_regstart[mcnt]; regend[mcnt] = best_regend[mcnt]; @@ -4026,7 +4086,8 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) /* Go through the first `min (num_regs, regs->num_regs)' registers, since that is all we initialized. */ - for (mcnt = 1; mcnt < MIN (num_regs, regs->num_regs); mcnt++) + for (mcnt = 1; (unsigned) mcnt < MIN (num_regs, regs->num_regs); + mcnt++) { if (REG_UNSET (regstart[mcnt]) || REG_UNSET (regend[mcnt])) regs->start[mcnt] = regs->end[mcnt] = -1; @@ -4044,7 +4105,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) we (re)allocated the registers, this is the case, because we always allocate enough to have at least one -1 at the end. */ - for (mcnt = num_regs; mcnt < regs->num_regs; mcnt++) + for (mcnt = num_regs; (unsigned) mcnt < regs->num_regs; mcnt++) regs->start[mcnt] = regs->end[mcnt] = -1; } /* regs && !bufp->no_sub */ @@ -4316,7 +4377,8 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) EVER_MATCHED_SOMETHING (reg_info[*p]) = 0; /* Restore this and inner groups' (if any) registers. */ - for (r = *p; r < *p + *(p + 1); r++) + for (r = *p; r < (unsigned) *p + (unsigned) *(p + 1); + r++) { regstart[r] = old_regstart[r]; @@ -4475,7 +4537,11 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) DEBUG_PRINT1 ("EXECUTING on_failure_keep_string_jump"); EXTRACT_NUMBER_AND_INCR (mcnt, p); +#ifdef _LIBC + DEBUG_PRINT3 (" %d (to %p):\n", mcnt, p + mcnt); +#else DEBUG_PRINT3 (" %d (to 0x%x):\n", mcnt, p + mcnt); +#endif PUSH_FAILURE_POINT (p + mcnt, NULL, -2); break; @@ -4498,7 +4564,11 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) DEBUG_PRINT1 ("EXECUTING on_failure_jump"); EXTRACT_NUMBER_AND_INCR (mcnt, p); +#ifdef _LIBC + DEBUG_PRINT3 (" %d (to %p)", mcnt, p + mcnt); +#else DEBUG_PRINT3 (" %d (to 0x%x)", mcnt, p + mcnt); +#endif /* If this on_failure_jump comes right before a group (i.e., the original * applied to a group), save the information @@ -4626,10 +4696,17 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) = *p2 == (unsigned char) endline ? '\n' : p2[2]; #endif +#if 0 if ((re_opcode_t) p1[3] == exactn && ! ((int) p2[1] * BYTEWIDTH > (int) p1[5] && (p2[2 + p1[5] / BYTEWIDTH] & (1 << (p1[5] % BYTEWIDTH))))) +#else + if ((re_opcode_t) p1[3] == exactn + && ! ((int) p2[1] * BYTEWIDTH > (int) p1[4] + && (p2[2 + p1[4] / BYTEWIDTH] + & (1 << (p1[4] % BYTEWIDTH))))) +#endif { p[-3] = (unsigned char) pop_failure_jump; DEBUG_PRINT3 (" %c != %c => pop_failure_jump.\n", @@ -4704,16 +4781,26 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) dummy_low_reg, dummy_high_reg, reg_dummy, reg_dummy, reg_info_dummy); } - /* Note fall through. */ + /* Note fall through. */ + unconditional_jump: +#ifdef _LIBC + DEBUG_PRINT2 ("\n%p: ", p); +#else + DEBUG_PRINT2 ("\n0x%x: ", p); +#endif + /* Note fall through. */ /* Unconditionally jump (without popping any failure points). */ case jump: - unconditional_jump: EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */ DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt); p += mcnt; /* Do the jump. */ +#ifdef _LIBC + DEBUG_PRINT2 ("(to %p).\n", p); +#else DEBUG_PRINT2 ("(to 0x%x).\n", p); +#endif break; @@ -4762,11 +4849,19 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) mcnt--; p += 2; STORE_NUMBER_AND_INCR (p, mcnt); - DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p, mcnt); +#ifdef _LIBC + DEBUG_PRINT3 (" Setting %p to %d.\n", p - 2, mcnt); +#else + DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p - 2, mcnt); +#endif } else if (mcnt == 0) { +#ifdef _LIBC + DEBUG_PRINT2 (" Setting two bytes from %p to no_op.\n", p+2); +#else DEBUG_PRINT2 (" Setting two bytes from 0x%x to no_op.\n", p+2); +#endif p[2] = (unsigned char) no_op; p[3] = (unsigned char) no_op; goto on_failure; @@ -4782,6 +4877,11 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) { mcnt--; STORE_NUMBER (p + 2, mcnt); +#ifdef _LIBC + DEBUG_PRINT3 (" Setting %p to %d.\n", p + 2, mcnt); +#else + DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p + 2, mcnt); +#endif goto unconditional_jump; } /* If don't have to jump any more, skip over the rest of command. */ @@ -4796,7 +4896,11 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) EXTRACT_NUMBER_AND_INCR (mcnt, p); p1 = p + mcnt; EXTRACT_NUMBER_AND_INCR (mcnt, p); +#ifdef _LIBC + DEBUG_PRINT3 (" Setting %p to %d.\n", p1, mcnt); +#else DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p1, mcnt); +#endif STORE_NUMBER (p1, mcnt); break; } @@ -5252,8 +5356,8 @@ bcmp_translate (s1, s2, len, translate) register int len; RE_TRANSLATE_TYPE translate; { - register const unsigned char *p1 = (const unsigned char *) s1, - *p2 = (const unsigned char *) s2; + register const unsigned char *p1 = (const unsigned char *) s1; + register const unsigned char *p2 = (const unsigned char *) s2; while (len) { if (translate[*p1++] != translate[*p2++]) return 1; @@ -5366,6 +5470,7 @@ re_exec (s) return 0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0); } + #endif /* _REGEX_RE_COMP */ /* POSIX.2 functions. Don't define these for Emacs. */ @@ -5560,7 +5665,8 @@ regerror (errcode, preg, errbuf, errbuf_size) size_t msg_size; if (errcode < 0 - || errcode >= (sizeof (re_error_msgid) / sizeof (re_error_msgid[0]))) + || errcode >= (int) (sizeof (re_error_msgid) + / sizeof (re_error_msgid[0]))) /* Only error codes returned by the rest of the code should be passed to this routine. If we are given anything else, or if other regex code generates an invalid error code, then the program has a bug. |