comparison src/regex.c @ 2615:4db544ffcbff

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Fri, 30 Apr 1993 16:42:24 +0000
parents cc54f01475dd
children ce6924085fc7
comparison
equal deleted inserted replaced
2614:bad8a1dfeb3b 2615:4db544ffcbff
541 } 541 }
542 542
543 /* Loop over pattern commands. */ 543 /* Loop over pattern commands. */
544 while (p < pend) 544 while (p < pend)
545 { 545 {
546 printf ("%d:\t", p - start);
547
546 switch ((re_opcode_t) *p++) 548 switch ((re_opcode_t) *p++)
547 { 549 {
548 case no_op: 550 case no_op:
549 printf ("/no_op"); 551 printf ("/no_op");
550 break; 552 break;
579 break; 581 break;
580 582
581 case charset: 583 case charset:
582 case charset_not: 584 case charset_not:
583 { 585 {
584 register int c; 586 register int c, last = -100;
585 587 register int in_range = 0;
586 printf ("/charset%s", 588
587 (re_opcode_t) *(p - 1) == charset_not ? "_not" : ""); 589 printf ("/charset [%s",
590 (re_opcode_t) *(p - 1) == charset_not ? "^" : "");
588 591
589 assert (p + *p < pend); 592 assert (p + *p < pend);
590 593
591 for (c = 0; c < *p; c++) 594 for (c = 0; c < 256; c++)
595 if (c / 8 < *p
596 && (p[1 + (c/8)] & (1 << (c % 8))))
597 {
598 /* Are we starting a range? */
599 if (last + 1 == c && ! in_range)
600 {
601 putchar ('-');
602 in_range = 1;
603 }
604 /* Have we broken a range? */
605 else if (last + 1 != c && in_range)
592 { 606 {
593 unsigned bit; 607 printchar (last);
594 unsigned char map_byte = p[1 + c]; 608 in_range = 0;
609 }
595 610
596 putchar ('/'); 611 if (! in_range)
597 612 printchar (c);
598 for (bit = 0; bit < BYTEWIDTH; bit++) 613
599 if (map_byte & (1 << bit)) 614 last = c;
600 printchar (c * BYTEWIDTH + bit);
601 } 615 }
616
617 if (in_range)
618 printchar (last);
619
620 putchar (']');
621
602 p += 1 + *p; 622 p += 1 + *p;
603 break;
604 } 623 }
624 break;
605 625
606 case begline: 626 case begline:
607 printf ("/begline"); 627 printf ("/begline");
608 break; 628 break;
609 629
611 printf ("/endline"); 631 printf ("/endline");
612 break; 632 break;
613 633
614 case on_failure_jump: 634 case on_failure_jump:
615 extract_number_and_incr (&mcnt, &p); 635 extract_number_and_incr (&mcnt, &p);
616 printf ("/on_failure_jump/0/%d", mcnt); 636 printf ("/on_failure_jump to %d", p + mcnt - start);
617 break; 637 break;
618 638
619 case on_failure_keep_string_jump: 639 case on_failure_keep_string_jump:
620 extract_number_and_incr (&mcnt, &p); 640 extract_number_and_incr (&mcnt, &p);
621 printf ("/on_failure_keep_string_jump/0/%d", mcnt); 641 printf ("/on_failure_keep_string_jump to %d", p + mcnt - start);
622 break; 642 break;
623 643
624 case dummy_failure_jump: 644 case dummy_failure_jump:
625 extract_number_and_incr (&mcnt, &p); 645 extract_number_and_incr (&mcnt, &p);
626 printf ("/dummy_failure_jump/0/%d", mcnt); 646 printf ("/dummy_failure_jump to %d", p + mcnt - start);
627 break; 647 break;
628 648
629 case push_dummy_failure: 649 case push_dummy_failure:
630 printf ("/push_dummy_failure"); 650 printf ("/push_dummy_failure");
631 break; 651 break;
632 652
633 case maybe_pop_jump: 653 case maybe_pop_jump:
634 extract_number_and_incr (&mcnt, &p); 654 extract_number_and_incr (&mcnt, &p);
635 printf ("/maybe_pop_jump/0/%d", mcnt); 655 printf ("/maybe_pop_jump to %d", p + mcnt - start);
636 break; 656 break;
637 657
638 case pop_failure_jump: 658 case pop_failure_jump:
639 extract_number_and_incr (&mcnt, &p); 659 extract_number_and_incr (&mcnt, &p);
640 printf ("/pop_failure_jump/0/%d", mcnt); 660 printf ("/pop_failure_jump to %d", p + mcnt - start);
641 break; 661 break;
642 662
643 case jump_past_alt: 663 case jump_past_alt:
644 extract_number_and_incr (&mcnt, &p); 664 extract_number_and_incr (&mcnt, &p);
645 printf ("/jump_past_alt/0/%d", mcnt); 665 printf ("/jump_past_alt to %d", p + mcnt - start);
646 break; 666 break;
647 667
648 case jump: 668 case jump:
649 extract_number_and_incr (&mcnt, &p); 669 extract_number_and_incr (&mcnt, &p);
650 printf ("/jump/0/%d", mcnt); 670 printf ("/jump to %d", p + mcnt - start);
651 break; 671 break;
652 672
653 case succeed_n: 673 case succeed_n:
654 extract_number_and_incr (&mcnt, &p); 674 extract_number_and_incr (&mcnt, &p);
655 extract_number_and_incr (&mcnt2, &p); 675 extract_number_and_incr (&mcnt2, &p);
656 printf ("/succeed_n/0/%d/0/%d", mcnt, mcnt2); 676 printf ("/succeed_n to %d, %d times", p + mcnt - start, mcnt2);
657 break; 677 break;
658 678
659 case jump_n: 679 case jump_n:
660 extract_number_and_incr (&mcnt, &p); 680 extract_number_and_incr (&mcnt, &p);
661 extract_number_and_incr (&mcnt2, &p); 681 extract_number_and_incr (&mcnt2, &p);
662 printf ("/jump_n/0/%d/0/%d", mcnt, mcnt2); 682 printf ("/jump_n to %d, %d times", p + mcnt - start, mcnt2);
663 break; 683 break;
664 684
665 case set_number_at: 685 case set_number_at:
666 extract_number_and_incr (&mcnt, &p); 686 extract_number_and_incr (&mcnt, &p);
667 extract_number_and_incr (&mcnt2, &p); 687 extract_number_and_incr (&mcnt2, &p);
668 printf ("/set_number_at/0/%d/0/%d", mcnt, mcnt2); 688 printf ("/set_number_at location %d to %d", p + mcnt - start, mcnt2);
669 break; 689 break;
670 690
671 case wordbound: 691 case wordbound:
672 printf ("/wordbound"); 692 printf ("/wordbound");
673 break; 693 break;
726 break; 746 break;
727 747
728 default: 748 default:
729 printf ("?%d", *(p-1)); 749 printf ("?%d", *(p-1));
730 } 750 }
751
752 putchar ('\n');
731 } 753 }
732 printf ("/\n"); 754
755 printf ("%d:\tend of pattern.\n", p - start);
733 } 756 }
734 757
735 758
736 void 759 void
737 print_compiled_pattern (bufp) 760 print_compiled_pattern (bufp)
2056 bufp->used = b - bufp->buffer; 2079 bufp->used = b - bufp->buffer;
2057 2080
2058 #ifdef DEBUG 2081 #ifdef DEBUG
2059 if (debug) 2082 if (debug)
2060 { 2083 {
2061 DEBUG_PRINT1 ("\nCompiled pattern: "); 2084 DEBUG_PRINT1 ("\nCompiled pattern: \n");
2062 print_compiled_pattern (bufp); 2085 print_compiled_pattern (bufp);
2063 } 2086 }
2064 #endif /* DEBUG */ 2087 #endif /* DEBUG */
2065 2088
2066 return REG_NOERROR; 2089 return REG_NOERROR;