comparison src/regex.c @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 8de8e3f6228a
children 576fb035e263
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
159 { 159 {
160 static int done = 0; 160 static int done = 0;
161 161
162 if (!done) 162 if (!done)
163 { 163 {
164 CONST char *word_syntax_chars = 164 const char *word_syntax_chars =
165 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"; 165 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
166 166
167 memset (re_syntax_table, 0, sizeof (re_syntax_table)); 167 memset (re_syntax_table, 0, sizeof (re_syntax_table));
168 168
169 while (*word_syntax_chars) 169 while (*word_syntax_chars)
963 /* and maybe the category table? */ 963 /* and maybe the category table? */
964 } 964 }
965 965
966 966
967 static void 967 static void
968 print_double_string (CONST char *where, CONST char *string1, int size1, 968 print_double_string (const char *where, const char *string1, int size1,
969 CONST char *string2, int size2) 969 const char *string2, int size2)
970 { 970 {
971 if (where == NULL) 971 if (where == NULL)
972 printf ("(null)"); 972 printf ("(null)");
973 else 973 else
974 { 974 {
1029 /* This table gives an error message for each of the error codes listed 1029 /* This table gives an error message for each of the error codes listed
1030 in regex.h. Obviously the order here has to be same as there. 1030 in regex.h. Obviously the order here has to be same as there.
1031 POSIX doesn't require that we do anything for REG_NOERROR, 1031 POSIX doesn't require that we do anything for REG_NOERROR,
1032 but why not be nice? */ 1032 but why not be nice? */
1033 1033
1034 static CONST char *re_error_msgid[] = 1034 static const char *re_error_msgid[] =
1035 { 1035 {
1036 "Success", /* REG_NOERROR */ 1036 "Success", /* REG_NOERROR */
1037 "No match", /* REG_NOMATCH */ 1037 "No match", /* REG_NOMATCH */
1038 "Invalid regular expression", /* REG_BADPAT */ 1038 "Invalid regular expression", /* REG_BADPAT */
1039 "Invalid collation character", /* REG_ECOLLATE */ 1039 "Invalid collation character", /* REG_ECOLLATE */
1363 1363
1364 #define POP_FAILURE_POINT(str, pat, low_reg, high_reg, regstart, regend, reg_info)\ 1364 #define POP_FAILURE_POINT(str, pat, low_reg, high_reg, regstart, regend, reg_info)\
1365 { \ 1365 { \
1366 DEBUG_STATEMENT (fail_stack_elt_t ffailure_id;) \ 1366 DEBUG_STATEMENT (fail_stack_elt_t ffailure_id;) \
1367 int this_reg; \ 1367 int this_reg; \
1368 CONST unsigned char *string_temp; \ 1368 const unsigned char *string_temp; \
1369 \ 1369 \
1370 assert (!FAIL_STACK_EMPTY ()); \ 1370 assert (!FAIL_STACK_EMPTY ()); \
1371 \ 1371 \
1372 /* Remove failure points and point to how many regs pushed. */ \ 1372 /* Remove failure points and point to how many regs pushed. */ \
1373 DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \ 1373 DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \
1383 /* If the saved string location is NULL, it came from an \ 1383 /* If the saved string location is NULL, it came from an \
1384 on_failure_keep_string_jump opcode, and we want to throw away the \ 1384 on_failure_keep_string_jump opcode, and we want to throw away the \
1385 saved NULL, thus retaining our current position in the string. */ \ 1385 saved NULL, thus retaining our current position in the string. */ \
1386 string_temp = POP_FAILURE_POINTER (); \ 1386 string_temp = POP_FAILURE_POINTER (); \
1387 if (string_temp != NULL) \ 1387 if (string_temp != NULL) \
1388 str = (CONST char *) string_temp; \ 1388 str = (const char *) string_temp; \
1389 \ 1389 \
1390 DEBUG_PRINT2 (" Popping string 0x%lx: `", (long) str); \ 1390 DEBUG_PRINT2 (" Popping string 0x%lx: `", (long) str); \
1391 DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \ 1391 DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \
1392 DEBUG_PRINT1 ("'\n"); \ 1392 DEBUG_PRINT1 ("'\n"); \
1393 \ 1393 \
1408 \ 1408 \
1409 reg_info[this_reg].word = POP_FAILURE_ELT (); \ 1409 reg_info[this_reg].word = POP_FAILURE_ELT (); \
1410 DEBUG_PRINT2 (" info: 0x%lx\n", \ 1410 DEBUG_PRINT2 (" info: 0x%lx\n", \
1411 * (long *) &reg_info[this_reg]); \ 1411 * (long *) &reg_info[this_reg]); \
1412 \ 1412 \
1413 regend[this_reg] = (CONST char *) POP_FAILURE_POINTER (); \ 1413 regend[this_reg] = (const char *) POP_FAILURE_POINTER (); \
1414 DEBUG_PRINT2 (" end: 0x%lx\n", (long) regend[this_reg]); \ 1414 DEBUG_PRINT2 (" end: 0x%lx\n", (long) regend[this_reg]); \
1415 \ 1415 \
1416 regstart[this_reg] = (CONST char *) POP_FAILURE_POINTER (); \ 1416 regstart[this_reg] = (const char *) POP_FAILURE_POINTER (); \
1417 DEBUG_PRINT2 (" start: 0x%lx\n", (long) regstart[this_reg]); \ 1417 DEBUG_PRINT2 (" start: 0x%lx\n", (long) regstart[this_reg]); \
1418 } \ 1418 } \
1419 \ 1419 \
1420 set_regs_matched_done = 0; \ 1420 set_regs_matched_done = 0; \
1421 DEBUG_STATEMENT (nfailure_points_popped++); \ 1421 DEBUG_STATEMENT (nfailure_points_popped++); \
1507 #ifdef MULE 1507 #ifdef MULE
1508 1508
1509 #define PATFETCH_EXTENDED(emch) \ 1509 #define PATFETCH_EXTENDED(emch) \
1510 do {if (p == pend) return REG_EEND; \ 1510 do {if (p == pend) return REG_EEND; \
1511 assert (p < pend); \ 1511 assert (p < pend); \
1512 emch = charptr_emchar ((CONST Bufbyte *) p); \ 1512 emch = charptr_emchar ((const Bufbyte *) p); \
1513 INC_CHARPTR (p); \ 1513 INC_CHARPTR (p); \
1514 if (translate && emch < 0x80) \ 1514 if (translate && emch < 0x80) \
1515 emch = (Emchar) (unsigned char) translate[emch]; \ 1515 emch = (Emchar) (unsigned char) translate[emch]; \
1516 } while (0) 1516 } while (0)
1517 1517
1518 #define PATFETCH_RAW_EXTENDED(emch) \ 1518 #define PATFETCH_RAW_EXTENDED(emch) \
1519 do {if (p == pend) return REG_EEND; \ 1519 do {if (p == pend) return REG_EEND; \
1520 assert (p < pend); \ 1520 assert (p < pend); \
1521 emch = charptr_emchar ((CONST Bufbyte *) p); \ 1521 emch = charptr_emchar ((const Bufbyte *) p); \
1522 INC_CHARPTR (p); \ 1522 INC_CHARPTR (p); \
1523 } while (0) 1523 } while (0)
1524 1524
1525 #define PATUNFETCH_EXTENDED DEC_CHARPTR (p) 1525 #define PATUNFETCH_EXTENDED DEC_CHARPTR (p)
1526 1526
1760 static void store_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2); 1760 static void store_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2);
1761 static void insert_op1 (re_opcode_t op, unsigned char *loc, int arg, 1761 static void insert_op1 (re_opcode_t op, unsigned char *loc, int arg,
1762 unsigned char *end); 1762 unsigned char *end);
1763 static void insert_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2, 1763 static void insert_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2,
1764 unsigned char *end); 1764 unsigned char *end);
1765 static boolean at_begline_loc_p (CONST char *pattern, CONST char *p, 1765 static boolean at_begline_loc_p (const char *pattern, const char *p,
1766 reg_syntax_t syntax); 1766 reg_syntax_t syntax);
1767 static boolean at_endline_loc_p (CONST char *p, CONST char *pend, int syntax); 1767 static boolean at_endline_loc_p (const char *p, const char *pend, int syntax);
1768 static boolean group_in_compile_stack (compile_stack_type compile_stack, 1768 static boolean group_in_compile_stack (compile_stack_type compile_stack,
1769 regnum_t regnum); 1769 regnum_t regnum);
1770 static reg_errcode_t compile_range (CONST char **p_ptr, CONST char *pend, 1770 static reg_errcode_t compile_range (const char **p_ptr, const char *pend,
1771 char *translate, reg_syntax_t syntax, 1771 char *translate, reg_syntax_t syntax,
1772 unsigned char *b); 1772 unsigned char *b);
1773 #ifdef MULE 1773 #ifdef MULE
1774 static reg_errcode_t compile_extended_range (CONST char **p_ptr, 1774 static reg_errcode_t compile_extended_range (const char **p_ptr,
1775 CONST char *pend, 1775 const char *pend,
1776 char *translate, 1776 char *translate,
1777 reg_syntax_t syntax, 1777 reg_syntax_t syntax,
1778 Lisp_Object rtab); 1778 Lisp_Object rtab);
1779 #endif /* MULE */ 1779 #endif /* MULE */
1780 static boolean group_match_null_string_p (unsigned char **p, 1780 static boolean group_match_null_string_p (unsigned char **p,
1783 static boolean alt_match_null_string_p (unsigned char *p, unsigned char *end, 1783 static boolean alt_match_null_string_p (unsigned char *p, unsigned char *end,
1784 register_info_type *reg_info); 1784 register_info_type *reg_info);
1785 static boolean common_op_match_null_string_p (unsigned char **p, 1785 static boolean common_op_match_null_string_p (unsigned char **p,
1786 unsigned char *end, 1786 unsigned char *end,
1787 register_info_type *reg_info); 1787 register_info_type *reg_info);
1788 static int bcmp_translate (CONST unsigned char *s1, CONST unsigned char *s2, 1788 static int bcmp_translate (const unsigned char *s1, const unsigned char *s2,
1789 REGISTER int len, char *translate); 1789 REGISTER int len, char *translate);
1790 static int re_match_2_internal (struct re_pattern_buffer *bufp, 1790 static int re_match_2_internal (struct re_pattern_buffer *bufp,
1791 CONST char *string1, int size1, 1791 const char *string1, int size1,
1792 CONST char *string2, int size2, int pos, 1792 const char *string2, int size2, int pos,
1793 struct re_registers *regs, int stop); 1793 struct re_registers *regs, int stop);
1794 1794
1795 #ifndef MATCH_MAY_ALLOCATE 1795 #ifndef MATCH_MAY_ALLOCATE
1796 1796
1797 /* If we cannot allocate large objects within re_match_2_internal, 1797 /* If we cannot allocate large objects within re_match_2_internal,
1806 /* Size with which the following vectors are currently allocated. 1806 /* Size with which the following vectors are currently allocated.
1807 That is so we can make them bigger as needed, 1807 That is so we can make them bigger as needed,
1808 but never make them smaller. */ 1808 but never make them smaller. */
1809 static int regs_allocated_size; 1809 static int regs_allocated_size;
1810 1810
1811 static CONST char ** regstart, ** regend; 1811 static const char ** regstart, ** regend;
1812 static CONST char ** old_regstart, ** old_regend; 1812 static const char ** old_regstart, ** old_regend;
1813 static CONST char **best_regstart, **best_regend; 1813 static const char **best_regstart, **best_regend;
1814 static register_info_type *reg_info; 1814 static register_info_type *reg_info;
1815 static CONST char **reg_dummy; 1815 static const char **reg_dummy;
1816 static register_info_type *reg_info_dummy; 1816 static register_info_type *reg_info_dummy;
1817 1817
1818 /* Make the register vectors big enough for NUM_REGS registers, 1818 /* Make the register vectors big enough for NUM_REGS registers,
1819 but don't make them smaller. */ 1819 but don't make them smaller. */
1820 1820
1821 static 1821 static
1822 regex_grow_registers (int num_regs) 1822 regex_grow_registers (int num_regs)
1823 { 1823 {
1824 if (num_regs > regs_allocated_size) 1824 if (num_regs > regs_allocated_size)
1825 { 1825 {
1826 RETALLOC_IF (regstart, num_regs, CONST char *); 1826 RETALLOC_IF (regstart, num_regs, const char *);
1827 RETALLOC_IF (regend, num_regs, CONST char *); 1827 RETALLOC_IF (regend, num_regs, const char *);
1828 RETALLOC_IF (old_regstart, num_regs, CONST char *); 1828 RETALLOC_IF (old_regstart, num_regs, const char *);
1829 RETALLOC_IF (old_regend, num_regs, CONST char *); 1829 RETALLOC_IF (old_regend, num_regs, const char *);
1830 RETALLOC_IF (best_regstart, num_regs, CONST char *); 1830 RETALLOC_IF (best_regstart, num_regs, const char *);
1831 RETALLOC_IF (best_regend, num_regs, CONST char *); 1831 RETALLOC_IF (best_regend, num_regs, const char *);
1832 RETALLOC_IF (reg_info, num_regs, register_info_type); 1832 RETALLOC_IF (reg_info, num_regs, register_info_type);
1833 RETALLOC_IF (reg_dummy, num_regs, CONST char *); 1833 RETALLOC_IF (reg_dummy, num_regs, const char *);
1834 RETALLOC_IF (reg_info_dummy, num_regs, register_info_type); 1834 RETALLOC_IF (reg_info_dummy, num_regs, register_info_type);
1835 1835
1836 regs_allocated_size = num_regs; 1836 regs_allocated_size = num_regs;
1837 } 1837 }
1838 } 1838 }
1860 /* Return, freeing storage we allocated. */ 1860 /* Return, freeing storage we allocated. */
1861 #define FREE_STACK_RETURN(value) \ 1861 #define FREE_STACK_RETURN(value) \
1862 return (free (compile_stack.stack), value) 1862 return (free (compile_stack.stack), value)
1863 1863
1864 static reg_errcode_t 1864 static reg_errcode_t
1865 regex_compile (CONST char *pattern, int size, reg_syntax_t syntax, 1865 regex_compile (const char *pattern, int size, reg_syntax_t syntax,
1866 struct re_pattern_buffer *bufp) 1866 struct re_pattern_buffer *bufp)
1867 { 1867 {
1868 /* We fetch characters from PATTERN here. We declare these as int 1868 /* We fetch characters from PATTERN here. We declare these as int
1869 (or possibly long) so that chars above 127 can be used as 1869 (or possibly long) so that chars above 127 can be used as
1870 array indices. The macros that fetch a character from the pattern 1870 array indices. The macros that fetch a character from the pattern
1872 get bitten by negative numbers here. */ 1872 get bitten by negative numbers here. */
1873 /* XEmacs change: used to be unsigned char. */ 1873 /* XEmacs change: used to be unsigned char. */
1874 REGISTER EMACS_INT c, c1; 1874 REGISTER EMACS_INT c, c1;
1875 1875
1876 /* A random temporary spot in PATTERN. */ 1876 /* A random temporary spot in PATTERN. */
1877 CONST char *p1; 1877 const char *p1;
1878 1878
1879 /* Points to the end of the buffer, where we should append. */ 1879 /* Points to the end of the buffer, where we should append. */
1880 REGISTER unsigned char *b; 1880 REGISTER unsigned char *b;
1881 1881
1882 /* Keeps track of unclosed groups. */ 1882 /* Keeps track of unclosed groups. */
1883 compile_stack_type compile_stack; 1883 compile_stack_type compile_stack;
1884 1884
1885 /* Points to the current (ending) position in the pattern. */ 1885 /* Points to the current (ending) position in the pattern. */
1886 CONST char *p = pattern; 1886 const char *p = pattern;
1887 CONST char *pend = pattern + size; 1887 const char *pend = pattern + size;
1888 1888
1889 /* How to translate the characters in the pattern. */ 1889 /* How to translate the characters in the pattern. */
1890 char *translate = bufp->translate; 1890 char *translate = bufp->translate;
1891 1891
1892 /* Address of the count-byte of the most recently inserted `exactn' 1892 /* Address of the count-byte of the most recently inserted `exactn'
1903 /* Address of beginning of regexp, or inside of last group. */ 1903 /* Address of beginning of regexp, or inside of last group. */
1904 unsigned char *begalt; 1904 unsigned char *begalt;
1905 1905
1906 /* Place in the uncompiled pattern (i.e., the {) to 1906 /* Place in the uncompiled pattern (i.e., the {) to
1907 which to go back if the interval is invalid. */ 1907 which to go back if the interval is invalid. */
1908 CONST char *beg_interval; 1908 const char *beg_interval;
1909 1909
1910 /* Address of the place where a forward jump should go to the end of 1910 /* Address of the place where a forward jump should go to the end of
1911 the containing expression. Each alternative of an `or' -- except the 1911 the containing expression. Each alternative of an `or' -- except the
1912 last -- ends with a forward jump of this sort. */ 1912 last -- ends with a forward jump of this sort. */
1913 unsigned char *fixup_alt_jump = 0; 1913 unsigned char *fixup_alt_jump = 0;
2386 are working. */ 2386 are working. */
2387 PATFETCH (c); 2387 PATFETCH (c);
2388 if (c == ':' || c == ']' || p == pend 2388 if (c == ':' || c == ']' || p == pend
2389 || c1 == CHAR_CLASS_MAX_LENGTH) 2389 || c1 == CHAR_CLASS_MAX_LENGTH)
2390 break; 2390 break;
2391 str[c1++] = c; 2391 str[c1++] = (char) c;
2392 } 2392 }
2393 str[c1] = '\0'; 2393 str[c1] = '\0';
2394 2394
2395 /* If isn't a word bracketed by `[:' and:`]': 2395 /* If isn't a word bracketed by `[:' and:`]':
2396 undo the ending character, the letters, and leave 2396 undo the ending character, the letters, and leave
3006 /* `p' points to the location after where `c' came from. */ 3006 /* `p' points to the location after where `c' came from. */
3007 normal_char: 3007 normal_char:
3008 { 3008 {
3009 /* XEmacs: modifications here for Mule. */ 3009 /* XEmacs: modifications here for Mule. */
3010 /* `q' points to the beginning of the next char. */ 3010 /* `q' points to the beginning of the next char. */
3011 CONST char *q = p - 1; 3011 const char *q = p - 1;
3012 INC_CHARPTR (q); 3012 INC_CHARPTR (q);
3013 3013
3014 /* If no exactn currently being built. */ 3014 /* If no exactn currently being built. */
3015 if (!pending_exact 3015 if (!pending_exact
3016 3016
3182 /* P points to just after a ^ in PATTERN. Return true if that ^ comes 3182 /* P points to just after a ^ in PATTERN. Return true if that ^ comes
3183 after an alternative or a begin-subexpression. We assume there is at 3183 after an alternative or a begin-subexpression. We assume there is at
3184 least one character before the ^. */ 3184 least one character before the ^. */
3185 3185
3186 static boolean 3186 static boolean
3187 at_begline_loc_p (CONST char *pattern, CONST char *p, reg_syntax_t syntax) 3187 at_begline_loc_p (const char *pattern, const char *p, reg_syntax_t syntax)
3188 { 3188 {
3189 CONST char *prev = p - 2; 3189 const char *prev = p - 2;
3190 boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\'; 3190 boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\';
3191 3191
3192 return 3192 return
3193 /* After a subexpression? */ 3193 /* After a subexpression? */
3194 (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash)) 3194 (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash))
3199 3199
3200 /* The dual of at_begline_loc_p. This one is for $. We assume there is 3200 /* The dual of at_begline_loc_p. This one is for $. We assume there is
3201 at least one character after the $, i.e., `P < PEND'. */ 3201 at least one character after the $, i.e., `P < PEND'. */
3202 3202
3203 static boolean 3203 static boolean
3204 at_endline_loc_p (CONST char *p, CONST char *pend, int syntax) 3204 at_endline_loc_p (const char *p, const char *pend, int syntax)
3205 { 3205 {
3206 CONST char *next = p; 3206 const char *next = p;
3207 boolean next_backslash = *next == '\\'; 3207 boolean next_backslash = *next == '\\';
3208 CONST char *next_next = p + 1 < pend ? p + 1 : 0; 3208 const char *next_next = p + 1 < pend ? p + 1 : 0;
3209 3209
3210 return 3210 return
3211 /* Before a subexpression? */ 3211 /* Before a subexpression? */
3212 (syntax & RE_NO_BK_PARENS ? *next == ')' 3212 (syntax & RE_NO_BK_PARENS ? *next == ')'
3213 : next_backslash && next_next && *next_next == ')') 3213 : next_backslash && next_next && *next_next == ')')
3245 3245
3246 We use these short variable names so we can use the same macros as 3246 We use these short variable names so we can use the same macros as
3247 `regex_compile' itself. */ 3247 `regex_compile' itself. */
3248 3248
3249 static reg_errcode_t 3249 static reg_errcode_t
3250 compile_range (CONST char **p_ptr, CONST char *pend, char *translate, 3250 compile_range (const char **p_ptr, const char *pend, char *translate,
3251 reg_syntax_t syntax, unsigned char *b) 3251 reg_syntax_t syntax, unsigned char *b)
3252 { 3252 {
3253 unsigned this_char; 3253 unsigned this_char;
3254 3254
3255 CONST char *p = *p_ptr; 3255 const char *p = *p_ptr;
3256 int range_start, range_end; 3256 int range_start, range_end;
3257 3257
3258 if (p == pend) 3258 if (p == pend)
3259 return REG_ERANGE; 3259 return REG_ERANGE;
3260 3260
3263 is set, the range endpoints will be negative if we fetch using a 3263 is set, the range endpoints will be negative if we fetch using a
3264 signed char *. 3264 signed char *.
3265 3265
3266 We also want to fetch the endpoints without translating them; the 3266 We also want to fetch the endpoints without translating them; the
3267 appropriate translation is done in the bit-setting loop below. */ 3267 appropriate translation is done in the bit-setting loop below. */
3268 /* The SVR4 compiler on the 3B2 had trouble with unsigned CONST char *. */ 3268 /* The SVR4 compiler on the 3B2 had trouble with unsigned const char *. */
3269 range_start = ((CONST unsigned char *) p)[-2]; 3269 range_start = ((const unsigned char *) p)[-2];
3270 range_end = ((CONST unsigned char *) p)[0]; 3270 range_end = ((const unsigned char *) p)[0];
3271 3271
3272 /* Have to increment the pointer into the pattern string, so the 3272 /* Have to increment the pointer into the pattern string, so the
3273 caller isn't still at the ending character. */ 3273 caller isn't still at the ending character. */
3274 (*p_ptr)++; 3274 (*p_ptr)++;
3275 3275
3290 } 3290 }
3291 3291
3292 #ifdef MULE 3292 #ifdef MULE
3293 3293
3294 static reg_errcode_t 3294 static reg_errcode_t
3295 compile_extended_range (CONST char **p_ptr, CONST char *pend, char *translate, 3295 compile_extended_range (const char **p_ptr, const char *pend, char *translate,
3296 reg_syntax_t syntax, Lisp_Object rtab) 3296 reg_syntax_t syntax, Lisp_Object rtab)
3297 { 3297 {
3298 Emchar this_char, range_start, range_end; 3298 Emchar this_char, range_start, range_end;
3299 CONST Bufbyte *p; 3299 const Bufbyte *p;
3300 3300
3301 if (*p_ptr == pend) 3301 if (*p_ptr == pend)
3302 return REG_ERANGE; 3302 return REG_ERANGE;
3303 3303
3304 p = (CONST Bufbyte *) *p_ptr; 3304 p = (const Bufbyte *) *p_ptr;
3305 range_end = charptr_emchar (p); 3305 range_end = charptr_emchar (p);
3306 p--; /* back to '-' */ 3306 p--; /* back to '-' */
3307 DEC_CHARPTR (p); /* back to start of range */ 3307 DEC_CHARPTR (p); /* back to start of range */
3308 /* We also want to fetch the endpoints without translating them; the 3308 /* We also want to fetch the endpoints without translating them; the
3309 appropriate translation is done in the bit-setting loop below. */ 3309 appropriate translation is done in the bit-setting loop below. */
3856 3856
3857 /* Like re_search_2, below, but only one string is specified, and 3857 /* Like re_search_2, below, but only one string is specified, and
3858 doesn't let you say where to stop matching. */ 3858 doesn't let you say where to stop matching. */
3859 3859
3860 int 3860 int
3861 re_search (struct re_pattern_buffer *bufp, CONST char *string, int size, 3861 re_search (struct re_pattern_buffer *bufp, const char *string, int size,
3862 int startpos, int range, struct re_registers *regs) 3862 int startpos, int range, struct re_registers *regs)
3863 { 3863 {
3864 return re_search_2 (bufp, NULL, 0, string, size, startpos, range, 3864 return re_search_2 (bufp, NULL, 0, string, size, startpos, range,
3865 regs, size); 3865 regs, size);
3866 } 3866 }
3899 We return either the position in the strings at which the match was 3899 We return either the position in the strings at which the match was
3900 found, -1 if no match, or -2 if error (such as failure 3900 found, -1 if no match, or -2 if error (such as failure
3901 stack overflow). */ 3901 stack overflow). */
3902 3902
3903 int 3903 int
3904 re_search_2 (struct re_pattern_buffer *bufp, CONST char *string1, 3904 re_search_2 (struct re_pattern_buffer *bufp, const char *string1,
3905 int size1, CONST char *string2, int size2, int startpos, 3905 int size1, const char *string2, int size2, int startpos,
3906 int range, struct re_registers *regs, int stop) 3906 int range, struct re_registers *regs, int stop)
3907 { 3907 {
3908 int val; 3908 int val;
3909 REGISTER char *fastmap = bufp->fastmap; 3909 REGISTER char *fastmap = bufp->fastmap;
3910 REGISTER char *translate = bufp->translate; 3910 REGISTER char *translate = bufp->translate;
3911 int total_size = size1 + size2; 3911 int total_size = size1 + size2;
3912 int endpos = startpos + range; 3912 int endpos = startpos + range;
3913 #ifdef REGEX_BEGLINE_CHECK 3913 #ifdef REGEX_BEGLINE_CHECK
3914 int anchored_at_begline = 0; 3914 int anchored_at_begline = 0;
3915 #endif 3915 #endif
3916 CONST unsigned char *d; 3916 const unsigned char *d;
3917 Charcount d_size; 3917 Charcount d_size;
3918 3918
3919 /* Check for out-of-range STARTPOS. */ 3919 /* Check for out-of-range STARTPOS. */
3920 if (startpos < 0 || startpos > total_size) 3920 if (startpos < 0 || startpos > total_size)
3921 return -1; 3921 return -1;
3933 { 3933 {
3934 if (startpos > 0) 3934 if (startpos > 0)
3935 return -1; 3935 return -1;
3936 else 3936 else
3937 { 3937 {
3938 d = ((CONST unsigned char *) 3938 d = ((const unsigned char *)
3939 (startpos >= size1 ? string2 - size1 : string1) + startpos); 3939 (startpos >= size1 ? string2 - size1 : string1) + startpos);
3940 range = charcount_to_bytecount (d, 1); 3940 range = charcount_to_bytecount (d, 1);
3941 } 3941 }
3942 } 3942 }
3943 3943
3978 int irange = range; 3978 int irange = range;
3979 3979
3980 if (startpos < size1 && startpos + range >= size1) 3980 if (startpos < size1 && startpos + range >= size1)
3981 lim = range - (size1 - startpos); 3981 lim = range - (size1 - startpos);
3982 3982
3983 d = ((CONST unsigned char *) 3983 d = ((const unsigned char *)
3984 (startpos >= size1 ? string2 - size1 : string1) + startpos); 3984 (startpos >= size1 ? string2 - size1 : string1) + startpos);
3985 DEC_CHARPTR(d); /* Ok, since startpos != size1. */ 3985 DEC_CHARPTR(d); /* Ok, since startpos != size1. */
3986 d_size = charcount_to_bytecount (d, 1); 3986 d_size = charcount_to_bytecount (d, 1);
3987 3987
3988 if (translate) 3988 if (translate)
4020 int irange = range; 4020 int irange = range;
4021 4021
4022 if (startpos < size1 && startpos + range >= size1) 4022 if (startpos < size1 && startpos + range >= size1)
4023 lim = range - (size1 - startpos); 4023 lim = range - (size1 - startpos);
4024 4024
4025 d = ((CONST unsigned char *) 4025 d = ((const unsigned char *)
4026 (startpos >= size1 ? string2 - size1 : string1) + startpos); 4026 (startpos >= size1 ? string2 - size1 : string1) + startpos);
4027 4027
4028 /* Written out as an if-else to avoid testing `translate' 4028 /* Written out as an if-else to avoid testing `translate'
4029 inside the loop. */ 4029 inside the loop. */
4030 if (translate) 4030 if (translate)
4088 advance: 4088 advance:
4089 if (!range) 4089 if (!range)
4090 break; 4090 break;
4091 else if (range > 0) 4091 else if (range > 0)
4092 { 4092 {
4093 d = ((CONST unsigned char *) 4093 d = ((const unsigned char *)
4094 (startpos >= size1 ? string2 - size1 : string1) + startpos); 4094 (startpos >= size1 ? string2 - size1 : string1) + startpos);
4095 d_size = charcount_to_bytecount (d, 1); 4095 d_size = charcount_to_bytecount (d, 1);
4096 range -= d_size; 4096 range -= d_size;
4097 startpos += d_size; 4097 startpos += d_size;
4098 } 4098 }
4099 else 4099 else
4100 { 4100 {
4101 /* Note startpos > size1 not >=. If we are on the 4101 /* Note startpos > size1 not >=. If we are on the
4102 string1/string2 boundary, we want to backup into string1. */ 4102 string1/string2 boundary, we want to backup into string1. */
4103 d = ((CONST unsigned char *) 4103 d = ((const unsigned char *)
4104 (startpos > size1 ? string2 - size1 : string1) + startpos); 4104 (startpos > size1 ? string2 - size1 : string1) + startpos);
4105 DEC_CHARPTR(d); 4105 DEC_CHARPTR(d);
4106 d_size = charcount_to_bytecount (d, 1); 4106 d_size = charcount_to_bytecount (d, 1);
4107 range += d_size; 4107 range += d_size;
4108 startpos -= d_size; 4108 startpos -= d_size;
4189 4189
4190 #ifndef emacs /* Emacs never uses this. */ 4190 #ifndef emacs /* Emacs never uses this. */
4191 /* re_match is like re_match_2 except it takes only a single string. */ 4191 /* re_match is like re_match_2 except it takes only a single string. */
4192 4192
4193 int 4193 int
4194 re_match (struct re_pattern_buffer *bufp, CONST char *string, int size, 4194 re_match (struct re_pattern_buffer *bufp, const char *string, int size,
4195 int pos, struct re_registers *regs) 4195 int pos, struct re_registers *regs)
4196 { 4196 {
4197 int result = re_match_2_internal (bufp, NULL, 0, string, size, 4197 int result = re_match_2_internal (bufp, NULL, 0, string, size,
4198 pos, regs, size); 4198 pos, regs, size);
4199 alloca (0); 4199 alloca (0);
4214 We return -1 if no match, -2 if an internal error (such as the 4214 We return -1 if no match, -2 if an internal error (such as the
4215 failure stack overflowing). Otherwise, we return the length of the 4215 failure stack overflowing). Otherwise, we return the length of the
4216 matched substring. */ 4216 matched substring. */
4217 4217
4218 int 4218 int
4219 re_match_2 (struct re_pattern_buffer *bufp, CONST char *string1, 4219 re_match_2 (struct re_pattern_buffer *bufp, const char *string1,
4220 int size1, CONST char *string2, int size2, int pos, 4220 int size1, const char *string2, int size2, int pos,
4221 struct re_registers *regs, int stop) 4221 struct re_registers *regs, int stop)
4222 { 4222 {
4223 int result = re_match_2_internal (bufp, string1, size1, string2, size2, 4223 int result = re_match_2_internal (bufp, string1, size1, string2, size2,
4224 pos, regs, stop); 4224 pos, regs, stop);
4225 alloca (0); 4225 alloca (0);
4227 } 4227 }
4228 4228
4229 /* This is a separate function so that we can force an alloca cleanup 4229 /* This is a separate function so that we can force an alloca cleanup
4230 afterwards. */ 4230 afterwards. */
4231 static int 4231 static int
4232 re_match_2_internal (struct re_pattern_buffer *bufp, CONST char *string1, 4232 re_match_2_internal (struct re_pattern_buffer *bufp, const char *string1,
4233 int size1, CONST char *string2, int size2, int pos, 4233 int size1, const char *string2, int size2, int pos,
4234 struct re_registers *regs, int stop) 4234 struct re_registers *regs, int stop)
4235 { 4235 {
4236 /* General temporaries. */ 4236 /* General temporaries. */
4237 int mcnt; 4237 int mcnt;
4238 unsigned char *p1; 4238 unsigned char *p1;
4239 int should_succeed; /* XEmacs change */ 4239 int should_succeed; /* XEmacs change */
4240 4240
4241 /* Just past the end of the corresponding string. */ 4241 /* Just past the end of the corresponding string. */
4242 CONST char *end1, *end2; 4242 const char *end1, *end2;
4243 4243
4244 /* Pointers into string1 and string2, just past the last characters in 4244 /* Pointers into string1 and string2, just past the last characters in
4245 each to consider matching. */ 4245 each to consider matching. */
4246 CONST char *end_match_1, *end_match_2; 4246 const char *end_match_1, *end_match_2;
4247 4247
4248 /* Where we are in the data, and the end of the current string. */ 4248 /* Where we are in the data, and the end of the current string. */
4249 CONST char *d, *dend; 4249 const char *d, *dend;
4250 4250
4251 /* Where we are in the pattern, and the end of the pattern. */ 4251 /* Where we are in the pattern, and the end of the pattern. */
4252 unsigned char *p = bufp->buffer; 4252 unsigned char *p = bufp->buffer;
4253 REGISTER unsigned char *pend = p + bufp->used; 4253 REGISTER unsigned char *pend = p + bufp->used;
4254 4254
4297 regnum-th regstart pointer points to where in the pattern we began 4297 regnum-th regstart pointer points to where in the pattern we began
4298 matching and the regnum-th regend points to right after where we 4298 matching and the regnum-th regend points to right after where we
4299 stopped matching the regnum-th subexpression. (The zeroth register 4299 stopped matching the regnum-th subexpression. (The zeroth register
4300 keeps track of what the whole pattern matches.) */ 4300 keeps track of what the whole pattern matches.) */
4301 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */ 4301 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
4302 CONST char **regstart, **regend; 4302 const char **regstart, **regend;
4303 #endif 4303 #endif
4304 4304
4305 /* If a group that's operated upon by a repetition operator fails to 4305 /* If a group that's operated upon by a repetition operator fails to
4306 match anything, then the register for its start will need to be 4306 match anything, then the register for its start will need to be
4307 restored because it will have been set to wherever in the string we 4307 restored because it will have been set to wherever in the string we
4308 are when we last see its open-group operator. Similarly for a 4308 are when we last see its open-group operator. Similarly for a
4309 register's end. */ 4309 register's end. */
4310 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */ 4310 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
4311 CONST char **old_regstart, **old_regend; 4311 const char **old_regstart, **old_regend;
4312 #endif 4312 #endif
4313 4313
4314 /* The is_active field of reg_info helps us keep track of which (possibly 4314 /* The is_active field of reg_info helps us keep track of which (possibly
4315 nested) subexpressions we are currently in. The matched_something 4315 nested) subexpressions we are currently in. The matched_something
4316 field of reg_info[reg_num] helps us tell whether or not we have 4316 field of reg_info[reg_num] helps us tell whether or not we have
4325 variables when we find a match better than any we've seen before. 4325 variables when we find a match better than any we've seen before.
4326 This happens as we backtrack through the failure points, which in 4326 This happens as we backtrack through the failure points, which in
4327 turn happens only if we have not yet matched the entire string. */ 4327 turn happens only if we have not yet matched the entire string. */
4328 unsigned best_regs_set = false; 4328 unsigned best_regs_set = false;
4329 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */ 4329 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
4330 CONST char **best_regstart, **best_regend; 4330 const char **best_regstart, **best_regend;
4331 #endif 4331 #endif
4332 4332
4333 /* Logically, this is `best_regend[0]'. But we don't want to have to 4333 /* Logically, this is `best_regend[0]'. But we don't want to have to
4334 allocate space for that if we're not allocating space for anything 4334 allocate space for that if we're not allocating space for anything
4335 else (see below). Also, we never need info about register 0 for 4335 else (see below). Also, we never need info about register 0 for
4336 any of the other register vectors, and it seems rather a kludge to 4336 any of the other register vectors, and it seems rather a kludge to
4337 treat `best_regend' differently than the rest. So we keep track of 4337 treat `best_regend' differently than the rest. So we keep track of
4338 the end of the best match so far in a separate variable. We 4338 the end of the best match so far in a separate variable. We
4339 initialize this to NULL so that when we backtrack the first time 4339 initialize this to NULL so that when we backtrack the first time
4340 and need to test it, it's not garbage. */ 4340 and need to test it, it's not garbage. */
4341 CONST char *match_end = NULL; 4341 const char *match_end = NULL;
4342 4342
4343 /* This helps SET_REGS_MATCHED avoid doing redundant work. */ 4343 /* This helps SET_REGS_MATCHED avoid doing redundant work. */
4344 int set_regs_matched_done = 0; 4344 int set_regs_matched_done = 0;
4345 4345
4346 /* Used when we pop values we don't care about. */ 4346 /* Used when we pop values we don't care about. */
4347 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */ 4347 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
4348 CONST char **reg_dummy; 4348 const char **reg_dummy;
4349 register_info_type *reg_info_dummy; 4349 register_info_type *reg_info_dummy;
4350 #endif 4350 #endif
4351 4351
4352 #ifdef DEBUG 4352 #ifdef DEBUG
4353 /* Counts the total number of registers pushed. */ 4353 /* Counts the total number of registers pushed. */
4371 there are groups, we include space for register 0 (the whole 4371 there are groups, we include space for register 0 (the whole
4372 pattern), even though we never use it, since it simplifies the 4372 pattern), even though we never use it, since it simplifies the
4373 array indexing. We should fix this. */ 4373 array indexing. We should fix this. */
4374 if (bufp->re_nsub) 4374 if (bufp->re_nsub)
4375 { 4375 {
4376 regstart = REGEX_TALLOC (num_regs, CONST char *); 4376 regstart = REGEX_TALLOC (num_regs, const char *);
4377 regend = REGEX_TALLOC (num_regs, CONST char *); 4377 regend = REGEX_TALLOC (num_regs, const char *);
4378 old_regstart = REGEX_TALLOC (num_regs, CONST char *); 4378 old_regstart = REGEX_TALLOC (num_regs, const char *);
4379 old_regend = REGEX_TALLOC (num_regs, CONST char *); 4379 old_regend = REGEX_TALLOC (num_regs, const char *);
4380 best_regstart = REGEX_TALLOC (num_regs, CONST char *); 4380 best_regstart = REGEX_TALLOC (num_regs, const char *);
4381 best_regend = REGEX_TALLOC (num_regs, CONST char *); 4381 best_regend = REGEX_TALLOC (num_regs, const char *);
4382 reg_info = REGEX_TALLOC (num_regs, register_info_type); 4382 reg_info = REGEX_TALLOC (num_regs, register_info_type);
4383 reg_dummy = REGEX_TALLOC (num_regs, CONST char *); 4383 reg_dummy = REGEX_TALLOC (num_regs, const char *);
4384 reg_info_dummy = REGEX_TALLOC (num_regs, register_info_type); 4384 reg_info_dummy = REGEX_TALLOC (num_regs, register_info_type);
4385 4385
4386 if (!(regstart && regend && old_regstart && old_regend && reg_info 4386 if (!(regstart && regend && old_regstart && old_regend && reg_info
4387 && best_regstart && best_regend && reg_dummy && reg_info_dummy)) 4387 && best_regstart && best_regend && reg_dummy && reg_info_dummy))
4388 { 4388 {
4733 boolean not = (re_opcode_t) *(p - 1) == charset_mule_not; 4733 boolean not = (re_opcode_t) *(p - 1) == charset_mule_not;
4734 4734
4735 DEBUG_PRINT2 ("EXECUTING charset_mule%s.\n", not ? "_not" : ""); 4735 DEBUG_PRINT2 ("EXECUTING charset_mule%s.\n", not ? "_not" : "");
4736 4736
4737 PREFETCH (); 4737 PREFETCH ();
4738 c = charptr_emchar ((CONST Bufbyte *) d); 4738 c = charptr_emchar ((const Bufbyte *) d);
4739 c = TRANSLATE_EXTENDED_UNSAFE (c); /* The character to match. */ 4739 c = TRANSLATE_EXTENDED_UNSAFE (c); /* The character to match. */
4740 4740
4741 if (EQ (Qt, unified_range_table_lookup (p, c, Qnil))) 4741 if (EQ (Qt, unified_range_table_lookup (p, c, Qnil)))
4742 not = !not; 4742 not = !not;
4743 4743
4948 4948
4949 /* \<digit> has been turned into a `duplicate' command which is 4949 /* \<digit> has been turned into a `duplicate' command which is
4950 followed by the numeric value of <digit> as the register number. */ 4950 followed by the numeric value of <digit> as the register number. */
4951 case duplicate: 4951 case duplicate:
4952 { 4952 {
4953 REGISTER CONST char *d2, *dend2; 4953 REGISTER const char *d2, *dend2;
4954 int regno = *p++; /* Get which register to match against. */ 4954 int regno = *p++; /* Get which register to match against. */
4955 DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno); 4955 DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno);
4956 4956
4957 /* Can't back reference a group which we've never matched. */ 4957 /* Can't back reference a group which we've never matched. */
4958 if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno])) 4958 if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno]))
5304 actual values. Otherwise, we will restore only one 5304 actual values. Otherwise, we will restore only one
5305 register from the stack, since lowest will == highest in 5305 register from the stack, since lowest will == highest in
5306 `pop_failure_point'. */ 5306 `pop_failure_point'. */
5307 unsigned dummy_low_reg, dummy_high_reg; 5307 unsigned dummy_low_reg, dummy_high_reg;
5308 unsigned char *pdummy; 5308 unsigned char *pdummy;
5309 CONST char *sdummy = NULL; 5309 const char *sdummy = NULL;
5310 5310
5311 DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n"); 5311 DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n");
5312 POP_FAILURE_POINT (sdummy, pdummy, 5312 POP_FAILURE_POINT (sdummy, pdummy,
5313 dummy_low_reg, dummy_high_reg, 5313 dummy_low_reg, dummy_high_reg,
5314 reg_dummy, reg_dummy, reg_info_dummy); 5314 reg_dummy, reg_dummy, reg_info_dummy);
5420 int result; 5420 int result;
5421 if (AT_STRINGS_BEG (d) || AT_STRINGS_END (d)) 5421 if (AT_STRINGS_BEG (d) || AT_STRINGS_END (d))
5422 result = 1; 5422 result = 1;
5423 else 5423 else
5424 { 5424 {
5425 CONST unsigned char *d_before = 5425 const unsigned char *d_before =
5426 (CONST unsigned char *) POS_BEFORE_GAP_UNSAFE (d); 5426 (const unsigned char *) POS_BEFORE_GAP_UNSAFE (d);
5427 CONST unsigned char *d_after = 5427 const unsigned char *d_after =
5428 (CONST unsigned char *) POS_AFTER_GAP_UNSAFE (d); 5428 (const unsigned char *) POS_AFTER_GAP_UNSAFE (d);
5429 Emchar emch1, emch2; 5429 Emchar emch1, emch2;
5430 5430
5431 DEC_CHARPTR (d_before); 5431 DEC_CHARPTR (d_before);
5432 emch1 = charptr_emchar (d_before); 5432 emch1 = charptr_emchar (d_before);
5433 emch2 = charptr_emchar (d_after); 5433 emch2 = charptr_emchar (d_after);
5451 5451
5452 if (WORDCHAR_P (d) && (AT_STRINGS_BEG (d) || !WORDCHAR_P (d - 1))) 5452 if (WORDCHAR_P (d) && (AT_STRINGS_BEG (d) || !WORDCHAR_P (d - 1)))
5453 break; 5453 break;
5454 5454
5455 */ 5455 */
5456 CONST unsigned char *dtmp = 5456 const unsigned char *dtmp =
5457 (CONST unsigned char *) POS_AFTER_GAP_UNSAFE (d); 5457 (const unsigned char *) POS_AFTER_GAP_UNSAFE (d);
5458 Emchar emch = charptr_emchar (dtmp); 5458 Emchar emch = charptr_emchar (dtmp);
5459 if (!WORDCHAR_P_UNSAFE (emch)) 5459 if (!WORDCHAR_P_UNSAFE (emch))
5460 goto fail; 5460 goto fail;
5461 if (AT_STRINGS_BEG (d)) 5461 if (AT_STRINGS_BEG (d))
5462 break; 5462 break;
5463 dtmp = (CONST unsigned char *) POS_BEFORE_GAP_UNSAFE (d); 5463 dtmp = (const unsigned char *) POS_BEFORE_GAP_UNSAFE (d);
5464 DEC_CHARPTR (dtmp); 5464 DEC_CHARPTR (dtmp);
5465 emch = charptr_emchar (dtmp); 5465 emch = charptr_emchar (dtmp);
5466 if (!WORDCHAR_P_UNSAFE (emch)) 5466 if (!WORDCHAR_P_UNSAFE (emch))
5467 break; 5467 break;
5468 goto fail; 5468 goto fail;
5477 && (!WORDCHAR_P (d) || AT_STRINGS_END (d))) 5477 && (!WORDCHAR_P (d) || AT_STRINGS_END (d)))
5478 break; 5478 break;
5479 5479
5480 The or condition is incorrect (reversed). 5480 The or condition is incorrect (reversed).
5481 */ 5481 */
5482 CONST unsigned char *dtmp; 5482 const unsigned char *dtmp;
5483 Emchar emch; 5483 Emchar emch;
5484 if (AT_STRINGS_BEG (d)) 5484 if (AT_STRINGS_BEG (d))
5485 goto fail; 5485 goto fail;
5486 dtmp = (CONST unsigned char *) POS_BEFORE_GAP_UNSAFE (d); 5486 dtmp = (const unsigned char *) POS_BEFORE_GAP_UNSAFE (d);
5487 DEC_CHARPTR (dtmp); 5487 DEC_CHARPTR (dtmp);
5488 emch = charptr_emchar (dtmp); 5488 emch = charptr_emchar (dtmp);
5489 if (!WORDCHAR_P_UNSAFE (emch)) 5489 if (!WORDCHAR_P_UNSAFE (emch))
5490 goto fail; 5490 goto fail;
5491 if (AT_STRINGS_END (d)) 5491 if (AT_STRINGS_END (d))
5492 break; 5492 break;
5493 dtmp = (CONST unsigned char *) POS_AFTER_GAP_UNSAFE (d); 5493 dtmp = (const unsigned char *) POS_AFTER_GAP_UNSAFE (d);
5494 emch = charptr_emchar (dtmp); 5494 emch = charptr_emchar (dtmp);
5495 if (!WORDCHAR_P_UNSAFE (emch)) 5495 if (!WORDCHAR_P_UNSAFE (emch))
5496 break; 5496 break;
5497 goto fail; 5497 goto fail;
5498 } 5498 }
5499 5499
5500 #ifdef emacs 5500 #ifdef emacs
5501 case before_dot: 5501 case before_dot:
5502 DEBUG_PRINT1 ("EXECUTING before_dot.\n"); 5502 DEBUG_PRINT1 ("EXECUTING before_dot.\n");
5503 if (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d) >= 5503 if (!regex_emacs_buffer_p
5504 BUF_PT (regex_emacs_buffer)) 5504 || (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d)
5505 >= BUF_PT (regex_emacs_buffer)))
5505 goto fail; 5506 goto fail;
5506 break; 5507 break;
5507 5508
5508 case at_dot: 5509 case at_dot:
5509 DEBUG_PRINT1 ("EXECUTING at_dot.\n"); 5510 DEBUG_PRINT1 ("EXECUTING at_dot.\n");
5510 if (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d) 5511 if (!regex_emacs_buffer_p
5511 != BUF_PT (regex_emacs_buffer)) 5512 || (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d)
5513 != BUF_PT (regex_emacs_buffer)))
5512 goto fail; 5514 goto fail;
5513 break; 5515 break;
5514 5516
5515 case after_dot: 5517 case after_dot:
5516 DEBUG_PRINT1 ("EXECUTING after_dot.\n"); 5518 DEBUG_PRINT1 ("EXECUTING after_dot.\n");
5517 if (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d) 5519 if (!regex_emacs_buffer_p
5518 <= BUF_PT (regex_emacs_buffer)) 5520 || (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d)
5521 <= BUF_PT (regex_emacs_buffer)))
5519 goto fail; 5522 goto fail;
5520 break; 5523 break;
5521 #if 0 /* not emacs19 */ 5524 #if 0 /* not emacs19 */
5522 case at_dot: 5525 case at_dot:
5523 DEBUG_PRINT1 ("EXECUTING at_dot.\n"); 5526 DEBUG_PRINT1 ("EXECUTING at_dot.\n");
5541 { 5544 {
5542 int matches; 5545 int matches;
5543 Emchar emch; 5546 Emchar emch;
5544 5547
5545 PREFETCH (); 5548 PREFETCH ();
5546 emch = charptr_emchar ((CONST Bufbyte *) d); 5549 emch = charptr_emchar ((const Bufbyte *) d);
5547 matches = (SYNTAX_UNSAFE 5550 matches = (SYNTAX_UNSAFE
5548 (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table), 5551 (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table),
5549 emch) == (enum syntaxcode) mcnt); 5552 emch) == (enum syntaxcode) mcnt);
5550 INC_CHARPTR (d); 5553 INC_CHARPTR (d);
5551 if (matches != should_succeed) 5554 if (matches != should_succeed)
5574 { 5577 {
5575 Emchar emch; 5578 Emchar emch;
5576 5579
5577 mcnt = *p++; 5580 mcnt = *p++;
5578 PREFETCH (); 5581 PREFETCH ();
5579 emch = charptr_emchar ((CONST Bufbyte *) d); 5582 emch = charptr_emchar ((const Bufbyte *) d);
5580 INC_CHARPTR (d); 5583 INC_CHARPTR (d);
5581 if (check_category_char(emch, regex_emacs_buffer->category_table, 5584 if (check_category_char(emch, regex_emacs_buffer->category_table,
5582 mcnt, should_succeed)) 5585 mcnt, should_succeed))
5583 goto fail; 5586 goto fail;
5584 SET_REGS_MATCHED (); 5587 SET_REGS_MATCHED ();
5916 5919
5917 /* Return zero if TRANSLATE[S1] and TRANSLATE[S2] are identical for LEN 5920 /* Return zero if TRANSLATE[S1] and TRANSLATE[S2] are identical for LEN
5918 bytes; nonzero otherwise. */ 5921 bytes; nonzero otherwise. */
5919 5922
5920 static int 5923 static int
5921 bcmp_translate (CONST unsigned char *s1, CONST unsigned char *s2, 5924 bcmp_translate (const unsigned char *s1, const unsigned char *s2,
5922 REGISTER int len, char *translate) 5925 REGISTER int len, char *translate)
5923 { 5926 {
5924 REGISTER CONST unsigned char *p1 = s1, *p2 = s2; 5927 REGISTER const unsigned char *p1 = s1, *p2 = s2;
5925 while (len) 5928 while (len)
5926 { 5929 {
5927 if (translate[*p1++] != translate[*p2++]) return 1; 5930 if (translate[*p1++] != translate[*p2++]) return 1;
5928 len--; 5931 len--;
5929 } 5932 }
5939 Assumes the `allocated' (and perhaps `buffer') and `translate' fields 5942 Assumes the `allocated' (and perhaps `buffer') and `translate' fields
5940 are set in BUFP on entry. 5943 are set in BUFP on entry.
5941 5944
5942 We call regex_compile to do the actual compilation. */ 5945 We call regex_compile to do the actual compilation. */
5943 5946
5944 CONST char * 5947 const char *
5945 re_compile_pattern (CONST char *pattern, int length, 5948 re_compile_pattern (const char *pattern, int length,
5946 struct re_pattern_buffer *bufp) 5949 struct re_pattern_buffer *bufp)
5947 { 5950 {
5948 reg_errcode_t ret; 5951 reg_errcode_t ret;
5949 5952
5950 /* GNU code is written to assume at least RE_NREGS registers will be set 5953 /* GNU code is written to assume at least RE_NREGS registers will be set
5973 5976
5974 /* BSD has one and only one pattern buffer. */ 5977 /* BSD has one and only one pattern buffer. */
5975 static struct re_pattern_buffer re_comp_buf; 5978 static struct re_pattern_buffer re_comp_buf;
5976 5979
5977 char * 5980 char *
5978 re_comp (CONST char *s) 5981 re_comp (const char *s)
5979 { 5982 {
5980 reg_errcode_t ret; 5983 reg_errcode_t ret;
5981 5984
5982 if (!s) 5985 if (!s)
5983 { 5986 {
6007 ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf); 6010 ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf);
6008 6011
6009 if (!ret) 6012 if (!ret)
6010 return NULL; 6013 return NULL;
6011 6014
6012 /* Yes, we're discarding `CONST' here if !HAVE_LIBINTL. */ 6015 /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */
6013 return (char *) gettext (re_error_msgid[(int) ret]); 6016 return (char *) gettext (re_error_msgid[(int) ret]);
6014 } 6017 }
6015 6018
6016 6019
6017 int 6020 int
6018 re_exec (CONST char *s) 6021 re_exec (const char *s)
6019 { 6022 {
6020 CONST int len = strlen (s); 6023 const int len = strlen (s);
6021 return 6024 return
6022 0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0); 6025 0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0);
6023 } 6026 }
6024 #endif /* _REGEX_RE_COMP */ 6027 #endif /* _REGEX_RE_COMP */
6025 6028
6060 6063
6061 It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for 6064 It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for
6062 the return codes and their meanings.) */ 6065 the return codes and their meanings.) */
6063 6066
6064 int 6067 int
6065 regcomp (regex_t *preg, CONST char *pattern, int cflags) 6068 regcomp (regex_t *preg, const char *pattern, int cflags)
6066 { 6069 {
6067 reg_errcode_t ret; 6070 reg_errcode_t ret;
6068 unsigned syntax 6071 unsigned syntax
6069 = (cflags & REG_EXTENDED) ? 6072 = (cflags & REG_EXTENDED) ?
6070 RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC; 6073 RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC;
6133 string; if REG_NOTEOL is set, then $ does not match at the end. 6136 string; if REG_NOTEOL is set, then $ does not match at the end.
6134 6137
6135 We return 0 if we find a match and REG_NOMATCH if not. */ 6138 We return 0 if we find a match and REG_NOMATCH if not. */
6136 6139
6137 int 6140 int
6138 regexec (CONST regex_t *preg, CONST char *string, size_t nmatch, 6141 regexec (const regex_t *preg, const char *string, size_t nmatch,
6139 regmatch_t pmatch[], int eflags) 6142 regmatch_t pmatch[], int eflags)
6140 { 6143 {
6141 int ret; 6144 int ret;
6142 struct re_registers regs; 6145 struct re_registers regs;
6143 regex_t private_preg; 6146 regex_t private_preg;
6194 6197
6195 /* Returns a message corresponding to an error code, ERRCODE, returned 6198 /* Returns a message corresponding to an error code, ERRCODE, returned
6196 from either regcomp or regexec. We don't use PREG here. */ 6199 from either regcomp or regexec. We don't use PREG here. */
6197 6200
6198 size_t 6201 size_t
6199 regerror (int errcode, CONST regex_t *preg, char *errbuf, size_t errbuf_size) 6202 regerror (int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
6200 { 6203 {
6201 CONST char *msg; 6204 const char *msg;
6202 size_t msg_size; 6205 size_t msg_size;
6203 6206
6204 if (errcode < 0 6207 if (errcode < 0
6205 || errcode >= (sizeof (re_error_msgid) / sizeof (re_error_msgid[0]))) 6208 || errcode >= (sizeof (re_error_msgid) / sizeof (re_error_msgid[0])))
6206 /* Only error codes returned by the rest of the code should be passed 6209 /* Only error codes returned by the rest of the code should be passed