Mercurial > hg > xemacs-beta
comparison src/regex.c @ 272:c5d627a313b1 r21-0b34
Import from CVS: tag r21-0b34
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:28:48 +0200 |
parents | 084402c475ba |
children | ca9a9ec9c1c1 |
comparison
equal
deleted
inserted
replaced
271:c7b7086b0a39 | 272:c5d627a313b1 |
---|---|
184 static char re_syntax_table[CHAR_SET_SIZE]; | 184 static char re_syntax_table[CHAR_SET_SIZE]; |
185 | 185 |
186 static void | 186 static void |
187 init_syntax_once (void) | 187 init_syntax_once (void) |
188 { | 188 { |
189 REGISTER int c; | 189 static int done = 0; |
190 static int done = 0; | 190 |
191 | 191 if (!done) |
192 if (done) | 192 { |
193 return; | 193 CONST char *word_syntax_chars = |
194 | 194 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"; |
195 memset (re_syntax_table, 0, sizeof (re_syntax_table)); | 195 |
196 | 196 memset (re_syntax_table, 0, sizeof (re_syntax_table)); |
197 for (c = 'a'; c <= 'z'; c++) | 197 |
198 re_syntax_table[c] = Sword; | 198 while (*word_syntax_chars) |
199 | 199 re_syntax_table[(unsigned int)(*word_syntax_chars++)] = Sword; |
200 for (c = 'A'; c <= 'Z'; c++) | 200 |
201 re_syntax_table[c] = Sword; | 201 done = 1; |
202 | 202 } |
203 for (c = '0'; c <= '9'; c++) | |
204 re_syntax_table[c] = Sword; | |
205 | |
206 re_syntax_table['_'] = Sword; | |
207 | |
208 done = 1; | |
209 } | 203 } |
210 | 204 |
211 #endif /* not SYNTAX_TABLE */ | 205 #endif /* not SYNTAX_TABLE */ |
212 | 206 |
213 #define SYNTAX_UNSAFE(ignored, c) re_syntax_table[c] | 207 #define SYNTAX_UNSAFE(ignored, c) re_syntax_table[c] |
247 | 241 |
248 #ifdef MULE | 242 #ifdef MULE |
249 /* The IS*() macros can be passed any character, including an extended | 243 /* The IS*() macros can be passed any character, including an extended |
250 one. We need to make sure there are no crashes, which would occur | 244 one. We need to make sure there are no crashes, which would occur |
251 otherwise due to out-of-bounds array references. */ | 245 otherwise due to out-of-bounds array references. */ |
252 #define ISASCII(c) (((unsigned EMACS_INT) (c)) < 0x100 && ISASCII_1 (c)) | 246 #define ISASCII(c) (((EMACS_UINT) (c)) < 0x100 && ISASCII_1 (c)) |
253 #else | 247 #else |
254 #define ISASCII(c) ISASCII_1 (c) | 248 #define ISASCII(c) ISASCII_1 (c) |
255 #endif /* MULE */ | 249 #endif /* MULE */ |
256 | 250 |
257 #ifdef isblank | 251 #ifdef isblank |
677 was_a_range = 1; | 671 was_a_range = 1; |
678 i++; | 672 i++; |
679 } | 673 } |
680 if (was_a_range) | 674 if (was_a_range) |
681 { | 675 { |
682 printf ("-"); | 676 putchar ('-'); |
683 putchar (i - 1); | 677 putchar (i - 1); |
684 } | 678 } |
685 } | 679 } |
686 } | 680 } |
687 putchar ('\n'); | 681 putchar ('\n'); |
698 unsigned char *p = start; | 692 unsigned char *p = start; |
699 unsigned char *pend = end; | 693 unsigned char *pend = end; |
700 | 694 |
701 if (start == NULL) | 695 if (start == NULL) |
702 { | 696 { |
703 printf ("(null)\n"); | 697 puts ("(null)"); |
704 return; | 698 return; |
705 } | 699 } |
706 | 700 |
707 /* Loop over pattern commands. */ | 701 /* Loop over pattern commands. */ |
708 while (p < pend) | 702 while (p < pend) |
1001 | 995 |
1002 static void | 996 static void |
1003 print_double_string (CONST char *where, CONST char *string1, int size1, | 997 print_double_string (CONST char *where, CONST char *string1, int size1, |
1004 CONST char *string2, int size2) | 998 CONST char *string2, int size2) |
1005 { | 999 { |
1006 unsigned this_char; | |
1007 | |
1008 if (where == NULL) | 1000 if (where == NULL) |
1009 printf ("(null)"); | 1001 printf ("(null)"); |
1010 else | 1002 else |
1011 { | 1003 { |
1004 unsigned int this_char; | |
1005 | |
1012 if (FIRST_STRING_P (where)) | 1006 if (FIRST_STRING_P (where)) |
1013 { | 1007 { |
1014 for (this_char = where - string1; this_char < size1; this_char++) | 1008 for (this_char = where - string1; this_char < size1; this_char++) |
1015 putchar (string1[this_char]); | 1009 putchar (string1[this_char]); |
1016 | 1010 |
1065 in regex.h. Obviously the order here has to be same as there. | 1059 in regex.h. Obviously the order here has to be same as there. |
1066 POSIX doesn't require that we do anything for REG_NOERROR, | 1060 POSIX doesn't require that we do anything for REG_NOERROR, |
1067 but why not be nice? */ | 1061 but why not be nice? */ |
1068 | 1062 |
1069 static CONST char *re_error_msgid[] = | 1063 static CONST char *re_error_msgid[] = |
1070 { "Success", /* REG_NOERROR */ | 1064 { |
1071 "No match", /* REG_NOMATCH */ | 1065 "Success", /* REG_NOERROR */ |
1072 "Invalid regular expression", /* REG_BADPAT */ | 1066 "No match", /* REG_NOMATCH */ |
1073 "Invalid collation character", /* REG_ECOLLATE */ | 1067 "Invalid regular expression", /* REG_BADPAT */ |
1074 "Invalid character class name", /* REG_ECTYPE */ | 1068 "Invalid collation character", /* REG_ECOLLATE */ |
1075 "Trailing backslash", /* REG_EESCAPE */ | 1069 "Invalid character class name", /* REG_ECTYPE */ |
1076 "Invalid back reference", /* REG_ESUBREG */ | 1070 "Trailing backslash", /* REG_EESCAPE */ |
1077 "Unmatched [ or [^", /* REG_EBRACK */ | 1071 "Invalid back reference", /* REG_ESUBREG */ |
1078 "Unmatched ( or \\(", /* REG_EPAREN */ | 1072 "Unmatched [ or [^", /* REG_EBRACK */ |
1079 "Unmatched \\{", /* REG_EBRACE */ | 1073 "Unmatched ( or \\(", /* REG_EPAREN */ |
1080 "Invalid content of \\{\\}", /* REG_BADBR */ | 1074 "Unmatched \\{", /* REG_EBRACE */ |
1081 "Invalid range end", /* REG_ERANGE */ | 1075 "Invalid content of \\{\\}", /* REG_BADBR */ |
1082 "Memory exhausted", /* REG_ESPACE */ | 1076 "Invalid range end", /* REG_ERANGE */ |
1083 "Invalid preceding regular expression", /* REG_BADRPT */ | 1077 "Memory exhausted", /* REG_ESPACE */ |
1084 "Premature end of regular expression", /* REG_EEND */ | 1078 "Invalid preceding regular expression", /* REG_BADRPT */ |
1085 "Regular expression too big", /* REG_ESIZE */ | 1079 "Premature end of regular expression", /* REG_EEND */ |
1086 "Unmatched ) or \\)", /* REG_ERPAREN */ | 1080 "Regular expression too big", /* REG_ESIZE */ |
1081 "Unmatched ) or \\)", /* REG_ERPAREN */ | |
1087 #ifdef emacs | 1082 #ifdef emacs |
1088 "Invalid syntax designator", /* REG_ESYNTAX */ | 1083 "Invalid syntax designator", /* REG_ESYNTAX */ |
1089 #endif | 1084 #endif |
1090 #ifdef MULE | 1085 #ifdef MULE |
1091 "Ranges may not span charsets", /* REG_ERANGESPAN */ | 1086 "Ranges may not span charsets", /* REG_ERANGESPAN */ |
1092 "Invalid category designator", /* REG_ECATEGORY */ | 1087 "Invalid category designator", /* REG_ECATEGORY */ |
1093 #endif | 1088 #endif |
1094 }; | 1089 }; |
1095 | 1090 |
1096 /* Avoiding alloca during matching, to placate r_alloc. */ | 1091 /* Avoiding alloca during matching, to placate r_alloc. */ |
1097 | 1092 |
1098 /* Define MATCH_MAY_ALLOCATE unless we need to make sure that the | 1093 /* Define MATCH_MAY_ALLOCATE unless we need to make sure that the |
1099 searching and matching functions should not call alloca. On some | 1094 searching and matching functions should not call alloca. On some |
4060 (startpos >= size1 ? string2 - size1 : string1) + startpos); | 4055 (startpos >= size1 ? string2 - size1 : string1) + startpos); |
4061 | 4056 |
4062 /* Written out as an if-else to avoid testing `translate' | 4057 /* Written out as an if-else to avoid testing `translate' |
4063 inside the loop. */ | 4058 inside the loop. */ |
4064 if (translate) | 4059 if (translate) |
4060 while (range > lim && | |
4065 #ifdef MULE | 4061 #ifdef MULE |
4066 while (range > lim && *d < 0x80 && !fastmap[translate[*d]]) | 4062 *d < 0x80 && |
4067 #else | 4063 #endif |
4068 while (range > lim && !fastmap[(unsigned char)translate[*d]]) | 4064 !fastmap[(unsigned char)translate[*d]]) |
4069 #endif | |
4070 { | 4065 { |
4071 d_size = charcount_to_bytecount (d, 1); | 4066 d_size = charcount_to_bytecount (d, 1); |
4072 range -= d_size; | 4067 range -= d_size; |
4073 d += d_size; /* Speedier INC_CHARPTR(d) */ | 4068 d += d_size; /* Speedier INC_CHARPTR(d) */ |
4074 } | 4069 } |
5326 actual values. Otherwise, we will restore only one | 5321 actual values. Otherwise, we will restore only one |
5327 register from the stack, since lowest will == highest in | 5322 register from the stack, since lowest will == highest in |
5328 `pop_failure_point'. */ | 5323 `pop_failure_point'. */ |
5329 unsigned dummy_low_reg, dummy_high_reg; | 5324 unsigned dummy_low_reg, dummy_high_reg; |
5330 unsigned char *pdummy; | 5325 unsigned char *pdummy; |
5331 CONST char *sdummy; | 5326 CONST char *sdummy = NULL; |
5332 | 5327 |
5333 DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n"); | 5328 DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n"); |
5334 POP_FAILURE_POINT (sdummy, pdummy, | 5329 POP_FAILURE_POINT (sdummy, pdummy, |
5335 dummy_low_reg, dummy_high_reg, | 5330 dummy_low_reg, dummy_high_reg, |
5336 reg_dummy, reg_dummy, reg_info_dummy); | 5331 reg_dummy, reg_dummy, reg_info_dummy); |