Mercurial > hg > xemacs-beta
comparison src/regex.c @ 1028:b03923afd851
[xemacs-hg @ 2002-10-03 18:08:18 by stephent]
Ba-a-a-ad Steve <873crnjt30.fsf@tleepslib.sk.tsukuba.ac.jp>
author | stephent |
---|---|
date | Thu, 03 Oct 2002 18:08:24 +0000 |
parents | ccaf90c5a53a |
children | 1b0339b048ce |
comparison
equal
deleted
inserted
replaced
1027:089f79dae3ab | 1028:b03923afd851 |
---|---|
4845 | 4845 |
4846 succeed_label: | 4846 succeed_label: |
4847 DEBUG_PRINT1 ("Accepting match.\n"); | 4847 DEBUG_PRINT1 ("Accepting match.\n"); |
4848 | 4848 |
4849 /* If caller wants register contents data back, do it. */ | 4849 /* If caller wants register contents data back, do it. */ |
4850 if (regs && !bufp->no_sub) | 4850 { |
4851 { | 4851 int num_nonshy_regs = bufp->re_nsub + 1; |
4852 int num_nonshy_regs = bufp->re_nsub + 1; | 4852 if (regs && !bufp->no_sub) |
4853 /* Have the register data arrays been allocated? */ | 4853 { |
4854 if (bufp->regs_allocated == REGS_UNALLOCATED) | 4854 /* Have the register data arrays been allocated? */ |
4855 { /* No. So allocate them with malloc. We need one | 4855 if (bufp->regs_allocated == REGS_UNALLOCATED) |
4856 extra element beyond `num_regs' for the `-1' marker | 4856 { /* No. So allocate them with malloc. We need one |
4857 GNU code uses. */ | 4857 extra element beyond `num_regs' for the `-1' marker |
4858 regs->num_regs = MAX (RE_NREGS, num_nonshy_regs + 1); | 4858 GNU code uses. */ |
4859 regs->start = TALLOC (regs->num_regs, regoff_t); | 4859 regs->num_regs = MAX (RE_NREGS, num_nonshy_regs + 1); |
4860 regs->end = TALLOC (regs->num_regs, regoff_t); | 4860 regs->start = TALLOC (regs->num_regs, regoff_t); |
4861 if (regs->start == NULL || regs->end == NULL) | 4861 regs->end = TALLOC (regs->num_regs, regoff_t); |
4862 { | 4862 if (regs->start == NULL || regs->end == NULL) |
4863 FREE_VARIABLES (); | 4863 { |
4864 return -2; | 4864 FREE_VARIABLES (); |
4865 } | 4865 return -2; |
4866 bufp->regs_allocated = REGS_REALLOCATE; | 4866 } |
4867 } | 4867 bufp->regs_allocated = REGS_REALLOCATE; |
4868 else if (bufp->regs_allocated == REGS_REALLOCATE) | 4868 } |
4869 { /* Yes. If we need more elements than were already | 4869 else if (bufp->regs_allocated == REGS_REALLOCATE) |
4870 allocated, reallocate them. If we need fewer, just | 4870 { /* Yes. If we need more elements than were already |
4871 leave it alone. */ | 4871 allocated, reallocate them. If we need fewer, just |
4872 if (regs->num_regs < num_nonshy_regs + 1) | 4872 leave it alone. */ |
4873 { | 4873 if (regs->num_regs < num_nonshy_regs + 1) |
4874 regs->num_regs = num_nonshy_regs + 1; | 4874 { |
4875 RETALLOC (regs->start, regs->num_regs, regoff_t); | 4875 regs->num_regs = num_nonshy_regs + 1; |
4876 RETALLOC (regs->end, regs->num_regs, regoff_t); | 4876 RETALLOC (regs->start, regs->num_regs, regoff_t); |
4877 if (regs->start == NULL || regs->end == NULL) | 4877 RETALLOC (regs->end, regs->num_regs, regoff_t); |
4878 { | 4878 if (regs->start == NULL || regs->end == NULL) |
4879 FREE_VARIABLES (); | 4879 { |
4880 return -2; | 4880 FREE_VARIABLES (); |
4881 } | 4881 return -2; |
4882 } | 4882 } |
4883 } | 4883 } |
4884 else | 4884 } |
4885 { | 4885 else |
4886 /* These braces fend off a "empty body in an else-statement" | 4886 { |
4887 warning under GCC when assert expands to nothing. */ | 4887 /* The braces fend off a "empty body in an else-statement" |
4888 assert (bufp->regs_allocated == REGS_FIXED); | 4888 warning under GCC when assert expands to nothing. */ |
4889 } | 4889 assert (bufp->regs_allocated == REGS_FIXED); |
4890 | 4890 } |
4891 /* Convert the pointer data in `regstart' and `regend' to | 4891 |
4892 indices. Register zero has to be set differently, | 4892 /* Convert the pointer data in `regstart' and `regend' to |
4893 since we haven't kept track of any info for it. */ | 4893 indices. Register zero has to be set differently, |
4894 if (regs->num_regs > 0) | 4894 since we haven't kept track of any info for it. */ |
4895 { | 4895 if (regs->num_regs > 0) |
4896 regs->start[0] = pos; | 4896 { |
4897 regs->end[0] = (MATCHING_IN_FIRST_STRING | 4897 regs->start[0] = pos; |
4898 ? ((regoff_t) (d - string1)) | 4898 regs->end[0] = (MATCHING_IN_FIRST_STRING |
4899 : ((regoff_t) (d - string2 + size1))); | 4899 ? ((regoff_t) (d - string1)) |
4900 } | 4900 : ((regoff_t) (d - string2 + size1))); |
4901 | 4901 } |
4902 /* Go through the first `min (num_regs, regs->num_regs)' | 4902 |
4903 registers, since that is all we initialized. */ | 4903 /* Go through the first `min (num_regs, regs->num_regs)' |
4904 for (mcnt = 1; mcnt < MIN (num_nonshy_regs, regs->num_regs); | 4904 registers, since that is all we initialized. */ |
4905 mcnt++) | 4905 for (mcnt = 1; mcnt < MIN (num_nonshy_regs, regs->num_regs); |
4906 { | 4906 mcnt++) |
4907 int internal_reg = bufp->external_to_internal_register[mcnt]; | 4907 { |
4908 if (REG_UNSET (regstart[internal_reg]) || | 4908 int internal_reg = bufp->external_to_internal_register[mcnt]; |
4909 REG_UNSET (regend[internal_reg])) | 4909 if (REG_UNSET (regstart[internal_reg]) || |
4910 regs->start[mcnt] = regs->end[mcnt] = -1; | 4910 REG_UNSET (regend[internal_reg])) |
4911 else | 4911 regs->start[mcnt] = regs->end[mcnt] = -1; |
4912 { | 4912 else |
4913 regs->start[mcnt] = | 4913 { |
4914 (regoff_t) POINTER_TO_OFFSET (regstart[internal_reg]); | 4914 regs->start[mcnt] = |
4915 regs->end[mcnt] = | 4915 (regoff_t) POINTER_TO_OFFSET (regstart[internal_reg]); |
4916 (regoff_t) POINTER_TO_OFFSET (regend[internal_reg]); | 4916 regs->end[mcnt] = |
4917 } | 4917 (regoff_t) POINTER_TO_OFFSET (regend[internal_reg]); |
4918 } | 4918 } |
4919 } /* regs && !bufp->no_sub */ | 4919 } |
4920 | 4920 } /* regs && !bufp->no_sub */ |
4921 /* If we have regs and the regs structure has more elements than | 4921 |
4922 were in the pattern, set the extra elements to -1. If we | 4922 /* If we have regs and the regs structure has more elements than |
4923 (re)allocated the registers, this is the case, because we | 4923 were in the pattern, set the extra elements to -1. If we |
4924 always allocate enough to have at least one -1 at the end. | 4924 (re)allocated the registers, this is the case, because we |
4925 | 4925 always allocate enough to have at least one -1 at the end. |
4926 We do this even when no_sub is set because some applications | 4926 |
4927 (XEmacs) reuse register structures which may contain stale | 4927 We do this even when no_sub is set because some applications |
4928 information, and permit attempts to access those registers. | 4928 (XEmacs) reuse register structures which may contain stale |
4929 | 4929 information, and permit attempts to access those registers. |
4930 It would be possible to require the caller to do this, but we'd | 4930 |
4931 have to change the API for this function to reflect that, and | 4931 It would be possible to require the caller to do this, but we'd |
4932 audit all callers. */ | 4932 have to change the API for this function to reflect that, and |
4933 if (regs && regs->num_regs > 0) | 4933 audit all callers. */ |
4934 for (mcnt = num_nonshy_regs; mcnt < regs->num_regs; mcnt++) | 4934 if (regs && regs->num_regs > 0) |
4935 regs->start[mcnt] = regs->end[mcnt] = -1; | 4935 for (mcnt = num_nonshy_regs; mcnt < regs->num_regs; mcnt++) |
4936 | 4936 regs->start[mcnt] = regs->end[mcnt] = -1; |
4937 } | |
4937 DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n", | 4938 DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n", |
4938 nfailure_points_pushed, nfailure_points_popped, | 4939 nfailure_points_pushed, nfailure_points_popped, |
4939 nfailure_points_pushed - nfailure_points_popped); | 4940 nfailure_points_pushed - nfailure_points_popped); |
4940 DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed); | 4941 DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed); |
4941 | 4942 |