Mercurial > hg > xemacs-beta
comparison src/regex.c @ 502:7039e6323819
[xemacs-hg @ 2001-05-04 22:41:46 by ben]
----------------------- byte-comp warning fixes -----------------
New functions for cleanly eliminating byte-compiler warnings.
Their definitions require no changes at all in bytecomp.el,
meaning that any package that wants to use them and be compatible
with older versions of XEmacs need only copy the code and rename
the functions (i.e. prefix them with the package name).
Eliminate byte-compiler warnings using the new functions in
bytecomp-runtime.el.
Move coding-system-put,get,category, since they're not
Mule-specific and are used in prefer-coding-system.
font.el was incredibly ugly. Clean it up. Avoid using defsubst
for any exported functions, to avoid possible compatibility
problems if we later change the internal interface. (It happened
before, with face accessors, between 19.8 and 19.9). Fix tons
of warnings.
Clean up (new function gpm-is-supported-p eliminates duplicate
code in gpm-create/delete-device-hook) and eliminate warnings.
---------- make byte-recompile-directory work in the ---------
core `lisp' dir, even in the absence of
a Mule XEmacs (i.e. make it skip the Mule
files rather than trying to compile them).
now you should be able to do `touch *.el'
in the `lisp' dir, then
M-x byte-recompile-directory, and get no
warnings.
Avoid trying to compile Mule files in byte-recompile-directory
when we're not in a Mule XEmacs, since we're highly likely to get
syntax errors.
Add a coding-system cookie to all Mule files so that
byte-recompile-directory ignores them.
Magic cookie function moved to files.el from code-files.el (for
use by bytecomp even in a non-coding-system XEmacs), and changed
names and semantics for use by bytecomp. NOTE: IMO this is an
internal function that we can change as we like (and there is
absolutely no code anywhere else using the function).
---------------- GUI improvements: menus, help -------------------
Rearrange order of keymap declarations to be alphabetical.
Improve help on help to include all bindings, and group by
category. Add bindings for new Info commands. Remove
warnings. Use command-hyper-apropos in place of command-apropos.
Add a function to do the equivalent of command-apropos.
Evals its help-text argument so you can put expressions there.
Used now by help-for-help.
Add binding to continue text searches. Expand index searches to
work over multiple info documents. Add commands to search
text/index in User and Lispref.
Add new entry, "Uncomment Region" (parallels "Comment Out Region").
Redo Help menu; add bindings for new Info commands to search the
index or text of the User and Lispref manuals. Add command for
mark-paragraph, activate-region. Make Edit->R accelerator be
rectangle, not register (more commonly used), and put rectangle
first. Fix the Edit Init File entry to never load the .elc file.
Simplify the default-popup-menu. Add Cmds->Tabs menu.
Use kp-left not kp_left, etc.
---------------- Miscellaneous bug fixes/cleanup -------------------
byte-compiler-options: Correct doc string.
easy-menu-do-define: fix extra quote.
fill-paragraph-or-region:Rewrite to be more correct -- use
call-interactively so that we always get exactly the same
behavior as if the functions were called directly.
No need to fiddle with zmacs-region-stays, now that bogus
clearing of it (2001-04-28 src/ChangeLog) is removed.
Put dialog titles back in -- this time correctly. Fix various
other problems with leaks and such.
key-sequence-list-description:
Clean up fun to always correctly canonicalize.
Clean up Kinsoku comments, synch comment-region with FSF 20.7.
* simple.el (region-exists-p):
* simple.el (region-active-p):
Add comment about which one is correct to use in menu specs.
* sound.el (load-sound-file):
Minor code clean up.
* startup.el:
* startup.el (command-line-early):
* startup.el (initial-scratch-message):
Comment changes. Add info about sample.init.el to splash screen.
Improve initial-scratch-message and clarify purpose of Scratch
buffer. Fix byte-compile warning.
------------------------ Added features -------------------------
Add new variable to control whether etags checks all parent
directories for tag files. (On by default.)
* hash-table.el: New file, useful utility functions.
* dumped-lisp.el (preloaded-file-list): Dump hash-table.el.
------------ notable bug fix: Windows event code --------------
Get critical quit working.
------------ notable bug fix and new feature: regex code --------------
Shy groups were implemented in a horrible, half-assed way that
would cause them to screw up regex searching in most cases.
Fixed to work correctly.
Also extended back-reference syntax past 9. Only is recognized
as such if there are at least that many non-shy groups; and
optionally will warn about such uses, to catch old code that
might be using them differently. (Added variable to control
this in search.c -- `warn-about-possibly-incompatible-back-
references', on by default for the moment. Declared in lisp.h.
---------------- process/SIGIO improvements -------------------
define USE_GETADDRINFO to replace more complex conditional,
and use it. the code conditionalized on this in
unix_open_network_stream had *serious* problems handling errors.
it's now fixed, and major amounts of duplicate code between
the two versions were combined.
don't disable SIGIO and other interrupts unless
CONNECT_NEEDS_SLOWED_INTERRUPTS is defined -- don't penalize OS's
without bugs. similarly for a freebsd bug that was affecting all
OS's.
* s\ultrix.h:
define CONNECT_NEEDS_SLOWED_INTERRUPTS, since that's the OS
mentioned as having a kernel bug.
* sysdep.c (request_sigio_on_device):
* sysdep.c (unrequest_sigio_on_device):
fix SIGIO problems on Linux. add check for O_ASYNC in case it's
defined and FASYNC isn't. add comment about other ways to do
SIGIO on Linux.
* callproc.c (Fold_call_process_internal):
* process.c (Fstart_process_internal):
Deal with the possibility that `default-directory' doesn't
have terminating slash. Correct comments about vfork.
---------------- Miscellaneous bug fixes/cleanup -------------------
* callint.c (Finteractive):
Add lots of documentation -- exactly what the Lisp equivalents of
all the interactive specs are.
* console.h (struct console): change type of quit_char to Emchar.
* event-msw.c (lstream_type_create_mswindows_selectable): spacing
change.
Eliminate events-mod.h and combine into events.h.
* emacs.c:
* emacs.c (make_arg_list_1):
* emacs.c (main_1):
A couple of char->Extbyte changes, add a comment.
* glyphs-msw.c:
Correct indentation of function defns to not exceed 80 cols.
Try (sort of) to fix some code that sets the colors of the
progress gauge. (Commented out)
* keymap.c (syms_of_keymap):
use DEFSYMBOL.
* process.c (read_process_output):
No need to fiddle with zmacs_region_stays, now that bogus
clearing of it (see below) is removed.
* search.c (Freplace_match): warning fix.
author | ben |
---|---|
date | Fri, 04 May 2001 22:42:35 +0000 |
parents | 223736d75acb |
children | cd662ad69f40 |
comparison
equal
deleted
inserted
replaced
501:0a255b32b157 | 502:7039e6323819 |
---|---|
413 not one of those specified. */ | 413 not one of those specified. */ |
414 charset_not, | 414 charset_not, |
415 | 415 |
416 /* Start remembering the text that is matched, for storing in a | 416 /* Start remembering the text that is matched, for storing in a |
417 register. Followed by one byte with the register number, in | 417 register. Followed by one byte with the register number, in |
418 the range 0 to one less than the pattern buffer's re_nsub | 418 the range 1 to the pattern buffer's re_ngroups |
419 field. Then followed by one byte with the number of groups | 419 field. Then followed by one byte with the number of groups |
420 inner to this one. (This last has to be part of the | 420 inner to this one. (This last has to be part of the |
421 start_memory only because we need it in the on_failure_jump | 421 start_memory only because we need it in the on_failure_jump |
422 of re_match_2.) */ | 422 of re_match_2.) */ |
423 start_memory, | 423 start_memory, |
424 | 424 |
425 /* Stop remembering the text that is matched and store it in a | 425 /* Stop remembering the text that is matched and store it in a |
426 memory register. Followed by one byte with the register | 426 memory register. Followed by one byte with the register |
427 number, in the range 0 to one less than `re_nsub' in the | 427 number, in the range 1 to `re_ngroups' in the |
428 pattern buffer, and one byte with the number of inner groups, | 428 pattern buffer, and one byte with the number of inner groups, |
429 just like `start_memory'. (We need the number of inner | 429 just like `start_memory'. (We need the number of inner |
430 groups here because we don't have any easy way of finding the | 430 groups here because we don't have any easy way of finding the |
431 corresponding start_memory when we're at a stop_memory.) */ | 431 corresponding start_memory when we're at a stop_memory.) */ |
432 stop_memory, | 432 stop_memory, |
969 printf ("fastmap: "); | 969 printf ("fastmap: "); |
970 print_fastmap (bufp->fastmap); | 970 print_fastmap (bufp->fastmap); |
971 } | 971 } |
972 | 972 |
973 printf ("re_nsub: %ld\t", (long)bufp->re_nsub); | 973 printf ("re_nsub: %ld\t", (long)bufp->re_nsub); |
974 printf ("re_ngroups: %ld\t", (long)bufp->re_ngroups); | |
974 printf ("regs_alloc: %d\t", bufp->regs_allocated); | 975 printf ("regs_alloc: %d\t", bufp->regs_allocated); |
975 printf ("can_be_null: %d\t", bufp->can_be_null); | 976 printf ("can_be_null: %d\t", bufp->can_be_null); |
976 printf ("newline_anchor: %d\n", bufp->newline_anchor); | 977 printf ("newline_anchor: %d\n", bufp->newline_anchor); |
977 printf ("no_sub: %d\t", bufp->no_sub); | 978 printf ("no_sub: %d\t", bufp->no_sub); |
978 printf ("not_bol: %d\t", bufp->not_bol); | 979 printf ("not_bol: %d\t", bufp->not_bol); |
979 printf ("not_eol: %d\t", bufp->not_eol); | 980 printf ("not_eol: %d\t", bufp->not_eol); |
980 printf ("syntax: %d\n", bufp->syntax); | 981 printf ("syntax: %d\n", bufp->syntax); |
981 /* Perhaps we should print the translate table? */ | 982 /* Perhaps we should print the translate table? */ |
982 /* and maybe the category table? */ | 983 /* and maybe the category table? */ |
984 | |
985 if (bufp->external_to_internal_register) | |
986 { | |
987 int i; | |
988 | |
989 printf ("external_to_internal_register:\n"); | |
990 for (i = 0; i <= bufp->re_nsub; i++) | |
991 { | |
992 if (i > 0) | |
993 printf (", "); | |
994 printf ("%d -> %d", i, bufp->external_to_internal_register[i]); | |
995 } | |
996 printf ("\n"); | |
997 } | |
983 } | 998 } |
984 | 999 |
985 | 1000 |
986 static void | 1001 static void |
987 print_double_string (re_char *where, re_char *string1, int size1, | 1002 print_double_string (re_char *where, re_char *string1, int size1, |
1692 {start,stop}_memory, the maximum number of groups we can report | 1707 {start,stop}_memory, the maximum number of groups we can report |
1693 things about is what fits in that byte. */ | 1708 things about is what fits in that byte. */ |
1694 #define MAX_REGNUM 255 | 1709 #define MAX_REGNUM 255 |
1695 | 1710 |
1696 /* But patterns can have more than `MAX_REGNUM' registers. We just | 1711 /* But patterns can have more than `MAX_REGNUM' registers. We just |
1697 ignore the excess. */ | 1712 ignore the excess. |
1713 #### not true! groups past this will fail in lots of ways, if we | |
1714 ever have to backtrack. | |
1715 */ | |
1698 typedef unsigned regnum_t; | 1716 typedef unsigned regnum_t; |
1699 | 1717 |
1718 #define INIT_REG_TRANSLATE_SIZE 5 | |
1700 | 1719 |
1701 /* Macros for the compile stack. */ | 1720 /* Macros for the compile stack. */ |
1702 | 1721 |
1703 /* Since offsets can go either forwards or backwards, this type needs to | 1722 /* Since offsets can go either forwards or backwards, this type needs to |
1704 be able to hold values from -(MAX_BUF_SIZE - 1) to MAX_BUF_SIZE - 1. */ | 1723 be able to hold values from -(MAX_BUF_SIZE - 1) to MAX_BUF_SIZE - 1. */ |
1878 contents of BUFP are undefined): | 1897 contents of BUFP are undefined): |
1879 `buffer' is the compiled pattern; | 1898 `buffer' is the compiled pattern; |
1880 `syntax' is set to SYNTAX; | 1899 `syntax' is set to SYNTAX; |
1881 `used' is set to the length of the compiled pattern; | 1900 `used' is set to the length of the compiled pattern; |
1882 `fastmap_accurate' is zero; | 1901 `fastmap_accurate' is zero; |
1883 `re_nsub' is the number of subexpressions in PATTERN; | 1902 `re_ngroups' is the number of groups/subexpressions (including shy |
1903 groups) in PATTERN; | |
1904 `re_nsub' is the number of non-shy groups in PATTERN; | |
1884 `not_bol' and `not_eol' are zero; | 1905 `not_bol' and `not_eol' are zero; |
1885 | 1906 |
1886 The `fastmap' and `newline_anchor' fields are neither | 1907 The `fastmap' and `newline_anchor' fields are neither |
1887 examined nor set. */ | 1908 examined nor set. */ |
1888 | 1909 |
1976 at the end. */ | 1997 at the end. */ |
1977 bufp->used = 0; | 1998 bufp->used = 0; |
1978 | 1999 |
1979 /* Always count groups, whether or not bufp->no_sub is set. */ | 2000 /* Always count groups, whether or not bufp->no_sub is set. */ |
1980 bufp->re_nsub = 0; | 2001 bufp->re_nsub = 0; |
2002 bufp->re_ngroups = 0; | |
2003 | |
2004 bufp->warned_about_incompatible_back_references = 0; | |
2005 | |
2006 if (bufp->external_to_internal_register == 0) | |
2007 { | |
2008 bufp->external_to_internal_register_size = INIT_REG_TRANSLATE_SIZE; | |
2009 RETALLOC (bufp->external_to_internal_register, | |
2010 bufp->external_to_internal_register_size, | |
2011 int); | |
2012 } | |
2013 | |
2014 { | |
2015 int i; | |
2016 | |
2017 bufp->external_to_internal_register[0] = 0; | |
2018 for (i = 1; i < bufp->external_to_internal_register_size; i++) | |
2019 bufp->external_to_internal_register[i] = (int) 0xDEADBEEF; | |
2020 } | |
1981 | 2021 |
1982 #if !defined (emacs) && !defined (SYNTAX_TABLE) | 2022 #if !defined (emacs) && !defined (SYNTAX_TABLE) |
1983 /* Initialize the syntax table. */ | 2023 /* Initialize the syntax table. */ |
1984 init_syntax_once (); | 2024 init_syntax_once (); |
1985 #endif | 2025 #endif |
2558 goto normal_backslash; | 2598 goto normal_backslash; |
2559 | 2599 |
2560 handle_open: | 2600 handle_open: |
2561 { | 2601 { |
2562 regnum_t r; | 2602 regnum_t r; |
2603 int shy = 0; | |
2563 | 2604 |
2564 if (!(syntax & RE_NO_SHY_GROUPS) | 2605 if (!(syntax & RE_NO_SHY_GROUPS) |
2565 && p != pend | 2606 && p != pend |
2566 && *p == '?') | 2607 && *p == '?') |
2567 { | 2608 { |
2568 p++; | 2609 p++; |
2569 PATFETCH (c); | 2610 PATFETCH (c); |
2570 switch (c) | 2611 switch (c) |
2571 { | 2612 { |
2572 case ':': /* shy groups */ | 2613 case ':': /* shy groups */ |
2573 r = MAX_REGNUM + 1; | 2614 shy = 1; |
2574 break; | 2615 break; |
2575 | 2616 |
2576 /* All others are reserved for future constructs. */ | 2617 /* All others are reserved for future constructs. */ |
2577 default: | 2618 default: |
2578 FREE_STACK_RETURN (REG_BADPAT); | 2619 FREE_STACK_RETURN (REG_BADPAT); |
2579 } | 2620 } |
2580 } | 2621 } |
2581 else | 2622 |
2582 { | 2623 r = ++regnum; |
2583 bufp->re_nsub++; | 2624 bufp->re_ngroups++; |
2584 r = ++regnum; | 2625 if (!shy) |
2585 } | 2626 { |
2627 bufp->re_nsub++; | |
2628 while (bufp->external_to_internal_register_size <= | |
2629 bufp->re_nsub) | |
2630 { | |
2631 int i; | |
2632 int old_size = | |
2633 bufp->external_to_internal_register_size; | |
2634 bufp->external_to_internal_register_size += 5; | |
2635 RETALLOC (bufp->external_to_internal_register, | |
2636 bufp->external_to_internal_register_size, | |
2637 int); | |
2638 /* debugging */ | |
2639 for (i = old_size; | |
2640 i < bufp->external_to_internal_register_size; i++) | |
2641 bufp->external_to_internal_register[i] = | |
2642 (int) 0xDEADBEEF; | |
2643 } | |
2644 | |
2645 bufp->external_to_internal_register[bufp->re_nsub] = | |
2646 bufp->re_ngroups; | |
2647 } | |
2586 | 2648 |
2587 if (COMPILE_STACK_FULL) | 2649 if (COMPILE_STACK_FULL) |
2588 { | 2650 { |
2589 RETALLOC (compile_stack.stack, compile_stack.size << 1, | 2651 RETALLOC (compile_stack.stack, compile_stack.size << 1, |
2590 compile_stack_elt_t); | 2652 compile_stack_elt_t); |
2604 COMPILE_STACK_TOP.regnum = r; | 2666 COMPILE_STACK_TOP.regnum = r; |
2605 | 2667 |
2606 /* We will eventually replace the 0 with the number of | 2668 /* We will eventually replace the 0 with the number of |
2607 groups inner to this one. But do not push a | 2669 groups inner to this one. But do not push a |
2608 start_memory for groups beyond the last one we can | 2670 start_memory for groups beyond the last one we can |
2609 represent in the compiled pattern. */ | 2671 represent in the compiled pattern. |
2672 #### bad bad bad. this will fail in lots of ways, if we | |
2673 ever have to backtrack for these groups. | |
2674 */ | |
2610 if (r <= MAX_REGNUM) | 2675 if (r <= MAX_REGNUM) |
2611 { | 2676 { |
2612 COMPILE_STACK_TOP.inner_group_offset | 2677 COMPILE_STACK_TOP.inner_group_offset |
2613 = buf_end - bufp->buffer + 2; | 2678 = buf_end - bufp->buffer + 2; |
2614 BUF_PUSH_3 (start_memory, r, 0); | 2679 BUF_PUSH_3 (start_memory, r, 0); |
2994 break; | 3059 break; |
2995 | 3060 |
2996 case '1': case '2': case '3': case '4': case '5': | 3061 case '1': case '2': case '3': case '4': case '5': |
2997 case '6': case '7': case '8': case '9': | 3062 case '6': case '7': case '8': case '9': |
2998 { | 3063 { |
2999 regnum_t reg; | 3064 regnum_t reg, regint; |
3065 int may_need_to_unfetch = 0; | |
3000 if (syntax & RE_NO_BK_REFS) | 3066 if (syntax & RE_NO_BK_REFS) |
3001 goto normal_char; | 3067 goto normal_char; |
3002 | 3068 |
3069 /* This only goes up to 99. It could be extended to work | |
3070 up to 255 (the maximum number of registers that can be | |
3071 handled by the current regexp engine, because it stores | |
3072 its register numbers in the compiled pattern as one byte, | |
3073 ugh). Doing that's a bit trickier, because you might | |
3074 have the case where \25 a back-ref but \255 is not, ... */ | |
3003 reg = c - '0'; | 3075 reg = c - '0'; |
3004 | 3076 if (p < pend) |
3005 if (reg > regnum) | 3077 { |
3078 PATFETCH (c); | |
3079 if (c >= '0' && c <= '9') | |
3080 { | |
3081 regnum_t new_reg = reg * 10 + c - '0'; | |
3082 if (new_reg <= bufp->re_nsub) | |
3083 { | |
3084 reg = new_reg; | |
3085 may_need_to_unfetch = 1; | |
3086 } | |
3087 else | |
3088 PATUNFETCH; | |
3089 } | |
3090 } | |
3091 | |
3092 if (reg > bufp->re_nsub) | |
3006 FREE_STACK_RETURN (REG_ESUBREG); | 3093 FREE_STACK_RETURN (REG_ESUBREG); |
3007 | 3094 |
3095 regint = bufp->external_to_internal_register[reg]; | |
3008 /* Can't back reference to a subexpression if inside of it. */ | 3096 /* Can't back reference to a subexpression if inside of it. */ |
3009 if (group_in_compile_stack (compile_stack, reg)) | 3097 if (group_in_compile_stack (compile_stack, regint)) |
3010 goto normal_char; | 3098 { |
3099 if (may_need_to_unfetch) | |
3100 PATUNFETCH; | |
3101 goto normal_char; | |
3102 } | |
3103 | |
3104 #ifdef emacs | |
3105 if (reg > 9 && | |
3106 bufp->warned_about_incompatible_back_references == 0) | |
3107 { | |
3108 bufp->warned_about_incompatible_back_references = 1; | |
3109 warn_when_safe (intern ("regex"), Qinfo, | |
3110 "Back reference \\%d now has new " | |
3111 "semantics in %s", reg, pattern); | |
3112 } | |
3113 #endif | |
3011 | 3114 |
3012 laststart = buf_end; | 3115 laststart = buf_end; |
3013 BUF_PUSH_2 (duplicate, reg); | 3116 BUF_PUSH_2 (duplicate, regint); |
3014 } | 3117 } |
3015 break; | 3118 break; |
3016 | 3119 |
3017 | 3120 |
3018 case '+': | 3121 case '+': |
3123 #ifndef MATCH_MAY_ALLOCATE | 3226 #ifndef MATCH_MAY_ALLOCATE |
3124 /* Initialize the failure stack to the largest possible stack. This | 3227 /* Initialize the failure stack to the largest possible stack. This |
3125 isn't necessary unless we're trying to avoid calling alloca in | 3228 isn't necessary unless we're trying to avoid calling alloca in |
3126 the search and match routines. */ | 3229 the search and match routines. */ |
3127 { | 3230 { |
3128 int num_regs = bufp->re_nsub + 1; | 3231 int num_regs = bufp->re_ngroups + 1; |
3129 | 3232 |
3130 /* Since DOUBLE_FAIL_STACK refuses to double only if the current size | 3233 /* Since DOUBLE_FAIL_STACK refuses to double only if the current size |
3131 is strictly greater than re_max_failures, the largest possible stack | 3234 is strictly greater than re_max_failures, the largest possible stack |
3132 is 2 * re_max_failures failure points. */ | 3235 is 2 * re_max_failures failure points. */ |
3133 if (fail_stack.size < (2 * re_max_failures * MAX_FAILURE_ITEMS)) | 3236 if (fail_stack.size < (2 * re_max_failures * MAX_FAILURE_ITEMS)) |
4384 #endif | 4487 #endif |
4385 | 4488 |
4386 /* We fill all the registers internally, independent of what we | 4489 /* We fill all the registers internally, independent of what we |
4387 return, for use in backreferences. The number here includes | 4490 return, for use in backreferences. The number here includes |
4388 an element for register zero. */ | 4491 an element for register zero. */ |
4389 unsigned num_regs = bufp->re_nsub + 1; | 4492 unsigned num_regs = bufp->re_ngroups + 1; |
4390 | 4493 |
4391 /* The currently active registers. */ | 4494 /* The currently active registers. */ |
4392 unsigned lowest_active_reg = NO_LOWEST_ACTIVE_REG; | 4495 unsigned lowest_active_reg = NO_LOWEST_ACTIVE_REG; |
4393 unsigned highest_active_reg = NO_HIGHEST_ACTIVE_REG; | 4496 unsigned highest_active_reg = NO_HIGHEST_ACTIVE_REG; |
4394 | 4497 |
4470 /* Do not bother to initialize all the register variables if there are | 4573 /* Do not bother to initialize all the register variables if there are |
4471 no groups in the pattern, as it takes a fair amount of time. If | 4574 no groups in the pattern, as it takes a fair amount of time. If |
4472 there are groups, we include space for register 0 (the whole | 4575 there are groups, we include space for register 0 (the whole |
4473 pattern), even though we never use it, since it simplifies the | 4576 pattern), even though we never use it, since it simplifies the |
4474 array indexing. We should fix this. */ | 4577 array indexing. We should fix this. */ |
4475 if (bufp->re_nsub) | 4578 if (bufp->re_ngroups) |
4476 { | 4579 { |
4477 regstart = REGEX_TALLOC (num_regs, re_char *); | 4580 regstart = REGEX_TALLOC (num_regs, re_char *); |
4478 regend = REGEX_TALLOC (num_regs, re_char *); | 4581 regend = REGEX_TALLOC (num_regs, re_char *); |
4479 old_regstart = REGEX_TALLOC (num_regs, re_char *); | 4582 old_regstart = REGEX_TALLOC (num_regs, re_char *); |
4480 old_regend = REGEX_TALLOC (num_regs, re_char *); | 4583 old_regend = REGEX_TALLOC (num_regs, re_char *); |
4648 DEBUG_PRINT1 ("Accepting match.\n"); | 4751 DEBUG_PRINT1 ("Accepting match.\n"); |
4649 | 4752 |
4650 /* If caller wants register contents data back, do it. */ | 4753 /* If caller wants register contents data back, do it. */ |
4651 if (regs && !bufp->no_sub) | 4754 if (regs && !bufp->no_sub) |
4652 { | 4755 { |
4756 int num_nonshy_regs = bufp->re_nsub + 1; | |
4653 /* Have the register data arrays been allocated? */ | 4757 /* Have the register data arrays been allocated? */ |
4654 if (bufp->regs_allocated == REGS_UNALLOCATED) | 4758 if (bufp->regs_allocated == REGS_UNALLOCATED) |
4655 { /* No. So allocate them with malloc. We need one | 4759 { /* No. So allocate them with malloc. We need one |
4656 extra element beyond `num_regs' for the `-1' marker | 4760 extra element beyond `num_regs' for the `-1' marker |
4657 GNU code uses. */ | 4761 GNU code uses. */ |
4658 regs->num_regs = MAX (RE_NREGS, num_regs + 1); | 4762 regs->num_regs = MAX (RE_NREGS, num_nonshy_regs + 1); |
4659 regs->start = TALLOC (regs->num_regs, regoff_t); | 4763 regs->start = TALLOC (regs->num_regs, regoff_t); |
4660 regs->end = TALLOC (regs->num_regs, regoff_t); | 4764 regs->end = TALLOC (regs->num_regs, regoff_t); |
4661 if (regs->start == NULL || regs->end == NULL) | 4765 if (regs->start == NULL || regs->end == NULL) |
4662 { | 4766 { |
4663 FREE_VARIABLES (); | 4767 FREE_VARIABLES (); |
4667 } | 4771 } |
4668 else if (bufp->regs_allocated == REGS_REALLOCATE) | 4772 else if (bufp->regs_allocated == REGS_REALLOCATE) |
4669 { /* Yes. If we need more elements than were already | 4773 { /* Yes. If we need more elements than were already |
4670 allocated, reallocate them. If we need fewer, just | 4774 allocated, reallocate them. If we need fewer, just |
4671 leave it alone. */ | 4775 leave it alone. */ |
4672 if (regs->num_regs < num_regs + 1) | 4776 if (regs->num_regs < num_nonshy_regs + 1) |
4673 { | 4777 { |
4674 regs->num_regs = num_regs + 1; | 4778 regs->num_regs = num_nonshy_regs + 1; |
4675 RETALLOC (regs->start, regs->num_regs, regoff_t); | 4779 RETALLOC (regs->start, regs->num_regs, regoff_t); |
4676 RETALLOC (regs->end, regs->num_regs, regoff_t); | 4780 RETALLOC (regs->end, regs->num_regs, regoff_t); |
4677 if (regs->start == NULL || regs->end == NULL) | 4781 if (regs->start == NULL || regs->end == NULL) |
4678 { | 4782 { |
4679 FREE_VARIABLES (); | 4783 FREE_VARIABLES (); |
4699 : ((regoff_t) (d - string2 + size1))); | 4803 : ((regoff_t) (d - string2 + size1))); |
4700 } | 4804 } |
4701 | 4805 |
4702 /* Go through the first `min (num_regs, regs->num_regs)' | 4806 /* Go through the first `min (num_regs, regs->num_regs)' |
4703 registers, since that is all we initialized. */ | 4807 registers, since that is all we initialized. */ |
4704 for (mcnt = 1; mcnt < MIN (num_regs, regs->num_regs); mcnt++) | 4808 for (mcnt = 1; mcnt < MIN (num_nonshy_regs, regs->num_regs); |
4809 mcnt++) | |
4705 { | 4810 { |
4706 if (REG_UNSET (regstart[mcnt]) || REG_UNSET (regend[mcnt])) | 4811 int internal_reg = bufp->external_to_internal_register[mcnt]; |
4812 if (REG_UNSET (regstart[internal_reg]) || | |
4813 REG_UNSET (regend[internal_reg])) | |
4707 regs->start[mcnt] = regs->end[mcnt] = -1; | 4814 regs->start[mcnt] = regs->end[mcnt] = -1; |
4708 else | 4815 else |
4709 { | 4816 { |
4710 regs->start[mcnt] | 4817 regs->start[mcnt] = |
4711 = (regoff_t) POINTER_TO_OFFSET (regstart[mcnt]); | 4818 (regoff_t) POINTER_TO_OFFSET (regstart[internal_reg]); |
4712 regs->end[mcnt] | 4819 regs->end[mcnt] = |
4713 = (regoff_t) POINTER_TO_OFFSET (regend[mcnt]); | 4820 (regoff_t) POINTER_TO_OFFSET (regend[internal_reg]); |
4714 } | 4821 } |
4715 } | 4822 } |
4716 | 4823 |
4717 /* If the regs structure we return has more elements than | 4824 /* If the regs structure we return has more elements than |
4718 were in the pattern, set the extra elements to -1. If | 4825 were in the pattern, set the extra elements to -1. If |
4719 we (re)allocated the registers, this is the case, | 4826 we (re)allocated the registers, this is the case, |
4720 because we always allocate enough to have at least one | 4827 because we always allocate enough to have at least one |
4721 -1 at the end. */ | 4828 -1 at the end. */ |
4722 for (mcnt = num_regs; mcnt < regs->num_regs; mcnt++) | 4829 for (mcnt = num_nonshy_regs; mcnt < regs->num_regs; mcnt++) |
4723 regs->start[mcnt] = regs->end[mcnt] = -1; | 4830 regs->start[mcnt] = regs->end[mcnt] = -1; |
4724 } /* regs && !bufp->no_sub */ | 4831 } /* regs && !bufp->no_sub */ |
4725 | 4832 |
4726 DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n", | 4833 DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n", |
4727 nfailure_points_pushed, nfailure_points_popped, | 4834 nfailure_points_pushed, nfailure_points_popped, |
5063 p += 2; | 5170 p += 2; |
5064 break; | 5171 break; |
5065 | 5172 |
5066 | 5173 |
5067 /* \<digit> has been turned into a `duplicate' command which is | 5174 /* \<digit> has been turned into a `duplicate' command which is |
5068 followed by the numeric value of <digit> as the register number. */ | 5175 followed by the numeric value of <digit> as the register number. |
5176 (Already passed through external-to-internal-register mapping, | |
5177 so it refers to the actual group number, not the non-shy-only | |
5178 numbering used in the external world.) */ | |
5069 case duplicate: | 5179 case duplicate: |
5070 { | 5180 { |
5071 REGISTER re_char *d2, *dend2; | 5181 REGISTER re_char *d2, *dend2; |
5072 int regno = *p++; /* Get which register to match against. */ | 5182 /* Get which register to match against. */ |
5183 int regno = *p++; | |
5073 DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno); | 5184 DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno); |
5074 | 5185 |
5075 /* Can't back reference a group which we've never matched. */ | 5186 /* Can't back reference a group which we've never matched. */ |
5076 if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno])) | 5187 if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno])) |
5077 goto fail; | 5188 goto fail; |
6220 REG_EXTENDED bit in CFLAGS is set; otherwise, to | 6331 REG_EXTENDED bit in CFLAGS is set; otherwise, to |
6221 RE_SYNTAX_POSIX_BASIC; | 6332 RE_SYNTAX_POSIX_BASIC; |
6222 `newline_anchor' to REG_NEWLINE being set in CFLAGS; | 6333 `newline_anchor' to REG_NEWLINE being set in CFLAGS; |
6223 `fastmap' and `fastmap_accurate' to zero; | 6334 `fastmap' and `fastmap_accurate' to zero; |
6224 `re_nsub' to the number of subexpressions in PATTERN. | 6335 `re_nsub' to the number of subexpressions in PATTERN. |
6336 (non-shy of course. POSIX probably doesn't know about | |
6337 shy ones, and in any case they should be invisible.) | |
6225 | 6338 |
6226 PATTERN is the address of the pattern string. | 6339 PATTERN is the address of the pattern string. |
6227 | 6340 |
6228 CFLAGS is a series of bits which affect compilation. | 6341 CFLAGS is a series of bits which affect compilation. |
6229 | 6342 |