comparison src/regex.c @ 450:98528da0b7fc r21-2-40

Import from CVS: tag r21-2-40
author cvs
date Mon, 13 Aug 2007 11:39:20 +0200
parents 1ccc32a20af4
children e7ef97881643
comparison
equal deleted inserted replaced
449:c83749d23eb5 450:98528da0b7fc
4155 4155
4156 #define MATCHING_IN_FIRST_STRING (dend == end_match_1) 4156 #define MATCHING_IN_FIRST_STRING (dend == end_match_1)
4157 4157
4158 /* Call before fetching a character with *d. This switches over to 4158 /* Call before fetching a character with *d. This switches over to
4159 string2 if necessary. */ 4159 string2 if necessary. */
4160 #define PREFETCH() \ 4160 #define REGEX_PREFETCH() \
4161 while (d == dend) \ 4161 while (d == dend) \
4162 { \ 4162 { \
4163 /* End of string2 => fail. */ \ 4163 /* End of string2 => fail. */ \
4164 if (dend == end_match_2) \ 4164 if (dend == end_match_2) \
4165 goto fail; \ 4165 goto fail; \
4697 { 4697 {
4698 #ifdef MULE 4698 #ifdef MULE
4699 Emchar pat_ch, buf_ch; 4699 Emchar pat_ch, buf_ch;
4700 Bytecount pat_len; 4700 Bytecount pat_len;
4701 4701
4702 PREFETCH (); 4702 REGEX_PREFETCH ();
4703 pat_ch = charptr_emchar (p); 4703 pat_ch = charptr_emchar (p);
4704 buf_ch = charptr_emchar (d); 4704 buf_ch = charptr_emchar (d);
4705 if (RE_TRANSLATE (buf_ch) != pat_ch) 4705 if (RE_TRANSLATE (buf_ch) != pat_ch)
4706 goto fail; 4706 goto fail;
4707 4707
4709 p += pat_len; 4709 p += pat_len;
4710 INC_CHARPTR (d); 4710 INC_CHARPTR (d);
4711 4711
4712 mcnt -= pat_len; 4712 mcnt -= pat_len;
4713 #else /* not MULE */ 4713 #else /* not MULE */
4714 PREFETCH (); 4714 REGEX_PREFETCH ();
4715 if ((unsigned char) RE_TRANSLATE (*d++) != *p++) 4715 if ((unsigned char) RE_TRANSLATE (*d++) != *p++)
4716 goto fail; 4716 goto fail;
4717 mcnt--; 4717 mcnt--;
4718 #endif 4718 #endif
4719 } 4719 }
4721 } 4721 }
4722 else 4722 else
4723 { 4723 {
4724 do 4724 do
4725 { 4725 {
4726 PREFETCH (); 4726 REGEX_PREFETCH ();
4727 if (*d++ != *p++) goto fail; 4727 if (*d++ != *p++) goto fail;
4728 } 4728 }
4729 while (--mcnt); 4729 while (--mcnt);
4730 } 4730 }
4731 SET_REGS_MATCHED (); 4731 SET_REGS_MATCHED ();
4734 4734
4735 /* Match any character except possibly a newline or a null. */ 4735 /* Match any character except possibly a newline or a null. */
4736 case anychar: 4736 case anychar:
4737 DEBUG_PRINT1 ("EXECUTING anychar.\n"); 4737 DEBUG_PRINT1 ("EXECUTING anychar.\n");
4738 4738
4739 PREFETCH (); 4739 REGEX_PREFETCH ();
4740 4740
4741 if ((!(bufp->syntax & RE_DOT_NEWLINE) && TRANSLATE (*d) == '\n') 4741 if ((!(bufp->syntax & RE_DOT_NEWLINE) && TRANSLATE (*d) == '\n')
4742 || (bufp->syntax & RE_DOT_NOT_NULL && TRANSLATE (*d) == '\000')) 4742 || (bufp->syntax & RE_DOT_NOT_NULL && TRANSLATE (*d) == '\000'))
4743 goto fail; 4743 goto fail;
4744 4744
4754 REGISTER unsigned char c; 4754 REGISTER unsigned char c;
4755 boolean not = (re_opcode_t) *(p - 1) == charset_not; 4755 boolean not = (re_opcode_t) *(p - 1) == charset_not;
4756 4756
4757 DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : ""); 4757 DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : "");
4758 4758
4759 PREFETCH (); 4759 REGEX_PREFETCH ();
4760 c = TRANSLATE (*d); /* The character to match. */ 4760 c = TRANSLATE (*d); /* The character to match. */
4761 4761
4762 /* Cast to `unsigned' instead of `unsigned char' in case the 4762 /* Cast to `unsigned' instead of `unsigned char' in case the
4763 bit list is a full 32 bytes long. */ 4763 bit list is a full 32 bytes long. */
4764 if (c < (unsigned) (*p * BYTEWIDTH) 4764 if (c < (unsigned) (*p * BYTEWIDTH)
4781 REGISTER Emchar c; 4781 REGISTER Emchar c;
4782 boolean not = (re_opcode_t) *(p - 1) == charset_mule_not; 4782 boolean not = (re_opcode_t) *(p - 1) == charset_mule_not;
4783 4783
4784 DEBUG_PRINT2 ("EXECUTING charset_mule%s.\n", not ? "_not" : ""); 4784 DEBUG_PRINT2 ("EXECUTING charset_mule%s.\n", not ? "_not" : "");
4785 4785
4786 PREFETCH (); 4786 REGEX_PREFETCH ();
4787 c = charptr_emchar ((const Bufbyte *) d); 4787 c = charptr_emchar ((const Bufbyte *) d);
4788 c = TRANSLATE_EXTENDED_UNSAFE (c); /* The character to match. */ 4788 c = TRANSLATE_EXTENDED_UNSAFE (c); /* The character to match. */
4789 4789
4790 if (EQ (Qt, unified_range_table_lookup (p, c, Qnil))) 4790 if (EQ (Qt, unified_range_table_lookup (p, c, Qnil)))
4791 not = !not; 4791 not = !not;
5033 } 5033 }
5034 /* At end of register contents => success */ 5034 /* At end of register contents => success */
5035 if (d2 == dend2) break; 5035 if (d2 == dend2) break;
5036 5036
5037 /* If necessary, advance to next segment in data. */ 5037 /* If necessary, advance to next segment in data. */
5038 PREFETCH (); 5038 REGEX_PREFETCH ();
5039 5039
5040 /* How many characters left in this segment to match. */ 5040 /* How many characters left in this segment to match. */
5041 mcnt = dend - d; 5041 mcnt = dend - d;
5042 5042
5043 /* Want how many consecutive characters we can match in 5043 /* Want how many consecutive characters we can match in
5592 matchornotsyntax: 5592 matchornotsyntax:
5593 { 5593 {
5594 int matches; 5594 int matches;
5595 Emchar emch; 5595 Emchar emch;
5596 5596
5597 PREFETCH (); 5597 REGEX_PREFETCH ();
5598 emch = charptr_emchar ((const Bufbyte *) d); 5598 emch = charptr_emchar ((const Bufbyte *) d);
5599 matches = (SYNTAX_UNSAFE 5599 matches = (SYNTAX_UNSAFE
5600 (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table), 5600 (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table),
5601 emch) == (enum syntaxcode) mcnt); 5601 emch) == (enum syntaxcode) mcnt);
5602 INC_CHARPTR (d); 5602 INC_CHARPTR (d);
5625 matchornotcategory: 5625 matchornotcategory:
5626 { 5626 {
5627 Emchar emch; 5627 Emchar emch;
5628 5628
5629 mcnt = *p++; 5629 mcnt = *p++;
5630 PREFETCH (); 5630 REGEX_PREFETCH ();
5631 emch = charptr_emchar ((const Bufbyte *) d); 5631 emch = charptr_emchar ((const Bufbyte *) d);
5632 INC_CHARPTR (d); 5632 INC_CHARPTR (d);
5633 if (check_category_char(emch, regex_emacs_buffer->category_table, 5633 if (check_category_char(emch, regex_emacs_buffer->category_table,
5634 mcnt, should_succeed)) 5634 mcnt, should_succeed))
5635 goto fail; 5635 goto fail;
5643 /* end of category patch */ 5643 /* end of category patch */
5644 #endif /* MULE */ 5644 #endif /* MULE */
5645 #else /* not emacs */ 5645 #else /* not emacs */
5646 case wordchar: 5646 case wordchar:
5647 DEBUG_PRINT1 ("EXECUTING non-Emacs wordchar.\n"); 5647 DEBUG_PRINT1 ("EXECUTING non-Emacs wordchar.\n");
5648 PREFETCH (); 5648 REGEX_PREFETCH ();
5649 if (!WORDCHAR_P_UNSAFE ((int) (*d))) 5649 if (!WORDCHAR_P_UNSAFE ((int) (*d)))
5650 goto fail; 5650 goto fail;
5651 SET_REGS_MATCHED (); 5651 SET_REGS_MATCHED ();
5652 d++; 5652 d++;
5653 break; 5653 break;
5654 5654
5655 case notwordchar: 5655 case notwordchar:
5656 DEBUG_PRINT1 ("EXECUTING non-Emacs notwordchar.\n"); 5656 DEBUG_PRINT1 ("EXECUTING non-Emacs notwordchar.\n");
5657 PREFETCH (); 5657 REGEX_PREFETCH ();
5658 if (!WORDCHAR_P_UNSAFE ((int) (*d))) 5658 if (!WORDCHAR_P_UNSAFE ((int) (*d)))
5659 goto fail; 5659 goto fail;
5660 SET_REGS_MATCHED (); 5660 SET_REGS_MATCHED ();
5661 d++; 5661 d++;
5662 break; 5662 break;