| 2199 | `regex_compile' itself. */ |
| 2200 | |
| 2201 | static reg_errcode_t |
| 2202 | compile_range (p_ptr, pend, translate, syntax, b) |
| 2203 | const char **p_ptr, *pend; |
| 2204 | char *translate; |
| 2205 | reg_syntax_t syntax; |
| 2206 | unsigned char *b; |
| 2207 | { |
| 2208 | unsigned this_char; |
| 2209 | |
| 2210 | const char *p = *p_ptr; |
| 2211 | int range_start, range_end; |
| 2212 | |
| 2213 | if (p == pend) |
| 2214 | return REG_ERANGE; |
| 2215 | |
| 2216 | /* Even though the pattern is a signed `char *', we need to fetch |
| 2217 | with unsigned char *'s; if the high bit of the pattern character |
| 2218 | is set, the range endpoints will be negative if we fetch using a |
| 2219 | signed char *. |
| 2220 | |
| 2221 | We also want to fetch the endpoints without translating them; the |
| 2222 | appropriate translation is done in the bit-setting loop below. */ |
| 2223 | range_start = ((unsigned char *) p)[-2]; |
| 2224 | range_end = ((unsigned char *) p)[0]; |
| 2225 | |
| 2226 | /* Have to increment the pointer into the pattern string, so the |
| 2227 | caller isn't still at the ending character. */ |
| 2228 | (*p_ptr)++; |
| 2229 | |
| 2230 | /* If the start is after the end, the range is empty. */ |
| 2231 | if (range_start > range_end) |
| 2232 | return syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR; |
| 2233 | |
| 2234 | /* Here we see why `this_char' has to be larger than an `unsigned |
| 2235 | char' -- the range is inclusive, so if `range_end' == 0xff |
| 2236 | (assuming 8-bit characters), we would otherwise go into an infinite |
| 2237 | loop, since all characters <= 0xff. */ |
| 2238 | for (this_char = range_start; this_char <= range_end; this_char++) |
| 2239 | { |
| 2240 | SET_LIST_BIT (TRANSLATE (this_char)); |
| 2241 | } |
| 2242 | |
| 2243 | return REG_NOERROR; |
| 2244 | } |
| 2245 | |
| 2246 | /* Failure stack declarations and macros; both re_compile_fastmap and |
| 2247 | re_match_2 use a failure stack. These have to be macros because of |