Mercurial > hg > octave-lojdl > gnulib-hg
annotate regex.c @ 2371:3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
(enum re_opcode_t): Update description of succeed_n.
(PATFETCH): Always define.
(regex_compile): Use lookahead rather than PATUNFETCH (for repetition
operators, char classes, shy-groups and intervals).
Optimize special cases of intervals so as to only use succeed_n and
jump_n when really needed.
(re_compile_fastmap): Simplify handling of jump_n and succeed_n now
that we don't have to handle the special cases any more.
Simplify on_failure_jump handling as well.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 27 Mar 2000 22:26:37 +0000 |
parents | d8ded9c0e20c |
children | c0c46914f4fe |
rev | line source |
---|---|
679 | 1 /* Extended regular expression matching and search library, version |
2 0.12. (Implements POSIX draft P10003.2/D11.2, except for | |
2 | 3 internationalization features.) |
4 | |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5 Copyright (C) 1993,94,95,96,97,98,2000 Free Software Foundation, Inc. |
2 | 6 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
7 This program is free software; you can redistribute it and/or modify |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
8 it under the terms of the GNU General Public License as published by |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
9 the Free Software Foundation; either version 2, or (at your option) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
10 any later version. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
11 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
12 This program is distributed in the hope that it will be useful, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
941 | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
15 GNU General Public License for more details. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
16 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
18 along with this program; if not, write to the Free Software |
542 | 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
941 | 20 USA. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
21 |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
22 /* TODO: |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
23 - use analyze_first to optimize non-empty loops |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
24 - clean up multibyte issues |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
25 - structure the opcode space into opcode+flag. |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
26 - merge with glic's regex.[ch] |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
27 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
28 That's it for now -sm */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
29 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
30 /* AIX requires this to be the first thing in the file. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
31 #if defined (_AIX) && !defined (REGEX_MALLOC) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
32 #pragma alloca |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
33 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
34 |
511
799190471f84
(NUM_FAILURE_ITEMS, POP_FAILURE_POINT, PUSH_FAILURE_POINT):
Richard Stallman <rms@gnu.org>
parents:
506
diff
changeset
|
35 #undef _GNU_SOURCE |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
36 #define _GNU_SOURCE |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
37 |
1383
a7627de5ef66
(PTR_TO_OFFSET): Alternate definition if not `emacs'.
Richard Stallman <rms@gnu.org>
parents:
1382
diff
changeset
|
38 #ifdef emacs |
941 | 39 /* Converts the pointer to the char to BEG-based offset from the start. */ |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
40 #define PTR_TO_OFFSET(d) POS_AS_IN_BUFFER (POINTER_TO_OFFSET (d)) |
1382
894acce816ca
(POS_AS_IN_BUFFER): Add 1 only if operating on a buffer.
Richard Stallman <rms@gnu.org>
parents:
1381
diff
changeset
|
41 #define POS_AS_IN_BUFFER(p) ((p) + (NILP (re_match_object) || BUFFERP (re_match_object))) |
1383
a7627de5ef66
(PTR_TO_OFFSET): Alternate definition if not `emacs'.
Richard Stallman <rms@gnu.org>
parents:
1382
diff
changeset
|
42 #else |
a7627de5ef66
(PTR_TO_OFFSET): Alternate definition if not `emacs'.
Richard Stallman <rms@gnu.org>
parents:
1382
diff
changeset
|
43 #define PTR_TO_OFFSET(d) 0 |
a7627de5ef66
(PTR_TO_OFFSET): Alternate definition if not `emacs'.
Richard Stallman <rms@gnu.org>
parents:
1382
diff
changeset
|
44 #endif |
939 | 45 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
46 #ifdef HAVE_CONFIG_H |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
47 #include <config.h> |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
48 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
49 |
941 | 50 /* We need this for `regex.h', and perhaps for the Emacs include files. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
51 #include <sys/types.h> |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
52 |
941 | 53 /* This is for other GNU distributions with internationalized messages. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
54 #if HAVE_LIBINTL_H || defined (_LIBC) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
55 # include <libintl.h> |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
56 #else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
57 # define gettext(msgid) (msgid) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
58 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
59 |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
60 #ifndef gettext_noop |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
61 /* This define is so xgettext can find the internationalizable |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
62 strings. */ |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
63 #define gettext_noop(String) String |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
64 #endif |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
65 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
66 /* The `emacs' switch turns on certain matching commands |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
67 that make sense only in Emacs. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
68 #ifdef emacs |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
69 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
70 #include "lisp.h" |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
71 #include "buffer.h" |
939 | 72 |
73 /* Make syntax table lookup grant data in gl_state. */ | |
74 #define SYNTAX_ENTRY_VIA_PROPERTY | |
75 | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
76 #include "syntax.h" |
939 | 77 #include "charset.h" |
78 #include "category.h" | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
79 |
786
c9e346539fc6
[emacs] (malloc, free): Define as xmalloc, and xfree.
Richard Stallman <rms@gnu.org>
parents:
692
diff
changeset
|
80 #define malloc xmalloc |
1326
bf0e53366c55
(realloc) <emacs>: Define to xrealloc.
Andreas Schwab <schwab@suse.de>
parents:
1321
diff
changeset
|
81 #define realloc xrealloc |
786
c9e346539fc6
[emacs] (malloc, free): Define as xmalloc, and xfree.
Richard Stallman <rms@gnu.org>
parents:
692
diff
changeset
|
82 #define free xfree |
c9e346539fc6
[emacs] (malloc, free): Define as xmalloc, and xfree.
Richard Stallman <rms@gnu.org>
parents:
692
diff
changeset
|
83 |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
84 #define RE_STRING_CHAR(p, s) \ |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
85 (multibyte ? (STRING_CHAR (p, s)) : (*(p))) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
86 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
87 #else /* not emacs */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
88 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
89 /* If we are not linking with Emacs proper, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
90 we can't use the relocating allocator |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
91 even if config.h says that we can. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
92 #undef REL_ALLOC |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
93 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
94 #if defined (STDC_HEADERS) || defined (_LIBC) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
95 #include <stdlib.h> |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
96 #else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
97 char *malloc (); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
98 char *realloc (); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
99 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
100 |
451
b08ce70c8b7c
Undefined INHIBIT_STRING_HEADER when we have no
Karl Heuer <kwzh@gnu.org>
parents:
449
diff
changeset
|
101 /* When used in Emacs's lib-src, we need to get bzero and bcopy somehow. |
941 | 102 If nothing else has been done, use the method below. */ |
451
b08ce70c8b7c
Undefined INHIBIT_STRING_HEADER when we have no
Karl Heuer <kwzh@gnu.org>
parents:
449
diff
changeset
|
103 #ifdef INHIBIT_STRING_HEADER |
b08ce70c8b7c
Undefined INHIBIT_STRING_HEADER when we have no
Karl Heuer <kwzh@gnu.org>
parents:
449
diff
changeset
|
104 #if !(defined (HAVE_BZERO) && defined (HAVE_BCOPY)) |
b08ce70c8b7c
Undefined INHIBIT_STRING_HEADER when we have no
Karl Heuer <kwzh@gnu.org>
parents:
449
diff
changeset
|
105 #if !defined (bzero) && !defined (bcopy) |
b08ce70c8b7c
Undefined INHIBIT_STRING_HEADER when we have no
Karl Heuer <kwzh@gnu.org>
parents:
449
diff
changeset
|
106 #undef INHIBIT_STRING_HEADER |
b08ce70c8b7c
Undefined INHIBIT_STRING_HEADER when we have no
Karl Heuer <kwzh@gnu.org>
parents:
449
diff
changeset
|
107 #endif |
b08ce70c8b7c
Undefined INHIBIT_STRING_HEADER when we have no
Karl Heuer <kwzh@gnu.org>
parents:
449
diff
changeset
|
108 #endif |
b08ce70c8b7c
Undefined INHIBIT_STRING_HEADER when we have no
Karl Heuer <kwzh@gnu.org>
parents:
449
diff
changeset
|
109 #endif |
b08ce70c8b7c
Undefined INHIBIT_STRING_HEADER when we have no
Karl Heuer <kwzh@gnu.org>
parents:
449
diff
changeset
|
110 |
b08ce70c8b7c
Undefined INHIBIT_STRING_HEADER when we have no
Karl Heuer <kwzh@gnu.org>
parents:
449
diff
changeset
|
111 /* This is the normal way of making sure we have a bcopy and a bzero. |
b08ce70c8b7c
Undefined INHIBIT_STRING_HEADER when we have no
Karl Heuer <kwzh@gnu.org>
parents:
449
diff
changeset
|
112 This is used in most programs--a few other programs avoid this |
b08ce70c8b7c
Undefined INHIBIT_STRING_HEADER when we have no
Karl Heuer <kwzh@gnu.org>
parents:
449
diff
changeset
|
113 by defining INHIBIT_STRING_HEADER. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
114 #ifndef INHIBIT_STRING_HEADER |
460
ea133fff5811
Use `defined' to test HAVE_STRING_H and STDC_HEADERS.
Richard Stallman <rms@gnu.org>
parents:
451
diff
changeset
|
115 #if defined (HAVE_STRING_H) || defined (STDC_HEADERS) || defined (_LIBC) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
116 #include <string.h> |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
117 #ifndef bcmp |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
118 #define bcmp(s1, s2, n) memcmp ((s1), (s2), (n)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
119 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
120 #ifndef bcopy |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
121 #define bcopy(s, d, n) memcpy ((d), (s), (n)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
122 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
123 #ifndef bzero |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
124 #define bzero(s, n) memset ((s), 0, (n)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
125 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
126 #else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
127 #include <strings.h> |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
128 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
129 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
130 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
131 /* Define the syntax stuff for \<, \>, etc. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
132 |
2359
dbf725277cfc
(enum syntaxcode): Provide default for non-Emacs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2357
diff
changeset
|
133 /* Sword must be nonzero for the wordchar pattern commands in re_match_2. */ |
dbf725277cfc
(enum syntaxcode): Provide default for non-Emacs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2357
diff
changeset
|
134 enum syntaxcode { Swhitespace = 0, Sword = 1 }; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
135 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
136 #ifdef SWITCH_ENUM_BUG |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
137 #define SWITCH_ENUM_CAST(x) ((int)(x)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
138 #else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
139 #define SWITCH_ENUM_CAST(x) (x) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
140 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
141 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
142 #ifdef SYNTAX_TABLE |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
143 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
144 extern char *re_syntax_table; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
145 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
146 #else /* not SYNTAX_TABLE */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
147 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
148 /* How many characters in the character set. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
149 #define CHAR_SET_SIZE 256 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
150 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
151 static char re_syntax_table[CHAR_SET_SIZE]; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
152 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
153 static void |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
154 init_syntax_once () |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
155 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
156 register int c; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
157 static int done = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
158 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
159 if (done) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
160 return; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
161 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
162 bzero (re_syntax_table, sizeof re_syntax_table); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
163 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
164 for (c = 'a'; c <= 'z'; c++) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
165 re_syntax_table[c] = Sword; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
166 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
167 for (c = 'A'; c <= 'Z'; c++) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
168 re_syntax_table[c] = Sword; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
169 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
170 for (c = '0'; c <= '9'; c++) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
171 re_syntax_table[c] = Sword; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
172 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
173 re_syntax_table['_'] = Sword; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
174 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
175 done = 1; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
176 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
177 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
178 #endif /* not SYNTAX_TABLE */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
179 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
180 #define SYNTAX(c) re_syntax_table[c] |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
181 |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
182 /* Dummy macros for non-Emacs environments. */ |
939 | 183 #define BASE_LEADING_CODE_P(c) (0) |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
184 #define CHAR_CHARSET(c) 0 |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
185 #define CHARSET_LEADING_CODE_BASE(c) 0 |
939 | 186 #define WORD_BOUNDARY_P(c1, c2) (0) |
187 #define CHAR_HEAD_P(p) (1) | |
188 #define SINGLE_BYTE_CHAR_P(c) (1) | |
189 #define SAME_CHARSET_P(c1, c2) (1) | |
190 #define MULTIBYTE_FORM_LENGTH(p, s) (1) | |
191 #define STRING_CHAR(p, s) (*(p)) | |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
192 #define RE_STRING_CHAR STRING_CHAR |
939 | 193 #define STRING_CHAR_AND_LENGTH(p, s, actual_len) ((actual_len) = 1, *(p)) |
194 #define GET_CHAR_BEFORE_2(c, p, str1, end1, str2, end2) \ | |
195 (c = ((p) == (str2) ? *((end1) - 1) : *((p) - 1))) | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
196 #endif /* not emacs */ |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
197 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
198 #ifndef RE_TRANSLATE |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
199 #define RE_TRANSLATE(TBL, C) ((unsigned char)(TBL)[C]) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
200 #define RE_TRANSLATE_P(TBL) (TBL) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
201 #endif |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
202 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
203 /* Get the interface, including the syntax bits. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
204 #include "regex.h" |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
205 |
1965
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
206 /* isalpha etc. are used for the character classes. */ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
207 #include <ctype.h> |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
208 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
209 #ifdef emacs |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
210 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
211 /* 1 if C is an ASCII character. */ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
212 #define IS_REAL_ASCII(c) ((c) < 0200) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
213 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
214 /* 1 if C is a unibyte character. */ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
215 #define ISUNIBYTE(c) (SINGLE_BYTE_CHAR_P ((c))) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
216 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
217 /* The Emacs definitions should not be directly affected by locales. */ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
218 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
219 /* In Emacs, these are only used for single-byte characters. */ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
220 #define ISDIGIT(c) ((c) >= '0' && (c) <= '9') |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
221 #define ISCNTRL(c) ((c) < ' ') |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
222 #define ISXDIGIT(c) (((c) >= '0' && (c) <= '9') \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
223 || ((c) >= 'a' && (c) <= 'f') \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
224 || ((c) >= 'A' && (c) <= 'F')) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
225 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
226 /* This is only used for single-byte characters. */ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
227 #define ISBLANK(c) ((c) == ' ' || (c) == '\t') |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
228 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
229 /* The rest must handle multibyte characters. */ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
230 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
231 #define ISGRAPH(c) (SINGLE_BYTE_CHAR_P (c) \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
232 ? (c) > ' ' && !((c) >= 0177 && (c) <= 0237) \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
233 : 1) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
234 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
235 #define ISPRINT(c) (SINGLE_BYTE_CHAR_P (c) \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
236 ? (c) >= ' ' && !((c) >= 0177 && (c) <= 0237) \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
237 : 1) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
238 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
239 #define ISALNUM(c) (IS_REAL_ASCII (c) \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
240 ? (((c) >= 'a' && (c) <= 'z') \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
241 || ((c) >= 'A' && (c) <= 'Z') \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
242 || ((c) >= '0' && (c) <= '9')) \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
243 : SYNTAX (c) == Sword) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
244 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
245 #define ISALPHA(c) (IS_REAL_ASCII (c) \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
246 ? (((c) >= 'a' && (c) <= 'z') \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
247 || ((c) >= 'A' && (c) <= 'Z')) \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
248 : SYNTAX (c) == Sword) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
249 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
250 #define ISLOWER(c) (LOWERCASEP (c)) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
251 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
252 #define ISPUNCT(c) (IS_REAL_ASCII (c) \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
253 ? ((c) > ' ' && (c) < 0177 \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
254 && !(((c) >= 'a' && (c) <= 'z') \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
255 || ((c) >= 'A' && (c) <= 'Z') \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
256 || ((c) >= '0' && (c) <= '9'))) \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
257 : SYNTAX (c) != Sword) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
258 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
259 #define ISSPACE(c) (SYNTAX (c) == Swhitespace) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
260 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
261 #define ISUPPER(c) (UPPERCASEP (c)) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
262 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
263 #define ISWORD(c) (SYNTAX (c) == Sword) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
264 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
265 #else /* not emacs */ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
266 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
267 /* Jim Meyering writes: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
268 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
269 "... Some ctype macros are valid only for character codes that |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
270 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
271 using /bin/cc or gcc but without giving an ansi option). So, all |
941 | 272 ctype uses should be through macros like ISPRINT... If |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
273 STDC_HEADERS is defined, then autoconf has verified that the ctype |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
274 macros don't need to be guarded with references to isascii. ... |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
275 Defining isascii to 1 should let any compiler worth its salt |
941 | 276 eliminate the && through constant folding." */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
277 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
278 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
279 #define ISASCII(c) 1 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
280 #else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
281 #define ISASCII(c) isascii(c) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
282 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
283 |
1965
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
284 /* 1 if C is an ASCII character. */ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
285 #define IS_REAL_ASCII(c) ((c) < 0200) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
286 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
287 /* This distinction is not meaningful, except in Emacs. */ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
288 #define ISUNIBYTE(c) 1 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
289 |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
290 #define ISDIGIT(c) (ISASCII (c) && isdigit (c)) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
291 #define ISCNTRL(c) (ISASCII (c) && iscntrl (c)) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
292 #define ISXDIGIT(c) (ISASCII (c) && isxdigit (c)) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
293 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
294 #ifdef isblank |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
295 #define ISBLANK(c) (ISASCII (c) && isblank (c)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
296 #else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
297 #define ISBLANK(c) ((c) == ' ' || (c) == '\t') |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
298 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
299 #ifdef isgraph |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
300 #define ISGRAPH(c) (ISASCII (c) && isgraph (c)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
301 #else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
302 #define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
303 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
304 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
305 #define ISPRINT(c) (ISASCII (c) && isprint (c)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
306 #define ISDIGIT(c) (ISASCII (c) && isdigit (c)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
307 #define ISALNUM(c) (ISASCII (c) && isalnum (c)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
308 #define ISALPHA(c) (ISASCII (c) && isalpha (c)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
309 #define ISCNTRL(c) (ISASCII (c) && iscntrl (c)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
310 #define ISLOWER(c) (ISASCII (c) && islower (c)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
311 #define ISPUNCT(c) (ISASCII (c) && ispunct (c)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
312 #define ISSPACE(c) (ISASCII (c) && isspace (c)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
313 #define ISUPPER(c) (ISASCII (c) && isupper (c)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
314 #define ISXDIGIT(c) (ISASCII (c) && isxdigit (c)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
315 |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
316 #define ISWORD(c) ISALPHA(c) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
317 |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
318 #endif /* not emacs */ |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
319 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
320 #ifndef NULL |
447 | 321 #define NULL (void *)0 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
322 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
323 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
324 /* We remove any previous definition of `SIGN_EXTEND_CHAR', |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
325 since ours (we hope) works properly with all combinations of |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
326 machines, compilers, `char' and `unsigned char' argument types. |
941 | 327 (Per Bothner suggested the basic approach.) */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
328 #undef SIGN_EXTEND_CHAR |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
329 #if __STDC__ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
330 #define SIGN_EXTEND_CHAR(c) ((signed char) (c)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
331 #else /* not __STDC__ */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
332 /* As in Harbison and Steele. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
333 #define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
334 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
335 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
336 /* Should we use malloc or alloca? If REGEX_MALLOC is not defined, we |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
337 use `alloca' instead of `malloc'. This is because using malloc in |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
338 re_search* or re_match* could cause memory leaks when C-g is used in |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
339 Emacs; also, malloc is slower and causes storage fragmentation. On |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
340 the other hand, malloc is more portable, and easier to debug. |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
341 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
342 Because we sometimes use alloca, some routines have to be macros, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
343 not functions -- `alloca'-allocated space disappears at the end of the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
344 function it is called in. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
345 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
346 #ifdef REGEX_MALLOC |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
347 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
348 #define REGEX_ALLOCATE malloc |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
349 #define REGEX_REALLOCATE(source, osize, nsize) realloc (source, nsize) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
350 #define REGEX_FREE free |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
351 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
352 #else /* not REGEX_MALLOC */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
353 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
354 /* Emacs already defines alloca, sometimes. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
355 #ifndef alloca |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
356 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
357 /* Make alloca work the best possible way. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
358 #ifdef __GNUC__ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
359 #define alloca __builtin_alloca |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
360 #else /* not __GNUC__ */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
361 #if HAVE_ALLOCA_H |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
362 #include <alloca.h> |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
363 #else /* not __GNUC__ or HAVE_ALLOCA_H */ |
503 | 364 #if 0 /* It is a bad idea to declare alloca. We always cast the result. */ |
941 | 365 #ifndef _AIX /* Already did AIX, up at the top. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
366 char *alloca (); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
367 #endif /* not _AIX */ |
503 | 368 #endif |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
369 #endif /* not HAVE_ALLOCA_H */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
370 #endif /* not __GNUC__ */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
371 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
372 #endif /* not alloca */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
373 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
374 #define REGEX_ALLOCATE alloca |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
375 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
376 /* Assumes a `char *destination' variable. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
377 #define REGEX_REALLOCATE(source, osize, nsize) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
378 (destination = (char *) alloca (nsize), \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
379 bcopy (source, destination, osize), \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
380 destination) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
381 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
382 /* No need to do anything to free, after alloca. */ |
442
a7b85a203afa
[REGEX_FREE]: Use ((void)0) instead of just (0).
Jim Meyering <jim@meyering.net>
parents:
441
diff
changeset
|
383 #define REGEX_FREE(arg) ((void)0) /* Do nothing! But inhibit gcc warning. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
384 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
385 #endif /* not REGEX_MALLOC */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
386 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
387 /* Define how to allocate the failure stack. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
388 |
463 | 389 #if defined (REL_ALLOC) && defined (REGEX_MALLOC) |
462
115ffc5a3b13
Don't use relocatable allocator.
Richard Stallman <rms@gnu.org>
parents:
460
diff
changeset
|
390 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
391 #define REGEX_ALLOCATE_STACK(size) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
392 r_alloc (&failure_stack_ptr, (size)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
393 #define REGEX_REALLOCATE_STACK(source, osize, nsize) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
394 r_re_alloc (&failure_stack_ptr, (nsize)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
395 #define REGEX_FREE_STACK(ptr) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
396 r_alloc_free (&failure_stack_ptr) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
397 |
462
115ffc5a3b13
Don't use relocatable allocator.
Richard Stallman <rms@gnu.org>
parents:
460
diff
changeset
|
398 #else /* not using relocating allocator */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
399 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
400 #ifdef REGEX_MALLOC |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
401 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
402 #define REGEX_ALLOCATE_STACK malloc |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
403 #define REGEX_REALLOCATE_STACK(source, osize, nsize) realloc (source, nsize) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
404 #define REGEX_FREE_STACK free |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
405 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
406 #else /* not REGEX_MALLOC */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
407 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
408 #define REGEX_ALLOCATE_STACK alloca |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
409 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
410 #define REGEX_REALLOCATE_STACK(source, osize, nsize) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
411 REGEX_REALLOCATE (source, osize, nsize) |
941 | 412 /* No need to explicitly free anything. */ |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
413 #define REGEX_FREE_STACK(arg) ((void)0) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
414 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
415 #endif /* not REGEX_MALLOC */ |
462
115ffc5a3b13
Don't use relocatable allocator.
Richard Stallman <rms@gnu.org>
parents:
460
diff
changeset
|
416 #endif /* not using relocating allocator */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
417 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
418 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
419 /* True if `size1' is non-NULL and PTR is pointing anywhere inside |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
420 `string1' or just past its end. This works if PTR is NULL, which is |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
421 a good thing. */ |
941 | 422 #define FIRST_STRING_P(ptr) \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
423 (size1 && string1 <= (ptr) && (ptr) <= string1 + size1) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
424 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
425 /* (Re)Allocate N items of type T using malloc, or fail. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
426 #define TALLOC(n, t) ((t *) malloc ((n) * sizeof (t))) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
427 #define RETALLOC(addr, n, t) ((addr) = (t *) realloc (addr, (n) * sizeof (t))) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
428 #define RETALLOC_IF(addr, n, t) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
429 if (addr) RETALLOC((addr), (n), t); else (addr) = TALLOC ((n), t) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
430 #define REGEX_TALLOC(n, t) ((t *) REGEX_ALLOCATE ((n) * sizeof (t))) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
431 |
941 | 432 #define BYTEWIDTH 8 /* In bits. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
433 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
434 #define STREQ(s1, s2) ((strcmp (s1, s2) == 0)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
435 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
436 #undef MAX |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
437 #undef MIN |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
438 #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
439 #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
440 |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
441 /* Type of source-pattern and string chars. */ |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
442 typedef const unsigned char re_char; |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
443 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
444 typedef char boolean; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
445 #define false 0 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
446 #define true 1 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
447 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
448 static int re_match_2_internal (); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
449 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
450 /* These are the command codes that appear in compiled regular |
941 | 451 expressions. Some opcodes are followed by argument bytes. A |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
452 command code can specify any interpretation whatsoever for its |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
453 arguments. Zero bytes may appear in the compiled regular expression. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
454 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
455 typedef enum |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
456 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
457 no_op = 0, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
458 |
941 | 459 /* Succeed right away--no more backtracking. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
460 succeed, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
461 |
941 | 462 /* Followed by one byte giving n, then by n literal bytes. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
463 exactn, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
464 |
941 | 465 /* Matches any (more or less) character. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
466 anychar, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
467 |
941 | 468 /* Matches any one char belonging to specified set. First |
469 following byte is number of bitmap bytes. Then come bytes | |
470 for a bitmap saying which chars are in. Bits in each byte | |
471 are ordered low-bit-first. A character is in the set if its | |
472 bit is 1. A character too large to have a bit in the map is | |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
473 automatically not in the set. |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
474 |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
475 If the length byte has the 0x80 bit set, then that stuff |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
476 is followed by a range table: |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
477 2 bytes of flags for character sets (low 8 bits, high 8 bits) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
478 See RANGE_TABLE_WORK_BITS below. |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
479 2 bytes, the number of pairs that follow |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
480 pairs, each 2 multibyte characters, |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
481 each multibyte character represented as 3 bytes. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
482 charset, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
483 |
941 | 484 /* Same parameters as charset, but match any character that is |
485 not one of those specified. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
486 charset_not, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
487 |
941 | 488 /* Start remembering the text that is matched, for storing in a |
489 register. Followed by one byte with the register number, in | |
490 the range 0 to one less than the pattern buffer's re_nsub | |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
491 field. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
492 start_memory, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
493 |
941 | 494 /* Stop remembering the text that is matched and store it in a |
495 memory register. Followed by one byte with the register | |
496 number, in the range 0 to one less than `re_nsub' in the | |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
497 pattern buffer. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
498 stop_memory, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
499 |
941 | 500 /* Match a duplicate of something remembered. Followed by one |
501 byte containing the register number. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
502 duplicate, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
503 |
941 | 504 /* Fail unless at beginning of line. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
505 begline, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
506 |
941 | 507 /* Fail unless at end of line. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
508 endline, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
509 |
941 | 510 /* Succeeds if at beginning of buffer (if emacs) or at beginning |
511 of string to be matched (if not). */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
512 begbuf, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
513 |
941 | 514 /* Analogously, for end of buffer/string. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
515 endbuf, |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
516 |
941 | 517 /* Followed by two byte relative address to which to jump. */ |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
518 jump, |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
519 |
941 | 520 /* Followed by two-byte relative address of place to resume at |
521 in case of failure. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
522 on_failure_jump, |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
523 |
941 | 524 /* Like on_failure_jump, but pushes a placeholder instead of the |
525 current string position when executed. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
526 on_failure_keep_string_jump, |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
527 |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
528 /* Just like `on_failure_jump', except that it checks that we |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
529 don't get stuck in an infinite loop (matching an empty string |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
530 indefinitely). */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
531 on_failure_jump_loop, |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
532 |
2370
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
533 /* Just like `on_failure_jump_loop', except that it checks for |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
534 a different kind of loop (the kind that shows up with non-greedy |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
535 operators). This operation has to be immediately preceded |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
536 by a `no_op'. */ |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
537 on_failure_jump_nastyloop, |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
538 |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
539 /* A smart `on_failure_jump' used for greedy * and + operators. |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
540 It analyses the loop before which it is put and if the |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
541 loop does not require backtracking, it changes itself to |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
542 `on_failure_keep_string_jump' and short-circuits the loop, |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
543 else it just defaults to changing itself into `on_failure_jump'. |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
544 It assumes that it is pointing to just past a `jump'. */ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
545 on_failure_jump_smart, |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
546 |
941 | 547 /* Followed by two-byte relative address and two-byte number n. |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
548 After matching N times, jump to the address upon failure. |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
549 Does not work if N starts at 0: use on_failure_jump_loop |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
550 instead. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
551 succeed_n, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
552 |
941 | 553 /* Followed by two-byte relative address, and two-byte number n. |
554 Jump to the address N times, then fail. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
555 jump_n, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
556 |
941 | 557 /* Set the following two-byte relative address to the |
558 subsequent two-byte number. The address *includes* the two | |
559 bytes of number. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
560 set_number_at, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
561 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
562 wordbeg, /* Succeeds if at word beginning. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
563 wordend, /* Succeeds if at word end. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
564 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
565 wordbound, /* Succeeds if at a word boundary. */ |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
566 notwordbound, /* Succeeds if not at a word boundary. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
567 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
568 /* Matches any character whose syntax is specified. Followed by |
941 | 569 a byte which contains a syntax code, e.g., Sword. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
570 syntaxspec, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
571 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
572 /* Matches any character whose syntax is not that specified. */ |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
573 notsyntaxspec |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
574 |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
575 #ifdef emacs |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
576 ,before_dot, /* Succeeds if before point. */ |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
577 at_dot, /* Succeeds if at point. */ |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
578 after_dot, /* Succeeds if after point. */ |
939 | 579 |
580 /* Matches any character whose category-set contains the specified | |
941 | 581 category. The operator is followed by a byte which contains a |
582 category code (mnemonic ASCII character). */ | |
939 | 583 categoryspec, |
584 | |
585 /* Matches any character whose category-set does not contain the | |
586 specified category. The operator is followed by a byte which | |
587 contains the category code (mnemonic ASCII character). */ | |
588 notcategoryspec | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
589 #endif /* emacs */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
590 } re_opcode_t; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
591 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
592 /* Common operations on the compiled pattern. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
593 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
594 /* Store NUMBER in two contiguous bytes starting at DESTINATION. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
595 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
596 #define STORE_NUMBER(destination, number) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
597 do { \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
598 (destination)[0] = (number) & 0377; \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
599 (destination)[1] = (number) >> 8; \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
600 } while (0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
601 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
602 /* Same as STORE_NUMBER, except increment DESTINATION to |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
603 the byte after where the number is stored. Therefore, DESTINATION |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
604 must be an lvalue. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
605 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
606 #define STORE_NUMBER_AND_INCR(destination, number) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
607 do { \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
608 STORE_NUMBER (destination, number); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
609 (destination) += 2; \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
610 } while (0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
611 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
612 /* Put into DESTINATION a number stored in two contiguous bytes starting |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
613 at SOURCE. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
614 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
615 #define EXTRACT_NUMBER(destination, source) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
616 do { \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
617 (destination) = *(source) & 0377; \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
618 (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
619 } while (0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
620 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
621 #ifdef DEBUG |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
622 static void |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
623 extract_number (dest, source) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
624 int *dest; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
625 unsigned char *source; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
626 { |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
627 int temp = SIGN_EXTEND_CHAR (*(source + 1)); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
628 *dest = *source & 0377; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
629 *dest += temp << 8; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
630 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
631 |
941 | 632 #ifndef EXTRACT_MACROS /* To debug the macros. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
633 #undef EXTRACT_NUMBER |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
634 #define EXTRACT_NUMBER(dest, src) extract_number (&dest, src) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
635 #endif /* not EXTRACT_MACROS */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
636 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
637 #endif /* DEBUG */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
638 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
639 /* Same as EXTRACT_NUMBER, except increment SOURCE to after the number. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
640 SOURCE must be an lvalue. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
641 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
642 #define EXTRACT_NUMBER_AND_INCR(destination, source) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
643 do { \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
644 EXTRACT_NUMBER (destination, source); \ |
941 | 645 (source) += 2; \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
646 } while (0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
647 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
648 #ifdef DEBUG |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
649 static void |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
650 extract_number_and_incr (destination, source) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
651 int *destination; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
652 unsigned char **source; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
653 { |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
654 extract_number (destination, *source); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
655 *source += 2; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
656 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
657 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
658 #ifndef EXTRACT_MACROS |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
659 #undef EXTRACT_NUMBER_AND_INCR |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
660 #define EXTRACT_NUMBER_AND_INCR(dest, src) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
661 extract_number_and_incr (&dest, &src) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
662 #endif /* not EXTRACT_MACROS */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
663 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
664 #endif /* DEBUG */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
665 |
939 | 666 /* Store a multibyte character in three contiguous bytes starting |
667 DESTINATION, and increment DESTINATION to the byte after where the | |
941 | 668 character is stored. Therefore, DESTINATION must be an lvalue. */ |
939 | 669 |
670 #define STORE_CHARACTER_AND_INCR(destination, character) \ | |
671 do { \ | |
672 (destination)[0] = (character) & 0377; \ | |
673 (destination)[1] = ((character) >> 8) & 0377; \ | |
674 (destination)[2] = (character) >> 16; \ | |
675 (destination) += 3; \ | |
676 } while (0) | |
677 | |
678 /* Put into DESTINATION a character stored in three contiguous bytes | |
941 | 679 starting at SOURCE. */ |
939 | 680 |
681 #define EXTRACT_CHARACTER(destination, source) \ | |
682 do { \ | |
683 (destination) = ((source)[0] \ | |
684 | ((source)[1] << 8) \ | |
685 | ((source)[2] << 16)); \ | |
686 } while (0) | |
687 | |
688 | |
689 /* Macros for charset. */ | |
690 | |
691 /* Size of bitmap of charset P in bytes. P is a start of charset, | |
692 i.e. *P is (re_opcode_t) charset or (re_opcode_t) charset_not. */ | |
693 #define CHARSET_BITMAP_SIZE(p) ((p)[1] & 0x7F) | |
694 | |
695 /* Nonzero if charset P has range table. */ | |
941 | 696 #define CHARSET_RANGE_TABLE_EXISTS_P(p) ((p)[1] & 0x80) |
939 | 697 |
698 /* Return the address of range table of charset P. But not the start | |
699 of table itself, but the before where the number of ranges is | |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
700 stored. `2 +' means to skip re_opcode_t and size of bitmap, |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
701 and the 2 bytes of flags at the start of the range table. */ |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
702 #define CHARSET_RANGE_TABLE(p) (&(p)[4 + CHARSET_BITMAP_SIZE (p)]) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
703 |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
704 /* Extract the bit flags that start a range table. */ |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
705 #define CHARSET_RANGE_TABLE_BITS(p) \ |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
706 ((p)[2 + CHARSET_BITMAP_SIZE (p)] \ |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
707 + (p)[3 + CHARSET_BITMAP_SIZE (p)] * 0x100) |
939 | 708 |
709 /* Test if C is listed in the bitmap of charset P. */ | |
710 #define CHARSET_LOOKUP_BITMAP(p, c) \ | |
711 ((c) < CHARSET_BITMAP_SIZE (p) * BYTEWIDTH \ | |
712 && (p)[2 + (c) / BYTEWIDTH] & (1 << ((c) % BYTEWIDTH))) | |
713 | |
714 /* Return the address of end of RANGE_TABLE. COUNT is number of | |
941 | 715 ranges (which is a pair of (start, end)) in the RANGE_TABLE. `* 2' |
716 is start of range and end of range. `* 3' is size of each start | |
939 | 717 and end. */ |
718 #define CHARSET_RANGE_TABLE_END(range_table, count) \ | |
719 ((range_table) + (count) * 2 * 3) | |
720 | |
941 | 721 /* Test if C is in RANGE_TABLE. A flag NOT is negated if C is in. |
939 | 722 COUNT is number of ranges in RANGE_TABLE. */ |
723 #define CHARSET_LOOKUP_RANGE_TABLE_RAW(not, c, range_table, count) \ | |
724 do \ | |
725 { \ | |
726 int range_start, range_end; \ | |
727 unsigned char *p; \ | |
728 unsigned char *range_table_end \ | |
729 = CHARSET_RANGE_TABLE_END ((range_table), (count)); \ | |
730 \ | |
731 for (p = (range_table); p < range_table_end; p += 2 * 3) \ | |
732 { \ | |
733 EXTRACT_CHARACTER (range_start, p); \ | |
734 EXTRACT_CHARACTER (range_end, p + 3); \ | |
735 \ | |
736 if (range_start <= (c) && (c) <= range_end) \ | |
737 { \ | |
738 (not) = !(not); \ | |
739 break; \ | |
740 } \ | |
741 } \ | |
742 } \ | |
743 while (0) | |
744 | |
745 /* Test if C is in range table of CHARSET. The flag NOT is negated if | |
746 C is listed in it. */ | |
747 #define CHARSET_LOOKUP_RANGE_TABLE(not, c, charset) \ | |
748 do \ | |
749 { \ | |
750 /* Number of ranges in range table. */ \ | |
751 int count; \ | |
752 unsigned char *range_table = CHARSET_RANGE_TABLE (charset); \ | |
753 \ | |
754 EXTRACT_NUMBER_AND_INCR (count, range_table); \ | |
755 CHARSET_LOOKUP_RANGE_TABLE_RAW ((not), (c), range_table, count); \ | |
756 } \ | |
757 while (0) | |
758 | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
759 /* If DEBUG is defined, Regex prints many voluminous messages about what |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
760 it is doing (if the variable `debug' is nonzero). If linked with the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
761 main program in `iregex.c', you can enter patterns and strings |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
762 interactively. And if linked with the main program in `main.c' and |
941 | 763 the other test files, you can run the already-written tests. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
764 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
765 #ifdef DEBUG |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
766 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
767 /* We use standard I/O for debugging. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
768 #include <stdio.h> |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
769 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
770 /* It is useful to test things that ``must'' be true when debugging. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
771 #include <assert.h> |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
772 |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
773 static int debug = -100000; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
774 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
775 #define DEBUG_STATEMENT(e) e |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
776 #define DEBUG_PRINT1(x) if (debug > 0) printf (x) |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
777 #define DEBUG_PRINT2(x1, x2) if (debug > 0) printf (x1, x2) |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
778 #define DEBUG_PRINT3(x1, x2, x3) if (debug > 0) printf (x1, x2, x3) |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
779 #define DEBUG_PRINT4(x1, x2, x3, x4) if (debug > 0) printf (x1, x2, x3, x4) |
941 | 780 #define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \ |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
781 if (debug > 0) print_partial_compiled_pattern (s, e) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
782 #define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \ |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
783 if (debug > 0) print_double_string (w, s1, sz1, s2, sz2) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
784 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
785 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
786 /* Print the fastmap in human-readable form. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
787 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
788 void |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
789 print_fastmap (fastmap) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
790 char *fastmap; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
791 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
792 unsigned was_a_range = 0; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
793 unsigned i = 0; |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
794 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
795 while (i < (1 << BYTEWIDTH)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
796 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
797 if (fastmap[i++]) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
798 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
799 was_a_range = 0; |
941 | 800 putchar (i - 1); |
801 while (i < (1 << BYTEWIDTH) && fastmap[i]) | |
802 { | |
803 was_a_range = 1; | |
804 i++; | |
805 } | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
806 if (was_a_range) |
941 | 807 { |
808 printf ("-"); | |
809 putchar (i - 1); | |
810 } | |
811 } | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
812 } |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
813 putchar ('\n'); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
814 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
815 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
816 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
817 /* Print a compiled pattern string in human-readable form, starting at |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
818 the START pointer into it and ending just before the pointer END. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
819 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
820 void |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
821 print_partial_compiled_pattern (start, end) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
822 unsigned char *start; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
823 unsigned char *end; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
824 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
825 int mcnt, mcnt2; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
826 unsigned char *p = start; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
827 unsigned char *pend = end; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
828 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
829 if (start == NULL) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
830 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
831 printf ("(null)\n"); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
832 return; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
833 } |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
834 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
835 /* Loop over pattern commands. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
836 while (p < pend) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
837 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
838 printf ("%d:\t", p - start); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
839 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
840 switch ((re_opcode_t) *p++) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
841 { |
941 | 842 case no_op: |
843 printf ("/no_op"); | |
844 break; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
845 |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
846 case succeed: |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
847 printf ("/succeed"); |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
848 break; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
849 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
850 case exactn: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
851 mcnt = *p++; |
941 | 852 printf ("/exactn/%d", mcnt); |
853 do | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
854 { |
941 | 855 putchar ('/'); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
856 putchar (*p++); |
941 | 857 } |
858 while (--mcnt); | |
859 break; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
860 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
861 case start_memory: |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
862 printf ("/start_memory/%d", *p++); |
941 | 863 break; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
864 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
865 case stop_memory: |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
866 printf ("/stop_memory/%d", *p++); |
941 | 867 break; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
868 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
869 case duplicate: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
870 printf ("/duplicate/%d", *p++); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
871 break; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
872 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
873 case anychar: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
874 printf ("/anychar"); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
875 break; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
876 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
877 case charset: |
941 | 878 case charset_not: |
879 { | |
880 register int c, last = -100; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
881 register int in_range = 0; |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
882 int length = CHARSET_BITMAP_SIZE (p - 1); |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
883 int has_range_table = CHARSET_RANGE_TABLE_EXISTS_P (p - 1); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
884 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
885 printf ("/charset [%s", |
941 | 886 (re_opcode_t) *(p - 1) == charset_not ? "^" : ""); |
887 | |
888 assert (p + *p < pend); | |
889 | |
890 for (c = 0; c < 256; c++) | |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
891 if (c / 8 < length |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
892 && (p[1 + (c/8)] & (1 << (c % 8)))) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
893 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
894 /* Are we starting a range? */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
895 if (last + 1 == c && ! in_range) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
896 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
897 putchar ('-'); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
898 in_range = 1; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
899 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
900 /* Have we broken a range? */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
901 else if (last + 1 != c && in_range) |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
902 { |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
903 putchar (last); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
904 in_range = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
905 } |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
906 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
907 if (! in_range) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
908 putchar (c); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
909 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
910 last = c; |
941 | 911 } |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
912 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
913 if (in_range) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
914 putchar (last); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
915 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
916 putchar (']'); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
917 |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
918 p += 1 + length; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
919 |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
920 if (has_range_table) |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
921 { |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
922 int count; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
923 printf ("has-range-table"); |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
924 |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
925 /* ??? Should print the range table; for now, just skip it. */ |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
926 p += 2; /* skip range table bits */ |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
927 EXTRACT_NUMBER_AND_INCR (count, p); |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
928 p = CHARSET_RANGE_TABLE_END (p, count); |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
929 } |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
930 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
931 break; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
932 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
933 case begline: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
934 printf ("/begline"); |
941 | 935 break; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
936 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
937 case endline: |
941 | 938 printf ("/endline"); |
939 break; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
940 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
941 case on_failure_jump: |
941 | 942 extract_number_and_incr (&mcnt, &p); |
943 printf ("/on_failure_jump to %d", p + mcnt - start); | |
944 break; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
945 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
946 case on_failure_keep_string_jump: |
941 | 947 extract_number_and_incr (&mcnt, &p); |
948 printf ("/on_failure_keep_string_jump to %d", p + mcnt - start); | |
949 break; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
950 |
2370
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
951 case on_failure_jump_nastyloop: |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
952 extract_number_and_incr (&mcnt, &p); |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
953 printf ("/on_failure_jump_nastyloop to %d", p + mcnt - start); |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
954 break; |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
955 |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
956 case on_failure_jump_loop: |
941 | 957 extract_number_and_incr (&mcnt, &p); |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
958 printf ("/on_failure_jump_loop to %d", p + mcnt - start); |
941 | 959 break; |
960 | |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
961 case on_failure_jump_smart: |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
962 extract_number_and_incr (&mcnt, &p); |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
963 printf ("/on_failure_jump_smart to %d", p + mcnt - start); |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
964 break; |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
965 |
941 | 966 case jump: |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
967 extract_number_and_incr (&mcnt, &p); |
941 | 968 printf ("/jump to %d", p + mcnt - start); |
679 | 969 break; |
970 | |
941 | 971 case succeed_n: |
972 extract_number_and_incr (&mcnt, &p); | |
973 extract_number_and_incr (&mcnt2, &p); | |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
974 printf ("/succeed_n to %d, %d times", p - 2 + mcnt - start, mcnt2); |
941 | 975 break; |
976 | |
977 case jump_n: | |
978 extract_number_and_incr (&mcnt, &p); | |
979 extract_number_and_incr (&mcnt2, &p); | |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
980 printf ("/jump_n to %d, %d times", p - 2 + mcnt - start, mcnt2); |
941 | 981 break; |
982 | |
983 case set_number_at: | |
984 extract_number_and_incr (&mcnt, &p); | |
985 extract_number_and_incr (&mcnt2, &p); | |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
986 printf ("/set_number_at location %d to %d", p - 2 + mcnt - start, mcnt2); |
941 | 987 break; |
988 | |
989 case wordbound: | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
990 printf ("/wordbound"); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
991 break; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
992 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
993 case notwordbound: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
994 printf ("/notwordbound"); |
941 | 995 break; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
996 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
997 case wordbeg: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
998 printf ("/wordbeg"); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
999 break; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1000 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1001 case wordend: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1002 printf ("/wordend"); |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1003 |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
1004 case syntaxspec: |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
1005 printf ("/syntaxspec"); |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
1006 mcnt = *p++; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
1007 printf ("/%d", mcnt); |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
1008 break; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
1009 |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
1010 case notsyntaxspec: |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
1011 printf ("/notsyntaxspec"); |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
1012 mcnt = *p++; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
1013 printf ("/%d", mcnt); |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
1014 break; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
1015 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1016 #ifdef emacs |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1017 case before_dot: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1018 printf ("/before_dot"); |
941 | 1019 break; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1020 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1021 case at_dot: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1022 printf ("/at_dot"); |
941 | 1023 break; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1024 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1025 case after_dot: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1026 printf ("/after_dot"); |
941 | 1027 break; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1028 |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
1029 case categoryspec: |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
1030 printf ("/categoryspec"); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1031 mcnt = *p++; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1032 printf ("/%d", mcnt); |
941 | 1033 break; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1034 |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
1035 case notcategoryspec: |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
1036 printf ("/notcategoryspec"); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1037 mcnt = *p++; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1038 printf ("/%d", mcnt); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1039 break; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1040 #endif /* emacs */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1041 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1042 case begbuf: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1043 printf ("/begbuf"); |
941 | 1044 break; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1045 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1046 case endbuf: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1047 printf ("/endbuf"); |
941 | 1048 break; |
1049 | |
1050 default: | |
1051 printf ("?%d", *(p-1)); | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1052 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1053 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1054 putchar ('\n'); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1055 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1056 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1057 printf ("%d:\tend of pattern.\n", p - start); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1058 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1059 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1060 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1061 void |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1062 print_compiled_pattern (bufp) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1063 struct re_pattern_buffer *bufp; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1064 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1065 unsigned char *buffer = bufp->buffer; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1066 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1067 print_partial_compiled_pattern (buffer, buffer + bufp->used); |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1068 printf ("%ld bytes used/%ld bytes allocated.\n", bufp->used, bufp->allocated); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1069 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1070 if (bufp->fastmap_accurate && bufp->fastmap) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1071 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1072 printf ("fastmap: "); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1073 print_fastmap (bufp->fastmap); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1074 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1075 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1076 printf ("re_nsub: %d\t", bufp->re_nsub); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1077 printf ("regs_alloc: %d\t", bufp->regs_allocated); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1078 printf ("can_be_null: %d\t", bufp->can_be_null); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1079 printf ("newline_anchor: %d\n", bufp->newline_anchor); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1080 printf ("no_sub: %d\t", bufp->no_sub); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1081 printf ("not_bol: %d\t", bufp->not_bol); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1082 printf ("not_eol: %d\t", bufp->not_eol); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1083 printf ("syntax: %d\n", bufp->syntax); |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1084 fflush (stdout); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1085 /* Perhaps we should print the translate table? */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1086 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1087 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1088 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1089 void |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1090 print_double_string (where, string1, size1, string2, size2) |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1091 re_char *where; |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1092 re_char *string1; |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1093 re_char *string2; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1094 int size1; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1095 int size2; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1096 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1097 unsigned this_char; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1098 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1099 if (where == NULL) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1100 printf ("(null)"); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1101 else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1102 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1103 if (FIRST_STRING_P (where)) |
941 | 1104 { |
1105 for (this_char = where - string1; this_char < size1; this_char++) | |
1106 putchar (string1[this_char]); | |
1107 | |
1108 where = string2; | |
1109 } | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1110 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1111 for (this_char = where - string2; this_char < size2; this_char++) |
941 | 1112 putchar (string2[this_char]); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1113 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1114 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1115 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1116 #else /* not DEBUG */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1117 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1118 #undef assert |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1119 #define assert(e) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1120 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1121 #define DEBUG_STATEMENT(e) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1122 #define DEBUG_PRINT1(x) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1123 #define DEBUG_PRINT2(x1, x2) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1124 #define DEBUG_PRINT3(x1, x2, x3) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1125 #define DEBUG_PRINT4(x1, x2, x3, x4) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1126 #define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1127 #define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1128 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1129 #endif /* not DEBUG */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1130 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1131 /* Set by `re_set_syntax' to the current regexp syntax to recognize. Can |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1132 also be assigned to arbitrarily: each pattern buffer stores its own |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1133 syntax, so it can be changed between regex compilations. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1134 /* This has no initializer because initialized variables in Emacs |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1135 become read-only after dumping. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1136 reg_syntax_t re_syntax_options; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1137 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1138 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1139 /* Specify the precise syntax of regexps for compilation. This provides |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1140 for compatibility for various utilities which historically have |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1141 different, incompatible syntaxes. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1142 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1143 The argument SYNTAX is a bit mask comprised of the various bits |
941 | 1144 defined in regex.h. We return the old syntax. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1145 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1146 reg_syntax_t |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1147 re_set_syntax (syntax) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1148 reg_syntax_t syntax; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1149 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1150 reg_syntax_t ret = re_syntax_options; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1151 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1152 re_syntax_options = syntax; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1153 return ret; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1154 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1155 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1156 /* This table gives an error message for each of the error codes listed |
941 | 1157 in regex.h. Obviously the order here has to be same as there. |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1158 POSIX doesn't require that we do anything for REG_NOERROR, |
941 | 1159 but why not be nice? */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1160 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1161 static const char *re_error_msgid[] = |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1162 { |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1163 gettext_noop ("Success"), /* REG_NOERROR */ |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1164 gettext_noop ("No match"), /* REG_NOMATCH */ |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1165 gettext_noop ("Invalid regular expression"), /* REG_BADPAT */ |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1166 gettext_noop ("Invalid collation character"), /* REG_ECOLLATE */ |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1167 gettext_noop ("Invalid character class name"), /* REG_ECTYPE */ |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1168 gettext_noop ("Trailing backslash"), /* REG_EESCAPE */ |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1169 gettext_noop ("Invalid back reference"), /* REG_ESUBREG */ |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1170 gettext_noop ("Unmatched [ or [^"), /* REG_EBRACK */ |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1171 gettext_noop ("Unmatched ( or \\("), /* REG_EPAREN */ |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1172 gettext_noop ("Unmatched \\{"), /* REG_EBRACE */ |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1173 gettext_noop ("Invalid content of \\{\\}"), /* REG_BADBR */ |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1174 gettext_noop ("Invalid range end"), /* REG_ERANGE */ |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1175 gettext_noop ("Memory exhausted"), /* REG_ESPACE */ |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1176 gettext_noop ("Invalid preceding regular expression"), /* REG_BADRPT */ |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1177 gettext_noop ("Premature end of regular expression"), /* REG_EEND */ |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1178 gettext_noop ("Regular expression too big"), /* REG_ESIZE */ |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1179 gettext_noop ("Unmatched ) or \\)"), /* REG_ERPAREN */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1180 }; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1181 |
941 | 1182 /* Avoiding alloca during matching, to placate r_alloc. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1183 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1184 /* Define MATCH_MAY_ALLOCATE unless we need to make sure that the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1185 searching and matching functions should not call alloca. On some |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1186 systems, alloca is implemented in terms of malloc, and if we're |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1187 using the relocating allocator routines, then malloc could cause a |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1188 relocation, which might (if the strings being searched are in the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1189 ralloc heap) shift the data out from underneath the regexp |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1190 routines. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1191 |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1192 Here's another reason to avoid allocation: Emacs |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1193 processes input from X in a signal handler; processing X input may |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1194 call malloc; if input arrives while a matching routine is calling |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1195 malloc, then we're scrod. But Emacs can't just block input while |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1196 calling matching routines; then we don't notice interrupts when |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1197 they come in. So, Emacs blocks input around all regexp calls |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1198 except the matching calls, which it leaves unprotected, in the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1199 faith that they will not malloc. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1200 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1201 /* Normally, this is fine. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1202 #define MATCH_MAY_ALLOCATE |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1203 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1204 /* When using GNU C, we are not REALLY using the C alloca, no matter |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1205 what config.h may say. So don't take precautions for it. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1206 #ifdef __GNUC__ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1207 #undef C_ALLOCA |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1208 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1209 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1210 /* The match routines may not allocate if (1) they would do it with malloc |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1211 and (2) it's not safe for them to use malloc. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1212 Note that if REL_ALLOC is defined, matching would not use malloc for the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1213 failure stack, but we would still use it for the register vectors; |
941 | 1214 so REL_ALLOC should not affect this. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1215 #if (defined (C_ALLOCA) || defined (REGEX_MALLOC)) && defined (emacs) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1216 #undef MATCH_MAY_ALLOCATE |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1217 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1218 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1219 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1220 /* Failure stack declarations and macros; both re_compile_fastmap and |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1221 re_match_2 use a failure stack. These have to be macros because of |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1222 REGEX_ALLOCATE_STACK. */ |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1223 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1224 |
1156
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1225 /* Approximate number of failure points for which to initially allocate space |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1226 when matching. If this number is exceeded, we allocate more |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1227 space, so it is not a hard limit. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1228 #ifndef INIT_FAILURE_ALLOC |
1156
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1229 #define INIT_FAILURE_ALLOC 20 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1230 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1231 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1232 /* Roughly the maximum number of failure points on the stack. Would be |
1156
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1233 exactly that if always used TYPICAL_FAILURE_SIZE items each time we failed. |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1234 This is a variable only so users of regex can assign to it; we never |
941 | 1235 change it ourselves. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1236 #if defined (MATCH_MAY_ALLOCATE) |
1156
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1237 /* Note that 4400 is enough to cause a crash on Alpha OSF/1, |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1238 whose default stack limit is 2mb. In order for a larger |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1239 value to work reliably, you have to try to make it accord |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1240 with the process stack limit. */ |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1241 int re_max_failures = 40000; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1242 #else |
1156
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1243 int re_max_failures = 4000; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1244 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1245 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1246 union fail_stack_elt |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1247 { |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1248 const unsigned char *pointer; |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1249 unsigned int integer; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1250 }; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1251 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1252 typedef union fail_stack_elt fail_stack_elt_t; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1253 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1254 typedef struct |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1255 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1256 fail_stack_elt_t *stack; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1257 unsigned size; |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1258 unsigned avail; /* Offset of next open position. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1259 unsigned frame; /* Offset of the cur constructed frame. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1260 } fail_stack_type; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1261 |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1262 #define PATTERN_STACK_EMPTY() (fail_stack.avail == 0) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1263 #define FAIL_STACK_EMPTY() (fail_stack.frame == 0) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1264 #define FAIL_STACK_FULL() (fail_stack.avail == fail_stack.size) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1265 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1266 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1267 /* Define macros to initialize and free the failure stack. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1268 Do `return -2' if the alloc fails. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1269 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1270 #ifdef MATCH_MAY_ALLOCATE |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1271 #define INIT_FAIL_STACK() \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1272 do { \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1273 fail_stack.stack = (fail_stack_elt_t *) \ |
1156
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1274 REGEX_ALLOCATE_STACK (INIT_FAILURE_ALLOC * TYPICAL_FAILURE_SIZE \ |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1275 * sizeof (fail_stack_elt_t)); \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1276 \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1277 if (fail_stack.stack == NULL) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1278 return -2; \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1279 \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1280 fail_stack.size = INIT_FAILURE_ALLOC; \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1281 fail_stack.avail = 0; \ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1282 fail_stack.frame = 0; \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1283 } while (0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1284 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1285 #define RESET_FAIL_STACK() REGEX_FREE_STACK (fail_stack.stack) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1286 #else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1287 #define INIT_FAIL_STACK() \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1288 do { \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1289 fail_stack.avail = 0; \ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1290 fail_stack.frame = 0; \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1291 } while (0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1292 |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
1293 #define RESET_FAIL_STACK() ((void)0) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1294 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1295 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1296 |
1156
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1297 /* Double the size of FAIL_STACK, up to a limit |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1298 which allows approximately `re_max_failures' items. |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1299 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1300 Return 1 if succeeds, and 0 if either ran out of memory |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1301 allocating space for it or it was already too large. |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1302 |
941 | 1303 REGEX_REALLOCATE_STACK requires `destination' be declared. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1304 |
1156
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1305 /* Factor to increase the failure stack size by |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1306 when we increase it. |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1307 This used to be 2, but 2 was too wasteful |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1308 because the old discarded stacks added up to as much space |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1309 were as ultimate, maximum-size stack. */ |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1310 #define FAIL_STACK_GROWTH_FACTOR 4 |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1311 |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1312 #define GROW_FAIL_STACK(fail_stack) \ |
1158
282562802f46
(GROW_FAIL_STACK): Fix test for stack size at max.
Karl Heuer <kwzh@gnu.org>
parents:
1157
diff
changeset
|
1313 (((fail_stack).size * sizeof (fail_stack_elt_t) \ |
282562802f46
(GROW_FAIL_STACK): Fix test for stack size at max.
Karl Heuer <kwzh@gnu.org>
parents:
1157
diff
changeset
|
1314 >= re_max_failures * TYPICAL_FAILURE_SIZE) \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1315 ? 0 \ |
1156
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1316 : ((fail_stack).stack \ |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1317 = (fail_stack_elt_t *) \ |
941 | 1318 REGEX_REALLOCATE_STACK ((fail_stack).stack, \ |
1319 (fail_stack).size * sizeof (fail_stack_elt_t), \ | |
1156
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1320 MIN (re_max_failures * TYPICAL_FAILURE_SIZE, \ |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1321 ((fail_stack).size * sizeof (fail_stack_elt_t) \ |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1322 * FAIL_STACK_GROWTH_FACTOR))), \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1323 \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1324 (fail_stack).stack == NULL \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1325 ? 0 \ |
1157
5aa89bba935d
(GROW_FAIL_STACK): Fix previous change:
Karl Heuer <kwzh@gnu.org>
parents:
1156
diff
changeset
|
1326 : ((fail_stack).size \ |
5aa89bba935d
(GROW_FAIL_STACK): Fix previous change:
Karl Heuer <kwzh@gnu.org>
parents:
1156
diff
changeset
|
1327 = (MIN (re_max_failures * TYPICAL_FAILURE_SIZE, \ |
5aa89bba935d
(GROW_FAIL_STACK): Fix previous change:
Karl Heuer <kwzh@gnu.org>
parents:
1156
diff
changeset
|
1328 ((fail_stack).size * sizeof (fail_stack_elt_t) \ |
5aa89bba935d
(GROW_FAIL_STACK): Fix previous change:
Karl Heuer <kwzh@gnu.org>
parents:
1156
diff
changeset
|
1329 * FAIL_STACK_GROWTH_FACTOR)) \ |
5aa89bba935d
(GROW_FAIL_STACK): Fix previous change:
Karl Heuer <kwzh@gnu.org>
parents:
1156
diff
changeset
|
1330 / sizeof (fail_stack_elt_t)), \ |
941 | 1331 1))) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1332 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1333 |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1334 /* Push pointer POINTER on FAIL_STACK. |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1335 Return 1 if was able to do so and 0 if ran out of memory allocating |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1336 space to do so. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1337 #define PUSH_PATTERN_OP(POINTER, FAIL_STACK) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1338 ((FAIL_STACK_FULL () \ |
1156
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1339 && !GROW_FAIL_STACK (FAIL_STACK)) \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1340 ? 0 \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1341 : ((FAIL_STACK).stack[(FAIL_STACK).avail++].pointer = POINTER, \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1342 1)) |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1343 #define POP_PATTERN_OP() POP_FAILURE_POINTER () |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1344 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1345 /* Push a pointer value onto the failure stack. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1346 Assumes the variable `fail_stack'. Probably should only |
941 | 1347 be called from within `PUSH_FAILURE_POINT'. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1348 #define PUSH_FAILURE_POINTER(item) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1349 fail_stack.stack[fail_stack.avail++].pointer = (unsigned char *) (item) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1350 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1351 /* This pushes an integer-valued item onto the failure stack. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1352 Assumes the variable `fail_stack'. Probably should only |
941 | 1353 be called from within `PUSH_FAILURE_POINT'. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1354 #define PUSH_FAILURE_INT(item) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1355 fail_stack.stack[fail_stack.avail++].integer = (item) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1356 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1357 /* Push a fail_stack_elt_t value onto the failure stack. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1358 Assumes the variable `fail_stack'. Probably should only |
941 | 1359 be called from within `PUSH_FAILURE_POINT'. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1360 #define PUSH_FAILURE_ELT(item) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1361 fail_stack.stack[fail_stack.avail++] = (item) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1362 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1363 /* These three POP... operations complement the three PUSH... operations. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1364 All assume that `fail_stack' is nonempty. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1365 #define POP_FAILURE_POINTER() fail_stack.stack[--fail_stack.avail].pointer |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1366 #define POP_FAILURE_INT() fail_stack.stack[--fail_stack.avail].integer |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1367 #define POP_FAILURE_ELT() fail_stack.stack[--fail_stack.avail] |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1368 |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1369 /* Individual items aside from the registers. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1370 #define NUM_NONREG_ITEMS 3 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1371 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1372 /* Used to examine the stack (to detect infinite loops). */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1373 #define FAILURE_PAT(h) fail_stack.stack[(h) - 1].pointer |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1374 #define FAILURE_STR(h) (fail_stack.stack[(h) - 2].pointer) |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1375 #define NEXT_FAILURE_HANDLE(h) fail_stack.stack[(h) - 3].integer |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1376 #define TOP_FAILURE_HANDLE() fail_stack.frame |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1377 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1378 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1379 #define ENSURE_FAIL_STACK(space) \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1380 while (REMAINING_AVAIL_SLOTS <= space) { \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1381 if (!GROW_FAIL_STACK (fail_stack)) \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1382 return -2; \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1383 DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", (fail_stack).size);\ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1384 DEBUG_PRINT2 (" slots available: %d\n", REMAINING_AVAIL_SLOTS);\ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1385 } |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1386 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1387 /* Push register NUM onto the stack. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1388 #define PUSH_FAILURE_REG(num) \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1389 do { \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1390 char *destination; \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1391 ENSURE_FAIL_STACK(3); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1392 DEBUG_PRINT4 (" Push reg %d (spanning %p -> %p)\n", \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1393 num, regstart[num], regend[num]); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1394 PUSH_FAILURE_POINTER (regstart[num]); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1395 PUSH_FAILURE_POINTER (regend[num]); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1396 PUSH_FAILURE_INT (num); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1397 } while (0) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1398 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1399 /* Pop a saved register off the stack. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1400 #define POP_FAILURE_REG() \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1401 do { \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1402 int reg = POP_FAILURE_INT (); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1403 regend[reg] = POP_FAILURE_POINTER (); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1404 regstart[reg] = POP_FAILURE_POINTER (); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1405 DEBUG_PRINT4 (" Pop reg %d (spanning %p -> %p)\n", \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1406 reg, regstart[reg], regend[reg]); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1407 } while (0) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1408 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1409 /* Check that we are not stuck in an infinite loop. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1410 #define CHECK_INFINITE_LOOP(pat_cur, string_place) \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1411 do { \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1412 int failure = TOP_FAILURE_HANDLE(); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1413 /* Check for infinite matching loops */ \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1414 while (failure > 0 && \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1415 (FAILURE_STR (failure) == string_place \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1416 || FAILURE_STR (failure) == NULL)) \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1417 { \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1418 assert (FAILURE_PAT (failure) >= bufp->buffer \ |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1419 && FAILURE_PAT (failure) <= bufp->buffer + bufp->used); \ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1420 if (FAILURE_PAT (failure) == pat_cur) \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1421 goto fail; \ |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1422 DEBUG_PRINT2 (" Other pattern: %p\n", FAILURE_PAT (failure)); \ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1423 failure = NEXT_FAILURE_HANDLE(failure); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1424 } \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1425 DEBUG_PRINT2 (" Other string: %p\n", FAILURE_STR (failure)); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1426 } while (0) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1427 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1428 /* Push the information about the state we will need |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1429 if we ever fail back to it. |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1430 |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1431 Requires variables fail_stack, regstart, regend and |
1156
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1432 num_regs be declared. GROW_FAIL_STACK requires `destination' be |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1433 declared. |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1434 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1435 Does `return FAILURE_CODE' if runs out of memory. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1436 |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1437 #define PUSH_FAILURE_POINT(pattern, string_place) \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1438 do { \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1439 char *destination; \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1440 /* Must be int, so when we don't save any registers, the arithmetic \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1441 of 0 + -1 isn't done as unsigned. */ \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1442 \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1443 DEBUG_STATEMENT (failure_id++); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1444 DEBUG_STATEMENT (nfailure_points_pushed++); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1445 DEBUG_PRINT2 ("\nPUSH_FAILURE_POINT #%u:\n", failure_id); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1446 DEBUG_PRINT2 (" Before push, next avail: %d\n", (fail_stack).avail); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1447 DEBUG_PRINT2 (" size: %d\n", (fail_stack).size);\ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1448 \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1449 ENSURE_FAIL_STACK (NUM_NONREG_ITEMS); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1450 \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1451 DEBUG_PRINT1 ("\n"); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1452 \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1453 DEBUG_PRINT2 (" Push frame index: %d\n", fail_stack.frame); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1454 PUSH_FAILURE_INT (fail_stack.frame); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1455 \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1456 DEBUG_PRINT2 (" Push string %p: `", string_place); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1457 DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, size2);\ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1458 DEBUG_PRINT1 ("'\n"); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1459 PUSH_FAILURE_POINTER (string_place); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1460 \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1461 DEBUG_PRINT2 (" Push pattern %p: ", pattern); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1462 DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern, pend); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1463 PUSH_FAILURE_POINTER (pattern); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1464 \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1465 /* Close the frame by moving the frame pointer past it. */ \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1466 fail_stack.frame = fail_stack.avail; \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1467 } while (0) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1468 |
1156
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1469 /* Estimate the size of data pushed by a typical failure stack entry. |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1470 An estimate is all we need, because all we use this for |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1471 is to choose a limit for how big to make the failure stack. */ |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1472 |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1473 #define TYPICAL_FAILURE_SIZE 20 |
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
1474 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1475 /* How many items can still be added to the stack without overflowing it. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1476 #define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1477 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1478 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1479 /* Pops what PUSH_FAIL_STACK pushes. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1480 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1481 We restore into the parameters, all of which should be lvalues: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1482 STR -- the saved data position. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1483 PAT -- the saved pattern position. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1484 REGSTART, REGEND -- arrays of string positions. |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1485 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1486 Also assumes the variables `fail_stack' and (if debugging), `bufp', |
941 | 1487 `pend', `string1', `size1', `string2', and `size2'. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1488 |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1489 #define POP_FAILURE_POINT(str, pat) \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1490 do { \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1491 assert (!FAIL_STACK_EMPTY ()); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1492 \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1493 /* Remove failure points and point to how many regs pushed. */ \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1494 DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1495 DEBUG_PRINT2 (" Before pop, next avail: %d\n", fail_stack.avail); \ |
941 | 1496 DEBUG_PRINT2 (" size: %d\n", fail_stack.size); \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1497 \ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1498 /* Pop the saved registers. */ \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1499 while (fail_stack.frame < fail_stack.avail) \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1500 POP_FAILURE_REG (); \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1501 \ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1502 pat = (unsigned char *) POP_FAILURE_POINTER (); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1503 DEBUG_PRINT2 (" Popping pattern %p: ", pat); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1504 DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1505 \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1506 /* If the saved string location is NULL, it came from an \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1507 on_failure_keep_string_jump opcode, and we want to throw away the \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1508 saved NULL, thus retaining our current position in the string. */ \ |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1509 str = (re_char *) POP_FAILURE_POINTER (); \ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1510 DEBUG_PRINT2 (" Popping string %p: `", str); \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1511 DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1512 DEBUG_PRINT1 ("'\n"); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1513 \ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1514 fail_stack.frame = POP_FAILURE_INT (); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1515 DEBUG_PRINT2 (" Popping frame index: %d\n", fail_stack.frame); \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1516 \ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1517 assert (fail_stack.avail >= 0); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1518 assert (fail_stack.frame <= fail_stack.avail); \ |
480
998dc67883fb
(PUSH_FAILURE_POINT, POP_FAILURE_POINT): Don't push or pop
Richard Stallman <rms@gnu.org>
parents:
463
diff
changeset
|
1519 \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1520 DEBUG_STATEMENT (nfailure_points_popped++); \ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1521 } while (0) /* POP_FAILURE_POINT */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1522 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1523 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1524 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1525 /* Registers are set to a sentinel when they haven't yet matched. */ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1526 #define REG_UNSET_VALUE NULL |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1527 #define REG_UNSET(e) ((e) == REG_UNSET_VALUE) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1528 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1529 /* Subroutine declarations and macros for regex_compile. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1530 |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1531 static void store_op1 _RE_ARGS((re_opcode_t op, unsigned char *loc, int arg)); |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1532 static void store_op2 _RE_ARGS((re_opcode_t op, unsigned char *loc, |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1533 int arg1, int arg2)); |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1534 static void insert_op1 _RE_ARGS((re_opcode_t op, unsigned char *loc, |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1535 int arg, unsigned char *end)); |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1536 static void insert_op2 _RE_ARGS((re_opcode_t op, unsigned char *loc, |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1537 int arg1, int arg2, unsigned char *end)); |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1538 static boolean at_begline_loc_p _RE_ARGS((const unsigned char *pattern, |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1539 const unsigned char *p, |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1540 reg_syntax_t syntax)); |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1541 static boolean at_endline_loc_p _RE_ARGS((const unsigned char *p, |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1542 const unsigned char *pend, |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1543 reg_syntax_t syntax)); |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
1544 static unsigned char *skip_one_char _RE_ARGS((unsigned char *p)); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1545 |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1546 /* Fetch the next character in the uncompiled pattern---translating it |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1547 if necessary. Also cast from a signed character in the constant |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1548 string passed to us by the user to an unsigned char that we can use |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1549 as an array index (in, e.g., `translate'). */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1550 #define PATFETCH(c) \ |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1551 do { \ |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1552 PATFETCH_RAW (c); \ |
1328
0aa10b723959
Use RE_TRANSLATE_P to check whether translation is
Andreas Schwab <schwab@suse.de>
parents:
1326
diff
changeset
|
1553 if (RE_TRANSLATE_P (translate)) c = RE_TRANSLATE (translate, c); \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1554 } while (0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1555 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1556 /* Fetch the next character in the uncompiled pattern, with no |
941 | 1557 translation. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1558 #define PATFETCH_RAW(c) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1559 do {if (p == pend) return REG_EEND; \ |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1560 c = *p++; \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1561 } while (0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1562 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1563 /* Go backwards one character in the pattern. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1564 #define PATUNFETCH p-- |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1565 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1566 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1567 /* If `translate' is non-null, return translate[D], else just D. We |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1568 cast the subscript to translate because some data is declared as |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1569 `char *', to avoid warnings when a string constant is passed. But |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1570 when we use a character as a subscript we must make it unsigned. */ |
501
f29b13c2cefd
(TRANSLATE, PATFETCH): Cast elt of `translate'.
Richard Stallman <rms@gnu.org>
parents:
490
diff
changeset
|
1571 #ifndef TRANSLATE |
f29b13c2cefd
(TRANSLATE, PATFETCH): Cast elt of `translate'.
Richard Stallman <rms@gnu.org>
parents:
490
diff
changeset
|
1572 #define TRANSLATE(d) \ |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1573 (RE_TRANSLATE_P (translate) ? RE_TRANSLATE (translate, (d)) : (d)) |
501
f29b13c2cefd
(TRANSLATE, PATFETCH): Cast elt of `translate'.
Richard Stallman <rms@gnu.org>
parents:
490
diff
changeset
|
1574 #endif |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1575 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1576 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1577 /* Macros for outputting the compiled pattern into `buffer'. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1578 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1579 /* If the buffer isn't allocated when it comes in, use this. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1580 #define INIT_BUF_SIZE 32 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1581 |
941 | 1582 /* Make sure we have at least N more bytes of space in buffer. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1583 #define GET_BUFFER_SPACE(n) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1584 while (b - bufp->buffer + (n) > bufp->allocated) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1585 EXTEND_BUFFER () |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1586 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1587 /* Make sure we have one more byte of buffer space and then add C to it. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1588 #define BUF_PUSH(c) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1589 do { \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1590 GET_BUFFER_SPACE (1); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1591 *b++ = (unsigned char) (c); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1592 } while (0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1593 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1594 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1595 /* Ensure we have two more bytes of buffer space and then append C1 and C2. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1596 #define BUF_PUSH_2(c1, c2) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1597 do { \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1598 GET_BUFFER_SPACE (2); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1599 *b++ = (unsigned char) (c1); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1600 *b++ = (unsigned char) (c2); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1601 } while (0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1602 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1603 |
941 | 1604 /* As with BUF_PUSH_2, except for three bytes. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1605 #define BUF_PUSH_3(c1, c2, c3) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1606 do { \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1607 GET_BUFFER_SPACE (3); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1608 *b++ = (unsigned char) (c1); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1609 *b++ = (unsigned char) (c2); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1610 *b++ = (unsigned char) (c3); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1611 } while (0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1612 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1613 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1614 /* Store a jump with opcode OP at LOC to location TO. We store a |
941 | 1615 relative address offset by the three bytes the jump itself occupies. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1616 #define STORE_JUMP(op, loc, to) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1617 store_op1 (op, loc, (to) - (loc) - 3) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1618 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1619 /* Likewise, for a two-argument jump. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1620 #define STORE_JUMP2(op, loc, to, arg) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1621 store_op2 (op, loc, (to) - (loc) - 3, arg) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1622 |
941 | 1623 /* Like `STORE_JUMP', but for inserting. Assume `b' is the buffer end. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1624 #define INSERT_JUMP(op, loc, to) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1625 insert_op1 (op, loc, (to) - (loc) - 3, b) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1626 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1627 /* Like `STORE_JUMP2', but for inserting. Assume `b' is the buffer end. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1628 #define INSERT_JUMP2(op, loc, to, arg) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1629 insert_op2 (op, loc, (to) - (loc) - 3, arg, b) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1630 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1631 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1632 /* This is not an arbitrary limit: the arguments which represent offsets |
941 | 1633 into the pattern are two bytes long. So if 2^16 bytes turns out to |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1634 be too small, many things would have to change. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1635 #define MAX_BUF_SIZE (1L << 16) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1636 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1637 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1638 /* Extend the buffer by twice its current size via realloc and |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1639 reset the pointers that pointed into the old block to point to the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1640 correct places in the new one. If extending the buffer results in it |
941 | 1641 being larger than MAX_BUF_SIZE, then flag memory exhausted. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1642 #define EXTEND_BUFFER() \ |
941 | 1643 do { \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1644 unsigned char *old_buffer = bufp->buffer; \ |
941 | 1645 if (bufp->allocated == MAX_BUF_SIZE) \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1646 return REG_ESIZE; \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1647 bufp->allocated <<= 1; \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1648 if (bufp->allocated > MAX_BUF_SIZE) \ |
941 | 1649 bufp->allocated = MAX_BUF_SIZE; \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1650 bufp->buffer = (unsigned char *) realloc (bufp->buffer, bufp->allocated);\ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1651 if (bufp->buffer == NULL) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1652 return REG_ESPACE; \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1653 /* If the buffer moved, move all the pointers into it. */ \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1654 if (old_buffer != bufp->buffer) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1655 { \ |
941 | 1656 b = (b - old_buffer) + bufp->buffer; \ |
1657 begalt = (begalt - old_buffer) + bufp->buffer; \ | |
1658 if (fixup_alt_jump) \ | |
1659 fixup_alt_jump = (fixup_alt_jump - old_buffer) + bufp->buffer;\ | |
1660 if (laststart) \ | |
1661 laststart = (laststart - old_buffer) + bufp->buffer; \ | |
1662 if (pending_exact) \ | |
1663 pending_exact = (pending_exact - old_buffer) + bufp->buffer; \ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1664 } \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1665 } while (0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1666 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1667 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1668 /* Since we have one byte reserved for the register number argument to |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1669 {start,stop}_memory, the maximum number of groups we can report |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1670 things about is what fits in that byte. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1671 #define MAX_REGNUM 255 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1672 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1673 /* But patterns can have more than `MAX_REGNUM' registers. We just |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1674 ignore the excess. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1675 typedef unsigned regnum_t; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1676 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1677 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1678 /* Macros for the compile stack. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1679 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1680 /* Since offsets can go either forwards or backwards, this type needs to |
941 | 1681 be able to hold values from -(MAX_BUF_SIZE - 1) to MAX_BUF_SIZE - 1. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1682 typedef int pattern_offset_t; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1683 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1684 typedef struct |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1685 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1686 pattern_offset_t begalt_offset; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1687 pattern_offset_t fixup_alt_jump; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1688 pattern_offset_t laststart_offset; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1689 regnum_t regnum; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1690 } compile_stack_elt_t; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1691 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1692 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1693 typedef struct |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1694 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1695 compile_stack_elt_t *stack; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1696 unsigned size; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1697 unsigned avail; /* Offset of next open position. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1698 } compile_stack_type; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1699 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1700 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1701 #define INIT_COMPILE_STACK_SIZE 32 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1702 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1703 #define COMPILE_STACK_EMPTY (compile_stack.avail == 0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1704 #define COMPILE_STACK_FULL (compile_stack.avail == compile_stack.size) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1705 |
941 | 1706 /* The next available element. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1707 #define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail]) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1708 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1709 |
939 | 1710 /* Structure to manage work area for range table. */ |
1711 struct range_table_work_area | |
1712 { | |
1713 int *table; /* actual work area. */ | |
1714 int allocated; /* allocated size for work area in bytes. */ | |
941 | 1715 int used; /* actually used size in words. */ |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1716 int bits; /* flag to record character classes */ |
939 | 1717 }; |
1718 | |
1719 /* Make sure that WORK_AREA can hold more N multibyte characters. */ | |
1720 #define EXTEND_RANGE_TABLE_WORK_AREA(work_area, n) \ | |
1721 do { \ | |
1722 if (((work_area).used + (n)) * sizeof (int) > (work_area).allocated) \ | |
1723 { \ | |
1724 (work_area).allocated += 16 * sizeof (int); \ | |
1725 if ((work_area).table) \ | |
1726 (work_area).table \ | |
1727 = (int *) realloc ((work_area).table, (work_area).allocated); \ | |
1728 else \ | |
1729 (work_area).table \ | |
1730 = (int *) malloc ((work_area).allocated); \ | |
1731 if ((work_area).table == 0) \ | |
1732 FREE_STACK_RETURN (REG_ESPACE); \ | |
1733 } \ | |
1734 } while (0) | |
1735 | |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1736 #define SET_RANGE_TABLE_WORK_AREA_BIT(work_area, bit) \ |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1737 (work_area).bits |= (bit) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1738 |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1739 /* These bits represent the various character classes such as [:alnum:] |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1740 in a charset's range table. */ |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1741 #define BIT_ALNUM 0x1 |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1742 #define BIT_ALPHA 0x2 |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1743 #define BIT_WORD 0x4 |
1965
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
1744 #define BIT_ASCII 0x8 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
1745 #define BIT_NONASCII 0x10 |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1746 #define BIT_GRAPH 0x20 |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1747 #define BIT_LOWER 0x40 |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1748 #define BIT_PRINT 0x80 |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1749 #define BIT_PUNCT 0x100 |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1750 #define BIT_SPACE 0x200 |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1751 #define BIT_UPPER 0x400 |
1965
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
1752 #define BIT_UNIBYTE 0x800 |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
1753 #define BIT_MULTIBYTE 0x1000 |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1754 |
939 | 1755 /* Set a range (RANGE_START, RANGE_END) to WORK_AREA. */ |
1756 #define SET_RANGE_TABLE_WORK_AREA(work_area, range_start, range_end) \ | |
1757 do { \ | |
1758 EXTEND_RANGE_TABLE_WORK_AREA ((work_area), 2); \ | |
1759 (work_area).table[(work_area).used++] = (range_start); \ | |
1760 (work_area).table[(work_area).used++] = (range_end); \ | |
1761 } while (0) | |
1762 | |
941 | 1763 /* Free allocated memory for WORK_AREA. */ |
939 | 1764 #define FREE_RANGE_TABLE_WORK_AREA(work_area) \ |
1765 do { \ | |
1766 if ((work_area).table) \ | |
1767 free ((work_area).table); \ | |
1768 } while (0) | |
1769 | |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1770 #define CLEAR_RANGE_TABLE_WORK_USED(work_area) ((work_area).used = 0, (work_area).bits = 0) |
939 | 1771 #define RANGE_TABLE_WORK_USED(work_area) ((work_area).used) |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1772 #define RANGE_TABLE_WORK_BITS(work_area) ((work_area).bits) |
939 | 1773 #define RANGE_TABLE_WORK_ELT(work_area, i) ((work_area).table[i]) |
1774 | |
1775 | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1776 /* Set the bit for character C in a list. */ |
941 | 1777 #define SET_LIST_BIT(c) \ |
1778 (b[((unsigned char) (c)) / BYTEWIDTH] \ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1779 |= 1 << (((unsigned char) c) % BYTEWIDTH)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1780 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1781 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1782 /* Get the next unsigned number in the uncompiled pattern. */ |
941 | 1783 #define GET_UNSIGNED_NUMBER(num) \ |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1784 do { if (p != pend) \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1785 { \ |
941 | 1786 PATFETCH (c); \ |
1787 while (ISDIGIT (c)) \ | |
1788 { \ | |
1789 if (num < 0) \ | |
1790 num = 0; \ | |
1791 num = num * 10 + c - '0'; \ | |
1792 if (p == pend) \ | |
1793 break; \ | |
1794 PATFETCH (c); \ | |
1795 } \ | |
1796 } \ | |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1797 } while (0) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1798 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1799 #define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1800 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1801 #define IS_CHAR_CLASS(string) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1802 (STREQ (string, "alpha") || STREQ (string, "upper") \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1803 || STREQ (string, "lower") || STREQ (string, "digit") \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1804 || STREQ (string, "alnum") || STREQ (string, "xdigit") \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1805 || STREQ (string, "space") || STREQ (string, "print") \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1806 || STREQ (string, "punct") || STREQ (string, "graph") \ |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
1807 || STREQ (string, "cntrl") || STREQ (string, "blank") \ |
1965
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
1808 || STREQ (string, "word") \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
1809 || STREQ (string, "ascii") || STREQ (string, "nonascii") \ |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
1810 || STREQ (string, "unibyte") || STREQ (string, "multibyte")) |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1811 |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1812 /* QUIT is only used on NTemacs. */ |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1813 #if !defined (WINDOWSNT) || !defined (emacs) |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1814 #undef QUIT |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1815 #define QUIT |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1816 #endif |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1817 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1818 #ifndef MATCH_MAY_ALLOCATE |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1819 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1820 /* If we cannot allocate large objects within re_match_2_internal, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1821 we make the fail stack and register vectors global. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1822 The fail stack, we grow to the maximum size when a regexp |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1823 is compiled. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1824 The register vectors, we adjust in size each time we |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1825 compile a regexp, according to the number of registers it needs. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1826 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1827 static fail_stack_type fail_stack; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1828 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1829 /* Size with which the following vectors are currently allocated. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1830 That is so we can make them bigger as needed, |
941 | 1831 but never make them smaller. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1832 static int regs_allocated_size; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1833 |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1834 static re_char ** regstart, ** regend; |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1835 static re_char **best_regstart, **best_regend; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1836 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1837 /* Make the register vectors big enough for NUM_REGS registers, |
941 | 1838 but don't make them smaller. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1839 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1840 static |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1841 regex_grow_registers (num_regs) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1842 int num_regs; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1843 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1844 if (num_regs > regs_allocated_size) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1845 { |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1846 RETALLOC_IF (regstart, num_regs, re_char *); |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1847 RETALLOC_IF (regend, num_regs, re_char *); |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1848 RETALLOC_IF (best_regstart, num_regs, re_char *); |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1849 RETALLOC_IF (best_regend, num_regs, re_char *); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1850 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1851 regs_allocated_size = num_regs; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1852 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1853 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1854 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1855 #endif /* not MATCH_MAY_ALLOCATE */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1856 |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1857 static boolean group_in_compile_stack _RE_ARGS ((compile_stack_type |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1858 compile_stack, |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1859 regnum_t regnum)); |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1860 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1861 /* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1862 Returns one of error codes defined in `regex.h', or zero for success. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1863 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1864 Assumes the `allocated' (and perhaps `buffer') and `translate' |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1865 fields are set in BUFP on entry. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1866 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1867 If it succeeds, results are put in BUFP (if it returns an error, the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1868 contents of BUFP are undefined): |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1869 `buffer' is the compiled pattern; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1870 `syntax' is set to SYNTAX; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1871 `used' is set to the length of the compiled pattern; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1872 `fastmap_accurate' is zero; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1873 `re_nsub' is the number of subexpressions in PATTERN; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1874 `not_bol' and `not_eol' are zero; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1875 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1876 The `fastmap' and `newline_anchor' fields are neither |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1877 examined nor set. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1878 |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1879 /* Insert the `jump' from the end of last alternative to "here". |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1880 The space for the jump has already been allocated. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1881 #define FIXUP_ALT_JUMP() \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1882 do { \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1883 if (fixup_alt_jump) \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1884 STORE_JUMP (jump, fixup_alt_jump, b); \ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1885 } while (0) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1886 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
1887 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1888 /* Return, freeing storage we allocated. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1889 #define FREE_STACK_RETURN(value) \ |
939 | 1890 do { \ |
1891 FREE_RANGE_TABLE_WORK_AREA (range_table_work); \ | |
1892 free (compile_stack.stack); \ | |
1893 return value; \ | |
1894 } while (0) | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1895 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1896 static reg_errcode_t |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1897 regex_compile (pattern, size, syntax, bufp) |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1898 re_char *pattern; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1899 int size; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1900 reg_syntax_t syntax; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1901 struct re_pattern_buffer *bufp; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1902 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1903 /* We fetch characters from PATTERN here. Even though PATTERN is |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1904 `char *' (i.e., signed), we declare these variables as unsigned, so |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1905 they can be reliably used as array indices. */ |
939 | 1906 register unsigned int c, c1; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1907 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1908 /* A random temporary spot in PATTERN. */ |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1909 re_char *p1; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1910 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1911 /* Points to the end of the buffer, where we should append. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1912 register unsigned char *b; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1913 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1914 /* Keeps track of unclosed groups. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1915 compile_stack_type compile_stack; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1916 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1917 /* Points to the current (ending) position in the pattern. */ |
1440
ba6fdbf593bb
(regex_compile): Declare p with non-const type on AIX.
Richard Stallman <rms@gnu.org>
parents:
1383
diff
changeset
|
1918 #ifdef AIX |
ba6fdbf593bb
(regex_compile): Declare p with non-const type on AIX.
Richard Stallman <rms@gnu.org>
parents:
1383
diff
changeset
|
1919 /* `const' makes AIX compiler fail. */ |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1920 unsigned char *p = pattern; |
1440
ba6fdbf593bb
(regex_compile): Declare p with non-const type on AIX.
Richard Stallman <rms@gnu.org>
parents:
1383
diff
changeset
|
1921 #else |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1922 re_char *p = pattern; |
1440
ba6fdbf593bb
(regex_compile): Declare p with non-const type on AIX.
Richard Stallman <rms@gnu.org>
parents:
1383
diff
changeset
|
1923 #endif |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1924 re_char *pend = pattern + size; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1925 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1926 /* How to translate the characters in the pattern. */ |
501
f29b13c2cefd
(TRANSLATE, PATFETCH): Cast elt of `translate'.
Richard Stallman <rms@gnu.org>
parents:
490
diff
changeset
|
1927 RE_TRANSLATE_TYPE translate = bufp->translate; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1928 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1929 /* Address of the count-byte of the most recently inserted `exactn' |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1930 command. This makes it possible to tell if a new exact-match |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1931 character can be added to that command or if the character requires |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1932 a new `exactn' command. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1933 unsigned char *pending_exact = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1934 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1935 /* Address of start of the most recently finished expression. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1936 This tells, e.g., postfix * where to find the start of its |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1937 operand. Reset at the beginning of groups and alternatives. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1938 unsigned char *laststart = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1939 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1940 /* Address of beginning of regexp, or inside of last group. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1941 unsigned char *begalt; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1942 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1943 /* Place in the uncompiled pattern (i.e., the {) to |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1944 which to go back if the interval is invalid. */ |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
1945 re_char *beg_interval; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1946 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1947 /* Address of the place where a forward jump should go to the end of |
941 | 1948 the containing expression. Each alternative of an `or' -- except the |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1949 last -- ends with a forward jump of this sort. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1950 unsigned char *fixup_alt_jump = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1951 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1952 /* Counts open-groups as they are encountered. Remembered for the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1953 matching close-group on the compile stack, so the same register |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1954 number is put in the stop_memory as the start_memory. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1955 regnum_t regnum = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1956 |
939 | 1957 /* Work area for range table of charset. */ |
1958 struct range_table_work_area range_table_work; | |
1959 | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1960 #ifdef DEBUG |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1961 debug++; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1962 DEBUG_PRINT1 ("\nCompiling pattern: "); |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
1963 if (debug > 0) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1964 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1965 unsigned debug_count; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1966 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1967 for (debug_count = 0; debug_count < size; debug_count++) |
941 | 1968 putchar (pattern[debug_count]); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1969 putchar ('\n'); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1970 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1971 #endif /* DEBUG */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1972 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1973 /* Initialize the compile stack. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1974 compile_stack.stack = TALLOC (INIT_COMPILE_STACK_SIZE, compile_stack_elt_t); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1975 if (compile_stack.stack == NULL) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1976 return REG_ESPACE; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1977 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1978 compile_stack.size = INIT_COMPILE_STACK_SIZE; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1979 compile_stack.avail = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1980 |
939 | 1981 range_table_work.table = 0; |
1982 range_table_work.allocated = 0; | |
1983 | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1984 /* Initialize the pattern buffer. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1985 bufp->syntax = syntax; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1986 bufp->fastmap_accurate = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1987 bufp->not_bol = bufp->not_eol = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1988 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1989 /* Set `used' to zero, so that if we return an error, the pattern |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1990 printer (for debugging) will think there's no pattern. We reset it |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1991 at the end. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1992 bufp->used = 0; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1993 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1994 /* Always count groups, whether or not bufp->no_sub is set. */ |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
1995 bufp->re_nsub = 0; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
1996 |
939 | 1997 #ifdef emacs |
1998 /* bufp->multibyte is set before regex_compile is called, so don't alter | |
1999 it. */ | |
2000 #else /* not emacs */ | |
2001 /* Nothing is recognized as a multibyte character. */ | |
2002 bufp->multibyte = 0; | |
2003 #endif | |
2004 | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2005 #if !defined (emacs) && !defined (SYNTAX_TABLE) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2006 /* Initialize the syntax table. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2007 init_syntax_once (); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2008 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2009 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2010 if (bufp->allocated == 0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2011 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2012 if (bufp->buffer) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2013 { /* If zero allocated, but buffer is non-null, try to realloc |
941 | 2014 enough space. This loses if buffer's address is bogus, but |
2015 that is the user's responsibility. */ | |
2016 RETALLOC (bufp->buffer, INIT_BUF_SIZE, unsigned char); | |
2017 } | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2018 else |
941 | 2019 { /* Caller did not allocate a buffer. Do it for them. */ |
2020 bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char); | |
2021 } | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2022 if (!bufp->buffer) FREE_STACK_RETURN (REG_ESPACE); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2023 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2024 bufp->allocated = INIT_BUF_SIZE; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2025 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2026 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2027 begalt = b = bufp->buffer; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2028 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2029 /* Loop through the uncompiled pattern until we're at the end. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2030 while (p != pend) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2031 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2032 PATFETCH (c); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2033 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2034 switch (c) |
941 | 2035 { |
2036 case '^': | |
2037 { | |
2038 if ( /* If at start of pattern, it's an operator. */ | |
2039 p == pattern + 1 | |
2040 /* If context independent, it's an operator. */ | |
2041 || syntax & RE_CONTEXT_INDEP_ANCHORS | |
2042 /* Otherwise, depends on what's come before. */ | |
2043 || at_begline_loc_p (pattern, p, syntax)) | |
2044 BUF_PUSH (begline); | |
2045 else | |
2046 goto normal_char; | |
2047 } | |
2048 break; | |
2049 | |
2050 | |
2051 case '$': | |
2052 { | |
2053 if ( /* If at end of pattern, it's an operator. */ | |
2054 p == pend | |
2055 /* If context independent, it's an operator. */ | |
2056 || syntax & RE_CONTEXT_INDEP_ANCHORS | |
2057 /* Otherwise, depends on what's next. */ | |
2058 || at_endline_loc_p (p, pend, syntax)) | |
2059 BUF_PUSH (endline); | |
2060 else | |
2061 goto normal_char; | |
2062 } | |
2063 break; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2064 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2065 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2066 case '+': |
941 | 2067 case '?': |
2068 if ((syntax & RE_BK_PLUS_QM) | |
2069 || (syntax & RE_LIMITED_OPS)) | |
2070 goto normal_char; | |
2071 handle_plus: | |
2072 case '*': | |
2073 /* If there is no previous pattern... */ | |
2074 if (!laststart) | |
2075 { | |
2076 if (syntax & RE_CONTEXT_INVALID_OPS) | |
2077 FREE_STACK_RETURN (REG_BADRPT); | |
2078 else if (!(syntax & RE_CONTEXT_INDEP_OPS)) | |
2079 goto normal_char; | |
2080 } | |
2081 | |
2082 { | |
2083 /* 1 means zero (many) matches is allowed. */ | |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
2084 boolean zero_times_ok = 0, many_times_ok = 0; |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
2085 boolean greedy = 1; |
941 | 2086 |
2087 /* If there is a sequence of repetition chars, collapse it | |
2088 down to just one (the right one). We can't combine | |
2089 interval operators with these because of, e.g., `a{2}*', | |
2090 which should only match an even number of `a's. */ | |
2091 | |
2092 for (;;) | |
2093 { | |
2034
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2094 if (!(syntax & RE_ALL_GREEDY) |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2095 && c == '?' && (zero_times_ok || many_times_ok)) |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2096 greedy = 0; |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2097 else |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2098 { |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2099 zero_times_ok |= c != '+'; |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2100 many_times_ok |= c != '?'; |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2101 } |
941 | 2102 |
2103 if (p == pend) | |
2104 break; | |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2105 else if (*p == '*' |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2106 || (!(syntax & RE_BK_PLUS_QM) |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2107 && (*p == '+' || *p == '?'))) |
941 | 2108 ; |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2109 else if (syntax & RE_BK_PLUS_QM && *p == '\\') |
941 | 2110 { |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2111 if (p+1 == pend) |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2112 FREE_STACK_RETURN (REG_EESCAPE); |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2113 if (p[1] == '+' || p[1] == '?') |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2114 PATFETCH (c); /* Gobble up the backslash. */ |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2115 else |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2116 break; |
941 | 2117 } |
2118 else | |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2119 break; |
941 | 2120 /* If we get here, we found another repeat character. */ |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2121 PATFETCH (c); |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2122 } |
941 | 2123 |
2124 /* Star, etc. applied to an empty pattern is equivalent | |
2125 to an empty pattern. */ | |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2126 if (!laststart || laststart == b) |
941 | 2127 break; |
2128 | |
2129 /* Now we know whether or not zero matches is allowed | |
2130 and also whether or not two or more matches is allowed. */ | |
2034
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2131 if (greedy) |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2132 { |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2133 if (many_times_ok) |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2134 { |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2135 boolean simple = skip_one_char (laststart) == b; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2136 unsigned int startoffset = 0; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2137 assert (skip_one_char (laststart) <= b); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2138 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2139 if (!zero_times_ok && simple) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2140 { /* Since simple * loops can be made faster by using |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2141 on_failure_keep_string_jump, we turn simple P+ |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2142 into PP* if P is simple. */ |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2143 unsigned char *p1, *p2; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2144 startoffset = b - laststart; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2145 GET_BUFFER_SPACE (startoffset); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2146 p1 = b; p2 = laststart; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2147 while (p2 < p1) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2148 *b++ = *p2++; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2149 zero_times_ok = 1; |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2150 } |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2151 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2152 GET_BUFFER_SPACE (6); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2153 if (!zero_times_ok) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2154 /* A + loop. */ |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2155 STORE_JUMP (on_failure_jump_loop, b, b + 6); |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2156 else |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2157 /* Simple * loops can use on_failure_keep_string_jump |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2158 depending on what follows. But since we don't know |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2159 that yet, we leave the decision up to |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2160 on_failure_jump_smart. */ |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2161 INSERT_JUMP (simple ? on_failure_jump_smart |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2162 : on_failure_jump_loop, |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2163 laststart + startoffset, b + 6); |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2164 b += 3; |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2165 STORE_JUMP (jump, b, laststart + startoffset); |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2166 b += 3; |
941 | 2167 } |
2168 else | |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2169 { |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2170 /* A simple ? pattern. */ |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2171 assert (zero_times_ok); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2172 GET_BUFFER_SPACE (3); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2173 INSERT_JUMP (on_failure_jump, laststart, b + 3); |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2174 b += 3; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2175 } |
2034
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2176 } |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2177 else /* not greedy */ |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2178 { /* I wish the greedy and non-greedy cases could be merged. */ |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2179 |
2370
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
2180 GET_BUFFER_SPACE (7); /* We might use less. */ |
2034
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2181 if (many_times_ok) |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2182 { |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2183 /* The non-greedy multiple match looks like a repeat..until: |
2034
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2184 we only need a conditional jump at the end of the loop */ |
2370
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
2185 BUF_PUSH (no_op); |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
2186 STORE_JUMP (on_failure_jump_nastyloop, b, laststart); |
2034
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2187 b += 3; |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2188 if (zero_times_ok) |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2189 { |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2190 /* The repeat...until naturally matches one or more. |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2191 To also match zero times, we need to first jump to |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2192 the end of the loop (its conditional jump). */ |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2193 INSERT_JUMP (jump, laststart, b); |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2194 b += 3; |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2195 } |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2196 } |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2197 else |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2198 { |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2199 /* non-greedy a?? */ |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2200 INSERT_JUMP (jump, laststart, b + 3); |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2201 b += 3; |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2202 INSERT_JUMP (on_failure_jump, laststart, laststart + 6); |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2203 b += 3; |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2204 } |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2205 } |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
2206 } |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
2207 pending_exact = 0; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2208 break; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2209 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2210 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2211 case '.': |
941 | 2212 laststart = b; |
2213 BUF_PUSH (anychar); | |
2214 break; | |
2215 | |
2216 | |
2217 case '[': | |
2218 { | |
939 | 2219 CLEAR_RANGE_TABLE_WORK_USED (range_table_work); |
2220 | |
941 | 2221 if (p == pend) FREE_STACK_RETURN (REG_EBRACK); |
2222 | |
2223 /* Ensure that we have enough space to push a charset: the | |
2224 opcode, the length count, and the bitset; 34 bytes in all. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2225 GET_BUFFER_SPACE (34); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2226 |
941 | 2227 laststart = b; |
2228 | |
2229 /* We test `*p == '^' twice, instead of using an if | |
2230 statement, so we only need one BUF_PUSH. */ | |
2231 BUF_PUSH (*p == '^' ? charset_not : charset); | |
2232 if (*p == '^') | |
2233 p++; | |
2234 | |
2235 /* Remember the first position in the bracket expression. */ | |
2236 p1 = p; | |
2237 | |
2238 /* Push the number of bytes in the bitmap. */ | |
2239 BUF_PUSH ((1 << BYTEWIDTH) / BYTEWIDTH); | |
2240 | |
2241 /* Clear the whole map. */ | |
2242 bzero (b, (1 << BYTEWIDTH) / BYTEWIDTH); | |
2243 | |
2244 /* charset_not matches newline according to a syntax bit. */ | |
2245 if ((re_opcode_t) b[-2] == charset_not | |
2246 && (syntax & RE_HAT_LISTS_NOT_NEWLINE)) | |
2247 SET_LIST_BIT ('\n'); | |
2248 | |
2249 /* Read in characters and ranges, setting map bits. */ | |
2250 for (;;) | |
2251 { | |
939 | 2252 int len; |
2253 boolean escaped_char = false; | |
2254 | |
941 | 2255 if (p == pend) FREE_STACK_RETURN (REG_EBRACK); |
2256 | |
2257 PATFETCH (c); | |
2258 | |
2259 /* \ might escape characters inside [...] and [^...]. */ | |
2260 if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\') | |
2261 { | |
2262 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE); | |
679 | 2263 |
2264 PATFETCH (c); | |
939 | 2265 escaped_char = true; |
941 | 2266 } |
939 | 2267 else |
2268 { | |
992 | 2269 /* Could be the end of the bracket expression. If it's |
2270 not (i.e., when the bracket expression is `[]' so | |
2271 far), the ']' character bit gets set way below. */ | |
2272 if (c == ']' && p != p1 + 1) | |
2273 break; | |
941 | 2274 } |
939 | 2275 |
2276 /* If C indicates start of multibyte char, get the | |
2277 actual character code in C, and set the pattern | |
2278 pointer P to the next character boundary. */ | |
2279 if (bufp->multibyte && BASE_LEADING_CODE_P (c)) | |
2280 { | |
2281 PATUNFETCH; | |
2282 c = STRING_CHAR_AND_LENGTH (p, pend - p, len); | |
2283 p += len; | |
941 | 2284 } |
939 | 2285 /* What should we do for the character which is |
2286 greater than 0x7F, but not BASE_LEADING_CODE_P? | |
2287 XXX */ | |
2288 | |
941 | 2289 /* See if we're at the beginning of a possible character |
2290 class. */ | |
939 | 2291 |
2292 else if (!escaped_char && | |
2293 syntax & RE_CHAR_CLASSES && c == '[' && *p == ':') | |
992 | 2294 { |
2295 /* Leave room for the null. */ | |
941 | 2296 char str[CHAR_CLASS_MAX_LENGTH + 1]; |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2297 const unsigned char *class_beg; |
941 | 2298 |
2299 PATFETCH (c); | |
2300 c1 = 0; | |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2301 class_beg = p; |
941 | 2302 |
2303 /* If pattern is `[[:'. */ | |
2304 if (p == pend) FREE_STACK_RETURN (REG_EBRACK); | |
2305 | |
2306 for (;;) | |
2307 { | |
2308 PATFETCH (c); | |
2309 if (c == ':' || c == ']' || p == pend | |
2310 || c1 == CHAR_CLASS_MAX_LENGTH) | |
2311 break; | |
2312 str[c1++] = c; | |
2313 } | |
2314 str[c1] = '\0'; | |
939 | 2315 |
2316 /* If isn't a word bracketed by `[:' and `:]': | |
2317 undo the ending character, the letters, and | |
2318 leave the leading `:' and `[' (but set bits for | |
2319 them). */ | |
941 | 2320 if (c == ':' && *p == ']') |
2321 { | |
2322 int ch; | |
2323 boolean is_alnum = STREQ (str, "alnum"); | |
2324 boolean is_alpha = STREQ (str, "alpha"); | |
1965
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
2325 boolean is_ascii = STREQ (str, "ascii"); |
941 | 2326 boolean is_blank = STREQ (str, "blank"); |
2327 boolean is_cntrl = STREQ (str, "cntrl"); | |
2328 boolean is_digit = STREQ (str, "digit"); | |
2329 boolean is_graph = STREQ (str, "graph"); | |
2330 boolean is_lower = STREQ (str, "lower"); | |
1965
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
2331 boolean is_multibyte = STREQ (str, "multibyte"); |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
2332 boolean is_nonascii = STREQ (str, "nonascii"); |
941 | 2333 boolean is_print = STREQ (str, "print"); |
2334 boolean is_punct = STREQ (str, "punct"); | |
2335 boolean is_space = STREQ (str, "space"); | |
1965
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
2336 boolean is_unibyte = STREQ (str, "unibyte"); |
941 | 2337 boolean is_upper = STREQ (str, "upper"); |
1965
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
2338 boolean is_word = STREQ (str, "word"); |
941 | 2339 boolean is_xdigit = STREQ (str, "xdigit"); |
2340 | |
2341 if (!IS_CHAR_CLASS (str)) | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2342 FREE_STACK_RETURN (REG_ECTYPE); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2343 |
941 | 2344 /* Throw away the ] at the end of the character |
2345 class. */ | |
2346 PATFETCH (c); | |
2347 | |
2348 if (p == pend) FREE_STACK_RETURN (REG_EBRACK); | |
2349 | |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2350 /* Most character classes in a multibyte match |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2351 just set a flag. Exceptions are is_blank, |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2352 is_digit, is_cntrl, and is_xdigit, since |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2353 they can only match ASCII characters. We |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2354 don't need to handle them for multibyte. */ |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2355 |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2356 if (bufp->multibyte) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2357 { |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2358 int bit = 0; |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2359 |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2360 if (is_alnum) bit = BIT_ALNUM; |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2361 if (is_alpha) bit = BIT_ALPHA; |
1965
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
2362 if (is_ascii) bit = BIT_ASCII; |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2363 if (is_graph) bit = BIT_GRAPH; |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2364 if (is_lower) bit = BIT_LOWER; |
1965
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
2365 if (is_multibyte) bit = BIT_MULTIBYTE; |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
2366 if (is_nonascii) bit = BIT_NONASCII; |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2367 if (is_print) bit = BIT_PRINT; |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2368 if (is_punct) bit = BIT_PUNCT; |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2369 if (is_space) bit = BIT_SPACE; |
1965
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
2370 if (is_unibyte) bit = BIT_UNIBYTE; |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2371 if (is_upper) bit = BIT_UPPER; |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2372 if (is_word) bit = BIT_WORD; |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2373 if (bit) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2374 SET_RANGE_TABLE_WORK_AREA_BIT (range_table_work, |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2375 bit); |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2376 } |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2377 |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2378 /* Handle character classes for ASCII characters. */ |
941 | 2379 for (ch = 0; ch < 1 << BYTEWIDTH; ch++) |
2380 { | |
692
1036844e8833
(regex_compile): Use TRANSLATE before calling SET_LIST_BIT.
Richard Stallman <rms@gnu.org>
parents:
680
diff
changeset
|
2381 int translated = TRANSLATE (ch); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2382 /* This was split into 3 if's to |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2383 avoid an arbitrary limit in some compiler. */ |
941 | 2384 if ( (is_alnum && ISALNUM (ch)) |
2385 || (is_alpha && ISALPHA (ch)) | |
2386 || (is_blank && ISBLANK (ch)) | |
2387 || (is_cntrl && ISCNTRL (ch))) | |
692
1036844e8833
(regex_compile): Use TRANSLATE before calling SET_LIST_BIT.
Richard Stallman <rms@gnu.org>
parents:
680
diff
changeset
|
2388 SET_LIST_BIT (translated); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2389 if ( (is_digit && ISDIGIT (ch)) |
941 | 2390 || (is_graph && ISGRAPH (ch)) |
2391 || (is_lower && ISLOWER (ch)) | |
2392 || (is_print && ISPRINT (ch))) | |
692
1036844e8833
(regex_compile): Use TRANSLATE before calling SET_LIST_BIT.
Richard Stallman <rms@gnu.org>
parents:
680
diff
changeset
|
2393 SET_LIST_BIT (translated); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2394 if ( (is_punct && ISPUNCT (ch)) |
941 | 2395 || (is_space && ISSPACE (ch)) |
2396 || (is_upper && ISUPPER (ch)) | |
2397 || (is_xdigit && ISXDIGIT (ch))) | |
692
1036844e8833
(regex_compile): Use TRANSLATE before calling SET_LIST_BIT.
Richard Stallman <rms@gnu.org>
parents:
680
diff
changeset
|
2398 SET_LIST_BIT (translated); |
1965
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
2399 if ( (is_ascii && IS_REAL_ASCII (ch)) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
2400 || (is_nonascii && !IS_REAL_ASCII (ch)) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
2401 || (is_unibyte && ISUNIBYTE (ch)) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
2402 || (is_multibyte && !ISUNIBYTE (ch))) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
2403 SET_LIST_BIT (translated); |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
2404 |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2405 if ( (is_word && ISWORD (ch))) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2406 SET_LIST_BIT (translated); |
941 | 2407 } |
939 | 2408 |
2409 /* Repeat the loop. */ | |
2410 continue; | |
941 | 2411 } |
2412 else | |
2413 { | |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2414 /* Go back to right after the "[:". */ |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2415 p = class_beg; |
941 | 2416 SET_LIST_BIT ('['); |
939 | 2417 |
2418 /* Because the `:' may starts the range, we | |
2419 can't simply set bit and repeat the loop. | |
941 | 2420 Instead, just set it to C and handle below. */ |
939 | 2421 c = ':'; |
941 | 2422 } |
2423 } | |
939 | 2424 |
2425 if (p < pend && p[0] == '-' && p[1] != ']') | |
2426 { | |
2427 | |
2428 /* Discard the `-'. */ | |
2429 PATFETCH (c1); | |
2430 | |
2431 /* Fetch the character which ends the range. */ | |
2432 PATFETCH (c1); | |
2433 if (bufp->multibyte && BASE_LEADING_CODE_P (c1)) | |
2434 { | |
2435 PATUNFETCH; | |
2436 c1 = STRING_CHAR_AND_LENGTH (p, pend - p, len); | |
2437 p += len; | |
2438 } | |
2439 | |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
2440 if (SINGLE_BYTE_CHAR_P (c) |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
2441 && ! SINGLE_BYTE_CHAR_P (c1)) |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
2442 { |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
2443 /* Handle a range such as \177-\377 in multibyte mode. |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
2444 Split that into two ranges,, |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
2445 the low one ending at 0237, and the high one |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
2446 starting at ...040. */ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2447 /* Unless I'm missing something, |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2448 this line is useless. -sm |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2449 int c1_base = (c1 & ~0177) | 040; */ |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
2450 SET_RANGE_TABLE_WORK_AREA (range_table_work, c, c1); |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
2451 c1 = 0237; |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
2452 } |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
2453 else if (!SAME_CHARSET_P (c, c1)) |
939 | 2454 FREE_STACK_RETURN (REG_ERANGE); |
2455 } | |
941 | 2456 else |
939 | 2457 /* Range from C to C. */ |
2458 c1 = c; | |
2459 | |
2460 /* Set the range ... */ | |
2461 if (SINGLE_BYTE_CHAR_P (c)) | |
2462 /* ... into bitmap. */ | |
941 | 2463 { |
939 | 2464 unsigned this_char; |
2465 int range_start = c, range_end = c1; | |
2466 | |
2467 /* If the start is after the end, the range is empty. */ | |
2468 if (range_start > range_end) | |
2469 { | |
2470 if (syntax & RE_NO_EMPTY_RANGES) | |
2471 FREE_STACK_RETURN (REG_ERANGE); | |
2472 /* Else, repeat the loop. */ | |
679 | 2473 } |
2474 else | |
2475 { | |
939 | 2476 for (this_char = range_start; this_char <= range_end; |
2477 this_char++) | |
2478 SET_LIST_BIT (TRANSLATE (this_char)); | |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
2479 } |
941 | 2480 } |
679 | 2481 else |
939 | 2482 /* ... into range table. */ |
2483 SET_RANGE_TABLE_WORK_AREA (range_table_work, c, c1); | |
679 | 2484 } |
2485 | |
941 | 2486 /* Discard any (non)matching list bytes that are all 0 at the |
2487 end of the map. Decrease the map-length byte too. */ | |
2488 while ((int) b[-1] > 0 && b[b[-1] - 1] == 0) | |
2489 b[-1]--; | |
2490 b += b[-1]; | |
939 | 2491 |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2492 /* Build real range table from work area. */ |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2493 if (RANGE_TABLE_WORK_USED (range_table_work) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2494 || RANGE_TABLE_WORK_BITS (range_table_work)) |
939 | 2495 { |
2496 int i; | |
2497 int used = RANGE_TABLE_WORK_USED (range_table_work); | |
2498 | |
2499 /* Allocate space for COUNT + RANGE_TABLE. Needs two | |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2500 bytes for flags, two for COUNT, and three bytes for |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2501 each character. */ |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2502 GET_BUFFER_SPACE (4 + used * 3); |
939 | 2503 |
2504 /* Indicate the existence of range table. */ | |
2505 laststart[1] |= 0x80; | |
2506 | |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2507 /* Store the character class flag bits into the range table. |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2508 If not in emacs, these flag bits are always 0. */ |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2509 *b++ = RANGE_TABLE_WORK_BITS (range_table_work) & 0xff; |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2510 *b++ = RANGE_TABLE_WORK_BITS (range_table_work) >> 8; |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
2511 |
939 | 2512 STORE_NUMBER_AND_INCR (b, used / 2); |
2513 for (i = 0; i < used; i++) | |
2514 STORE_CHARACTER_AND_INCR | |
2515 (b, RANGE_TABLE_WORK_ELT (range_table_work, i)); | |
2516 } | |
941 | 2517 } |
2518 break; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2519 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2520 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2521 case '(': |
941 | 2522 if (syntax & RE_NO_BK_PARENS) |
2523 goto handle_open; | |
2524 else | |
2525 goto normal_char; | |
2526 | |
2527 | |
2528 case ')': | |
2529 if (syntax & RE_NO_BK_PARENS) | |
2530 goto handle_close; | |
2531 else | |
2532 goto normal_char; | |
2533 | |
2534 | |
2535 case '\n': | |
2536 if (syntax & RE_NEWLINE_ALT) | |
2537 goto handle_alt; | |
2538 else | |
2539 goto normal_char; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2540 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2541 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2542 case '|': |
941 | 2543 if (syntax & RE_NO_BK_VBAR) |
2544 goto handle_alt; | |
2545 else | |
2546 goto normal_char; | |
2547 | |
2548 | |
2549 case '{': | |
2550 if (syntax & RE_INTERVALS && syntax & RE_NO_BK_BRACES) | |
2551 goto handle_interval; | |
2552 else | |
2553 goto normal_char; | |
2554 | |
2555 | |
2556 case '\\': | |
2557 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE); | |
2558 | |
2559 /* Do not translate the character after the \, so that we can | |
2560 distinguish, e.g., \B from \b, even if we normally would | |
2561 translate, e.g., B to b. */ | |
2562 PATFETCH_RAW (c); | |
2563 | |
2564 switch (c) | |
2565 { | |
2566 case '(': | |
2567 if (syntax & RE_NO_BK_PARENS) | |
2568 goto normal_backslash; | |
2569 | |
2570 handle_open: | |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2571 { |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2572 int shy = 0; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2573 if (p+1 < pend) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2574 { |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2575 /* Look for a special (?...) construct */ |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2576 if ((syntax & RE_SHY_GROUPS) && *p == '?') |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2577 { |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2578 PATFETCH (c); /* Gobble up the '?'. */ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2579 PATFETCH (c); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2580 switch (c) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2581 { |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2582 case ':': shy = 1; break; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2583 default: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2584 /* Only (?:...) is supported right now. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2585 FREE_STACK_RETURN (REG_BADPAT); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2586 } |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2587 } |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2588 } |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2589 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2590 if (!shy) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2591 { |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2592 bufp->re_nsub++; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2593 regnum++; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2594 } |
941 | 2595 |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2596 if (COMPILE_STACK_FULL) |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2597 { |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2598 RETALLOC (compile_stack.stack, compile_stack.size << 1, |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2599 compile_stack_elt_t); |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2600 if (compile_stack.stack == NULL) return REG_ESPACE; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2601 |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2602 compile_stack.size <<= 1; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2603 } |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2604 |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2605 /* These are the values to restore when we hit end of this |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2606 group. They are all relative offsets, so that if the |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2607 whole pattern moves because of realloc, they will still |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2608 be valid. */ |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2609 COMPILE_STACK_TOP.begalt_offset = begalt - bufp->buffer; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2610 COMPILE_STACK_TOP.fixup_alt_jump |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2611 = fixup_alt_jump ? fixup_alt_jump - bufp->buffer + 1 : 0; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2612 COMPILE_STACK_TOP.laststart_offset = b - bufp->buffer; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2613 COMPILE_STACK_TOP.regnum = shy ? -regnum : regnum; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2614 |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2615 /* Do not push a |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2616 start_memory for groups beyond the last one we can |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2617 represent in the compiled pattern. */ |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2618 if (regnum <= MAX_REGNUM && !shy) |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2619 BUF_PUSH_2 (start_memory, regnum); |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2620 |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2621 compile_stack.avail++; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2622 |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2623 fixup_alt_jump = 0; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2624 laststart = 0; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2625 begalt = b; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2626 /* If we've reached MAX_REGNUM groups, then this open |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2627 won't actually generate any code, so we'll have to |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2628 clear pending_exact explicitly. */ |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2629 pending_exact = 0; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2630 break; |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2631 } |
941 | 2632 |
2633 case ')': | |
2634 if (syntax & RE_NO_BK_PARENS) goto normal_backslash; | |
2635 | |
2636 if (COMPILE_STACK_EMPTY) | |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2637 { |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2638 if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2639 goto normal_backslash; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2640 else |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2641 FREE_STACK_RETURN (REG_ERPAREN); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2642 } |
941 | 2643 |
2644 handle_close: | |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2645 FIXUP_ALT_JUMP (); |
941 | 2646 |
2647 /* See similar code for backslashed left paren above. */ | |
2648 if (COMPILE_STACK_EMPTY) | |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2649 { |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2650 if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2651 goto normal_char; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2652 else |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2653 FREE_STACK_RETURN (REG_ERPAREN); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2654 } |
941 | 2655 |
2656 /* Since we just checked for an empty stack above, this | |
2657 ``can't happen''. */ | |
2658 assert (compile_stack.avail != 0); | |
2659 { | |
2660 /* We don't just want to restore into `regnum', because | |
2661 later groups should continue to be numbered higher, | |
2662 as in `(ab)c(de)' -- the second group is #2. */ | |
2663 regnum_t this_group_regnum; | |
2664 | |
2665 compile_stack.avail--; | |
2666 begalt = bufp->buffer + COMPILE_STACK_TOP.begalt_offset; | |
2667 fixup_alt_jump | |
2668 = COMPILE_STACK_TOP.fixup_alt_jump | |
2669 ? bufp->buffer + COMPILE_STACK_TOP.fixup_alt_jump - 1 | |
2670 : 0; | |
2671 laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset; | |
2672 this_group_regnum = COMPILE_STACK_TOP.regnum; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2673 /* If we've reached MAX_REGNUM groups, then this open |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2674 won't actually generate any code, so we'll have to |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2675 clear pending_exact explicitly. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2676 pending_exact = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2677 |
941 | 2678 /* We're at the end of the group, so now we know how many |
2679 groups were inside this one. */ | |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2680 if (this_group_regnum <= MAX_REGNUM && this_group_regnum > 0) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2681 BUF_PUSH_2 (stop_memory, this_group_regnum); |
941 | 2682 } |
2683 break; | |
2684 | |
2685 | |
2686 case '|': /* `\|'. */ | |
2687 if (syntax & RE_LIMITED_OPS || syntax & RE_NO_BK_VBAR) | |
2688 goto normal_backslash; | |
2689 handle_alt: | |
2690 if (syntax & RE_LIMITED_OPS) | |
2691 goto normal_char; | |
2692 | |
2693 /* Insert before the previous alternative a jump which | |
2694 jumps to this alternative if the former fails. */ | |
2695 GET_BUFFER_SPACE (3); | |
2696 INSERT_JUMP (on_failure_jump, begalt, b + 6); | |
2697 pending_exact = 0; | |
2698 b += 3; | |
2699 | |
2700 /* The alternative before this one has a jump after it | |
2701 which gets executed if it gets matched. Adjust that | |
2702 jump so it will jump to this alternative's analogous | |
2703 jump (put in below, which in turn will jump to the next | |
2704 (if any) alternative's such jump, etc.). The last such | |
2705 jump jumps to the correct final destination. A picture: | |
2706 _____ _____ | |
2707 | | | | | |
2708 | v | v | |
2709 a | b | c | |
2710 | |
2711 If we are at `b', then fixup_alt_jump right now points to a | |
2712 three-byte space after `a'. We'll put in the jump, set | |
2713 fixup_alt_jump to right after `b', and leave behind three | |
2714 bytes which we'll fill in when we get to after `c'. */ | |
2715 | |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
2716 FIXUP_ALT_JUMP (); |
941 | 2717 |
2718 /* Mark and leave space for a jump after this alternative, | |
2719 to be filled in later either by next alternative or | |
2720 when know we're at the end of a series of alternatives. */ | |
2721 fixup_alt_jump = b; | |
2722 GET_BUFFER_SPACE (3); | |
2723 b += 3; | |
2724 | |
2725 laststart = 0; | |
2726 begalt = b; | |
2727 break; | |
2728 | |
2729 | |
2730 case '{': | |
2731 /* If \{ is a literal. */ | |
2732 if (!(syntax & RE_INTERVALS) | |
2733 /* If we're at `\{' and it's not the open-interval | |
2734 operator. */ | |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2735 || (syntax & RE_NO_BK_BRACES) |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2736 /* What is that? -sm */ |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2737 /* || (p - 2 == pattern && p == pend) */) |
941 | 2738 goto normal_backslash; |
2739 | |
2740 handle_interval: | |
2741 { | |
2742 /* If got here, then the syntax allows intervals. */ | |
2743 | |
2744 /* At least (most) this many matches must be made. */ | |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
2745 int lower_bound = 0, upper_bound = -1; |
941 | 2746 |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2747 beg_interval = p; |
941 | 2748 |
2749 if (p == pend) | |
2750 { | |
2751 if (syntax & RE_NO_BK_BRACES) | |
2752 goto unfetch_interval; | |
2753 else | |
2754 FREE_STACK_RETURN (REG_EBRACE); | |
2755 } | |
2756 | |
2757 GET_UNSIGNED_NUMBER (lower_bound); | |
2758 | |
2759 if (c == ',') | |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2760 GET_UNSIGNED_NUMBER (upper_bound); |
941 | 2761 else |
2762 /* Interval such as `{1}' => match exactly once. */ | |
2763 upper_bound = lower_bound; | |
2764 | |
2765 if (lower_bound < 0 || upper_bound > RE_DUP_MAX | |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2766 || (upper_bound >= 0 && lower_bound > upper_bound)) |
941 | 2767 { |
2768 if (syntax & RE_NO_BK_BRACES) | |
2769 goto unfetch_interval; | |
2770 else | |
2771 FREE_STACK_RETURN (REG_BADBR); | |
2772 } | |
2773 | |
2774 if (!(syntax & RE_NO_BK_BRACES)) | |
2775 { | |
2776 if (c != '\\') FREE_STACK_RETURN (REG_EBRACE); | |
2777 | |
2778 PATFETCH (c); | |
2779 } | |
2780 | |
2781 if (c != '}') | |
2782 { | |
2783 if (syntax & RE_NO_BK_BRACES) | |
2784 goto unfetch_interval; | |
2785 else | |
2786 FREE_STACK_RETURN (REG_BADBR); | |
2787 } | |
2788 | |
2789 /* We just parsed a valid interval. */ | |
2790 | |
2791 /* If it's invalid to have no preceding re. */ | |
2792 if (!laststart) | |
2793 { | |
2794 if (syntax & RE_CONTEXT_INVALID_OPS) | |
2795 FREE_STACK_RETURN (REG_BADRPT); | |
2796 else if (syntax & RE_CONTEXT_INDEP_OPS) | |
2797 laststart = b; | |
2798 else | |
2799 goto unfetch_interval; | |
2800 } | |
2801 | |
2802 if (upper_bound == 0) | |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2803 /* If the upper bound is zero, just drop the sub pattern |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2804 altogether. */ |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2805 b = laststart; |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2806 else if (lower_bound == 1 && upper_bound == 1) |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2807 /* Just match it once: nothing to do here. */ |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2808 ; |
941 | 2809 |
2810 /* Otherwise, we have a nontrivial interval. When | |
2811 we're all done, the pattern will look like: | |
2812 set_number_at <jump count> <upper bound> | |
2813 set_number_at <succeed_n count> <lower bound> | |
2814 succeed_n <after jump addr> <succeed_n count> | |
2815 <body of loop> | |
2816 jump_n <succeed_n addr> <jump count> | |
2817 (The upper bound and `jump_n' are omitted if | |
2818 `upper_bound' is 1, though.) */ | |
2819 else | |
2820 { /* If the upper bound is > 1, we need to insert | |
2821 more at the end of the loop. */ | |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2822 unsigned int nbytes = (upper_bound < 0 ? 3 |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2823 : upper_bound > 1 ? 5 : 0); |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2824 unsigned int startoffset = 0; |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2825 |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2826 GET_BUFFER_SPACE (20); /* We might use less. */ |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2827 |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2828 if (lower_bound == 0) |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2829 { |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2830 /* A succeed_n that starts with 0 is really a |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2831 a simple on_failure_jump_loop. */ |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2832 INSERT_JUMP (on_failure_jump_loop, laststart, |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2833 b + 3 + nbytes); |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2834 b += 3; |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2835 } |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2836 else |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2837 { |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2838 /* Initialize lower bound of the `succeed_n', even |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2839 though it will be set during matching by its |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2840 attendant `set_number_at' (inserted next), |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2841 because `re_compile_fastmap' needs to know. |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2842 Jump to the `jump_n' we might insert below. */ |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2843 INSERT_JUMP2 (succeed_n, laststart, |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2844 b + 5 + nbytes, |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2845 lower_bound); |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2846 b += 5; |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2847 |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2848 /* Code to initialize the lower bound. Insert |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2849 before the `succeed_n'. The `5' is the last two |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2850 bytes of this `set_number_at', plus 3 bytes of |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2851 the following `succeed_n'. */ |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2852 insert_op2 (set_number_at, laststart, 5, lower_bound, b); |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2853 b += 5; |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2854 startoffset += 5; |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2855 } |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2856 |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2857 if (upper_bound < 0) |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2858 { |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2859 /* A negative upper bound stands for infinity, |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2860 in which case it degenerates to a plain jump. */ |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2861 STORE_JUMP (jump, b, laststart + startoffset); |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2862 b += 3; |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2863 } |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2864 else if (upper_bound > 1) |
941 | 2865 { /* More than one repetition is allowed, so |
2866 append a backward jump to the `succeed_n' | |
2867 that starts this interval. | |
2868 | |
2869 When we've reached this during matching, | |
2870 we'll have matched the interval once, so | |
2871 jump back only `upper_bound - 1' times. */ | |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2872 STORE_JUMP2 (jump_n, b, laststart + startoffset, |
941 | 2873 upper_bound - 1); |
2874 b += 5; | |
2875 | |
2876 /* The location we want to set is the second | |
2877 parameter of the `jump_n'; that is `b-2' as | |
2878 an absolute address. `laststart' will be | |
2879 the `set_number_at' we're about to insert; | |
2880 `laststart+3' the number to set, the source | |
2881 for the relative address. But we are | |
2882 inserting into the middle of the pattern -- | |
2883 so everything is getting moved up by 5. | |
2884 Conclusion: (b - 2) - (laststart + 3) + 5, | |
2885 i.e., b - laststart. | |
2886 | |
2887 We insert this at the beginning of the loop | |
2888 so that if we fail during matching, we'll | |
2889 reinitialize the bounds. */ | |
2890 insert_op2 (set_number_at, laststart, b - laststart, | |
2891 upper_bound - 1, b); | |
2892 b += 5; | |
2893 } | |
2894 } | |
2895 pending_exact = 0; | |
2896 beg_interval = NULL; | |
2897 } | |
2898 break; | |
2899 | |
2900 unfetch_interval: | |
2901 /* If an invalid interval, match the characters as literals. */ | |
2902 assert (beg_interval); | |
2903 p = beg_interval; | |
2904 beg_interval = NULL; | |
2905 | |
2906 /* normal_char and normal_backslash need `c'. */ | |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2907 c = '{'; |
941 | 2908 |
2909 if (!(syntax & RE_NO_BK_BRACES)) | |
2910 { | |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2911 assert (p > pattern && p[-1] == '\\'); |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2912 goto normal_backslash; |
941 | 2913 } |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2914 else |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
2915 goto normal_char; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2916 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2917 #ifdef emacs |
941 | 2918 /* There is no way to specify the before_dot and after_dot |
2919 operators. rms says this is ok. --karl */ | |
2920 case '=': | |
2921 BUF_PUSH (at_dot); | |
2922 break; | |
2923 | |
2924 case 's': | |
2925 laststart = b; | |
2926 PATFETCH (c); | |
2927 BUF_PUSH_2 (syntaxspec, syntax_spec_code[c]); | |
2928 break; | |
2929 | |
2930 case 'S': | |
2931 laststart = b; | |
2932 PATFETCH (c); | |
2933 BUF_PUSH_2 (notsyntaxspec, syntax_spec_code[c]); | |
2934 break; | |
939 | 2935 |
2936 case 'c': | |
679 | 2937 laststart = b; |
939 | 2938 PATFETCH_RAW (c); |
2939 BUF_PUSH_2 (categoryspec, c); | |
679 | 2940 break; |
2941 | |
939 | 2942 case 'C': |
679 | 2943 laststart = b; |
939 | 2944 PATFETCH_RAW (c); |
2945 BUF_PUSH_2 (notcategoryspec, c); | |
679 | 2946 break; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2947 #endif /* emacs */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2948 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
2949 |
941 | 2950 case 'w': |
2951 laststart = b; | |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
2952 BUF_PUSH_2 (syntaxspec, Sword); |
941 | 2953 break; |
2954 | |
2955 | |
2956 case 'W': | |
2957 laststart = b; | |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
2958 BUF_PUSH_2 (notsyntaxspec, Sword); |
941 | 2959 break; |
2960 | |
2961 | |
2962 case '<': | |
2963 BUF_PUSH (wordbeg); | |
2964 break; | |
2965 | |
2966 case '>': | |
2967 BUF_PUSH (wordend); | |
2968 break; | |
2969 | |
2970 case 'b': | |
2971 BUF_PUSH (wordbound); | |
2972 break; | |
2973 | |
2974 case 'B': | |
2975 BUF_PUSH (notwordbound); | |
2976 break; | |
2977 | |
2978 case '`': | |
2979 BUF_PUSH (begbuf); | |
2980 break; | |
2981 | |
2982 case '\'': | |
2983 BUF_PUSH (endbuf); | |
2984 break; | |
2985 | |
2986 case '1': case '2': case '3': case '4': case '5': | |
2987 case '6': case '7': case '8': case '9': | |
2988 if (syntax & RE_NO_BK_REFS) | |
2989 goto normal_char; | |
2990 | |
2991 c1 = c - '0'; | |
2992 | |
2993 if (c1 > regnum) | |
2994 FREE_STACK_RETURN (REG_ESUBREG); | |
2995 | |
2996 /* Can't back reference to a subexpression if inside of it. */ | |
2997 if (group_in_compile_stack (compile_stack, c1)) | |
2998 goto normal_char; | |
2999 | |
3000 laststart = b; | |
3001 BUF_PUSH_2 (duplicate, c1); | |
3002 break; | |
3003 | |
3004 | |
3005 case '+': | |
3006 case '?': | |
3007 if (syntax & RE_BK_PLUS_QM) | |
3008 goto handle_plus; | |
3009 else | |
3010 goto normal_backslash; | |
3011 | |
3012 default: | |
3013 normal_backslash: | |
3014 /* You might think it would be useful for \ to mean | |
3015 not to translate; but if we don't translate it | |
3016 it will never match anything. */ | |
3017 c = TRANSLATE (c); | |
3018 goto normal_char; | |
3019 } | |
3020 break; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3021 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3022 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3023 default: |
941 | 3024 /* Expects the character in `c'. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3025 normal_char: |
939 | 3026 p1 = p - 1; /* P1 points the head of C. */ |
3027 #ifdef emacs | |
3028 if (bufp->multibyte) | |
1545
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3029 { |
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3030 c = STRING_CHAR (p1, pend - p1); |
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3031 c = TRANSLATE (c); |
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3032 /* Set P to the next character boundary. */ |
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3033 p += MULTIBYTE_FORM_LENGTH (p1, pend - p1) - 1; |
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3034 } |
939 | 3035 #endif |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3036 /* If no exactn currently being built. */ |
941 | 3037 if (!pending_exact |
3038 | |
3039 /* If last exactn not at current position. */ | |
3040 || pending_exact + *pending_exact + 1 != b | |
3041 | |
3042 /* We have only one byte following the exactn for the count. */ | |
939 | 3043 || *pending_exact >= (1 << BYTEWIDTH) - (p - p1) |
3044 | |
941 | 3045 /* If followed by a repetition operator. */ |
1342
e5cbc689bc64
(regex_compile): When checking after exactn
Richard Stallman <rms@gnu.org>
parents:
1335
diff
changeset
|
3046 || (p != pend && (*p == '*' || *p == '^')) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3047 || ((syntax & RE_BK_PLUS_QM) |
1342
e5cbc689bc64
(regex_compile): When checking after exactn
Richard Stallman <rms@gnu.org>
parents:
1335
diff
changeset
|
3048 ? p + 1 < pend && *p == '\\' && (p[1] == '+' || p[1] == '?') |
e5cbc689bc64
(regex_compile): When checking after exactn
Richard Stallman <rms@gnu.org>
parents:
1335
diff
changeset
|
3049 : p != pend && (*p == '+' || *p == '?')) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3050 || ((syntax & RE_INTERVALS) |
941 | 3051 && ((syntax & RE_NO_BK_BRACES) |
1342
e5cbc689bc64
(regex_compile): When checking after exactn
Richard Stallman <rms@gnu.org>
parents:
1335
diff
changeset
|
3052 ? p != pend && *p == '{' |
e5cbc689bc64
(regex_compile): When checking after exactn
Richard Stallman <rms@gnu.org>
parents:
1335
diff
changeset
|
3053 : p + 1 < pend && p[0] == '\\' && p[1] == '{'))) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3054 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3055 /* Start building a new exactn. */ |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3056 |
941 | 3057 laststart = b; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3058 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3059 BUF_PUSH_2 (exactn, 0); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3060 pending_exact = b - 1; |
941 | 3061 } |
939 | 3062 |
1545
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3063 #ifdef emacs |
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3064 if (! SINGLE_BYTE_CHAR_P (c)) |
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3065 { |
2034
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
3066 unsigned char str[MAX_MULTIBYTE_LENGTH]; |
00db7733320d
1999-12-15 Kenichi Handa <handa@etl.go.jp>
Dave Love <fx@gnu.org>
parents:
1972
diff
changeset
|
3067 int i = CHAR_STRING (c, str); |
1545
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3068 int j; |
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3069 for (j = 0; j < i; j++) |
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3070 { |
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3071 BUF_PUSH (str[j]); |
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3072 (*pending_exact)++; |
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3073 } |
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3074 } |
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3075 else |
84951ef7a5ed
(regex_compile): Handle translation of multibyte
Karl Heuer <kwzh@gnu.org>
parents:
1440
diff
changeset
|
3076 #endif |
939 | 3077 { |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3078 BUF_PUSH (c); |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3079 (*pending_exact)++; |
939 | 3080 } |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3081 break; |
941 | 3082 } /* switch (c) */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3083 } /* while p != pend */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3084 |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3085 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3086 /* Through the pattern now. */ |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3087 |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3088 FIXUP_ALT_JUMP (); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3089 |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3090 if (!COMPILE_STACK_EMPTY) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3091 FREE_STACK_RETURN (REG_EPAREN); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3092 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3093 /* If we don't want backtracking, force success |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3094 the first time we reach the end of the compiled pattern. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3095 if (syntax & RE_NO_POSIX_BACKTRACKING) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3096 BUF_PUSH (succeed); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3097 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3098 free (compile_stack.stack); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3099 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3100 /* We have succeeded; set the length of the buffer. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3101 bufp->used = b - bufp->buffer; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3102 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3103 #ifdef DEBUG |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
3104 if (debug > 0) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3105 { |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3106 re_compile_fastmap (bufp); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3107 DEBUG_PRINT1 ("\nCompiled pattern: \n"); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3108 print_compiled_pattern (bufp); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3109 } |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
3110 debug--; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3111 #endif /* DEBUG */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3112 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3113 #ifndef MATCH_MAY_ALLOCATE |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3114 /* Initialize the failure stack to the largest possible stack. This |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3115 isn't necessary unless we're trying to avoid calling alloca in |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3116 the search and match routines. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3117 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3118 int num_regs = bufp->re_nsub + 1; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3119 |
1156
8e1cbb305ddc
(TYPICAL_FAILURE_SIZE): Renamed from MAX_FAILURE_ITEMS.
Karl Heuer <kwzh@gnu.org>
parents:
992
diff
changeset
|
3120 if (fail_stack.size < re_max_failures * TYPICAL_FAILURE_SIZE) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3121 { |
1297
ac5117571763
(regex_compile) [!MATCH_MAY_ALLOCATE]: Fix paren error.
Richard Stallman <rms@gnu.org>
parents:
1296
diff
changeset
|
3122 fail_stack.size = re_max_failures * TYPICAL_FAILURE_SIZE; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3123 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3124 if (! fail_stack.stack) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3125 fail_stack.stack |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3126 = (fail_stack_elt_t *) malloc (fail_stack.size |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3127 * sizeof (fail_stack_elt_t)); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3128 else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3129 fail_stack.stack |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3130 = (fail_stack_elt_t *) realloc (fail_stack.stack, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3131 (fail_stack.size |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3132 * sizeof (fail_stack_elt_t))); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3133 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3134 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3135 regex_grow_registers (num_regs); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3136 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3137 #endif /* not MATCH_MAY_ALLOCATE */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3138 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3139 return REG_NOERROR; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3140 } /* regex_compile */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3141 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3142 /* Subroutines for `regex_compile'. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3143 |
941 | 3144 /* Store OP at LOC followed by two-byte integer parameter ARG. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3145 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3146 static void |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3147 store_op1 (op, loc, arg) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3148 re_opcode_t op; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3149 unsigned char *loc; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3150 int arg; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3151 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3152 *loc = (unsigned char) op; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3153 STORE_NUMBER (loc + 1, arg); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3154 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3155 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3156 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3157 /* Like `store_op1', but for two two-byte parameters ARG1 and ARG2. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3158 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3159 static void |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3160 store_op2 (op, loc, arg1, arg2) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3161 re_opcode_t op; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3162 unsigned char *loc; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3163 int arg1, arg2; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3164 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3165 *loc = (unsigned char) op; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3166 STORE_NUMBER (loc + 1, arg1); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3167 STORE_NUMBER (loc + 3, arg2); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3168 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3169 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3170 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3171 /* Copy the bytes from LOC to END to open up three bytes of space at LOC |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3172 for OP followed by two-byte integer parameter ARG. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3173 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3174 static void |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3175 insert_op1 (op, loc, arg, end) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3176 re_opcode_t op; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3177 unsigned char *loc; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3178 int arg; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3179 unsigned char *end; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3180 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3181 register unsigned char *pfrom = end; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3182 register unsigned char *pto = end + 3; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3183 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3184 while (pfrom != loc) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3185 *--pto = *--pfrom; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3186 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3187 store_op1 (op, loc, arg); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3188 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3189 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3190 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3191 /* Like `insert_op1', but for two two-byte parameters ARG1 and ARG2. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3192 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3193 static void |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3194 insert_op2 (op, loc, arg1, arg2, end) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3195 re_opcode_t op; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3196 unsigned char *loc; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3197 int arg1, arg2; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3198 unsigned char *end; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3199 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3200 register unsigned char *pfrom = end; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3201 register unsigned char *pto = end + 5; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3202 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3203 while (pfrom != loc) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3204 *--pto = *--pfrom; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3205 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3206 store_op2 (op, loc, arg1, arg2); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3207 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3208 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3209 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3210 /* P points to just after a ^ in PATTERN. Return true if that ^ comes |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3211 after an alternative or a begin-subexpression. We assume there is at |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3212 least one character before the ^. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3213 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3214 static boolean |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3215 at_begline_loc_p (pattern, p, syntax) |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
3216 const unsigned char *pattern, *p; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3217 reg_syntax_t syntax; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3218 { |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
3219 const unsigned char *prev = p - 2; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3220 boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\'; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3221 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3222 return |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3223 /* After a subexpression? */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3224 (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash)) |
941 | 3225 /* After an alternative? */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3226 || (*prev == '|' && (syntax & RE_NO_BK_VBAR || prev_prev_backslash)); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3227 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3228 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3229 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3230 /* The dual of at_begline_loc_p. This one is for $. We assume there is |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3231 at least one character after the $, i.e., `P < PEND'. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3232 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3233 static boolean |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3234 at_endline_loc_p (p, pend, syntax) |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
3235 const unsigned char *p, *pend; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
3236 reg_syntax_t syntax; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3237 { |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
3238 const unsigned char *next = p; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3239 boolean next_backslash = *next == '\\'; |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
3240 const unsigned char *next_next = p + 1 < pend ? p + 1 : 0; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3241 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3242 return |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3243 /* Before a subexpression? */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3244 (syntax & RE_NO_BK_PARENS ? *next == ')' |
941 | 3245 : next_backslash && next_next && *next_next == ')') |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3246 /* Before an alternative? */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3247 || (syntax & RE_NO_BK_VBAR ? *next == '|' |
941 | 3248 : next_backslash && next_next && *next_next == '|'); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3249 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3250 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3251 |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3252 /* Returns true if REGNUM is in one of COMPILE_STACK's elements and |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3253 false if it's not. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3254 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3255 static boolean |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3256 group_in_compile_stack (compile_stack, regnum) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3257 compile_stack_type compile_stack; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3258 regnum_t regnum; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3259 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3260 int this_element; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3261 |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3262 for (this_element = compile_stack.avail - 1; |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3263 this_element >= 0; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3264 this_element--) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3265 if (compile_stack.stack[this_element].regnum == regnum) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3266 return true; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3267 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3268 return false; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3269 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3270 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3271 /* re_compile_fastmap computes a ``fastmap'' for the compiled pattern in |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3272 BUFP. A fastmap records which of the (1 << BYTEWIDTH) possible |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3273 characters can start a string that matches the pattern. This fastmap |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3274 is used by re_search to skip quickly over impossible starting points. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3275 |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
3276 Character codes above (1 << BYTEWIDTH) are not represented in the |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
3277 fastmap, but the leading codes are represented. Thus, the fastmap |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
3278 indicates which character sets could start a match. |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
3279 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3280 The caller must supply the address of a (1 << BYTEWIDTH)-byte data |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3281 area as BUFP->fastmap. |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3282 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3283 We set the `fastmap', `fastmap_accurate', and `can_be_null' fields in |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3284 the pattern buffer. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3285 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3286 Returns 0 if we succeed, -2 if an internal error. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3287 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3288 int |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3289 re_compile_fastmap (bufp) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3290 struct re_pattern_buffer *bufp; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3291 { |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3292 int j, k; |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3293 boolean not; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3294 #ifdef MATCH_MAY_ALLOCATE |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3295 fail_stack_type fail_stack; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3296 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3297 #ifndef REGEX_MALLOC |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3298 char *destination; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3299 #endif |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3300 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3301 register char *fastmap = bufp->fastmap; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3302 unsigned char *pattern = bufp->buffer; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3303 unsigned long size = bufp->used; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3304 unsigned char *p = pattern; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3305 register unsigned char *pend = pattern + size; |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3306 const boolean multibyte = bufp->multibyte; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3307 |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
3308 #if defined (REL_ALLOC) && defined (REGEX_MALLOC) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3309 /* This holds the pointer to the failure stack, when |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3310 it is allocated relocatably. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3311 fail_stack_elt_t *failure_stack_ptr; |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
3312 #endif |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3313 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3314 /* Assume that each path through the pattern can be null until |
941 | 3315 proven otherwise. We set this false at the bottom of switch |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3316 statement, to which we get only if a particular path doesn't |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3317 match the empty string. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3318 boolean path_can_be_null = true; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3319 |
939 | 3320 /* If all elements for base leading-codes in fastmap is set, this |
941 | 3321 flag is set true. */ |
939 | 3322 boolean match_any_multibyte_characters = false; |
3323 | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3324 assert (fastmap != NULL && p != NULL); |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3325 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3326 INIT_FAIL_STACK (); |
941 | 3327 bzero (fastmap, 1 << BYTEWIDTH); /* Assume nothing's valid. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3328 bufp->fastmap_accurate = 1; /* It will be when we're done. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3329 bufp->can_be_null = 0; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3330 |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3331 /* The loop below works as follows: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3332 - It has a working-list kept in the PATTERN_STACK and which basically |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3333 starts by only containing a pointer to the first operation. |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3334 - If the opcode we're looking at is a match against some set of |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3335 chars, then we add those chars to the fastmap and go on to the |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3336 next work element from the worklist (done via `break'). |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3337 - If the opcode is a control operator on the other hand, we either |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3338 ignore it (if it's meaningless at this point, such as `start_memory') |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3339 or execute it (if it's a jump). If the jump has several destinations |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3340 (i.e. `on_failure_jump'), then we push the other destination onto the |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3341 worklist. |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3342 We guarantee termination by ignoring backward jumps (more or less), |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3343 so that `p' is monotonically increasing. More to the point, we |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3344 never set `p' (or push) anything `<= p1'. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3345 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3346 /* If can_be_null is set, then the fastmap will not be used anyway. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3347 while (!bufp->can_be_null) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3348 { |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3349 /* `p1' is used as a marker of how far back a `on_failure_jump' |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3350 can go without being ignored. It is normally equal to `p' |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3351 (which prevents any backward `on_failure_jump') except right |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3352 after a plain `jump', to allow patterns such as: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3353 0: jump 10 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3354 3..9: <body> |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3355 10: on_failure_jump 3 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3356 as used for the *? operator. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3357 unsigned char *p1 = p; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3358 |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3359 if (p >= pend || *p == succeed) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3360 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3361 /* We have reached the (effective) end of pattern. */ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3362 if (!PATTERN_STACK_EMPTY ()) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3363 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3364 bufp->can_be_null |= path_can_be_null; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3365 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3366 /* Reset for next path. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3367 path_can_be_null = true; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3368 |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
3369 p = (unsigned char*) POP_PATTERN_OP (); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3370 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3371 continue; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3372 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3373 else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3374 break; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3375 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3376 |
941 | 3377 /* We should never be about to go beyond the end of the pattern. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3378 assert (p < pend); |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3379 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3380 switch (SWITCH_ENUM_CAST ((re_opcode_t) *p++)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3381 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3382 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3383 case duplicate: |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3384 /* If the first character has to match a backreference, that means |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3385 that the group was empty (since it already matched). Since this |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3386 is the only case that interests us here, we can assume that the |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3387 backreference must match the empty string. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3388 p++; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3389 continue; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3390 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3391 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3392 /* Following are the cases which match a character. These end |
941 | 3393 with `break'. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3394 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3395 case exactn: |
941 | 3396 fastmap[p[1]] = 1; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3397 break; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3398 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3399 |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3400 case anychar: |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3401 /* We could put all the chars except for \n (and maybe \0) |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3402 but we don't bother since it is generally not worth it. */ |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3403 bufp->can_be_null = 1; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3404 continue; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3405 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3406 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3407 case charset_not: |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3408 /* Chars beyond end of bitmap are possible matches. |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3409 All the single-byte codes can occur in multibyte buffers. |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3410 So any that are not listed in the charset |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3411 are possible matches, even in multibyte buffers. */ |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3412 if (!fastmap) break; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3413 for (j = CHARSET_BITMAP_SIZE (&p[-1]) * BYTEWIDTH; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3414 j < (1 << BYTEWIDTH); j++) |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3415 fastmap[j] = 1; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3416 /* Fallthrough */ |
939 | 3417 case charset: |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3418 if (!fastmap) break; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3419 not = (re_opcode_t) *(p - 1) == charset_not; |
939 | 3420 for (j = CHARSET_BITMAP_SIZE (&p[-1]) * BYTEWIDTH - 1, p++; |
3421 j >= 0; j--) | |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3422 if (!!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))) ^ not) |
939 | 3423 fastmap[j] = 1; |
3424 | |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3425 if ((not && multibyte) |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3426 /* Any character set can possibly contain a character |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3427 which doesn't match the specified set of characters. */ |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3428 || (CHARSET_RANGE_TABLE_EXISTS_P (&p[-2]) |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3429 && CHARSET_RANGE_TABLE_BITS (&p[-2]) != 0)) |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3430 /* If we can match a character class, we can match |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3431 any character set. */ |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3432 { |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3433 set_fastmap_for_multibyte_characters: |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3434 if (match_any_multibyte_characters == false) |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3435 { |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3436 for (j = 0x80; j < 0xA0; j++) /* XXX */ |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3437 if (BASE_LEADING_CODE_P (j)) |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3438 fastmap[j] = 1; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3439 match_any_multibyte_characters = true; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3440 } |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3441 } |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3442 |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3443 else if (!not && CHARSET_RANGE_TABLE_EXISTS_P (&p[-2]) |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3444 && match_any_multibyte_characters == false) |
939 | 3445 { |
3446 /* Set fastmap[I] 1 where I is a base leading code of each | |
3447 multibyte character in the range table. */ | |
3448 int c, count; | |
3449 | |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3450 /* Make P points the range table. `+ 2' is to skip flag |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3451 bits for a character class. */ |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3452 p += CHARSET_BITMAP_SIZE (&p[-2]) + 2; |
939 | 3453 |
1965
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
3454 /* Extract the number of ranges in range table into COUNT. */ |
939 | 3455 EXTRACT_NUMBER_AND_INCR (count, p); |
3456 for (; count > 0; count--, p += 2 * 3) /* XXX */ | |
3457 { | |
3458 /* Extract the start of each range. */ | |
3459 EXTRACT_CHARACTER (c, p); | |
3460 j = CHAR_CHARSET (c); | |
3461 fastmap[CHARSET_LEADING_CODE_BASE (j)] = 1; | |
3462 } | |
3463 } | |
3464 break; | |
3465 | |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3466 case syntaxspec: |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3467 case notsyntaxspec: |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3468 if (!fastmap) break; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3469 #ifndef emacs |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3470 not = (re_opcode_t)p[-1] == notsyntaxspec; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3471 k = *p++; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3472 for (j = 0; j < (1 << BYTEWIDTH); j++) |
2359
dbf725277cfc
(enum syntaxcode): Provide default for non-Emacs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2357
diff
changeset
|
3473 if ((SYNTAX (j) == (enum syntaxcode) k) ^ not) |
939 | 3474 fastmap[j] = 1; |
3475 break; | |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3476 #else /* emacs */ |
939 | 3477 /* This match depends on text properties. These end with |
3478 aborting optimizations. */ | |
3479 bufp->can_be_null = 1; | |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3480 continue; |
939 | 3481 |
3482 case categoryspec: | |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3483 case notcategoryspec: |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3484 if (!fastmap) break; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3485 not = (re_opcode_t)p[-1] == notcategoryspec; |
939 | 3486 k = *p++; |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3487 for (j = 0; j < (1 << BYTEWIDTH); j++) |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3488 if ((CHAR_HAS_CATEGORY (j, k)) ^ not) |
939 | 3489 fastmap[j] = 1; |
3490 | |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3491 if (multibyte) |
939 | 3492 /* Any character set can possibly contain a character |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3493 whose category is K (or not). */ |
939 | 3494 goto set_fastmap_for_multibyte_characters; |
3495 break; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3496 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3497 /* All cases after this match the empty string. These end with |
941 | 3498 `continue'. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3499 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3500 case before_dot: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3501 case at_dot: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3502 case after_dot: |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
3503 #endif /* !emacs */ |
941 | 3504 case no_op: |
3505 case begline: | |
3506 case endline: | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3507 case begbuf: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3508 case endbuf: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3509 case wordbound: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3510 case notwordbound: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3511 case wordbeg: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3512 case wordend: |
941 | 3513 continue; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3514 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3515 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3516 case jump: |
941 | 3517 EXTRACT_NUMBER_AND_INCR (j, p); |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3518 if (j < 0) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3519 /* Backward jumps can only go back to code that we've already |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3520 visited. `re_compile' should make sure this is true. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3521 break; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3522 p += j; |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3523 switch (SWITCH_ENUM_CAST ((re_opcode_t) *p)) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3524 { |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3525 case on_failure_jump: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3526 case on_failure_keep_string_jump: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3527 case on_failure_jump_loop: |
2370
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
3528 case on_failure_jump_nastyloop: |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3529 case on_failure_jump_smart: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3530 p++; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3531 break; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3532 default: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3533 continue; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3534 }; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3535 /* Keep `p1' to allow the `on_failure_jump' we are jumping to |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3536 to jump back to "just after here". */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3537 /* Fallthrough */ |
941 | 3538 |
3539 case on_failure_jump: | |
3540 case on_failure_keep_string_jump: | |
2370
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
3541 case on_failure_jump_nastyloop: |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3542 case on_failure_jump_loop: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3543 case on_failure_jump_smart: |
941 | 3544 EXTRACT_NUMBER_AND_INCR (j, p); |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3545 if (p + j <= p1) |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3546 ; /* Backward jump to be ignored. */ |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3547 else if (!PUSH_PATTERN_OP (p + j, fail_stack)) |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3548 return (RESET_FAIL_STACK (), -2); |
941 | 3549 continue; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3550 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3551 |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3552 case jump_n: |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3553 /* This code simply does not properly handle forward jump_n. */ |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3554 DEBUG_STATEMENT (EXTRACT_NUMBER (j, p); assert (j < 0)); |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3555 p += 4; |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3556 /* jump_n can either jump or fall through. The (backward) jump |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3557 case has already been handled, so we only need to look at the |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3558 fallthrough case. */ |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3559 continue; |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3560 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3561 case succeed_n: |
2371
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3562 /* If N == 0, it should be an on_failure_jump_loop instead. */ |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3563 DEBUG_STATEMENT (EXTRACT_NUMBER (j, p + 2); assert (j > 0)); |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3564 p += 4; |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3565 /* We only care about one iteration of the loop, so we don't |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3566 need to consider the case where this behaves like an |
3274fb530385
(REGEX_FREE_STACK, RESET_FAIL_STACK): Make them usable as an expression.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2370
diff
changeset
|
3567 on_failure_jump. */ |
941 | 3568 continue; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3569 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3570 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3571 case set_number_at: |
941 | 3572 p += 4; |
3573 continue; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3574 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3575 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3576 case start_memory: |
941 | 3577 case stop_memory: |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3578 p += 1; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3579 continue; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3580 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3581 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3582 default: |
941 | 3583 abort (); /* We have listed all the cases. */ |
3584 } /* switch *p++ */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3585 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3586 /* Getting here means we have found the possible starting |
941 | 3587 characters for one path of the pattern -- and that the empty |
3588 string does not match. We need not follow this path further. | |
3589 Instead, look at the next alternative (remembered on the | |
3590 stack), or quit if no more. The test at the top of the loop | |
3591 does these things. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3592 path_can_be_null = false; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3593 p = pend; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3594 } /* while p */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3595 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3596 /* Set `can_be_null' for the last path (also the first path, if the |
941 | 3597 pattern is empty). */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3598 bufp->can_be_null |= path_can_be_null; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3599 RESET_FAIL_STACK (); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3600 return 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3601 } /* re_compile_fastmap */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3602 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3603 /* Set REGS to hold NUM_REGS registers, storing them in STARTS and |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3604 ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3605 this memory for recording register information. STARTS and ENDS |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3606 must be allocated using the malloc library routine, and must each |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3607 be at least NUM_REGS * sizeof (regoff_t) bytes long. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3608 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3609 If NUM_REGS == 0, then subsequent matches should allocate their own |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3610 register data. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3611 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3612 Unless this function is called, the first search or match using |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3613 PATTERN_BUFFER will allocate its own register data, without |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3614 freeing the old data. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3615 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3616 void |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3617 re_set_registers (bufp, regs, num_regs, starts, ends) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3618 struct re_pattern_buffer *bufp; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3619 struct re_registers *regs; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3620 unsigned num_regs; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3621 regoff_t *starts, *ends; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3622 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3623 if (num_regs) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3624 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3625 bufp->regs_allocated = REGS_REALLOCATE; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3626 regs->num_regs = num_regs; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3627 regs->start = starts; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3628 regs->end = ends; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3629 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3630 else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3631 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3632 bufp->regs_allocated = REGS_UNALLOCATED; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3633 regs->num_regs = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3634 regs->start = regs->end = (regoff_t *) 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3635 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3636 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3637 |
941 | 3638 /* Searching routines. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3639 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3640 /* Like re_search_2, below, but only one string is specified, and |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3641 doesn't let you say where to stop matching. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3642 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3643 int |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3644 re_search (bufp, string, size, startpos, range, regs) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3645 struct re_pattern_buffer *bufp; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3646 const char *string; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3647 int size, startpos, range; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3648 struct re_registers *regs; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3649 { |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3650 return re_search_2 (bufp, NULL, 0, string, size, startpos, range, |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3651 regs, size); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3652 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3653 |
939 | 3654 /* End address of virtual concatenation of string. */ |
3655 #define STOP_ADDR_VSTRING(P) \ | |
3656 (((P) >= size1 ? string2 + size2 : string1 + size1)) | |
3657 | |
3658 /* Address of POS in the concatenation of virtual string. */ | |
3659 #define POS_ADDR_VSTRING(POS) \ | |
3660 (((POS) >= size1 ? string2 - size1 : string1) + (POS)) | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3661 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3662 /* Using the compiled pattern in BUFP->buffer, first tries to match the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3663 virtual concatenation of STRING1 and STRING2, starting first at index |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3664 STARTPOS, then at STARTPOS + 1, and so on. |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3665 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3666 STRING1 and STRING2 have length SIZE1 and SIZE2, respectively. |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3667 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3668 RANGE is how far to scan while trying to match. RANGE = 0 means try |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3669 only at STARTPOS; in general, the last start tried is STARTPOS + |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3670 RANGE. |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3671 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3672 In REGS, return the indices of the virtual concatenation of STRING1 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3673 and STRING2 that matched the entire BUFP->buffer and its contained |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3674 subexpressions. |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3675 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3676 Do not consider matching one past the index STOP in the virtual |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3677 concatenation of STRING1 and STRING2. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3678 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3679 We return either the position in the strings at which the match was |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3680 found, -1 if no match, or -2 if error (such as failure |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3681 stack overflow). */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3682 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3683 int |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
3684 re_search_2 (bufp, str1, size1, str2, size2, startpos, range, regs, stop) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3685 struct re_pattern_buffer *bufp; |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
3686 const char *str1, *str2; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3687 int size1, size2; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3688 int startpos; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3689 int range; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3690 struct re_registers *regs; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3691 int stop; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3692 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3693 int val; |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
3694 re_char *string1 = (re_char*) str1; |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
3695 re_char *string2 = (re_char*) str2; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3696 register char *fastmap = bufp->fastmap; |
501
f29b13c2cefd
(TRANSLATE, PATFETCH): Cast elt of `translate'.
Richard Stallman <rms@gnu.org>
parents:
490
diff
changeset
|
3697 register RE_TRANSLATE_TYPE translate = bufp->translate; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3698 int total_size = size1 + size2; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3699 int endpos = startpos + range; |
678
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3700 int anchored_start = 0; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3701 |
941 | 3702 /* Nonzero if we have to concern multibyte character. */ |
2370
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
3703 const boolean multibyte = bufp->multibyte; |
939 | 3704 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3705 /* Check for out-of-range STARTPOS. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3706 if (startpos < 0 || startpos > total_size) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3707 return -1; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3708 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3709 /* Fix up RANGE if it might eventually take us outside |
490
985fe9826996
(re_search_2): Use 0, not -1, as the lower bound
Richard Stallman <rms@gnu.org>
parents:
481
diff
changeset
|
3710 the virtual concatenation of STRING1 and STRING2. |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3711 Make sure we won't move STARTPOS below 0 or above TOTAL_SIZE. */ |
490
985fe9826996
(re_search_2): Use 0, not -1, as the lower bound
Richard Stallman <rms@gnu.org>
parents:
481
diff
changeset
|
3712 if (endpos < 0) |
985fe9826996
(re_search_2): Use 0, not -1, as the lower bound
Richard Stallman <rms@gnu.org>
parents:
481
diff
changeset
|
3713 range = 0 - startpos; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3714 else if (endpos > total_size) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3715 range = total_size - startpos; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3716 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3717 /* If the search isn't to be a backwards one, don't waste time in a |
1329
818db3848f2b
(re_search_2): Fix handling of at_dot.
Richard Stallman <rms@gnu.org>
parents:
1328
diff
changeset
|
3718 search for a pattern anchored at beginning of buffer. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3719 if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == begbuf && range > 0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3720 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3721 if (startpos > 0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3722 return -1; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3723 else |
1329
818db3848f2b
(re_search_2): Fix handling of at_dot.
Richard Stallman <rms@gnu.org>
parents:
1328
diff
changeset
|
3724 range = 0; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3725 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3726 |
481
35afc74165b7
(re_search_2): If pattern starts with \=, optimize search.
Richard Stallman <rms@gnu.org>
parents:
480
diff
changeset
|
3727 #ifdef emacs |
35afc74165b7
(re_search_2): If pattern starts with \=, optimize search.
Richard Stallman <rms@gnu.org>
parents:
480
diff
changeset
|
3728 /* In a forward search for something that starts with \=. |
35afc74165b7
(re_search_2): If pattern starts with \=, optimize search.
Richard Stallman <rms@gnu.org>
parents:
480
diff
changeset
|
3729 don't keep searching past point. */ |
35afc74165b7
(re_search_2): If pattern starts with \=, optimize search.
Richard Stallman <rms@gnu.org>
parents:
480
diff
changeset
|
3730 if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == at_dot && range > 0) |
35afc74165b7
(re_search_2): If pattern starts with \=, optimize search.
Richard Stallman <rms@gnu.org>
parents:
480
diff
changeset
|
3731 { |
1329
818db3848f2b
(re_search_2): Fix handling of at_dot.
Richard Stallman <rms@gnu.org>
parents:
1328
diff
changeset
|
3732 range = PT_BYTE - BEGV_BYTE - startpos; |
818db3848f2b
(re_search_2): Fix handling of at_dot.
Richard Stallman <rms@gnu.org>
parents:
1328
diff
changeset
|
3733 if (range < 0) |
481
35afc74165b7
(re_search_2): If pattern starts with \=, optimize search.
Richard Stallman <rms@gnu.org>
parents:
480
diff
changeset
|
3734 return -1; |
35afc74165b7
(re_search_2): If pattern starts with \=, optimize search.
Richard Stallman <rms@gnu.org>
parents:
480
diff
changeset
|
3735 } |
35afc74165b7
(re_search_2): If pattern starts with \=, optimize search.
Richard Stallman <rms@gnu.org>
parents:
480
diff
changeset
|
3736 #endif /* emacs */ |
35afc74165b7
(re_search_2): If pattern starts with \=, optimize search.
Richard Stallman <rms@gnu.org>
parents:
480
diff
changeset
|
3737 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3738 /* Update the fastmap now if not correct already. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3739 if (fastmap && !bufp->fastmap_accurate) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3740 if (re_compile_fastmap (bufp) == -2) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3741 return -2; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3742 |
678
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3743 /* See whether the pattern is anchored. */ |
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3744 if (bufp->buffer[0] == begline) |
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3745 anchored_start = 1; |
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3746 |
939 | 3747 #ifdef emacs |
1321
a37088328c87
(re_match_2, re_search_2): Convert position to a charpos,
Karl Heuer <kwzh@gnu.org>
parents:
1313
diff
changeset
|
3748 gl_state.object = re_match_object; |
a37088328c87
(re_match_2, re_search_2): Convert position to a charpos,
Karl Heuer <kwzh@gnu.org>
parents:
1313
diff
changeset
|
3749 { |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
3750 int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (POS_AS_IN_BUFFER (startpos)); |
1321
a37088328c87
(re_match_2, re_search_2): Convert position to a charpos,
Karl Heuer <kwzh@gnu.org>
parents:
1313
diff
changeset
|
3751 |
a37088328c87
(re_match_2, re_search_2): Convert position to a charpos,
Karl Heuer <kwzh@gnu.org>
parents:
1313
diff
changeset
|
3752 SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, charpos, 1); |
a37088328c87
(re_match_2, re_search_2): Convert position to a charpos,
Karl Heuer <kwzh@gnu.org>
parents:
1313
diff
changeset
|
3753 } |
939 | 3754 #endif |
3755 | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3756 /* Loop through the string, looking for a place to start matching. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3757 for (;;) |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3758 { |
678
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3759 /* If the pattern is anchored, |
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3760 skip quickly past places we cannot match. |
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3761 We don't bother to treat startpos == 0 specially |
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3762 because that case doesn't repeat. */ |
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3763 if (anchored_start && startpos > 0) |
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3764 { |
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3765 if (! (bufp->newline_anchor |
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3766 && ((startpos <= size1 ? string1[startpos - 1] |
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3767 : string2[startpos - size1 - 1]) |
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3768 == '\n'))) |
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3769 goto advance; |
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3770 } |
bd677f8ba924
(re_search_2): Optimize regexp that starts with ^.
Richard Stallman <rms@gnu.org>
parents:
677
diff
changeset
|
3771 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3772 /* If a fastmap is supplied, skip quickly over characters that |
941 | 3773 cannot be the start of a match. If the pattern can match the |
3774 null string, however, we don't need to skip characters; we want | |
3775 the first null string. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3776 if (fastmap && startpos < total_size && !bufp->can_be_null) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3777 { |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
3778 register re_char *d; |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3779 register unsigned int buf_ch; |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3780 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3781 d = POS_ADDR_VSTRING (startpos); |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3782 |
941 | 3783 if (range > 0) /* Searching forwards. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3784 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3785 register int lim = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3786 int irange = range; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3787 |
941 | 3788 if (startpos < size1 && startpos + range >= size1) |
3789 lim = range - (size1 - startpos); | |
939 | 3790 |
941 | 3791 /* Written out as an if-else to avoid testing `translate' |
3792 inside the loop. */ | |
1335
97f50084cc62
(re_search_2): Fix indentation.
Andreas Schwab <schwab@suse.de>
parents:
1329
diff
changeset
|
3793 if (RE_TRANSLATE_P (translate)) |
97f50084cc62
(re_search_2): Fix indentation.
Andreas Schwab <schwab@suse.de>
parents:
1329
diff
changeset
|
3794 { |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3795 if (multibyte) |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3796 while (range > lim) |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3797 { |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3798 int buf_charlen; |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3799 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3800 buf_ch = STRING_CHAR_AND_LENGTH (d, range - lim, |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3801 buf_charlen); |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3802 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3803 buf_ch = RE_TRANSLATE (translate, buf_ch); |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3804 if (buf_ch >= 0400 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3805 || fastmap[buf_ch]) |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3806 break; |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3807 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3808 range -= buf_charlen; |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3809 d += buf_charlen; |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3810 } |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3811 else |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3812 while (range > lim |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
3813 && !fastmap[RE_TRANSLATE (translate, *d)]) |
1381
24423cbaf6a9
(re_search_2): Don't use ++ inside RE_TRANSLATE.
Richard Stallman <rms@gnu.org>
parents:
1342
diff
changeset
|
3814 { |
24423cbaf6a9
(re_search_2): Don't use ++ inside RE_TRANSLATE.
Richard Stallman <rms@gnu.org>
parents:
1342
diff
changeset
|
3815 d++; |
24423cbaf6a9
(re_search_2): Don't use ++ inside RE_TRANSLATE.
Richard Stallman <rms@gnu.org>
parents:
1342
diff
changeset
|
3816 range--; |
24423cbaf6a9
(re_search_2): Don't use ++ inside RE_TRANSLATE.
Richard Stallman <rms@gnu.org>
parents:
1342
diff
changeset
|
3817 } |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3818 } |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3819 else |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
3820 while (range > lim && !fastmap[*d]) |
1381
24423cbaf6a9
(re_search_2): Don't use ++ inside RE_TRANSLATE.
Richard Stallman <rms@gnu.org>
parents:
1342
diff
changeset
|
3821 { |
24423cbaf6a9
(re_search_2): Don't use ++ inside RE_TRANSLATE.
Richard Stallman <rms@gnu.org>
parents:
1342
diff
changeset
|
3822 d++; |
24423cbaf6a9
(re_search_2): Don't use ++ inside RE_TRANSLATE.
Richard Stallman <rms@gnu.org>
parents:
1342
diff
changeset
|
3823 range--; |
24423cbaf6a9
(re_search_2): Don't use ++ inside RE_TRANSLATE.
Richard Stallman <rms@gnu.org>
parents:
1342
diff
changeset
|
3824 } |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3825 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3826 startpos += irange - range; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3827 } |
941 | 3828 else /* Searching backwards. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3829 { |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
3830 buf_ch = STRING_CHAR (d, (startpos >= size1 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
3831 ? size2 + size1 - startpos |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
3832 : size1 - startpos)); |
1328
0aa10b723959
Use RE_TRANSLATE_P to check whether translation is
Andreas Schwab <schwab@suse.de>
parents:
1326
diff
changeset
|
3833 if (RE_TRANSLATE_P (translate)) |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3834 buf_ch = RE_TRANSLATE (translate, buf_ch); |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3835 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3836 if (! (buf_ch >= 0400 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
3837 || fastmap[buf_ch])) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3838 goto advance; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3839 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3840 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3841 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3842 /* If can't match the null string, and that's all we have left, fail. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3843 if (range >= 0 && startpos == total_size && fastmap |
941 | 3844 && !bufp->can_be_null) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3845 return -1; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3846 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3847 val = re_match_2_internal (bufp, string1, size1, string2, size2, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3848 startpos, regs, stop); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3849 #ifndef REGEX_MALLOC |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3850 #ifdef C_ALLOCA |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3851 alloca (0); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3852 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3853 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3854 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3855 if (val >= 0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3856 return startpos; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3857 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3858 if (val == -2) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3859 return -2; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3860 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3861 advance: |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3862 if (!range) |
941 | 3863 break; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3864 else if (range > 0) |
941 | 3865 { |
939 | 3866 /* Update STARTPOS to the next character boundary. */ |
3867 if (multibyte) | |
3868 { | |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
3869 re_char *p = POS_ADDR_VSTRING (startpos); |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
3870 re_char *pend = STOP_ADDR_VSTRING (startpos); |
939 | 3871 int len = MULTIBYTE_FORM_LENGTH (p, pend - p); |
3872 | |
3873 range -= len; | |
3874 if (range < 0) | |
3875 break; | |
3876 startpos += len; | |
3877 } | |
3878 else | |
3879 { | |
961
6959c7741ed2
(re_search_2): Cast result of POS_ADDR_VSTRING.
Richard Stallman <rms@gnu.org>
parents:
942
diff
changeset
|
3880 range--; |
6959c7741ed2
(re_search_2): Cast result of POS_ADDR_VSTRING.
Richard Stallman <rms@gnu.org>
parents:
942
diff
changeset
|
3881 startpos++; |
6959c7741ed2
(re_search_2): Cast result of POS_ADDR_VSTRING.
Richard Stallman <rms@gnu.org>
parents:
942
diff
changeset
|
3882 } |
679 | 3883 } |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3884 else |
941 | 3885 { |
3886 range++; | |
3887 startpos--; | |
939 | 3888 |
3889 /* Update STARTPOS to the previous character boundary. */ | |
3890 if (multibyte) | |
3891 { | |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
3892 re_char *p = POS_ADDR_VSTRING (startpos); |
939 | 3893 int len = 0; |
3894 | |
3895 /* Find the head of multibyte form. */ | |
1204
28ff40a118b8
(re_search_2): Fix call to CHAR_HEAD_P.
Richard Stallman <rms@gnu.org>
parents:
1158
diff
changeset
|
3896 while (!CHAR_HEAD_P (*p)) |
939 | 3897 p--, len++; |
3898 | |
3899 /* Adjust it. */ | |
3900 #if 0 /* XXX */ | |
3901 if (MULTIBYTE_FORM_LENGTH (p, len + 1) != (len + 1)) | |
3902 ; | |
3903 else | |
3904 #endif | |
3905 { | |
3906 range += len; | |
3907 if (range > 0) | |
3908 break; | |
3909 | |
3910 startpos -= len; | |
3911 } | |
3912 } | |
941 | 3913 } |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3914 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3915 return -1; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3916 } /* re_search_2 */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3917 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3918 /* Declarations and macros for re_match_2. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3919 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3920 static int bcmp_translate (); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3921 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3922 /* This converts PTR, a pointer into one of the search strings `string1' |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3923 and `string2' into an offset from the beginning of that string. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3924 #define POINTER_TO_OFFSET(ptr) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3925 (FIRST_STRING_P (ptr) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3926 ? ((regoff_t) ((ptr) - string1)) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3927 : ((regoff_t) ((ptr) - string2 + size1))) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3928 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3929 /* Call before fetching a character with *d. This switches over to |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3930 string2 if necessary. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3931 #define PREFETCH() \ |
941 | 3932 while (d == dend) \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3933 { \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3934 /* End of string2 => fail. */ \ |
941 | 3935 if (dend == end_match_2) \ |
3936 goto fail; \ | |
3937 /* End of string1 => advance to string2. */ \ | |
3938 d = string2; \ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3939 dend = end_match_2; \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3940 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3941 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3942 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3943 /* Test if at very beginning or at very end of the virtual concatenation |
941 | 3944 of `string1' and `string2'. If only one string, it's `string2'. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3945 #define AT_STRINGS_BEG(d) ((d) == (size1 ? string1 : string2) || !size2) |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
3946 #define AT_STRINGS_END(d) ((d) == end2) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3947 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3948 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3949 /* Test if D points to a character which is word-constituent. We have |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3950 two special cases to check for: if past the end of string1, look at |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3951 the first character in string2; and if before the beginning of |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3952 string2, look at the last character in string1. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3953 #define WORDCHAR_P(d) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3954 (SYNTAX ((d) == end1 ? *string2 \ |
941 | 3955 : (d) == string2 - 1 ? *(end1 - 1) : *(d)) \ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3956 == Sword) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3957 |
521
7089c3a3a164
(AT_WORD_BOUNDARY): Disable macro.
Karl Heuer <kwzh@gnu.org>
parents:
515
diff
changeset
|
3958 /* Disabled due to a compiler bug -- see comment at case wordbound */ |
939 | 3959 |
3960 /* The comment at case wordbound is following one, but we don't use | |
3961 AT_WORD_BOUNDARY anymore to support multibyte form. | |
3962 | |
3963 The DEC Alpha C compiler 3.x generates incorrect code for the | |
941 | 3964 test WORDCHAR_P (d - 1) != WORDCHAR_P (d) in the expansion of |
3965 AT_WORD_BOUNDARY, so this code is disabled. Expanding the | |
939 | 3966 macro and introducing temporary variables works around the bug. */ |
3967 | |
521
7089c3a3a164
(AT_WORD_BOUNDARY): Disable macro.
Karl Heuer <kwzh@gnu.org>
parents:
515
diff
changeset
|
3968 #if 0 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3969 /* Test if the character before D and the one at D differ with respect |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3970 to being word-constituent. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3971 #define AT_WORD_BOUNDARY(d) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3972 (AT_STRINGS_BEG (d) || AT_STRINGS_END (d) \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3973 || WORDCHAR_P (d - 1) != WORDCHAR_P (d)) |
521
7089c3a3a164
(AT_WORD_BOUNDARY): Disable macro.
Karl Heuer <kwzh@gnu.org>
parents:
515
diff
changeset
|
3974 #endif |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3975 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3976 /* Free everything we malloc. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3977 #ifdef MATCH_MAY_ALLOCATE |
942 | 3978 #define FREE_VAR(var) if (var) { REGEX_FREE (var); var = NULL; } else |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3979 #define FREE_VARIABLES() \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3980 do { \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3981 REGEX_FREE_STACK (fail_stack.stack); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3982 FREE_VAR (regstart); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3983 FREE_VAR (regend); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3984 FREE_VAR (best_regstart); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3985 FREE_VAR (best_regend); \ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3986 } while (0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3987 #else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3988 #define FREE_VARIABLES() ((void)0) /* Do nothing! But inhibit gcc warning. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3989 #endif /* not MATCH_MAY_ALLOCATE */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
3990 |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3991 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3992 /* Optimization routines. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
3993 |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
3994 /* If the operation is a match against one or more chars, |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
3995 return a pointer to the next operation, else return NULL. */ |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
3996 static unsigned char * |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
3997 skip_one_char (p) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
3998 unsigned char *p; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
3999 { |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4000 switch (SWITCH_ENUM_CAST (*p++)) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4001 { |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4002 case anychar: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4003 break; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4004 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4005 case exactn: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4006 p += *p + 1; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4007 break; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4008 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4009 case charset_not: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4010 case charset: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4011 if (CHARSET_RANGE_TABLE_EXISTS_P (p - 1)) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4012 { |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4013 int mcnt; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4014 p = CHARSET_RANGE_TABLE (p - 1); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4015 EXTRACT_NUMBER_AND_INCR (mcnt, p); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4016 p = CHARSET_RANGE_TABLE_END (p, mcnt); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4017 } |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4018 else |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4019 p += 1 + CHARSET_BITMAP_SIZE (p - 1); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4020 break; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4021 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4022 case syntaxspec: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4023 case notsyntaxspec: |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
4024 #ifdef emacs |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4025 case categoryspec: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4026 case notcategoryspec: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4027 #endif /* emacs */ |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4028 p++; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4029 break; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4030 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4031 default: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4032 p = NULL; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4033 } |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4034 return p; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4035 } |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4036 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4037 |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4038 /* Jump over non-matching operations. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4039 static unsigned char * |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4040 skip_noops (p, pend) |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4041 unsigned char *p, *pend; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4042 { |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4043 int mcnt; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4044 while (p < pend) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4045 { |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4046 switch (SWITCH_ENUM_CAST ((re_opcode_t) *p)) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4047 { |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4048 case start_memory: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4049 case stop_memory: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4050 p += 2; break; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4051 case no_op: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4052 p += 1; break; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4053 case jump: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4054 p += 1; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4055 EXTRACT_NUMBER_AND_INCR (mcnt, p); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4056 p += mcnt; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4057 break; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4058 default: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4059 return p; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4060 } |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4061 } |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4062 assert (p == pend); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4063 return p; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4064 } |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4065 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4066 /* Non-zero if "p1 matches something" implies "p2 fails". */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4067 static int |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4068 mutually_exclusive_p (bufp, p1, p2) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4069 struct re_pattern_buffer *bufp; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4070 unsigned char *p1, *p2; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4071 { |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4072 re_opcode_t op2; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4073 const boolean multibyte = bufp->multibyte; |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4074 unsigned char *pend = bufp->buffer + bufp->used; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4075 |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4076 assert (p1 >= bufp->buffer && p1 < pend |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4077 && p2 >= bufp->buffer && p2 <= pend); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4078 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4079 /* Skip over open/close-group commands. |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4080 If what follows this loop is a ...+ construct, |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4081 look at what begins its body, since we will have to |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4082 match at least one of that. */ |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4083 p2 = skip_noops (p2, pend); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4084 /* The same skip can be done for p1, except that this function |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4085 is only used in the case where p1 is a simple match operator. */ |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4086 /* p1 = skip_noops (p1, pend); */ |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4087 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4088 assert (p1 >= bufp->buffer && p1 < pend |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4089 && p2 >= bufp->buffer && p2 <= pend); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4090 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4091 op2 = p2 == pend ? succeed : *p2; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4092 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4093 switch (SWITCH_ENUM_CAST (op2)) |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4094 { |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4095 case succeed: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4096 case endbuf: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4097 /* If we're at the end of the pattern, we can change. */ |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4098 if (skip_one_char (p1)) |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4099 { |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4100 DEBUG_PRINT1 (" End of pattern: fast loop.\n"); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4101 return 1; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4102 } |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4103 break; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4104 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4105 case endline: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4106 if (!bufp->newline_anchor) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4107 break; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4108 /* Fallthrough */ |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4109 case exactn: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4110 { |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4111 register unsigned int c |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4112 = (re_opcode_t) *p2 == endline ? '\n' |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4113 : RE_STRING_CHAR(p2 + 2, pend - p2 - 2); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4114 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4115 if ((re_opcode_t) *p1 == exactn) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4116 { |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4117 if (c != RE_STRING_CHAR (p1 + 2, pend - p1 - 2)) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4118 { |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4119 DEBUG_PRINT3 (" '%c' != '%c' => fast loop.\n", c, p1[2]); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4120 return 1; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4121 } |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4122 } |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4123 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4124 else if ((re_opcode_t) *p1 == charset |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4125 || (re_opcode_t) *p1 == charset_not) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4126 { |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4127 int not = (re_opcode_t) *p1 == charset_not; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4128 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4129 /* Test if C is listed in charset (or charset_not) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4130 at `p1'. */ |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4131 if (SINGLE_BYTE_CHAR_P (c)) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4132 { |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4133 if (c < CHARSET_BITMAP_SIZE (p1) * BYTEWIDTH |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4134 && p1[2 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4135 not = !not; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4136 } |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4137 else if (CHARSET_RANGE_TABLE_EXISTS_P (p1)) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4138 CHARSET_LOOKUP_RANGE_TABLE (not, c, p1); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4139 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4140 /* `not' is equal to 1 if c would match, which means |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4141 that we can't change to pop_failure_jump. */ |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4142 if (!not) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4143 { |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4144 DEBUG_PRINT1 (" No match => fast loop.\n"); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4145 return 1; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4146 } |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4147 } |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4148 else if ((re_opcode_t) *p1 == anychar |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4149 && c == '\n') |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4150 { |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4151 DEBUG_PRINT1 (" . != \\n => fast loop.\n"); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4152 return 1; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4153 } |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4154 } |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4155 break; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4156 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4157 case charset: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4158 case charset_not: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4159 { |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4160 if ((re_opcode_t) *p1 == exactn) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4161 /* Reuse the code above. */ |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4162 return mutually_exclusive_p (bufp, p2, p1); |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4163 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4164 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4165 /* It is hard to list up all the character in charset |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4166 P2 if it includes multibyte character. Give up in |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4167 such case. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4168 else if (!multibyte || !CHARSET_RANGE_TABLE_EXISTS_P (p2)) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4169 { |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4170 /* Now, we are sure that P2 has no range table. |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4171 So, for the size of bitmap in P2, `p2[1]' is |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4172 enough. But P1 may have range table, so the |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4173 size of bitmap table of P1 is extracted by |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4174 using macro `CHARSET_BITMAP_SIZE'. |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4175 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4176 Since we know that all the character listed in |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4177 P2 is ASCII, it is enough to test only bitmap |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4178 table of P1. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4179 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4180 if (*p1 == *p2) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4181 { |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4182 int idx; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4183 /* We win if the charset inside the loop |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4184 has no overlap with the one after the loop. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4185 for (idx = 0; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4186 (idx < (int) p2[1] |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4187 && idx < CHARSET_BITMAP_SIZE (p1)); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4188 idx++) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4189 if ((p2[2 + idx] & p1[2 + idx]) != 0) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4190 break; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4191 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4192 if (idx == p2[1] |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4193 || idx == CHARSET_BITMAP_SIZE (p1)) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4194 { |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4195 DEBUG_PRINT1 (" No match => fast loop.\n"); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4196 return 1; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4197 } |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4198 } |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4199 else if ((re_opcode_t) *p1 == charset |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4200 || (re_opcode_t) *p1 == charset_not) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4201 { |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4202 int idx; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4203 /* We win if the charset_not inside the loop lists |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4204 every character listed in the charset after. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4205 for (idx = 0; idx < (int) p2[1]; idx++) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4206 if (! (p2[2 + idx] == 0 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4207 || (idx < CHARSET_BITMAP_SIZE (p1) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4208 && ((p2[2 + idx] & ~ p1[2 + idx]) == 0)))) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4209 break; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4210 |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4211 if (idx == p2[1]) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4212 { |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4213 DEBUG_PRINT1 (" No match => fast loop.\n"); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4214 return 1; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4215 } |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4216 } |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4217 } |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4218 } |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4219 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4220 case wordend: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4221 case notsyntaxspec: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4222 return ((re_opcode_t) *p1 == syntaxspec |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4223 && p1[1] == (op2 == wordend ? Sword : p2[1])); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4224 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4225 case wordbeg: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4226 case syntaxspec: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4227 return ((re_opcode_t) *p1 == notsyntaxspec |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4228 && p1[1] == (op2 == wordend ? Sword : p2[1])); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4229 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4230 case wordbound: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4231 return (((re_opcode_t) *p1 == notsyntaxspec |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4232 || (re_opcode_t) *p1 == syntaxspec) |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4233 && p1[1] == Sword); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4234 |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
4235 #ifdef emacs |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4236 case categoryspec: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4237 return ((re_opcode_t) *p1 == notcategoryspec && p1[1] == p2[1]); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4238 case notcategoryspec: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4239 return ((re_opcode_t) *p1 == categoryspec && p1[1] == p2[1]); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4240 #endif /* emacs */ |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4241 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4242 default: |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
4243 ; |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4244 } |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4245 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4246 /* Safe default. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4247 return 0; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4248 } |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4249 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4250 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4251 /* Matching routines. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4252 |
941 | 4253 #ifndef emacs /* Emacs never uses this. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4254 /* re_match is like re_match_2 except it takes only a single string. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4255 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4256 int |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4257 re_match (bufp, string, size, pos, regs) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4258 struct re_pattern_buffer *bufp; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4259 const char *string; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4260 int size, pos; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4261 struct re_registers *regs; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4262 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4263 int result = re_match_2_internal (bufp, NULL, 0, string, size, |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4264 pos, regs, size); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4265 alloca (0); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4266 return result; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4267 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4268 #endif /* not emacs */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4269 |
939 | 4270 #ifdef emacs |
4271 /* In Emacs, this is the string or buffer in which we | |
941 | 4272 are matching. It is used for looking up syntax properties. */ |
939 | 4273 Lisp_Object re_match_object; |
4274 #endif | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4275 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4276 /* re_match_2 matches the compiled pattern in BUFP against the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4277 the (virtual) concatenation of STRING1 and STRING2 (of length SIZE1 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4278 and SIZE2, respectively). We start matching at POS, and stop |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4279 matching at STOP. |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4280 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4281 If REGS is non-null and the `no_sub' field of BUFP is nonzero, we |
941 | 4282 store offsets for the substring each group matched in REGS. See the |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4283 documentation for exactly how many groups we fill. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4284 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4285 We return -1 if no match, -2 if an internal error (such as the |
941 | 4286 failure stack overflowing). Otherwise, we return the length of the |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4287 matched substring. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4288 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4289 int |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4290 re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4291 struct re_pattern_buffer *bufp; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4292 const char *string1, *string2; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4293 int size1, size2; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4294 int pos; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4295 struct re_registers *regs; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4296 int stop; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4297 { |
939 | 4298 int result; |
941 | 4299 |
939 | 4300 #ifdef emacs |
1321
a37088328c87
(re_match_2, re_search_2): Convert position to a charpos,
Karl Heuer <kwzh@gnu.org>
parents:
1313
diff
changeset
|
4301 int charpos; |
a37088328c87
(re_match_2, re_search_2): Convert position to a charpos,
Karl Heuer <kwzh@gnu.org>
parents:
1313
diff
changeset
|
4302 gl_state.object = re_match_object; |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4303 charpos = SYNTAX_TABLE_BYTE_TO_CHAR (POS_AS_IN_BUFFER (pos)); |
1321
a37088328c87
(re_match_2, re_search_2): Convert position to a charpos,
Karl Heuer <kwzh@gnu.org>
parents:
1313
diff
changeset
|
4304 SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, charpos, 1); |
939 | 4305 #endif |
4306 | |
4307 result = re_match_2_internal (bufp, string1, size1, string2, size2, | |
1321
a37088328c87
(re_match_2, re_search_2): Convert position to a charpos,
Karl Heuer <kwzh@gnu.org>
parents:
1313
diff
changeset
|
4308 pos, regs, stop); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4309 alloca (0); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4310 return result; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4311 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4312 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4313 /* This is a separate function so that we can force an alloca cleanup |
941 | 4314 afterwards. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4315 static int |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4316 re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4317 struct re_pattern_buffer *bufp; |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
4318 re_char *string1, *string2; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4319 int size1, size2; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4320 int pos; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4321 struct re_registers *regs; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4322 int stop; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4323 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4324 /* General temporaries. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4325 int mcnt; |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
4326 boolean not; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4327 unsigned char *p1; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4328 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4329 /* Just past the end of the corresponding string. */ |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
4330 re_char *end1, *end2; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4331 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4332 /* Pointers into string1 and string2, just past the last characters in |
941 | 4333 each to consider matching. */ |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
4334 re_char *end_match_1, *end_match_2; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4335 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4336 /* Where we are in the data, and the end of the current string. */ |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
4337 re_char *d, *dend; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4338 |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4339 /* Used sometimes to remember where we were before starting matching |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4340 an operator so that we can go back in case of failure. This "atomic" |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4341 behavior of matching opcodes is indispensable to the correctness |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4342 of the on_failure_keep_string_jump optimization. */ |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4343 re_char *dfail; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4344 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4345 /* Where we are in the pattern, and the end of the pattern. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4346 unsigned char *p = bufp->buffer; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4347 register unsigned char *pend = p + bufp->used; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4348 |
941 | 4349 /* We use this to map every character in the string. */ |
501
f29b13c2cefd
(TRANSLATE, PATFETCH): Cast elt of `translate'.
Richard Stallman <rms@gnu.org>
parents:
490
diff
changeset
|
4350 RE_TRANSLATE_TYPE translate = bufp->translate; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4351 |
941 | 4352 /* Nonzero if we have to concern multibyte character. */ |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
4353 const boolean multibyte = bufp->multibyte; |
939 | 4354 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4355 /* Failure point stack. Each place that can handle a failure further |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4356 down the line pushes a failure point on this stack. It consists of |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4357 regstart, and regend for all registers corresponding to |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4358 the subexpressions we're currently inside, plus the number of such |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4359 registers, and, finally, two char *'s. The first char * is where |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4360 to resume scanning the pattern; the second one is where to resume |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4361 scanning the strings. */ |
941 | 4362 #ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4363 fail_stack_type fail_stack; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4364 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4365 #ifdef DEBUG |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4366 static unsigned failure_id = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4367 unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4368 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4369 |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4370 #if defined (REL_ALLOC) && defined (REGEX_MALLOC) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4371 /* This holds the pointer to the failure stack, when |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4372 it is allocated relocatably. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4373 fail_stack_elt_t *failure_stack_ptr; |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4374 #endif |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4375 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4376 /* We fill all the registers internally, independent of what we |
941 | 4377 return, for use in backreferences. The number here includes |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4378 an element for register zero. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4379 unsigned num_regs = bufp->re_nsub + 1; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4380 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4381 /* Information on the contents of registers. These are pointers into |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4382 the input strings; they record just what was matched (on this |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4383 attempt) by a subexpression part of the pattern, that is, the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4384 regnum-th regstart pointer points to where in the pattern we began |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4385 matching and the regnum-th regend points to right after where we |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4386 stopped matching the regnum-th subexpression. (The zeroth register |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4387 keeps track of what the whole pattern matches.) */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4388 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */ |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
4389 re_char **regstart, **regend; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4390 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4391 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4392 /* The following record the register info as found in the above |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4393 variables when we find a match better than any we've seen before. |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4394 This happens as we backtrack through the failure points, which in |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4395 turn happens only if we have not yet matched the entire string. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4396 unsigned best_regs_set = false; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4397 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */ |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
4398 re_char **best_regstart, **best_regend; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4399 #endif |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4400 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4401 /* Logically, this is `best_regend[0]'. But we don't want to have to |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4402 allocate space for that if we're not allocating space for anything |
941 | 4403 else (see below). Also, we never need info about register 0 for |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4404 any of the other register vectors, and it seems rather a kludge to |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4405 treat `best_regend' differently than the rest. So we keep track of |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4406 the end of the best match so far in a separate variable. We |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4407 initialize this to NULL so that when we backtrack the first time |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4408 and need to test it, it's not garbage. */ |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
4409 re_char *match_end = NULL; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4410 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4411 #ifdef DEBUG |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4412 /* Counts the total number of registers pushed. */ |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4413 unsigned num_regs_pushed = 0; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4414 #endif |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4415 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4416 DEBUG_PRINT1 ("\n\nEntering re_match_2.\n"); |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4417 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4418 INIT_FAIL_STACK (); |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4419 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4420 #ifdef MATCH_MAY_ALLOCATE |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4421 /* Do not bother to initialize all the register variables if there are |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4422 no groups in the pattern, as it takes a fair amount of time. If |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4423 there are groups, we include space for register 0 (the whole |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4424 pattern), even though we never use it, since it simplifies the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4425 array indexing. We should fix this. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4426 if (bufp->re_nsub) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4427 { |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
4428 regstart = REGEX_TALLOC (num_regs, re_char *); |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
4429 regend = REGEX_TALLOC (num_regs, re_char *); |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
4430 best_regstart = REGEX_TALLOC (num_regs, re_char *); |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
4431 best_regend = REGEX_TALLOC (num_regs, re_char *); |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4432 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4433 if (!(regstart && regend && best_regstart && best_regend)) |
941 | 4434 { |
4435 FREE_VARIABLES (); | |
4436 return -2; | |
4437 } | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4438 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4439 else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4440 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4441 /* We must initialize all our variables to NULL, so that |
941 | 4442 `FREE_VARIABLES' doesn't try to free them. */ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4443 regstart = regend = best_regstart = best_regend = NULL; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4444 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4445 #endif /* MATCH_MAY_ALLOCATE */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4446 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4447 /* The starting position is bogus. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4448 if (pos < 0 || pos > size1 + size2) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4449 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4450 FREE_VARIABLES (); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4451 return -1; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4452 } |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4453 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4454 /* Initialize subexpression text positions to -1 to mark ones that no |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4455 start_memory/stop_memory has been seen for. Also initialize the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4456 register information struct. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4457 for (mcnt = 1; mcnt < num_regs; mcnt++) |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4458 regstart[mcnt] = regend[mcnt] = REG_UNSET_VALUE; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4459 |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4460 /* Shorten strings to `stop'. */ |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4461 if (stop <= size1) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4462 { |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4463 size1 = stop; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4464 size2 = 0; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4465 } |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4466 else if (stop <= size1 + size2) |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4467 size2 = stop - size1; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4468 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4469 /* We move `string1' into `string2' if the latter's empty -- but not if |
941 | 4470 `string1' is null. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4471 if (size2 == 0 && string1 != NULL) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4472 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4473 string2 = string1; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4474 size2 = size1; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4475 string1 = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4476 size1 = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4477 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4478 end1 = string1 + size1; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4479 end2 = string2 + size2; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4480 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4481 /* Compute where to stop matching, within the two strings. */ |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4482 end_match_1 = end1; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4483 end_match_2 = end2; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4484 |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4485 /* `p' scans through the pattern as `d' scans through the data. |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4486 `dend' is the end of the input string that `d' points within. `d' |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4487 is advanced into the following input string whenever necessary, but |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4488 this happens before fetching; therefore, at the beginning of the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4489 loop, `d' can be pointing at the end of a string, but it cannot |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4490 equal `string2'. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4491 if (size1 > 0 && pos <= size1) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4492 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4493 d = string1 + pos; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4494 dend = end_match_1; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4495 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4496 else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4497 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4498 d = string2 + pos - size1; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4499 dend = end_match_2; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4500 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4501 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4502 DEBUG_PRINT1 ("The compiled pattern is: "); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4503 DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4504 DEBUG_PRINT1 ("The string to match is: `"); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4505 DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4506 DEBUG_PRINT1 ("'\n"); |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4507 |
941 | 4508 /* This loops over pattern commands. It exits by returning from the |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4509 function if the match is complete, or it drops through if the match |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4510 fails at this starting point in the input data. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4511 for (;;) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4512 { |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4513 DEBUG_PRINT2 ("\n%p: ", p); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4514 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4515 if (p == pend) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4516 { /* End of pattern means we might have succeeded. */ |
941 | 4517 DEBUG_PRINT1 ("end of pattern ... "); |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4518 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4519 /* If we haven't matched the entire string, and we want the |
941 | 4520 longest match, try backtracking. */ |
4521 if (d != end_match_2) | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4522 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4523 /* 1 if this match ends in the same string (string1 or string2) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4524 as the best previous match. */ |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4525 boolean same_str_p = (FIRST_STRING_P (match_end) |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4526 == FIRST_STRING_P (d)); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4527 /* 1 if this match is the best seen so far. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4528 boolean best_match_p; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4529 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4530 /* AIX compiler got confused when this was combined |
941 | 4531 with the previous declaration. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4532 if (same_str_p) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4533 best_match_p = d > match_end; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4534 else |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4535 best_match_p = !FIRST_STRING_P (d); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4536 |
941 | 4537 DEBUG_PRINT1 ("backtracking.\n"); |
4538 | |
4539 if (!FAIL_STACK_EMPTY ()) | |
4540 { /* More failure points to try. */ | |
4541 | |
4542 /* If exceeds best match so far, save it. */ | |
4543 if (!best_regs_set || best_match_p) | |
4544 { | |
4545 best_regs_set = true; | |
4546 match_end = d; | |
4547 | |
4548 DEBUG_PRINT1 ("\nSAVING match as best so far.\n"); | |
4549 | |
4550 for (mcnt = 1; mcnt < num_regs; mcnt++) | |
4551 { | |
4552 best_regstart[mcnt] = regstart[mcnt]; | |
4553 best_regend[mcnt] = regend[mcnt]; | |
4554 } | |
4555 } | |
4556 goto fail; | |
4557 } | |
4558 | |
4559 /* If no failure points, don't restore garbage. And if | |
4560 last match is real best match, don't restore second | |
4561 best one. */ | |
4562 else if (best_regs_set && !best_match_p) | |
4563 { | |
4564 restore_best_regs: | |
4565 /* Restore best match. It may happen that `dend == | |
4566 end_match_1' while the restored d is in string2. | |
4567 For example, the pattern `x.*y.*z' against the | |
4568 strings `x-' and `y-z-', if the two strings are | |
4569 not consecutive in memory. */ | |
4570 DEBUG_PRINT1 ("Restoring best registers.\n"); | |
4571 | |
4572 d = match_end; | |
4573 dend = ((d >= string1 && d <= end1) | |
4574 ? end_match_1 : end_match_2); | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4575 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4576 for (mcnt = 1; mcnt < num_regs; mcnt++) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4577 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4578 regstart[mcnt] = best_regstart[mcnt]; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4579 regend[mcnt] = best_regend[mcnt]; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4580 } |
941 | 4581 } |
4582 } /* d != end_match_2 */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4583 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4584 succeed_label: |
941 | 4585 DEBUG_PRINT1 ("Accepting match.\n"); |
4586 | |
4587 /* If caller wants register contents data back, do it. */ | |
4588 if (regs && !bufp->no_sub) | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4589 { |
941 | 4590 /* Have the register data arrays been allocated? */ |
4591 if (bufp->regs_allocated == REGS_UNALLOCATED) | |
4592 { /* No. So allocate them with malloc. We need one | |
4593 extra element beyond `num_regs' for the `-1' marker | |
4594 GNU code uses. */ | |
4595 regs->num_regs = MAX (RE_NREGS, num_regs + 1); | |
4596 regs->start = TALLOC (regs->num_regs, regoff_t); | |
4597 regs->end = TALLOC (regs->num_regs, regoff_t); | |
4598 if (regs->start == NULL || regs->end == NULL) | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4599 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4600 FREE_VARIABLES (); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4601 return -2; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4602 } |
941 | 4603 bufp->regs_allocated = REGS_REALLOCATE; |
4604 } | |
4605 else if (bufp->regs_allocated == REGS_REALLOCATE) | |
4606 { /* Yes. If we need more elements than were already | |
4607 allocated, reallocate them. If we need fewer, just | |
4608 leave it alone. */ | |
4609 if (regs->num_regs < num_regs + 1) | |
4610 { | |
4611 regs->num_regs = num_regs + 1; | |
4612 RETALLOC (regs->start, regs->num_regs, regoff_t); | |
4613 RETALLOC (regs->end, regs->num_regs, regoff_t); | |
4614 if (regs->start == NULL || regs->end == NULL) | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4615 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4616 FREE_VARIABLES (); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4617 return -2; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4618 } |
941 | 4619 } |
4620 } | |
4621 else | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4622 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4623 /* These braces fend off a "empty body in an else-statement" |
941 | 4624 warning under GCC when assert expands to nothing. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4625 assert (bufp->regs_allocated == REGS_FIXED); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4626 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4627 |
941 | 4628 /* Convert the pointer data in `regstart' and `regend' to |
4629 indices. Register zero has to be set differently, | |
4630 since we haven't kept track of any info for it. */ | |
4631 if (regs->num_regs > 0) | |
4632 { | |
4633 regs->start[0] = pos; | |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4634 regs->end[0] = POINTER_TO_OFFSET (d); |
941 | 4635 } |
4636 | |
4637 /* Go through the first `min (num_regs, regs->num_regs)' | |
4638 registers, since that is all we initialized. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4639 for (mcnt = 1; mcnt < MIN (num_regs, regs->num_regs); mcnt++) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4640 { |
941 | 4641 if (REG_UNSET (regstart[mcnt]) || REG_UNSET (regend[mcnt])) |
4642 regs->start[mcnt] = regs->end[mcnt] = -1; | |
4643 else | |
4644 { | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4645 regs->start[mcnt] |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4646 = (regoff_t) POINTER_TO_OFFSET (regstart[mcnt]); |
941 | 4647 regs->end[mcnt] |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4648 = (regoff_t) POINTER_TO_OFFSET (regend[mcnt]); |
941 | 4649 } |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4650 } |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4651 |
941 | 4652 /* If the regs structure we return has more elements than |
4653 were in the pattern, set the extra elements to -1. If | |
4654 we (re)allocated the registers, this is the case, | |
4655 because we always allocate enough to have at least one | |
4656 -1 at the end. */ | |
4657 for (mcnt = num_regs; mcnt < regs->num_regs; mcnt++) | |
4658 regs->start[mcnt] = regs->end[mcnt] = -1; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4659 } /* regs && !bufp->no_sub */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4660 |
941 | 4661 DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n", |
4662 nfailure_points_pushed, nfailure_points_popped, | |
4663 nfailure_points_pushed - nfailure_points_popped); | |
4664 DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed); | |
4665 | |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4666 mcnt = POINTER_TO_OFFSET (d) - pos; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4667 |
941 | 4668 DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt); |
4669 | |
4670 FREE_VARIABLES (); | |
4671 return mcnt; | |
4672 } | |
4673 | |
4674 /* Otherwise match next pattern command. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4675 switch (SWITCH_ENUM_CAST ((re_opcode_t) *p++)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4676 { |
941 | 4677 /* Ignore these. Used to ignore the n of succeed_n's which |
4678 currently have n == 0. */ | |
4679 case no_op: | |
4680 DEBUG_PRINT1 ("EXECUTING no_op.\n"); | |
4681 break; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4682 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4683 case succeed: |
941 | 4684 DEBUG_PRINT1 ("EXECUTING succeed.\n"); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4685 goto succeed_label; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4686 |
941 | 4687 /* Match the next n pattern characters exactly. The following |
4688 byte in the pattern defines n, and the n bytes after that | |
4689 are the characters to match. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4690 case exactn: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4691 mcnt = *p++; |
941 | 4692 DEBUG_PRINT2 ("EXECUTING exactn %d.\n", mcnt); |
4693 | |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4694 /* Remember the start point to rollback upon failure. */ |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4695 dfail = d; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4696 |
941 | 4697 /* This is written out as an if-else so we don't waste time |
4698 testing `translate' inside the loop. */ | |
1328
0aa10b723959
Use RE_TRANSLATE_P to check whether translation is
Andreas Schwab <schwab@suse.de>
parents:
1326
diff
changeset
|
4699 if (RE_TRANSLATE_P (translate)) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4700 { |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4701 #ifdef emacs |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4702 if (multibyte) |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4703 do |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4704 { |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4705 int pat_charlen, buf_charlen; |
1312
a9a56c9deb21
(re_match_2_internal): Declare buf_ch unsigned int.
Richard Stallman <rms@gnu.org>
parents:
1297
diff
changeset
|
4706 unsigned int pat_ch, buf_ch; |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4707 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4708 PREFETCH (); |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4709 pat_ch = STRING_CHAR_AND_LENGTH (p, pend - p, pat_charlen); |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4710 buf_ch = STRING_CHAR_AND_LENGTH (d, dend - d, buf_charlen); |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4711 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4712 if (RE_TRANSLATE (translate, buf_ch) |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4713 != pat_ch) |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4714 { |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4715 d = dfail; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4716 goto fail; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4717 } |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4718 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4719 p += pat_charlen; |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4720 d += buf_charlen; |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4721 mcnt -= pat_charlen; |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4722 } |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4723 while (mcnt > 0); |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4724 else |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4725 #endif /* not emacs */ |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4726 do |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4727 { |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4728 PREFETCH (); |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
4729 if (RE_TRANSLATE (translate, *d) != *p++) |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4730 { |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4731 d = dfail; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4732 goto fail; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4733 } |
1381
24423cbaf6a9
(re_search_2): Don't use ++ inside RE_TRANSLATE.
Richard Stallman <rms@gnu.org>
parents:
1342
diff
changeset
|
4734 d++; |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4735 } |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4736 while (--mcnt); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4737 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4738 else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4739 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4740 do |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4741 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4742 PREFETCH (); |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4743 if (*d++ != *p++) |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4744 { |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4745 d = dfail; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4746 goto fail; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4747 } |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4748 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4749 while (--mcnt); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4750 } |
941 | 4751 break; |
4752 | |
4753 | |
4754 /* Match any character except possibly a newline or a null. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4755 case anychar: |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4756 { |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4757 int buf_charlen; |
1312
a9a56c9deb21
(re_match_2_internal): Declare buf_ch unsigned int.
Richard Stallman <rms@gnu.org>
parents:
1297
diff
changeset
|
4758 unsigned int buf_ch; |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4759 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4760 DEBUG_PRINT1 ("EXECUTING anychar.\n"); |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4761 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4762 PREFETCH (); |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4763 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4764 #ifdef emacs |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4765 if (multibyte) |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4766 buf_ch = STRING_CHAR_AND_LENGTH (d, dend - d, buf_charlen); |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4767 else |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4768 #endif /* not emacs */ |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4769 { |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
4770 buf_ch = *d; |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4771 buf_charlen = 1; |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4772 } |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4773 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4774 buf_ch = TRANSLATE (buf_ch); |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4775 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4776 if ((!(bufp->syntax & RE_DOT_NEWLINE) |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4777 && buf_ch == '\n') |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4778 || ((bufp->syntax & RE_DOT_NOT_NULL) |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4779 && buf_ch == '\000')) |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4780 goto fail; |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4781 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4782 DEBUG_PRINT2 (" Matched `%d'.\n", *d); |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4783 d += buf_charlen; |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
4784 } |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4785 break; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4786 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4787 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4788 case charset: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4789 case charset_not: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4790 { |
939 | 4791 register unsigned int c; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4792 boolean not = (re_opcode_t) *(p - 1) == charset_not; |
939 | 4793 int len; |
4794 | |
4795 /* Start of actual range_table, or end of bitmap if there is no | |
4796 range table. */ | |
4797 unsigned char *range_table; | |
4798 | |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4799 /* Nonzero if there is a range table. */ |
939 | 4800 int range_table_exists; |
4801 | |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4802 /* Number of ranges of range table. This is not included |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4803 in the initial byte-length of the command. */ |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4804 int count = 0; |
939 | 4805 |
941 | 4806 DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : ""); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4807 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4808 PREFETCH (); |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
4809 c = *d; |
939 | 4810 |
4811 range_table_exists = CHARSET_RANGE_TABLE_EXISTS_P (&p[-1]); | |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4812 |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4813 #ifdef emacs |
939 | 4814 if (range_table_exists) |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4815 { |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4816 range_table = CHARSET_RANGE_TABLE (&p[-1]); /* Past the bitmap. */ |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4817 EXTRACT_NUMBER_AND_INCR (count, range_table); |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4818 } |
939 | 4819 |
4820 if (multibyte && BASE_LEADING_CODE_P (c)) | |
4821 c = STRING_CHAR_AND_LENGTH (d, dend - d, len); | |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4822 #endif /* emacs */ |
939 | 4823 |
4824 if (SINGLE_BYTE_CHAR_P (c)) | |
4825 { /* Lookup bitmap. */ | |
4826 c = TRANSLATE (c); /* The character to match. */ | |
4827 len = 1; | |
4828 | |
4829 /* Cast to `unsigned' instead of `unsigned char' in | |
4830 case the bit list is a full 32 bytes long. */ | |
4831 if (c < (unsigned) (CHARSET_BITMAP_SIZE (&p[-1]) * BYTEWIDTH) | |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4832 && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4833 not = !not; |
939 | 4834 } |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4835 #ifdef emacs |
939 | 4836 else if (range_table_exists) |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4837 { |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4838 int class_bits = CHARSET_RANGE_TABLE_BITS (&p[-1]); |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4839 |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4840 if ( (class_bits & BIT_ALNUM && ISALNUM (c)) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4841 | (class_bits & BIT_ALPHA && ISALPHA (c)) |
1965
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
4842 | (class_bits & BIT_ASCII && IS_REAL_ASCII (c)) |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4843 | (class_bits & BIT_GRAPH && ISGRAPH (c)) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4844 | (class_bits & BIT_LOWER && ISLOWER (c)) |
1965
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
4845 | (class_bits & BIT_MULTIBYTE && !ISUNIBYTE (c)) |
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
4846 | (class_bits & BIT_NONASCII && !IS_REAL_ASCII (c)) |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4847 | (class_bits & BIT_PRINT && ISPRINT (c)) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4848 | (class_bits & BIT_PUNCT && ISPUNCT (c)) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4849 | (class_bits & BIT_SPACE && ISSPACE (c)) |
1965
058a9ce57dd7
1999-09-04 Richard Stallman <rms@gnu.org>
Dave Love <fx@gnu.org>
parents:
1933
diff
changeset
|
4850 | (class_bits & BIT_UNIBYTE && ISUNIBYTE (c)) |
1933
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4851 | (class_bits & BIT_UPPER && ISUPPER (c)) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4852 | (class_bits & BIT_WORD && ISWORD (c))) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4853 not = !not; |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4854 else |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4855 CHARSET_LOOKUP_RANGE_TABLE_RAW (not, c, range_table, count); |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4856 } |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4857 #endif /* emacs */ |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4858 |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4859 if (range_table_exists) |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4860 p = CHARSET_RANGE_TABLE_END (range_table, count); |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4861 else |
5ffa81ab1988
[emacs]: Handle character classes for multibyte chars:
Richard Stallman <rms@gnu.org>
parents:
1660
diff
changeset
|
4862 p += CHARSET_BITMAP_SIZE (&p[-1]) + 1; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4863 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4864 if (!not) goto fail; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4865 |
939 | 4866 d += len; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4867 break; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4868 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4869 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4870 |
941 | 4871 /* The beginning of a group is represented by start_memory. |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4872 The argument is the register number. The text |
941 | 4873 matched within the group is recorded (in the internal |
4874 registers data structure) under the register number. */ | |
4875 case start_memory: | |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4876 DEBUG_PRINT2 ("EXECUTING start_memory %d:\n", *p); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4877 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4878 /* In case we need to undo this operation (via backtracking). */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4879 PUSH_FAILURE_REG ((unsigned int)*p); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4880 |
941 | 4881 regstart[*p] = d; |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4882 regend[*p] = REG_UNSET_VALUE; /* probably unnecessary. -sm */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4883 DEBUG_PRINT2 (" regstart: %d\n", POINTER_TO_OFFSET (regstart[*p])); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4884 |
941 | 4885 /* Move past the register number and inner group count. */ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4886 p += 1; |
941 | 4887 break; |
4888 | |
4889 | |
4890 /* The stop_memory opcode represents the end of a group. Its | |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4891 argument is the same as start_memory's: the register number. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4892 case stop_memory: |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4893 DEBUG_PRINT2 ("EXECUTING stop_memory %d:\n", *p); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4894 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4895 assert (!REG_UNSET (regstart[*p])); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4896 /* Strictly speaking, there should be code such as: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4897 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4898 assert (REG_UNSET (regend[*p])); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4899 PUSH_FAILURE_REGSTOP ((unsigned int)*p); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4900 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4901 But the only info to be pushed is regend[*p] and it is known to |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4902 be UNSET, so there really isn't anything to push. |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4903 Not pushing anything, on the other hand deprives us from the |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4904 guarantee that regend[*p] is UNSET since undoing this operation |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4905 will not reset its value properly. This is not important since |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4906 the value will only be read on the next start_memory or at |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4907 the very end and both events can only happen if this stop_memory |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4908 is *not* undone. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4909 |
941 | 4910 regend[*p] = d; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4911 DEBUG_PRINT2 (" regend: %d\n", POINTER_TO_OFFSET (regend[*p])); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4912 |
941 | 4913 /* Move past the register number and the inner group count. */ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
4914 p += 1; |
941 | 4915 break; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4916 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4917 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4918 /* \<digit> has been turned into a `duplicate' command which is |
941 | 4919 followed by the numeric value of <digit> as the register number. */ |
4920 case duplicate: | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4921 { |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
4922 register re_char *d2, *dend2; |
941 | 4923 int regno = *p++; /* Get which register to match against. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4924 DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4925 |
941 | 4926 /* Can't back reference a group which we've never matched. */ |
4927 if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno])) | |
4928 goto fail; | |
4929 | |
4930 /* Where in input to try to start matching. */ | |
4931 d2 = regstart[regno]; | |
4932 | |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4933 /* Remember the start point to rollback upon failure. */ |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4934 dfail = d; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4935 |
941 | 4936 /* Where to stop matching; if both the place to start and |
4937 the place to stop matching are in the same string, then | |
4938 set to the place to stop, otherwise, for now have to use | |
4939 the end of the first string. */ | |
4940 | |
4941 dend2 = ((FIRST_STRING_P (regstart[regno]) | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4942 == FIRST_STRING_P (regend[regno])) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4943 ? regend[regno] : end_match_1); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4944 for (;;) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4945 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4946 /* If necessary, advance to next segment in register |
941 | 4947 contents. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4948 while (d2 == dend2) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4949 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4950 if (dend2 == end_match_2) break; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4951 if (dend2 == regend[regno]) break; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4952 |
941 | 4953 /* End of string1 => advance to string2. */ |
4954 d2 = string2; | |
4955 dend2 = regend[regno]; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4956 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4957 /* At end of register contents => success */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4958 if (d2 == dend2) break; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4959 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4960 /* If necessary, advance to next segment in data. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4961 PREFETCH (); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4962 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4963 /* How many characters left in this segment to match. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4964 mcnt = dend - d; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4965 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4966 /* Want how many consecutive characters we can match in |
941 | 4967 one shot, so, if necessary, adjust the count. */ |
4968 if (mcnt > dend2 - d2) | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4969 mcnt = dend2 - d2; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
4970 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4971 /* Compare that many; failure if mismatch, else move |
941 | 4972 past them. */ |
1328
0aa10b723959
Use RE_TRANSLATE_P to check whether translation is
Andreas Schwab <schwab@suse.de>
parents:
1326
diff
changeset
|
4973 if (RE_TRANSLATE_P (translate) |
941 | 4974 ? bcmp_translate (d, d2, mcnt, translate) |
4975 : bcmp (d, d2, mcnt)) | |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4976 { |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4977 d = dfail; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4978 goto fail; |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
4979 } |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4980 d += mcnt, d2 += mcnt; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4981 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4982 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4983 break; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4984 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4985 |
941 | 4986 /* begline matches the empty string at the beginning of the string |
4987 (unless `not_bol' is set in `bufp'), and, if | |
4988 `newline_anchor' is set, after newlines. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
4989 case begline: |
941 | 4990 DEBUG_PRINT1 ("EXECUTING begline.\n"); |
4991 | |
4992 if (AT_STRINGS_BEG (d)) | |
4993 { | |
4994 if (!bufp->not_bol) break; | |
4995 } | |
4996 else if (d[-1] == '\n' && bufp->newline_anchor) | |
4997 { | |
4998 break; | |
4999 } | |
5000 /* In all other cases, we fail. */ | |
5001 goto fail; | |
5002 | |
5003 | |
5004 /* endline is the dual of begline. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5005 case endline: |
941 | 5006 DEBUG_PRINT1 ("EXECUTING endline.\n"); |
5007 | |
5008 if (AT_STRINGS_END (d)) | |
5009 { | |
5010 if (!bufp->not_eol) break; | |
5011 } | |
5012 | |
5013 /* We have to ``prefetch'' the next character. */ | |
5014 else if ((d == end1 ? *string2 : *d) == '\n' | |
5015 && bufp->newline_anchor) | |
5016 { | |
5017 break; | |
5018 } | |
5019 goto fail; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5020 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5021 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5022 /* Match at the very beginning of the data. */ |
941 | 5023 case begbuf: |
5024 DEBUG_PRINT1 ("EXECUTING begbuf.\n"); | |
5025 if (AT_STRINGS_BEG (d)) | |
5026 break; | |
5027 goto fail; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5028 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5029 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5030 /* Match at the very end of the data. */ |
941 | 5031 case endbuf: |
5032 DEBUG_PRINT1 ("EXECUTING endbuf.\n"); | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5033 if (AT_STRINGS_END (d)) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5034 break; |
941 | 5035 goto fail; |
5036 | |
5037 | |
5038 /* on_failure_keep_string_jump is used to optimize `.*\n'. It | |
5039 pushes NULL as the value for the string on the stack. Then | |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5040 `POP_FAILURE_POINT' will keep the current value for the |
941 | 5041 string, instead of restoring it. To see why, consider |
5042 matching `foo\nbar' against `.*\n'. The .* matches the foo; | |
5043 then the . fails against the \n. But the next thing we want | |
5044 to do is match the \n against the \n; if we restored the | |
5045 string value, we would be back at the foo. | |
5046 | |
5047 Because this is used only in specific cases, we don't need to | |
5048 check all the things that `on_failure_jump' does, to make | |
5049 sure the right things get saved on the stack. Hence we don't | |
5050 share its code. The only reason to push anything on the | |
5051 stack at all is that otherwise we would have to change | |
5052 `anychar's code to do something besides goto fail in this | |
5053 case; that seems worse than this. */ | |
5054 case on_failure_keep_string_jump: | |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5055 EXTRACT_NUMBER_AND_INCR (mcnt, p); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5056 DEBUG_PRINT3 ("EXECUTING on_failure_keep_string_jump %d (to %p):\n", |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5057 mcnt, p + mcnt); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5058 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5059 PUSH_FAILURE_POINT (p - 3, NULL); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5060 break; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5061 |
2370
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5062 /* A nasty loop is introduced by the non-greedy *? and +?. |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5063 With such loops, the stack only ever contains one failure point |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5064 at a time, so that a plain on_failure_jump_loop kind of |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5065 cycle detection cannot work. Worse yet, such a detection |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5066 can not only fail to detect a cycle, but it can also wrongly |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5067 detect a cycle (between different instantiations of the same |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5068 loop. |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5069 So the method used for those nasty loops is a little different: |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5070 We use a special cycle-detection-stack-frame which is pushed |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5071 when the on_failure_jump_nastyloop failure-point is *popped*. |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5072 This special frame thus marks the beginning of one iteration |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5073 through the loop and we can hence easily check right here |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5074 whether something matched between the beginning and the end of |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5075 the loop. */ |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5076 case on_failure_jump_nastyloop: |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5077 EXTRACT_NUMBER_AND_INCR (mcnt, p); |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5078 DEBUG_PRINT3 ("EXECUTING on_failure_jump_nastyloop %d (to %p):\n", |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5079 mcnt, p + mcnt); |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5080 |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5081 assert ((re_opcode_t)p[-4] == no_op); |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5082 CHECK_INFINITE_LOOP (p - 4, d); |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5083 PUSH_FAILURE_POINT (p - 3, d); |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5084 break; |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5085 |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
5086 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
5087 /* Simple loop detecting on_failure_jump: just check on the |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
5088 failure stack if the same spot was already hit earlier. */ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5089 case on_failure_jump_loop: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5090 on_failure: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5091 EXTRACT_NUMBER_AND_INCR (mcnt, p); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5092 DEBUG_PRINT3 ("EXECUTING on_failure_jump_loop %d (to %p):\n", |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5093 mcnt, p + mcnt); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5094 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5095 CHECK_INFINITE_LOOP (p - 3, d); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5096 PUSH_FAILURE_POINT (p - 3, d); |
941 | 5097 break; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5098 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5099 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5100 /* Uses of on_failure_jump: |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5101 |
941 | 5102 Each alternative starts with an on_failure_jump that points |
5103 to the beginning of the next alternative. Each alternative | |
5104 except the last ends with a jump that in effect jumps past | |
5105 the rest of the alternatives. (They really jump to the | |
5106 ending jump of the following alternative, because tensioning | |
5107 these jumps is a hassle.) | |
5108 | |
5109 Repeats start with an on_failure_jump that points past both | |
5110 the repetition text and either the following jump or | |
5111 pop_failure_jump back to this on_failure_jump. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5112 case on_failure_jump: |
1660
ef1f39a7e7c3
(re_match_2_internal) [WINDOWSNT & emacs]: Insert QUIT at various places.
Richard Stallman <rms@gnu.org>
parents:
1583
diff
changeset
|
5113 QUIT; |
941 | 5114 EXTRACT_NUMBER_AND_INCR (mcnt, p); |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5115 DEBUG_PRINT3 ("EXECUTING on_failure_jump %d (to %p):\n", |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5116 mcnt, p + mcnt); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5117 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5118 PUSH_FAILURE_POINT (p -3, d); |
941 | 5119 break; |
5120 | |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
5121 /* This operation is used for greedy *. |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5122 Compare the beginning of the repeat with what in the |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5123 pattern follows its end. If we can establish that there |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5124 is nothing that they would both match, i.e., that we |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5125 would have to backtrack because of (as in, e.g., `a*a') |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5126 then we can use a non-backtracking loop based on |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
5127 on_failure_keep_string_jump instead of on_failure_jump. */ |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5128 case on_failure_jump_smart: |
1660
ef1f39a7e7c3
(re_match_2_internal) [WINDOWSNT & emacs]: Insert QUIT at various places.
Richard Stallman <rms@gnu.org>
parents:
1583
diff
changeset
|
5129 QUIT; |
941 | 5130 EXTRACT_NUMBER_AND_INCR (mcnt, p); |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5131 DEBUG_PRINT3 ("EXECUTING on_failure_jump_smart %d (to %p).\n", |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5132 mcnt, p + mcnt); |
941 | 5133 { |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5134 unsigned char *p1 = p; /* Next operation. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5135 unsigned char *p2 = p + mcnt; /* Destination of the jump. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5136 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5137 p -= 3; /* Reset so that we will re-execute the |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5138 instruction once it's been changed. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5139 |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
5140 EXTRACT_NUMBER (mcnt, p2 - 2); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
5141 |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
5142 /* Ensure this is a indeed the trivial kind of loop |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
5143 we are expecting. */ |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
5144 assert (skip_one_char (p1) == p2 - 3); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
5145 assert ((re_opcode_t) p2[-3] == jump && p2 + mcnt == p); |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
5146 DEBUG_STATEMENT (debug += 2); |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5147 if (mutually_exclusive_p (bufp, p1, p2)) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5148 { |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5149 /* Use a fast `on_failure_keep_string_jump' loop. */ |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
5150 DEBUG_PRINT1 (" smart exclusive => fast loop.\n"); |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
5151 *p = (unsigned char) on_failure_keep_string_jump; |
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
5152 STORE_NUMBER (p2 - 2, mcnt + 3); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5153 } |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5154 else |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5155 { |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5156 /* Default to a safe `on_failure_jump' loop. */ |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5157 DEBUG_PRINT1 (" smart default => slow loop.\n"); |
2355
0786b40fdf1c
(RE_STRING_CHAR): New macro.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2350
diff
changeset
|
5158 *p = (unsigned char) on_failure_jump; |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5159 } |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
5160 DEBUG_STATEMENT (debug -= 2); |
939 | 5161 } |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5162 break; |
941 | 5163 |
5164 /* Unconditionally jump (without popping any failure points). */ | |
5165 case jump: | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5166 unconditional_jump: |
1660
ef1f39a7e7c3
(re_match_2_internal) [WINDOWSNT & emacs]: Insert QUIT at various places.
Richard Stallman <rms@gnu.org>
parents:
1583
diff
changeset
|
5167 QUIT; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5168 EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */ |
941 | 5169 DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt); |
5170 p += mcnt; /* Do the jump. */ | |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5171 DEBUG_PRINT2 ("(to %p).\n", p); |
941 | 5172 break; |
5173 | |
5174 | |
5175 /* Have to succeed matching what follows at least n times. | |
5176 After that, handle like `on_failure_jump'. */ | |
5177 case succeed_n: | |
5178 EXTRACT_NUMBER (mcnt, p + 2); | |
5179 DEBUG_PRINT2 ("EXECUTING succeed_n %d.\n", mcnt); | |
5180 | |
5181 assert (mcnt >= 0); | |
5182 /* Originally, this is how many times we HAVE to succeed. */ | |
5183 if (mcnt > 0) | |
5184 { | |
5185 mcnt--; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5186 p += 2; |
941 | 5187 STORE_NUMBER_AND_INCR (p, mcnt); |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5188 DEBUG_PRINT3 (" Setting %p to %d.\n", p, mcnt); |
941 | 5189 } |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5190 else if (mcnt == 0) |
941 | 5191 { |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5192 DEBUG_PRINT2 (" Setting two bytes from %p to no_op.\n", p+2); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5193 p[2] = (unsigned char) no_op; |
941 | 5194 p[3] = (unsigned char) no_op; |
5195 goto on_failure; | |
5196 } | |
5197 break; | |
5198 | |
5199 case jump_n: | |
5200 EXTRACT_NUMBER (mcnt, p + 2); | |
5201 DEBUG_PRINT2 ("EXECUTING jump_n %d.\n", mcnt); | |
5202 | |
5203 /* Originally, this is how many times we CAN jump. */ | |
5204 if (mcnt) | |
5205 { | |
5206 mcnt--; | |
5207 STORE_NUMBER (p + 2, mcnt); | |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5208 goto unconditional_jump; |
941 | 5209 } |
5210 /* If don't have to jump any more, skip over the rest of command. */ | |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5211 else |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5212 p += 4; |
941 | 5213 break; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5214 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5215 case set_number_at: |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5216 { |
941 | 5217 DEBUG_PRINT1 ("EXECUTING set_number_at.\n"); |
5218 | |
5219 EXTRACT_NUMBER_AND_INCR (mcnt, p); | |
5220 p1 = p + mcnt; | |
5221 EXTRACT_NUMBER_AND_INCR (mcnt, p); | |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5222 DEBUG_PRINT3 (" Setting %p to %d.\n", p1, mcnt); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5223 STORE_NUMBER (p1, mcnt); |
941 | 5224 break; |
5225 } | |
521
7089c3a3a164
(AT_WORD_BOUNDARY): Disable macro.
Karl Heuer <kwzh@gnu.org>
parents:
515
diff
changeset
|
5226 |
7089c3a3a164
(AT_WORD_BOUNDARY): Disable macro.
Karl Heuer <kwzh@gnu.org>
parents:
515
diff
changeset
|
5227 case wordbound: |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5228 case notwordbound: |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5229 not = (re_opcode_t) *(p - 1) == notwordbound; |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5230 DEBUG_PRINT2 ("EXECUTING %swordbound.\n", not?"not":""); |
939 | 5231 |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
5232 /* We SUCCEED (or FAIL) in one of the following cases: */ |
939 | 5233 |
5234 /* Case 1: D is at the beginning or the end of string. */ | |
521
7089c3a3a164
(AT_WORD_BOUNDARY): Disable macro.
Karl Heuer <kwzh@gnu.org>
parents:
515
diff
changeset
|
5235 if (AT_STRINGS_BEG (d) || AT_STRINGS_END (d)) |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5236 not = !not; |
939 | 5237 else |
5238 { | |
5239 /* C1 is the character before D, S1 is the syntax of C1, C2 | |
5240 is the character at D, and S2 is the syntax of C2. */ | |
5241 int c1, c2, s1, s2; | |
5242 #ifdef emacs | |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5243 int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (PTR_TO_OFFSET (d - 1)); |
1204
28ff40a118b8
(re_search_2): Fix call to CHAR_HEAD_P.
Richard Stallman <rms@gnu.org>
parents:
1158
diff
changeset
|
5244 UPDATE_SYNTAX_TABLE (charpos); |
941 | 5245 #endif |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5246 /* FIXME: This does a STRING_CHAR even for unibyte buffers. */ |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5247 GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); |
939 | 5248 s1 = SYNTAX (c1); |
5249 #ifdef emacs | |
1204
28ff40a118b8
(re_search_2): Fix call to CHAR_HEAD_P.
Richard Stallman <rms@gnu.org>
parents:
1158
diff
changeset
|
5250 UPDATE_SYNTAX_TABLE_FORWARD (charpos + 1); |
941 | 5251 #endif |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5252 PREFETCH (); |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5253 /* FIXME: This does a STRING_CHAR even for unibyte buffers. */ |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5254 c2 = STRING_CHAR (d, dend - d); |
939 | 5255 s2 = SYNTAX (c2); |
5256 | |
5257 if (/* Case 2: Only one of S1 and S2 is Sword. */ | |
5258 ((s1 == Sword) != (s2 == Sword)) | |
5259 /* Case 3: Both of S1 and S2 are Sword, and macro | |
941 | 5260 WORD_BOUNDARY_P (C1, C2) returns nonzero. */ |
939 | 5261 || ((s1 == Sword) && WORD_BOUNDARY_P (c1, c2))) |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5262 not = !not; |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5263 } |
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5264 if (not) |
521
7089c3a3a164
(AT_WORD_BOUNDARY): Disable macro.
Karl Heuer <kwzh@gnu.org>
parents:
515
diff
changeset
|
5265 break; |
939 | 5266 else |
521
7089c3a3a164
(AT_WORD_BOUNDARY): Disable macro.
Karl Heuer <kwzh@gnu.org>
parents:
515
diff
changeset
|
5267 goto fail; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5268 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5269 case wordbeg: |
941 | 5270 DEBUG_PRINT1 ("EXECUTING wordbeg.\n"); |
939 | 5271 |
5272 /* We FAIL in one of the following cases: */ | |
5273 | |
941 | 5274 /* Case 1: D is at the end of string. */ |
939 | 5275 if (AT_STRINGS_END (d)) |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
5276 goto fail; |
939 | 5277 else |
5278 { | |
5279 /* C1 is the character before D, S1 is the syntax of C1, C2 | |
5280 is the character at D, and S2 is the syntax of C2. */ | |
5281 int c1, c2, s1, s2; | |
5282 #ifdef emacs | |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
5283 int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (PTR_TO_OFFSET (d)); |
1218
51cf07183c67
(re_match_2_internal): Use SYNTAX_TABLE_BYTE_TO_CHAR.
Richard Stallman <rms@gnu.org>
parents:
1204
diff
changeset
|
5284 UPDATE_SYNTAX_TABLE (charpos); |
941 | 5285 #endif |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
5286 PREFETCH (); |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
5287 /* FIXME: This does a STRING_CHAR even for unibyte buffers. */ |
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
5288 c2 = STRING_CHAR (d, dend - d); |
939 | 5289 s2 = SYNTAX (c2); |
941 | 5290 |
939 | 5291 /* Case 2: S2 is not Sword. */ |
5292 if (s2 != Sword) | |
5293 goto fail; | |
5294 | |
5295 /* Case 3: D is not at the beginning of string ... */ | |
5296 if (!AT_STRINGS_BEG (d)) | |
5297 { | |
5298 GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); | |
5299 #ifdef emacs | |
1204
28ff40a118b8
(re_search_2): Fix call to CHAR_HEAD_P.
Richard Stallman <rms@gnu.org>
parents:
1158
diff
changeset
|
5300 UPDATE_SYNTAX_TABLE_BACKWARD (charpos - 1); |
941 | 5301 #endif |
939 | 5302 s1 = SYNTAX (c1); |
5303 | |
5304 /* ... and S1 is Sword, and WORD_BOUNDARY_P (C1, C2) | |
941 | 5305 returns 0. */ |
939 | 5306 if ((s1 == Sword) && !WORD_BOUNDARY_P (c1, c2)) |
5307 goto fail; | |
5308 } | |
5309 } | |
5310 break; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5311 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5312 case wordend: |
941 | 5313 DEBUG_PRINT1 ("EXECUTING wordend.\n"); |
939 | 5314 |
5315 /* We FAIL in one of the following cases: */ | |
5316 | |
5317 /* Case 1: D is at the beginning of string. */ | |
5318 if (AT_STRINGS_BEG (d)) | |
5319 goto fail; | |
5320 else | |
5321 { | |
5322 /* C1 is the character before D, S1 is the syntax of C1, C2 | |
5323 is the character at D, and S2 is the syntax of C2. */ | |
5324 int c1, c2, s1, s2; | |
1204
28ff40a118b8
(re_search_2): Fix call to CHAR_HEAD_P.
Richard Stallman <rms@gnu.org>
parents:
1158
diff
changeset
|
5325 #ifdef emacs |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
5326 int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (PTR_TO_OFFSET (d) - 1); |
1218
51cf07183c67
(re_match_2_internal): Use SYNTAX_TABLE_BYTE_TO_CHAR.
Richard Stallman <rms@gnu.org>
parents:
1204
diff
changeset
|
5327 UPDATE_SYNTAX_TABLE (charpos); |
1204
28ff40a118b8
(re_search_2): Fix call to CHAR_HEAD_P.
Richard Stallman <rms@gnu.org>
parents:
1158
diff
changeset
|
5328 #endif |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
5329 GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2); |
939 | 5330 s1 = SYNTAX (c1); |
5331 | |
5332 /* Case 2: S1 is not Sword. */ | |
5333 if (s1 != Sword) | |
5334 goto fail; | |
5335 | |
5336 /* Case 3: D is not at the end of string ... */ | |
5337 if (!AT_STRINGS_END (d)) | |
5338 { | |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5339 PREFETCH (); |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
5340 /* FIXME: This does a STRING_CHAR even for unibyte buffers. */ |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5341 c2 = STRING_CHAR (d, dend - d); |
1204
28ff40a118b8
(re_search_2): Fix call to CHAR_HEAD_P.
Richard Stallman <rms@gnu.org>
parents:
1158
diff
changeset
|
5342 #ifdef emacs |
28ff40a118b8
(re_search_2): Fix call to CHAR_HEAD_P.
Richard Stallman <rms@gnu.org>
parents:
1158
diff
changeset
|
5343 UPDATE_SYNTAX_TABLE_FORWARD (charpos); |
28ff40a118b8
(re_search_2): Fix call to CHAR_HEAD_P.
Richard Stallman <rms@gnu.org>
parents:
1158
diff
changeset
|
5344 #endif |
939 | 5345 s2 = SYNTAX (c2); |
5346 | |
5347 /* ... and S2 is Sword, and WORD_BOUNDARY_P (C1, C2) | |
941 | 5348 returns 0. */ |
939 | 5349 if ((s2 == Sword) && !WORD_BOUNDARY_P (c1, c2)) |
941 | 5350 goto fail; |
939 | 5351 } |
5352 } | |
5353 break; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5354 |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5355 case syntaxspec: |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5356 case notsyntaxspec: |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5357 not = (re_opcode_t) *(p - 1) == notsyntaxspec; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5358 mcnt = *p++; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5359 DEBUG_PRINT3 ("EXECUTING %ssyntaxspec %d.\n", not?"not":"", mcnt); |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5360 PREFETCH (); |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5361 #ifdef emacs |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5362 { |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5363 int pos1 = SYNTAX_TABLE_BYTE_TO_CHAR (PTR_TO_OFFSET (d)); |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5364 UPDATE_SYNTAX_TABLE (pos1); |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5365 } |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5366 #endif |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5367 { |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5368 int c, len; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5369 |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5370 if (multibyte) |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5371 /* we must concern about multibyte form, ... */ |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5372 c = STRING_CHAR_AND_LENGTH (d, dend - d, len); |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5373 else |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5374 /* everything should be handled as ASCII, even though it |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5375 looks like multibyte form. */ |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5376 c = *d, len = 1; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5377 |
2359
dbf725277cfc
(enum syntaxcode): Provide default for non-Emacs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2357
diff
changeset
|
5378 if ((SYNTAX (c) != (enum syntaxcode) mcnt) ^ not) |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5379 goto fail; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5380 d += len; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5381 } |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5382 break; |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5383 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5384 #ifdef emacs |
941 | 5385 case before_dot: |
5386 DEBUG_PRINT1 ("EXECUTING before_dot.\n"); | |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5387 if (PTR_BYTE_POS (d) >= PT_BYTE) |
941 | 5388 goto fail; |
5389 break; | |
5390 | |
5391 case at_dot: | |
5392 DEBUG_PRINT1 ("EXECUTING at_dot.\n"); | |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5393 if (PTR_BYTE_POS (d) != PT_BYTE) |
941 | 5394 goto fail; |
5395 break; | |
5396 | |
5397 case after_dot: | |
5398 DEBUG_PRINT1 ("EXECUTING after_dot.\n"); | |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5399 if (PTR_BYTE_POS (d) <= PT_BYTE) |
941 | 5400 goto fail; |
5401 break; | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5402 |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5403 case categoryspec: |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5404 case notcategoryspec: |
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5405 not = (re_opcode_t) *(p - 1) == notcategoryspec; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5406 mcnt = *p++; |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5407 DEBUG_PRINT3 ("EXECUTING %scategoryspec %d.\n", not?"not":"", mcnt); |
939 | 5408 PREFETCH (); |
5409 { | |
5410 int c, len; | |
5411 | |
5412 if (multibyte) | |
5413 c = STRING_CHAR_AND_LENGTH (d, dend - d, len); | |
5414 else | |
5415 c = *d, len = 1; | |
5416 | |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5417 if ((!CHAR_HAS_CATEGORY (c, mcnt)) ^ not) |
939 | 5418 goto fail; |
5419 d += len; | |
5420 } | |
5421 break; | |
5422 | |
2356
d93889e88226
(CHAR_CHARSET, CHARSET_LEADING_CODE_BASE): Add default
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2355
diff
changeset
|
5423 #endif /* emacs */ |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5424 |
939 | 5425 default: |
5426 abort (); | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5427 } |
939 | 5428 continue; /* Successfully executed one pattern command; keep going. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5429 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5430 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5431 /* We goto here if a matching operation fails. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5432 fail: |
1660
ef1f39a7e7c3
(re_match_2_internal) [WINDOWSNT & emacs]: Insert QUIT at various places.
Richard Stallman <rms@gnu.org>
parents:
1583
diff
changeset
|
5433 QUIT; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5434 if (!FAIL_STACK_EMPTY ()) |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5435 { |
2349
5fa185a9956e
* regex.c: Declare a new type `re_char' used throughout the code for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2345
diff
changeset
|
5436 re_char *str; |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5437 unsigned char *pat; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5438 /* A restart point is known. Restore to that state. */ |
939 | 5439 DEBUG_PRINT1 ("\nFAIL:\n"); |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5440 POP_FAILURE_POINT (str, pat); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5441 switch (SWITCH_ENUM_CAST ((re_opcode_t) *pat++)) |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5442 { |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5443 case on_failure_keep_string_jump: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5444 assert (str == NULL); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5445 goto continue_failure_jump; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5446 |
2370
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5447 case on_failure_jump_nastyloop: |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5448 assert ((re_opcode_t)pat[-2] == no_op); |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5449 PUSH_FAILURE_POINT (pat - 2, str); |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5450 /* Fallthrough */ |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5451 |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5452 case on_failure_jump_loop: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5453 case on_failure_jump: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5454 case succeed_n: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5455 d = str; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5456 continue_failure_jump: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5457 EXTRACT_NUMBER_AND_INCR (mcnt, pat); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5458 p = pat + mcnt; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5459 break; |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5460 |
2370
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5461 case no_op: |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5462 /* A special frame used for nastyloops. */ |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5463 goto fail; |
d8ded9c0e20c
(enum re_opcode_t): New opcode on_failure_jump_nastyloop.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2359
diff
changeset
|
5464 |
2345
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5465 default: |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5466 abort(); |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5467 } |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5468 |
93d6633849d6
This is a big redesign of failure-stack and register handling, prompted
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2153
diff
changeset
|
5469 assert (p >= bufp->buffer && p <= pend); |
939 | 5470 |
5471 if (d >= string1 && d <= end1) | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5472 dend = end_match_1; |
939 | 5473 } |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5474 else |
939 | 5475 break; /* Matching at this starting point really fails. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5476 } /* for (;;) */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5477 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5478 if (best_regs_set) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5479 goto restore_best_regs; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5480 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5481 FREE_VARIABLES (); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5482 |
939 | 5483 return -1; /* Failure to match. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5484 } /* re_match_2 */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5485 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5486 /* Subroutine definitions for re_match_2. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5487 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5488 /* Return zero if TRANSLATE[S1] and TRANSLATE[S2] are identical for LEN |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5489 bytes; nonzero otherwise. */ |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5490 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5491 static int |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5492 bcmp_translate (s1, s2, len, translate) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5493 unsigned char *s1, *s2; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5494 register int len; |
501
f29b13c2cefd
(TRANSLATE, PATFETCH): Cast elt of `translate'.
Richard Stallman <rms@gnu.org>
parents:
490
diff
changeset
|
5495 RE_TRANSLATE_TYPE translate; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5496 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5497 register unsigned char *p1 = s1, *p2 = s2; |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5498 unsigned char *p1_end = s1 + len; |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5499 unsigned char *p2_end = s2 + len; |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5500 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5501 while (p1 != p1_end && p2 != p2_end) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5502 { |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5503 int p1_charlen, p2_charlen; |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5504 int p1_ch, p2_ch; |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5505 |
2350
f3edfed6aa96
(re_match_2): Fix string shortening (to fit `stop') to make sure
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
2349
diff
changeset
|
5506 /* FIXME: This assumes `multibyte = true'. */ |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5507 p1_ch = STRING_CHAR_AND_LENGTH (p1, p1_end - p1, p1_charlen); |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5508 p2_ch = STRING_CHAR_AND_LENGTH (p2, p2_end - p2, p2_charlen); |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5509 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5510 if (RE_TRANSLATE (translate, p1_ch) |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5511 != RE_TRANSLATE (translate, p2_ch)) |
963
ed0235161e4b
(TRANSLATE, re_search_2, re_match_2_internal,bcmp_translate):
Richard Stallman <rms@gnu.org>
parents:
961
diff
changeset
|
5512 return 1; |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5513 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5514 p1 += p1_charlen, p2 += p2_charlen; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5515 } |
1296
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5516 |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5517 if (p1 != p1_end || p2 != p2_end) |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5518 return 1; |
7b938cc81ae2
(compile_range): Unused function deleted.
Richard Stallman <rms@gnu.org>
parents:
1218
diff
changeset
|
5519 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5520 return 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5521 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5522 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5523 /* Entry points for GNU code. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5524 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5525 /* re_compile_pattern is the GNU regular expression compiler: it |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5526 compiles PATTERN (of length SIZE) and puts the result in BUFP. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5527 Returns 0 if the pattern was valid, otherwise an error string. |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5528 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5529 Assumes the `allocated' (and perhaps `buffer') and `translate' fields |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5530 are set in BUFP on entry. |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5531 |
939 | 5532 We call regex_compile to do the actual compilation. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5533 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5534 const char * |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5535 re_compile_pattern (pattern, length, bufp) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5536 const char *pattern; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5537 int length; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5538 struct re_pattern_buffer *bufp; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5539 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5540 reg_errcode_t ret; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5541 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5542 /* GNU code is written to assume at least RE_NREGS registers will be set |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5543 (and at least one extra will be -1). */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5544 bufp->regs_allocated = REGS_UNALLOCATED; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5545 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5546 /* And GNU code determines whether or not to get register information |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5547 by passing null for the REGS argument to re_match, etc., not by |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5548 setting no_sub. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5549 bufp->no_sub = 0; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5550 |
939 | 5551 /* Match anchors at newline. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5552 bufp->newline_anchor = 1; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5553 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5554 ret = regex_compile (pattern, length, re_syntax_options, bufp); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5555 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5556 if (!ret) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5557 return NULL; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5558 return gettext (re_error_msgid[(int) ret]); |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5559 } |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5560 |
939 | 5561 /* Entry points compatible with 4.2 BSD regex library. We don't define |
5562 them unless specifically requested. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5563 |
622
152fc00ed9b5
Tue May 21 19:18:05 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
Roland McGrath <roland@gnu.org>
parents:
607
diff
changeset
|
5564 #if defined (_REGEX_RE_COMP) || defined (_LIBC) |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5565 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5566 /* BSD has one and only one pattern buffer. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5567 static struct re_pattern_buffer re_comp_buf; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5568 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5569 char * |
636
ddd029a89661
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
parents:
631
diff
changeset
|
5570 #ifdef _LIBC |
ddd029a89661
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
parents:
631
diff
changeset
|
5571 /* Make these definitions weak in libc, so POSIX programs can redefine |
ddd029a89661
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
parents:
631
diff
changeset
|
5572 these names if they don't use our functions, and still use |
ddd029a89661
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
parents:
631
diff
changeset
|
5573 regcomp/regexec below without link errors. */ |
ddd029a89661
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
parents:
631
diff
changeset
|
5574 weak_function |
ddd029a89661
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
parents:
631
diff
changeset
|
5575 #endif |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5576 re_comp (s) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5577 const char *s; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5578 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5579 reg_errcode_t ret; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5580 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5581 if (!s) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5582 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5583 if (!re_comp_buf.buffer) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5584 return gettext ("No previous regular expression"); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5585 return 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5586 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5587 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5588 if (!re_comp_buf.buffer) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5589 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5590 re_comp_buf.buffer = (unsigned char *) malloc (200); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5591 if (re_comp_buf.buffer == NULL) |
939 | 5592 return gettext (re_error_msgid[(int) REG_ESPACE]); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5593 re_comp_buf.allocated = 200; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5594 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5595 re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5596 if (re_comp_buf.fastmap == NULL) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5597 return gettext (re_error_msgid[(int) REG_ESPACE]); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5598 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5599 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5600 /* Since `re_exec' always passes NULL for the `regs' argument, we |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5601 don't need to initialize the pattern buffer fields which affect it. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5602 |
939 | 5603 /* Match anchors at newlines. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5604 re_comp_buf.newline_anchor = 1; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5605 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5606 ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf); |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5607 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5608 if (!ret) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5609 return NULL; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5610 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5611 /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5612 return (char *) gettext (re_error_msgid[(int) ret]); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5613 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5614 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5615 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5616 int |
636
ddd029a89661
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
parents:
631
diff
changeset
|
5617 #ifdef _LIBC |
ddd029a89661
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
parents:
631
diff
changeset
|
5618 weak_function |
ddd029a89661
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
parents:
631
diff
changeset
|
5619 #endif |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5620 re_exec (s) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5621 const char *s; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5622 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5623 const int len = strlen (s); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5624 return |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5625 0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5626 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5627 #endif /* _REGEX_RE_COMP */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5628 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5629 /* POSIX.2 functions. Don't define these for Emacs. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5630 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5631 #ifndef emacs |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5632 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5633 /* regcomp takes a regular expression as a string and compiles it. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5634 |
939 | 5635 PREG is a regex_t *. We do not expect any fields to be initialized, |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5636 since POSIX says we shouldn't. Thus, we set |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5637 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5638 `buffer' to the compiled pattern; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5639 `used' to the length of the compiled pattern; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5640 `syntax' to RE_SYNTAX_POSIX_EXTENDED if the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5641 REG_EXTENDED bit in CFLAGS is set; otherwise, to |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5642 RE_SYNTAX_POSIX_BASIC; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5643 `newline_anchor' to REG_NEWLINE being set in CFLAGS; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5644 `fastmap' and `fastmap_accurate' to zero; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5645 `re_nsub' to the number of subexpressions in PATTERN. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5646 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5647 PATTERN is the address of the pattern string. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5648 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5649 CFLAGS is a series of bits which affect compilation. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5650 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5651 If REG_EXTENDED is set, we use POSIX extended syntax; otherwise, we |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5652 use POSIX basic syntax. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5653 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5654 If REG_NEWLINE is set, then . and [^...] don't match newline. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5655 Also, regexec will try a match beginning after every newline. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5656 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5657 If REG_ICASE is set, then we considers upper- and lowercase |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5658 versions of letters to be equivalent when matching. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5659 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5660 If REG_NOSUB is set, then when PREG is passed to regexec, that |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5661 routine will report only success or failure, and nothing about the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5662 registers. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5663 |
939 | 5664 It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5665 the return codes and their meanings.) */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5666 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5667 int |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5668 regcomp (preg, pattern, cflags) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5669 regex_t *preg; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5670 const char *pattern; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5671 int cflags; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5672 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5673 reg_errcode_t ret; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5674 unsigned syntax |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5675 = (cflags & REG_EXTENDED) ? |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5676 RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5677 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5678 /* regex_compile will allocate the space for the compiled pattern. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5679 preg->buffer = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5680 preg->allocated = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5681 preg->used = 0; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5682 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5683 /* Don't bother to use a fastmap when searching. This simplifies the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5684 REG_NEWLINE case: if we used a fastmap, we'd have to put all the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5685 characters after newlines into the fastmap. This way, we just try |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5686 every character. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5687 preg->fastmap = 0; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5688 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5689 if (cflags & REG_ICASE) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5690 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5691 unsigned i; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5692 |
501
f29b13c2cefd
(TRANSLATE, PATFETCH): Cast elt of `translate'.
Richard Stallman <rms@gnu.org>
parents:
490
diff
changeset
|
5693 preg->translate |
f29b13c2cefd
(TRANSLATE, PATFETCH): Cast elt of `translate'.
Richard Stallman <rms@gnu.org>
parents:
490
diff
changeset
|
5694 = (RE_TRANSLATE_TYPE) malloc (CHAR_SET_SIZE |
f29b13c2cefd
(TRANSLATE, PATFETCH): Cast elt of `translate'.
Richard Stallman <rms@gnu.org>
parents:
490
diff
changeset
|
5695 * sizeof (*(RE_TRANSLATE_TYPE)0)); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5696 if (preg->translate == NULL) |
939 | 5697 return (int) REG_ESPACE; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5698 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5699 /* Map uppercase characters to corresponding lowercase ones. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5700 for (i = 0; i < CHAR_SET_SIZE; i++) |
939 | 5701 preg->translate[i] = ISUPPER (i) ? tolower (i) : i; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5702 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5703 else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5704 preg->translate = NULL; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5705 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5706 /* If REG_NEWLINE is set, newlines are treated differently. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5707 if (cflags & REG_NEWLINE) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5708 { /* REG_NEWLINE implies neither . nor [^...] match newline. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5709 syntax &= ~RE_DOT_NEWLINE; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5710 syntax |= RE_HAT_LISTS_NOT_NEWLINE; |
939 | 5711 /* It also changes the matching behavior. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5712 preg->newline_anchor = 1; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5713 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5714 else |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5715 preg->newline_anchor = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5716 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5717 preg->no_sub = !!(cflags & REG_NOSUB); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5718 |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5719 /* POSIX says a null character in the pattern terminates it, so we |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5720 can use strlen here in compiling the pattern. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5721 ret = regex_compile (pattern, strlen (pattern), syntax, preg); |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5722 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5723 /* POSIX doesn't distinguish between an unmatched open-group and an |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5724 unmatched close-group: both are REG_EPAREN. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5725 if (ret == REG_ERPAREN) ret = REG_EPAREN; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5726 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5727 return (int) ret; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5728 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5729 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5730 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5731 /* regexec searches for a given pattern, specified by PREG, in the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5732 string STRING. |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5733 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5734 If NMATCH is zero or REG_NOSUB was set in the cflags argument to |
939 | 5735 `regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5736 least NMATCH elements, and we set them to the offsets of the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5737 corresponding matched substrings. |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5738 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5739 EFLAGS specifies `execution flags' which affect matching: if |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5740 REG_NOTBOL is set, then ^ does not match at the beginning of the |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5741 string; if REG_NOTEOL is set, then $ does not match at the end. |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5742 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5743 We return 0 if we find a match and REG_NOMATCH if not. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5744 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5745 int |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5746 regexec (preg, string, nmatch, pmatch, eflags) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5747 const regex_t *preg; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5748 const char *string; |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5749 size_t nmatch; |
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5750 regmatch_t pmatch[]; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5751 int eflags; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5752 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5753 int ret; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5754 struct re_registers regs; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5755 regex_t private_preg; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5756 int len = strlen (string); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5757 boolean want_reg_info = !preg->no_sub && nmatch > 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5758 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5759 private_preg = *preg; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5760 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5761 private_preg.not_bol = !!(eflags & REG_NOTBOL); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5762 private_preg.not_eol = !!(eflags & REG_NOTEOL); |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5763 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5764 /* The user has told us exactly how many registers to return |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5765 information about, via `nmatch'. We have to pass that on to the |
939 | 5766 matching routines. */ |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5767 private_preg.regs_allocated = REGS_FIXED; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5768 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5769 if (want_reg_info) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5770 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5771 regs.num_regs = nmatch; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5772 regs.start = TALLOC (nmatch, regoff_t); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5773 regs.end = TALLOC (nmatch, regoff_t); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5774 if (regs.start == NULL || regs.end == NULL) |
939 | 5775 return (int) REG_NOMATCH; |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5776 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5777 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5778 /* Perform the searching operation. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5779 ret = re_search (&private_preg, string, len, |
939 | 5780 /* start: */ 0, /* range: */ len, |
5781 want_reg_info ? ®s : (struct re_registers *) 0); | |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5782 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5783 /* Copy the register information to the POSIX structure. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5784 if (want_reg_info) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5785 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5786 if (ret >= 0) |
939 | 5787 { |
5788 unsigned r; | |
5789 | |
5790 for (r = 0; r < nmatch; r++) | |
5791 { | |
5792 pmatch[r].rm_so = regs.start[r]; | |
5793 pmatch[r].rm_eo = regs.end[r]; | |
5794 } | |
5795 } | |
5796 | |
5797 /* If we needed the temporary register info, free the space now. */ | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5798 free (regs.start); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5799 free (regs.end); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5800 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5801 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5802 /* We want zero return to mean success, unlike `re_search'. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5803 return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5804 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5805 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5806 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5807 /* Returns a message corresponding to an error code, ERRCODE, returned |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5808 from either regcomp or regexec. We don't use PREG here. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5809 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5810 size_t |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5811 regerror (errcode, preg, errbuf, errbuf_size) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5812 int errcode; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5813 const regex_t *preg; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5814 char *errbuf; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5815 size_t errbuf_size; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5816 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5817 const char *msg; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5818 size_t msg_size; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5819 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5820 if (errcode < 0 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5821 || errcode >= (sizeof (re_error_msgid) / sizeof (re_error_msgid[0]))) |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5822 /* Only error codes returned by the rest of the code should be passed |
939 | 5823 to this routine. If we are given anything else, or if other regex |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5824 code generates an invalid error code, then the program has a bug. |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5825 Dump core so we can fix it. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5826 abort (); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5827 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5828 msg = gettext (re_error_msgid[errcode]); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5829 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5830 msg_size = strlen (msg) + 1; /* Includes the null. */ |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5831 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5832 if (errbuf_size != 0) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5833 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5834 if (msg_size > errbuf_size) |
939 | 5835 { |
5836 strncpy (errbuf, msg, errbuf_size - 1); | |
5837 errbuf[errbuf_size - 1] = 0; | |
5838 } | |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5839 else |
939 | 5840 strcpy (errbuf, msg); |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5841 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5842 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5843 return msg_size; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5844 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5845 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5846 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5847 /* Free dynamically allocated space used by PREG. */ |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5848 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5849 void |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5850 regfree (preg) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5851 regex_t *preg; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5852 { |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5853 if (preg->buffer != NULL) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5854 free (preg->buffer); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5855 preg->buffer = NULL; |
515
69ba3b63e1d1
(gettext_noop): New macro, identity fn.
Roland McGrath <roland@gnu.org>
parents:
511
diff
changeset
|
5856 |
441
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5857 preg->allocated = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5858 preg->used = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5859 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5860 if (preg->fastmap != NULL) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5861 free (preg->fastmap); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5862 preg->fastmap = NULL; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5863 preg->fastmap_accurate = 0; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5864 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5865 if (preg->translate != NULL) |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5866 free (preg->translate); |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5867 preg->translate = NULL; |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5868 } |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5869 |
403b2dfdfa0b
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
parents:
438
diff
changeset
|
5870 #endif /* not emacs */ |