122 |
# define SYNTAX_ENTRY_VIA_PROPERTY |
# define SYNTAX_ENTRY_VIA_PROPERTY |
123 |
|
|
124 |
# include "syntax.h" |
# include "syntax.h" |
125 |
# include "charset.h" |
# include "character.h" |
126 |
# include "category.h" |
# include "category.h" |
127 |
|
|
128 |
# ifdef malloc |
# ifdef malloc |
143 |
# define POS_AS_IN_BUFFER(p) ((p) + (NILP (re_match_object) || BUFFERP (re_match_object))) |
# define POS_AS_IN_BUFFER(p) ((p) + (NILP (re_match_object) || BUFFERP (re_match_object))) |
144 |
|
|
145 |
# define RE_MULTIBYTE_P(bufp) ((bufp)->multibyte) |
# define RE_MULTIBYTE_P(bufp) ((bufp)->multibyte) |
146 |
|
# define RE_TARGET_MULTIBYTE_P(bufp) ((bufp)->target_multibyte) |
147 |
# define RE_STRING_CHAR(p, s) \ |
# define RE_STRING_CHAR(p, s) \ |
148 |
(multibyte ? (STRING_CHAR (p, s)) : (*(p))) |
(multibyte ? (STRING_CHAR (p, s)) : (*(p))) |
149 |
# define RE_STRING_CHAR_AND_LENGTH(p, s, len) \ |
# define RE_STRING_CHAR_AND_LENGTH(p, s, len) \ |
150 |
(multibyte ? (STRING_CHAR_AND_LENGTH (p, s, len)) : ((len) = 1, *(p))) |
(multibyte ? (STRING_CHAR_AND_LENGTH (p, s, len)) : ((len) = 1, *(p))) |
151 |
|
|
152 |
/* Set C a (possibly multibyte) character before P. P points into a |
/* Set C a (possibly converted to multibyte) character before P. P |
153 |
string which is the virtual concatenation of STR1 (which ends at |
points into a string which is the virtual concatenation of STR1 |
154 |
END1) or STR2 (which ends at END2). */ |
(which ends at END1) or STR2 (which ends at END2). */ |
155 |
# define GET_CHAR_BEFORE_2(c, p, str1, end1, str2, end2) \ |
# define GET_CHAR_BEFORE_2(c, p, str1, end1, str2, end2) \ |
156 |
do { \ |
do { \ |
157 |
if (multibyte) \ |
if (multibyte) \ |
158 |
{ \ |
{ \ |
159 |
re_char *dtemp = (p) == (str2) ? (end1) : (p); \ |
re_char *dtemp = (p) == (str2) ? (end1) : (p); \ |
160 |
re_char *dlimit = ((p) > (str2) && (p) <= (end2)) ? (str2) : (str1); \ |
re_char *dlimit = ((p) > (str2) && (p) <= (end2)) ? (str2) : (str1); \ |
161 |
re_char *d0 = dtemp; \ |
while (dtemp-- > dlimit && !CHAR_HEAD_P (*dtemp)); \ |
162 |
PREV_CHAR_BOUNDARY (d0, dlimit); \ |
c = STRING_CHAR (dtemp, (p) - dtemp); \ |
163 |
c = STRING_CHAR (d0, dtemp - d0); \ |
} \ |
164 |
} \ |
else \ |
165 |
else \ |
{ \ |
166 |
(c = ((p) == (str2) ? (end1) : (p))[-1]); \ |
(c = ((p) == (str2) ? (end1) : (p))[-1]); \ |
167 |
|
MAKE_CHAR_MULTIBYTE (c); \ |
168 |
|
} \ |
169 |
} while (0) |
} while (0) |
170 |
|
|
171 |
|
/* Set C a (possibly converted to multibyte) character at P, and set |
172 |
|
LEN to the byte length of that character. */ |
173 |
|
# define GET_CHAR_AFTER(c, p, len) \ |
174 |
|
do { \ |
175 |
|
if (multibyte) \ |
176 |
|
c = STRING_CHAR_AND_LENGTH (p, 0, len); \ |
177 |
|
else \ |
178 |
|
{ \ |
179 |
|
c = *p; \ |
180 |
|
len = 1; \ |
181 |
|
MAKE_CHAR_MULTIBYTE (c); \ |
182 |
|
} \ |
183 |
|
} while (0) |
184 |
|
|
185 |
#else /* not emacs */ |
#else /* not emacs */ |
186 |
|
|
247 |
# define CHARSET_LEADING_CODE_BASE(c) 0 |
# define CHARSET_LEADING_CODE_BASE(c) 0 |
248 |
# define MAX_MULTIBYTE_LENGTH 1 |
# define MAX_MULTIBYTE_LENGTH 1 |
249 |
# define RE_MULTIBYTE_P(x) 0 |
# define RE_MULTIBYTE_P(x) 0 |
250 |
|
# define RE_TARGET_MULTIBYTE_P(x) 0 |
251 |
# define WORD_BOUNDARY_P(c1, c2) (0) |
# define WORD_BOUNDARY_P(c1, c2) (0) |
252 |
# define CHAR_HEAD_P(p) (1) |
# define CHAR_HEAD_P(p) (1) |
253 |
# define SINGLE_BYTE_CHAR_P(c) (1) |
# define SINGLE_BYTE_CHAR_P(c) (1) |
261 |
# define RE_STRING_CHAR_AND_LENGTH STRING_CHAR_AND_LENGTH |
# define RE_STRING_CHAR_AND_LENGTH STRING_CHAR_AND_LENGTH |
262 |
# define GET_CHAR_BEFORE_2(c, p, str1, end1, str2, end2) \ |
# define GET_CHAR_BEFORE_2(c, p, str1, end1, str2, end2) \ |
263 |
(c = ((p) == (str2) ? *((end1) - 1) : *((p) - 1))) |
(c = ((p) == (str2) ? *((end1) - 1) : *((p) - 1))) |
264 |
|
# define GET_CHAR_AFTER(c, p, len) \ |
265 |
|
(c = *p, len = 1) |
266 |
# define MAKE_CHAR(charset, c1, c2) (c1) |
# define MAKE_CHAR(charset, c1, c2) (c1) |
267 |
|
# define BYTE8_TO_CHAR(c) (c) |
268 |
|
# define CHAR_BYTE8_P(c) (0) |
269 |
|
# define MAKE_CHAR_MULTIBYTE(c) (c) |
270 |
|
# define MAKE_CHAR_UNIBYTE(c) (c) |
271 |
|
# define CHAR_LEADING_CODE(c) (c) |
272 |
|
|
273 |
#endif /* not emacs */ |
#endif /* not emacs */ |
274 |
|
|
275 |
#ifndef RE_TRANSLATE |
#ifndef RE_TRANSLATE |
475 |
# ifdef __GNUC__ |
# ifdef __GNUC__ |
476 |
# define alloca __builtin_alloca |
# define alloca __builtin_alloca |
477 |
# else /* not __GNUC__ */ |
# else /* not __GNUC__ */ |
478 |
# if HAVE_ALLOCA_H |
# ifdef HAVE_ALLOCA_H |
479 |
# include <alloca.h> |
# include <alloca.h> |
480 |
# endif /* HAVE_ALLOCA_H */ |
# endif /* HAVE_ALLOCA_H */ |
481 |
# endif /* not __GNUC__ */ |
# endif /* not __GNUC__ */ |
1896 |
|
|
1897 |
#define EXTEND_RANGE_TABLE(work_area, n) \ |
#define EXTEND_RANGE_TABLE(work_area, n) \ |
1898 |
do { \ |
do { \ |
1899 |
if (((work_area)->used + (n)) * sizeof (int) > (work_area)->allocated) \ |
if (((work_area).used + (n)) * sizeof (int) > (work_area).allocated) \ |
1900 |
{ \ |
{ \ |
1901 |
extend_range_table_work_area (work_area); \ |
extend_range_table_work_area (&work_area); \ |
1902 |
if ((work_area)->table == 0) \ |
if ((work_area).table == 0) \ |
1903 |
return (REG_ESPACE); \ |
return (REG_ESPACE); \ |
1904 |
} \ |
} \ |
1905 |
} while (0) |
} while (0) |
1916 |
#define BIT_UPPER 0x10 |
#define BIT_UPPER 0x10 |
1917 |
#define BIT_MULTIBYTE 0x20 |
#define BIT_MULTIBYTE 0x20 |
1918 |
|
|
1919 |
/* Set a range START..END to WORK_AREA. |
/* Set a range (RANGE_START, RANGE_END) to WORK_AREA. */ |
1920 |
The range is passed through TRANSLATE, so START and END |
#define SET_RANGE_TABLE_WORK_AREA(work_area, range_start, range_end) \ |
|
should be untranslated. */ |
|
|
#define SET_RANGE_TABLE_WORK_AREA(work_area, start, end) \ |
|
1921 |
do { \ |
do { \ |
1922 |
int tem; \ |
EXTEND_RANGE_TABLE ((work_area), 2); \ |
1923 |
tem = set_image_of_range (&work_area, start, end, translate); \ |
(work_area).table[(work_area).used++] = (range_start); \ |
1924 |
if (tem > 0) \ |
(work_area).table[(work_area).used++] = (range_end); \ |
|
FREE_STACK_RETURN (tem); \ |
|
1925 |
} while (0) |
} while (0) |
1926 |
|
|
1927 |
/* Free allocated memory for WORK_AREA. */ |
/* Free allocated memory for WORK_AREA. */ |
1941 |
#define SET_LIST_BIT(c) (b[((c)) / BYTEWIDTH] |= 1 << ((c) % BYTEWIDTH)) |
#define SET_LIST_BIT(c) (b[((c)) / BYTEWIDTH] |= 1 << ((c) % BYTEWIDTH)) |
1942 |
|
|
1943 |
|
|
1944 |
|
#ifdef emacs |
1945 |
|
|
1946 |
|
/* Store characters in the rage range C0 to C1 in WORK_AREA while |
1947 |
|
translating them and paying attention to the continuity of |
1948 |
|
translated characters. |
1949 |
|
|
1950 |
|
Implementation note: It is better to implement this fairly big |
1951 |
|
macro by a function, but it's not that easy because macros called |
1952 |
|
in this macro assume various local variables already declared. */ |
1953 |
|
|
1954 |
|
#define SETUP_MULTIBYTE_RANGE(work_area, c0, c1) \ |
1955 |
|
do { \ |
1956 |
|
re_wchar_t c, t, t_last; \ |
1957 |
|
int n; \ |
1958 |
|
\ |
1959 |
|
c = (c0); \ |
1960 |
|
t_last = multibyte ? TRANSLATE (c) : TRANSLATE (MAKE_CHAR_MULTIBYTE (c)); \ |
1961 |
|
for (c++, n = 1; c <= (c1); c++, n++) \ |
1962 |
|
{ \ |
1963 |
|
t = multibyte ? TRANSLATE (c) : TRANSLATE (MAKE_CHAR_MULTIBYTE (c)); \ |
1964 |
|
if (t_last + n == t) \ |
1965 |
|
continue; \ |
1966 |
|
SET_RANGE_TABLE_WORK_AREA ((work_area), t_last, t_last + n - 1); \ |
1967 |
|
t_last = t; \ |
1968 |
|
n = 0; \ |
1969 |
|
} \ |
1970 |
|
if (n > 0) \ |
1971 |
|
SET_RANGE_TABLE_WORK_AREA ((work_area), t_last, t_last + n - 1); \ |
1972 |
|
} while (0) |
1973 |
|
|
1974 |
|
#endif /* emacs */ |
1975 |
|
|
1976 |
/* Get the next unsigned number in the uncompiled pattern. */ |
/* Get the next unsigned number in the uncompiled pattern. */ |
1977 |
#define GET_UNSIGNED_NUMBER(num) \ |
#define GET_UNSIGNED_NUMBER(num) \ |
1978 |
do { if (p != pend) \ |
do { if (p != pend) \ |
2128 |
= (int *) malloc (work_area->allocated); |
= (int *) malloc (work_area->allocated); |
2129 |
} |
} |
2130 |
|
|
2131 |
|
#if 0 |
2132 |
#ifdef emacs |
#ifdef emacs |
2133 |
|
|
2134 |
/* Carefully find the ranges of codes that are equivalent |
/* Carefully find the ranges of codes that are equivalent |
2361 |
|
|
2362 |
return -1; |
return -1; |
2363 |
} |
} |
2364 |
|
#endif /* 0 */ |
2365 |
|
|
2366 |
#ifndef MATCH_MAY_ALLOCATE |
#ifndef MATCH_MAY_ALLOCATE |
2367 |
|
|
2505 |
/* If the object matched can contain multibyte characters. */ |
/* If the object matched can contain multibyte characters. */ |
2506 |
const boolean multibyte = RE_MULTIBYTE_P (bufp); |
const boolean multibyte = RE_MULTIBYTE_P (bufp); |
2507 |
|
|
2508 |
|
/* If a target of matching can contain multibyte characters. */ |
2509 |
|
const boolean target_multibyte = RE_TARGET_MULTIBYTE_P (bufp); |
2510 |
|
|
2511 |
#ifdef DEBUG |
#ifdef DEBUG |
2512 |
debug++; |
debug++; |
2513 |
DEBUG_PRINT1 ("\nCompiling pattern: "); |
DEBUG_PRINT1 ("\nCompiling pattern: "); |
2827 |
break; |
break; |
2828 |
} |
} |
2829 |
|
|
|
/* What should we do for the character which is |
|
|
greater than 0x7F, but not BASE_LEADING_CODE_P? |
|
|
XXX */ |
|
|
|
|
2830 |
/* See if we're at the beginning of a possible character |
/* See if we're at the beginning of a possible character |
2831 |
class. */ |
class. */ |
2832 |
|
|
2865 |
{ |
{ |
2866 |
re_wchar_t ch; |
re_wchar_t ch; |
2867 |
re_wctype_t cc; |
re_wctype_t cc; |
2868 |
|
int limit; |
2869 |
|
|
2870 |
cc = re_wctype (str); |
cc = re_wctype (str); |
2871 |
|
|
2885 |
don't need to handle them for multibyte. |
don't need to handle them for multibyte. |
2886 |
They are distinguished by a negative wctype. */ |
They are distinguished by a negative wctype. */ |
2887 |
|
|
2888 |
if (multibyte) |
for (ch = 0; ch < 128; ++ch) |
2889 |
SET_RANGE_TABLE_WORK_AREA_BIT (range_table_work, |
if (re_iswctype (btowc (ch), cc)) |
2890 |
re_wctype_to_bit (cc)); |
{ |
2891 |
|
c = TRANSLATE (ch); |
2892 |
|
SET_LIST_BIT (c); |
2893 |
|
} |
2894 |
|
|
2895 |
for (ch = 0; ch < 1 << BYTEWIDTH; ++ch) |
if (target_multibyte) |
2896 |
|
{ |
2897 |
|
SET_RANGE_TABLE_WORK_AREA_BIT |
2898 |
|
(range_table_work, re_wctype_to_bit (cc)); |
2899 |
|
} |
2900 |
|
else |
2901 |
{ |
{ |
2902 |
int translated = TRANSLATE (ch); |
for (ch = 0; ch < (1 << BYTEWIDTH); ++ch) |
2903 |
if (re_iswctype (btowc (ch), cc)) |
{ |
2904 |
SET_LIST_BIT (translated); |
c = ch; |
2905 |
|
MAKE_CHAR_MULTIBYTE (c); |
2906 |
|
if (re_iswctype (btowc (c), cc)) |
2907 |
|
{ |
2908 |
|
c = TRANSLATE (c); |
2909 |
|
MAKE_CHAR_UNIBYTE (c); |
2910 |
|
SET_LIST_BIT (c); |
2911 |
|
} |
2912 |
|
} |
2913 |
} |
} |
2914 |
|
|
2915 |
/* Repeat the loop. */ |
/* Repeat the loop. */ |
2936 |
|
|
2937 |
/* Fetch the character which ends the range. */ |
/* Fetch the character which ends the range. */ |
2938 |
PATFETCH (c1); |
PATFETCH (c1); |
2939 |
|
if (c > c1) |
|
if (SINGLE_BYTE_CHAR_P (c)) |
|
2940 |
{ |
{ |
2941 |
if (! SINGLE_BYTE_CHAR_P (c1)) |
if (syntax & RE_NO_EMPTY_RANGES) |
2942 |
{ |
FREE_STACK_RETURN (REG_ERANGE); |
2943 |
/* Handle a range starting with a |
/* Else, repeat the loop. */ |
|
character of less than 256, and ending |
|
|
with a character of not less than 256. |
|
|
Split that into two ranges, the low one |
|
|
ending at 0377, and the high one |
|
|
starting at the smallest character in |
|
|
the charset of C1 and ending at C1. */ |
|
|
int charset = CHAR_CHARSET (c1); |
|
|
re_wchar_t c2 = MAKE_CHAR (charset, 0, 0); |
|
|
|
|
|
SET_RANGE_TABLE_WORK_AREA (range_table_work, |
|
|
c2, c1); |
|
|
c1 = 0377; |
|
|
} |
|
2944 |
} |
} |
|
else if (!SAME_CHARSET_P (c, c1)) |
|
|
FREE_STACK_RETURN (REG_ERANGE); |
|
2945 |
} |
} |
2946 |
else |
else |
2947 |
/* Range from C to C. */ |
/* Range from C to C. */ |
2948 |
c1 = c; |
c1 = c; |
2949 |
|
|
2950 |
/* Set the range ... */ |
#ifndef emacs |
2951 |
if (SINGLE_BYTE_CHAR_P (c)) |
c = TRANSLATE (c); |
2952 |
/* ... into bitmap. */ |
c1 = TRANSLATE (c1); |
2953 |
|
/* Set the range into bitmap */ |
2954 |
|
for (; c <= c1; c++) |
2955 |
|
SET_LIST_BIT (TRANSLATE (c)); |
2956 |
|
#else /* not emacs */ |
2957 |
|
if (target_multibyte) |
2958 |
{ |
{ |
2959 |
re_wchar_t this_char; |
if (c1 >= 128) |
|
re_wchar_t range_start = c, range_end = c1; |
|
|
|
|
|
/* If the start is after the end, the range is empty. */ |
|
|
if (range_start > range_end) |
|
2960 |
{ |
{ |
2961 |
if (syntax & RE_NO_EMPTY_RANGES) |
re_wchar_t c0 = MAX (c, 128); |
2962 |
FREE_STACK_RETURN (REG_ERANGE); |
|
2963 |
/* Else, repeat the loop. */ |
SETUP_MULTIBYTE_RANGE (range_table_work, c0, c1); |
2964 |
|
c1 = 127; |
2965 |
} |
} |
2966 |
else |
for (; c <= c1; c++) |
2967 |
|
SET_LIST_BIT (TRANSLATE (c)); |
2968 |
|
} |
2969 |
|
else |
2970 |
|
{ |
2971 |
|
re_wchar_t c0; |
2972 |
|
|
2973 |
|
for (; c <= c1; c++) |
2974 |
{ |
{ |
2975 |
for (this_char = range_start; this_char <= range_end; |
c0 = c; |
2976 |
this_char++) |
if (! multibyte) |
2977 |
SET_LIST_BIT (TRANSLATE (this_char)); |
MAKE_CHAR_MULTIBYTE (c0); |
2978 |
|
c0 = TRANSLATE (c0); |
2979 |
|
MAKE_CHAR_UNIBYTE (c0); |
2980 |
|
SET_LIST_BIT (c0); |
2981 |
} |
} |
2982 |
} |
} |
2983 |
else |
#endif /* not emacs */ |
|
/* ... into range table. */ |
|
|
SET_RANGE_TABLE_WORK_AREA (range_table_work, c, c1); |
|
2984 |
} |
} |
2985 |
|
|
2986 |
/* Discard any (non)matching list bytes that are all 0 at the |
/* Discard any (non)matching list bytes that are all 0 at the |
3554 |
{ |
{ |
3555 |
int len; |
int len; |
3556 |
|
|
3557 |
|
if (! multibyte) |
3558 |
|
MAKE_CHAR_MULTIBYTE (c); |
3559 |
c = TRANSLATE (c); |
c = TRANSLATE (c); |
3560 |
if (multibyte) |
if (target_multibyte) |
3561 |
len = CHAR_STRING (c, b); |
{ |
3562 |
|
len = CHAR_STRING (c, b); |
3563 |
|
b += len; |
3564 |
|
} |
3565 |
else |
else |
3566 |
*b = c, len = 1; |
{ |
3567 |
b += len; |
MAKE_CHAR_UNIBYTE (c); |
3568 |
|
*b++ = c; |
3569 |
|
len = 1; |
3570 |
|
} |
3571 |
(*pending_exact) += len; |
(*pending_exact) += len; |
3572 |
} |
} |
3573 |
|
|
3593 |
/* We have succeeded; set the length of the buffer. */ |
/* We have succeeded; set the length of the buffer. */ |
3594 |
bufp->used = b - bufp->buffer; |
bufp->used = b - bufp->buffer; |
3595 |
|
|
3596 |
|
#ifdef emacs |
3597 |
|
/* Now the buffer is adjusted for the multibyteness of a target. */ |
3598 |
|
bufp->multibyte = bufp->target_multibyte; |
3599 |
|
#endif |
3600 |
|
|
3601 |
#ifdef DEBUG |
#ifdef DEBUG |
3602 |
if (debug > 0) |
if (debug > 0) |
3603 |
{ |
{ |
3843 |
|
|
3844 |
case exactn: |
case exactn: |
3845 |
if (fastmap) |
if (fastmap) |
3846 |
{ |
/* If multibyte is nonzero, the first byte of each |
3847 |
int c = RE_STRING_CHAR (p + 1, pend - p); |
character is an ASCII or a leading code. Otherwise, |
3848 |
|
each byte is a character. Thus, this works in both |
3849 |
if (SINGLE_BYTE_CHAR_P (c)) |
cases. */ |
3850 |
fastmap[c] = 1; |
fastmap[p[1]] = 1; |
|
else |
|
|
fastmap[p[1]] = 1; |
|
|
} |
|
3851 |
break; |
break; |
3852 |
|
|
3853 |
|
|
3859 |
|
|
3860 |
|
|
3861 |
case charset_not: |
case charset_not: |
|
/* Chars beyond end of bitmap are possible matches. |
|
|
All the single-byte codes can occur in multibyte buffers. |
|
|
So any that are not listed in the charset |
|
|
are possible matches, even in multibyte buffers. */ |
|
3862 |
if (!fastmap) break; |
if (!fastmap) break; |
3863 |
for (j = CHARSET_BITMAP_SIZE (&p[-1]) * BYTEWIDTH; |
{ |
3864 |
j < (1 << BYTEWIDTH); j++) |
/* Chars beyond end of bitmap are possible matches. */ |
3865 |
fastmap[j] = 1; |
/* In a multibyte case, the bitmap is used only for ASCII |
3866 |
|
characters. */ |
3867 |
|
int limit = multibyte ? 128 : (1 << BYTEWIDTH); |
3868 |
|
|
3869 |
|
for (j = CHARSET_BITMAP_SIZE (&p[-1]) * BYTEWIDTH; |
3870 |
|
j < limit; j++) |
3871 |
|
fastmap[j] = 1; |
3872 |
|
} |
3873 |
|
|
3874 |
/* Fallthrough */ |
/* Fallthrough */ |
3875 |
case charset: |
case charset: |
3876 |
if (!fastmap) break; |
if (!fastmap) break; |
3881 |
fastmap[j] = 1; |
fastmap[j] = 1; |
3882 |
|
|
3883 |
if ((not && multibyte) |
if ((not && multibyte) |
3884 |
/* Any character set can possibly contain a character |
/* Any leading code can possibly start a character |
3885 |
which doesn't match the specified set of characters. */ |
which doesn't match the specified set of characters. */ |
3886 |
|| (CHARSET_RANGE_TABLE_EXISTS_P (&p[-2]) |
|| (CHARSET_RANGE_TABLE_EXISTS_P (&p[-2]) |
3887 |
&& CHARSET_RANGE_TABLE_BITS (&p[-2]) != 0)) |
&& CHARSET_RANGE_TABLE_BITS (&p[-2]) != 0)) |
3888 |
/* If we can match a character class, we can match |
/* If we can match a character class, we can match |
3889 |
any character set. */ |
any multibyte characters. */ |
3890 |
{ |
{ |
|
set_fastmap_for_multibyte_characters: |
|
3891 |
if (match_any_multibyte_characters == false) |
if (match_any_multibyte_characters == false) |
3892 |
{ |
{ |
3893 |
for (j = 0x80; j < 0xA0; j++) /* XXX */ |
for (j = 0x80; j < (1 << BYTEWIDTH); j++) |
3894 |
if (BASE_LEADING_CODE_P (j)) |
fastmap[j] = 1; |
|
fastmap[j] = 1; |
|
3895 |
match_any_multibyte_characters = true; |
match_any_multibyte_characters = true; |
3896 |
} |
} |
3897 |
} |
} |
3899 |
else if (!not && CHARSET_RANGE_TABLE_EXISTS_P (&p[-2]) |
else if (!not && CHARSET_RANGE_TABLE_EXISTS_P (&p[-2]) |
3900 |
&& match_any_multibyte_characters == false) |
&& match_any_multibyte_characters == false) |
3901 |
{ |
{ |
3902 |
/* Set fastmap[I] 1 where I is a base leading code of each |
/* Set fastmap[I] to 1 where I is a leading code of each |
3903 |
multibyte character in the range table. */ |
multibyte characer in the range table. */ |
3904 |
int c, count; |
int c, count; |
3905 |
|
unsigned char lc1, lc2; |
3906 |
|
|
3907 |
/* Make P points the range table. `+ 2' is to skip flag |
/* Make P points the range table. `+ 2' is to skip flag |
3908 |
bits for a character class. */ |
bits for a character class. */ |
3912 |
EXTRACT_NUMBER_AND_INCR (count, p); |
EXTRACT_NUMBER_AND_INCR (count, p); |
3913 |
for (; count > 0; count--, p += 2 * 3) /* XXX */ |
for (; count > 0; count--, p += 2 * 3) /* XXX */ |
3914 |
{ |
{ |
3915 |
/* Extract the start of each range. */ |
/* Extract the start and end of each range. */ |
3916 |
|
EXTRACT_CHARACTER (c, p); |
3917 |
|
lc1 = CHAR_LEADING_CODE (c); |
3918 |
|
p += 3; |
3919 |
EXTRACT_CHARACTER (c, p); |
EXTRACT_CHARACTER (c, p); |
3920 |
j = CHAR_CHARSET (c); |
lc2 = CHAR_LEADING_CODE (c); |
3921 |
fastmap[CHARSET_LEADING_CODE_BASE (j)] = 1; |
for (j = lc1; j <= lc2; j++) |
3922 |
|
fastmap[j] = 1; |
3923 |
} |
} |
3924 |
} |
} |
3925 |
break; |
break; |
3944 |
if (!fastmap) break; |
if (!fastmap) break; |
3945 |
not = (re_opcode_t)p[-1] == notcategoryspec; |
not = (re_opcode_t)p[-1] == notcategoryspec; |
3946 |
k = *p++; |
k = *p++; |
3947 |
for (j = 0; j < (1 << BYTEWIDTH); j++) |
for (j = (multibyte ? 127 : (1 << BYTEWIDTH)); j >= 0; j--) |
3948 |
if ((CHAR_HAS_CATEGORY (j, k)) ^ not) |
if ((CHAR_HAS_CATEGORY (j, k)) ^ not) |
3949 |
fastmap[j] = 1; |
fastmap[j] = 1; |
3950 |
|
|
3951 |
if (multibyte) |
if (multibyte) |
3952 |
/* Any character set can possibly contain a character |
{ |
3953 |
whose category is K (or not). */ |
/* Any character set can possibly contain a character |
3954 |
goto set_fastmap_for_multibyte_characters; |
whose category is K (or not). */ |
3955 |
|
if (match_any_multibyte_characters == false) |
3956 |
|
{ |
3957 |
|
for (j = 0x80; j < (1 << BYTEWIDTH); j++) |
3958 |
|
fastmap[j] = 1; |
3959 |
|
match_any_multibyte_characters = true; |
3960 |
|
} |
3961 |
|
} |
3962 |
break; |
break; |
3963 |
|
|
3964 |
/* All cases after this match the empty string. These end with |
/* All cases after this match the empty string. These end with |
4206 |
int total_size = size1 + size2; |
int total_size = size1 + size2; |
4207 |
int endpos = startpos + range; |
int endpos = startpos + range; |
4208 |
boolean anchored_start; |
boolean anchored_start; |
4209 |
|
/* Nonzero if BUFP is setup for multibyte characters. We are sure |
4210 |
/* Nonzero if we have to concern multibyte character. */ |
that it is the same as RE_TARGET_MULTIBYTE_P (bufp). */ |
4211 |
const boolean multibyte = RE_MULTIBYTE_P (bufp); |
const boolean multibyte = RE_MULTIBYTE_P (bufp); |
4212 |
|
|
4213 |
/* Check for out-of-range STARTPOS. */ |
/* Check for out-of-range STARTPOS. */ |
4304 |
|
|
4305 |
buf_ch = STRING_CHAR_AND_LENGTH (d, range - lim, |
buf_ch = STRING_CHAR_AND_LENGTH (d, range - lim, |
4306 |
buf_charlen); |
buf_charlen); |
|
|
|
4307 |
buf_ch = RE_TRANSLATE (translate, buf_ch); |
buf_ch = RE_TRANSLATE (translate, buf_ch); |
4308 |
if (buf_ch >= 0400 |
if (fastmap[CHAR_LEADING_CODE (buf_ch)]) |
|
|| fastmap[buf_ch]) |
|
4309 |
break; |
break; |
4310 |
|
|
4311 |
range -= buf_charlen; |
range -= buf_charlen; |
4312 |
d += buf_charlen; |
d += buf_charlen; |
4313 |
} |
} |
4314 |
else |
else |
4315 |
while (range > lim |
while (range > lim) |
|
&& !fastmap[RE_TRANSLATE (translate, *d)]) |
|
4316 |
{ |
{ |
4317 |
|
buf_ch = *d; |
4318 |
|
MAKE_CHAR_MULTIBYTE (buf_ch); |
4319 |
|
buf_ch = RE_TRANSLATE (translate, buf_ch); |
4320 |
|
MAKE_CHAR_UNIBYTE (buf_ch); |
4321 |
|
if (fastmap[buf_ch]) |
4322 |
|
break; |
4323 |
d++; |
d++; |
4324 |
range--; |
range--; |
4325 |
} |
} |
4326 |
} |
} |
4327 |
else |
else |
4328 |
while (range > lim && !fastmap[*d]) |
{ |
4329 |
{ |
if (multibyte) |
4330 |
d++; |
while (range > lim) |
4331 |
range--; |
{ |
4332 |
} |
int buf_charlen; |
4333 |
|
|
4334 |
|
buf_ch = STRING_CHAR_AND_LENGTH (d, range - lim, |
4335 |
|
buf_charlen); |
4336 |
|
if (fastmap[CHAR_LEADING_CODE (buf_ch)]) |
4337 |
|
break; |
4338 |
|
range -= buf_charlen; |
4339 |
|
d += buf_charlen; |
4340 |
|
} |
4341 |
|
else |
4342 |
|
while (range > lim && !fastmap[*d]) |
4343 |
|
{ |
4344 |
|
d++; |
4345 |
|
range--; |
4346 |
|
} |
4347 |
|
} |
4348 |
startpos += irange - range; |
startpos += irange - range; |
4349 |
} |
} |
4350 |
else /* Searching backwards. */ |
else /* Searching backwards. */ |
4352 |
int room = (startpos >= size1 |
int room = (startpos >= size1 |
4353 |
? size2 + size1 - startpos |
? size2 + size1 - startpos |
4354 |
: size1 - startpos); |
: size1 - startpos); |
4355 |
buf_ch = RE_STRING_CHAR (d, room); |
if (multibyte) |
4356 |
buf_ch = TRANSLATE (buf_ch); |
{ |
4357 |
|
buf_ch = STRING_CHAR (d, room); |
4358 |
if (! (buf_ch >= 0400 |
buf_ch = TRANSLATE (buf_ch); |
4359 |
|| fastmap[buf_ch])) |
if (! fastmap[CHAR_LEADING_CODE (buf_ch)]) |
4360 |
goto advance; |
goto advance; |
4361 |
|
} |
4362 |
|
else |
4363 |
|
{ |
4364 |
|
if (! fastmap[TRANSLATE (*d)]) |
4365 |
|
goto advance; |
4366 |
|
} |
4367 |
} |
} |
4368 |
} |
} |
4369 |
|
|
4660 |
|
|
4661 |
/* Test if C is listed in charset (or charset_not) |
/* Test if C is listed in charset (or charset_not) |
4662 |
at `p1'. */ |
at `p1'. */ |
4663 |
if (SINGLE_BYTE_CHAR_P (c)) |
if (! multibyte || IS_REAL_ASCII (c)) |
4664 |
{ |
{ |
4665 |
if (c < CHARSET_BITMAP_SIZE (p1) * BYTEWIDTH |
if (c < CHARSET_BITMAP_SIZE (p1) * BYTEWIDTH |
4666 |
&& p1[2 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) |
&& p1[2 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) |
4703 |
size of bitmap table of P1 is extracted by |
size of bitmap table of P1 is extracted by |
4704 |
using macro `CHARSET_BITMAP_SIZE'. |
using macro `CHARSET_BITMAP_SIZE'. |
4705 |
|
|
4706 |
Since we know that all the character listed in |
In a multibyte case, we know that all the character |
4707 |
P2 is ASCII, it is enough to test only bitmap |
listed in P2 is ASCII. In a unibyte case, P1 has only a |
4708 |
table of P1. */ |
bitmap table. So, in both cases, it is enough to test |
4709 |
|
only the bitmap table of P1. */ |
4710 |
|
|
4711 |
if ((re_opcode_t) *p1 == charset) |
if ((re_opcode_t) *p1 == charset) |
4712 |
{ |
{ |
4864 |
} |
} |
4865 |
WEAK_ALIAS (__re_match_2, re_match_2) |
WEAK_ALIAS (__re_match_2, re_match_2) |
4866 |
|
|
4867 |
|
#ifdef emacs |
4868 |
|
#define TRANSLATE_VIA_MULTIBYTE(c) \ |
4869 |
|
do { \ |
4870 |
|
if (multibyte) \ |
4871 |
|
(c) = TRANSLATE (c); \ |
4872 |
|
else \ |
4873 |
|
{ \ |
4874 |
|
MAKE_CHAR_MULTIBYTE (c); \ |
4875 |
|
(c) = TRANSLATE (c); \ |
4876 |
|
MAKE_CHAR_UNIBYTE (c); \ |
4877 |
|
} \ |
4878 |
|
} while (0) |
4879 |
|
|
4880 |
|
#else |
4881 |
|
#define TRANSLATE_VIA_MULTIBYTE(c) ((c) = TRANSLATE (c)) |
4882 |
|
#endif |
4883 |
|
|
4884 |
|
|
4885 |
/* This is a separate function so that we can force an alloca cleanup |
/* This is a separate function so that we can force an alloca cleanup |
4886 |
afterwards. */ |
afterwards. */ |
4887 |
static int |
static int |
4921 |
/* We use this to map every character in the string. */ |
/* We use this to map every character in the string. */ |
4922 |
RE_TRANSLATE_TYPE translate = bufp->translate; |
RE_TRANSLATE_TYPE translate = bufp->translate; |
4923 |
|
|
4924 |
/* Nonzero if we have to concern multibyte character. */ |
/* Nonzero if BUFP is setup for multibyte characters. We are sure |
4925 |
|
that it is the same as RE_TARGET_MULTIBYTE_P (bufp). */ |
4926 |
const boolean multibyte = RE_MULTIBYTE_P (bufp); |
const boolean multibyte = RE_MULTIBYTE_P (bufp); |
4927 |
|
|
4928 |
/* Failure point stack. Each place that can handle a failure further |
/* Failure point stack. Each place that can handle a failure further |
5276 |
/* Remember the start point to rollback upon failure. */ |
/* Remember the start point to rollback upon failure. */ |
5277 |
dfail = d; |
dfail = d; |
5278 |
|
|
5279 |
|
#ifndef emacs |
5280 |
/* This is written out as an if-else so we don't waste time |
/* This is written out as an if-else so we don't waste time |
5281 |
testing `translate' inside the loop. */ |
testing `translate' inside the loop. */ |
5282 |
if (RE_TRANSLATE_P (translate)) |
if (RE_TRANSLATE_P (translate)) |
5283 |
{ |
do |
5284 |
if (multibyte) |
{ |
5285 |
do |
PREFETCH (); |
5286 |
|
if (RE_TRANSLATE (translate, *d) != *p++) |
5287 |
{ |
{ |
5288 |
int pat_charlen, buf_charlen; |
d = dfail; |
5289 |
unsigned int pat_ch, buf_ch; |
goto fail; |
5290 |
|
} |
5291 |
PREFETCH (); |
d++; |
5292 |
pat_ch = STRING_CHAR_AND_LENGTH (p, pend - p, pat_charlen); |
} |
5293 |
buf_ch = STRING_CHAR_AND_LENGTH (d, dend - d, buf_charlen); |
while (--mcnt); |
5294 |
|
else |
5295 |
|
do |
5296 |
|
{ |
5297 |
|
PREFETCH (); |
5298 |
|
if (*d++ != *p++) |
5299 |
|
{ |
5300 |
|
d = dfail; |
5301 |
|
goto fail; |
5302 |
|
} |
5303 |
|
} |
5304 |
|
while (--mcnt); |
5305 |
|
#else /* emacs */ |
5306 |
|
/* The cost of testing `translate' is comparatively small. */ |
5307 |
|
if (multibyte) |
5308 |
|
do |
5309 |
|
{ |
5310 |
|
int pat_charlen, buf_charlen; |
5311 |
|
unsigned int pat_ch, buf_ch; |
5312 |
|
|
5313 |
if (RE_TRANSLATE (translate, buf_ch) |
PREFETCH (); |
5314 |
!= pat_ch) |
pat_ch = STRING_CHAR_AND_LENGTH (p, pend - p, pat_charlen); |
5315 |
{ |
buf_ch = STRING_CHAR_AND_LENGTH (d, dend - d, buf_charlen); |
|
d = dfail; |
|
|
goto fail; |
|
|
} |
|
5316 |
|
|
5317 |
p += pat_charlen; |
if (TRANSLATE (buf_ch) != pat_ch) |
|
d += buf_charlen; |
|
|
mcnt -= pat_charlen; |
|
|
} |
|
|
while (mcnt > 0); |
|
|
else |
|
|
do |
|
5318 |
{ |
{ |
5319 |
PREFETCH (); |
d = dfail; |
5320 |
if (RE_TRANSLATE (translate, *d) != *p++) |
goto fail; |
|
{ |
|
|
d = dfail; |
|
|
goto fail; |
|
|
} |
|
|
d++; |
|
5321 |
} |
} |
5322 |
while (--mcnt); |
|
5323 |
} |
p += pat_charlen; |
5324 |
|
d += buf_charlen; |
5325 |
|
mcnt -= pat_charlen; |
5326 |
|
} |
5327 |
|
while (mcnt > 0); |
5328 |
else |
else |
5329 |
{ |
do |
5330 |
do |
{ |
5331 |
{ |
unsigned int buf_ch; |
5332 |
PREFETCH (); |
|
5333 |
if (*d++ != *p++) |
PREFETCH (); |
5334 |
{ |
buf_ch = *d++; |
5335 |
d = dfail; |
TRANSLATE_VIA_MULTIBYTE (buf_ch); |
5336 |
goto fail; |
if (buf_ch != *p++) |
5337 |
} |
{ |
5338 |
} |
d = dfail; |
5339 |
while (--mcnt); |
goto fail; |
5340 |
} |
} |
5341 |
|
} |
5342 |
|
while (--mcnt); |
5343 |
|
#endif |
5344 |
break; |
break; |
5345 |
|
|
5346 |
|
|
5398 |
|
|
5399 |
PREFETCH (); |
PREFETCH (); |
5400 |
c = RE_STRING_CHAR_AND_LENGTH (d, dend - d, len); |
c = RE_STRING_CHAR_AND_LENGTH (d, dend - d, len); |
5401 |
c = TRANSLATE (c); /* The character to match. */ |
TRANSLATE_VIA_MULTIBYTE (c); /* The character to match. */ |
5402 |
|
|
5403 |
if (SINGLE_BYTE_CHAR_P (c)) |
if (! multibyte || IS_REAL_ASCII (c)) |
5404 |
{ /* Lookup bitmap. */ |
{ /* Lookup bitmap. */ |
5405 |
/* Cast to `unsigned' instead of `unsigned char' in |
/* Cast to `unsigned' instead of `unsigned char' in |
5406 |
case the bit list is a full 32 bytes long. */ |
case the bit list is a full 32 bytes long. */ |
5563 |
} |
} |
5564 |
else |
else |
5565 |
{ |
{ |
5566 |
unsigned char c; |
unsigned c; |
5567 |
GET_CHAR_BEFORE_2 (c, d, string1, end1, string2, end2); |
GET_CHAR_BEFORE_2 (c, d, string1, end1, string2, end2); |
5568 |
if (c == '\n') |
if (c == '\n') |
5569 |
break; |
break; |
5832 |
is the character at D, and S2 is the syntax of C2. */ |
is the character at D, and S2 is the syntax of C2. */ |
5833 |
re_wchar_t c1, c2; |
re_wchar_t c1, c2; |
5834 |
int s1, s2; |
int s1, s2; |
5835 |
|
int dummy; |
5836 |
#ifdef emacs |
#ifdef emacs |
5837 |
int offset = PTR_TO_OFFSET (d - 1); |
int offset = PTR_TO_OFFSET (d - 1); |
5838 |
int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); |
int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); |
5844 |
UPDATE_SYNTAX_TABLE_FORWARD (charpos + 1); |
UPDATE_SYNTAX_TABLE_FORWARD (charpos + 1); |
5845 |
#endif |
#endif |
5846 |
PREFETCH_NOLIMIT (); |
PREFETCH_NOLIMIT (); |
5847 |
c2 = RE_STRING_CHAR (d, dend - d); |
GET_CHAR_AFTER (c2, d, dummy); |
5848 |
s2 = SYNTAX (c2); |
s2 = SYNTAX (c2); |
5849 |
|
|
5850 |
if (/* Case 2: Only one of S1 and S2 is Sword. */ |
if (/* Case 2: Only one of S1 and S2 is Sword. */ |
5873 |
is the character at D, and S2 is the syntax of C2. */ |
is the character at D, and S2 is the syntax of C2. */ |
5874 |
re_wchar_t c1, c2; |
re_wchar_t c1, c2; |
5875 |
int s1, s2; |
int s1, s2; |
5876 |
|
int dummy; |
5877 |
#ifdef emacs |
#ifdef emacs |
5878 |
int offset = PTR_TO_OFFSET (d); |
int offset = PTR_TO_OFFSET (d); |
5879 |
int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); |
int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); |
5880 |
UPDATE_SYNTAX_TABLE (charpos); |
UPDATE_SYNTAX_TABLE (charpos); |
5881 |
#endif |
#endif |
5882 |
PREFETCH (); |
PREFETCH (); |
5883 |
c2 = RE_STRING_CHAR (d, dend - d); |
GET_CHAR_AFTER (c2, d, dummy); |
5884 |
s2 = SYNTAX (c2); |
s2 = SYNTAX (c2); |
5885 |
|
|
5886 |
/* Case 2: S2 is not Sword. */ |
/* Case 2: S2 is not Sword. */ |
5918 |
is the character at D, and S2 is the syntax of C2. */ |
is the character at D, and S2 is the syntax of C2. */ |
5919 |
re_wchar_t c1, c2; |
re_wchar_t c1, c2; |
5920 |
int s1, s2; |
int s1, s2; |
5921 |
|
int dummy; |
5922 |
#ifdef emacs |
#ifdef emacs |
5923 |
int offset = PTR_TO_OFFSET (d) - 1; |
int offset = PTR_TO_OFFSET (d) - 1; |
5924 |
int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); |
int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset); |
5935 |
if (!AT_STRINGS_END (d)) |
if (!AT_STRINGS_END (d)) |
5936 |
{ |
{ |
5937 |
PREFETCH_NOLIMIT (); |
PREFETCH_NOLIMIT (); |
5938 |
c2 = RE_STRING_CHAR (d, dend - d); |
GET_CHAR_AFTER (c2, d, dummy); |
5939 |
#ifdef emacs |
#ifdef emacs |
5940 |
UPDATE_SYNTAX_TABLE_FORWARD (charpos); |
UPDATE_SYNTAX_TABLE_FORWARD (charpos); |
5941 |
#endif |
#endif |
5966 |
int len; |
int len; |
5967 |
re_wchar_t c; |
re_wchar_t c; |
5968 |
|
|
5969 |
c = RE_STRING_CHAR_AND_LENGTH (d, dend - d, len); |
GET_CHAR_AFTER (c, d, len); |
|
|
|
5970 |
if ((SYNTAX (c) != (enum syntaxcode) mcnt) ^ not) |
if ((SYNTAX (c) != (enum syntaxcode) mcnt) ^ not) |
5971 |
goto fail; |
goto fail; |
5972 |
d += len; |
d += len; |
6002 |
int len; |
int len; |
6003 |
re_wchar_t c; |
re_wchar_t c; |
6004 |
|
|
6005 |
c = RE_STRING_CHAR_AND_LENGTH (d, dend - d, len); |
GET_CHAR_AFTER (c, d, len); |
|
|
|
6006 |
if ((!CHAR_HAS_CATEGORY (c, mcnt)) ^ not) |
if ((!CHAR_HAS_CATEGORY (c, mcnt)) ^ not) |
6007 |
goto fail; |
goto fail; |
6008 |
d += len; |
d += len; |
6094 |
int p1_charlen, p2_charlen; |
int p1_charlen, p2_charlen; |
6095 |
re_wchar_t p1_ch, p2_ch; |
re_wchar_t p1_ch, p2_ch; |
6096 |
|
|
6097 |
p1_ch = RE_STRING_CHAR_AND_LENGTH (p1, p1_end - p1, p1_charlen); |
GET_CHAR_AFTER (p1_ch, p1, p1_charlen); |
6098 |
p2_ch = RE_STRING_CHAR_AND_LENGTH (p2, p2_end - p2, p2_charlen); |
GET_CHAR_AFTER (p2_ch, p2, p2_charlen); |
6099 |
|
|
6100 |
if (RE_TRANSLATE (translate, p1_ch) |
if (RE_TRANSLATE (translate, p1_ch) |
6101 |
!= RE_TRANSLATE (translate, p2_ch)) |
!= RE_TRANSLATE (translate, p2_ch)) |