Mercurial > hg > xemacs-beta
comparison src/regex.c @ 1346:01c57eb70ae9
[xemacs-hg @ 2003-03-09 02:27:27 by ben]
To: xemacs-patches@xemacs.org
i.c: Sleep between calls to check for I/O, since these calls are non-blocking.
behavior.el: Allow other keywords for forward compatibility.
cl-macs.el: Rewrite to eliminate byte-compiler warning when `return' is used
without `finally'.
cmdloop.el: Avoid truncated error messages for `end-of-file' and the like.
cmdloop.el: Avoid char-int error after syncing.
files.el: Eliminate byte-compile warnings.
printer.el: Fix line-width calculations.
#### This used to work. Someone's changes (perhaps by
Michael Sperber?) seem to have messed something up.
simple.el: Use new clear-left-side functions to avoid messages ending up on
the same line as other output.
xemacs.mak: Add override for info/ as well when separate source/build dirs.
xemacs.mak: Order sections in main build process and add comments. Add
additional dependencies to try and prevent later steps from
happening when failures in earlier steps have occurred.
Makefile.in.in: Order sections in main build process and add comments. Add
additional dependencies to try and prevent later steps from
happening when failures in earlier steps have occurred.
alloc.c: Don't arbitrarily clear Vconfigure_info_directory since it
messes up separate build/source dirs.
console.c, console.h, device-msw.c, device.c: Add accidentally omitted msprinter console and data descriptions.
print.c, console-msw.c: Add clear-left-side functionality to help keep stdio/stderr
output from separate sources on separate lines. Generalize
the different kinds of debugging output. Add dpa().
profile.c: Add better docs on Unix/Windows differences.
regex.c: Fix problems with rel-alloc compilation caused by previous patch.
emacs.c: Seg fault rather than abort on Cygwin, since gdb doesn't trap
aborts properly.
console-gtk-impl.h, console-gtk.h, console-msw.h, console-x-impl.h, console-x.h, dialog-gtk.c, dialog-x.c, event-msw.c, frame-gtk.c, frame-x.c, frameslots.h, glyphs-gtk.c, glyphs-x.c, gui-gtk.c, gui-x.c, inline.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, scrollbar-gtk.c, scrollbar-x.c, ui-gtk.c: Delete popup-data object. Delete menubar_data field from frames,
since its usage is frame-specific. Delete menubar-msw.h,
gui-x.h, gui-gtk.h. Clean up handling of lwlib callback data
GCPRO'ing and add missing GCPRO recomputation in widget code.
author | ben |
---|---|
date | Sun, 09 Mar 2003 02:27:46 +0000 |
parents | 1b0339b048ce |
children | 8d350b095c21 |
comparison
equal
deleted
inserted
replaced
1345:3b27da507d56 | 1346:01c57eb70ae9 |
---|---|
79 | 79 |
80 #if (defined (DEBUG_XEMACS) && !defined (DEBUG)) | 80 #if (defined (DEBUG_XEMACS) && !defined (DEBUG)) |
81 #define DEBUG | 81 #define DEBUG |
82 #endif | 82 #endif |
83 | 83 |
84 #ifdef MULE | |
85 | |
86 Lisp_Object Vthe_lisp_rangetab; | |
87 | |
88 void | |
89 vars_of_regex (void) | |
90 { | |
91 Vthe_lisp_rangetab = Fmake_range_table (); | |
92 staticpro (&Vthe_lisp_rangetab); | |
93 } | |
94 | |
95 #else /* not MULE */ | |
96 | |
97 void | |
98 vars_of_regex (void) | |
99 { | |
100 } | |
101 | |
102 #endif /* MULE */ | |
103 | |
104 #define RE_TRANSLATE_1(ch) TRT_TABLE_OF (translate, (Ichar) ch) | 84 #define RE_TRANSLATE_1(ch) TRT_TABLE_OF (translate, (Ichar) ch) |
105 #define TRANSLATE_P(tr) (!NILP (tr)) | 85 #define TRANSLATE_P(tr) (!NILP (tr)) |
106 | 86 |
107 /* Converts the pointer to the char to BEG-based offset from the start. */ | 87 /* Converts the pointer to the char to BEG-based offset from the start. */ |
108 #define PTR_TO_OFFSET(d) (MATCHING_IN_FIRST_STRING \ | 88 #define PTR_TO_OFFSET(d) (MATCHING_IN_FIRST_STRING \ |
109 ? (d) - string1 : (d) - (string2 - size1)) | 89 ? (d) - string1 : (d) - (string2 - size1)) |
110 | |
111 /* Convert an offset from the start of the logical text string formed by | |
112 concatenating the two strings together into a character position in the | |
113 Lisp buffer or string that the text represents. Knows that | |
114 when handling buffer text, the "string" we're passed in is always | |
115 BEGV - ZV. */ | |
116 | |
117 static Charxpos | |
118 offset_to_charxpos (Lisp_Object lispobj, int off) | |
119 { | |
120 if (STRINGP (lispobj)) | |
121 return string_index_byte_to_char (lispobj, off); | |
122 else if (BUFFERP (lispobj)) | |
123 return bytebpos_to_charbpos (XBUFFER (lispobj), | |
124 off + BYTE_BUF_BEGV (XBUFFER (lispobj))); | |
125 else | |
126 return 0; | |
127 } | |
128 | |
129 #ifdef REL_ALLOC | |
130 | |
131 /* STRING1 is the value of STRING1 given to re_match_2(). LISPOBJ is | |
132 the Lisp object (if any) from which the string is taken. If LISPOBJ | |
133 is a buffer, return a relocation offset to be added to all pointers to | |
134 string data so that they will be accurate again, after an allocation or | |
135 reallocation that potentially relocated the buffer data. | |
136 */ | |
137 static Bytecount | |
138 offset_post_relocation (Lisp_Object lispobj, char *string1) | |
139 { | |
140 struct buffer *buf; | |
141 | |
142 if (!BUFFERP (lispobj)) | |
143 return 0; | |
144 return (BYTE_BUF_BYTE_ADDRESS (XBUFFER (lispobj), | |
145 BYTE_BUF_BEGV (XBUFFER (lispobj))) - | |
146 string1); | |
147 } | |
148 | |
149 #endif /* REL_ALLOC */ | |
150 | |
151 #ifdef ERROR_CHECK_MALLOC | |
152 | |
153 /* NOTE that this can run malloc() so you need to adjust afterwards. */ | |
154 | |
155 static int | |
156 bind_regex_malloc_disallowed (int value) | |
157 { | |
158 /* Tricky, because the act of binding can run malloc(). */ | |
159 int old_regex_malloc_disallowed = regex_malloc_disallowed; | |
160 int depth; | |
161 regex_malloc_disallowed = 0; | |
162 depth = record_unwind_protect_restoring_int (®ex_malloc_disallowed, | |
163 old_regex_malloc_disallowed); | |
164 regex_malloc_disallowed = value; | |
165 return depth; | |
166 } | |
167 | |
168 #endif /* ERROR_CHECK_MALLOC */ | |
169 | 90 |
170 #else /* not emacs */ | 91 #else /* not emacs */ |
171 | 92 |
172 /* If we are not linking with Emacs proper, | 93 /* If we are not linking with Emacs proper, |
173 we can't use the relocating allocator | 94 we can't use the relocating allocator |
435 | 356 |
436 /* Define how to allocate the failure stack. */ | 357 /* Define how to allocate the failure stack. */ |
437 | 358 |
438 #ifdef REGEX_REL_ALLOC | 359 #ifdef REGEX_REL_ALLOC |
439 #define REGEX_ALLOCATE_STACK(size) \ | 360 #define REGEX_ALLOCATE_STACK(size) \ |
440 r_alloc ((char **) &failure_stack_ptr, (size)) | 361 r_alloc ((unsigned char **) &failure_stack_ptr, (size)) |
441 #define REGEX_REALLOCATE_STACK(source, osize, nsize) \ | 362 #define REGEX_REALLOCATE_STACK(source, osize, nsize) \ |
442 r_re_alloc ((char **) &failure_stack_ptr, (nsize)) | 363 r_re_alloc ((unsigned char **) &failure_stack_ptr, (nsize)) |
443 #define REGEX_FREE_STACK(ptr) \ | 364 #define REGEX_FREE_STACK(ptr) \ |
444 r_alloc_free ((void **) &failure_stack_ptr) | 365 r_alloc_free ((unsigned char **) &failure_stack_ptr) |
445 | 366 |
446 #else /* not REGEX_REL_ALLOC */ | 367 #else /* not REGEX_REL_ALLOC */ |
447 | 368 |
448 #ifdef REGEX_MALLOC | 369 #ifdef REGEX_MALLOC |
449 | 370 |
488 typedef const unsigned char re_char; | 409 typedef const unsigned char re_char; |
489 | 410 |
490 typedef char re_bool; | 411 typedef char re_bool; |
491 #define false 0 | 412 #define false 0 |
492 #define true 1 | 413 #define true 1 |
414 | |
415 | |
416 #ifdef emacs | |
417 | |
418 #ifdef MULE | |
419 | |
420 Lisp_Object Vthe_lisp_rangetab; | |
421 | |
422 void | |
423 vars_of_regex (void) | |
424 { | |
425 Vthe_lisp_rangetab = Fmake_range_table (); | |
426 staticpro (&Vthe_lisp_rangetab); | |
427 } | |
428 | |
429 #else /* not MULE */ | |
430 | |
431 void | |
432 vars_of_regex (void) | |
433 { | |
434 } | |
435 | |
436 #endif /* MULE */ | |
437 | |
438 /* Convert an offset from the start of the logical text string formed by | |
439 concatenating the two strings together into a character position in the | |
440 Lisp buffer or string that the text represents. Knows that | |
441 when handling buffer text, the "string" we're passed in is always | |
442 BEGV - ZV. */ | |
443 | |
444 static Charxpos | |
445 offset_to_charxpos (Lisp_Object lispobj, int off) | |
446 { | |
447 if (STRINGP (lispobj)) | |
448 return string_index_byte_to_char (lispobj, off); | |
449 else if (BUFFERP (lispobj)) | |
450 return bytebpos_to_charbpos (XBUFFER (lispobj), | |
451 off + BYTE_BUF_BEGV (XBUFFER (lispobj))); | |
452 else | |
453 return 0; | |
454 } | |
455 | |
456 #ifdef REL_ALLOC | |
457 | |
458 /* STRING1 is the value of STRING1 given to re_match_2(). LISPOBJ is | |
459 the Lisp object (if any) from which the string is taken. If LISPOBJ | |
460 is a buffer, return a relocation offset to be added to all pointers to | |
461 string data so that they will be accurate again, after an allocation or | |
462 reallocation that potentially relocated the buffer data. | |
463 */ | |
464 static Bytecount | |
465 offset_post_relocation (Lisp_Object lispobj, Ibyte *orig_buftext) | |
466 { | |
467 if (!BUFFERP (lispobj)) | |
468 return 0; | |
469 return (BYTE_BUF_BYTE_ADDRESS (XBUFFER (lispobj), | |
470 BYTE_BUF_BEGV (XBUFFER (lispobj))) - | |
471 orig_buftext); | |
472 } | |
473 | |
474 #endif /* REL_ALLOC */ | |
475 | |
476 #ifdef ERROR_CHECK_MALLOC | |
477 | |
478 /* NOTE that this can run malloc() so you need to adjust afterwards. */ | |
479 | |
480 static int | |
481 bind_regex_malloc_disallowed (int value) | |
482 { | |
483 /* Tricky, because the act of binding can run malloc(). */ | |
484 int old_regex_malloc_disallowed = regex_malloc_disallowed; | |
485 int depth; | |
486 regex_malloc_disallowed = 0; | |
487 depth = record_unwind_protect_restoring_int (®ex_malloc_disallowed, | |
488 old_regex_malloc_disallowed); | |
489 regex_malloc_disallowed = value; | |
490 return depth; | |
491 } | |
492 | |
493 #endif /* ERROR_CHECK_MALLOC */ | |
494 | |
495 #endif /* emacs */ | |
493 | 496 |
494 | 497 |
495 /* These are the command codes that appear in compiled regular | 498 /* These are the command codes that appear in compiled regular |
496 expressions. Some opcodes are followed by argument bytes. A | 499 expressions. Some opcodes are followed by argument bytes. A |
497 command code can specify any interpretation whatsoever for its | 500 command code can specify any interpretation whatsoever for its |
1401 #if !defined (emacs) || !defined (REL_ALLOC) | 1404 #if !defined (emacs) || !defined (REL_ALLOC) |
1402 #define RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS() | 1405 #define RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS() |
1403 #else | 1406 #else |
1404 /* Don't change NULL pointers */ | 1407 /* Don't change NULL pointers */ |
1405 #define ADD_IF_NZ(val) if (val) val += rmdp_offset | 1408 #define ADD_IF_NZ(val) if (val) val += rmdp_offset |
1406 #define RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS() \ | 1409 #define RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS() \ |
1407 do \ | 1410 do \ |
1408 { \ | 1411 { \ |
1409 Bytecount rmdp_offset = offset_post_relocation (lispobj, string1); \ | 1412 Bytecount rmdp_offset = offset_post_relocation (lispobj, orig_buftext); \ |
1410 \ | 1413 \ |
1411 if (rmdp_offset) \ | 1414 if (rmdp_offset) \ |
1412 { \ | 1415 { \ |
1413 int i; \ | 1416 int i; \ |
1414 \ | 1417 \ |
1415 ADD_IF_NZ (string1); \ | 1418 ADD_IF_NZ (string1); \ |
1416 ADD_IF_NZ (string2); \ | 1419 ADD_IF_NZ (string2); \ |
1417 ADD_IF_NZ (d); \ | 1420 ADD_IF_NZ (d); \ |
1418 ADD_IF_NZ (dend); \ | 1421 ADD_IF_NZ (dend); \ |
1419 ADD_IF_NZ (end1); \ | 1422 ADD_IF_NZ (end1); \ |
1420 ADD_IF_NZ (end2); \ | 1423 ADD_IF_NZ (end2); \ |
1421 ADD_IF_NZ (end_match_1); \ | 1424 ADD_IF_NZ (end_match_1); \ |
1422 ADD_IF_NZ (end_match_2); \ | 1425 ADD_IF_NZ (end_match_2); \ |
1423 \ | 1426 \ |
1424 if (bufp->re_ngroups) \ | 1427 if (bufp->re_ngroups) \ |
1425 { \ | 1428 { \ |
1426 for (i = 0; i < numregs; i++) \ | 1429 for (i = 0; i < num_regs; i++) \ |
1427 { \ | 1430 { \ |
1428 ADD_IF_NZ (regstart[i]); \ | 1431 ADD_IF_NZ (regstart[i]); \ |
1429 ADD_IF_NZ (regend[i]); \ | 1432 ADD_IF_NZ (regend[i]); \ |
1430 ADD_IF_NZ (old_regstart[i]); \ | 1433 ADD_IF_NZ (old_regstart[i]); \ |
1431 ADD_IF_NZ (old_regend[i]); \ | 1434 ADD_IF_NZ (old_regend[i]); \ |
1432 ADD_IF_NZ (best_regstart[i]); \ | 1435 ADD_IF_NZ (best_regstart[i]); \ |
1433 ADD_IF_NZ (best_regend[i]); \ | 1436 ADD_IF_NZ (best_regend[i]); \ |
1434 ADD_IF_NZ (reg_dummy[i]); \ | 1437 ADD_IF_NZ (reg_dummy[i]); \ |
1435 } \ | 1438 } \ |
1436 } \ | 1439 } \ |
1437 \ | 1440 \ |
1438 ADD_IF_NZ (match_end); \ | 1441 ADD_IF_NZ (match_end); \ |
1439 } \ | 1442 } \ |
1440 } while (0) | 1443 } while (0) |
1441 #endif /* !defined (emacs) || !defined (REL_ALLOC) */ | 1444 #endif /* !defined (emacs) || !defined (REL_ALLOC) */ |
1442 | 1445 |
1443 #if !defined (emacs) || !defined (REL_ALLOC) | 1446 #if !defined (emacs) || !defined (REL_ALLOC) |
1444 #define RE_SEARCH_RELOCATE_MOVEABLE_DATA_POINTERS() | 1447 #define RE_SEARCH_RELOCATE_MOVEABLE_DATA_POINTERS() |
1445 #else | 1448 #else |
1446 #define RE_SEARCH_RELOCATE_MOVEABLE_DATA_POINTERS() \ | 1449 #define RE_SEARCH_RELOCATE_MOVEABLE_DATA_POINTERS() \ |
1447 do \ | 1450 do \ |
1448 { \ | 1451 { \ |
1449 Bytecount rmdp_offset = offset_post_relocation (lispobj, str1); \ | 1452 Bytecount rmdp_offset = offset_post_relocation (lispobj, orig_buftext); \ |
1450 \ | 1453 \ |
1451 if (rmdp_offset) \ | 1454 if (rmdp_offset) \ |
1452 { \ | 1455 { \ |
1453 int i; \ | 1456 ADD_IF_NZ (str1); \ |
1454 \ | 1457 ADD_IF_NZ (str2); \ |
1455 ADD_IF_NZ (str1); \ | 1458 ADD_IF_NZ (string1); \ |
1456 ADD_IF_NZ (str2); \ | 1459 ADD_IF_NZ (string2); \ |
1457 ADD_IF_NZ (string1); \ | 1460 ADD_IF_NZ (d); \ |
1458 ADD_IF_NZ (string2); \ | 1461 } \ |
1459 ADD_IF_NZ (d); \ | |
1460 \ | |
1461 \ | |
1462 \ | |
1463 ADD_IF_NZ (dend); \ | |
1464 ADD_IF_NZ (end1); \ | |
1465 ADD_IF_NZ (end2); \ | |
1466 ADD_IF_NZ (end_match_1); \ | |
1467 ADD_IF_NZ (end_match_2); \ | |
1468 \ | |
1469 if (bufp->re_ngroups) \ | |
1470 { \ | |
1471 for (i = 0; i < numregs; i++) \ | |
1472 { \ | |
1473 ADD_IF_NZ (regstart[i]); \ | |
1474 ADD_IF_NZ (regend[i]); \ | |
1475 ADD_IF_NZ (old_regstart[i]); \ | |
1476 ADD_IF_NZ (old_regend[i]); \ | |
1477 ADD_IF_NZ (best_regstart[i]); \ | |
1478 ADD_IF_NZ (best_regend[i]); \ | |
1479 ADD_IF_NZ (reg_dummy[i]); \ | |
1480 } \ | |
1481 } \ | |
1482 \ | |
1483 ADD_IF_NZ (match_end); \ | |
1484 } \ | |
1485 } while (0) | 1462 } while (0) |
1486 | 1463 |
1487 #endif /* emacs */ | 1464 #endif /* emacs */ |
1488 | 1465 |
1489 /* Push pointer POINTER on FAIL_STACK. | 1466 /* Push pointer POINTER on FAIL_STACK. |
4284 int anchored_at_begline = 0; | 4261 int anchored_at_begline = 0; |
4285 #endif | 4262 #endif |
4286 re_char *d; | 4263 re_char *d; |
4287 #ifdef emacs | 4264 #ifdef emacs |
4288 Internal_Format fmt = buffer_or_other_internal_format (lispobj); | 4265 Internal_Format fmt = buffer_or_other_internal_format (lispobj); |
4266 #ifdef REL_ALLOC | |
4267 Ibyte *orig_buftext = | |
4268 BUFFERP (lispobj) ? | |
4269 BYTE_BUF_BYTE_ADDRESS (XBUFFER (lispobj), | |
4270 BYTE_BUF_BEGV (XBUFFER (lispobj))) : | |
4271 0; | |
4272 #endif | |
4289 #ifdef ERROR_CHECK_MALLOC | 4273 #ifdef ERROR_CHECK_MALLOC |
4290 int depth; | 4274 int depth; |
4291 #endif | 4275 #endif |
4292 #endif /* emacs */ | 4276 #endif /* emacs */ |
4293 #if 1 | 4277 #if 1 |
4912 /* 1 if this match is the best seen so far. */ | 4896 /* 1 if this match is the best seen so far. */ |
4913 re_bool best_match_p; | 4897 re_bool best_match_p; |
4914 | 4898 |
4915 #ifdef emacs | 4899 #ifdef emacs |
4916 Internal_Format fmt = buffer_or_other_internal_format (lispobj); | 4900 Internal_Format fmt = buffer_or_other_internal_format (lispobj); |
4901 #ifdef REL_ALLOC | |
4902 Ibyte *orig_buftext = | |
4903 BUFFERP (lispobj) ? | |
4904 BYTE_BUF_BYTE_ADDRESS (XBUFFER (lispobj), | |
4905 BYTE_BUF_BEGV (XBUFFER (lispobj))) : | |
4906 0; | |
4907 #endif | |
4908 | |
4917 #ifdef ERROR_CHECK_MALLOC | 4909 #ifdef ERROR_CHECK_MALLOC |
4918 int depth = bind_regex_malloc_disallowed (1); | 4910 int depth = bind_regex_malloc_disallowed (1); |
4919 #endif | 4911 #endif |
4920 #endif /* emacs */ | 4912 #endif /* emacs */ |
4921 | 4913 |
4965 #if defined (emacs) && defined (REL_ALLOC) | 4957 #if defined (emacs) && defined (REL_ALLOC) |
4966 { | 4958 { |
4967 /* If the allocations above (or the call to setup_syntax_cache() in | 4959 /* If the allocations above (or the call to setup_syntax_cache() in |
4968 re_match_2) caused a rel-alloc relocation, then fix up the data | 4960 re_match_2) caused a rel-alloc relocation, then fix up the data |
4969 pointers */ | 4961 pointers */ |
4970 Bytecount offset = offset_post_relocation (lispobj, string1); | 4962 Bytecount offset = offset_post_relocation (lispobj, orig_buftext); |
4971 if (offset) | 4963 if (offset) |
4972 { | 4964 { |
4973 string1 += offset; | 4965 string1 += offset; |
4974 string2 += offset; | 4966 string2 += offset; |
4975 } | 4967 } |
5053 if (!no_quit_in_re_search) | 5045 if (!no_quit_in_re_search) |
5054 { | 5046 { |
5055 BEGIN_REGEX_MALLOC_OK (); | 5047 BEGIN_REGEX_MALLOC_OK (); |
5056 QUIT; | 5048 QUIT; |
5057 END_REGEX_MALLOC_OK (); | 5049 END_REGEX_MALLOC_OK (); |
5058 RE_SEARCH_RELOCATE_MOVEABLE_DATA_POINTERS (); | 5050 RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS (); |
5059 } | 5051 } |
5060 #endif | 5052 #endif |
5061 | 5053 |
5062 if (p == pend) | 5054 if (p == pend) |
5063 { /* End of pattern means we might have succeeded. */ | 5055 { /* End of pattern means we might have succeeded. */ |