| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#if defined (_AIX) && !defined (REGEX_MALLOC) |
| 24 |
#pragma alloca |
| 25 |
#endif |
| 26 |
|
| 27 |
#ifndef _GNU_SOURCE |
| 28 |
#define _GNU_SOURCE |
| 29 |
#endif |
| 30 |
|
| 31 |
|
| 32 |
#include <sys/types.h> |
| 33 |
|
| 34 |
#ifdef HAVE_CONFIG_H |
| 35 |
#include "config.h" |
| 36 |
#endif |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
#ifdef emacs |
| 41 |
|
| 42 |
#include "lisp.h" |
| 43 |
#include "buffer.h" |
| 44 |
#include "syntax.h" |
| 45 |
|
| 46 |
|
| 47 |
#undef NULL |
| 48 |
|
| 49 |
#else |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
#if HAVE_STRING_H || STDC_HEADERS |
| 54 |
#include <string.h> |
| 55 |
#ifndef bcmp |
| 56 |
#define bcmp(s1, s2, n) memcmp ((s1), (s2), (n)) |
| 57 |
#endif |
| 58 |
#ifndef bcopy |
| 59 |
#define bcopy(s, d, n) memcpy ((d), (s), (n)) |
| 60 |
#endif |
| 61 |
#ifndef bzero |
| 62 |
#define bzero(s, n) memset ((s), 0, (n)) |
| 63 |
#endif |
| 64 |
#else |
| 65 |
#include <strings.h> |
| 66 |
#endif |
| 67 |
|
| 68 |
#ifdef STDC_HEADERS |
| 69 |
#include <stdlib.h> |
| 70 |
#else |
| 71 |
char *malloc (); |
| 72 |
char *realloc (); |
| 73 |
#endif |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
#ifndef Sword |
| 81 |
#define Sword 1 |
| 82 |
#endif |
| 83 |
|
| 84 |
#ifdef SYNTAX_TABLE |
| 85 |
|
| 86 |
extern char *re_syntax_table; |
| 87 |
|
| 88 |
#else |
| 89 |
|
| 90 |
|
| 91 |
#define CHAR_SET_SIZE 256 |
| 92 |
|
| 93 |
static char re_syntax_table[CHAR_SET_SIZE]; |
| 94 |
|
| 95 |
static void |
| 96 |
init_syntax_once () |
| 97 |
{ |
| 98 |
register int c; |
| 99 |
static int done = 0; |
| 100 |
|
| 101 |
if (done) |
| 102 |
return; |
| 103 |
|
| 104 |
bzero (re_syntax_table, sizeof re_syntax_table); |
| 105 |
|
| 106 |
for (c = 'a'; c <= 'z'; c++) |
| 107 |
re_syntax_table[c] = Sword; |
| 108 |
|
| 109 |
for (c = 'A'; c <= 'Z'; c++) |
| 110 |
re_syntax_table[c] = Sword; |
| 111 |
|
| 112 |
for (c = '0'; c <= '9'; c++) |
| 113 |
re_syntax_table[c] = Sword; |
| 114 |
|
| 115 |
re_syntax_table['_'] = Sword; |
| 116 |
|
| 117 |
done = 1; |
| 118 |
} |
| 119 |
|
| 120 |
#endif |
| 121 |
|
| 122 |
#define SYNTAX(c) re_syntax_table[c] |
| 123 |
|
| 124 |
#endif |
| 125 |
|
| 126 |
|
| 127 |
#include "regex.h" |
| 128 |
|
| 129 |
|
| 130 |
#include <ctype.h> |
| 131 |
|
| 132 |
#ifndef isascii |
| 133 |
#define isascii(c) 1 |
| 134 |
#endif |
| 135 |
|
| 136 |
#ifdef isblank |
| 137 |
#define ISBLANK(c) (isascii (c) && isblank (c)) |
| 138 |
#else |
| 139 |
#define ISBLANK(c) ((c) == ' ' || (c) == '\t') |
| 140 |
#endif |
| 141 |
#ifdef isgraph |
| 142 |
#define ISGRAPH(c) (isascii (c) && isgraph (c)) |
| 143 |
#else |
| 144 |
#define ISGRAPH(c) (isascii (c) && isprint (c) && !isspace (c)) |
| 145 |
#endif |
| 146 |
|
| 147 |
#define ISPRINT(c) (isascii (c) && isprint (c)) |
| 148 |
#define ISDIGIT(c) (isascii (c) && isdigit (c)) |
| 149 |
#define ISALNUM(c) (isascii (c) && isalnum (c)) |
| 150 |
#define ISALPHA(c) (isascii (c) && isalpha (c)) |
| 151 |
#define ISCNTRL(c) (isascii (c) && iscntrl (c)) |
| 152 |
#define ISLOWER(c) (isascii (c) && islower (c)) |
| 153 |
#define ISPUNCT(c) (isascii (c) && ispunct (c)) |
| 154 |
#define ISSPACE(c) (isascii (c) && isspace (c)) |
| 155 |
#define ISUPPER(c) (isascii (c) && isupper (c)) |
| 156 |
#define ISXDIGIT(c) (isascii (c) && isxdigit (c)) |
| 157 |
|
| 158 |
#ifndef NULL |
| 159 |
#define NULL 0 |
| 160 |
#endif |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
#undef SIGN_EXTEND_CHAR |
| 167 |
#if __STDC__ |
| 168 |
#define SIGN_EXTEND_CHAR(c) ((signed char) (c)) |
| 169 |
#else |
| 170 |
|
| 171 |
#define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128) |
| 172 |
#endif |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
#ifdef REGEX_MALLOC |
| 185 |
|
| 186 |
#define REGEX_ALLOCATE malloc |
| 187 |
#define REGEX_REALLOCATE(source, osize, nsize) realloc (source, nsize) |
| 188 |
|
| 189 |
#else |
| 190 |
|
| 191 |
|
| 192 |
#ifndef alloca |
| 193 |
|
| 194 |
|
| 195 |
#ifdef __GNUC__ |
| 196 |
#define alloca __builtin_alloca |
| 197 |
#else |
| 198 |
#if HAVE_ALLOCA_H |
| 199 |
#include <alloca.h> |
| 200 |
#else |
| 201 |
#ifndef _AIX |
| 202 |
char *alloca (); |
| 203 |
#endif |
| 204 |
#endif |
| 205 |
#endif |
| 206 |
|
| 207 |
#endif |
| 208 |
|
| 209 |
#define REGEX_ALLOCATE alloca |
| 210 |
|
| 211 |
|
| 212 |
#define REGEX_REALLOCATE(source, osize, nsize) \ |
| 213 |
(destination = (char *) alloca (nsize), \ |
| 214 |
bcopy (source, destination, osize), \ |
| 215 |
destination) |
| 216 |
|
| 217 |
#endif |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
#define FIRST_STRING_P(ptr) \ |
| 224 |
(size1 && string1 <= (ptr) && (ptr) <= string1 + size1) |
| 225 |
|
| 226 |
|
| 227 |
#define TALLOC(n, t) ((t *) malloc ((n) * sizeof (t))) |
| 228 |
#define RETALLOC(addr, n, t) ((addr) = (t *) realloc (addr, (n) * sizeof (t))) |
| 229 |
#define REGEX_TALLOC(n, t) ((t *) REGEX_ALLOCATE ((n) * sizeof (t))) |
| 230 |
|
| 231 |
#define BYTEWIDTH 8 |
| 232 |
|
| 233 |
#define STREQ(s1, s2) ((strcmp (s1, s2) == 0)) |
| 234 |
|
| 235 |
#define MAX(a, b) ((a) > (b) ? (a) : (b)) |
| 236 |
#define MIN(a, b) ((a) < (b) ? (a) : (b)) |
| 237 |
|
| 238 |
typedef char boolean; |
| 239 |
#define false 0 |
| 240 |
#define true 1 |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
typedef enum |
| 252 |
{ |
| 253 |
no_op = 0, |
| 254 |
|
| 255 |
|
| 256 |
exactn = 1, |
| 257 |
|
| 258 |
|
| 259 |
anychar, |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
charset, |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
charset_not, |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
start_memory, |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
stop_memory, |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
duplicate, |
| 294 |
|
| 295 |
|
| 296 |
begline, |
| 297 |
|
| 298 |
|
| 299 |
endline, |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
begbuf, |
| 304 |
|
| 305 |
|
| 306 |
endbuf, |
| 307 |
|
| 308 |
|
| 309 |
jump, |
| 310 |
|
| 311 |
|
| 312 |
jump_past_alt, |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
on_failure_jump, |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
on_failure_keep_string_jump, |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
pop_failure_jump, |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
maybe_pop_jump, |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
dummy_failure_jump, |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
push_dummy_failure, |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
succeed_n, |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
jump_n, |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
set_number_at, |
| 358 |
|
| 359 |
wordchar, |
| 360 |
notwordchar, |
| 361 |
|
| 362 |
wordbeg, |
| 363 |
wordend, |
| 364 |
|
| 365 |
wordbound, |
| 366 |
notwordbound |
| 367 |
|
| 368 |
#ifdef emacs |
| 369 |
,before_dot, |
| 370 |
at_dot, |
| 371 |
after_dot, |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
syntaxspec, |
| 376 |
|
| 377 |
|
| 378 |
notsyntaxspec |
| 379 |
#endif |
| 380 |
} re_opcode_t; |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
#define STORE_NUMBER(destination, number) \ |
| 387 |
do { \ |
| 388 |
(destination)[0] = (number) & 0377; \ |
| 389 |
(destination)[1] = (number) >> 8; \ |
| 390 |
} while (0) |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
#define STORE_NUMBER_AND_INCR(destination, number) \ |
| 397 |
do { \ |
| 398 |
STORE_NUMBER (destination, number); \ |
| 399 |
(destination) += 2; \ |
| 400 |
} while (0) |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
#define EXTRACT_NUMBER(destination, source) \ |
| 406 |
do { \ |
| 407 |
(destination) = *(source) & 0377; \ |
| 408 |
(destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \ |
| 409 |
} while (0) |
| 410 |
|
| 411 |
#ifdef DEBUG |
| 412 |
static void |
| 413 |
extract_number (dest, source) |
| 414 |
int *dest; |
| 415 |
unsigned char *source; |
| 416 |
{ |
| 417 |
int temp = SIGN_EXTEND_CHAR (*(source + 1)); |
| 418 |
*dest = *source & 0377; |
| 419 |
*dest += temp << 8; |
| 420 |
} |
| 421 |
|
| 422 |
#ifndef EXTRACT_MACROS |
| 423 |
#undef EXTRACT_NUMBER |
| 424 |
#define EXTRACT_NUMBER(dest, src) extract_number (&dest, src) |
| 425 |
#endif |
| 426 |
|
| 427 |
#endif |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
#define EXTRACT_NUMBER_AND_INCR(destination, source) \ |
| 433 |
do { \ |
| 434 |
EXTRACT_NUMBER (destination, source); \ |
| 435 |
(source) += 2; \ |
| 436 |
} while (0) |
| 437 |
|
| 438 |
#ifdef DEBUG |
| 439 |
static void |
| 440 |
extract_number_and_incr (destination, source) |
| 441 |
int *destination; |
| 442 |
unsigned char **source; |
| 443 |
{ |
| 444 |
extract_number (destination, *source); |
| 445 |
*source += 2; |
| 446 |
} |
| 447 |
|
| 448 |
#ifndef EXTRACT_MACROS |
| 449 |
#undef EXTRACT_NUMBER_AND_INCR |
| 450 |
#define EXTRACT_NUMBER_AND_INCR(dest, src) \ |
| 451 |
extract_number_and_incr (&dest, &src) |
| 452 |
#endif |
| 453 |
|
| 454 |
#endif |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
#ifdef DEBUG |
| 463 |
|
| 464 |
|
| 465 |
#include <stdio.h> |
| 466 |
|
| 467 |
|
| 468 |
#include <assert.h> |
| 469 |
|
| 470 |
static int debug = 0; |
| 471 |
|
| 472 |
#define DEBUG_STATEMENT(e) e |
| 473 |
#define DEBUG_PRINT1(x) if (debug) printf (x) |
| 474 |
#define DEBUG_PRINT2(x1, x2) if (debug) printf (x1, x2) |
| 475 |
#define DEBUG_PRINT3(x1, x2, x3) if (debug) printf (x1, x2, x3) |
| 476 |
#define DEBUG_PRINT4(x1, x2, x3, x4) if (debug) printf (x1, x2, x3, x4) |
| 477 |
#define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \ |
| 478 |
if (debug) print_partial_compiled_pattern (s, e) |
| 479 |
#define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \ |
| 480 |
if (debug) print_double_string (w, s1, sz1, s2, sz2) |
| 481 |
|
| 482 |
|
| 483 |
extern void printchar (); |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
void |
| 488 |
print_fastmap (fastmap) |
| 489 |
char *fastmap; |
| 490 |
{ |
| 491 |
unsigned was_a_range = 0; |
| 492 |
unsigned i = 0; |
| 493 |
|
| 494 |
while (i < (1 << BYTEWIDTH)) |
| 495 |
{ |
| 496 |
if (fastmap[i++]) |
| 497 |
{ |
| 498 |
was_a_range = 0; |
| 499 |
printchar (i - 1); |
| 500 |
while (i < (1 << BYTEWIDTH) && fastmap[i]) |
| 501 |
{ |
| 502 |
was_a_range = 1; |
| 503 |
i++; |
| 504 |
} |
| 505 |
if (was_a_range) |
| 506 |
{ |
| 507 |
printf ("-"); |
| 508 |
printchar (i - 1); |
| 509 |
} |
| 510 |
} |
| 511 |
} |
| 512 |
putchar ('\n'); |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
void |
| 520 |
print_partial_compiled_pattern (start, end) |
| 521 |
unsigned char *start; |
| 522 |
unsigned char *end; |
| 523 |
{ |
| 524 |
int mcnt, mcnt2; |
| 525 |
unsigned char *p = start; |
| 526 |
unsigned char *pend = end; |
| 527 |
|
| 528 |
if (start == NULL) |
| 529 |
{ |
| 530 |
printf ("(null)\n"); |
| 531 |
return; |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
while (p < pend) |
| 536 |
{ |
| 537 |
switch ((re_opcode_t) *p++) |
| 538 |
{ |
| 539 |
case no_op: |
| 540 |
printf ("/no_op"); |
| 541 |
break; |
| 542 |
|
| 543 |
case exactn: |
| 544 |
mcnt = *p++; |
| 545 |
printf ("/exactn/%d", mcnt); |
| 546 |
do |
| 547 |
{ |
| 548 |
putchar ('/'); |
| 549 |
printchar (*p++); |
| 550 |
} |
| 551 |
while (--mcnt); |
| 552 |
break; |
| 553 |
|
| 554 |
case start_memory: |
| 555 |
mcnt = *p++; |
| 556 |
printf ("/start_memory/%d/%d", mcnt, *p++); |
| 557 |
break; |
| 558 |
|
| 559 |
case stop_memory: |
| 560 |
mcnt = *p++; |
| 561 |
printf ("/stop_memory/%d/%d", mcnt, *p++); |
| 562 |
break; |
| 563 |
|
| 564 |
case duplicate: |
| 565 |
printf ("/duplicate/%d", *p++); |
| 566 |
break; |
| 567 |
|
| 568 |
case anychar: |
| 569 |
printf ("/anychar"); |
| 570 |
break; |
| 571 |
|
| 572 |
case charset: |
| 573 |
case charset_not: |
| 574 |
{ |
| 575 |
register int c; |
| 576 |
|
| 577 |
printf ("/charset%s", |
| 578 |
(re_opcode_t) *(p - 1) == charset_not ? "_not" : ""); |
| 579 |
|
| 580 |
assert (p + *p < pend); |
| 581 |
|
| 582 |
for (c = 0; c < *p; c++) |
| 583 |
{ |
| 584 |
unsigned bit; |
| 585 |
unsigned char map_byte = p[1 + c]; |
| 586 |
|
| 587 |
putchar ('/'); |
| 588 |
|
| 589 |
for (bit = 0; bit < BYTEWIDTH; bit++) |
| 590 |
if (map_byte & (1 << bit)) |
| 591 |
printchar (c * BYTEWIDTH + bit); |
| 592 |
} |
| 593 |
p += 1 + *p; |
| 594 |
break; |
| 595 |
} |
| 596 |
|
| 597 |
case begline: |
| 598 |
printf ("/begline"); |
| 599 |
break; |
| 600 |
|
| 601 |
case endline: |
| 602 |
printf ("/endline"); |
| 603 |
break; |
| 604 |
|
| 605 |
case on_failure_jump: |
| 606 |
extract_number_and_incr (&mcnt, &p); |
| 607 |
printf ("/on_failure_jump/0/%d", mcnt); |
| 608 |
break; |
| 609 |
|
| 610 |
case on_failure_keep_string_jump: |
| 611 |
extract_number_and_incr (&mcnt, &p); |
| 612 |
printf ("/on_failure_keep_string_jump/0/%d", mcnt); |
| 613 |
break; |
| 614 |
|
| 615 |
case dummy_failure_jump: |
| 616 |
extract_number_and_incr (&mcnt, &p); |
| 617 |
printf ("/dummy_failure_jump/0/%d", mcnt); |
| 618 |
break; |
| 619 |
|
| 620 |
case push_dummy_failure: |
| 621 |
printf ("/push_dummy_failure"); |
| 622 |
break; |
| 623 |
|
| 624 |
case maybe_pop_jump: |
| 625 |
extract_number_and_incr (&mcnt, &p); |
| 626 |
printf ("/maybe_pop_jump/0/%d", mcnt); |
| 627 |
break; |
| 628 |
|
| 629 |
case pop_failure_jump: |
| 630 |
extract_number_and_incr (&mcnt, &p); |
| 631 |
printf ("/pop_failure_jump/0/%d", mcnt); |
| 632 |
break; |
| 633 |
|
| 634 |
case jump_past_alt: |
| 635 |
extract_number_and_incr (&mcnt, &p); |
| 636 |
printf ("/jump_past_alt/0/%d", mcnt); |
| 637 |
break; |
| 638 |
|
| 639 |
case jump: |
| 640 |
extract_number_and_incr (&mcnt, &p); |
| 641 |
printf ("/jump/0/%d", mcnt); |
| 642 |
break; |
| 643 |
|
| 644 |
case succeed_n: |
| 645 |
extract_number_and_incr (&mcnt, &p); |
| 646 |
extract_number_and_incr (&mcnt2, &p); |
| 647 |
printf ("/succeed_n/0/%d/0/%d", mcnt, mcnt2); |
| 648 |
break; |
| 649 |
|
| 650 |
case jump_n: |
| 651 |
extract_number_and_incr (&mcnt, &p); |
| 652 |
extract_number_and_incr (&mcnt2, &p); |
| 653 |
printf ("/jump_n/0/%d/0/%d", mcnt, mcnt2); |
| 654 |
break; |
| 655 |
|
| 656 |
case set_number_at: |
| 657 |
extract_number_and_incr (&mcnt, &p); |
| 658 |
extract_number_and_incr (&mcnt2, &p); |
| 659 |
printf ("/set_number_at/0/%d/0/%d", mcnt, mcnt2); |
| 660 |
break; |
| 661 |
|
| 662 |
case wordbound: |
| 663 |
printf ("/wordbound"); |
| 664 |
break; |
| 665 |
|
| 666 |
case notwordbound: |
| 667 |
printf ("/notwordbound"); |
| 668 |
break; |
| 669 |
|
| 670 |
case wordbeg: |
| 671 |
printf ("/wordbeg"); |
| 672 |
break; |
| 673 |
|
| 674 |
case wordend: |
| 675 |
printf ("/wordend"); |
| 676 |
|
| 677 |
#ifdef emacs |
| 678 |
case before_dot: |
| 679 |
printf ("/before_dot"); |
| 680 |
break; |
| 681 |
|
| 682 |
case at_dot: |
| 683 |
printf ("/at_dot"); |
| 684 |
break; |
| 685 |
|
| 686 |
case after_dot: |
| 687 |
printf ("/after_dot"); |
| 688 |
break; |
| 689 |
|
| 690 |
case syntaxspec: |
| 691 |
printf ("/syntaxspec"); |
| 692 |
mcnt = *p++; |
| 693 |
printf ("/%d", mcnt); |
| 694 |
break; |
| 695 |
|
| 696 |
case notsyntaxspec: |
| 697 |
printf ("/notsyntaxspec"); |
| 698 |
mcnt = *p++; |
| 699 |
printf ("/%d", mcnt); |
| 700 |
break; |
| 701 |
#endif |
| 702 |
|
| 703 |
case wordchar: |
| 704 |
printf ("/wordchar"); |
| 705 |
break; |
| 706 |
|
| 707 |
case notwordchar: |
| 708 |
printf ("/notwordchar"); |
| 709 |
break; |
| 710 |
|
| 711 |
case begbuf: |
| 712 |
printf ("/begbuf"); |
| 713 |
break; |
| 714 |
|
| 715 |
case endbuf: |
| 716 |
printf ("/endbuf"); |
| 717 |
break; |
| 718 |
|
| 719 |
default: |
| 720 |
printf ("?%d", *(p-1)); |
| 721 |
} |
| 722 |
} |
| 723 |
printf ("/\n"); |
| 724 |
} |
| 725 |
|
| 726 |
|
| 727 |
void |
| 728 |
print_compiled_pattern (bufp) |
| 729 |
struct re_pattern_buffer *bufp; |
| 730 |
{ |
| 731 |
unsigned char *buffer = bufp->buffer; |
| 732 |
|
| 733 |
print_partial_compiled_pattern (buffer, buffer + bufp->used); |
| 734 |
printf ("%d bytes used/%d bytes allocated.\n", bufp->used, bufp->allocated); |
| 735 |
|
| 736 |
if (bufp->fastmap_accurate && bufp->fastmap) |
| 737 |
{ |
| 738 |
printf ("fastmap: "); |
| 739 |
print_fastmap (bufp->fastmap); |
| 740 |
} |
| 741 |
|
| 742 |
printf ("re_nsub: %d\t", bufp->re_nsub); |
| 743 |
printf ("regs_alloc: %d\t", bufp->regs_allocated); |
| 744 |
printf ("can_be_null: %d\t", bufp->can_be_null); |
| 745 |
printf ("newline_anchor: %d\n", bufp->newline_anchor); |
| 746 |
printf ("no_sub: %d\t", bufp->no_sub); |
| 747 |
printf ("not_bol: %d\t", bufp->not_bol); |
| 748 |
printf ("not_eol: %d\t", bufp->not_eol); |
| 749 |
printf ("syntax: %d\n", bufp->syntax); |
| 750 |
|
| 751 |
} |
| 752 |
|
| 753 |
|
| 754 |
void |
| 755 |
print_double_string (where, string1, size1, string2, size2) |
| 756 |
const char *where; |
| 757 |
const char *string1; |
| 758 |
const char *string2; |
| 759 |
int size1; |
| 760 |
int size2; |
| 761 |
{ |
| 762 |
unsigned this_char; |
| 763 |
|
| 764 |
if (where == NULL) |
| 765 |
printf ("(null)"); |
| 766 |
else |
| 767 |
{ |
| 768 |
if (FIRST_STRING_P (where)) |
| 769 |
{ |
| 770 |
for (this_char = where - string1; this_char < size1; this_char++) |
| 771 |
printchar (string1[this_char]); |
| 772 |
|
| 773 |
where = string2; |
| 774 |
} |
| 775 |
|
| 776 |
for (this_char = where - string2; this_char < size2; this_char++) |
| 777 |
printchar (string2[this_char]); |
| 778 |
} |
| 779 |
} |
| 780 |
|
| 781 |
#else |
| 782 |
|
| 783 |
#undef assert |
| 784 |
#define assert(e) |
| 785 |
|
| 786 |
#define DEBUG_STATEMENT(e) |
| 787 |
#define DEBUG_PRINT1(x) |
| 788 |
#define DEBUG_PRINT2(x1, x2) |
| 789 |
#define DEBUG_PRINT3(x1, x2, x3) |
| 790 |
#define DEBUG_PRINT4(x1, x2, x3, x4) |
| 791 |
#define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) |
| 792 |
#define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) |
| 793 |
|
| 794 |
#endif |
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
reg_syntax_t re_syntax_options = RE_SYNTAX_EMACS; |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
reg_syntax_t |
| 810 |
re_set_syntax (syntax) |
| 811 |
reg_syntax_t syntax; |
| 812 |
{ |
| 813 |
reg_syntax_t ret = re_syntax_options; |
| 814 |
|
| 815 |
re_syntax_options = syntax; |
| 816 |
return ret; |
| 817 |
} |
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
static const char *re_error_msg[] = |
| 823 |
{ NULL, |
| 824 |
"No match", |
| 825 |
"Invalid regular expression", |
| 826 |
"Invalid collation character", |
| 827 |
"Invalid character class name", |
| 828 |
"Trailing backslash", |
| 829 |
"Invalid back reference", |
| 830 |
"Unmatched [ or [^", |
| 831 |
"Unmatched ( or \\(", |
| 832 |
"Unmatched \\{", |
| 833 |
"Invalid content of \\{\\}", |
| 834 |
"Invalid range end", |
| 835 |
"Memory exhausted", |
| 836 |
"Invalid preceding regular expression", |
| 837 |
"Premature end of regular expression", |
| 838 |
"Regular expression too big", |
| 839 |
"Unmatched ) or \\)", |
| 840 |
}; |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
static void store_op1 (), store_op2 (); |
| 845 |
static void insert_op1 (), insert_op2 (); |
| 846 |
static boolean at_begline_loc_p (), at_endline_loc_p (); |
| 847 |
static boolean group_in_compile_stack (); |
| 848 |
static reg_errcode_t compile_range (); |
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
#define PATFETCH(c) \ |
| 855 |
do {if (p == pend) return REG_EEND; \ |
| 856 |
c = (unsigned char) *p++; \ |
| 857 |
if (translate) c = translate[c]; \ |
| 858 |
} while (0) |
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
#define PATFETCH_RAW(c) \ |
| 863 |
do {if (p == pend) return REG_EEND; \ |
| 864 |
c = (unsigned char) *p++; \ |
| 865 |
} while (0) |
| 866 |
|
| 867 |
|
| 868 |
#define PATUNFETCH p-- |
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
#define TRANSLATE(d) (translate ? translate[(unsigned char) (d)] : (d)) |
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
#define INIT_BUF_SIZE 32 |
| 882 |
|
| 883 |
|
| 884 |
#define GET_BUFFER_SPACE(n) \ |
| 885 |
while (b - bufp->buffer + (n) > bufp->allocated) \ |
| 886 |
EXTEND_BUFFER () |
| 887 |
|
| 888 |
|
| 889 |
#define BUF_PUSH(c) \ |
| 890 |
do { \ |
| 891 |
GET_BUFFER_SPACE (1); \ |
| 892 |
*b++ = (unsigned char) (c); \ |
| 893 |
} while (0) |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
#define BUF_PUSH_2(c1, c2) \ |
| 898 |
do { \ |
| 899 |
GET_BUFFER_SPACE (2); \ |
| 900 |
*b++ = (unsigned char) (c1); \ |
| 901 |
*b++ = (unsigned char) (c2); \ |
| 902 |
} while (0) |
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
#define BUF_PUSH_3(c1, c2, c3) \ |
| 907 |
do { \ |
| 908 |
GET_BUFFER_SPACE (3); \ |
| 909 |
*b++ = (unsigned char) (c1); \ |
| 910 |
*b++ = (unsigned char) (c2); \ |
| 911 |
*b++ = (unsigned char) (c3); \ |
| 912 |
} while (0) |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
#define STORE_JUMP(op, loc, to) \ |
| 918 |
store_op1 (op, loc, (to) - (loc) - 3) |
| 919 |
|
| 920 |
|
| 921 |
#define STORE_JUMP2(op, loc, to, arg) \ |
| 922 |
store_op2 (op, loc, (to) - (loc) - 3, arg) |
| 923 |
|
| 924 |
|
| 925 |
#define INSERT_JUMP(op, loc, to) \ |
| 926 |
insert_op1 (op, loc, (to) - (loc) - 3, b) |
| 927 |
|
| 928 |
|
| 929 |
#define INSERT_JUMP2(op, loc, to, arg) \ |
| 930 |
insert_op2 (op, loc, (to) - (loc) - 3, arg, b) |
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
#define MAX_BUF_SIZE (1L << 16) |
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
#define EXTEND_BUFFER() \ |
| 944 |
do { \ |
| 945 |
unsigned char *old_buffer = bufp->buffer; \ |
| 946 |
if (bufp->allocated == MAX_BUF_SIZE) \ |
| 947 |
return REG_ESIZE; \ |
| 948 |
bufp->allocated <<= 1; \ |
| 949 |
if (bufp->allocated > MAX_BUF_SIZE) \ |
| 950 |
bufp->allocated = MAX_BUF_SIZE; \ |
| 951 |
bufp->buffer = (unsigned char *) realloc (bufp->buffer, bufp->allocated);\ |
| 952 |
if (bufp->buffer == NULL) \ |
| 953 |
return REG_ESPACE; \ |
| 954 |
\ |
| 955 |
if (old_buffer != bufp->buffer) \ |
| 956 |
{ \ |
| 957 |
b = (b - old_buffer) + bufp->buffer; \ |
| 958 |
begalt = (begalt - old_buffer) + bufp->buffer; \ |
| 959 |
if (fixup_alt_jump) \ |
| 960 |
fixup_alt_jump = (fixup_alt_jump - old_buffer) + bufp->buffer;\ |
| 961 |
if (laststart) \ |
| 962 |
laststart = (laststart - old_buffer) + bufp->buffer; \ |
| 963 |
if (pending_exact) \ |
| 964 |
pending_exact = (pending_exact - old_buffer) + bufp->buffer; \ |
| 965 |
} \ |
| 966 |
} while (0) |
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
#define MAX_REGNUM 255 |
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
typedef unsigned regnum_t; |
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
typedef int pattern_offset_t; |
| 984 |
|
| 985 |
typedef struct |
| 986 |
{ |
| 987 |
pattern_offset_t begalt_offset; |
| 988 |
pattern_offset_t fixup_alt_jump; |
| 989 |
pattern_offset_t inner_group_offset; |
| 990 |
pattern_offset_t laststart_offset; |
| 991 |
regnum_t regnum; |
| 992 |
} compile_stack_elt_t; |
| 993 |
|
| 994 |
|
| 995 |
typedef struct |
| 996 |
{ |
| 997 |
compile_stack_elt_t *stack; |
| 998 |
unsigned size; |
| 999 |
unsigned avail; |
| 1000 |
} compile_stack_type; |
| 1001 |
|
| 1002 |
|
| 1003 |
#define INIT_COMPILE_STACK_SIZE 32 |
| 1004 |
|
| 1005 |
#define COMPILE_STACK_EMPTY (compile_stack.avail == 0) |
| 1006 |
#define COMPILE_STACK_FULL (compile_stack.avail == compile_stack.size) |
| 1007 |
|
| 1008 |
|
| 1009 |
#define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail]) |
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
#define SET_LIST_BIT(c) \ |
| 1014 |
(b[((unsigned char) (c)) / BYTEWIDTH] \ |
| 1015 |
|= 1 << (((unsigned char) c) % BYTEWIDTH)) |
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
#define GET_UNSIGNED_NUMBER(num) \ |
| 1020 |
{ if (p != pend) \ |
| 1021 |
{ \ |
| 1022 |
PATFETCH (c); \ |
| 1023 |
while (ISDIGIT (c)) \ |
| 1024 |
{ \ |
| 1025 |
if (num < 0) \ |
| 1026 |
num = 0; \ |
| 1027 |
num = num * 10 + c - '0'; \ |
| 1028 |
if (p == pend) \ |
| 1029 |
break; \ |
| 1030 |
PATFETCH (c); \ |
| 1031 |
} \ |
| 1032 |
} \ |
| 1033 |
} |
| 1034 |
|
| 1035 |
#define CHAR_CLASS_MAX_LENGTH 6 |
| 1036 |
|
| 1037 |
#define IS_CHAR_CLASS(string) \ |
| 1038 |
(STREQ (string, "alpha") || STREQ (string, "upper") \ |
| 1039 |
|| STREQ (string, "lower") || STREQ (string, "digit") \ |
| 1040 |
|| STREQ (string, "alnum") || STREQ (string, "xdigit") \ |
| 1041 |
|| STREQ (string, "space") || STREQ (string, "print") \ |
| 1042 |
|| STREQ (string, "punct") || STREQ (string, "graph") \ |
| 1043 |
|| STREQ (string, "cntrl") || STREQ (string, "blank")) |
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
static reg_errcode_t |
| 1064 |
regex_compile (pattern, size, syntax, bufp) |
| 1065 |
const char *pattern; |
| 1066 |
int size; |
| 1067 |
reg_syntax_t syntax; |
| 1068 |
struct re_pattern_buffer *bufp; |
| 1069 |
{ |
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
register unsigned char c, c1; |
| 1074 |
|
| 1075 |
|
| 1076 |
const char *p1; |
| 1077 |
|
| 1078 |
|
| 1079 |
register unsigned char *b; |
| 1080 |
|
| 1081 |
|
| 1082 |
compile_stack_type compile_stack; |
| 1083 |
|
| 1084 |
|
| 1085 |
const char *p = pattern; |
| 1086 |
const char *pend = pattern + size; |
| 1087 |
|
| 1088 |
|
| 1089 |
char *translate = bufp->translate; |
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
unsigned char *pending_exact = NULL; |
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
unsigned char *laststart = NULL; |
| 1101 |
|
| 1102 |
|
| 1103 |
unsigned char *begalt; |
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
const char *beg_interval; |
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
unsigned char *fixup_alt_jump = NULL; |
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
regnum_t regnum = 0; |
| 1118 |
|
| 1119 |
#ifdef DEBUG |
| 1120 |
DEBUG_PRINT1 ("\nCompiling pattern: "); |
| 1121 |
if (debug) |
| 1122 |
{ |
| 1123 |
unsigned debug_count; |
| 1124 |
|
| 1125 |
for (debug_count = 0; debug_count < size; debug_count++) |
| 1126 |
printchar (pattern[debug_count]); |
| 1127 |
putchar ('\n'); |
| 1128 |
} |
| 1129 |
#endif |
| 1130 |
|
| 1131 |
|
| 1132 |
compile_stack.stack = TALLOC (INIT_COMPILE_STACK_SIZE, compile_stack_elt_t); |
| 1133 |
if (compile_stack.stack == NULL) |
| 1134 |
return REG_ESPACE; |
| 1135 |
|
| 1136 |
compile_stack.size = INIT_COMPILE_STACK_SIZE; |
| 1137 |
compile_stack.avail = 0; |
| 1138 |
|
| 1139 |
|
| 1140 |
bufp->syntax = syntax; |
| 1141 |
bufp->fastmap_accurate = 0; |
| 1142 |
bufp->not_bol = bufp->not_eol = 0; |
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
bufp->used = 0; |
| 1148 |
|
| 1149 |
|
| 1150 |
bufp->re_nsub = 0; |
| 1151 |
|
| 1152 |
#if !defined (emacs) && !defined (SYNTAX_TABLE) |
| 1153 |
|
| 1154 |
init_syntax_once (); |
| 1155 |
#endif |
| 1156 |
|
| 1157 |
if (bufp->allocated == 0) |
| 1158 |
{ |
| 1159 |
if (bufp->buffer) |
| 1160 |
{ |
| 1161 |
|
| 1162 |
|
| 1163 |
RETALLOC (bufp->buffer, INIT_BUF_SIZE, unsigned char); |
| 1164 |
} |
| 1165 |
else |
| 1166 |
{ |
| 1167 |
bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char); |
| 1168 |
} |
| 1169 |
if (!bufp->buffer) return REG_ESPACE; |
| 1170 |
|
| 1171 |
bufp->allocated = INIT_BUF_SIZE; |
| 1172 |
} |
| 1173 |
|
| 1174 |
begalt = b = bufp->buffer; |
| 1175 |
|
| 1176 |
|
| 1177 |
while (p != pend) |
| 1178 |
{ |
| 1179 |
PATFETCH (c); |
| 1180 |
|
| 1181 |
switch (c) |
| 1182 |
{ |
| 1183 |
case '^': |
| 1184 |
{ |
| 1185 |
if ( |
| 1186 |
p == pattern + 1 |
| 1187 |
|
| 1188 |
|| syntax & RE_CONTEXT_INDEP_ANCHORS |
| 1189 |
|
| 1190 |
|| at_begline_loc_p (pattern, p, syntax)) |
| 1191 |
BUF_PUSH (begline); |
| 1192 |
else |
| 1193 |
goto normal_char; |
| 1194 |
} |
| 1195 |
break; |
| 1196 |
|
| 1197 |
|
| 1198 |
case '$': |
| 1199 |
{ |
| 1200 |
if ( |
| 1201 |
p == pend |
| 1202 |
|
| 1203 |
|| syntax & RE_CONTEXT_INDEP_ANCHORS |
| 1204 |
|
| 1205 |
|| at_endline_loc_p (p, pend, syntax)) |
| 1206 |
BUF_PUSH (endline); |
| 1207 |
else |
| 1208 |
goto normal_char; |
| 1209 |
} |
| 1210 |
break; |
| 1211 |
|
| 1212 |
|
| 1213 |
case '+': |
| 1214 |
case '?': |
| 1215 |
if ((syntax & RE_BK_PLUS_QM) |
| 1216 |
|| (syntax & RE_LIMITED_OPS)) |
| 1217 |
goto normal_char; |
| 1218 |
handle_plus: |
| 1219 |
case '*': |
| 1220 |
|
| 1221 |
if (!laststart) |
| 1222 |
{ |
| 1223 |
if (syntax & RE_CONTEXT_INVALID_OPS) |
| 1224 |
return REG_BADRPT; |
| 1225 |
else if (!(syntax & RE_CONTEXT_INDEP_OPS)) |
| 1226 |
goto normal_char; |
| 1227 |
} |
| 1228 |
|
| 1229 |
{ |
| 1230 |
|
| 1231 |
boolean keep_string_p = false; |
| 1232 |
|
| 1233 |
|
| 1234 |
char zero_times_ok = 0, many_times_ok = 0; |
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
for (;;) |
| 1242 |
{ |
| 1243 |
zero_times_ok |= c != '+'; |
| 1244 |
many_times_ok |= c != '?'; |
| 1245 |
|
| 1246 |
if (p == pend) |
| 1247 |
break; |
| 1248 |
|
| 1249 |
PATFETCH (c); |
| 1250 |
|
| 1251 |
if (c == '*' |
| 1252 |
|| (!(syntax & RE_BK_PLUS_QM) && (c == '+' || c == '?'))) |
| 1253 |
; |
| 1254 |
|
| 1255 |
else if (syntax & RE_BK_PLUS_QM && c == '\\') |
| 1256 |
{ |
| 1257 |
if (p == pend) return REG_EESCAPE; |
| 1258 |
|
| 1259 |
PATFETCH (c1); |
| 1260 |
if (!(c1 == '+' || c1 == '?')) |
| 1261 |
{ |
| 1262 |
PATUNFETCH; |
| 1263 |
PATUNFETCH; |
| 1264 |
break; |
| 1265 |
} |
| 1266 |
|
| 1267 |
c = c1; |
| 1268 |
} |
| 1269 |
else |
| 1270 |
{ |
| 1271 |
PATUNFETCH; |
| 1272 |
break; |
| 1273 |
} |
| 1274 |
|
| 1275 |
|
| 1276 |
} |
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
if (!laststart) |
| 1281 |
break; |
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
if (many_times_ok) |
| 1286 |
{ |
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
assert (p - 1 > pattern); |
| 1297 |
|
| 1298 |
|
| 1299 |
GET_BUFFER_SPACE (3); |
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
if (TRANSLATE (*(p - 2)) == TRANSLATE ('.') |
| 1307 |
&& zero_times_ok |
| 1308 |
&& p < pend && TRANSLATE (*p) == TRANSLATE ('\n') |
| 1309 |
&& !(syntax & RE_DOT_NEWLINE)) |
| 1310 |
{ |
| 1311 |
STORE_JUMP (jump, b, laststart); |
| 1312 |
keep_string_p = true; |
| 1313 |
} |
| 1314 |
else |
| 1315 |
|
| 1316 |
STORE_JUMP (maybe_pop_jump, b, laststart - 3); |
| 1317 |
|
| 1318 |
|
| 1319 |
b += 3; |
| 1320 |
} |
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
GET_BUFFER_SPACE (3); |
| 1325 |
INSERT_JUMP (keep_string_p ? on_failure_keep_string_jump |
| 1326 |
: on_failure_jump, |
| 1327 |
laststart, b + 3); |
| 1328 |
pending_exact = 0; |
| 1329 |
b += 3; |
| 1330 |
|
| 1331 |
if (!zero_times_ok) |
| 1332 |
{ |
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
GET_BUFFER_SPACE (3); |
| 1339 |
INSERT_JUMP (dummy_failure_jump, laststart, laststart + 6); |
| 1340 |
b += 3; |
| 1341 |
} |
| 1342 |
} |
| 1343 |
break; |
| 1344 |
|
| 1345 |
|
| 1346 |
case '.': |
| 1347 |
laststart = b; |
| 1348 |
BUF_PUSH (anychar); |
| 1349 |
break; |
| 1350 |
|
| 1351 |
|
| 1352 |
case '[': |
| 1353 |
{ |
| 1354 |
boolean had_char_class = false; |
| 1355 |
|
| 1356 |
if (p == pend) return REG_EBRACK; |
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
GET_BUFFER_SPACE (34); |
| 1361 |
|
| 1362 |
laststart = b; |
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
BUF_PUSH (*p == '^' ? charset_not : charset); |
| 1367 |
if (*p == '^') |
| 1368 |
p++; |
| 1369 |
|
| 1370 |
|
| 1371 |
p1 = p; |
| 1372 |
|
| 1373 |
|
| 1374 |
BUF_PUSH ((1 << BYTEWIDTH) / BYTEWIDTH); |
| 1375 |
|
| 1376 |
|
| 1377 |
bzero (b, (1 << BYTEWIDTH) / BYTEWIDTH); |
| 1378 |
|
| 1379 |
|
| 1380 |
if ((re_opcode_t) b[-2] == charset_not |
| 1381 |
&& (syntax & RE_HAT_LISTS_NOT_NEWLINE)) |
| 1382 |
SET_LIST_BIT ('\n'); |
| 1383 |
|
| 1384 |
|
| 1385 |
for (;;) |
| 1386 |
{ |
| 1387 |
if (p == pend) return REG_EBRACK; |
| 1388 |
|
| 1389 |
PATFETCH (c); |
| 1390 |
|
| 1391 |
|
| 1392 |
if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\') |
| 1393 |
{ |
| 1394 |
if (p == pend) return REG_EESCAPE; |
| 1395 |
|
| 1396 |
PATFETCH (c1); |
| 1397 |
SET_LIST_BIT (c1); |
| 1398 |
continue; |
| 1399 |
} |
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
if (c == ']' && p != p1 + 1) |
| 1405 |
break; |
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
if (had_char_class && c == '-' && *p != ']') |
| 1410 |
return REG_ERANGE; |
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
if (c == '-' |
| 1417 |
&& !(p - 2 >= pattern && p[-2] == '[') |
| 1418 |
&& !(p - 3 >= pattern && p[-3] == '[' && p[-2] == '^') |
| 1419 |
&& *p != ']') |
| 1420 |
{ |
| 1421 |
reg_errcode_t ret |
| 1422 |
= compile_range (&p, pend, translate, syntax, b); |
| 1423 |
if (ret != REG_NOERROR) return ret; |
| 1424 |
} |
| 1425 |
|
| 1426 |
else if (p[0] == '-' && p[1] != ']') |
| 1427 |
{ |
| 1428 |
reg_errcode_t ret; |
| 1429 |
|
| 1430 |
|
| 1431 |
PATFETCH (c1); |
| 1432 |
|
| 1433 |
ret = compile_range (&p, pend, translate, syntax, b); |
| 1434 |
if (ret != REG_NOERROR) return ret; |
| 1435 |
} |
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
else if (syntax & RE_CHAR_CLASSES && c == '[' && *p == ':') |
| 1441 |
{ |
| 1442 |
char str[CHAR_CLASS_MAX_LENGTH + 1]; |
| 1443 |
|
| 1444 |
PATFETCH (c); |
| 1445 |
c1 = 0; |
| 1446 |
|
| 1447 |
|
| 1448 |
if (p == pend) return REG_EBRACK; |
| 1449 |
|
| 1450 |
for (;;) |
| 1451 |
{ |
| 1452 |
PATFETCH (c); |
| 1453 |
if (c == ':' || c == ']' || p == pend |
| 1454 |
|| c1 == CHAR_CLASS_MAX_LENGTH) |
| 1455 |
break; |
| 1456 |
str[c1++] = c; |
| 1457 |
} |
| 1458 |
str[c1] = '\0'; |
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
if (c == ':' && *p == ']') |
| 1464 |
{ |
| 1465 |
int ch; |
| 1466 |
boolean is_alnum = STREQ (str, "alnum"); |
| 1467 |
boolean is_alpha = STREQ (str, "alpha"); |
| 1468 |
boolean is_blank = STREQ (str, "blank"); |
| 1469 |
boolean is_cntrl = STREQ (str, "cntrl"); |
| 1470 |
boolean is_digit = STREQ (str, "digit"); |
| 1471 |
boolean is_graph = STREQ (str, "graph"); |
| 1472 |
boolean is_lower = STREQ (str, "lower"); |
| 1473 |
boolean is_print = STREQ (str, "print"); |
| 1474 |
boolean is_punct = STREQ (str, "punct"); |
| 1475 |
boolean is_space = STREQ (str, "space"); |
| 1476 |
boolean is_upper = STREQ (str, "upper"); |
| 1477 |
boolean is_xdigit = STREQ (str, "xdigit"); |
| 1478 |
|
| 1479 |
if (!IS_CHAR_CLASS (str)) return REG_ECTYPE; |
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
PATFETCH (c); |
| 1484 |
|
| 1485 |
if (p == pend) return REG_EBRACK; |
| 1486 |
|
| 1487 |
for (ch = 0; ch < 1 << BYTEWIDTH; ch++) |
| 1488 |
{ |
| 1489 |
if ( (is_alnum && ISALNUM (ch)) |
| 1490 |
|| (is_alpha && ISALPHA (ch)) |
| 1491 |
|| (is_blank && ISBLANK (ch)) |
| 1492 |
|| (is_cntrl && ISCNTRL (ch)) |
| 1493 |
|| (is_digit && ISDIGIT (ch)) |
| 1494 |
|| (is_graph && ISGRAPH (ch)) |
| 1495 |
|| (is_lower && ISLOWER (ch)) |
| 1496 |
|| (is_print && ISPRINT (ch)) |
| 1497 |
|| (is_punct && ISPUNCT (ch)) |
| 1498 |
|| (is_space && ISSPACE (ch)) |
| 1499 |
|| (is_upper && ISUPPER (ch)) |
| 1500 |
|| (is_xdigit && ISXDIGIT (ch))) |
| 1501 |
SET_LIST_BIT (ch); |
| 1502 |
} |
| 1503 |
had_char_class = true; |
| 1504 |
} |
| 1505 |
else |
| 1506 |
{ |
| 1507 |
c1++; |
| 1508 |
while (c1--) |
| 1509 |
PATUNFETCH; |
| 1510 |
SET_LIST_BIT ('['); |
| 1511 |
SET_LIST_BIT (':'); |
| 1512 |
had_char_class = false; |
| 1513 |
} |
| 1514 |
} |
| 1515 |
else |
| 1516 |
{ |
| 1517 |
had_char_class = false; |
| 1518 |
SET_LIST_BIT (c); |
| 1519 |
} |
| 1520 |
} |
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
while ((int) b[-1] > 0 && b[b[-1] - 1] == 0) |
| 1525 |
b[-1]--; |
| 1526 |
b += b[-1]; |
| 1527 |
} |
| 1528 |
break; |
| 1529 |
|
| 1530 |
|
| 1531 |
case '(': |
| 1532 |
if (syntax & RE_NO_BK_PARENS) |
| 1533 |
goto handle_open; |
| 1534 |
else |
| 1535 |
goto normal_char; |
| 1536 |
|
| 1537 |
|
| 1538 |
case ')': |
| 1539 |
if (syntax & RE_NO_BK_PARENS) |
| 1540 |
goto handle_close; |
| 1541 |
else |
| 1542 |
goto normal_char; |
| 1543 |
|
| 1544 |
|
| 1545 |
case '\n': |
| 1546 |
if (syntax & RE_NEWLINE_ALT) |
| 1547 |
goto handle_alt; |
| 1548 |
else |
| 1549 |
goto normal_char; |
| 1550 |
|
| 1551 |
|
| 1552 |
case '|': |
| 1553 |
if (syntax & RE_NO_BK_VBAR) |
| 1554 |
goto handle_alt; |
| 1555 |
else |
| 1556 |
goto normal_char; |
| 1557 |
|
| 1558 |
|
| 1559 |
case '{': |
| 1560 |
if (syntax & RE_INTERVALS && syntax & RE_NO_BK_BRACES) |
| 1561 |
goto handle_interval; |
| 1562 |
else |
| 1563 |
goto normal_char; |
| 1564 |
|
| 1565 |
|
| 1566 |
case '\\': |
| 1567 |
if (p == pend) return REG_EESCAPE; |
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
PATFETCH_RAW (c); |
| 1573 |
|
| 1574 |
switch (c) |
| 1575 |
{ |
| 1576 |
case '(': |
| 1577 |
if (syntax & RE_NO_BK_PARENS) |
| 1578 |
goto normal_backslash; |
| 1579 |
|
| 1580 |
handle_open: |
| 1581 |
bufp->re_nsub++; |
| 1582 |
regnum++; |
| 1583 |
|
| 1584 |
if (COMPILE_STACK_FULL) |
| 1585 |
{ |
| 1586 |
RETALLOC (compile_stack.stack, compile_stack.size << 1, |
| 1587 |
compile_stack_elt_t); |
| 1588 |
if (compile_stack.stack == NULL) return REG_ESPACE; |
| 1589 |
|
| 1590 |
compile_stack.size <<= 1; |
| 1591 |
} |
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
COMPILE_STACK_TOP.begalt_offset = begalt - bufp->buffer; |
| 1598 |
COMPILE_STACK_TOP.fixup_alt_jump |
| 1599 |
= fixup_alt_jump ? fixup_alt_jump - bufp->buffer + 1 : 0; |
| 1600 |
COMPILE_STACK_TOP.laststart_offset = b - bufp->buffer; |
| 1601 |
COMPILE_STACK_TOP.regnum = regnum; |
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
if (regnum <= MAX_REGNUM) |
| 1608 |
{ |
| 1609 |
COMPILE_STACK_TOP.inner_group_offset = b - bufp->buffer + 2; |
| 1610 |
BUF_PUSH_3 (start_memory, regnum, 0); |
| 1611 |
} |
| 1612 |
|
| 1613 |
compile_stack.avail++; |
| 1614 |
|
| 1615 |
fixup_alt_jump = 0; |
| 1616 |
laststart = 0; |
| 1617 |
begalt = b; |
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
pending_exact = 0; |
| 1622 |
break; |
| 1623 |
|
| 1624 |
|
| 1625 |
case ')': |
| 1626 |
if (syntax & RE_NO_BK_PARENS) goto normal_backslash; |
| 1627 |
|
| 1628 |
if (COMPILE_STACK_EMPTY) |
| 1629 |
if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) |
| 1630 |
goto normal_backslash; |
| 1631 |
else |
| 1632 |
return REG_ERPAREN; |
| 1633 |
|
| 1634 |
handle_close: |
| 1635 |
if (fixup_alt_jump) |
| 1636 |
{ |
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
BUF_PUSH (push_dummy_failure); |
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
STORE_JUMP (jump_past_alt, fixup_alt_jump, b - 1); |
| 1645 |
} |
| 1646 |
|
| 1647 |
|
| 1648 |
if (COMPILE_STACK_EMPTY) |
| 1649 |
if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) |
| 1650 |
goto normal_char; |
| 1651 |
else |
| 1652 |
return REG_ERPAREN; |
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
assert (compile_stack.avail != 0); |
| 1657 |
{ |
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
regnum_t this_group_regnum; |
| 1662 |
|
| 1663 |
compile_stack.avail--; |
| 1664 |
begalt = bufp->buffer + COMPILE_STACK_TOP.begalt_offset; |
| 1665 |
fixup_alt_jump |
| 1666 |
= COMPILE_STACK_TOP.fixup_alt_jump |
| 1667 |
? bufp->buffer + COMPILE_STACK_TOP.fixup_alt_jump - 1 |
| 1668 |
: 0; |
| 1669 |
laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset; |
| 1670 |
this_group_regnum = COMPILE_STACK_TOP.regnum; |
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
pending_exact = 0; |
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
if (this_group_regnum <= MAX_REGNUM) |
| 1679 |
{ |
| 1680 |
unsigned char *inner_group_loc |
| 1681 |
= bufp->buffer + COMPILE_STACK_TOP.inner_group_offset; |
| 1682 |
|
| 1683 |
*inner_group_loc = regnum - this_group_regnum; |
| 1684 |
BUF_PUSH_3 (stop_memory, this_group_regnum, |
| 1685 |
regnum - this_group_regnum); |
| 1686 |
} |
| 1687 |
} |
| 1688 |
break; |
| 1689 |
|
| 1690 |
|
| 1691 |
case '|': |
| 1692 |
if (syntax & RE_LIMITED_OPS || syntax & RE_NO_BK_VBAR) |
| 1693 |
goto normal_backslash; |
| 1694 |
handle_alt: |
| 1695 |
if (syntax & RE_LIMITED_OPS) |
| 1696 |
goto normal_char; |
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
GET_BUFFER_SPACE (3); |
| 1701 |
INSERT_JUMP (on_failure_jump, begalt, b + 6); |
| 1702 |
pending_exact = 0; |
| 1703 |
b += 3; |
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
if (fixup_alt_jump) |
| 1722 |
STORE_JUMP (jump_past_alt, fixup_alt_jump, b); |
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
fixup_alt_jump = b; |
| 1728 |
GET_BUFFER_SPACE (3); |
| 1729 |
b += 3; |
| 1730 |
|
| 1731 |
laststart = 0; |
| 1732 |
begalt = b; |
| 1733 |
break; |
| 1734 |
|
| 1735 |
|
| 1736 |
case '{': |
| 1737 |
|
| 1738 |
if (!(syntax & RE_INTERVALS) |
| 1739 |
|
| 1740 |
|
| 1741 |
|| ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES)) |
| 1742 |
|| (p - 2 == pattern && p == pend)) |
| 1743 |
goto normal_backslash; |
| 1744 |
|
| 1745 |
handle_interval: |
| 1746 |
{ |
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
int lower_bound = -1, upper_bound = -1; |
| 1751 |
|
| 1752 |
beg_interval = p - 1; |
| 1753 |
|
| 1754 |
if (p == pend) |
| 1755 |
{ |
| 1756 |
if (syntax & RE_NO_BK_BRACES) |
| 1757 |
goto unfetch_interval; |
| 1758 |
else |
| 1759 |
return REG_EBRACE; |
| 1760 |
} |
| 1761 |
|
| 1762 |
GET_UNSIGNED_NUMBER (lower_bound); |
| 1763 |
|
| 1764 |
if (c == ',') |
| 1765 |
{ |
| 1766 |
GET_UNSIGNED_NUMBER (upper_bound); |
| 1767 |
if (upper_bound < 0) upper_bound = RE_DUP_MAX; |
| 1768 |
} |
| 1769 |
else |
| 1770 |
|
| 1771 |
upper_bound = lower_bound; |
| 1772 |
|
| 1773 |
if (lower_bound < 0 || upper_bound > RE_DUP_MAX |
| 1774 |
|| lower_bound > upper_bound) |
| 1775 |
{ |
| 1776 |
if (syntax & RE_NO_BK_BRACES) |
| 1777 |
goto unfetch_interval; |
| 1778 |
else |
| 1779 |
return REG_BADBR; |
| 1780 |
} |
| 1781 |
|
| 1782 |
if (!(syntax & RE_NO_BK_BRACES)) |
| 1783 |
{ |
| 1784 |
if (c != '\\') return REG_EBRACE; |
| 1785 |
|
| 1786 |
PATFETCH (c); |
| 1787 |
} |
| 1788 |
|
| 1789 |
if (c != '}') |
| 1790 |
{ |
| 1791 |
if (syntax & RE_NO_BK_BRACES) |
| 1792 |
goto unfetch_interval; |
| 1793 |
else |
| 1794 |
return REG_BADBR; |
| 1795 |
} |
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
if (!laststart) |
| 1801 |
{ |
| 1802 |
if (syntax & RE_CONTEXT_INVALID_OPS) |
| 1803 |
return REG_BADRPT; |
| 1804 |
else if (syntax & RE_CONTEXT_INDEP_OPS) |
| 1805 |
laststart = b; |
| 1806 |
else |
| 1807 |
goto unfetch_interval; |
| 1808 |
} |
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
if (upper_bound == 0) |
| 1814 |
{ |
| 1815 |
GET_BUFFER_SPACE (3); |
| 1816 |
INSERT_JUMP (jump, laststart, b + 3); |
| 1817 |
b += 3; |
| 1818 |
} |
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
else |
| 1830 |
{ |
| 1831 |
|
| 1832 |
unsigned nbytes = 10 + (upper_bound > 1) * 10; |
| 1833 |
|
| 1834 |
GET_BUFFER_SPACE (nbytes); |
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
INSERT_JUMP2 (succeed_n, laststart, |
| 1842 |
b + 5 + (upper_bound > 1) * 5, |
| 1843 |
lower_bound); |
| 1844 |
b += 5; |
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
insert_op2 (set_number_at, laststart, 5, lower_bound, b); |
| 1851 |
b += 5; |
| 1852 |
|
| 1853 |
if (upper_bound > 1) |
| 1854 |
{ |
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
STORE_JUMP2 (jump_n, b, laststart + 5, |
| 1862 |
upper_bound - 1); |
| 1863 |
b += 5; |
| 1864 |
|
| 1865 |
|
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
insert_op2 (set_number_at, laststart, b - laststart, |
| 1880 |
upper_bound - 1, b); |
| 1881 |
b += 5; |
| 1882 |
} |
| 1883 |
} |
| 1884 |
pending_exact = 0; |
| 1885 |
beg_interval = NULL; |
| 1886 |
} |
| 1887 |
break; |
| 1888 |
|
| 1889 |
unfetch_interval: |
| 1890 |
|
| 1891 |
assert (beg_interval); |
| 1892 |
p = beg_interval; |
| 1893 |
beg_interval = NULL; |
| 1894 |
|
| 1895 |
|
| 1896 |
PATFETCH (c); |
| 1897 |
|
| 1898 |
if (!(syntax & RE_NO_BK_BRACES)) |
| 1899 |
{ |
| 1900 |
if (p > pattern && p[-1] == '\\') |
| 1901 |
goto normal_backslash; |
| 1902 |
} |
| 1903 |
goto normal_char; |
| 1904 |
|
| 1905 |
#ifdef emacs |
| 1906 |
|
| 1907 |
|
| 1908 |
case '=': |
| 1909 |
BUF_PUSH (at_dot); |
| 1910 |
break; |
| 1911 |
|
| 1912 |
case 's': |
| 1913 |
laststart = b; |
| 1914 |
PATFETCH (c); |
| 1915 |
BUF_PUSH_2 (syntaxspec, syntax_spec_code[c]); |
| 1916 |
break; |
| 1917 |
|
| 1918 |
case 'S': |
| 1919 |
laststart = b; |
| 1920 |
PATFETCH (c); |
| 1921 |
BUF_PUSH_2 (notsyntaxspec, syntax_spec_code[c]); |
| 1922 |
break; |
| 1923 |
#endif |
| 1924 |
|
| 1925 |
|
| 1926 |
case 'w': |
| 1927 |
laststart = b; |
| 1928 |
BUF_PUSH (wordchar); |
| 1929 |
break; |
| 1930 |
|
| 1931 |
|
| 1932 |
case 'W': |
| 1933 |
laststart = b; |
| 1934 |
BUF_PUSH (notwordchar); |
| 1935 |
break; |
| 1936 |
|
| 1937 |
|
| 1938 |
case '<': |
| 1939 |
BUF_PUSH (wordbeg); |
| 1940 |
break; |
| 1941 |
|
| 1942 |
case '>': |
| 1943 |
BUF_PUSH (wordend); |
| 1944 |
break; |
| 1945 |
|
| 1946 |
case 'b': |
| 1947 |
BUF_PUSH (wordbound); |
| 1948 |
break; |
| 1949 |
|
| 1950 |
case 'B': |
| 1951 |
BUF_PUSH (notwordbound); |
| 1952 |
break; |
| 1953 |
|
| 1954 |
case '`': |
| 1955 |
BUF_PUSH (begbuf); |
| 1956 |
break; |
| 1957 |
|
| 1958 |
case '\'': |
| 1959 |
BUF_PUSH (endbuf); |
| 1960 |
break; |
| 1961 |
|
| 1962 |
case '1': case '2': case '3': case '4': case '5': |
| 1963 |
case '6': case '7': case '8': case '9': |
| 1964 |
if (syntax & RE_NO_BK_REFS) |
| 1965 |
goto normal_char; |
| 1966 |
|
| 1967 |
c1 = c - '0'; |
| 1968 |
|
| 1969 |
if (c1 > regnum) |
| 1970 |
return REG_ESUBREG; |
| 1971 |
|
| 1972 |
|
| 1973 |
if (group_in_compile_stack (compile_stack, c1)) |
| 1974 |
goto normal_char; |
| 1975 |
|
| 1976 |
laststart = b; |
| 1977 |
BUF_PUSH_2 (duplicate, c1); |
| 1978 |
break; |
| 1979 |
|
| 1980 |
|
| 1981 |
case '+': |
| 1982 |
case '?': |
| 1983 |
if (syntax & RE_BK_PLUS_QM) |
| 1984 |
goto handle_plus; |
| 1985 |
else |
| 1986 |
goto normal_backslash; |
| 1987 |
|
| 1988 |
default: |
| 1989 |
normal_backslash: |
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
c = TRANSLATE (c); |
| 1994 |
goto normal_char; |
| 1995 |
} |
| 1996 |
break; |
| 1997 |
|
| 1998 |
|
| 1999 |
default: |
| 2000 |
|
| 2001 |
normal_char: |
| 2002 |
|
| 2003 |
if (!pending_exact |
| 2004 |
|
| 2005 |
|
| 2006 |
|| pending_exact + *pending_exact + 1 != b |
| 2007 |
|
| 2008 |
|
| 2009 |
|| *pending_exact == (1 << BYTEWIDTH) - 1 |
| 2010 |
|
| 2011 |
|
| 2012 |
|| *p == '*' || *p == '^' |
| 2013 |
|| ((syntax & RE_BK_PLUS_QM) |
| 2014 |
? *p == '\\' && (p[1] == '+' || p[1] == '?') |
| 2015 |
: (*p == '+' || *p == '?')) |
| 2016 |
|| ((syntax & RE_INTERVALS) |
| 2017 |
&& ((syntax & RE_NO_BK_BRACES) |
| 2018 |
? *p == '{' |
| 2019 |
: (p[0] == '\\' && p[1] == '{')))) |
| 2020 |
{ |
| 2021 |
|
| 2022 |
|
| 2023 |
laststart = b; |
| 2024 |
|
| 2025 |
BUF_PUSH_2 (exactn, 0); |
| 2026 |
pending_exact = b - 1; |
| 2027 |
} |
| 2028 |
|
| 2029 |
BUF_PUSH (c); |
| 2030 |
(*pending_exact)++; |
| 2031 |
break; |
| 2032 |
} |
| 2033 |
} |
| 2034 |
|
| 2035 |
|
| 2036 |
|
| 2037 |
|
| 2038 |
if (fixup_alt_jump) |
| 2039 |
STORE_JUMP (jump_past_alt, fixup_alt_jump, b); |
| 2040 |
|
| 2041 |
if (!COMPILE_STACK_EMPTY) |
| 2042 |
return REG_EPAREN; |
| 2043 |
|
| 2044 |
free (compile_stack.stack); |
| 2045 |
|
| 2046 |
|
| 2047 |
bufp->used = b - bufp->buffer; |
| 2048 |
|
| 2049 |
#ifdef DEBUG |
| 2050 |
if (debug) |
| 2051 |
{ |
| 2052 |
DEBUG_PRINT1 ("\nCompiled pattern: "); |
| 2053 |
print_compiled_pattern (bufp); |
| 2054 |
} |
| 2055 |
#endif |
| 2056 |
|
| 2057 |
return REG_NOERROR; |
| 2058 |
} |
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
static void |
| 2065 |
store_op1 (op, loc, arg) |
| 2066 |
re_opcode_t op; |
| 2067 |
unsigned char *loc; |
| 2068 |
int arg; |
| 2069 |
{ |
| 2070 |
*loc = (unsigned char) op; |
| 2071 |
STORE_NUMBER (loc + 1, arg); |
| 2072 |
} |
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
static void |
| 2078 |
store_op2 (op, loc, arg1, arg2) |
| 2079 |
re_opcode_t op; |
| 2080 |
unsigned char *loc; |
| 2081 |
int arg1, arg2; |
| 2082 |
{ |
| 2083 |
*loc = (unsigned char) op; |
| 2084 |
STORE_NUMBER (loc + 1, arg1); |
| 2085 |
STORE_NUMBER (loc + 3, arg2); |
| 2086 |
} |
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
static void |
| 2093 |
insert_op1 (op, loc, arg, end) |
| 2094 |
re_opcode_t op; |
| 2095 |
unsigned char *loc; |
| 2096 |
int arg; |
| 2097 |
unsigned char *end; |
| 2098 |
{ |
| 2099 |
register unsigned char *pfrom = end; |
| 2100 |
register unsigned char *pto = end + 3; |
| 2101 |
|
| 2102 |
while (pfrom != loc) |
| 2103 |
*--pto = *--pfrom; |
| 2104 |
|
| 2105 |
store_op1 (op, loc, arg); |
| 2106 |
} |
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
|
| 2111 |
static void |
| 2112 |
insert_op2 (op, loc, arg1, arg2, end) |
| 2113 |
re_opcode_t op; |
| 2114 |
unsigned char *loc; |
| 2115 |
int arg1, arg2; |
| 2116 |
unsigned char *end; |
| 2117 |
{ |
| 2118 |
register unsigned char *pfrom = end; |
| 2119 |
register unsigned char *pto = end + 5; |
| 2120 |
|
| 2121 |
while (pfrom != loc) |
| 2122 |
*--pto = *--pfrom; |
| 2123 |
|
| 2124 |
store_op2 (op, loc, arg1, arg2); |
| 2125 |
} |
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
static boolean |
| 2133 |
at_begline_loc_p (pattern, p, syntax) |
| 2134 |
const char *pattern, *p; |
| 2135 |
reg_syntax_t syntax; |
| 2136 |
{ |
| 2137 |
const char *prev = p - 2; |
| 2138 |
boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\'; |
| 2139 |
|
| 2140 |
return |
| 2141 |
|
| 2142 |
(*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash)) |
| 2143 |
|
| 2144 |
|| (*prev == '|' && (syntax & RE_NO_BK_VBAR || prev_prev_backslash)); |
| 2145 |
} |
| 2146 |
|
| 2147 |
|
| 2148 |
|
| 2149 |
|
| 2150 |
|
| 2151 |
static boolean |
| 2152 |
at_endline_loc_p (p, pend, syntax) |
| 2153 |
const char *p, *pend; |
| 2154 |
int syntax; |
| 2155 |
{ |
| 2156 |
const char *next = p; |
| 2157 |
boolean next_backslash = *next == '\\'; |
| 2158 |
const char *next_next = p + 1 < pend ? p + 1 : NULL; |
| 2159 |
|
| 2160 |
return |
| 2161 |
|
| 2162 |
(syntax & RE_NO_BK_PARENS ? *next == ')' |
| 2163 |
: next_backslash && next_next && *next_next == ')') |
| 2164 |
|
| 2165 |
|| (syntax & RE_NO_BK_VBAR ? *next == '|' |
| 2166 |
: next_backslash && next_next && *next_next == '|'); |
| 2167 |
} |
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
|
| 2173 |
static boolean |
| 2174 |
group_in_compile_stack (compile_stack, regnum) |
| 2175 |
compile_stack_type compile_stack; |
| 2176 |
regnum_t regnum; |
| 2177 |
{ |
| 2178 |
int this_element; |
| 2179 |
|
| 2180 |
for (this_element = compile_stack.avail - 1; |
| 2181 |
this_element >= 0; |
| 2182 |
this_element--) |
| 2183 |
if (compile_stack.stack[this_element].regnum == regnum) |
| 2184 |
return true; |
| 2185 |
|
| 2186 |
return false; |
| 2187 |
} |
| 2188 |
|
| 2189 |
|
| 2190 |
|
| 2191 |
|
| 2192 |
|
| 2193 |
|
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
|
| 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 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
range_start = ((unsigned char *) p)[-2]; |
| 2224 |
range_end = ((unsigned char *) p)[0]; |
| 2225 |
|
| 2226 |
|
| 2227 |
|
| 2228 |
(*p_ptr)++; |
| 2229 |
|
| 2230 |
|
| 2231 |
if (range_start > range_end) |
| 2232 |
return syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR; |
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 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 |
|
| 2247 |
|
| 2248 |
|
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
#ifndef INIT_FAILURE_ALLOC |
| 2255 |
#define INIT_FAILURE_ALLOC 5 |
| 2256 |
#endif |
| 2257 |
|
| 2258 |
|
| 2259 |
|
| 2260 |
|
| 2261 |
|
| 2262 |
int re_max_failures = 2000; |
| 2263 |
|
| 2264 |
typedef const unsigned char *fail_stack_elt_t; |
| 2265 |
|
| 2266 |
typedef struct |
| 2267 |
{ |
| 2268 |
fail_stack_elt_t *stack; |
| 2269 |
unsigned size; |
| 2270 |
unsigned avail; |
| 2271 |
} fail_stack_type; |
| 2272 |
|
| 2273 |
#define FAIL_STACK_EMPTY() (fail_stack.avail == 0) |
| 2274 |
#define FAIL_STACK_PTR_EMPTY() (fail_stack_ptr->avail == 0) |
| 2275 |
#define FAIL_STACK_FULL() (fail_stack.avail == fail_stack.size) |
| 2276 |
#define FAIL_STACK_TOP() (fail_stack.stack[fail_stack.avail]) |
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
#define INIT_FAIL_STACK() \ |
| 2282 |
do { \ |
| 2283 |
fail_stack.stack = (fail_stack_elt_t *) \ |
| 2284 |
REGEX_ALLOCATE (INIT_FAILURE_ALLOC * sizeof (fail_stack_elt_t)); \ |
| 2285 |
\ |
| 2286 |
if (fail_stack.stack == NULL) \ |
| 2287 |
return -2; \ |
| 2288 |
\ |
| 2289 |
fail_stack.size = INIT_FAILURE_ALLOC; \ |
| 2290 |
fail_stack.avail = 0; \ |
| 2291 |
} while (0) |
| 2292 |
|
| 2293 |
|
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
#define DOUBLE_FAIL_STACK(fail_stack) \ |
| 2302 |
((fail_stack).size > re_max_failures * MAX_FAILURE_ITEMS \ |
| 2303 |
? 0 \ |
| 2304 |
: ((fail_stack).stack = (fail_stack_elt_t *) \ |
| 2305 |
REGEX_REALLOCATE ((fail_stack).stack, \ |
| 2306 |
(fail_stack).size * sizeof (fail_stack_elt_t), \ |
| 2307 |
((fail_stack).size << 1) * sizeof (fail_stack_elt_t)), \ |
| 2308 |
\ |
| 2309 |
(fail_stack).stack == NULL \ |
| 2310 |
? 0 \ |
| 2311 |
: ((fail_stack).size <<= 1, \ |
| 2312 |
1))) |
| 2313 |
|
| 2314 |
|
| 2315 |
|
| 2316 |
|
| 2317 |
|
| 2318 |
|
| 2319 |
#define PUSH_PATTERN_OP(pattern_op, fail_stack) \ |
| 2320 |
((FAIL_STACK_FULL () \ |
| 2321 |
&& !DOUBLE_FAIL_STACK (fail_stack)) \ |
| 2322 |
? 0 \ |
| 2323 |
: ((fail_stack).stack[(fail_stack).avail++] = pattern_op, \ |
| 2324 |
1)) |
| 2325 |
|
| 2326 |
|
| 2327 |
|
| 2328 |
|
| 2329 |
#define PUSH_FAILURE_ITEM(item) \ |
| 2330 |
fail_stack.stack[fail_stack.avail++] = (fail_stack_elt_t) item |
| 2331 |
|
| 2332 |
|
| 2333 |
#define POP_FAILURE_ITEM() fail_stack.stack[--fail_stack.avail] |
| 2334 |
|
| 2335 |
|
| 2336 |
#ifdef DEBUG |
| 2337 |
#define DEBUG_PUSH PUSH_FAILURE_ITEM |
| 2338 |
#define DEBUG_POP(item_addr) *(item_addr) = POP_FAILURE_ITEM () |
| 2339 |
#else |
| 2340 |
#define DEBUG_PUSH(item) |
| 2341 |
#define DEBUG_POP(item_addr) |
| 2342 |
#endif |
| 2343 |
|
| 2344 |
|
| 2345 |
|
| 2346 |
|
| 2347 |
|
| 2348 |
|
| 2349 |
|
| 2350 |
|
| 2351 |
|
| 2352 |
|
| 2353 |
|
| 2354 |
#define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code) \ |
| 2355 |
do { \ |
| 2356 |
char *destination; \ |
| 2357 |
|
| 2358 |
\ |
| 2359 |
int this_reg; \ |
| 2360 |
\ |
| 2361 |
DEBUG_STATEMENT (failure_id++); \ |
| 2362 |
DEBUG_STATEMENT (nfailure_points_pushed++); \ |
| 2363 |
DEBUG_PRINT2 ("\nPUSH_FAILURE_POINT #%u:\n", failure_id); \ |
| 2364 |
DEBUG_PRINT2 (" Before push, next avail: %d\n", (fail_stack).avail);\ |
| 2365 |
DEBUG_PRINT2 (" size: %d\n", (fail_stack).size);\ |
| 2366 |
\ |
| 2367 |
DEBUG_PRINT2 (" slots needed: %d\n", NUM_FAILURE_ITEMS); \ |
| 2368 |
DEBUG_PRINT2 (" available: %d\n", REMAINING_AVAIL_SLOTS); \ |
| 2369 |
\ |
| 2370 |
\ |
| 2371 |
while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS) \ |
| 2372 |
{ \ |
| 2373 |
if (!DOUBLE_FAIL_STACK (fail_stack)) \ |
| 2374 |
return failure_code; \ |
| 2375 |
\ |
| 2376 |
DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", \ |
| 2377 |
(fail_stack).size); \ |
| 2378 |
DEBUG_PRINT2 (" slots available: %d\n", REMAINING_AVAIL_SLOTS);\ |
| 2379 |
} \ |
| 2380 |
\ |
| 2381 |
\ |
| 2382 |
DEBUG_PRINT1 ("\n"); \ |
| 2383 |
\ |
| 2384 |
for (this_reg = lowest_active_reg; this_reg <= highest_active_reg; \ |
| 2385 |
this_reg++) \ |
| 2386 |
{ \ |
| 2387 |
DEBUG_PRINT2 (" Pushing reg: %d\n", this_reg); \ |
| 2388 |
DEBUG_STATEMENT (num_regs_pushed++); \ |
| 2389 |
\ |
| 2390 |
DEBUG_PRINT2 (" start: 0x%x\n", regstart[this_reg]); \ |
| 2391 |
PUSH_FAILURE_ITEM (regstart[this_reg]); \ |
| 2392 |
\ |
| 2393 |
DEBUG_PRINT2 (" end: 0x%x\n", regend[this_reg]); \ |
| 2394 |
PUSH_FAILURE_ITEM (regend[this_reg]); \ |
| 2395 |
\ |
| 2396 |
DEBUG_PRINT2 (" info: 0x%x\n ", reg_info[this_reg]); \ |
| 2397 |
DEBUG_PRINT2 (" match_null=%d", \ |
| 2398 |
REG_MATCH_NULL_STRING_P (reg_info[this_reg])); \ |
| 2399 |
DEBUG_PRINT2 (" active=%d", IS_ACTIVE (reg_info[this_reg])); \ |
| 2400 |
DEBUG_PRINT2 (" matched_something=%d", \ |
| 2401 |
MATCHED_SOMETHING (reg_info[this_reg])); \ |
| 2402 |
DEBUG_PRINT2 (" ever_matched=%d", \ |
| 2403 |
EVER_MATCHED_SOMETHING (reg_info[this_reg])); \ |
| 2404 |
DEBUG_PRINT1 ("\n"); \ |
| 2405 |
PUSH_FAILURE_ITEM (reg_info[this_reg].word); \ |
| 2406 |
} \ |
| 2407 |
\ |
| 2408 |
DEBUG_PRINT2 (" Pushing low active reg: %d\n", lowest_active_reg);\ |
| 2409 |
PUSH_FAILURE_ITEM (lowest_active_reg); \ |
| 2410 |
\ |
| 2411 |
DEBUG_PRINT2 (" Pushing high active reg: %d\n", highest_active_reg);\ |
| 2412 |
PUSH_FAILURE_ITEM (highest_active_reg); \ |
| 2413 |
\ |
| 2414 |
DEBUG_PRINT2 (" Pushing pattern 0x%x: ", pattern_place); \ |
| 2415 |
DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend); \ |
| 2416 |
PUSH_FAILURE_ITEM (pattern_place); \ |
| 2417 |
\ |
| 2418 |
DEBUG_PRINT2 (" Pushing string 0x%x: `", string_place); \ |
| 2419 |
DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, \ |
| 2420 |
size2); \ |
| 2421 |
DEBUG_PRINT1 ("'\n"); \ |
| 2422 |
PUSH_FAILURE_ITEM (string_place); \ |
| 2423 |
\ |
| 2424 |
DEBUG_PRINT2 (" Pushing failure id: %u\n", failure_id); \ |
| 2425 |
DEBUG_PUSH (failure_id); \ |
| 2426 |
} while (0) |
| 2427 |
|
| 2428 |
|
| 2429 |
|
| 2430 |
#define NUM_REG_ITEMS 3 |
| 2431 |
|
| 2432 |
|
| 2433 |
#ifdef DEBUG |
| 2434 |
#define NUM_NONREG_ITEMS 5 |
| 2435 |
#else |
| 2436 |
#define NUM_NONREG_ITEMS 4 |
| 2437 |
#endif |
| 2438 |
|
| 2439 |
|
| 2440 |
#define MAX_FAILURE_ITEMS ((num_regs - 1) * NUM_REG_ITEMS + NUM_NONREG_ITEMS) |
| 2441 |
|
| 2442 |
|
| 2443 |
#define NUM_FAILURE_ITEMS \ |
| 2444 |
((highest_active_reg - lowest_active_reg + 1) * NUM_REG_ITEMS \ |
| 2445 |
+ NUM_NONREG_ITEMS) |
| 2446 |
|
| 2447 |
|
| 2448 |
#define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail) |
| 2449 |
|
| 2450 |
|
| 2451 |
|
| 2452 |
|
| 2453 |
|
| 2454 |
|
| 2455 |
|
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
|
| 2460 |
|
| 2461 |
|
| 2462 |
|
| 2463 |
#define POP_FAILURE_POINT(str, pat, low_reg, high_reg, regstart, regend, reg_info)\ |
| 2464 |
{ \ |
| 2465 |
DEBUG_STATEMENT (fail_stack_elt_t failure_id;) \ |
| 2466 |
int this_reg; \ |
| 2467 |
const unsigned char *string_temp; \ |
| 2468 |
\ |
| 2469 |
assert (!FAIL_STACK_EMPTY ()); \ |
| 2470 |
\ |
| 2471 |
\ |
| 2472 |
DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \ |
| 2473 |
DEBUG_PRINT2 (" Before pop, next avail: %d\n", fail_stack.avail); \ |
| 2474 |
DEBUG_PRINT2 (" size: %d\n", fail_stack.size); \ |
| 2475 |
\ |
| 2476 |
assert (fail_stack.avail >= NUM_NONREG_ITEMS); \ |
| 2477 |
\ |
| 2478 |
DEBUG_POP (&failure_id); \ |
| 2479 |
DEBUG_PRINT2 (" Popping failure id: %u\n", failure_id); \ |
| 2480 |
\ |
| 2481 |
|
| 2482 |
|
| 2483 |
\ |
| 2484 |
string_temp = POP_FAILURE_ITEM (); \ |
| 2485 |
if (string_temp != NULL) \ |
| 2486 |
str = (const char *) string_temp; \ |
| 2487 |
\ |
| 2488 |
DEBUG_PRINT2 (" Popping string 0x%x: `", str); \ |
| 2489 |
DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \ |
| 2490 |
DEBUG_PRINT1 ("'\n"); \ |
| 2491 |
\ |
| 2492 |
pat = (unsigned char *) POP_FAILURE_ITEM (); \ |
| 2493 |
DEBUG_PRINT2 (" Popping pattern 0x%x: ", pat); \ |
| 2494 |
DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \ |
| 2495 |
\ |
| 2496 |
\ |
| 2497 |
high_reg = (unsigned) POP_FAILURE_ITEM (); \ |
| 2498 |
DEBUG_PRINT2 (" Popping high active reg: %d\n", high_reg); \ |
| 2499 |
\ |
| 2500 |
low_reg = (unsigned) POP_FAILURE_ITEM (); \ |
| 2501 |
DEBUG_PRINT2 (" Popping low active reg: %d\n", low_reg); \ |
| 2502 |
\ |
| 2503 |
for (this_reg = high_reg; this_reg >= low_reg; this_reg--) \ |
| 2504 |
{ \ |
| 2505 |
DEBUG_PRINT2 (" Popping reg: %d\n", this_reg); \ |
| 2506 |
\ |
| 2507 |
reg_info[this_reg].word = POP_FAILURE_ITEM (); \ |
| 2508 |
DEBUG_PRINT2 (" info: 0x%x\n", reg_info[this_reg]); \ |
| 2509 |
\ |
| 2510 |
regend[this_reg] = (const char *) POP_FAILURE_ITEM (); \ |
| 2511 |
DEBUG_PRINT2 (" end: 0x%x\n", regend[this_reg]); \ |
| 2512 |
\ |
| 2513 |
regstart[this_reg] = (const char *) POP_FAILURE_ITEM (); \ |
| 2514 |
DEBUG_PRINT2 (" start: 0x%x\n", regstart[this_reg]); \ |
| 2515 |
} \ |
| 2516 |
\ |
| 2517 |
DEBUG_STATEMENT (nfailure_points_popped++); \ |
| 2518 |
} |
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
|
| 2525 |
|
| 2526 |
|
| 2527 |
|
| 2528 |
|
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
|
| 2533 |
int |
| 2534 |
re_compile_fastmap (bufp) |
| 2535 |
struct re_pattern_buffer *bufp; |
| 2536 |
{ |
| 2537 |
int j, k; |
| 2538 |
fail_stack_type fail_stack; |
| 2539 |
#ifndef REGEX_MALLOC |
| 2540 |
char *destination; |
| 2541 |
#endif |
| 2542 |
|
| 2543 |
unsigned num_regs = 0; |
| 2544 |
|
| 2545 |
register char *fastmap = bufp->fastmap; |
| 2546 |
unsigned char *pattern = bufp->buffer; |
| 2547 |
unsigned long size = bufp->used; |
| 2548 |
const unsigned char *p = pattern; |
| 2549 |
register unsigned char *pend = pattern + size; |
| 2550 |
|
| 2551 |
|
| 2552 |
|
| 2553 |
|
| 2554 |
|
| 2555 |
boolean path_can_be_null = true; |
| 2556 |
|
| 2557 |
|
| 2558 |
boolean succeed_n_p = false; |
| 2559 |
|
| 2560 |
assert (fastmap != NULL && p != NULL); |
| 2561 |
|
| 2562 |
INIT_FAIL_STACK (); |
| 2563 |
bzero (fastmap, 1 << BYTEWIDTH); |
| 2564 |
bufp->fastmap_accurate = 1; |
| 2565 |
bufp->can_be_null = 0; |
| 2566 |
|
| 2567 |
while (p != pend || !FAIL_STACK_EMPTY ()) |
| 2568 |
{ |
| 2569 |
if (p == pend) |
| 2570 |
{ |
| 2571 |
bufp->can_be_null |= path_can_be_null; |
| 2572 |
|
| 2573 |
|
| 2574 |
path_can_be_null = true; |
| 2575 |
|
| 2576 |
p = fail_stack.stack[--fail_stack.avail]; |
| 2577 |
} |
| 2578 |
|
| 2579 |
|
| 2580 |
assert (p < pend); |
| 2581 |
|
| 2582 |
#ifdef SWITCH_ENUM_BUG |
| 2583 |
switch ((int) ((re_opcode_t) *p++)) |
| 2584 |
#else |
| 2585 |
switch ((re_opcode_t) *p++) |
| 2586 |
#endif |
| 2587 |
{ |
| 2588 |
|
| 2589 |
|
| 2590 |
|
| 2591 |
|
| 2592 |
|
| 2593 |
|
| 2594 |
case duplicate: |
| 2595 |
bufp->can_be_null = 1; |
| 2596 |
return 0; |
| 2597 |
|
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
|
| 2602 |
case exactn: |
| 2603 |
fastmap[p[1]] = 1; |
| 2604 |
break; |
| 2605 |
|
| 2606 |
|
| 2607 |
case charset: |
| 2608 |
for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) |
| 2609 |
if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))) |
| 2610 |
fastmap[j] = 1; |
| 2611 |
break; |
| 2612 |
|
| 2613 |
|
| 2614 |
case charset_not: |
| 2615 |
|
| 2616 |
for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++) |
| 2617 |
fastmap[j] = 1; |
| 2618 |
|
| 2619 |
for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) |
| 2620 |
if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))) |
| 2621 |
fastmap[j] = 1; |
| 2622 |
break; |
| 2623 |
|
| 2624 |
|
| 2625 |
case wordchar: |
| 2626 |
for (j = 0; j < (1 << BYTEWIDTH); j++) |
| 2627 |
if (SYNTAX (j) == Sword) |
| 2628 |
fastmap[j] = 1; |
| 2629 |
break; |
| 2630 |
|
| 2631 |
|
| 2632 |
case notwordchar: |
| 2633 |
for (j = 0; j < (1 << BYTEWIDTH); j++) |
| 2634 |
if (SYNTAX (j) != Sword) |
| 2635 |
fastmap[j] = 1; |
| 2636 |
break; |
| 2637 |
|
| 2638 |
|
| 2639 |
case anychar: |
| 2640 |
|
| 2641 |
for (j = 0; j < (1 << BYTEWIDTH); j++) |
| 2642 |
fastmap[j] = 1; |
| 2643 |
|
| 2644 |
|
| 2645 |
if (!(bufp->syntax & RE_DOT_NEWLINE)) |
| 2646 |
fastmap['\n'] = 0; |
| 2647 |
|
| 2648 |
|
| 2649 |
|
| 2650 |
else if (bufp->can_be_null) |
| 2651 |
return 0; |
| 2652 |
|
| 2653 |
|
| 2654 |
break; |
| 2655 |
|
| 2656 |
|
| 2657 |
#ifdef emacs |
| 2658 |
case syntaxspec: |
| 2659 |
k = *p++; |
| 2660 |
for (j = 0; j < (1 << BYTEWIDTH); j++) |
| 2661 |
if (SYNTAX (j) == (enum syntaxcode) k) |
| 2662 |
fastmap[j] = 1; |
| 2663 |
break; |
| 2664 |
|
| 2665 |
|
| 2666 |
case notsyntaxspec: |
| 2667 |
k = *p++; |
| 2668 |
for (j = 0; j < (1 << BYTEWIDTH); j++) |
| 2669 |
if (SYNTAX (j) != (enum syntaxcode) k) |
| 2670 |
fastmap[j] = 1; |
| 2671 |
break; |
| 2672 |
|
| 2673 |
|
| 2674 |
|
| 2675 |
|
| 2676 |
|
| 2677 |
|
| 2678 |
case before_dot: |
| 2679 |
case at_dot: |
| 2680 |
case after_dot: |
| 2681 |
continue; |
| 2682 |
#endif |
| 2683 |
|
| 2684 |
|
| 2685 |
case no_op: |
| 2686 |
case begline: |
| 2687 |
case endline: |
| 2688 |
case begbuf: |
| 2689 |
case endbuf: |
| 2690 |
case wordbound: |
| 2691 |
case notwordbound: |
| 2692 |
case wordbeg: |
| 2693 |
case wordend: |
| 2694 |
case push_dummy_failure: |
| 2695 |
continue; |
| 2696 |
|
| 2697 |
|
| 2698 |
case jump_n: |
| 2699 |
case pop_failure_jump: |
| 2700 |
case maybe_pop_jump: |
| 2701 |
case jump: |
| 2702 |
case jump_past_alt: |
| 2703 |
case dummy_failure_jump: |
| 2704 |
EXTRACT_NUMBER_AND_INCR (j, p); |
| 2705 |
p += j; |
| 2706 |
if (j > 0) |
| 2707 |
continue; |
| 2708 |
|
| 2709 |
|
| 2710 |
|
| 2711 |
|
| 2712 |
|
| 2713 |
|
| 2714 |
if ((re_opcode_t) *p != on_failure_jump |
| 2715 |
&& (re_opcode_t) *p != succeed_n) |
| 2716 |
continue; |
| 2717 |
|
| 2718 |
p++; |
| 2719 |
EXTRACT_NUMBER_AND_INCR (j, p); |
| 2720 |
p += j; |
| 2721 |
|
| 2722 |
|
| 2723 |
if (!FAIL_STACK_EMPTY () |
| 2724 |
&& fail_stack.stack[fail_stack.avail - 1] == p) |
| 2725 |
fail_stack.avail--; |
| 2726 |
|
| 2727 |
continue; |
| 2728 |
|
| 2729 |
|
| 2730 |
case on_failure_jump: |
| 2731 |
case on_failure_keep_string_jump: |
| 2732 |
handle_on_failure_jump: |
| 2733 |
EXTRACT_NUMBER_AND_INCR (j, p); |
| 2734 |
|
| 2735 |
|
| 2736 |
|
| 2737 |
|
| 2738 |
|
| 2739 |
|
| 2740 |
|
| 2741 |
|
| 2742 |
if (p + j < pend) |
| 2743 |
{ |
| 2744 |
if (!PUSH_PATTERN_OP (p + j, fail_stack)) |
| 2745 |
return -2; |
| 2746 |
} |
| 2747 |
else |
| 2748 |
bufp->can_be_null = 1; |
| 2749 |
|
| 2750 |
if (succeed_n_p) |
| 2751 |
{ |
| 2752 |
EXTRACT_NUMBER_AND_INCR (k, p); |
| 2753 |
succeed_n_p = false; |
| 2754 |
} |
| 2755 |
|
| 2756 |
continue; |
| 2757 |
|
| 2758 |
|
| 2759 |
case succeed_n: |
| 2760 |
|
| 2761 |
p += 2; |
| 2762 |
|
| 2763 |
|
| 2764 |
EXTRACT_NUMBER_AND_INCR (k, p); |
| 2765 |
if (k == 0) |
| 2766 |
{ |
| 2767 |
p -= 4; |
| 2768 |
succeed_n_p = true; |
| 2769 |
goto handle_on_failure_jump; |
| 2770 |
} |
| 2771 |
continue; |
| 2772 |
|
| 2773 |
|
| 2774 |
case set_number_at: |
| 2775 |
p += 4; |
| 2776 |
continue; |
| 2777 |
|
| 2778 |
|
| 2779 |
case start_memory: |
| 2780 |
case stop_memory: |
| 2781 |
p += 2; |
| 2782 |
continue; |
| 2783 |
|
| 2784 |
|
| 2785 |
default: |
| 2786 |
abort (); |
| 2787 |
} |
| 2788 |
|
| 2789 |
|
| 2790 |
|
| 2791 |
|
| 2792 |
|
| 2793 |
|
| 2794 |
|
| 2795 |
path_can_be_null = false; |
| 2796 |
p = pend; |
| 2797 |
} |
| 2798 |
|
| 2799 |
|
| 2800 |
|
| 2801 |
bufp->can_be_null |= path_can_be_null; |
| 2802 |
return 0; |
| 2803 |
} |
| 2804 |
|
| 2805 |
|
| 2806 |
|
| 2807 |
|
| 2808 |
|
| 2809 |
|
| 2810 |
|
| 2811 |
|
| 2812 |
|
| 2813 |
|
| 2814 |
|
| 2815 |
|
| 2816 |
|
| 2817 |
|
| 2818 |
void |
| 2819 |
re_set_registers (bufp, regs, num_regs, starts, ends) |
| 2820 |
struct re_pattern_buffer *bufp; |
| 2821 |
struct re_registers *regs; |
| 2822 |
unsigned num_regs; |
| 2823 |
regoff_t *starts, *ends; |
| 2824 |
{ |
| 2825 |
if (num_regs) |
| 2826 |
{ |
| 2827 |
bufp->regs_allocated = REGS_REALLOCATE; |
| 2828 |
regs->num_regs = num_regs; |
| 2829 |
regs->start = starts; |
| 2830 |
regs->end = ends; |
| 2831 |
} |
| 2832 |
else |
| 2833 |
{ |
| 2834 |
bufp->regs_allocated = REGS_UNALLOCATED; |
| 2835 |
regs->num_regs = 0; |
| 2836 |
regs->start = regs->end = (regoff_t) 0; |
| 2837 |
} |
| 2838 |
} |
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
|
| 2845 |
int |
| 2846 |
re_search (bufp, string, size, startpos, range, regs) |
| 2847 |
struct re_pattern_buffer *bufp; |
| 2848 |
const char *string; |
| 2849 |
int size, startpos, range; |
| 2850 |
struct re_registers *regs; |
| 2851 |
{ |
| 2852 |
return re_search_2 (bufp, NULL, 0, string, size, startpos, range, |
| 2853 |
regs, size); |
| 2854 |
} |
| 2855 |
|
| 2856 |
|
| 2857 |
|
| 2858 |
|
| 2859 |
|
| 2860 |
|
| 2861 |
|
| 2862 |
|
| 2863 |
|
| 2864 |
|
| 2865 |
|
| 2866 |
|
| 2867 |
|
| 2868 |
|
| 2869 |
|
| 2870 |
|
| 2871 |
|
| 2872 |
|
| 2873 |
|
| 2874 |
|
| 2875 |
|
| 2876 |
|
| 2877 |
|
| 2878 |
int |
| 2879 |
re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop) |
| 2880 |
struct re_pattern_buffer *bufp; |
| 2881 |
const char *string1, *string2; |
| 2882 |
int size1, size2; |
| 2883 |
int startpos; |
| 2884 |
int range; |
| 2885 |
struct re_registers *regs; |
| 2886 |
int stop; |
| 2887 |
{ |
| 2888 |
int val; |
| 2889 |
register char *fastmap = bufp->fastmap; |
| 2890 |
register char *translate = bufp->translate; |
| 2891 |
int total_size = size1 + size2; |
| 2892 |
int endpos = startpos + range; |
| 2893 |
|
| 2894 |
|
| 2895 |
if (startpos < 0 || startpos > total_size) |
| 2896 |
return -1; |
| 2897 |
|
| 2898 |
|
| 2899 |
|
| 2900 |
if (endpos < -1) |
| 2901 |
range = -1 - startpos; |
| 2902 |
else if (endpos > total_size) |
| 2903 |
range = total_size - startpos; |
| 2904 |
|
| 2905 |
|
| 2906 |
|
| 2907 |
if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == begbuf && range > 0) |
| 2908 |
{ |
| 2909 |
if (startpos > 0) |
| 2910 |
return -1; |
| 2911 |
else |
| 2912 |
range = 1; |
| 2913 |
} |
| 2914 |
|
| 2915 |
|
| 2916 |
if (fastmap && !bufp->fastmap_accurate) |
| 2917 |
if (re_compile_fastmap (bufp) == -2) |
| 2918 |
return -2; |
| 2919 |
|
| 2920 |
|
| 2921 |
for (;;) |
| 2922 |
{ |
| 2923 |
|
| 2924 |
|
| 2925 |
|
| 2926 |
|
| 2927 |
if (fastmap && startpos < total_size && !bufp->can_be_null) |
| 2928 |
{ |
| 2929 |
if (range > 0) |
| 2930 |
{ |
| 2931 |
register const char *d; |
| 2932 |
register int lim = 0; |
| 2933 |
int irange = range; |
| 2934 |
|
| 2935 |
if (startpos < size1 && startpos + range >= size1) |
| 2936 |
lim = range - (size1 - startpos); |
| 2937 |
|
| 2938 |
d = (startpos >= size1 ? string2 - size1 : string1) + startpos; |
| 2939 |
|
| 2940 |
|
| 2941 |
|
| 2942 |
if (translate) |
| 2943 |
while (range > lim |
| 2944 |
&& !fastmap[(unsigned char) |
| 2945 |
translate[(unsigned char) *d++]]) |
| 2946 |
range--; |
| 2947 |
else |
| 2948 |
while (range > lim && !fastmap[(unsigned char) *d++]) |
| 2949 |
range--; |
| 2950 |
|
| 2951 |
startpos += irange - range; |
| 2952 |
} |
| 2953 |
else |
| 2954 |
{ |
| 2955 |
register char c = (size1 == 0 || startpos >= size1 |
| 2956 |
? string2[startpos - size1] |
| 2957 |
: string1[startpos]); |
| 2958 |
|
| 2959 |
if (!fastmap[(unsigned char) TRANSLATE (c)]) |
| 2960 |
goto advance; |
| 2961 |
} |
| 2962 |
} |
| 2963 |
|
| 2964 |
|
| 2965 |
if (range >= 0 && startpos == total_size && fastmap |
| 2966 |
&& !bufp->can_be_null) |
| 2967 |
return -1; |
| 2968 |
|
| 2969 |
val = re_match_2 (bufp, string1, size1, string2, size2, |
| 2970 |
startpos, regs, stop); |
| 2971 |
if (val >= 0) |
| 2972 |
return startpos; |
| 2973 |
|
| 2974 |
if (val == -2) |
| 2975 |
return -2; |
| 2976 |
|
| 2977 |
advance: |
| 2978 |
if (!range) |
| 2979 |
break; |
| 2980 |
else if (range > 0) |
| 2981 |
{ |
| 2982 |
range--; |
| 2983 |
startpos++; |
| 2984 |
} |
| 2985 |
else |
| 2986 |
{ |
| 2987 |
range++; |
| 2988 |
startpos--; |
| 2989 |
} |
| 2990 |
} |
| 2991 |
return -1; |
| 2992 |
} |
| 2993 |
|
| 2994 |
|
| 2995 |
|
| 2996 |
static int bcmp_translate (); |
| 2997 |
static boolean alt_match_null_string_p (), |
| 2998 |
common_op_match_null_string_p (), |
| 2999 |
group_match_null_string_p (); |
| 3000 |
|
| 3001 |
|
| 3002 |
|
| 3003 |
|
| 3004 |
|
| 3005 |
|
| 3006 |
|
| 3007 |
|
| 3008 |
|
| 3009 |
|
| 3010 |
|
| 3011 |
|
| 3012 |
typedef union |
| 3013 |
{ |
| 3014 |
fail_stack_elt_t word; |
| 3015 |
struct |
| 3016 |
{ |
| 3017 |
|
| 3018 |
|
| 3019 |
#define MATCH_NULL_UNSET_VALUE 3 |
| 3020 |
unsigned match_null_string_p : 2; |
| 3021 |
unsigned is_active : 1; |
| 3022 |
unsigned matched_something : 1; |
| 3023 |
unsigned ever_matched_something : 1; |
| 3024 |
} bits; |
| 3025 |
} register_info_type; |
| 3026 |
|
| 3027 |
#define REG_MATCH_NULL_STRING_P(R) ((R).bits.match_null_string_p) |
| 3028 |
#define IS_ACTIVE(R) ((R).bits.is_active) |
| 3029 |
#define MATCHED_SOMETHING(R) ((R).bits.matched_something) |
| 3030 |
#define EVER_MATCHED_SOMETHING(R) ((R).bits.ever_matched_something) |
| 3031 |
|
| 3032 |
|
| 3033 |
|
| 3034 |
|
| 3035 |
|
| 3036 |
#define SET_REGS_MATCHED() \ |
| 3037 |
do \ |
| 3038 |
{ \ |
| 3039 |
unsigned r; \ |
| 3040 |
for (r = lowest_active_reg; r <= highest_active_reg; r++) \ |
| 3041 |
{ \ |
| 3042 |
MATCHED_SOMETHING (reg_info[r]) \ |
| 3043 |
= EVER_MATCHED_SOMETHING (reg_info[r]) \ |
| 3044 |
= 1; \ |
| 3045 |
} \ |
| 3046 |
} \ |
| 3047 |
while (0) |
| 3048 |
|
| 3049 |
|
| 3050 |
|
| 3051 |
|
| 3052 |
#define POINTER_TO_OFFSET(ptr) \ |
| 3053 |
(FIRST_STRING_P (ptr) ? (ptr) - string1 : (ptr) - string2 + size1) |
| 3054 |
|
| 3055 |
|
| 3056 |
#define REG_UNSET_VALUE ((char *) -1) |
| 3057 |
#define REG_UNSET(e) ((e) == REG_UNSET_VALUE) |
| 3058 |
|
| 3059 |
|
| 3060 |
|
| 3061 |
|
| 3062 |
#define MATCHING_IN_FIRST_STRING (dend == end_match_1) |
| 3063 |
|
| 3064 |
|
| 3065 |
|
| 3066 |
#define PREFETCH() \ |
| 3067 |
while (d == dend) \ |
| 3068 |
{ \ |
| 3069 |
\ |
| 3070 |
if (dend == end_match_2) \ |
| 3071 |
goto fail; \ |
| 3072 |
\ |
| 3073 |
d = string2; \ |
| 3074 |
dend = end_match_2; \ |
| 3075 |
} |
| 3076 |
|
| 3077 |
|
| 3078 |
|
| 3079 |
|
| 3080 |
#define AT_STRINGS_BEG(d) ((d) == (size1 ? string1 : string2) || !size2) |
| 3081 |
#define AT_STRINGS_END(d) ((d) == end2) |
| 3082 |
|
| 3083 |
|
| 3084 |
|
| 3085 |
|
| 3086 |
|
| 3087 |
|
| 3088 |
#define WORDCHAR_P(d) \ |
| 3089 |
(SYNTAX ((d) == end1 ? *string2 \ |
| 3090 |
: (d) == string2 - 1 ? *(end1 - 1) : *(d)) \ |
| 3091 |
== Sword) |
| 3092 |
|
| 3093 |
|
| 3094 |
|
| 3095 |
#define AT_WORD_BOUNDARY(d) \ |
| 3096 |
(AT_STRINGS_BEG (d) || AT_STRINGS_END (d) \ |
| 3097 |
|| WORDCHAR_P (d - 1) != WORDCHAR_P (d)) |
| 3098 |
|
| 3099 |
|
| 3100 |
|
| 3101 |
#define FREE_VAR(var) if (var) free (var); var = NULL |
| 3102 |
#define FREE_VARIABLES() \ |
| 3103 |
do { \ |
| 3104 |
FREE_VAR (fail_stack.stack); \ |
| 3105 |
FREE_VAR (regstart); \ |
| 3106 |
FREE_VAR (regend); \ |
| 3107 |
FREE_VAR (old_regstart); \ |
| 3108 |
FREE_VAR (old_regend); \ |
| 3109 |
FREE_VAR (best_regstart); \ |
| 3110 |
FREE_VAR (best_regend); \ |
| 3111 |
FREE_VAR (reg_info); \ |
| 3112 |
FREE_VAR (reg_dummy); \ |
| 3113 |
FREE_VAR (reg_info_dummy); \ |
| 3114 |
} while (0) |
| 3115 |
|
| 3116 |
|
| 3117 |
|
| 3118 |
|
| 3119 |
|
| 3120 |
|
| 3121 |
|
| 3122 |
|
| 3123 |
|
| 3124 |
#define NO_HIGHEST_ACTIVE_REG (1 << BYTEWIDTH) |
| 3125 |
#define NO_LOWEST_ACTIVE_REG (NO_HIGHEST_ACTIVE_REG + 1) |
| 3126 |
|
| 3127 |
|
| 3128 |
|
| 3129 |
#ifndef emacs |
| 3130 |
|
| 3131 |
|
| 3132 |
int |
| 3133 |
re_match (bufp, string, size, pos, regs) |
| 3134 |
struct re_pattern_buffer *bufp; |
| 3135 |
const char *string; |
| 3136 |
int size, pos; |
| 3137 |
struct re_registers *regs; |
| 3138 |
{ |
| 3139 |
return re_match_2 (bufp, NULL, 0, string, size, pos, regs, size); |
| 3140 |
} |
| 3141 |
#endif |
| 3142 |
|
| 3143 |
|
| 3144 |
|
| 3145 |
|
| 3146 |
|
| 3147 |
|
| 3148 |
|
| 3149 |
|
| 3150 |
|
| 3151 |
|
| 3152 |
|
| 3153 |
|
| 3154 |
|
| 3155 |
|
| 3156 |
|
| 3157 |
int |
| 3158 |
re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop) |
| 3159 |
struct re_pattern_buffer *bufp; |
| 3160 |
const char *string1, *string2; |
| 3161 |
int size1, size2; |
| 3162 |
int pos; |
| 3163 |
struct re_registers *regs; |
| 3164 |
int stop; |
| 3165 |
{ |
| 3166 |
|
| 3167 |
int mcnt; |
| 3168 |
unsigned char *p1; |
| 3169 |
|
| 3170 |
|
| 3171 |
const char *end1, *end2; |
| 3172 |
|
| 3173 |
|
| 3174 |
|
| 3175 |
const char *end_match_1, *end_match_2; |
| 3176 |
|
| 3177 |
|
| 3178 |
const char *d, *dend; |
| 3179 |
|
| 3180 |
|
| 3181 |
unsigned char *p = bufp->buffer; |
| 3182 |
register unsigned char *pend = p + bufp->used; |
| 3183 |
|
| 3184 |
|
| 3185 |
char *translate = bufp->translate; |
| 3186 |
|
| 3187 |
|
| 3188 |
|
| 3189 |
|
| 3190 |
|
| 3191 |
|
| 3192 |
|
| 3193 |
|
| 3194 |
|
| 3195 |
|
| 3196 |
fail_stack_type fail_stack; |
| 3197 |
#ifdef DEBUG |
| 3198 |
static unsigned failure_id = 0; |
| 3199 |
unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0; |
| 3200 |
#endif |
| 3201 |
|
| 3202 |
|
| 3203 |
|
| 3204 |
|
| 3205 |
unsigned num_regs = bufp->re_nsub + 1; |
| 3206 |
|
| 3207 |
|
| 3208 |
unsigned lowest_active_reg = NO_LOWEST_ACTIVE_REG; |
| 3209 |
unsigned highest_active_reg = NO_HIGHEST_ACTIVE_REG; |
| 3210 |
|
| 3211 |
|
| 3212 |
|
| 3213 |
|
| 3214 |
|
| 3215 |
|
| 3216 |
|
| 3217 |
|
| 3218 |
const char **regstart, **regend; |
| 3219 |
|
| 3220 |
|
| 3221 |
|
| 3222 |
|
| 3223 |
|
| 3224 |
|
| 3225 |
const char **old_regstart, **old_regend; |
| 3226 |
|
| 3227 |
|
| 3228 |
|
| 3229 |
|
| 3230 |
|
| 3231 |
|
| 3232 |
|
| 3233 |
register_info_type *reg_info; |
| 3234 |
|
| 3235 |
|
| 3236 |
|
| 3237 |
|
| 3238 |
|
| 3239 |
unsigned best_regs_set = false; |
| 3240 |
const char **best_regstart, **best_regend; |
| 3241 |
|
| 3242 |
|
| 3243 |
|
| 3244 |
|
| 3245 |
|
| 3246 |
|
| 3247 |
|
| 3248 |
|
| 3249 |
|
| 3250 |
const char *match_end = NULL; |
| 3251 |
|
| 3252 |
|
| 3253 |
const char **reg_dummy; |
| 3254 |
register_info_type *reg_info_dummy; |
| 3255 |
|
| 3256 |
#ifdef DEBUG |
| 3257 |
|
| 3258 |
unsigned num_regs_pushed = 0; |
| 3259 |
#endif |
| 3260 |
|
| 3261 |
DEBUG_PRINT1 ("\n\nEntering re_match_2.\n"); |
| 3262 |
|
| 3263 |
INIT_FAIL_STACK (); |
| 3264 |
|
| 3265 |
|
| 3266 |
|
| 3267 |
|
| 3268 |
|
| 3269 |
|
| 3270 |
if (bufp->re_nsub) |
| 3271 |
{ |
| 3272 |
regstart = REGEX_TALLOC (num_regs, const char *); |
| 3273 |
regend = REGEX_TALLOC (num_regs, const char *); |
| 3274 |
old_regstart = REGEX_TALLOC (num_regs, const char *); |
| 3275 |
old_regend = REGEX_TALLOC (num_regs, const char *); |
| 3276 |
best_regstart = REGEX_TALLOC (num_regs, const char *); |
| 3277 |
best_regend = REGEX_TALLOC (num_regs, const char *); |
| 3278 |
reg_info = REGEX_TALLOC (num_regs, register_info_type); |
| 3279 |
reg_dummy = REGEX_TALLOC (num_regs, const char *); |
| 3280 |
reg_info_dummy = REGEX_TALLOC (num_regs, register_info_type); |
| 3281 |
|
| 3282 |
if (!(regstart && regend && old_regstart && old_regend && reg_info |
| 3283 |
&& best_regstart && best_regend && reg_dummy && reg_info_dummy)) |
| 3284 |
{ |
| 3285 |
FREE_VARIABLES (); |
| 3286 |
return -2; |
| 3287 |
} |
| 3288 |
} |
| 3289 |
#ifdef REGEX_MALLOC |
| 3290 |
else |
| 3291 |
{ |
| 3292 |
|
| 3293 |
|
| 3294 |
regstart = regend = old_regstart = old_regend = best_regstart |
| 3295 |
= best_regend = reg_dummy = NULL; |
| 3296 |
reg_info = reg_info_dummy = (register_info_type *) NULL; |
| 3297 |
} |
| 3298 |
#endif |
| 3299 |
|
| 3300 |
|
| 3301 |
if (pos < 0 || pos > size1 + size2) |
| 3302 |
{ |
| 3303 |
FREE_VARIABLES (); |
| 3304 |
return -1; |
| 3305 |
} |
| 3306 |
|
| 3307 |
|
| 3308 |
|
| 3309 |
|
| 3310 |
for (mcnt = 1; mcnt < num_regs; mcnt++) |
| 3311 |
{ |
| 3312 |
regstart[mcnt] = regend[mcnt] |
| 3313 |
= old_regstart[mcnt] = old_regend[mcnt] = REG_UNSET_VALUE; |
| 3314 |
|
| 3315 |
REG_MATCH_NULL_STRING_P (reg_info[mcnt]) = MATCH_NULL_UNSET_VALUE; |
| 3316 |
IS_ACTIVE (reg_info[mcnt]) = 0; |
| 3317 |
MATCHED_SOMETHING (reg_info[mcnt]) = 0; |
| 3318 |
EVER_MATCHED_SOMETHING (reg_info[mcnt]) = 0; |
| 3319 |
} |
| 3320 |
|
| 3321 |
|
| 3322 |
|
| 3323 |
if (size2 == 0 && string1 != NULL) |
| 3324 |
{ |
| 3325 |
string2 = string1; |
| 3326 |
size2 = size1; |
| 3327 |
string1 = 0; |
| 3328 |
size1 = 0; |
| 3329 |
} |
| 3330 |
end1 = string1 + size1; |
| 3331 |
end2 = string2 + size2; |
| 3332 |
|
| 3333 |
|
| 3334 |
if (stop <= size1) |
| 3335 |
{ |
| 3336 |
end_match_1 = string1 + stop; |
| 3337 |
end_match_2 = string2; |
| 3338 |
} |
| 3339 |
else |
| 3340 |
{ |
| 3341 |
end_match_1 = end1; |
| 3342 |
end_match_2 = string2 + stop - size1; |
| 3343 |
} |
| 3344 |
|
| 3345 |
|
| 3346 |
|
| 3347 |
|
| 3348 |
|
| 3349 |
|
| 3350 |
|
| 3351 |
if (size1 > 0 && pos <= size1) |
| 3352 |
{ |
| 3353 |
d = string1 + pos; |
| 3354 |
dend = end_match_1; |
| 3355 |
} |
| 3356 |
else |
| 3357 |
{ |
| 3358 |
d = string2 + pos - size1; |
| 3359 |
dend = end_match_2; |
| 3360 |
} |
| 3361 |
|
| 3362 |
DEBUG_PRINT1 ("The compiled pattern is: "); |
| 3363 |
DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend); |
| 3364 |
DEBUG_PRINT1 ("The string to match is: `"); |
| 3365 |
DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2); |
| 3366 |
DEBUG_PRINT1 ("'\n"); |
| 3367 |
|
| 3368 |
|
| 3369 |
|
| 3370 |
|
| 3371 |
for (;;) |
| 3372 |
{ |
| 3373 |
DEBUG_PRINT2 ("\n0x%x: ", p); |
| 3374 |
|
| 3375 |
if (p == pend) |
| 3376 |
{ |
| 3377 |
DEBUG_PRINT1 ("end of pattern ... "); |
| 3378 |
|
| 3379 |
|
| 3380 |
|
| 3381 |
if (d != end_match_2) |
| 3382 |
{ |
| 3383 |
DEBUG_PRINT1 ("backtracking.\n"); |
| 3384 |
|
| 3385 |
if (!FAIL_STACK_EMPTY ()) |
| 3386 |
{ |
| 3387 |
boolean same_str_p = (FIRST_STRING_P (match_end) |
| 3388 |
== MATCHING_IN_FIRST_STRING); |
| 3389 |
|
| 3390 |
|
| 3391 |
if (!best_regs_set |
| 3392 |
|| (same_str_p && d > match_end) |
| 3393 |
|| (!same_str_p && !MATCHING_IN_FIRST_STRING)) |
| 3394 |
{ |
| 3395 |
best_regs_set = true; |
| 3396 |
match_end = d; |
| 3397 |
|
| 3398 |
DEBUG_PRINT1 ("\nSAVING match as best so far.\n"); |
| 3399 |
|
| 3400 |
for (mcnt = 1; mcnt < num_regs; mcnt++) |
| 3401 |
{ |
| 3402 |
best_regstart[mcnt] = regstart[mcnt]; |
| 3403 |
best_regend[mcnt] = regend[mcnt]; |
| 3404 |
} |
| 3405 |
} |
| 3406 |
goto fail; |
| 3407 |
} |
| 3408 |
|
| 3409 |
|
| 3410 |
else if (best_regs_set) |
| 3411 |
{ |
| 3412 |
restore_best_regs: |
| 3413 |
|
| 3414 |
|
| 3415 |
|
| 3416 |
|
| 3417 |
|
| 3418 |
DEBUG_PRINT1 ("Restoring best registers.\n"); |
| 3419 |
|
| 3420 |
d = match_end; |
| 3421 |
dend = ((d >= string1 && d <= end1) |
| 3422 |
? end_match_1 : end_match_2); |
| 3423 |
|
| 3424 |
for (mcnt = 1; mcnt < num_regs; mcnt++) |
| 3425 |
{ |
| 3426 |
regstart[mcnt] = best_regstart[mcnt]; |
| 3427 |
regend[mcnt] = best_regend[mcnt]; |
| 3428 |
} |
| 3429 |
} |
| 3430 |
} |
| 3431 |
|
| 3432 |
DEBUG_PRINT1 ("Accepting match.\n"); |
| 3433 |
|
| 3434 |
|
| 3435 |
if (regs && !bufp->no_sub) |
| 3436 |
{ |
| 3437 |
|
| 3438 |
if (bufp->regs_allocated == REGS_UNALLOCATED) |
| 3439 |
{ |
| 3440 |
|
| 3441 |
|
| 3442 |
regs->num_regs = MAX (RE_NREGS, num_regs + 1); |
| 3443 |
regs->start = TALLOC (regs->num_regs, regoff_t); |
| 3444 |
regs->end = TALLOC (regs->num_regs, regoff_t); |
| 3445 |
if (regs->start == NULL || regs->end == NULL) |
| 3446 |
return -2; |
| 3447 |
bufp->regs_allocated = REGS_REALLOCATE; |
| 3448 |
} |
| 3449 |
else if (bufp->regs_allocated == REGS_REALLOCATE) |
| 3450 |
{ |
| 3451 |
|
| 3452 |
|
| 3453 |
if (regs->num_regs < num_regs + 1) |
| 3454 |
{ |
| 3455 |
regs->num_regs = num_regs + 1; |
| 3456 |
RETALLOC (regs->start, regs->num_regs, regoff_t); |
| 3457 |
RETALLOC (regs->end, regs->num_regs, regoff_t); |
| 3458 |
if (regs->start == NULL || regs->end == NULL) |
| 3459 |
return -2; |
| 3460 |
} |
| 3461 |
} |
| 3462 |
else |
| 3463 |
assert (bufp->regs_allocated == REGS_FIXED); |
| 3464 |
|
| 3465 |
|
| 3466 |
|
| 3467 |
|
| 3468 |
if (regs->num_regs > 0) |
| 3469 |
{ |
| 3470 |
regs->start[0] = pos; |
| 3471 |
regs->end[0] = (MATCHING_IN_FIRST_STRING ? d - string1 |
| 3472 |
: d - string2 + size1); |
| 3473 |
} |
| 3474 |
|
| 3475 |
|
| 3476 |
|
| 3477 |
for (mcnt = 1; mcnt < MIN (num_regs, regs->num_regs); mcnt++) |
| 3478 |
{ |
| 3479 |
if (REG_UNSET (regstart[mcnt]) || REG_UNSET (regend[mcnt])) |
| 3480 |
regs->start[mcnt] = regs->end[mcnt] = -1; |
| 3481 |
else |
| 3482 |
{ |
| 3483 |
regs->start[mcnt] = POINTER_TO_OFFSET (regstart[mcnt]); |
| 3484 |
regs->end[mcnt] = POINTER_TO_OFFSET (regend[mcnt]); |
| 3485 |
} |
| 3486 |
} |
| 3487 |
|
| 3488 |
|
| 3489 |
|
| 3490 |
|
| 3491 |
|
| 3492 |
|
| 3493 |
for (mcnt = num_regs; mcnt < regs->num_regs; mcnt++) |
| 3494 |
regs->start[mcnt] = regs->end[mcnt] = -1; |
| 3495 |
} |
| 3496 |
|
| 3497 |
FREE_VARIABLES (); |
| 3498 |
DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n", |
| 3499 |
nfailure_points_pushed, nfailure_points_popped, |
| 3500 |
nfailure_points_pushed - nfailure_points_popped); |
| 3501 |
DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed); |
| 3502 |
|
| 3503 |
mcnt = d - pos - (MATCHING_IN_FIRST_STRING |
| 3504 |
? string1 |
| 3505 |
: string2 - size1); |
| 3506 |
|
| 3507 |
DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt); |
| 3508 |
|
| 3509 |
return mcnt; |
| 3510 |
} |
| 3511 |
|
| 3512 |
|
| 3513 |
#ifdef SWITCH_ENUM_BUG |
| 3514 |
switch ((int) ((re_opcode_t) *p++)) |
| 3515 |
#else |
| 3516 |
switch ((re_opcode_t) *p++) |
| 3517 |
#endif |
| 3518 |
{ |
| 3519 |
|
| 3520 |
|
| 3521 |
case no_op: |
| 3522 |
DEBUG_PRINT1 ("EXECUTING no_op.\n"); |
| 3523 |
break; |
| 3524 |
|
| 3525 |
|
| 3526 |
|
| 3527 |
|
| 3528 |
|
| 3529 |
case exactn: |
| 3530 |
mcnt = *p++; |
| 3531 |
DEBUG_PRINT2 ("EXECUTING exactn %d.\n", mcnt); |
| 3532 |
|
| 3533 |
|
| 3534 |
|
| 3535 |
if (translate) |
| 3536 |
{ |
| 3537 |
do |
| 3538 |
{ |
| 3539 |
PREFETCH (); |
| 3540 |
if (translate[(unsigned char) *d++] != (char) *p++) |
| 3541 |
goto fail; |
| 3542 |
} |
| 3543 |
while (--mcnt); |
| 3544 |
} |
| 3545 |
else |
| 3546 |
{ |
| 3547 |
do |
| 3548 |
{ |
| 3549 |
PREFETCH (); |
| 3550 |
if (*d++ != (char) *p++) goto fail; |
| 3551 |
} |
| 3552 |
while (--mcnt); |
| 3553 |
} |
| 3554 |
SET_REGS_MATCHED (); |
| 3555 |
break; |
| 3556 |
|
| 3557 |
|
| 3558 |
|
| 3559 |
case anychar: |
| 3560 |
DEBUG_PRINT1 ("EXECUTING anychar.\n"); |
| 3561 |
|
| 3562 |
PREFETCH (); |
| 3563 |
|
| 3564 |
if ((!(bufp->syntax & RE_DOT_NEWLINE) && TRANSLATE (*d) == '\n') |
| 3565 |
|| (bufp->syntax & RE_DOT_NOT_NULL && TRANSLATE (*d) == '\000')) |
| 3566 |
goto fail; |
| 3567 |
|
| 3568 |
SET_REGS_MATCHED (); |
| 3569 |
DEBUG_PRINT2 (" Matched `%d'.\n", *d); |
| 3570 |
d++; |
| 3571 |
break; |
| 3572 |
|
| 3573 |
|
| 3574 |
case charset: |
| 3575 |
case charset_not: |
| 3576 |
{ |
| 3577 |
register unsigned char c; |
| 3578 |
boolean not = (re_opcode_t) *(p - 1) == charset_not; |
| 3579 |
|
| 3580 |
DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : ""); |
| 3581 |
|
| 3582 |
PREFETCH (); |
| 3583 |
c = TRANSLATE (*d); |
| 3584 |
|
| 3585 |
|
| 3586 |
|
| 3587 |
if (c < (unsigned) (*p * BYTEWIDTH) |
| 3588 |
&& p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) |
| 3589 |
not = !not; |
| 3590 |
|
| 3591 |
p += 1 + *p; |
| 3592 |
|
| 3593 |
if (!not) goto fail; |
| 3594 |
|
| 3595 |
SET_REGS_MATCHED (); |
| 3596 |
d++; |
| 3597 |
break; |
| 3598 |
} |
| 3599 |
|
| 3600 |
|
| 3601 |
|
| 3602 |
|
| 3603 |
|
| 3604 |
|
| 3605 |
|
| 3606 |
case start_memory: |
| 3607 |
DEBUG_PRINT3 ("EXECUTING start_memory %d (%d):\n", *p, p[1]); |
| 3608 |
|
| 3609 |
|
| 3610 |
p1 = p; |
| 3611 |
|
| 3612 |
if (REG_MATCH_NULL_STRING_P (reg_info[*p]) == MATCH_NULL_UNSET_VALUE) |
| 3613 |
REG_MATCH_NULL_STRING_P (reg_info[*p]) |
| 3614 |
= group_match_null_string_p (&p1, pend, reg_info); |
| 3615 |
|
| 3616 |
|
| 3617 |
|
| 3618 |
|
| 3619 |
|
| 3620 |
|
| 3621 |
old_regstart[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p]) |
| 3622 |
? REG_UNSET (regstart[*p]) ? d : regstart[*p] |
| 3623 |
: regstart[*p]; |
| 3624 |
DEBUG_PRINT2 (" old_regstart: %d\n", |
| 3625 |
POINTER_TO_OFFSET (old_regstart[*p])); |
| 3626 |
|
| 3627 |
regstart[*p] = d; |
| 3628 |
DEBUG_PRINT2 (" regstart: %d\n", POINTER_TO_OFFSET (regstart[*p])); |
| 3629 |
|
| 3630 |
IS_ACTIVE (reg_info[*p]) = 1; |
| 3631 |
MATCHED_SOMETHING (reg_info[*p]) = 0; |
| 3632 |
|
| 3633 |
|
| 3634 |
highest_active_reg = *p; |
| 3635 |
|
| 3636 |
|
| 3637 |
|
| 3638 |
if (lowest_active_reg == NO_LOWEST_ACTIVE_REG) |
| 3639 |
lowest_active_reg = *p; |
| 3640 |
|
| 3641 |
|
| 3642 |
p += 2; |
| 3643 |
break; |
| 3644 |
|
| 3645 |
|
| 3646 |
|
| 3647 |
|
| 3648 |
|
| 3649 |
case stop_memory: |
| 3650 |
DEBUG_PRINT3 ("EXECUTING stop_memory %d (%d):\n", *p, p[1]); |
| 3651 |
|
| 3652 |
|
| 3653 |
|
| 3654 |
|
| 3655 |
|
| 3656 |
|
| 3657 |
old_regend[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p]) |
| 3658 |
? REG_UNSET (regend[*p]) ? d : regend[*p] |
| 3659 |
: regend[*p]; |
| 3660 |
DEBUG_PRINT2 (" old_regend: %d\n", |
| 3661 |
POINTER_TO_OFFSET (old_regend[*p])); |
| 3662 |
|
| 3663 |
regend[*p] = d; |
| 3664 |
DEBUG_PRINT2 (" regend: %d\n", POINTER_TO_OFFSET (regend[*p])); |
| 3665 |
|
| 3666 |
|
| 3667 |
IS_ACTIVE (reg_info[*p]) = 0; |
| 3668 |
|
| 3669 |
|
| 3670 |
|
| 3671 |
if (lowest_active_reg == highest_active_reg) |
| 3672 |
{ |
| 3673 |
lowest_active_reg = NO_LOWEST_ACTIVE_REG; |
| 3674 |
highest_active_reg = NO_HIGHEST_ACTIVE_REG; |
| 3675 |
} |
| 3676 |
else |
| 3677 |
{ |
| 3678 |
|
| 3679 |
|
| 3680 |
|
| 3681 |
unsigned char r = *p - 1; |
| 3682 |
while (r > 0 && !IS_ACTIVE (reg_info[r])) |
| 3683 |
r--; |
| 3684 |
|
| 3685 |
|
| 3686 |
|
| 3687 |
|
| 3688 |
|
| 3689 |
|
| 3690 |
|
| 3691 |
|
| 3692 |
if (r == 0) |
| 3693 |
{ |
| 3694 |
lowest_active_reg = NO_LOWEST_ACTIVE_REG; |
| 3695 |
highest_active_reg = NO_HIGHEST_ACTIVE_REG; |
| 3696 |
} |
| 3697 |
else |
| 3698 |
highest_active_reg = r; |
| 3699 |
} |
| 3700 |
|
| 3701 |
|
| 3702 |
|
| 3703 |
|
| 3704 |
|
| 3705 |
|
| 3706 |
if ((!MATCHED_SOMETHING (reg_info[*p]) |
| 3707 |
|| (re_opcode_t) p[-3] == start_memory) |
| 3708 |
&& (p + 2) < pend) |
| 3709 |
{ |
| 3710 |
boolean is_a_jump_n = false; |
| 3711 |
|
| 3712 |
p1 = p + 2; |
| 3713 |
mcnt = 0; |
| 3714 |
switch ((re_opcode_t) *p1++) |
| 3715 |
{ |
| 3716 |
case jump_n: |
| 3717 |
is_a_jump_n = true; |
| 3718 |
case pop_failure_jump: |
| 3719 |
case maybe_pop_jump: |
| 3720 |
case jump: |
| 3721 |
case dummy_failure_jump: |
| 3722 |
EXTRACT_NUMBER_AND_INCR (mcnt, p1); |
| 3723 |
if (is_a_jump_n) |
| 3724 |
p1 += 2; |
| 3725 |
break; |
| 3726 |
|
| 3727 |
default: |
| 3728 |
; |
| 3729 |
} |
| 3730 |
p1 += mcnt; |
| 3731 |
|
| 3732 |
|
| 3733 |
|
| 3734 |
|
| 3735 |
|
| 3736 |
|
| 3737 |
if (mcnt < 0 && (re_opcode_t) *p1 == on_failure_jump |
| 3738 |
&& (re_opcode_t) p1[3] == start_memory && p1[4] == *p) |
| 3739 |
{ |
| 3740 |
|
| 3741 |
|
| 3742 |
|
| 3743 |
|
| 3744 |
|
| 3745 |
|
| 3746 |
|
| 3747 |
|
| 3748 |
|
| 3749 |
|
| 3750 |
if (EVER_MATCHED_SOMETHING (reg_info[*p])) |
| 3751 |
{ |
| 3752 |
unsigned r; |
| 3753 |
|
| 3754 |
EVER_MATCHED_SOMETHING (reg_info[*p]) = 0; |
| 3755 |
|
| 3756 |
|
| 3757 |
for (r = *p; r < *p + *(p + 1); r++) |
| 3758 |
{ |
| 3759 |
regstart[r] = old_regstart[r]; |
| 3760 |
|
| 3761 |
|
| 3762 |
if ((int) old_regend[r] >= (int) regstart[r]) |
| 3763 |
regend[r] = old_regend[r]; |
| 3764 |
} |
| 3765 |
} |
| 3766 |
p1++; |
| 3767 |
EXTRACT_NUMBER_AND_INCR (mcnt, p1); |
| 3768 |
PUSH_FAILURE_POINT (p1 + mcnt, d, -2); |
| 3769 |
|
| 3770 |
goto fail; |
| 3771 |
} |
| 3772 |
} |
| 3773 |
|
| 3774 |
|
| 3775 |
p += 2; |
| 3776 |
break; |
| 3777 |
|
| 3778 |
|
| 3779 |
|
| 3780 |
|
| 3781 |
case duplicate: |
| 3782 |
{ |
| 3783 |
register const char *d2, *dend2; |
| 3784 |
int regno = *p++; |
| 3785 |
DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno); |
| 3786 |
|
| 3787 |
|
| 3788 |
if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno])) |
| 3789 |
goto fail; |
| 3790 |
|
| 3791 |
|
| 3792 |
d2 = regstart[regno]; |
| 3793 |
|
| 3794 |
|
| 3795 |
|
| 3796 |
|
| 3797 |
|
| 3798 |
|
| 3799 |
dend2 = ((FIRST_STRING_P (regstart[regno]) |
| 3800 |
== FIRST_STRING_P (regend[regno])) |
| 3801 |
? regend[regno] : end_match_1); |
| 3802 |
for (;;) |
| 3803 |
{ |
| 3804 |
|
| 3805 |
|
| 3806 |
while (d2 == dend2) |
| 3807 |
{ |
| 3808 |
if (dend2 == end_match_2) break; |
| 3809 |
if (dend2 == regend[regno]) break; |
| 3810 |
|
| 3811 |
|
| 3812 |
d2 = string2; |
| 3813 |
dend2 = regend[regno]; |
| 3814 |
} |
| 3815 |
|
| 3816 |
if (d2 == dend2) break; |
| 3817 |
|
| 3818 |
|
| 3819 |
PREFETCH (); |
| 3820 |
|
| 3821 |
|
| 3822 |
mcnt = dend - d; |
| 3823 |
|
| 3824 |
|
| 3825 |
|
| 3826 |
if (mcnt > dend2 - d2) |
| 3827 |
mcnt = dend2 - d2; |
| 3828 |
|
| 3829 |
|
| 3830 |
|
| 3831 |
if (translate |
| 3832 |
? bcmp_translate (d, d2, mcnt, translate) |
| 3833 |
: bcmp (d, d2, mcnt)) |
| 3834 |
goto fail; |
| 3835 |
d += mcnt, d2 += mcnt; |
| 3836 |
} |
| 3837 |
} |
| 3838 |
break; |
| 3839 |
|
| 3840 |
|
| 3841 |
|
| 3842 |
|
| 3843 |
|
| 3844 |
case begline: |
| 3845 |
DEBUG_PRINT1 ("EXECUTING begline.\n"); |
| 3846 |
|
| 3847 |
if (AT_STRINGS_BEG (d)) |
| 3848 |
{ |
| 3849 |
if (!bufp->not_bol) break; |
| 3850 |
} |
| 3851 |
else if (d[-1] == '\n' && bufp->newline_anchor) |
| 3852 |
{ |
| 3853 |
break; |
| 3854 |
} |
| 3855 |
|
| 3856 |
goto fail; |
| 3857 |
|
| 3858 |
|
| 3859 |
|
| 3860 |
case endline: |
| 3861 |
DEBUG_PRINT1 ("EXECUTING endline.\n"); |
| 3862 |
|
| 3863 |
if (AT_STRINGS_END (d)) |
| 3864 |
{ |
| 3865 |
if (!bufp->not_eol) break; |
| 3866 |
} |
| 3867 |
|
| 3868 |
|
| 3869 |
else if ((d == end1 ? *string2 : *d) == '\n' |
| 3870 |
&& bufp->newline_anchor) |
| 3871 |
{ |
| 3872 |
break; |
| 3873 |
} |
| 3874 |
goto fail; |
| 3875 |
|
| 3876 |
|
| 3877 |
|
| 3878 |
case begbuf: |
| 3879 |
DEBUG_PRINT1 ("EXECUTING begbuf.\n"); |
| 3880 |
if (AT_STRINGS_BEG (d)) |
| 3881 |
break; |
| 3882 |
goto fail; |
| 3883 |
|
| 3884 |
|
| 3885 |
|
| 3886 |
case endbuf: |
| 3887 |
DEBUG_PRINT1 ("EXECUTING endbuf.\n"); |
| 3888 |
if (AT_STRINGS_END (d)) |
| 3889 |
break; |
| 3890 |
goto fail; |
| 3891 |
|
| 3892 |
|
| 3893 |
|
| 3894 |
|
| 3895 |
|
| 3896 |
|
| 3897 |
|
| 3898 |
|
| 3899 |
|
| 3900 |
|
| 3901 |
|
| 3902 |
|
| 3903 |
|
| 3904 |
|
| 3905 |
|
| 3906 |
|
| 3907 |
|
| 3908 |
|
| 3909 |
case on_failure_keep_string_jump: |
| 3910 |
DEBUG_PRINT1 ("EXECUTING on_failure_keep_string_jump"); |
| 3911 |
|
| 3912 |
EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 3913 |
DEBUG_PRINT3 (" %d (to 0x%x):\n", mcnt, p + mcnt); |
| 3914 |
|
| 3915 |
PUSH_FAILURE_POINT (p + mcnt, NULL, -2); |
| 3916 |
break; |
| 3917 |
|
| 3918 |
|
| 3919 |
|
| 3920 |
|
| 3921 |
|
| 3922 |
|
| 3923 |
|
| 3924 |
|
| 3925 |
|
| 3926 |
|
| 3927 |
|
| 3928 |
|
| 3929 |
|
| 3930 |
|
| 3931 |
case on_failure_jump: |
| 3932 |
on_failure: |
| 3933 |
DEBUG_PRINT1 ("EXECUTING on_failure_jump"); |
| 3934 |
|
| 3935 |
EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 3936 |
DEBUG_PRINT3 (" %d (to 0x%x)", mcnt, p + mcnt); |
| 3937 |
|
| 3938 |
|
| 3939 |
|
| 3940 |
|
| 3941 |
|
| 3942 |
|
| 3943 |
|
| 3944 |
|
| 3945 |
|
| 3946 |
|
| 3947 |
p1 = p; |
| 3948 |
|
| 3949 |
|
| 3950 |
|
| 3951 |
|
| 3952 |
|
| 3953 |
while (p1 < pend && (re_opcode_t) *p1 == no_op) |
| 3954 |
p1++; |
| 3955 |
|
| 3956 |
if (p1 < pend && (re_opcode_t) *p1 == start_memory) |
| 3957 |
{ |
| 3958 |
|
| 3959 |
|
| 3960 |
|
| 3961 |
|
| 3962 |
highest_active_reg = *(p1 + 1) + *(p1 + 2); |
| 3963 |
if (lowest_active_reg == NO_LOWEST_ACTIVE_REG) |
| 3964 |
lowest_active_reg = *(p1 + 1); |
| 3965 |
} |
| 3966 |
|
| 3967 |
DEBUG_PRINT1 (":\n"); |
| 3968 |
PUSH_FAILURE_POINT (p + mcnt, d, -2); |
| 3969 |
break; |
| 3970 |
|
| 3971 |
|
| 3972 |
|
| 3973 |
|
| 3974 |
case maybe_pop_jump: |
| 3975 |
EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 3976 |
DEBUG_PRINT2 ("EXECUTING maybe_pop_jump %d.\n", mcnt); |
| 3977 |
{ |
| 3978 |
register unsigned char *p2 = p; |
| 3979 |
|
| 3980 |
|
| 3981 |
|
| 3982 |
|
| 3983 |
|
| 3984 |
|
| 3985 |
|
| 3986 |
|
| 3987 |
|
| 3988 |
|
| 3989 |
|
| 3990 |
|
| 3991 |
|
| 3992 |
|
| 3993 |
|
| 3994 |
while (p2 + 2 < pend |
| 3995 |
&& ((re_opcode_t) *p2 == stop_memory |
| 3996 |
|| (re_opcode_t) *p2 == start_memory)) |
| 3997 |
p2 += 3; |
| 3998 |
|
| 3999 |
|
| 4000 |
if (p2 == pend) |
| 4001 |
{ |
| 4002 |
|
| 4003 |
|
| 4004 |
|
| 4005 |
p[-3] = (unsigned char) pop_failure_jump; |
| 4006 |
DEBUG_PRINT1 |
| 4007 |
(" End of pattern: change to `pop_failure_jump'.\n"); |
| 4008 |
} |
| 4009 |
|
| 4010 |
else if ((re_opcode_t) *p2 == exactn |
| 4011 |
|| (bufp->newline_anchor && (re_opcode_t) *p2 == endline)) |
| 4012 |
{ |
| 4013 |
register unsigned char c |
| 4014 |
= *p2 == (unsigned char) endline ? '\n' : p2[2]; |
| 4015 |
p1 = p + mcnt; |
| 4016 |
|
| 4017 |
|
| 4018 |
|
| 4019 |
|
| 4020 |
if ((re_opcode_t) p1[3] == exactn && p1[5] != c) |
| 4021 |
{ |
| 4022 |
p[-3] = (unsigned char) pop_failure_jump; |
| 4023 |
DEBUG_PRINT3 (" %c != %c => pop_failure_jump.\n", |
| 4024 |
c, p1[5]); |
| 4025 |
} |
| 4026 |
|
| 4027 |
else if ((re_opcode_t) p1[3] == charset |
| 4028 |
|| (re_opcode_t) p1[3] == charset_not) |
| 4029 |
{ |
| 4030 |
int not = (re_opcode_t) p1[3] == charset_not; |
| 4031 |
|
| 4032 |
if (c < (unsigned char) (p1[4] * BYTEWIDTH) |
| 4033 |
&& p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) |
| 4034 |
not = !not; |
| 4035 |
|
| 4036 |
|
| 4037 |
|
| 4038 |
if (!not) |
| 4039 |
{ |
| 4040 |
p[-3] = (unsigned char) pop_failure_jump; |
| 4041 |
DEBUG_PRINT1 (" No match => pop_failure_jump.\n"); |
| 4042 |
} |
| 4043 |
} |
| 4044 |
} |
| 4045 |
} |
| 4046 |
p -= 2; |
| 4047 |
if ((re_opcode_t) p[-1] != pop_failure_jump) |
| 4048 |
{ |
| 4049 |
p[-1] = (unsigned char) jump; |
| 4050 |
DEBUG_PRINT1 (" Match => jump.\n"); |
| 4051 |
goto unconditional_jump; |
| 4052 |
} |
| 4053 |
|
| 4054 |
|
| 4055 |
|
| 4056 |
|
| 4057 |
|
| 4058 |
|
| 4059 |
|
| 4060 |
|
| 4061 |
|
| 4062 |
case pop_failure_jump: |
| 4063 |
{ |
| 4064 |
|
| 4065 |
|
| 4066 |
|
| 4067 |
|
| 4068 |
|
| 4069 |
unsigned dummy_low_reg, dummy_high_reg; |
| 4070 |
unsigned char *pdummy; |
| 4071 |
const char *sdummy; |
| 4072 |
|
| 4073 |
DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n"); |
| 4074 |
POP_FAILURE_POINT (sdummy, pdummy, |
| 4075 |
dummy_low_reg, dummy_high_reg, |
| 4076 |
reg_dummy, reg_dummy, reg_info_dummy); |
| 4077 |
} |
| 4078 |
|
| 4079 |
|
| 4080 |
|
| 4081 |
|
| 4082 |
case jump: |
| 4083 |
unconditional_jump: |
| 4084 |
EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 4085 |
DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt); |
| 4086 |
p += mcnt; |
| 4087 |
DEBUG_PRINT2 ("(to 0x%x).\n", p); |
| 4088 |
break; |
| 4089 |
|
| 4090 |
|
| 4091 |
|
| 4092 |
|
| 4093 |
case jump_past_alt: |
| 4094 |
DEBUG_PRINT1 ("EXECUTING jump_past_alt.\n"); |
| 4095 |
goto unconditional_jump; |
| 4096 |
|
| 4097 |
|
| 4098 |
|
| 4099 |
|
| 4100 |
|
| 4101 |
|
| 4102 |
|
| 4103 |
case dummy_failure_jump: |
| 4104 |
DEBUG_PRINT1 ("EXECUTING dummy_failure_jump.\n"); |
| 4105 |
|
| 4106 |
|
| 4107 |
PUSH_FAILURE_POINT (0, 0, -2); |
| 4108 |
goto unconditional_jump; |
| 4109 |
|
| 4110 |
|
| 4111 |
|
| 4112 |
|
| 4113 |
|
| 4114 |
|
| 4115 |
|
| 4116 |
case push_dummy_failure: |
| 4117 |
DEBUG_PRINT1 ("EXECUTING push_dummy_failure.\n"); |
| 4118 |
|
| 4119 |
|
| 4120 |
PUSH_FAILURE_POINT (0, 0, -2); |
| 4121 |
break; |
| 4122 |
|
| 4123 |
|
| 4124 |
|
| 4125 |
case succeed_n: |
| 4126 |
EXTRACT_NUMBER (mcnt, p + 2); |
| 4127 |
DEBUG_PRINT2 ("EXECUTING succeed_n %d.\n", mcnt); |
| 4128 |
|
| 4129 |
assert (mcnt >= 0); |
| 4130 |
|
| 4131 |
if (mcnt > 0) |
| 4132 |
{ |
| 4133 |
mcnt--; |
| 4134 |
p += 2; |
| 4135 |
STORE_NUMBER_AND_INCR (p, mcnt); |
| 4136 |
DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p, mcnt); |
| 4137 |
} |
| 4138 |
else if (mcnt == 0) |
| 4139 |
{ |
| 4140 |
DEBUG_PRINT2 (" Setting two bytes from 0x%x to no_op.\n", p+2); |
| 4141 |
p[2] = (unsigned char) no_op; |
| 4142 |
p[3] = (unsigned char) no_op; |
| 4143 |
goto on_failure; |
| 4144 |
} |
| 4145 |
break; |
| 4146 |
|
| 4147 |
case jump_n: |
| 4148 |
EXTRACT_NUMBER (mcnt, p + 2); |
| 4149 |
DEBUG_PRINT2 ("EXECUTING jump_n %d.\n", mcnt); |
| 4150 |
|
| 4151 |
|
| 4152 |
if (mcnt) |
| 4153 |
{ |
| 4154 |
mcnt--; |
| 4155 |
STORE_NUMBER (p + 2, mcnt); |
| 4156 |
goto unconditional_jump; |
| 4157 |
} |
| 4158 |
|
| 4159 |
else |
| 4160 |
p += 4; |
| 4161 |
break; |
| 4162 |
|
| 4163 |
case set_number_at: |
| 4164 |
{ |
| 4165 |
DEBUG_PRINT1 ("EXECUTING set_number_at.\n"); |
| 4166 |
|
| 4167 |
EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 4168 |
p1 = p + mcnt; |
| 4169 |
EXTRACT_NUMBER_AND_INCR (mcnt, p); |
| 4170 |
DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p1, mcnt); |
| 4171 |
STORE_NUMBER (p1, mcnt); |
| 4172 |
break; |
| 4173 |
} |
| 4174 |
|
| 4175 |
case wordbound: |
| 4176 |
DEBUG_PRINT1 ("EXECUTING wordbound.\n"); |
| 4177 |
if (AT_WORD_BOUNDARY (d)) |
| 4178 |
break; |
| 4179 |
goto fail; |
| 4180 |
|
| 4181 |
case notwordbound: |
| 4182 |
DEBUG_PRINT1 ("EXECUTING notwordbound.\n"); |
| 4183 |
if (AT_WORD_BOUNDARY (d)) |
| 4184 |
goto fail; |
| 4185 |
break; |
| 4186 |
|
| 4187 |
case wordbeg: |
| 4188 |
DEBUG_PRINT1 ("EXECUTING wordbeg.\n"); |
| 4189 |
if (WORDCHAR_P (d) && (AT_STRINGS_BEG (d) || !WORDCHAR_P (d - 1))) |
| 4190 |
break; |
| 4191 |
goto fail; |
| 4192 |
|
| 4193 |
case wordend: |
| 4194 |
DEBUG_PRINT1 ("EXECUTING wordend.\n"); |
| 4195 |
if (!AT_STRINGS_BEG (d) && WORDCHAR_P (d - 1) |
| 4196 |
&& (!WORDCHAR_P (d) || AT_STRINGS_END (d))) |
| 4197 |
break; |
| 4198 |
goto fail; |
| 4199 |
|
| 4200 |
#ifdef emacs |
| 4201 |
#ifdef emacs19 |
| 4202 |
case before_dot: |
| 4203 |
DEBUG_PRINT1 ("EXECUTING before_dot.\n"); |
| 4204 |
if (PTR_CHAR_POS ((unsigned char *) d) >= point) |
| 4205 |
goto fail; |
| 4206 |
break; |
| 4207 |
|
| 4208 |
case at_dot: |
| 4209 |
DEBUG_PRINT1 ("EXECUTING at_dot.\n"); |
| 4210 |
if (PTR_CHAR_POS ((unsigned char *) d) != point) |
| 4211 |
goto fail; |
| 4212 |
break; |
| 4213 |
|
| 4214 |
case after_dot: |
| 4215 |
DEBUG_PRINT1 ("EXECUTING after_dot.\n"); |
| 4216 |
if (PTR_CHAR_POS ((unsigned char *) d) <= point) |
| 4217 |
goto fail; |
| 4218 |
break; |
| 4219 |
#else |
| 4220 |
case at_dot: |
| 4221 |
DEBUG_PRINT1 ("EXECUTING at_dot.\n"); |
| 4222 |
if (PTR_CHAR_POS ((unsigned char *) d) + 1 != point) |
| 4223 |
goto fail; |
| 4224 |
break; |
| 4225 |
#endif |
| 4226 |
|
| 4227 |
case syntaxspec: |
| 4228 |
DEBUG_PRINT2 ("EXECUTING syntaxspec %d.\n", mcnt); |
| 4229 |
mcnt = *p++; |
| 4230 |
goto matchsyntax; |
| 4231 |
|
| 4232 |
case wordchar: |
| 4233 |
DEBUG_PRINT1 ("EXECUTING Emacs wordchar.\n"); |
| 4234 |
mcnt = (int) Sword; |
| 4235 |
matchsyntax: |
| 4236 |
PREFETCH (); |
| 4237 |
if (SYNTAX (*d++) != (enum syntaxcode) mcnt) |
| 4238 |
goto fail; |
| 4239 |
SET_REGS_MATCHED (); |
| 4240 |
break; |
| 4241 |
|
| 4242 |
case notsyntaxspec: |
| 4243 |
DEBUG_PRINT2 ("EXECUTING notsyntaxspec %d.\n", mcnt); |
| 4244 |
mcnt = *p++; |
| 4245 |
goto matchnotsyntax; |
| 4246 |
|
| 4247 |
case notwordchar: |
| 4248 |
DEBUG_PRINT1 ("EXECUTING Emacs notwordchar.\n"); |
| 4249 |
mcnt = (int) Sword; |
| 4250 |
matchnotsyntax: |
| 4251 |
PREFETCH (); |
| 4252 |
if (SYNTAX (*d++) == (enum syntaxcode) mcnt) |
| 4253 |
goto fail; |
| 4254 |
SET_REGS_MATCHED (); |
| 4255 |
break; |
| 4256 |
|
| 4257 |
#else |
| 4258 |
case wordchar: |
| 4259 |
DEBUG_PRINT1 ("EXECUTING non-Emacs wordchar.\n"); |
| 4260 |
PREFETCH (); |
| 4261 |
if (!WORDCHAR_P (d)) |
| 4262 |
goto fail; |
| 4263 |
SET_REGS_MATCHED (); |
| 4264 |
d++; |
| 4265 |
break; |
| 4266 |
|
| 4267 |
case notwordchar: |
| 4268 |
DEBUG_PRINT1 ("EXECUTING non-Emacs notwordchar.\n"); |
| 4269 |
PREFETCH (); |
| 4270 |
if (WORDCHAR_P (d)) |
| 4271 |
goto fail; |
| 4272 |
SET_REGS_MATCHED (); |
| 4273 |
d++; |
| 4274 |
break; |
| 4275 |
#endif |
| 4276 |
|
| 4277 |
default: |
| 4278 |
abort (); |
| 4279 |
} |
| 4280 |
continue; |
| 4281 |
|
| 4282 |
|
| 4283 |
|
| 4284 |
fail: |
| 4285 |
if (!FAIL_STACK_EMPTY ()) |
| 4286 |
{ |
| 4287 |
DEBUG_PRINT1 ("\nFAIL:\n"); |
| 4288 |
POP_FAILURE_POINT (d, p, |
| 4289 |
lowest_active_reg, highest_active_reg, |
| 4290 |
regstart, regend, reg_info); |
| 4291 |
|
| 4292 |
|
| 4293 |
if (!p) |
| 4294 |
goto fail; |
| 4295 |
|
| 4296 |
|
| 4297 |
assert (p <= pend); |
| 4298 |
if (p < pend) |
| 4299 |
{ |
| 4300 |
boolean is_a_jump_n = false; |
| 4301 |
|
| 4302 |
|
| 4303 |
|
| 4304 |
switch ((re_opcode_t) *p) |
| 4305 |
{ |
| 4306 |
case jump_n: |
| 4307 |
is_a_jump_n = true; |
| 4308 |
case maybe_pop_jump: |
| 4309 |
case pop_failure_jump: |
| 4310 |
case jump: |
| 4311 |
p1 = p + 1; |
| 4312 |
EXTRACT_NUMBER_AND_INCR (mcnt, p1); |
| 4313 |
p1 += mcnt; |
| 4314 |
|
| 4315 |
if ((is_a_jump_n && (re_opcode_t) *p1 == succeed_n) |
| 4316 |
|| (!is_a_jump_n |
| 4317 |
&& (re_opcode_t) *p1 == on_failure_jump)) |
| 4318 |
goto fail; |
| 4319 |
break; |
| 4320 |
default: |
| 4321 |
; |
| 4322 |
} |
| 4323 |
} |
| 4324 |
|
| 4325 |
if (d >= string1 && d <= end1) |
| 4326 |
dend = end_match_1; |
| 4327 |
} |
| 4328 |
else |
| 4329 |
break; |
| 4330 |
} |
| 4331 |
|
| 4332 |
if (best_regs_set) |
| 4333 |
goto restore_best_regs; |
| 4334 |
|
| 4335 |
FREE_VARIABLES (); |
| 4336 |
|
| 4337 |
return -1; |
| 4338 |
} |
| 4339 |
|
| 4340 |
|
| 4341 |
|
| 4342 |
|
| 4343 |
|
| 4344 |
|
| 4345 |
|
| 4346 |
|
| 4347 |
|
| 4348 |
|
| 4349 |
|
| 4350 |
|
| 4351 |
|
| 4352 |
|
| 4353 |
static boolean |
| 4354 |
group_match_null_string_p (p, end, reg_info) |
| 4355 |
unsigned char **p, *end; |
| 4356 |
register_info_type *reg_info; |
| 4357 |
{ |
| 4358 |
int mcnt; |
| 4359 |
|
| 4360 |
unsigned char *p1 = *p + 2; |
| 4361 |
|
| 4362 |
while (p1 < end) |
| 4363 |
{ |
| 4364 |
|
| 4365 |
|
| 4366 |
|
| 4367 |
|
| 4368 |
switch ((re_opcode_t) *p1) |
| 4369 |
{ |
| 4370 |
|
| 4371 |
case on_failure_jump: |
| 4372 |
p1++; |
| 4373 |
EXTRACT_NUMBER_AND_INCR (mcnt, p1); |
| 4374 |
|
| 4375 |
|
| 4376 |
|
| 4377 |
|
| 4378 |
if (mcnt >= 0) |
| 4379 |
{ |
| 4380 |
|
| 4381 |
|
| 4382 |
|
| 4383 |
|
| 4384 |
|
| 4385 |
|
| 4386 |
|
| 4387 |
|
| 4388 |
|
| 4389 |
|
| 4390 |
|
| 4391 |
|
| 4392 |
|
| 4393 |
|
| 4394 |
|
| 4395 |
|
| 4396 |
|
| 4397 |
|
| 4398 |
while ((re_opcode_t) p1[mcnt-3] == jump_past_alt) |
| 4399 |
{ |
| 4400 |
|
| 4401 |
|
| 4402 |
|
| 4403 |
|
| 4404 |
if (!alt_match_null_string_p (p1, p1 + mcnt - 3, |
| 4405 |
reg_info)) |
| 4406 |
return false; |
| 4407 |
|
| 4408 |
|
| 4409 |
|
| 4410 |
p1 += mcnt; |
| 4411 |
|
| 4412 |
|
| 4413 |
|
| 4414 |
if ((re_opcode_t) *p1 != on_failure_jump) |
| 4415 |
break; |
| 4416 |
|
| 4417 |
|
| 4418 |
|
| 4419 |
p1++; |
| 4420 |
EXTRACT_NUMBER_AND_INCR (mcnt, p1); |
| 4421 |
if ((re_opcode_t) p1[mcnt-3] != jump_past_alt) |
| 4422 |
{ |
| 4423 |
|
| 4424 |
p1 -= 3; |
| 4425 |
break; |
| 4426 |
} |
| 4427 |
} |
| 4428 |
|
| 4429 |
|
| 4430 |
|
| 4431 |
|
| 4432 |
EXTRACT_NUMBER (mcnt, p1 - 2); |
| 4433 |
|
| 4434 |
if (!alt_match_null_string_p (p1, p1 + mcnt, reg_info)) |
| 4435 |
return false; |
| 4436 |
|
| 4437 |
p1 += mcnt; |
| 4438 |
} |
| 4439 |
break; |
| 4440 |
|
| 4441 |
|
| 4442 |
case stop_memory: |
| 4443 |
assert (p1[1] == **p); |
| 4444 |
*p = p1 + 2; |
| 4445 |
return true; |
| 4446 |
|
| 4447 |
|
| 4448 |
default: |
| 4449 |
if (!common_op_match_null_string_p (&p1, end, reg_info)) |
| 4450 |
return false; |
| 4451 |
} |
| 4452 |
} |
| 4453 |
|
| 4454 |
return false; |
| 4455 |
} |
| 4456 |
|
| 4457 |
|
| 4458 |
|
| 4459 |
|
| 4460 |
|
| 4461 |
|
| 4462 |
static boolean |
| 4463 |
alt_match_null_string_p (p, end, reg_info) |
| 4464 |
unsigned char *p, *end; |
| 4465 |
register_info_type *reg_info; |
| 4466 |
{ |
| 4467 |
int mcnt; |
| 4468 |
unsigned char *p1 = p; |
| 4469 |
|
| 4470 |
while (p1 < end) |
| 4471 |
{ |
| 4472 |
|
| 4473 |
|
| 4474 |
|
| 4475 |
switch ((re_opcode_t) *p1) |
| 4476 |
{ |
| 4477 |
|
| 4478 |
case on_failure_jump: |
| 4479 |
p1++; |
| 4480 |
EXTRACT_NUMBER_AND_INCR (mcnt, p1); |
| 4481 |
p1 += mcnt; |
| 4482 |
break; |
| 4483 |
|
| 4484 |
default: |
| 4485 |
if (!common_op_match_null_string_p (&p1, end, reg_info)) |
| 4486 |
return false; |
| 4487 |
} |
| 4488 |
} |
| 4489 |
|
| 4490 |
return true; |
| 4491 |
} |
| 4492 |
|
| 4493 |
|
| 4494 |
|
| 4495 |
|
| 4496 |
|
| 4497 |
|
| 4498 |
|
| 4499 |
static boolean |
| 4500 |
common_op_match_null_string_p (p, end, reg_info) |
| 4501 |
unsigned char **p, *end; |
| 4502 |
register_info_type *reg_info; |
| 4503 |
{ |
| 4504 |
int mcnt; |
| 4505 |
boolean ret; |
| 4506 |
int reg_no; |
| 4507 |
unsigned char *p1 = *p; |
| 4508 |
|
| 4509 |
switch ((re_opcode_t) *p1++) |
| 4510 |
{ |
| 4511 |
case no_op: |
| 4512 |
case begline: |
| 4513 |
case endline: |
| 4514 |
case begbuf: |
| 4515 |
case endbuf: |
| 4516 |
case wordbeg: |
| 4517 |
case wordend: |
| 4518 |
case wordbound: |
| 4519 |
case notwordbound: |
| 4520 |
#ifdef emacs |
| 4521 |
case before_dot: |
| 4522 |
case at_dot: |
| 4523 |
case after_dot: |
| 4524 |
#endif |
| 4525 |
break; |
| 4526 |
|
| 4527 |
case start_memory: |
| 4528 |
reg_no = *p1; |
| 4529 |
assert (reg_no > 0 && reg_no <= MAX_REGNUM); |
| 4530 |
ret = group_match_null_string_p (&p1, end, reg_info); |
| 4531 |
|
| 4532 |
|
| 4533 |
|
| 4534 |
|
| 4535 |
if (REG_MATCH_NULL_STRING_P (reg_info[reg_no]) == MATCH_NULL_UNSET_VALUE) |
| 4536 |
REG_MATCH_NULL_STRING_P (reg_info[reg_no]) = ret; |
| 4537 |
|
| 4538 |
if (!ret) |
| 4539 |
return false; |
| 4540 |
break; |
| 4541 |
|
| 4542 |
|
| 4543 |
case jump: |
| 4544 |
EXTRACT_NUMBER_AND_INCR (mcnt, p1); |
| 4545 |
if (mcnt >= 0) |
| 4546 |
p1 += mcnt; |
| 4547 |
else |
| 4548 |
return false; |
| 4549 |
break; |
| 4550 |
|
| 4551 |
case succeed_n: |
| 4552 |
|
| 4553 |
p1 += 2; |
| 4554 |
EXTRACT_NUMBER_AND_INCR (mcnt, p1); |
| 4555 |
|
| 4556 |
if (mcnt == 0) |
| 4557 |
{ |
| 4558 |
p1 -= 4; |
| 4559 |
EXTRACT_NUMBER_AND_INCR (mcnt, p1); |
| 4560 |
p1 += mcnt; |
| 4561 |
} |
| 4562 |
else |
| 4563 |
return false; |
| 4564 |
break; |
| 4565 |
|
| 4566 |
case duplicate: |
| 4567 |
if (!REG_MATCH_NULL_STRING_P (reg_info[*p1])) |
| 4568 |
return false; |
| 4569 |
break; |
| 4570 |
|
| 4571 |
case set_number_at: |
| 4572 |
p1 += 4; |
| 4573 |
|
| 4574 |
default: |
| 4575 |
|
| 4576 |
return false; |
| 4577 |
} |
| 4578 |
|
| 4579 |
*p = p1; |
| 4580 |
return true; |
| 4581 |
} |
| 4582 |
|
| 4583 |
|
| 4584 |
|
| 4585 |
|
| 4586 |
|
| 4587 |
static int |
| 4588 |
bcmp_translate (s1, s2, len, translate) |
| 4589 |
unsigned char *s1, *s2; |
| 4590 |
register int len; |
| 4591 |
char *translate; |
| 4592 |
{ |
| 4593 |
register unsigned char *p1 = s1, *p2 = s2; |
| 4594 |
while (len) |
| 4595 |
{ |
| 4596 |
if (translate[*p1++] != translate[*p2++]) return 1; |
| 4597 |
len--; |
| 4598 |
} |
| 4599 |
return 0; |
| 4600 |
} |
| 4601 |
|
| 4602 |
|
| 4603 |
|
| 4604 |
|
| 4605 |
|
| 4606 |
|
| 4607 |
|
| 4608 |
|
| 4609 |
|
| 4610 |
|
| 4611 |
|
| 4612 |
|
| 4613 |
const char * |
| 4614 |
re_compile_pattern (pattern, length, bufp) |
| 4615 |
const char *pattern; |
| 4616 |
int length; |
| 4617 |
struct re_pattern_buffer *bufp; |
| 4618 |
{ |
| 4619 |
reg_errcode_t ret; |
| 4620 |
|
| 4621 |
|
| 4622 |
|
| 4623 |
bufp->regs_allocated = REGS_UNALLOCATED; |
| 4624 |
|
| 4625 |
|
| 4626 |
|
| 4627 |
|
| 4628 |
bufp->no_sub = 0; |
| 4629 |
|
| 4630 |
|
| 4631 |
bufp->newline_anchor = 1; |
| 4632 |
|
| 4633 |
ret = regex_compile (pattern, length, re_syntax_options, bufp); |
| 4634 |
|
| 4635 |
return re_error_msg[(int) ret]; |
| 4636 |
} |
| 4637 |
|
| 4638 |
|
| 4639 |
|
| 4640 |
|
| 4641 |
#if !defined (emacs) && !defined (_POSIX_SOURCE) |
| 4642 |
|
| 4643 |
|
| 4644 |
static struct re_pattern_buffer re_comp_buf; |
| 4645 |
|
| 4646 |
char * |
| 4647 |
re_comp (s) |
| 4648 |
const char *s; |
| 4649 |
{ |
| 4650 |
reg_errcode_t ret; |
| 4651 |
|
| 4652 |
if (!s) |
| 4653 |
{ |
| 4654 |
if (!re_comp_buf.buffer) |
| 4655 |
return "No previous regular expression"; |
| 4656 |
return 0; |
| 4657 |
} |
| 4658 |
|
| 4659 |
if (!re_comp_buf.buffer) |
| 4660 |
{ |
| 4661 |
re_comp_buf.buffer = (unsigned char *) malloc (200); |
| 4662 |
if (re_comp_buf.buffer == NULL) |
| 4663 |
return "Memory exhausted"; |
| 4664 |
re_comp_buf.allocated = 200; |
| 4665 |
|
| 4666 |
re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH); |
| 4667 |
if (re_comp_buf.fastmap == NULL) |
| 4668 |
return "Memory exhausted"; |
| 4669 |
} |
| 4670 |
|
| 4671 |
|
| 4672 |
|
| 4673 |
|
| 4674 |
|
| 4675 |
re_comp_buf.newline_anchor = 1; |
| 4676 |
|
| 4677 |
ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf); |
| 4678 |
|
| 4679 |
|
| 4680 |
return (char *) re_error_msg[(int) ret]; |
| 4681 |
} |
| 4682 |
|
| 4683 |
|
| 4684 |
int |
| 4685 |
re_exec (s) |
| 4686 |
const char *s; |
| 4687 |
{ |
| 4688 |
const int len = strlen (s); |
| 4689 |
return |
| 4690 |
0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0); |
| 4691 |
} |
| 4692 |
#endif |
| 4693 |
|
| 4694 |
|
| 4695 |
|
| 4696 |
#ifndef emacs |
| 4697 |
|
| 4698 |
|
| 4699 |
|
| 4700 |
|
| 4701 |
|
| 4702 |
|
| 4703 |
|
| 4704 |
|
| 4705 |
|
| 4706 |
|
| 4707 |
|
| 4708 |
|
| 4709 |
|
| 4710 |
|
| 4711 |
|
| 4712 |
|
| 4713 |
|
| 4714 |
|
| 4715 |
|
| 4716 |
|
| 4717 |
|
| 4718 |
|
| 4719 |
|
| 4720 |
|
| 4721 |
|
| 4722 |
|
| 4723 |
|
| 4724 |
|
| 4725 |
|
| 4726 |
|
| 4727 |
|
| 4728 |
|
| 4729 |
|
| 4730 |
|
| 4731 |
|
| 4732 |
int |
| 4733 |
regcomp (preg, pattern, cflags) |
| 4734 |
regex_t *preg; |
| 4735 |
const char *pattern; |
| 4736 |
int cflags; |
| 4737 |
{ |
| 4738 |
reg_errcode_t ret; |
| 4739 |
unsigned syntax |
| 4740 |
= (cflags & REG_EXTENDED) ? |
| 4741 |
RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC; |
| 4742 |
|
| 4743 |
|
| 4744 |
preg->buffer = 0; |
| 4745 |
preg->allocated = 0; |
| 4746 |
|
| 4747 |
|
| 4748 |
|
| 4749 |
|
| 4750 |
|
| 4751 |
preg->fastmap = 0; |
| 4752 |
|
| 4753 |
if (cflags & REG_ICASE) |
| 4754 |
{ |
| 4755 |
unsigned i; |
| 4756 |
|
| 4757 |
preg->translate = (char *) malloc (CHAR_SET_SIZE); |
| 4758 |
if (preg->translate == NULL) |
| 4759 |
return (int) REG_ESPACE; |
| 4760 |
|
| 4761 |
|
| 4762 |
for (i = 0; i < CHAR_SET_SIZE; i++) |
| 4763 |
preg->translate[i] = ISUPPER (i) ? tolower (i) : i; |
| 4764 |
} |
| 4765 |
else |
| 4766 |
preg->translate = NULL; |
| 4767 |
|
| 4768 |
|
| 4769 |
if (cflags & REG_NEWLINE) |
| 4770 |
{ |
| 4771 |
syntax &= ~RE_DOT_NEWLINE; |
| 4772 |
syntax |= RE_HAT_LISTS_NOT_NEWLINE; |
| 4773 |
|
| 4774 |
preg->newline_anchor = 1; |
| 4775 |
} |
| 4776 |
else |
| 4777 |
preg->newline_anchor = 0; |
| 4778 |
|
| 4779 |
preg->no_sub = !!(cflags & REG_NOSUB); |
| 4780 |
|
| 4781 |
|
| 4782 |
|
| 4783 |
ret = regex_compile (pattern, strlen (pattern), syntax, preg); |
| 4784 |
|
| 4785 |
|
| 4786 |
|
| 4787 |
if (ret == REG_ERPAREN) ret = REG_EPAREN; |
| 4788 |
|
| 4789 |
return (int) ret; |
| 4790 |
} |
| 4791 |
|
| 4792 |
|
| 4793 |
|
| 4794 |
|
| 4795 |
|
| 4796 |
|
| 4797 |
|
| 4798 |
|
| 4799 |
|
| 4800 |
|
| 4801 |
|
| 4802 |
|
| 4803 |
|
| 4804 |
|
| 4805 |
|
| 4806 |
|
| 4807 |
int |
| 4808 |
regexec (preg, string, nmatch, pmatch, eflags) |
| 4809 |
const regex_t *preg; |
| 4810 |
const char *string; |
| 4811 |
size_t nmatch; |
| 4812 |
regmatch_t pmatch[]; |
| 4813 |
int eflags; |
| 4814 |
{ |
| 4815 |
int ret; |
| 4816 |
struct re_registers regs; |
| 4817 |
regex_t private_preg; |
| 4818 |
int len = strlen (string); |
| 4819 |
boolean want_reg_info = !preg->no_sub && nmatch > 0; |
| 4820 |
|
| 4821 |
private_preg = *preg; |
| 4822 |
|
| 4823 |
private_preg.not_bol = !!(eflags & REG_NOTBOL); |
| 4824 |
private_preg.not_eol = !!(eflags & REG_NOTEOL); |
| 4825 |
|
| 4826 |
|
| 4827 |
|
| 4828 |
|
| 4829 |
private_preg.regs_allocated = REGS_FIXED; |
| 4830 |
|
| 4831 |
if (want_reg_info) |
| 4832 |
{ |
| 4833 |
regs.num_regs = nmatch; |
| 4834 |
regs.start = TALLOC (nmatch, regoff_t); |
| 4835 |
regs.end = TALLOC (nmatch, regoff_t); |
| 4836 |
if (regs.start == NULL || regs.end == NULL) |
| 4837 |
return (int) REG_NOMATCH; |
| 4838 |
} |
| 4839 |
|
| 4840 |
|
| 4841 |
ret = re_search (&private_preg, string, len, |
| 4842 |
0, len, |
| 4843 |
want_reg_info ? ®s : (struct re_registers *) 0); |
| 4844 |
|
| 4845 |
|
| 4846 |
if (want_reg_info) |
| 4847 |
{ |
| 4848 |
if (ret >= 0) |
| 4849 |
{ |
| 4850 |
unsigned r; |
| 4851 |
|
| 4852 |
for (r = 0; r < nmatch; r++) |
| 4853 |
{ |
| 4854 |
pmatch[r].rm_so = regs.start[r]; |
| 4855 |
pmatch[r].rm_eo = regs.end[r]; |
| 4856 |
} |
| 4857 |
} |
| 4858 |
|
| 4859 |
|
| 4860 |
free (regs.start); |
| 4861 |
free (regs.end); |
| 4862 |
} |
| 4863 |
|
| 4864 |
|
| 4865 |
return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH; |
| 4866 |
} |
| 4867 |
|
| 4868 |
|
| 4869 |
|
| 4870 |
|
| 4871 |
|
| 4872 |
size_t |
| 4873 |
regerror (errcode, preg, errbuf, errbuf_size) |
| 4874 |
int errcode; |
| 4875 |
const regex_t *preg; |
| 4876 |
char *errbuf; |
| 4877 |
size_t errbuf_size; |
| 4878 |
{ |
| 4879 |
const char *msg; |
| 4880 |
size_t msg_size; |
| 4881 |
|
| 4882 |
if (errcode < 0 |
| 4883 |
|| errcode >= (sizeof (re_error_msg) / sizeof (re_error_msg[0]))) |
| 4884 |
|
| 4885 |
|
| 4886 |
|
| 4887 |
|
| 4888 |
abort (); |
| 4889 |
|
| 4890 |
msg = re_error_msg[errcode]; |
| 4891 |
|
| 4892 |
|
| 4893 |
|
| 4894 |
if (! msg) |
| 4895 |
msg = "Success"; |
| 4896 |
|
| 4897 |
msg_size = strlen (msg) + 1; |
| 4898 |
|
| 4899 |
if (errbuf_size != 0) |
| 4900 |
{ |
| 4901 |
if (msg_size > errbuf_size) |
| 4902 |
{ |
| 4903 |
strncpy (errbuf, msg, errbuf_size - 1); |
| 4904 |
errbuf[errbuf_size - 1] = 0; |
| 4905 |
} |
| 4906 |
else |
| 4907 |
strcpy (errbuf, msg); |
| 4908 |
} |
| 4909 |
|
| 4910 |
return msg_size; |
| 4911 |
} |
| 4912 |
|
| 4913 |
|
| 4914 |
|
| 4915 |
|
| 4916 |
void |
| 4917 |
regfree (preg) |
| 4918 |
regex_t *preg; |
| 4919 |
{ |
| 4920 |
if (preg->buffer != NULL) |
| 4921 |
free (preg->buffer); |
| 4922 |
preg->buffer = NULL; |
| 4923 |
|
| 4924 |
preg->allocated = 0; |
| 4925 |
preg->used = 0; |
| 4926 |
|
| 4927 |
if (preg->fastmap != NULL) |
| 4928 |
free (preg->fastmap); |
| 4929 |
preg->fastmap = NULL; |
| 4930 |
preg->fastmap_accurate = 0; |
| 4931 |
|
| 4932 |
if (preg->translate != NULL) |
| 4933 |
free (preg->translate); |
| 4934 |
preg->translate = NULL; |
| 4935 |
} |
| 4936 |
|
| 4937 |
#endif |
| 4938 |
|
| 4939 |
|
| 4940 |
|
| 4941 |
|
| 4942 |
|
| 4943 |
|
| 4944 |
|
| 4945 |
|