16010
|
1 /* Extended regular expression matching and search library, version
|
|
2 0.12. (Implements POSIX draft P10003.2/D11.2, except for
|
1155
|
3 internationalization features.)
|
|
4
|
21963
|
5 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
|
1155
|
6
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
7 This program is free software; you can redistribute it and/or modify
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
8 it under the terms of the GNU General Public License as published by
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
9 the Free Software Foundation; either version 2, or (at your option)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
10 any later version.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
11
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
12 This program is distributed in the hope that it will be useful,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18262
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
15 GNU General Public License for more details.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
16
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
17 You should have received a copy of the GNU General Public License
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
18 along with this program; if not, write to the Free Software
|
14414
|
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
18262
|
20 USA. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
21
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
22 /* AIX requires this to be the first thing in the file. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
23 #if defined (_AIX) && !defined (REGEX_MALLOC)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
24 #pragma alloca
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
25 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
26
|
13517
|
27 #undef _GNU_SOURCE
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
28 #define _GNU_SOURCE
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
29
|
22411
|
30 #ifdef emacs
|
18262
|
31 /* Converts the pointer to the char to BEG-based offset from the start. */
|
|
32 #define PTR_TO_OFFSET(d) \
|
18260
|
33 POS_AS_IN_BUFFER (MATCHING_IN_FIRST_STRING \
|
|
34 ? (d) - string1 : (d) - (string2 - size1))
|
22372
|
35 #define POS_AS_IN_BUFFER(p) ((p) + (NILP (re_match_object) || BUFFERP (re_match_object)))
|
22411
|
36 #else
|
|
37 #define PTR_TO_OFFSET(d) 0
|
|
38 #endif
|
18260
|
39
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
40 #ifdef HAVE_CONFIG_H
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
41 #include <config.h>
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
42 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
43
|
18262
|
44 /* We need this for `regex.h', and perhaps for the Emacs include files. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
45 #include <sys/types.h>
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
46
|
18262
|
47 /* This is for other GNU distributions with internationalized messages. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
48 #if HAVE_LIBINTL_H || defined (_LIBC)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
49 # include <libintl.h>
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
50 #else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
51 # define gettext(msgid) (msgid)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
52 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
53
|
13565
|
54 #ifndef gettext_noop
|
|
55 /* This define is so xgettext can find the internationalizable
|
|
56 strings. */
|
|
57 #define gettext_noop(String) String
|
|
58 #endif
|
|
59
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
60 /* The `emacs' switch turns on certain matching commands
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
61 that make sense only in Emacs. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
62 #ifdef emacs
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
63
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
64 #include "lisp.h"
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
65 #include "buffer.h"
|
18260
|
66
|
|
67 /* Make syntax table lookup grant data in gl_state. */
|
|
68 #define SYNTAX_ENTRY_VIA_PROPERTY
|
|
69
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
70 #include "syntax.h"
|
18260
|
71 #include "charset.h"
|
|
72 #include "category.h"
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
73
|
16537
|
74 #define malloc xmalloc
|
21558
|
75 #define realloc xrealloc
|
16537
|
76 #define free xfree
|
|
77
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
78 #else /* not emacs */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
79
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
80 /* If we are not linking with Emacs proper,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
81 we can't use the relocating allocator
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
82 even if config.h says that we can. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
83 #undef REL_ALLOC
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
84
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
85 #if defined (STDC_HEADERS) || defined (_LIBC)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
86 #include <stdlib.h>
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
87 #else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
88 char *malloc ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
89 char *realloc ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
90 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
91
|
12065
|
92 /* When used in Emacs's lib-src, we need to get bzero and bcopy somehow.
|
18262
|
93 If nothing else has been done, use the method below. */
|
12065
|
94 #ifdef INHIBIT_STRING_HEADER
|
|
95 #if !(defined (HAVE_BZERO) && defined (HAVE_BCOPY))
|
|
96 #if !defined (bzero) && !defined (bcopy)
|
|
97 #undef INHIBIT_STRING_HEADER
|
|
98 #endif
|
|
99 #endif
|
|
100 #endif
|
|
101
|
|
102 /* This is the normal way of making sure we have a bcopy and a bzero.
|
|
103 This is used in most programs--a few other programs avoid this
|
|
104 by defining INHIBIT_STRING_HEADER. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
105 #ifndef INHIBIT_STRING_HEADER
|
12331
|
106 #if defined (HAVE_STRING_H) || defined (STDC_HEADERS) || defined (_LIBC)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
107 #include <string.h>
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
108 #ifndef bcmp
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
109 #define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
110 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
111 #ifndef bcopy
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
112 #define bcopy(s, d, n) memcpy ((d), (s), (n))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
113 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
114 #ifndef bzero
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
115 #define bzero(s, n) memset ((s), 0, (n))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
116 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
117 #else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
118 #include <strings.h>
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
119 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
120 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
121
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
122 /* Define the syntax stuff for \<, \>, etc. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
123
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
124 /* This must be nonzero for the wordchar and notwordchar pattern
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
125 commands in re_match_2. */
|
13565
|
126 #ifndef Sword
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
127 #define Sword 1
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
128 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
129
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
130 #ifdef SWITCH_ENUM_BUG
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
131 #define SWITCH_ENUM_CAST(x) ((int)(x))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
132 #else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
133 #define SWITCH_ENUM_CAST(x) (x)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
134 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
135
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
136 #ifdef SYNTAX_TABLE
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
137
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
138 extern char *re_syntax_table;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
139
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
140 #else /* not SYNTAX_TABLE */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
141
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
142 /* How many characters in the character set. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
143 #define CHAR_SET_SIZE 256
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
144
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
145 static char re_syntax_table[CHAR_SET_SIZE];
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
146
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
147 static void
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
148 init_syntax_once ()
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
149 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
150 register int c;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
151 static int done = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
152
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
153 if (done)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
154 return;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
155
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
156 bzero (re_syntax_table, sizeof re_syntax_table);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
157
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
158 for (c = 'a'; c <= 'z'; c++)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
159 re_syntax_table[c] = Sword;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
160
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
161 for (c = 'A'; c <= 'Z'; c++)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
162 re_syntax_table[c] = Sword;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
163
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
164 for (c = '0'; c <= '9'; c++)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
165 re_syntax_table[c] = Sword;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
166
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
167 re_syntax_table['_'] = Sword;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
168
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
169 done = 1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
170 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
171
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
172 #endif /* not SYNTAX_TABLE */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
173
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
174 #define SYNTAX(c) re_syntax_table[c]
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
175
|
21348
|
176 /* Dummy macros for non-Emacs environments. */
|
18260
|
177 #define BASE_LEADING_CODE_P(c) (0)
|
|
178 #define WORD_BOUNDARY_P(c1, c2) (0)
|
|
179 #define CHAR_HEAD_P(p) (1)
|
|
180 #define SINGLE_BYTE_CHAR_P(c) (1)
|
|
181 #define SAME_CHARSET_P(c1, c2) (1)
|
|
182 #define MULTIBYTE_FORM_LENGTH(p, s) (1)
|
|
183 #define STRING_CHAR(p, s) (*(p))
|
|
184 #define STRING_CHAR_AND_LENGTH(p, s, actual_len) ((actual_len) = 1, *(p))
|
|
185 #define GET_CHAR_AFTER_2(c, p, str1, end1, str2, end2) \
|
|
186 (c = ((p) == (end1) ? *(str2) : *(p)))
|
|
187 #define GET_CHAR_BEFORE_2(c, p, str1, end1, str2, end2) \
|
|
188 (c = ((p) == (str2) ? *((end1) - 1) : *((p) - 1)))
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
189 #endif /* not emacs */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
190
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
191 /* Get the interface, including the syntax bits. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
192 #include "regex.h"
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
193
|
25877
|
194 /* isalpha etc. are used for the character classes. */
|
|
195 #include <ctype.h>
|
|
196
|
|
197 #ifdef emacs
|
|
198
|
|
199 /* 1 if C is an ASCII character. */
|
|
200 #define IS_REAL_ASCII(c) ((c) < 0200)
|
|
201
|
|
202 /* 1 if C is a unibyte character. */
|
|
203 #define ISUNIBYTE(c) (SINGLE_BYTE_CHAR_P ((c)))
|
|
204
|
|
205 /* The Emacs definitions should not be directly affected by locales. */
|
|
206
|
|
207 /* In Emacs, these are only used for single-byte characters. */
|
|
208 #define ISDIGIT(c) ((c) >= '0' && (c) <= '9')
|
|
209 #define ISCNTRL(c) ((c) < ' ')
|
|
210 #define ISXDIGIT(c) (((c) >= '0' && (c) <= '9') \
|
|
211 || ((c) >= 'a' && (c) <= 'f') \
|
|
212 || ((c) >= 'A' && (c) <= 'F'))
|
|
213
|
|
214 /* This is only used for single-byte characters. */
|
|
215 #define ISBLANK(c) ((c) == ' ' || (c) == '\t')
|
|
216
|
|
217 /* The rest must handle multibyte characters. */
|
|
218
|
|
219 #define ISGRAPH(c) (SINGLE_BYTE_CHAR_P (c) \
|
|
220 ? (c) > ' ' && !((c) >= 0177 && (c) <= 0237) \
|
|
221 : 1)
|
|
222
|
|
223 #define ISPRINT(c) (SINGLE_BYTE_CHAR_P (c) \
|
|
224 ? (c) >= ' ' && !((c) >= 0177 && (c) <= 0237) \
|
|
225 : 1)
|
|
226
|
|
227 #define ISALNUM(c) (IS_REAL_ASCII (c) \
|
|
228 ? (((c) >= 'a' && (c) <= 'z') \
|
|
229 || ((c) >= 'A' && (c) <= 'Z') \
|
|
230 || ((c) >= '0' && (c) <= '9')) \
|
|
231 : SYNTAX (c) == Sword)
|
|
232
|
|
233 #define ISALPHA(c) (IS_REAL_ASCII (c) \
|
|
234 ? (((c) >= 'a' && (c) <= 'z') \
|
|
235 || ((c) >= 'A' && (c) <= 'Z')) \
|
|
236 : SYNTAX (c) == Sword)
|
|
237
|
|
238 #define ISLOWER(c) (LOWERCASEP (c))
|
|
239
|
|
240 #define ISPUNCT(c) (IS_REAL_ASCII (c) \
|
|
241 ? ((c) > ' ' && (c) < 0177 \
|
|
242 && !(((c) >= 'a' && (c) <= 'z') \
|
|
243 || ((c) >= 'A' && (c) <= 'Z') \
|
|
244 || ((c) >= '0' && (c) <= '9'))) \
|
|
245 : SYNTAX (c) != Sword)
|
|
246
|
|
247 #define ISSPACE(c) (SYNTAX (c) == Swhitespace)
|
|
248
|
|
249 #define ISUPPER(c) (UPPERCASEP (c))
|
|
250
|
|
251 #define ISWORD(c) (SYNTAX (c) == Sword)
|
|
252
|
|
253 #else /* not emacs */
|
|
254
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
255 /* Jim Meyering writes:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
256
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
257 "... Some ctype macros are valid only for character codes that
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
258 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
259 using /bin/cc or gcc but without giving an ansi option). So, all
|
18262
|
260 ctype uses should be through macros like ISPRINT... If
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
261 STDC_HEADERS is defined, then autoconf has verified that the ctype
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
262 macros don't need to be guarded with references to isascii. ...
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
263 Defining isascii to 1 should let any compiler worth its salt
|
18262
|
264 eliminate the && through constant folding." */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
265
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
266 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
267 #define ISASCII(c) 1
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
268 #else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
269 #define ISASCII(c) isascii(c)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
270 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
271
|
25877
|
272 /* 1 if C is an ASCII character. */
|
|
273 #define IS_REAL_ASCII(c) ((c) < 0200)
|
|
274
|
|
275 /* This distinction is not meaningful, except in Emacs. */
|
|
276 #define ISUNIBYTE(c) 1
|
|
277
|
25440
|
278 #define ISDIGIT(c) (ISASCII (c) && isdigit (c))
|
|
279 #define ISCNTRL(c) (ISASCII (c) && iscntrl (c))
|
|
280 #define ISXDIGIT(c) (ISASCII (c) && isxdigit (c))
|
|
281
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
282 #ifdef isblank
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
283 #define ISBLANK(c) (ISASCII (c) && isblank (c))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
284 #else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
285 #define ISBLANK(c) ((c) == ' ' || (c) == '\t')
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
286 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
287 #ifdef isgraph
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
288 #define ISGRAPH(c) (ISASCII (c) && isgraph (c))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
289 #else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
290 #define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
291 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
292
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
293 #define ISPRINT(c) (ISASCII (c) && isprint (c))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
294 #define ISDIGIT(c) (ISASCII (c) && isdigit (c))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
295 #define ISALNUM(c) (ISASCII (c) && isalnum (c))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
296 #define ISALPHA(c) (ISASCII (c) && isalpha (c))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
297 #define ISCNTRL(c) (ISASCII (c) && iscntrl (c))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
298 #define ISLOWER(c) (ISASCII (c) && islower (c))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
299 #define ISPUNCT(c) (ISASCII (c) && ispunct (c))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
300 #define ISSPACE(c) (ISASCII (c) && isspace (c))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
301 #define ISUPPER(c) (ISASCII (c) && isupper (c))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
302 #define ISXDIGIT(c) (ISASCII (c) && isxdigit (c))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
303
|
25440
|
304 #define ISWORD(c) ISALPHA(c)
|
|
305
|
|
306 #endif /* not emacs */
|
|
307
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
308 #ifndef NULL
|
11952
|
309 #define NULL (void *)0
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
310 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
311
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
312 /* We remove any previous definition of `SIGN_EXTEND_CHAR',
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
313 since ours (we hope) works properly with all combinations of
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
314 machines, compilers, `char' and `unsigned char' argument types.
|
18262
|
315 (Per Bothner suggested the basic approach.) */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
316 #undef SIGN_EXTEND_CHAR
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
317 #if __STDC__
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
318 #define SIGN_EXTEND_CHAR(c) ((signed char) (c))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
319 #else /* not __STDC__ */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
320 /* As in Harbison and Steele. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
321 #define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
322 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
323
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
324 /* Should we use malloc or alloca? If REGEX_MALLOC is not defined, we
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
325 use `alloca' instead of `malloc'. This is because using malloc in
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
326 re_search* or re_match* could cause memory leaks when C-g is used in
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
327 Emacs; also, malloc is slower and causes storage fragmentation. On
|
13565
|
328 the other hand, malloc is more portable, and easier to debug.
|
|
329
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
330 Because we sometimes use alloca, some routines have to be macros,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
331 not functions -- `alloca'-allocated space disappears at the end of the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
332 function it is called in. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
333
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
334 #ifdef REGEX_MALLOC
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
335
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
336 #define REGEX_ALLOCATE malloc
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
337 #define REGEX_REALLOCATE(source, osize, nsize) realloc (source, nsize)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
338 #define REGEX_FREE free
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
339
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
340 #else /* not REGEX_MALLOC */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
341
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
342 /* Emacs already defines alloca, sometimes. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
343 #ifndef alloca
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
344
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
345 /* Make alloca work the best possible way. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
346 #ifdef __GNUC__
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
347 #define alloca __builtin_alloca
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
348 #else /* not __GNUC__ */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
349 #if HAVE_ALLOCA_H
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
350 #include <alloca.h>
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
351 #else /* not __GNUC__ or HAVE_ALLOCA_H */
|
13273
|
352 #if 0 /* It is a bad idea to declare alloca. We always cast the result. */
|
18262
|
353 #ifndef _AIX /* Already did AIX, up at the top. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
354 char *alloca ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
355 #endif /* not _AIX */
|
13273
|
356 #endif
|
13565
|
357 #endif /* not HAVE_ALLOCA_H */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
358 #endif /* not __GNUC__ */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
359
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
360 #endif /* not alloca */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
361
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
362 #define REGEX_ALLOCATE alloca
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
363
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
364 /* Assumes a `char *destination' variable. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
365 #define REGEX_REALLOCATE(source, osize, nsize) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
366 (destination = (char *) alloca (nsize), \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
367 bcopy (source, destination, osize), \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
368 destination)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
369
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
370 /* No need to do anything to free, after alloca. */
|
11865
|
371 #define REGEX_FREE(arg) ((void)0) /* Do nothing! But inhibit gcc warning. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
372
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
373 #endif /* not REGEX_MALLOC */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
374
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
375 /* Define how to allocate the failure stack. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
376
|
12570
|
377 #if defined (REL_ALLOC) && defined (REGEX_MALLOC)
|
12478
|
378
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
379 #define REGEX_ALLOCATE_STACK(size) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
380 r_alloc (&failure_stack_ptr, (size))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
381 #define REGEX_REALLOCATE_STACK(source, osize, nsize) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
382 r_re_alloc (&failure_stack_ptr, (nsize))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
383 #define REGEX_FREE_STACK(ptr) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
384 r_alloc_free (&failure_stack_ptr)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
385
|
12478
|
386 #else /* not using relocating allocator */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
387
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
388 #ifdef REGEX_MALLOC
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
389
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
390 #define REGEX_ALLOCATE_STACK malloc
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
391 #define REGEX_REALLOCATE_STACK(source, osize, nsize) realloc (source, nsize)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
392 #define REGEX_FREE_STACK free
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
393
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
394 #else /* not REGEX_MALLOC */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
395
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
396 #define REGEX_ALLOCATE_STACK alloca
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
397
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
398 #define REGEX_REALLOCATE_STACK(source, osize, nsize) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
399 REGEX_REALLOCATE (source, osize, nsize)
|
18262
|
400 /* No need to explicitly free anything. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
401 #define REGEX_FREE_STACK(arg)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
402
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
403 #endif /* not REGEX_MALLOC */
|
12478
|
404 #endif /* not using relocating allocator */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
405
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
406
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
407 /* True if `size1' is non-NULL and PTR is pointing anywhere inside
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
408 `string1' or just past its end. This works if PTR is NULL, which is
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
409 a good thing. */
|
18262
|
410 #define FIRST_STRING_P(ptr) \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
411 (size1 && string1 <= (ptr) && (ptr) <= string1 + size1)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
412
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
413 /* (Re)Allocate N items of type T using malloc, or fail. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
414 #define TALLOC(n, t) ((t *) malloc ((n) * sizeof (t)))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
415 #define RETALLOC(addr, n, t) ((addr) = (t *) realloc (addr, (n) * sizeof (t)))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
416 #define RETALLOC_IF(addr, n, t) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
417 if (addr) RETALLOC((addr), (n), t); else (addr) = TALLOC ((n), t)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
418 #define REGEX_TALLOC(n, t) ((t *) REGEX_ALLOCATE ((n) * sizeof (t)))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
419
|
18262
|
420 #define BYTEWIDTH 8 /* In bits. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
421
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
422 #define STREQ(s1, s2) ((strcmp (s1, s2) == 0))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
423
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
424 #undef MAX
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
425 #undef MIN
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
426 #define MAX(a, b) ((a) > (b) ? (a) : (b))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
427 #define MIN(a, b) ((a) < (b) ? (a) : (b))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
428
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
429 typedef char boolean;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
430 #define false 0
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
431 #define true 1
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
432
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
433 static int re_match_2_internal ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
434
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
435 /* These are the command codes that appear in compiled regular
|
18262
|
436 expressions. Some opcodes are followed by argument bytes. A
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
437 command code can specify any interpretation whatsoever for its
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
438 arguments. Zero bytes may appear in the compiled regular expression. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
439
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
440 typedef enum
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
441 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
442 no_op = 0,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
443
|
18262
|
444 /* Succeed right away--no more backtracking. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
445 succeed,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
446
|
18262
|
447 /* Followed by one byte giving n, then by n literal bytes. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
448 exactn,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
449
|
18262
|
450 /* Matches any (more or less) character. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
451 anychar,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
452
|
18262
|
453 /* Matches any one char belonging to specified set. First
|
|
454 following byte is number of bitmap bytes. Then come bytes
|
|
455 for a bitmap saying which chars are in. Bits in each byte
|
|
456 are ordered low-bit-first. A character is in the set if its
|
|
457 bit is 1. A character too large to have a bit in the map is
|
25440
|
458 automatically not in the set.
|
|
459
|
|
460 If the length byte has the 0x80 bit set, then that stuff
|
|
461 is followed by a range table:
|
|
462 2 bytes of flags for character sets (low 8 bits, high 8 bits)
|
|
463 See RANGE_TABLE_WORK_BITS below.
|
|
464 2 bytes, the number of pairs that follow
|
|
465 pairs, each 2 multibyte characters,
|
|
466 each multibyte character represented as 3 bytes. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
467 charset,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
468
|
18262
|
469 /* Same parameters as charset, but match any character that is
|
|
470 not one of those specified. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
471 charset_not,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
472
|
18262
|
473 /* Start remembering the text that is matched, for storing in a
|
|
474 register. Followed by one byte with the register number, in
|
|
475 the range 0 to one less than the pattern buffer's re_nsub
|
|
476 field. Then followed by one byte with the number of groups
|
|
477 inner to this one. (This last has to be part of the
|
|
478 start_memory only because we need it in the on_failure_jump
|
|
479 of re_match_2.) */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
480 start_memory,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
481
|
18262
|
482 /* Stop remembering the text that is matched and store it in a
|
|
483 memory register. Followed by one byte with the register
|
|
484 number, in the range 0 to one less than `re_nsub' in the
|
|
485 pattern buffer, and one byte with the number of inner groups,
|
|
486 just like `start_memory'. (We need the number of inner
|
|
487 groups here because we don't have any easy way of finding the
|
|
488 corresponding start_memory when we're at a stop_memory.) */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
489 stop_memory,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
490
|
18262
|
491 /* Match a duplicate of something remembered. Followed by one
|
|
492 byte containing the register number. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
493 duplicate,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
494
|
18262
|
495 /* Fail unless at beginning of line. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
496 begline,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
497
|
18262
|
498 /* Fail unless at end of line. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
499 endline,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
500
|
18262
|
501 /* Succeeds if at beginning of buffer (if emacs) or at beginning
|
|
502 of string to be matched (if not). */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
503 begbuf,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
504
|
18262
|
505 /* Analogously, for end of buffer/string. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
506 endbuf,
|
13565
|
507
|
18262
|
508 /* Followed by two byte relative address to which to jump. */
|
13565
|
509 jump,
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
510
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
511 /* Same as jump, but marks the end of an alternative. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
512 jump_past_alt,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
513
|
18262
|
514 /* Followed by two-byte relative address of place to resume at
|
|
515 in case of failure. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
516 on_failure_jump,
|
13565
|
517
|
18262
|
518 /* Like on_failure_jump, but pushes a placeholder instead of the
|
|
519 current string position when executed. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
520 on_failure_keep_string_jump,
|
13565
|
521
|
18262
|
522 /* Throw away latest failure point and then jump to following
|
|
523 two-byte relative address. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
524 pop_failure_jump,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
525
|
18262
|
526 /* Change to pop_failure_jump if know won't have to backtrack to
|
|
527 match; otherwise change to jump. This is used to jump
|
|
528 back to the beginning of a repeat. If what follows this jump
|
|
529 clearly won't match what the repeat does, such that we can be
|
|
530 sure that there is no use backtracking out of repetitions
|
|
531 already matched, then we change it to a pop_failure_jump.
|
|
532 Followed by two-byte address. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
533 maybe_pop_jump,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
534
|
18262
|
535 /* Jump to following two-byte address, and push a dummy failure
|
|
536 point. This failure point will be thrown away if an attempt
|
|
537 is made to use it for a failure. A `+' construct makes this
|
|
538 before the first repeat. Also used as an intermediary kind
|
|
539 of jump when compiling an alternative. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
540 dummy_failure_jump,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
541
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
542 /* Push a dummy failure point and continue. Used at the end of
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
543 alternatives. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
544 push_dummy_failure,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
545
|
18262
|
546 /* Followed by two-byte relative address and two-byte number n.
|
|
547 After matching N times, jump to the address upon failure. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
548 succeed_n,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
549
|
18262
|
550 /* Followed by two-byte relative address, and two-byte number n.
|
|
551 Jump to the address N times, then fail. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
552 jump_n,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
553
|
18262
|
554 /* Set the following two-byte relative address to the
|
|
555 subsequent two-byte number. The address *includes* the two
|
|
556 bytes of number. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
557 set_number_at,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
558
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
559 wordchar, /* Matches any word-constituent character. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
560 notwordchar, /* Matches any char that is not a word-constituent. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
561
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
562 wordbeg, /* Succeeds if at word beginning. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
563 wordend, /* Succeeds if at word end. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
564
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
565 wordbound, /* Succeeds if at a word boundary. */
|
18262
|
566 notwordbound /* Succeeds if not at a word boundary. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
567
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
568 #ifdef emacs
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
569 ,before_dot, /* Succeeds if before point. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
570 at_dot, /* Succeeds if at point. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
571 after_dot, /* Succeeds if after point. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
572
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
573 /* Matches any character whose syntax is specified. Followed by
|
18262
|
574 a byte which contains a syntax code, e.g., Sword. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
575 syntaxspec,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
576
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
577 /* Matches any character whose syntax is not that specified. */
|
18260
|
578 notsyntaxspec,
|
|
579
|
|
580 /* Matches any character whose category-set contains the specified
|
18262
|
581 category. The operator is followed by a byte which contains a
|
|
582 category code (mnemonic ASCII character). */
|
18260
|
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
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
589 #endif /* emacs */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
590 } re_opcode_t;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
591
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
592 /* Common operations on the compiled pattern. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
593
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
594 /* Store NUMBER in two contiguous bytes starting at DESTINATION. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
595
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
596 #define STORE_NUMBER(destination, number) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
597 do { \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
598 (destination)[0] = (number) & 0377; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
599 (destination)[1] = (number) >> 8; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
600 } while (0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
601
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
602 /* Same as STORE_NUMBER, except increment DESTINATION to
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
603 the byte after where the number is stored. Therefore, DESTINATION
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
604 must be an lvalue. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
605
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
606 #define STORE_NUMBER_AND_INCR(destination, number) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
607 do { \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
608 STORE_NUMBER (destination, number); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
609 (destination) += 2; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
610 } while (0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
611
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
612 /* Put into DESTINATION a number stored in two contiguous bytes starting
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
613 at SOURCE. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
614
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
615 #define EXTRACT_NUMBER(destination, source) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
616 do { \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
617 (destination) = *(source) & 0377; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
618 (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
619 } while (0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
620
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
621 #ifdef DEBUG
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
622 static void
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
623 extract_number (dest, source)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
624 int *dest;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
625 unsigned char *source;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
626 {
|
13565
|
627 int temp = SIGN_EXTEND_CHAR (*(source + 1));
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
628 *dest = *source & 0377;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
629 *dest += temp << 8;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
630 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
631
|
18262
|
632 #ifndef EXTRACT_MACROS /* To debug the macros. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
633 #undef EXTRACT_NUMBER
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
634 #define EXTRACT_NUMBER(dest, src) extract_number (&dest, src)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
635 #endif /* not EXTRACT_MACROS */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
636
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
637 #endif /* DEBUG */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
638
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
639 /* Same as EXTRACT_NUMBER, except increment SOURCE to after the number.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
640 SOURCE must be an lvalue. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
641
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
642 #define EXTRACT_NUMBER_AND_INCR(destination, source) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
643 do { \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
644 EXTRACT_NUMBER (destination, source); \
|
18262
|
645 (source) += 2; \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
646 } while (0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
647
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
648 #ifdef DEBUG
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
649 static void
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
650 extract_number_and_incr (destination, source)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
651 int *destination;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
652 unsigned char **source;
|
13565
|
653 {
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
654 extract_number (destination, *source);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
655 *source += 2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
656 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
657
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
658 #ifndef EXTRACT_MACROS
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
659 #undef EXTRACT_NUMBER_AND_INCR
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
660 #define EXTRACT_NUMBER_AND_INCR(dest, src) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
661 extract_number_and_incr (&dest, &src)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
662 #endif /* not EXTRACT_MACROS */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
663
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
664 #endif /* DEBUG */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
665
|
18260
|
666 /* Store a multibyte character in three contiguous bytes starting
|
|
667 DESTINATION, and increment DESTINATION to the byte after where the
|
18262
|
668 character is stored. Therefore, DESTINATION must be an lvalue. */
|
18260
|
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
|
18262
|
679 starting at SOURCE. */
|
18260
|
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. */
|
18262
|
696 #define CHARSET_RANGE_TABLE_EXISTS_P(p) ((p)[1] & 0x80)
|
18260
|
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
|
25440
|
700 stored. `2 +' means to skip re_opcode_t and size of bitmap,
|
|
701 and the 2 bytes of flags at the start of the range table. */
|
|
702 #define CHARSET_RANGE_TABLE(p) (&(p)[4 + CHARSET_BITMAP_SIZE (p)])
|
|
703
|
|
704 /* Extract the bit flags that start a range table. */
|
|
705 #define CHARSET_RANGE_TABLE_BITS(p) \
|
|
706 ((p)[2 + CHARSET_BITMAP_SIZE (p)] \
|
|
707 + (p)[3 + CHARSET_BITMAP_SIZE (p)] * 0x100)
|
18260
|
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
|
18262
|
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
|
18260
|
717 and end. */
|
|
718 #define CHARSET_RANGE_TABLE_END(range_table, count) \
|
|
719 ((range_table) + (count) * 2 * 3)
|
|
720
|
18262
|
721 /* Test if C is in RANGE_TABLE. A flag NOT is negated if C is in.
|
18260
|
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
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
759 /* If DEBUG is defined, Regex prints many voluminous messages about what
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
760 it is doing (if the variable `debug' is nonzero). If linked with the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
761 main program in `iregex.c', you can enter patterns and strings
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
762 interactively. And if linked with the main program in `main.c' and
|
18262
|
763 the other test files, you can run the already-written tests. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
764
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
765 #ifdef DEBUG
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
766
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
767 /* We use standard I/O for debugging. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
768 #include <stdio.h>
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
769
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
770 /* It is useful to test things that ``must'' be true when debugging. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
771 #include <assert.h>
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
772
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
773 static int debug = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
774
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
775 #define DEBUG_STATEMENT(e) e
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
776 #define DEBUG_PRINT1(x) if (debug) printf (x)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
777 #define DEBUG_PRINT2(x1, x2) if (debug) printf (x1, x2)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
778 #define DEBUG_PRINT3(x1, x2, x3) if (debug) printf (x1, x2, x3)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
779 #define DEBUG_PRINT4(x1, x2, x3, x4) if (debug) printf (x1, x2, x3, x4)
|
18262
|
780 #define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
781 if (debug) print_partial_compiled_pattern (s, e)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
782 #define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
783 if (debug) print_double_string (w, s1, sz1, s2, sz2)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
784
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
785
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
786 /* Print the fastmap in human-readable form. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
787
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
788 void
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
789 print_fastmap (fastmap)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
790 char *fastmap;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
791 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
792 unsigned was_a_range = 0;
|
13565
|
793 unsigned i = 0;
|
|
794
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
795 while (i < (1 << BYTEWIDTH))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
796 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
797 if (fastmap[i++])
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
798 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
799 was_a_range = 0;
|
18262
|
800 putchar (i - 1);
|
|
801 while (i < (1 << BYTEWIDTH) && fastmap[i])
|
|
802 {
|
|
803 was_a_range = 1;
|
|
804 i++;
|
|
805 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
806 if (was_a_range)
|
18262
|
807 {
|
|
808 printf ("-");
|
|
809 putchar (i - 1);
|
|
810 }
|
|
811 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
812 }
|
13565
|
813 putchar ('\n');
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
814 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
815
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
816
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
817 /* Print a compiled pattern string in human-readable form, starting at
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
818 the START pointer into it and ending just before the pointer END. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
819
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
820 void
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
821 print_partial_compiled_pattern (start, end)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
822 unsigned char *start;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
823 unsigned char *end;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
824 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
825 int mcnt, mcnt2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
826 unsigned char *p = start;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
827 unsigned char *pend = end;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
828
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
829 if (start == NULL)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
830 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
831 printf ("(null)\n");
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
832 return;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
833 }
|
13565
|
834
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
835 /* Loop over pattern commands. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
836 while (p < pend)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
837 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
838 printf ("%d:\t", p - start);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
839
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
840 switch ((re_opcode_t) *p++)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
841 {
|
18262
|
842 case no_op:
|
|
843 printf ("/no_op");
|
|
844 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
845
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
846 case exactn:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
847 mcnt = *p++;
|
18262
|
848 printf ("/exactn/%d", mcnt);
|
|
849 do
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
850 {
|
18262
|
851 putchar ('/');
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
852 putchar (*p++);
|
18262
|
853 }
|
|
854 while (--mcnt);
|
|
855 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
856
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
857 case start_memory:
|
18262
|
858 mcnt = *p++;
|
|
859 printf ("/start_memory/%d/%d", mcnt, *p++);
|
|
860 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
861
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
862 case stop_memory:
|
18262
|
863 mcnt = *p++;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
864 printf ("/stop_memory/%d/%d", mcnt, *p++);
|
18262
|
865 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
866
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
867 case duplicate:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
868 printf ("/duplicate/%d", *p++);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
869 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
870
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
871 case anychar:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
872 printf ("/anychar");
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
873 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
874
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
875 case charset:
|
18262
|
876 case charset_not:
|
|
877 {
|
|
878 register int c, last = -100;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
879 register int in_range = 0;
|
25440
|
880 int length = *p & 0x7f;
|
|
881 int has_range_table = *p & 0x80;
|
|
882 int range_length = p[length + 2] + p[length + 3] * 0x100;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
883
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
884 printf ("/charset [%s",
|
18262
|
885 (re_opcode_t) *(p - 1) == charset_not ? "^" : "");
|
|
886
|
|
887 assert (p + *p < pend);
|
|
888
|
|
889 for (c = 0; c < 256; c++)
|
25440
|
890 if (c / 8 < length
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
891 && (p[1 + (c/8)] & (1 << (c % 8))))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
892 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
893 /* Are we starting a range? */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
894 if (last + 1 == c && ! in_range)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
895 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
896 putchar ('-');
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
897 in_range = 1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
898 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
899 /* Have we broken a range? */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
900 else if (last + 1 != c && in_range)
|
25440
|
901 {
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
902 putchar (last);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
903 in_range = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
904 }
|
13565
|
905
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
906 if (! in_range)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
907 putchar (c);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
908
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
909 last = c;
|
18262
|
910 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
911
|
25440
|
912 p += 1 + length;
|
|
913
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
914 if (in_range)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
915 putchar (last);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
916
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
917 putchar (']');
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
918
|
25440
|
919 if (has_range_table)
|
|
920 printf ("has-range-table");
|
|
921
|
|
922 /* ??? Should print the range table; for now,
|
|
923 just skip it. */
|
|
924 if (has_range_table)
|
|
925 p += 4 + 6 * range_length;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
926 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
927 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
928
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
929 case begline:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
930 printf ("/begline");
|
18262
|
931 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
932
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
933 case endline:
|
18262
|
934 printf ("/endline");
|
|
935 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
936
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
937 case on_failure_jump:
|
18262
|
938 extract_number_and_incr (&mcnt, &p);
|
|
939 printf ("/on_failure_jump to %d", p + mcnt - start);
|
|
940 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
941
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
942 case on_failure_keep_string_jump:
|
18262
|
943 extract_number_and_incr (&mcnt, &p);
|
|
944 printf ("/on_failure_keep_string_jump to %d", p + mcnt - start);
|
|
945 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
946
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
947 case dummy_failure_jump:
|
18262
|
948 extract_number_and_incr (&mcnt, &p);
|
|
949 printf ("/dummy_failure_jump to %d", p + mcnt - start);
|
|
950 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
951
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
952 case push_dummy_failure:
|
18262
|
953 printf ("/push_dummy_failure");
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
954 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
955
|
18262
|
956 case maybe_pop_jump:
|
|
957 extract_number_and_incr (&mcnt, &p);
|
|
958 printf ("/maybe_pop_jump to %d", p + mcnt - start);
|
|
959 break;
|
|
960
|
|
961 case pop_failure_jump:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
962 extract_number_and_incr (&mcnt, &p);
|
18262
|
963 printf ("/pop_failure_jump to %d", p + mcnt - start);
|
13565
|
964 break;
|
|
965
|
18262
|
966 case jump_past_alt:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
967 extract_number_and_incr (&mcnt, &p);
|
18262
|
968 printf ("/jump_past_alt to %d", p + mcnt - start);
|
13565
|
969 break;
|
|
970
|
18262
|
971 case jump:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
972 extract_number_and_incr (&mcnt, &p);
|
18262
|
973 printf ("/jump to %d", p + mcnt - start);
|
16010
|
974 break;
|
|
975
|
18262
|
976 case succeed_n:
|
|
977 extract_number_and_incr (&mcnt, &p);
|
|
978 extract_number_and_incr (&mcnt2, &p);
|
18260
|
979 printf ("/succeed_n to %d, %d times", p + mcnt - start, mcnt2);
|
18262
|
980 break;
|
|
981
|
|
982 case jump_n:
|
|
983 extract_number_and_incr (&mcnt, &p);
|
|
984 extract_number_and_incr (&mcnt2, &p);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
985 printf ("/jump_n to %d, %d times", p + mcnt - start, mcnt2);
|
18262
|
986 break;
|
|
987
|
|
988 case set_number_at:
|
|
989 extract_number_and_incr (&mcnt, &p);
|
|
990 extract_number_and_incr (&mcnt2, &p);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
991 printf ("/set_number_at location %d to %d", p + mcnt - start, mcnt2);
|
18262
|
992 break;
|
|
993
|
|
994 case wordbound:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
995 printf ("/wordbound");
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
996 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
997
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
998 case notwordbound:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
999 printf ("/notwordbound");
|
18262
|
1000 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1001
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1002 case wordbeg:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1003 printf ("/wordbeg");
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1004 break;
|
13565
|
1005
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1006 case wordend:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1007 printf ("/wordend");
|
13565
|
1008
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1009 #ifdef emacs
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1010 case before_dot:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1011 printf ("/before_dot");
|
18262
|
1012 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1013
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1014 case at_dot:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1015 printf ("/at_dot");
|
18262
|
1016 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1017
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1018 case after_dot:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1019 printf ("/after_dot");
|
18262
|
1020 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1021
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1022 case syntaxspec:
|
18262
|
1023 printf ("/syntaxspec");
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1024 mcnt = *p++;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1025 printf ("/%d", mcnt);
|
18262
|
1026 break;
|
13565
|
1027
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1028 case notsyntaxspec:
|
18262
|
1029 printf ("/notsyntaxspec");
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1030 mcnt = *p++;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1031 printf ("/%d", mcnt);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1032 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1033 #endif /* emacs */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1034
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1035 case wordchar:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1036 printf ("/wordchar");
|
18262
|
1037 break;
|
13565
|
1038
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1039 case notwordchar:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1040 printf ("/notwordchar");
|
18262
|
1041 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1042
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1043 case begbuf:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1044 printf ("/begbuf");
|
18262
|
1045 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1046
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1047 case endbuf:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1048 printf ("/endbuf");
|
18262
|
1049 break;
|
|
1050
|
|
1051 default:
|
|
1052 printf ("?%d", *(p-1));
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1053 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1054
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1055 putchar ('\n');
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1056 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1057
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1058 printf ("%d:\tend of pattern.\n", p - start);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1059 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1060
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1061
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1062 void
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1063 print_compiled_pattern (bufp)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1064 struct re_pattern_buffer *bufp;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1065 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1066 unsigned char *buffer = bufp->buffer;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1067
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1068 print_partial_compiled_pattern (buffer, buffer + bufp->used);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1069 printf ("%d bytes used/%d bytes allocated.\n", bufp->used, bufp->allocated);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1070
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1071 if (bufp->fastmap_accurate && bufp->fastmap)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1072 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1073 printf ("fastmap: ");
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1074 print_fastmap (bufp->fastmap);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1075 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1076
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1077 printf ("re_nsub: %d\t", bufp->re_nsub);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1078 printf ("regs_alloc: %d\t", bufp->regs_allocated);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1079 printf ("can_be_null: %d\t", bufp->can_be_null);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1080 printf ("newline_anchor: %d\n", bufp->newline_anchor);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1081 printf ("no_sub: %d\t", bufp->no_sub);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1082 printf ("not_bol: %d\t", bufp->not_bol);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1083 printf ("not_eol: %d\t", bufp->not_eol);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1084 printf ("syntax: %d\n", bufp->syntax);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1085 /* Perhaps we should print the translate table? */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1086 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1087
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1088
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1089 void
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1090 print_double_string (where, string1, size1, string2, size2)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1091 const char *where;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1092 const char *string1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1093 const char *string2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1094 int size1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1095 int size2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1096 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1097 unsigned this_char;
|
13565
|
1098
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1099 if (where == NULL)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1100 printf ("(null)");
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1101 else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1102 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1103 if (FIRST_STRING_P (where))
|
18262
|
1104 {
|
|
1105 for (this_char = where - string1; this_char < size1; this_char++)
|
|
1106 putchar (string1[this_char]);
|
|
1107
|
|
1108 where = string2;
|
|
1109 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1110
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1111 for (this_char = where - string2; this_char < size2; this_char++)
|
18262
|
1112 putchar (string2[this_char]);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1113 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1114 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1115
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1116 #else /* not DEBUG */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1117
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1118 #undef assert
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1119 #define assert(e)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1120
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1121 #define DEBUG_STATEMENT(e)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1122 #define DEBUG_PRINT1(x)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1123 #define DEBUG_PRINT2(x1, x2)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1124 #define DEBUG_PRINT3(x1, x2, x3)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1125 #define DEBUG_PRINT4(x1, x2, x3, x4)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1126 #define DEBUG_PRINT_COMPILED_PATTERN(p, s, e)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1127 #define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1128
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1129 #endif /* not DEBUG */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1130
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1131 /* Set by `re_set_syntax' to the current regexp syntax to recognize. Can
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1132 also be assigned to arbitrarily: each pattern buffer stores its own
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1133 syntax, so it can be changed between regex compilations. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1134 /* This has no initializer because initialized variables in Emacs
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1135 become read-only after dumping. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1136 reg_syntax_t re_syntax_options;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1137
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1138
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1139 /* Specify the precise syntax of regexps for compilation. This provides
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1140 for compatibility for various utilities which historically have
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1141 different, incompatible syntaxes.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1142
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1143 The argument SYNTAX is a bit mask comprised of the various bits
|
18262
|
1144 defined in regex.h. We return the old syntax. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1145
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1146 reg_syntax_t
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1147 re_set_syntax (syntax)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1148 reg_syntax_t syntax;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1149 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1150 reg_syntax_t ret = re_syntax_options;
|
13565
|
1151
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1152 re_syntax_options = syntax;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1153 return ret;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1154 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1155
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1156 /* This table gives an error message for each of the error codes listed
|
18262
|
1157 in regex.h. Obviously the order here has to be same as there.
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1158 POSIX doesn't require that we do anything for REG_NOERROR,
|
18262
|
1159 but why not be nice? */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1160
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1161 static const char *re_error_msgid[] =
|
13565
|
1162 {
|
|
1163 gettext_noop ("Success"), /* REG_NOERROR */
|
|
1164 gettext_noop ("No match"), /* REG_NOMATCH */
|
|
1165 gettext_noop ("Invalid regular expression"), /* REG_BADPAT */
|
|
1166 gettext_noop ("Invalid collation character"), /* REG_ECOLLATE */
|
|
1167 gettext_noop ("Invalid character class name"), /* REG_ECTYPE */
|
|
1168 gettext_noop ("Trailing backslash"), /* REG_EESCAPE */
|
|
1169 gettext_noop ("Invalid back reference"), /* REG_ESUBREG */
|
|
1170 gettext_noop ("Unmatched [ or [^"), /* REG_EBRACK */
|
|
1171 gettext_noop ("Unmatched ( or \\("), /* REG_EPAREN */
|
|
1172 gettext_noop ("Unmatched \\{"), /* REG_EBRACE */
|
|
1173 gettext_noop ("Invalid content of \\{\\}"), /* REG_BADBR */
|
|
1174 gettext_noop ("Invalid range end"), /* REG_ERANGE */
|
|
1175 gettext_noop ("Memory exhausted"), /* REG_ESPACE */
|
|
1176 gettext_noop ("Invalid preceding regular expression"), /* REG_BADRPT */
|
|
1177 gettext_noop ("Premature end of regular expression"), /* REG_EEND */
|
|
1178 gettext_noop ("Regular expression too big"), /* REG_ESIZE */
|
|
1179 gettext_noop ("Unmatched ) or \\)"), /* REG_ERPAREN */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1180 };
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1181
|
18262
|
1182 /* Avoiding alloca during matching, to placate r_alloc. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1183
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1184 /* Define MATCH_MAY_ALLOCATE unless we need to make sure that the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1185 searching and matching functions should not call alloca. On some
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1186 systems, alloca is implemented in terms of malloc, and if we're
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1187 using the relocating allocator routines, then malloc could cause a
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1188 relocation, which might (if the strings being searched are in the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1189 ralloc heap) shift the data out from underneath the regexp
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1190 routines.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1191
|
13565
|
1192 Here's another reason to avoid allocation: Emacs
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1193 processes input from X in a signal handler; processing X input may
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1194 call malloc; if input arrives while a matching routine is calling
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1195 malloc, then we're scrod. But Emacs can't just block input while
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1196 calling matching routines; then we don't notice interrupts when
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1197 they come in. So, Emacs blocks input around all regexp calls
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1198 except the matching calls, which it leaves unprotected, in the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1199 faith that they will not malloc. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1200
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1201 /* Normally, this is fine. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1202 #define MATCH_MAY_ALLOCATE
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1203
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1204 /* When using GNU C, we are not REALLY using the C alloca, no matter
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1205 what config.h may say. So don't take precautions for it. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1206 #ifdef __GNUC__
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1207 #undef C_ALLOCA
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1208 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1209
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1210 /* The match routines may not allocate if (1) they would do it with malloc
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1211 and (2) it's not safe for them to use malloc.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1212 Note that if REL_ALLOC is defined, matching would not use malloc for the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1213 failure stack, but we would still use it for the register vectors;
|
18262
|
1214 so REL_ALLOC should not affect this. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1215 #if (defined (C_ALLOCA) || defined (REGEX_MALLOC)) && defined (emacs)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1216 #undef MATCH_MAY_ALLOCATE
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1217 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1218
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1219
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1220 /* Failure stack declarations and macros; both re_compile_fastmap and
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1221 re_match_2 use a failure stack. These have to be macros because of
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1222 REGEX_ALLOCATE_STACK. */
|
13565
|
1223
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1224
|
20449
|
1225 /* Approximate number of failure points for which to initially allocate space
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1226 when matching. If this number is exceeded, we allocate more
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1227 space, so it is not a hard limit. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1228 #ifndef INIT_FAILURE_ALLOC
|
20449
|
1229 #define INIT_FAILURE_ALLOC 20
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1230 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1231
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1232 /* Roughly the maximum number of failure points on the stack. Would be
|
20449
|
1233 exactly that if always used TYPICAL_FAILURE_SIZE items each time we failed.
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1234 This is a variable only so users of regex can assign to it; we never
|
18262
|
1235 change it ourselves. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1236 #if defined (MATCH_MAY_ALLOCATE)
|
20449
|
1237 /* Note that 4400 is enough to cause a crash on Alpha OSF/1,
|
|
1238 whose default stack limit is 2mb. In order for a larger
|
|
1239 value to work reliably, you have to try to make it accord
|
|
1240 with the process stack limit. */
|
|
1241 int re_max_failures = 40000;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1242 #else
|
20449
|
1243 int re_max_failures = 4000;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1244 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1245
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1246 union fail_stack_elt
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1247 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1248 unsigned char *pointer;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1249 int integer;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1250 };
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1251
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1252 typedef union fail_stack_elt fail_stack_elt_t;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1253
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1254 typedef struct
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1255 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1256 fail_stack_elt_t *stack;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1257 unsigned size;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1258 unsigned avail; /* Offset of next open position. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1259 } fail_stack_type;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1260
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1261 #define FAIL_STACK_EMPTY() (fail_stack.avail == 0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1262 #define FAIL_STACK_PTR_EMPTY() (fail_stack_ptr->avail == 0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1263 #define FAIL_STACK_FULL() (fail_stack.avail == fail_stack.size)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1264
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1265
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1266 /* Define macros to initialize and free the failure stack.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1267 Do `return -2' if the alloc fails. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1268
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1269 #ifdef MATCH_MAY_ALLOCATE
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1270 #define INIT_FAIL_STACK() \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1271 do { \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1272 fail_stack.stack = (fail_stack_elt_t *) \
|
20449
|
1273 REGEX_ALLOCATE_STACK (INIT_FAILURE_ALLOC * TYPICAL_FAILURE_SIZE \
|
|
1274 * sizeof (fail_stack_elt_t)); \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1275 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1276 if (fail_stack.stack == NULL) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1277 return -2; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1278 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1279 fail_stack.size = INIT_FAILURE_ALLOC; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1280 fail_stack.avail = 0; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1281 } while (0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1282
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1283 #define RESET_FAIL_STACK() REGEX_FREE_STACK (fail_stack.stack)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1284 #else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1285 #define INIT_FAIL_STACK() \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1286 do { \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1287 fail_stack.avail = 0; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1288 } while (0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1289
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1290 #define RESET_FAIL_STACK()
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1291 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1292
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1293
|
20449
|
1294 /* Double the size of FAIL_STACK, up to a limit
|
|
1295 which allows approximately `re_max_failures' items.
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1296
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1297 Return 1 if succeeds, and 0 if either ran out of memory
|
13565
|
1298 allocating space for it or it was already too large.
|
|
1299
|
18262
|
1300 REGEX_REALLOCATE_STACK requires `destination' be declared. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1301
|
20449
|
1302 /* Factor to increase the failure stack size by
|
|
1303 when we increase it.
|
|
1304 This used to be 2, but 2 was too wasteful
|
|
1305 because the old discarded stacks added up to as much space
|
|
1306 were as ultimate, maximum-size stack. */
|
|
1307 #define FAIL_STACK_GROWTH_FACTOR 4
|
|
1308
|
|
1309 #define GROW_FAIL_STACK(fail_stack) \
|
20455
|
1310 (((fail_stack).size * sizeof (fail_stack_elt_t) \
|
|
1311 >= re_max_failures * TYPICAL_FAILURE_SIZE) \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1312 ? 0 \
|
20449
|
1313 : ((fail_stack).stack \
|
|
1314 = (fail_stack_elt_t *) \
|
18262
|
1315 REGEX_REALLOCATE_STACK ((fail_stack).stack, \
|
|
1316 (fail_stack).size * sizeof (fail_stack_elt_t), \
|
20449
|
1317 MIN (re_max_failures * TYPICAL_FAILURE_SIZE, \
|
|
1318 ((fail_stack).size * sizeof (fail_stack_elt_t) \
|
|
1319 * FAIL_STACK_GROWTH_FACTOR))), \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1320 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1321 (fail_stack).stack == NULL \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1322 ? 0 \
|
20450
|
1323 : ((fail_stack).size \
|
|
1324 = (MIN (re_max_failures * TYPICAL_FAILURE_SIZE, \
|
|
1325 ((fail_stack).size * sizeof (fail_stack_elt_t) \
|
|
1326 * FAIL_STACK_GROWTH_FACTOR)) \
|
|
1327 / sizeof (fail_stack_elt_t)), \
|
18262
|
1328 1)))
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1329
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1330
|
13565
|
1331 /* Push pointer POINTER on FAIL_STACK.
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1332 Return 1 if was able to do so and 0 if ran out of memory allocating
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1333 space to do so. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1334 #define PUSH_PATTERN_OP(POINTER, FAIL_STACK) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1335 ((FAIL_STACK_FULL () \
|
20449
|
1336 && !GROW_FAIL_STACK (FAIL_STACK)) \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1337 ? 0 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1338 : ((FAIL_STACK).stack[(FAIL_STACK).avail++].pointer = POINTER, \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1339 1))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1340
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1341 /* Push a pointer value onto the failure stack.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1342 Assumes the variable `fail_stack'. Probably should only
|
18262
|
1343 be called from within `PUSH_FAILURE_POINT'. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1344 #define PUSH_FAILURE_POINTER(item) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1345 fail_stack.stack[fail_stack.avail++].pointer = (unsigned char *) (item)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1346
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1347 /* This pushes an integer-valued item onto the failure stack.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1348 Assumes the variable `fail_stack'. Probably should only
|
18262
|
1349 be called from within `PUSH_FAILURE_POINT'. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1350 #define PUSH_FAILURE_INT(item) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1351 fail_stack.stack[fail_stack.avail++].integer = (item)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1352
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1353 /* Push a fail_stack_elt_t value onto the failure stack.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1354 Assumes the variable `fail_stack'. Probably should only
|
18262
|
1355 be called from within `PUSH_FAILURE_POINT'. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1356 #define PUSH_FAILURE_ELT(item) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1357 fail_stack.stack[fail_stack.avail++] = (item)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1358
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1359 /* These three POP... operations complement the three PUSH... operations.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1360 All assume that `fail_stack' is nonempty. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1361 #define POP_FAILURE_POINTER() fail_stack.stack[--fail_stack.avail].pointer
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1362 #define POP_FAILURE_INT() fail_stack.stack[--fail_stack.avail].integer
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1363 #define POP_FAILURE_ELT() fail_stack.stack[--fail_stack.avail]
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1364
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1365 /* Used to omit pushing failure point id's when we're not debugging. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1366 #ifdef DEBUG
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1367 #define DEBUG_PUSH PUSH_FAILURE_INT
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1368 #define DEBUG_POP(item_addr) *(item_addr) = POP_FAILURE_INT ()
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1369 #else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1370 #define DEBUG_PUSH(item)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1371 #define DEBUG_POP(item_addr)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1372 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1373
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1374
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1375 /* Push the information about the state we will need
|
13565
|
1376 if we ever fail back to it.
|
|
1377
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1378 Requires variables fail_stack, regstart, regend, reg_info, and
|
20449
|
1379 num_regs be declared. GROW_FAIL_STACK requires `destination' be
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1380 declared.
|
13565
|
1381
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1382 Does `return FAILURE_CODE' if runs out of memory. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1383
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1384 #define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1385 do { \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1386 char *destination; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1387 /* Must be int, so when we don't save any registers, the arithmetic \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1388 of 0 + -1 isn't done as unsigned. */ \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1389 int this_reg; \
|
18262
|
1390 \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1391 DEBUG_STATEMENT (failure_id++); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1392 DEBUG_STATEMENT (nfailure_points_pushed++); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1393 DEBUG_PRINT2 ("\nPUSH_FAILURE_POINT #%u:\n", failure_id); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1394 DEBUG_PRINT2 (" Before push, next avail: %d\n", (fail_stack).avail);\
|
18262
|
1395 DEBUG_PRINT2 (" size: %d\n", (fail_stack).size);\
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1396 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1397 DEBUG_PRINT2 (" slots needed: %d\n", NUM_FAILURE_ITEMS); \
|
18262
|
1398 DEBUG_PRINT2 (" available: %d\n", REMAINING_AVAIL_SLOTS); \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1399 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1400 /* Ensure we have enough space allocated for what we will push. */ \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1401 while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1402 { \
|
20449
|
1403 if (!GROW_FAIL_STACK (fail_stack)) \
|
18262
|
1404 return failure_code; \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1405 \
|
18262
|
1406 DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1407 (fail_stack).size); \
|
18262
|
1408 DEBUG_PRINT2 (" slots available: %d\n", REMAINING_AVAIL_SLOTS);\
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1409 } \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1410 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1411 /* Push the info, starting with the registers. */ \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1412 DEBUG_PRINT1 ("\n"); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1413 \
|
13517
|
1414 if (1) \
|
12931
|
1415 for (this_reg = lowest_active_reg; this_reg <= highest_active_reg; \
|
|
1416 this_reg++) \
|
|
1417 { \
|
|
1418 DEBUG_PRINT2 (" Pushing reg: %d\n", this_reg); \
|
|
1419 DEBUG_STATEMENT (num_regs_pushed++); \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1420 \
|
12931
|
1421 DEBUG_PRINT2 (" start: 0x%x\n", regstart[this_reg]); \
|
|
1422 PUSH_FAILURE_POINTER (regstart[this_reg]); \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1423 \
|
12931
|
1424 DEBUG_PRINT2 (" end: 0x%x\n", regend[this_reg]); \
|
|
1425 PUSH_FAILURE_POINTER (regend[this_reg]); \
|
|
1426 \
|
|
1427 DEBUG_PRINT2 (" info: 0x%x\n ", reg_info[this_reg]); \
|
|
1428 DEBUG_PRINT2 (" match_null=%d", \
|
|
1429 REG_MATCH_NULL_STRING_P (reg_info[this_reg])); \
|
|
1430 DEBUG_PRINT2 (" active=%d", IS_ACTIVE (reg_info[this_reg])); \
|
|
1431 DEBUG_PRINT2 (" matched_something=%d", \
|
|
1432 MATCHED_SOMETHING (reg_info[this_reg])); \
|
|
1433 DEBUG_PRINT2 (" ever_matched=%d", \
|
|
1434 EVER_MATCHED_SOMETHING (reg_info[this_reg])); \
|
|
1435 DEBUG_PRINT1 ("\n"); \
|
|
1436 PUSH_FAILURE_ELT (reg_info[this_reg].word); \
|
|
1437 } \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1438 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1439 DEBUG_PRINT2 (" Pushing low active reg: %d\n", lowest_active_reg);\
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1440 PUSH_FAILURE_INT (lowest_active_reg); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1441 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1442 DEBUG_PRINT2 (" Pushing high active reg: %d\n", highest_active_reg);\
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1443 PUSH_FAILURE_INT (highest_active_reg); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1444 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1445 DEBUG_PRINT2 (" Pushing pattern 0x%x: ", pattern_place); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1446 DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1447 PUSH_FAILURE_POINTER (pattern_place); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1448 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1449 DEBUG_PRINT2 (" Pushing string 0x%x: `", string_place); \
|
18262
|
1450 DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1451 size2); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1452 DEBUG_PRINT1 ("'\n"); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1453 PUSH_FAILURE_POINTER (string_place); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1454 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1455 DEBUG_PRINT2 (" Pushing failure id: %u\n", failure_id); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1456 DEBUG_PUSH (failure_id); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1457 } while (0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1458
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1459 /* This is the number of items that are pushed and popped on the stack
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1460 for each register. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1461 #define NUM_REG_ITEMS 3
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1462
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1463 /* Individual items aside from the registers. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1464 #ifdef DEBUG
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1465 #define NUM_NONREG_ITEMS 5 /* Includes failure point id. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1466 #else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1467 #define NUM_NONREG_ITEMS 4
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1468 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1469
|
20449
|
1470 /* Estimate the size of data pushed by a typical failure stack entry.
|
|
1471 An estimate is all we need, because all we use this for
|
|
1472 is to choose a limit for how big to make the failure stack. */
|
|
1473
|
|
1474 #define TYPICAL_FAILURE_SIZE 20
|
|
1475
|
|
1476 /* This is how many items we actually use for a failure point.
|
|
1477 It depends on the regexp. */
|
12931
|
1478 #define NUM_FAILURE_ITEMS \
|
13517
|
1479 (((0 \
|
12931
|
1480 ? 0 : highest_active_reg - lowest_active_reg + 1) \
|
|
1481 * NUM_REG_ITEMS) \
|
|
1482 + NUM_NONREG_ITEMS)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1483
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1484 /* How many items can still be added to the stack without overflowing it. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1485 #define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1486
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1487
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1488 /* Pops what PUSH_FAIL_STACK pushes.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1489
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1490 We restore into the parameters, all of which should be lvalues:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1491 STR -- the saved data position.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1492 PAT -- the saved pattern position.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1493 LOW_REG, HIGH_REG -- the highest and lowest active registers.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1494 REGSTART, REGEND -- arrays of string positions.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1495 REG_INFO -- array of information about each subexpression.
|
13565
|
1496
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1497 Also assumes the variables `fail_stack' and (if debugging), `bufp',
|
18262
|
1498 `pend', `string1', `size1', `string2', and `size2'. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1499
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1500 #define POP_FAILURE_POINT(str, pat, low_reg, high_reg, regstart, regend, reg_info)\
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1501 { \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1502 DEBUG_STATEMENT (fail_stack_elt_t failure_id;) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1503 int this_reg; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1504 const unsigned char *string_temp; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1505 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1506 assert (!FAIL_STACK_EMPTY ()); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1507 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1508 /* Remove failure points and point to how many regs pushed. */ \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1509 DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1510 DEBUG_PRINT2 (" Before pop, next avail: %d\n", fail_stack.avail); \
|
18262
|
1511 DEBUG_PRINT2 (" size: %d\n", fail_stack.size); \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1512 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1513 assert (fail_stack.avail >= NUM_NONREG_ITEMS); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1514 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1515 DEBUG_POP (&failure_id); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1516 DEBUG_PRINT2 (" Popping failure id: %u\n", failure_id); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1517 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1518 /* If the saved string location is NULL, it came from an \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1519 on_failure_keep_string_jump opcode, and we want to throw away the \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1520 saved NULL, thus retaining our current position in the string. */ \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1521 string_temp = POP_FAILURE_POINTER (); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1522 if (string_temp != NULL) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1523 str = (const char *) string_temp; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1524 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1525 DEBUG_PRINT2 (" Popping string 0x%x: `", str); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1526 DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1527 DEBUG_PRINT1 ("'\n"); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1528 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1529 pat = (unsigned char *) POP_FAILURE_POINTER (); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1530 DEBUG_PRINT2 (" Popping pattern 0x%x: ", pat); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1531 DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1532 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1533 /* Restore register info. */ \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1534 high_reg = (unsigned) POP_FAILURE_INT (); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1535 DEBUG_PRINT2 (" Popping high active reg: %d\n", high_reg); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1536 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1537 low_reg = (unsigned) POP_FAILURE_INT (); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1538 DEBUG_PRINT2 (" Popping low active reg: %d\n", low_reg); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1539 \
|
13517
|
1540 if (1) \
|
12931
|
1541 for (this_reg = high_reg; this_reg >= low_reg; this_reg--) \
|
|
1542 { \
|
18262
|
1543 DEBUG_PRINT2 (" Popping reg: %d\n", this_reg); \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1544 \
|
12931
|
1545 reg_info[this_reg].word = POP_FAILURE_ELT (); \
|
18262
|
1546 DEBUG_PRINT2 (" info: 0x%x\n", reg_info[this_reg]); \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1547 \
|
12931
|
1548 regend[this_reg] = (const char *) POP_FAILURE_POINTER (); \
|
18262
|
1549 DEBUG_PRINT2 (" end: 0x%x\n", regend[this_reg]); \
|
12931
|
1550 \
|
|
1551 regstart[this_reg] = (const char *) POP_FAILURE_POINTER (); \
|
18262
|
1552 DEBUG_PRINT2 (" start: 0x%x\n", regstart[this_reg]); \
|
12931
|
1553 } \
|
13250
|
1554 else \
|
|
1555 { \
|
|
1556 for (this_reg = highest_active_reg; this_reg > high_reg; this_reg--) \
|
|
1557 { \
|
13323
|
1558 reg_info[this_reg].word.integer = 0; \
|
13250
|
1559 regend[this_reg] = 0; \
|
|
1560 regstart[this_reg] = 0; \
|
|
1561 } \
|
|
1562 highest_active_reg = high_reg; \
|
|
1563 } \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1564 \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1565 set_regs_matched_done = 0; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1566 DEBUG_STATEMENT (nfailure_points_popped++); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1567 } /* POP_FAILURE_POINT */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1568
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1569
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1570
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1571 /* Structure for per-register (a.k.a. per-group) information.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1572 Other register information, such as the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1573 starting and ending positions (which are addresses), and the list of
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1574 inner groups (which is a bits list) are maintained in separate
|
13565
|
1575 variables.
|
|
1576
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1577 We are making a (strictly speaking) nonportable assumption here: that
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1578 the compiler will pack our bit fields into something that fits into
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1579 the type of `word', i.e., is something that fits into one item on the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1580 failure stack. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1581
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1582 typedef union
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1583 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1584 fail_stack_elt_t word;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1585 struct
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1586 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1587 /* This field is one if this group can match the empty string,
|
18262
|
1588 zero if not. If not yet determined, `MATCH_NULL_UNSET_VALUE'. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1589 #define MATCH_NULL_UNSET_VALUE 3
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1590 unsigned match_null_string_p : 2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1591 unsigned is_active : 1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1592 unsigned matched_something : 1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1593 unsigned ever_matched_something : 1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1594 } bits;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1595 } register_info_type;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1596
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1597 #define REG_MATCH_NULL_STRING_P(R) ((R).bits.match_null_string_p)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1598 #define IS_ACTIVE(R) ((R).bits.is_active)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1599 #define MATCHED_SOMETHING(R) ((R).bits.matched_something)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1600 #define EVER_MATCHED_SOMETHING(R) ((R).bits.ever_matched_something)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1601
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1602
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1603 /* Call this when have matched a real character; it sets `matched' flags
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1604 for the subexpressions which we are currently inside. Also records
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1605 that those subexprs have matched. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1606 #define SET_REGS_MATCHED() \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1607 do \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1608 { \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1609 if (!set_regs_matched_done) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1610 { \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1611 unsigned r; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1612 set_regs_matched_done = 1; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1613 for (r = lowest_active_reg; r <= highest_active_reg; r++) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1614 { \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1615 MATCHED_SOMETHING (reg_info[r]) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1616 = EVER_MATCHED_SOMETHING (reg_info[r]) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1617 = 1; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1618 } \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1619 } \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1620 } \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1621 while (0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1622
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1623 /* Registers are set to a sentinel when they haven't yet matched. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1624 static char reg_unset_dummy;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1625 #define REG_UNSET_VALUE (®_unset_dummy)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1626 #define REG_UNSET(e) ((e) == REG_UNSET_VALUE)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1627
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1628 /* Subroutine declarations and macros for regex_compile. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1629
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1630 static void store_op1 (), store_op2 ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1631 static void insert_op1 (), insert_op2 ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1632 static boolean at_begline_loc_p (), at_endline_loc_p ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1633 static boolean group_in_compile_stack ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1634 static reg_errcode_t compile_range ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1635
|
13565
|
1636 /* Fetch the next character in the uncompiled pattern---translating it
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1637 if necessary. Also cast from a signed character in the constant
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1638 string passed to us by the user to an unsigned char that we can use
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1639 as an array index (in, e.g., `translate'). */
|
13250
|
1640 #ifndef PATFETCH
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1641 #define PATFETCH(c) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1642 do {if (p == pend) return REG_EEND; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1643 c = (unsigned char) *p++; \
|
21562
|
1644 if (RE_TRANSLATE_P (translate)) c = RE_TRANSLATE (translate, c); \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1645 } while (0)
|
13250
|
1646 #endif
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1647
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1648 /* Fetch the next character in the uncompiled pattern, with no
|
18262
|
1649 translation. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1650 #define PATFETCH_RAW(c) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1651 do {if (p == pend) return REG_EEND; \
|
18262
|
1652 c = (unsigned char) *p++; \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1653 } while (0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1654
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1655 /* Go backwards one character in the pattern. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1656 #define PATUNFETCH p--
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1657
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1658
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1659 /* If `translate' is non-null, return translate[D], else just D. We
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1660 cast the subscript to translate because some data is declared as
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1661 `char *', to avoid warnings when a string constant is passed. But
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1662 when we use a character as a subscript we must make it unsigned. */
|
13250
|
1663 #ifndef TRANSLATE
|
|
1664 #define TRANSLATE(d) \
|
21562
|
1665 (RE_TRANSLATE_P (translate) \
|
|
1666 ? (unsigned) RE_TRANSLATE (translate, (unsigned) (d)) : (d))
|
13250
|
1667 #endif
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1668
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1669
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1670 /* Macros for outputting the compiled pattern into `buffer'. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1671
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1672 /* If the buffer isn't allocated when it comes in, use this. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1673 #define INIT_BUF_SIZE 32
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1674
|
18262
|
1675 /* Make sure we have at least N more bytes of space in buffer. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1676 #define GET_BUFFER_SPACE(n) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1677 while (b - bufp->buffer + (n) > bufp->allocated) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1678 EXTEND_BUFFER ()
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1679
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1680 /* Make sure we have one more byte of buffer space and then add C to it. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1681 #define BUF_PUSH(c) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1682 do { \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1683 GET_BUFFER_SPACE (1); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1684 *b++ = (unsigned char) (c); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1685 } while (0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1686
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1687
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1688 /* Ensure we have two more bytes of buffer space and then append C1 and C2. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1689 #define BUF_PUSH_2(c1, c2) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1690 do { \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1691 GET_BUFFER_SPACE (2); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1692 *b++ = (unsigned char) (c1); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1693 *b++ = (unsigned char) (c2); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1694 } while (0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1695
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1696
|
18262
|
1697 /* As with BUF_PUSH_2, except for three bytes. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1698 #define BUF_PUSH_3(c1, c2, c3) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1699 do { \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1700 GET_BUFFER_SPACE (3); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1701 *b++ = (unsigned char) (c1); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1702 *b++ = (unsigned char) (c2); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1703 *b++ = (unsigned char) (c3); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1704 } while (0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1705
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1706
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1707 /* Store a jump with opcode OP at LOC to location TO. We store a
|
18262
|
1708 relative address offset by the three bytes the jump itself occupies. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1709 #define STORE_JUMP(op, loc, to) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1710 store_op1 (op, loc, (to) - (loc) - 3)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1711
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1712 /* Likewise, for a two-argument jump. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1713 #define STORE_JUMP2(op, loc, to, arg) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1714 store_op2 (op, loc, (to) - (loc) - 3, arg)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1715
|
18262
|
1716 /* Like `STORE_JUMP', but for inserting. Assume `b' is the buffer end. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1717 #define INSERT_JUMP(op, loc, to) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1718 insert_op1 (op, loc, (to) - (loc) - 3, b)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1719
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1720 /* Like `STORE_JUMP2', but for inserting. Assume `b' is the buffer end. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1721 #define INSERT_JUMP2(op, loc, to, arg) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1722 insert_op2 (op, loc, (to) - (loc) - 3, arg, b)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1723
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1724
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1725 /* This is not an arbitrary limit: the arguments which represent offsets
|
18262
|
1726 into the pattern are two bytes long. So if 2^16 bytes turns out to
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1727 be too small, many things would have to change. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1728 #define MAX_BUF_SIZE (1L << 16)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1729
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1730
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1731 /* Extend the buffer by twice its current size via realloc and
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1732 reset the pointers that pointed into the old block to point to the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1733 correct places in the new one. If extending the buffer results in it
|
18262
|
1734 being larger than MAX_BUF_SIZE, then flag memory exhausted. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1735 #define EXTEND_BUFFER() \
|
18262
|
1736 do { \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1737 unsigned char *old_buffer = bufp->buffer; \
|
18262
|
1738 if (bufp->allocated == MAX_BUF_SIZE) \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1739 return REG_ESIZE; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1740 bufp->allocated <<= 1; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1741 if (bufp->allocated > MAX_BUF_SIZE) \
|
18262
|
1742 bufp->allocated = MAX_BUF_SIZE; \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1743 bufp->buffer = (unsigned char *) realloc (bufp->buffer, bufp->allocated);\
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1744 if (bufp->buffer == NULL) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1745 return REG_ESPACE; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1746 /* If the buffer moved, move all the pointers into it. */ \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1747 if (old_buffer != bufp->buffer) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1748 { \
|
18262
|
1749 b = (b - old_buffer) + bufp->buffer; \
|
|
1750 begalt = (begalt - old_buffer) + bufp->buffer; \
|
|
1751 if (fixup_alt_jump) \
|
|
1752 fixup_alt_jump = (fixup_alt_jump - old_buffer) + bufp->buffer;\
|
|
1753 if (laststart) \
|
|
1754 laststart = (laststart - old_buffer) + bufp->buffer; \
|
|
1755 if (pending_exact) \
|
|
1756 pending_exact = (pending_exact - old_buffer) + bufp->buffer; \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1757 } \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1758 } while (0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1759
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1760
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1761 /* Since we have one byte reserved for the register number argument to
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1762 {start,stop}_memory, the maximum number of groups we can report
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1763 things about is what fits in that byte. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1764 #define MAX_REGNUM 255
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1765
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1766 /* But patterns can have more than `MAX_REGNUM' registers. We just
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1767 ignore the excess. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1768 typedef unsigned regnum_t;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1769
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1770
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1771 /* Macros for the compile stack. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1772
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1773 /* Since offsets can go either forwards or backwards, this type needs to
|
18262
|
1774 be able to hold values from -(MAX_BUF_SIZE - 1) to MAX_BUF_SIZE - 1. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1775 typedef int pattern_offset_t;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1776
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1777 typedef struct
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1778 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1779 pattern_offset_t begalt_offset;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1780 pattern_offset_t fixup_alt_jump;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1781 pattern_offset_t inner_group_offset;
|
13565
|
1782 pattern_offset_t laststart_offset;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1783 regnum_t regnum;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1784 } compile_stack_elt_t;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1785
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1786
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1787 typedef struct
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1788 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1789 compile_stack_elt_t *stack;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1790 unsigned size;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1791 unsigned avail; /* Offset of next open position. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1792 } compile_stack_type;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1793
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1794
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1795 #define INIT_COMPILE_STACK_SIZE 32
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1796
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1797 #define COMPILE_STACK_EMPTY (compile_stack.avail == 0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1798 #define COMPILE_STACK_FULL (compile_stack.avail == compile_stack.size)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1799
|
18262
|
1800 /* The next available element. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1801 #define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail])
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1802
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1803
|
18260
|
1804 /* Structure to manage work area for range table. */
|
|
1805 struct range_table_work_area
|
|
1806 {
|
|
1807 int *table; /* actual work area. */
|
|
1808 int allocated; /* allocated size for work area in bytes. */
|
18262
|
1809 int used; /* actually used size in words. */
|
25440
|
1810 int bits; /* flag to record character classes */
|
18260
|
1811 };
|
|
1812
|
|
1813 /* Make sure that WORK_AREA can hold more N multibyte characters. */
|
|
1814 #define EXTEND_RANGE_TABLE_WORK_AREA(work_area, n) \
|
|
1815 do { \
|
|
1816 if (((work_area).used + (n)) * sizeof (int) > (work_area).allocated) \
|
|
1817 { \
|
|
1818 (work_area).allocated += 16 * sizeof (int); \
|
|
1819 if ((work_area).table) \
|
|
1820 (work_area).table \
|
|
1821 = (int *) realloc ((work_area).table, (work_area).allocated); \
|
|
1822 else \
|
|
1823 (work_area).table \
|
|
1824 = (int *) malloc ((work_area).allocated); \
|
|
1825 if ((work_area).table == 0) \
|
|
1826 FREE_STACK_RETURN (REG_ESPACE); \
|
|
1827 } \
|
|
1828 } while (0)
|
|
1829
|
25440
|
1830 #define SET_RANGE_TABLE_WORK_AREA_BIT(work_area, bit) \
|
|
1831 (work_area).bits |= (bit)
|
|
1832
|
|
1833 /* These bits represent the various character classes such as [:alnum:]
|
|
1834 in a charset's range table. */
|
|
1835 #define BIT_ALNUM 0x1
|
|
1836 #define BIT_ALPHA 0x2
|
|
1837 #define BIT_WORD 0x4
|
25877
|
1838 #define BIT_ASCII 0x8
|
|
1839 #define BIT_NONASCII 0x10
|
25440
|
1840 #define BIT_GRAPH 0x20
|
|
1841 #define BIT_LOWER 0x40
|
|
1842 #define BIT_PRINT 0x80
|
|
1843 #define BIT_PUNCT 0x100
|
|
1844 #define BIT_SPACE 0x200
|
|
1845 #define BIT_UPPER 0x400
|
25877
|
1846 #define BIT_UNIBYTE 0x800
|
|
1847 #define BIT_MULTIBYTE 0x1000
|
25440
|
1848
|
18260
|
1849 /* Set a range (RANGE_START, RANGE_END) to WORK_AREA. */
|
|
1850 #define SET_RANGE_TABLE_WORK_AREA(work_area, range_start, range_end) \
|
|
1851 do { \
|
|
1852 EXTEND_RANGE_TABLE_WORK_AREA ((work_area), 2); \
|
|
1853 (work_area).table[(work_area).used++] = (range_start); \
|
|
1854 (work_area).table[(work_area).used++] = (range_end); \
|
|
1855 } while (0)
|
|
1856
|
18262
|
1857 /* Free allocated memory for WORK_AREA. */
|
18260
|
1858 #define FREE_RANGE_TABLE_WORK_AREA(work_area) \
|
|
1859 do { \
|
|
1860 if ((work_area).table) \
|
|
1861 free ((work_area).table); \
|
|
1862 } while (0)
|
|
1863
|
25440
|
1864 #define CLEAR_RANGE_TABLE_WORK_USED(work_area) ((work_area).used = 0, (work_area).bits = 0)
|
18260
|
1865 #define RANGE_TABLE_WORK_USED(work_area) ((work_area).used)
|
25440
|
1866 #define RANGE_TABLE_WORK_BITS(work_area) ((work_area).bits)
|
18260
|
1867 #define RANGE_TABLE_WORK_ELT(work_area, i) ((work_area).table[i])
|
|
1868
|
|
1869
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1870 /* Set the bit for character C in a list. */
|
18262
|
1871 #define SET_LIST_BIT(c) \
|
|
1872 (b[((unsigned char) (c)) / BYTEWIDTH] \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1873 |= 1 << (((unsigned char) c) % BYTEWIDTH))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1874
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1875
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1876 /* Get the next unsigned number in the uncompiled pattern. */
|
18262
|
1877 #define GET_UNSIGNED_NUMBER(num) \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1878 { if (p != pend) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1879 { \
|
18262
|
1880 PATFETCH (c); \
|
|
1881 while (ISDIGIT (c)) \
|
|
1882 { \
|
|
1883 if (num < 0) \
|
|
1884 num = 0; \
|
|
1885 num = num * 10 + c - '0'; \
|
|
1886 if (p == pend) \
|
|
1887 break; \
|
|
1888 PATFETCH (c); \
|
|
1889 } \
|
|
1890 } \
|
13565
|
1891 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1892
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1893 #define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1894
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1895 #define IS_CHAR_CLASS(string) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1896 (STREQ (string, "alpha") || STREQ (string, "upper") \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1897 || STREQ (string, "lower") || STREQ (string, "digit") \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1898 || STREQ (string, "alnum") || STREQ (string, "xdigit") \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1899 || STREQ (string, "space") || STREQ (string, "print") \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1900 || STREQ (string, "punct") || STREQ (string, "graph") \
|
25440
|
1901 || STREQ (string, "cntrl") || STREQ (string, "blank") \
|
25877
|
1902 || STREQ (string, "word") \
|
|
1903 || STREQ (string, "ascii") || STREQ (string, "nonascii") \
|
|
1904 || STREQ (string, "unibyte") || STREQ (string, "multibyte"))
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1905
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1906 #ifndef MATCH_MAY_ALLOCATE
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1907
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1908 /* If we cannot allocate large objects within re_match_2_internal,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1909 we make the fail stack and register vectors global.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1910 The fail stack, we grow to the maximum size when a regexp
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1911 is compiled.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1912 The register vectors, we adjust in size each time we
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1913 compile a regexp, according to the number of registers it needs. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1914
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1915 static fail_stack_type fail_stack;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1916
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1917 /* Size with which the following vectors are currently allocated.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1918 That is so we can make them bigger as needed,
|
18262
|
1919 but never make them smaller. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1920 static int regs_allocated_size;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1921
|
18262
|
1922 static const char ** regstart, ** regend;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1923 static const char ** old_regstart, ** old_regend;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1924 static const char **best_regstart, **best_regend;
|
13565
|
1925 static register_info_type *reg_info;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1926 static const char **reg_dummy;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1927 static register_info_type *reg_info_dummy;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1928
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1929 /* Make the register vectors big enough for NUM_REGS registers,
|
18262
|
1930 but don't make them smaller. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1931
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1932 static
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1933 regex_grow_registers (num_regs)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1934 int num_regs;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1935 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1936 if (num_regs > regs_allocated_size)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1937 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1938 RETALLOC_IF (regstart, num_regs, const char *);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1939 RETALLOC_IF (regend, num_regs, const char *);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1940 RETALLOC_IF (old_regstart, num_regs, const char *);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1941 RETALLOC_IF (old_regend, num_regs, const char *);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1942 RETALLOC_IF (best_regstart, num_regs, const char *);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1943 RETALLOC_IF (best_regend, num_regs, const char *);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1944 RETALLOC_IF (reg_info, num_regs, register_info_type);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1945 RETALLOC_IF (reg_dummy, num_regs, const char *);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1946 RETALLOC_IF (reg_info_dummy, num_regs, register_info_type);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1947
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1948 regs_allocated_size = num_regs;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1949 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1950 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1951
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1952 #endif /* not MATCH_MAY_ALLOCATE */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1953
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1954 /* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1955 Returns one of error codes defined in `regex.h', or zero for success.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1956
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1957 Assumes the `allocated' (and perhaps `buffer') and `translate'
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1958 fields are set in BUFP on entry.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1959
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1960 If it succeeds, results are put in BUFP (if it returns an error, the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1961 contents of BUFP are undefined):
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1962 `buffer' is the compiled pattern;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1963 `syntax' is set to SYNTAX;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1964 `used' is set to the length of the compiled pattern;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1965 `fastmap_accurate' is zero;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1966 `re_nsub' is the number of subexpressions in PATTERN;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1967 `not_bol' and `not_eol' are zero;
|
13565
|
1968
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1969 The `fastmap' and `newline_anchor' fields are neither
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1970 examined nor set. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1971
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1972 /* Return, freeing storage we allocated. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1973 #define FREE_STACK_RETURN(value) \
|
18260
|
1974 do { \
|
|
1975 FREE_RANGE_TABLE_WORK_AREA (range_table_work); \
|
|
1976 free (compile_stack.stack); \
|
|
1977 return value; \
|
|
1978 } while (0)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1979
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1980 static reg_errcode_t
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1981 regex_compile (pattern, size, syntax, bufp)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1982 const char *pattern;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1983 int size;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1984 reg_syntax_t syntax;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1985 struct re_pattern_buffer *bufp;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1986 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1987 /* We fetch characters from PATTERN here. Even though PATTERN is
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1988 `char *' (i.e., signed), we declare these variables as unsigned, so
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1989 they can be reliably used as array indices. */
|
18260
|
1990 register unsigned int c, c1;
|
13565
|
1991
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1992 /* A random temporary spot in PATTERN. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1993 const char *p1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1994
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1995 /* Points to the end of the buffer, where we should append. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1996 register unsigned char *b;
|
13565
|
1997
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1998 /* Keeps track of unclosed groups. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
1999 compile_stack_type compile_stack;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2000
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2001 /* Points to the current (ending) position in the pattern. */
|
22821
|
2002 #ifdef AIX
|
|
2003 /* `const' makes AIX compiler fail. */
|
|
2004 char *p = pattern;
|
|
2005 #else
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2006 const char *p = pattern;
|
22821
|
2007 #endif
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2008 const char *pend = pattern + size;
|
13565
|
2009
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2010 /* How to translate the characters in the pattern. */
|
13250
|
2011 RE_TRANSLATE_TYPE translate = bufp->translate;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2012
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2013 /* Address of the count-byte of the most recently inserted `exactn'
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2014 command. This makes it possible to tell if a new exact-match
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2015 character can be added to that command or if the character requires
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2016 a new `exactn' command. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2017 unsigned char *pending_exact = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2018
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2019 /* Address of start of the most recently finished expression.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2020 This tells, e.g., postfix * where to find the start of its
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2021 operand. Reset at the beginning of groups and alternatives. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2022 unsigned char *laststart = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2023
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2024 /* Address of beginning of regexp, or inside of last group. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2025 unsigned char *begalt;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2026
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2027 /* Place in the uncompiled pattern (i.e., the {) to
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2028 which to go back if the interval is invalid. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2029 const char *beg_interval;
|
13565
|
2030
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2031 /* Address of the place where a forward jump should go to the end of
|
18262
|
2032 the containing expression. Each alternative of an `or' -- except the
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2033 last -- ends with a forward jump of this sort. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2034 unsigned char *fixup_alt_jump = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2035
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2036 /* Counts open-groups as they are encountered. Remembered for the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2037 matching close-group on the compile stack, so the same register
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2038 number is put in the stop_memory as the start_memory. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2039 regnum_t regnum = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2040
|
18260
|
2041 /* Work area for range table of charset. */
|
|
2042 struct range_table_work_area range_table_work;
|
|
2043
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2044 #ifdef DEBUG
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2045 DEBUG_PRINT1 ("\nCompiling pattern: ");
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2046 if (debug)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2047 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2048 unsigned debug_count;
|
13565
|
2049
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2050 for (debug_count = 0; debug_count < size; debug_count++)
|
18262
|
2051 putchar (pattern[debug_count]);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2052 putchar ('\n');
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2053 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2054 #endif /* DEBUG */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2055
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2056 /* Initialize the compile stack. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2057 compile_stack.stack = TALLOC (INIT_COMPILE_STACK_SIZE, compile_stack_elt_t);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2058 if (compile_stack.stack == NULL)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2059 return REG_ESPACE;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2060
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2061 compile_stack.size = INIT_COMPILE_STACK_SIZE;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2062 compile_stack.avail = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2063
|
18260
|
2064 range_table_work.table = 0;
|
|
2065 range_table_work.allocated = 0;
|
|
2066
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2067 /* Initialize the pattern buffer. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2068 bufp->syntax = syntax;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2069 bufp->fastmap_accurate = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2070 bufp->not_bol = bufp->not_eol = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2071
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2072 /* Set `used' to zero, so that if we return an error, the pattern
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2073 printer (for debugging) will think there's no pattern. We reset it
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2074 at the end. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2075 bufp->used = 0;
|
13565
|
2076
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2077 /* Always count groups, whether or not bufp->no_sub is set. */
|
13565
|
2078 bufp->re_nsub = 0;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2079
|
18260
|
2080 #ifdef emacs
|
|
2081 /* bufp->multibyte is set before regex_compile is called, so don't alter
|
|
2082 it. */
|
|
2083 #else /* not emacs */
|
|
2084 /* Nothing is recognized as a multibyte character. */
|
|
2085 bufp->multibyte = 0;
|
|
2086 #endif
|
|
2087
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2088 #if !defined (emacs) && !defined (SYNTAX_TABLE)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2089 /* Initialize the syntax table. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2090 init_syntax_once ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2091 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2092
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2093 if (bufp->allocated == 0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2094 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2095 if (bufp->buffer)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2096 { /* If zero allocated, but buffer is non-null, try to realloc
|
18262
|
2097 enough space. This loses if buffer's address is bogus, but
|
|
2098 that is the user's responsibility. */
|
|
2099 RETALLOC (bufp->buffer, INIT_BUF_SIZE, unsigned char);
|
|
2100 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2101 else
|
18262
|
2102 { /* Caller did not allocate a buffer. Do it for them. */
|
|
2103 bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char);
|
|
2104 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2105 if (!bufp->buffer) FREE_STACK_RETURN (REG_ESPACE);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2106
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2107 bufp->allocated = INIT_BUF_SIZE;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2108 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2109
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2110 begalt = b = bufp->buffer;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2111
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2112 /* Loop through the uncompiled pattern until we're at the end. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2113 while (p != pend)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2114 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2115 PATFETCH (c);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2116
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2117 switch (c)
|
18262
|
2118 {
|
|
2119 case '^':
|
|
2120 {
|
|
2121 if ( /* If at start of pattern, it's an operator. */
|
|
2122 p == pattern + 1
|
|
2123 /* If context independent, it's an operator. */
|
|
2124 || syntax & RE_CONTEXT_INDEP_ANCHORS
|
|
2125 /* Otherwise, depends on what's come before. */
|
|
2126 || at_begline_loc_p (pattern, p, syntax))
|
|
2127 BUF_PUSH (begline);
|
|
2128 else
|
|
2129 goto normal_char;
|
|
2130 }
|
|
2131 break;
|
|
2132
|
|
2133
|
|
2134 case '$':
|
|
2135 {
|
|
2136 if ( /* If at end of pattern, it's an operator. */
|
|
2137 p == pend
|
|
2138 /* If context independent, it's an operator. */
|
|
2139 || syntax & RE_CONTEXT_INDEP_ANCHORS
|
|
2140 /* Otherwise, depends on what's next. */
|
|
2141 || at_endline_loc_p (p, pend, syntax))
|
|
2142 BUF_PUSH (endline);
|
|
2143 else
|
|
2144 goto normal_char;
|
|
2145 }
|
|
2146 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2147
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2148
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2149 case '+':
|
18262
|
2150 case '?':
|
|
2151 if ((syntax & RE_BK_PLUS_QM)
|
|
2152 || (syntax & RE_LIMITED_OPS))
|
|
2153 goto normal_char;
|
|
2154 handle_plus:
|
|
2155 case '*':
|
|
2156 /* If there is no previous pattern... */
|
|
2157 if (!laststart)
|
|
2158 {
|
|
2159 if (syntax & RE_CONTEXT_INVALID_OPS)
|
|
2160 FREE_STACK_RETURN (REG_BADRPT);
|
|
2161 else if (!(syntax & RE_CONTEXT_INDEP_OPS))
|
|
2162 goto normal_char;
|
|
2163 }
|
|
2164
|
|
2165 {
|
|
2166 /* Are we optimizing this jump? */
|
|
2167 boolean keep_string_p = false;
|
|
2168
|
|
2169 /* 1 means zero (many) matches is allowed. */
|
|
2170 char zero_times_ok = 0, many_times_ok = 0;
|
|
2171
|
|
2172 /* If there is a sequence of repetition chars, collapse it
|
|
2173 down to just one (the right one). We can't combine
|
|
2174 interval operators with these because of, e.g., `a{2}*',
|
|
2175 which should only match an even number of `a's. */
|
|
2176
|
|
2177 for (;;)
|
|
2178 {
|
|
2179 zero_times_ok |= c != '+';
|
|
2180 many_times_ok |= c != '?';
|
|
2181
|
|
2182 if (p == pend)
|
|
2183 break;
|
|
2184
|
|
2185 PATFETCH (c);
|
|
2186
|
|
2187 if (c == '*'
|
|
2188 || (!(syntax & RE_BK_PLUS_QM) && (c == '+' || c == '?')))
|
|
2189 ;
|
|
2190
|
|
2191 else if (syntax & RE_BK_PLUS_QM && c == '\\')
|
|
2192 {
|
|
2193 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
|
|
2194
|
|
2195 PATFETCH (c1);
|
|
2196 if (!(c1 == '+' || c1 == '?'))
|
|
2197 {
|
|
2198 PATUNFETCH;
|
|
2199 PATUNFETCH;
|
|
2200 break;
|
|
2201 }
|
|
2202
|
|
2203 c = c1;
|
|
2204 }
|
|
2205 else
|
|
2206 {
|
|
2207 PATUNFETCH;
|
|
2208 break;
|
|
2209 }
|
|
2210
|
|
2211 /* If we get here, we found another repeat character. */
|
|
2212 }
|
|
2213
|
|
2214 /* Star, etc. applied to an empty pattern is equivalent
|
|
2215 to an empty pattern. */
|
|
2216 if (!laststart)
|
|
2217 break;
|
|
2218
|
|
2219 /* Now we know whether or not zero matches is allowed
|
|
2220 and also whether or not two or more matches is allowed. */
|
|
2221 if (many_times_ok)
|
|
2222 { /* More than one repetition is allowed, so put in at the
|
|
2223 end a backward relative jump from `b' to before the next
|
|
2224 jump we're going to put in below (which jumps from
|
|
2225 laststart to after this jump).
|
|
2226
|
|
2227 But if we are at the `*' in the exact sequence `.*\n',
|
|
2228 insert an unconditional jump backwards to the .,
|
|
2229 instead of the beginning of the loop. This way we only
|
|
2230 push a failure point once, instead of every time
|
|
2231 through the loop. */
|
|
2232 assert (p - 1 > pattern);
|
|
2233
|
|
2234 /* Allocate the space for the jump. */
|
|
2235 GET_BUFFER_SPACE (3);
|
|
2236
|
|
2237 /* We know we are not at the first character of the pattern,
|
|
2238 because laststart was nonzero. And we've already
|
|
2239 incremented `p', by the way, to be the character after
|
|
2240 the `*'. Do we have to do something analogous here
|
|
2241 for null bytes, because of RE_DOT_NOT_NULL? */
|
21348
|
2242 if (TRANSLATE ((unsigned char)*(p - 2)) == TRANSLATE ('.')
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2243 && zero_times_ok
|
21348
|
2244 && p < pend
|
|
2245 && TRANSLATE ((unsigned char)*p) == TRANSLATE ('\n')
|
18262
|
2246 && !(syntax & RE_DOT_NEWLINE))
|
|
2247 { /* We have .*\n. */
|
|
2248 STORE_JUMP (jump, b, laststart);
|
|
2249 keep_string_p = true;
|
|
2250 }
|
|
2251 else
|
|
2252 /* Anything else. */
|
|
2253 STORE_JUMP (maybe_pop_jump, b, laststart - 3);
|
|
2254
|
|
2255 /* We've added more stuff to the buffer. */
|
|
2256 b += 3;
|
|
2257 }
|
|
2258
|
|
2259 /* On failure, jump from laststart to b + 3, which will be the
|
|
2260 end of the buffer after this jump is inserted. */
|
|
2261 GET_BUFFER_SPACE (3);
|
|
2262 INSERT_JUMP (keep_string_p ? on_failure_keep_string_jump
|
|
2263 : on_failure_jump,
|
|
2264 laststart, b + 3);
|
|
2265 pending_exact = 0;
|
|
2266 b += 3;
|
|
2267
|
|
2268 if (!zero_times_ok)
|
|
2269 {
|
|
2270 /* At least one repetition is required, so insert a
|
|
2271 `dummy_failure_jump' before the initial
|
|
2272 `on_failure_jump' instruction of the loop. This
|
|
2273 effects a skip over that instruction the first time
|
|
2274 we hit that loop. */
|
|
2275 GET_BUFFER_SPACE (3);
|
|
2276 INSERT_JUMP (dummy_failure_jump, laststart, laststart + 6);
|
|
2277 b += 3;
|
|
2278 }
|
|
2279 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2280 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2281
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2282
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2283 case '.':
|
18262
|
2284 laststart = b;
|
|
2285 BUF_PUSH (anychar);
|
|
2286 break;
|
|
2287
|
|
2288
|
|
2289 case '[':
|
|
2290 {
|
18260
|
2291 CLEAR_RANGE_TABLE_WORK_USED (range_table_work);
|
|
2292
|
18262
|
2293 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
|
|
2294
|
|
2295 /* Ensure that we have enough space to push a charset: the
|
|
2296 opcode, the length count, and the bitset; 34 bytes in all. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2297 GET_BUFFER_SPACE (34);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2298
|
18262
|
2299 laststart = b;
|
|
2300
|
|
2301 /* We test `*p == '^' twice, instead of using an if
|
|
2302 statement, so we only need one BUF_PUSH. */
|
|
2303 BUF_PUSH (*p == '^' ? charset_not : charset);
|
|
2304 if (*p == '^')
|
|
2305 p++;
|
|
2306
|
|
2307 /* Remember the first position in the bracket expression. */
|
|
2308 p1 = p;
|
|
2309
|
|
2310 /* Push the number of bytes in the bitmap. */
|
|
2311 BUF_PUSH ((1 << BYTEWIDTH) / BYTEWIDTH);
|
|
2312
|
|
2313 /* Clear the whole map. */
|
|
2314 bzero (b, (1 << BYTEWIDTH) / BYTEWIDTH);
|
|
2315
|
|
2316 /* charset_not matches newline according to a syntax bit. */
|
|
2317 if ((re_opcode_t) b[-2] == charset_not
|
|
2318 && (syntax & RE_HAT_LISTS_NOT_NEWLINE))
|
|
2319 SET_LIST_BIT ('\n');
|
|
2320
|
|
2321 /* Read in characters and ranges, setting map bits. */
|
|
2322 for (;;)
|
|
2323 {
|
18260
|
2324 int len;
|
|
2325 boolean escaped_char = false;
|
|
2326
|
18262
|
2327 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
|
|
2328
|
|
2329 PATFETCH (c);
|
|
2330
|
|
2331 /* \ might escape characters inside [...] and [^...]. */
|
|
2332 if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\')
|
|
2333 {
|
|
2334 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
|
16010
|
2335
|
|
2336 PATFETCH (c);
|
18260
|
2337 escaped_char = true;
|
18262
|
2338 }
|
18260
|
2339 else
|
|
2340 {
|
19184
|
2341 /* Could be the end of the bracket expression. If it's
|
|
2342 not (i.e., when the bracket expression is `[]' so
|
|
2343 far), the ']' character bit gets set way below. */
|
|
2344 if (c == ']' && p != p1 + 1)
|
|
2345 break;
|
18262
|
2346 }
|
18260
|
2347
|
|
2348 /* If C indicates start of multibyte char, get the
|
|
2349 actual character code in C, and set the pattern
|
|
2350 pointer P to the next character boundary. */
|
|
2351 if (bufp->multibyte && BASE_LEADING_CODE_P (c))
|
|
2352 {
|
|
2353 PATUNFETCH;
|
|
2354 c = STRING_CHAR_AND_LENGTH (p, pend - p, len);
|
|
2355 p += len;
|
18262
|
2356 }
|
18260
|
2357 /* What should we do for the character which is
|
|
2358 greater than 0x7F, but not BASE_LEADING_CODE_P?
|
|
2359 XXX */
|
|
2360
|
18262
|
2361 /* See if we're at the beginning of a possible character
|
|
2362 class. */
|
18260
|
2363
|
|
2364 else if (!escaped_char &&
|
|
2365 syntax & RE_CHAR_CLASSES && c == '[' && *p == ':')
|
19184
|
2366 {
|
|
2367 /* Leave room for the null. */
|
18262
|
2368 char str[CHAR_CLASS_MAX_LENGTH + 1];
|
|
2369
|
|
2370 PATFETCH (c);
|
|
2371 c1 = 0;
|
|
2372
|
|
2373 /* If pattern is `[[:'. */
|
|
2374 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
|
|
2375
|
|
2376 for (;;)
|
|
2377 {
|
|
2378 PATFETCH (c);
|
|
2379 if (c == ':' || c == ']' || p == pend
|
|
2380 || c1 == CHAR_CLASS_MAX_LENGTH)
|
|
2381 break;
|
|
2382 str[c1++] = c;
|
|
2383 }
|
|
2384 str[c1] = '\0';
|
18260
|
2385
|
|
2386 /* If isn't a word bracketed by `[:' and `:]':
|
|
2387 undo the ending character, the letters, and
|
|
2388 leave the leading `:' and `[' (but set bits for
|
|
2389 them). */
|
18262
|
2390 if (c == ':' && *p == ']')
|
|
2391 {
|
|
2392 int ch;
|
|
2393 boolean is_alnum = STREQ (str, "alnum");
|
|
2394 boolean is_alpha = STREQ (str, "alpha");
|
25877
|
2395 boolean is_ascii = STREQ (str, "ascii");
|
18262
|
2396 boolean is_blank = STREQ (str, "blank");
|
|
2397 boolean is_cntrl = STREQ (str, "cntrl");
|
|
2398 boolean is_digit = STREQ (str, "digit");
|
|
2399 boolean is_graph = STREQ (str, "graph");
|
|
2400 boolean is_lower = STREQ (str, "lower");
|
25877
|
2401 boolean is_multibyte = STREQ (str, "multibyte");
|
|
2402 boolean is_nonascii = STREQ (str, "nonascii");
|
18262
|
2403 boolean is_print = STREQ (str, "print");
|
|
2404 boolean is_punct = STREQ (str, "punct");
|
|
2405 boolean is_space = STREQ (str, "space");
|
25877
|
2406 boolean is_unibyte = STREQ (str, "unibyte");
|
18262
|
2407 boolean is_upper = STREQ (str, "upper");
|
25877
|
2408 boolean is_word = STREQ (str, "word");
|
18262
|
2409 boolean is_xdigit = STREQ (str, "xdigit");
|
|
2410
|
|
2411 if (!IS_CHAR_CLASS (str))
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2412 FREE_STACK_RETURN (REG_ECTYPE);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2413
|
18262
|
2414 /* Throw away the ] at the end of the character
|
|
2415 class. */
|
|
2416 PATFETCH (c);
|
|
2417
|
|
2418 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
|
|
2419
|
25440
|
2420 /* Most character classes in a multibyte match
|
|
2421 just set a flag. Exceptions are is_blank,
|
|
2422 is_digit, is_cntrl, and is_xdigit, since
|
|
2423 they can only match ASCII characters. We
|
|
2424 don't need to handle them for multibyte. */
|
|
2425
|
|
2426 if (bufp->multibyte)
|
|
2427 {
|
|
2428 int bit = 0;
|
|
2429
|
|
2430 if (is_alnum) bit = BIT_ALNUM;
|
|
2431 if (is_alpha) bit = BIT_ALPHA;
|
25877
|
2432 if (is_ascii) bit = BIT_ASCII;
|
25440
|
2433 if (is_graph) bit = BIT_GRAPH;
|
|
2434 if (is_lower) bit = BIT_LOWER;
|
25877
|
2435 if (is_multibyte) bit = BIT_MULTIBYTE;
|
|
2436 if (is_nonascii) bit = BIT_NONASCII;
|
25440
|
2437 if (is_print) bit = BIT_PRINT;
|
|
2438 if (is_punct) bit = BIT_PUNCT;
|
|
2439 if (is_space) bit = BIT_SPACE;
|
25877
|
2440 if (is_unibyte) bit = BIT_UNIBYTE;
|
25440
|
2441 if (is_upper) bit = BIT_UPPER;
|
|
2442 if (is_word) bit = BIT_WORD;
|
|
2443 if (bit)
|
|
2444 SET_RANGE_TABLE_WORK_AREA_BIT (range_table_work,
|
|
2445 bit);
|
|
2446 }
|
|
2447
|
|
2448 /* Handle character classes for ASCII characters. */
|
18262
|
2449 for (ch = 0; ch < 1 << BYTEWIDTH; ch++)
|
|
2450 {
|
16239
|
2451 int translated = TRANSLATE (ch);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2452 /* This was split into 3 if's to
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2453 avoid an arbitrary limit in some compiler. */
|
18262
|
2454 if ( (is_alnum && ISALNUM (ch))
|
|
2455 || (is_alpha && ISALPHA (ch))
|
|
2456 || (is_blank && ISBLANK (ch))
|
|
2457 || (is_cntrl && ISCNTRL (ch)))
|
16239
|
2458 SET_LIST_BIT (translated);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2459 if ( (is_digit && ISDIGIT (ch))
|
18262
|
2460 || (is_graph && ISGRAPH (ch))
|
|
2461 || (is_lower && ISLOWER (ch))
|
|
2462 || (is_print && ISPRINT (ch)))
|
16239
|
2463 SET_LIST_BIT (translated);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2464 if ( (is_punct && ISPUNCT (ch))
|
18262
|
2465 || (is_space && ISSPACE (ch))
|
|
2466 || (is_upper && ISUPPER (ch))
|
|
2467 || (is_xdigit && ISXDIGIT (ch)))
|
16239
|
2468 SET_LIST_BIT (translated);
|
25877
|
2469 if ( (is_ascii && IS_REAL_ASCII (ch))
|
|
2470 || (is_nonascii && !IS_REAL_ASCII (ch))
|
|
2471 || (is_unibyte && ISUNIBYTE (ch))
|
|
2472 || (is_multibyte && !ISUNIBYTE (ch)))
|
|
2473 SET_LIST_BIT (translated);
|
|
2474
|
25440
|
2475 if ( (is_word && ISWORD (ch)))
|
|
2476 SET_LIST_BIT (translated);
|
18262
|
2477 }
|
18260
|
2478
|
|
2479 /* Repeat the loop. */
|
|
2480 continue;
|
18262
|
2481 }
|
|
2482 else
|
|
2483 {
|
|
2484 c1++;
|
|
2485 while (c1--)
|
|
2486 PATUNFETCH;
|
|
2487 SET_LIST_BIT ('[');
|
18260
|
2488
|
|
2489 /* Because the `:' may starts the range, we
|
|
2490 can't simply set bit and repeat the loop.
|
18262
|
2491 Instead, just set it to C and handle below. */
|
18260
|
2492 c = ':';
|
18262
|
2493 }
|
|
2494 }
|
18260
|
2495
|
|
2496 if (p < pend && p[0] == '-' && p[1] != ']')
|
|
2497 {
|
|
2498
|
|
2499 /* Discard the `-'. */
|
|
2500 PATFETCH (c1);
|
|
2501
|
|
2502 /* Fetch the character which ends the range. */
|
|
2503 PATFETCH (c1);
|
|
2504 if (bufp->multibyte && BASE_LEADING_CODE_P (c1))
|
|
2505 {
|
|
2506 PATUNFETCH;
|
|
2507 c1 = STRING_CHAR_AND_LENGTH (p, pend - p, len);
|
|
2508 p += len;
|
|
2509 }
|
|
2510
|
21348
|
2511 if (SINGLE_BYTE_CHAR_P (c)
|
|
2512 && ! SINGLE_BYTE_CHAR_P (c1))
|
|
2513 {
|
|
2514 /* Handle a range such as \177-\377 in multibyte mode.
|
|
2515 Split that into two ranges,,
|
|
2516 the low one ending at 0237, and the high one
|
|
2517 starting at ...040. */
|
|
2518 int c1_base = (c1 & ~0177) | 040;
|
|
2519 SET_RANGE_TABLE_WORK_AREA (range_table_work, c, c1);
|
|
2520 c1 = 0237;
|
|
2521 }
|
|
2522 else if (!SAME_CHARSET_P (c, c1))
|
18260
|
2523 FREE_STACK_RETURN (REG_ERANGE);
|
|
2524 }
|
18262
|
2525 else
|
18260
|
2526 /* Range from C to C. */
|
|
2527 c1 = c;
|
|
2528
|
|
2529 /* Set the range ... */
|
|
2530 if (SINGLE_BYTE_CHAR_P (c))
|
|
2531 /* ... into bitmap. */
|
18262
|
2532 {
|
18260
|
2533 unsigned this_char;
|
|
2534 int range_start = c, range_end = c1;
|
|
2535
|
|
2536 /* If the start is after the end, the range is empty. */
|
|
2537 if (range_start > range_end)
|
|
2538 {
|
|
2539 if (syntax & RE_NO_EMPTY_RANGES)
|
|
2540 FREE_STACK_RETURN (REG_ERANGE);
|
|
2541 /* Else, repeat the loop. */
|
16010
|
2542 }
|
|
2543 else
|
|
2544 {
|
18260
|
2545 for (this_char = range_start; this_char <= range_end;
|
|
2546 this_char++)
|
|
2547 SET_LIST_BIT (TRANSLATE (this_char));
|
21348
|
2548 }
|
18262
|
2549 }
|
16010
|
2550 else
|
18260
|
2551 /* ... into range table. */
|
|
2552 SET_RANGE_TABLE_WORK_AREA (range_table_work, c, c1);
|
16010
|
2553 }
|
|
2554
|
18262
|
2555 /* Discard any (non)matching list bytes that are all 0 at the
|
|
2556 end of the map. Decrease the map-length byte too. */
|
|
2557 while ((int) b[-1] > 0 && b[b[-1] - 1] == 0)
|
|
2558 b[-1]--;
|
|
2559 b += b[-1];
|
18260
|
2560
|
25440
|
2561 /* Build real range table from work area. */
|
|
2562 if (RANGE_TABLE_WORK_USED (range_table_work)
|
|
2563 || RANGE_TABLE_WORK_BITS (range_table_work))
|
18260
|
2564 {
|
|
2565 int i;
|
|
2566 int used = RANGE_TABLE_WORK_USED (range_table_work);
|
|
2567
|
|
2568 /* Allocate space for COUNT + RANGE_TABLE. Needs two
|
25440
|
2569 bytes for flags, two for COUNT, and three bytes for
|
|
2570 each character. */
|
|
2571 GET_BUFFER_SPACE (4 + used * 3);
|
18260
|
2572
|
|
2573 /* Indicate the existence of range table. */
|
|
2574 laststart[1] |= 0x80;
|
|
2575
|
25440
|
2576 /* Store the character class flag bits into the range table.
|
|
2577 If not in emacs, these flag bits are always 0. */
|
|
2578 *b++ = RANGE_TABLE_WORK_BITS (range_table_work) & 0xff;
|
|
2579 *b++ = RANGE_TABLE_WORK_BITS (range_table_work) >> 8;
|
|
2580
|
18260
|
2581 STORE_NUMBER_AND_INCR (b, used / 2);
|
|
2582 for (i = 0; i < used; i++)
|
|
2583 STORE_CHARACTER_AND_INCR
|
|
2584 (b, RANGE_TABLE_WORK_ELT (range_table_work, i));
|
|
2585 }
|
18262
|
2586 }
|
|
2587 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2588
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2589
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2590 case '(':
|
18262
|
2591 if (syntax & RE_NO_BK_PARENS)
|
|
2592 goto handle_open;
|
|
2593 else
|
|
2594 goto normal_char;
|
|
2595
|
|
2596
|
|
2597 case ')':
|
|
2598 if (syntax & RE_NO_BK_PARENS)
|
|
2599 goto handle_close;
|
|
2600 else
|
|
2601 goto normal_char;
|
|
2602
|
|
2603
|
|
2604 case '\n':
|
|
2605 if (syntax & RE_NEWLINE_ALT)
|
|
2606 goto handle_alt;
|
|
2607 else
|
|
2608 goto normal_char;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2609
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2610
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2611 case '|':
|
18262
|
2612 if (syntax & RE_NO_BK_VBAR)
|
|
2613 goto handle_alt;
|
|
2614 else
|
|
2615 goto normal_char;
|
|
2616
|
|
2617
|
|
2618 case '{':
|
|
2619 if (syntax & RE_INTERVALS && syntax & RE_NO_BK_BRACES)
|
|
2620 goto handle_interval;
|
|
2621 else
|
|
2622 goto normal_char;
|
|
2623
|
|
2624
|
|
2625 case '\\':
|
|
2626 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
|
|
2627
|
|
2628 /* Do not translate the character after the \, so that we can
|
|
2629 distinguish, e.g., \B from \b, even if we normally would
|
|
2630 translate, e.g., B to b. */
|
|
2631 PATFETCH_RAW (c);
|
|
2632
|
|
2633 switch (c)
|
|
2634 {
|
|
2635 case '(':
|
|
2636 if (syntax & RE_NO_BK_PARENS)
|
|
2637 goto normal_backslash;
|
|
2638
|
|
2639 handle_open:
|
|
2640 bufp->re_nsub++;
|
|
2641 regnum++;
|
|
2642
|
|
2643 if (COMPILE_STACK_FULL)
|
|
2644 {
|
|
2645 RETALLOC (compile_stack.stack, compile_stack.size << 1,
|
|
2646 compile_stack_elt_t);
|
|
2647 if (compile_stack.stack == NULL) return REG_ESPACE;
|
|
2648
|
|
2649 compile_stack.size <<= 1;
|
|
2650 }
|
|
2651
|
|
2652 /* These are the values to restore when we hit end of this
|
|
2653 group. They are all relative offsets, so that if the
|
|
2654 whole pattern moves because of realloc, they will still
|
|
2655 be valid. */
|
|
2656 COMPILE_STACK_TOP.begalt_offset = begalt - bufp->buffer;
|
|
2657 COMPILE_STACK_TOP.fixup_alt_jump
|
|
2658 = fixup_alt_jump ? fixup_alt_jump - bufp->buffer + 1 : 0;
|
|
2659 COMPILE_STACK_TOP.laststart_offset = b - bufp->buffer;
|
|
2660 COMPILE_STACK_TOP.regnum = regnum;
|
|
2661
|
|
2662 /* We will eventually replace the 0 with the number of
|
|
2663 groups inner to this one. But do not push a
|
|
2664 start_memory for groups beyond the last one we can
|
|
2665 represent in the compiled pattern. */
|
|
2666 if (regnum <= MAX_REGNUM)
|
|
2667 {
|
|
2668 COMPILE_STACK_TOP.inner_group_offset = b - bufp->buffer + 2;
|
|
2669 BUF_PUSH_3 (start_memory, regnum, 0);
|
|
2670 }
|
|
2671
|
|
2672 compile_stack.avail++;
|
|
2673
|
|
2674 fixup_alt_jump = 0;
|
|
2675 laststart = 0;
|
|
2676 begalt = b;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2677 /* If we've reached MAX_REGNUM groups, then this open
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2678 won't actually generate any code, so we'll have to
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2679 clear pending_exact explicitly. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2680 pending_exact = 0;
|
18262
|
2681 break;
|
|
2682
|
|
2683
|
|
2684 case ')':
|
|
2685 if (syntax & RE_NO_BK_PARENS) goto normal_backslash;
|
|
2686
|
|
2687 if (COMPILE_STACK_EMPTY)
|
|
2688 if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
|
|
2689 goto normal_backslash;
|
|
2690 else
|
|
2691 FREE_STACK_RETURN (REG_ERPAREN);
|
|
2692
|
|
2693 handle_close:
|
|
2694 if (fixup_alt_jump)
|
|
2695 { /* Push a dummy failure point at the end of the
|
|
2696 alternative for a possible future
|
|
2697 `pop_failure_jump' to pop. See comments at
|
|
2698 `push_dummy_failure' in `re_match_2'. */
|
|
2699 BUF_PUSH (push_dummy_failure);
|
|
2700
|
|
2701 /* We allocated space for this jump when we assigned
|
|
2702 to `fixup_alt_jump', in the `handle_alt' case below. */
|
|
2703 STORE_JUMP (jump_past_alt, fixup_alt_jump, b - 1);
|
|
2704 }
|
|
2705
|
|
2706 /* See similar code for backslashed left paren above. */
|
|
2707 if (COMPILE_STACK_EMPTY)
|
|
2708 if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
|
|
2709 goto normal_char;
|
|
2710 else
|
|
2711 FREE_STACK_RETURN (REG_ERPAREN);
|
|
2712
|
|
2713 /* Since we just checked for an empty stack above, this
|
|
2714 ``can't happen''. */
|
|
2715 assert (compile_stack.avail != 0);
|
|
2716 {
|
|
2717 /* We don't just want to restore into `regnum', because
|
|
2718 later groups should continue to be numbered higher,
|
|
2719 as in `(ab)c(de)' -- the second group is #2. */
|
|
2720 regnum_t this_group_regnum;
|
|
2721
|
|
2722 compile_stack.avail--;
|
|
2723 begalt = bufp->buffer + COMPILE_STACK_TOP.begalt_offset;
|
|
2724 fixup_alt_jump
|
|
2725 = COMPILE_STACK_TOP.fixup_alt_jump
|
|
2726 ? bufp->buffer + COMPILE_STACK_TOP.fixup_alt_jump - 1
|
|
2727 : 0;
|
|
2728 laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset;
|
|
2729 this_group_regnum = COMPILE_STACK_TOP.regnum;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2730 /* If we've reached MAX_REGNUM groups, then this open
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2731 won't actually generate any code, so we'll have to
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2732 clear pending_exact explicitly. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2733 pending_exact = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2734
|
18262
|
2735 /* We're at the end of the group, so now we know how many
|
|
2736 groups were inside this one. */
|
|
2737 if (this_group_regnum <= MAX_REGNUM)
|
|
2738 {
|
|
2739 unsigned char *inner_group_loc
|
|
2740 = bufp->buffer + COMPILE_STACK_TOP.inner_group_offset;
|
|
2741
|
|
2742 *inner_group_loc = regnum - this_group_regnum;
|
|
2743 BUF_PUSH_3 (stop_memory, this_group_regnum,
|
|
2744 regnum - this_group_regnum);
|
|
2745 }
|
|
2746 }
|
|
2747 break;
|
|
2748
|
|
2749
|
|
2750 case '|': /* `\|'. */
|
|
2751 if (syntax & RE_LIMITED_OPS || syntax & RE_NO_BK_VBAR)
|
|
2752 goto normal_backslash;
|
|
2753 handle_alt:
|
|
2754 if (syntax & RE_LIMITED_OPS)
|
|
2755 goto normal_char;
|
|
2756
|
|
2757 /* Insert before the previous alternative a jump which
|
|
2758 jumps to this alternative if the former fails. */
|
|
2759 GET_BUFFER_SPACE (3);
|
|
2760 INSERT_JUMP (on_failure_jump, begalt, b + 6);
|
|
2761 pending_exact = 0;
|
|
2762 b += 3;
|
|
2763
|
|
2764 /* The alternative before this one has a jump after it
|
|
2765 which gets executed if it gets matched. Adjust that
|
|
2766 jump so it will jump to this alternative's analogous
|
|
2767 jump (put in below, which in turn will jump to the next
|
|
2768 (if any) alternative's such jump, etc.). The last such
|
|
2769 jump jumps to the correct final destination. A picture:
|
|
2770 _____ _____
|
|
2771 | | | |
|
|
2772 | v | v
|
|
2773 a | b | c
|
|
2774
|
|
2775 If we are at `b', then fixup_alt_jump right now points to a
|
|
2776 three-byte space after `a'. We'll put in the jump, set
|
|
2777 fixup_alt_jump to right after `b', and leave behind three
|
|
2778 bytes which we'll fill in when we get to after `c'. */
|
|
2779
|
|
2780 if (fixup_alt_jump)
|
|
2781 STORE_JUMP (jump_past_alt, fixup_alt_jump, b);
|
|
2782
|
|
2783 /* Mark and leave space for a jump after this alternative,
|
|
2784 to be filled in later either by next alternative or
|
|
2785 when know we're at the end of a series of alternatives. */
|
|
2786 fixup_alt_jump = b;
|
|
2787 GET_BUFFER_SPACE (3);
|
|
2788 b += 3;
|
|
2789
|
|
2790 laststart = 0;
|
|
2791 begalt = b;
|
|
2792 break;
|
|
2793
|
|
2794
|
|
2795 case '{':
|
|
2796 /* If \{ is a literal. */
|
|
2797 if (!(syntax & RE_INTERVALS)
|
|
2798 /* If we're at `\{' and it's not the open-interval
|
|
2799 operator. */
|
|
2800 || ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
|
|
2801 || (p - 2 == pattern && p == pend))
|
|
2802 goto normal_backslash;
|
|
2803
|
|
2804 handle_interval:
|
|
2805 {
|
|
2806 /* If got here, then the syntax allows intervals. */
|
|
2807
|
|
2808 /* At least (most) this many matches must be made. */
|
|
2809 int lower_bound = -1, upper_bound = -1;
|
|
2810
|
|
2811 beg_interval = p - 1;
|
|
2812
|
|
2813 if (p == pend)
|
|
2814 {
|
|
2815 if (syntax & RE_NO_BK_BRACES)
|
|
2816 goto unfetch_interval;
|
|
2817 else
|
|
2818 FREE_STACK_RETURN (REG_EBRACE);
|
|
2819 }
|
|
2820
|
|
2821 GET_UNSIGNED_NUMBER (lower_bound);
|
|
2822
|
|
2823 if (c == ',')
|
|
2824 {
|
|
2825 GET_UNSIGNED_NUMBER (upper_bound);
|
|
2826 if (upper_bound < 0) upper_bound = RE_DUP_MAX;
|
|
2827 }
|
|
2828 else
|
|
2829 /* Interval such as `{1}' => match exactly once. */
|
|
2830 upper_bound = lower_bound;
|
|
2831
|
|
2832 if (lower_bound < 0 || upper_bound > RE_DUP_MAX
|
|
2833 || lower_bound > upper_bound)
|
|
2834 {
|
|
2835 if (syntax & RE_NO_BK_BRACES)
|
|
2836 goto unfetch_interval;
|
|
2837 else
|
|
2838 FREE_STACK_RETURN (REG_BADBR);
|
|
2839 }
|
|
2840
|
|
2841 if (!(syntax & RE_NO_BK_BRACES))
|
|
2842 {
|
|
2843 if (c != '\\') FREE_STACK_RETURN (REG_EBRACE);
|
|
2844
|
|
2845 PATFETCH (c);
|
|
2846 }
|
|
2847
|
|
2848 if (c != '}')
|
|
2849 {
|
|
2850 if (syntax & RE_NO_BK_BRACES)
|
|
2851 goto unfetch_interval;
|
|
2852 else
|
|
2853 FREE_STACK_RETURN (REG_BADBR);
|
|
2854 }
|
|
2855
|
|
2856 /* We just parsed a valid interval. */
|
|
2857
|
|
2858 /* If it's invalid to have no preceding re. */
|
|
2859 if (!laststart)
|
|
2860 {
|
|
2861 if (syntax & RE_CONTEXT_INVALID_OPS)
|
|
2862 FREE_STACK_RETURN (REG_BADRPT);
|
|
2863 else if (syntax & RE_CONTEXT_INDEP_OPS)
|
|
2864 laststart = b;
|
|
2865 else
|
|
2866 goto unfetch_interval;
|
|
2867 }
|
|
2868
|
|
2869 /* If the upper bound is zero, don't want to succeed at
|
|
2870 all; jump from `laststart' to `b + 3', which will be
|
|
2871 the end of the buffer after we insert the jump. */
|
|
2872 if (upper_bound == 0)
|
|
2873 {
|
|
2874 GET_BUFFER_SPACE (3);
|
|
2875 INSERT_JUMP (jump, laststart, b + 3);
|
|
2876 b += 3;
|
|
2877 }
|
|
2878
|
|
2879 /* Otherwise, we have a nontrivial interval. When
|
|
2880 we're all done, the pattern will look like:
|
|
2881 set_number_at <jump count> <upper bound>
|
|
2882 set_number_at <succeed_n count> <lower bound>
|
|
2883 succeed_n <after jump addr> <succeed_n count>
|
|
2884 <body of loop>
|
|
2885 jump_n <succeed_n addr> <jump count>
|
|
2886 (The upper bound and `jump_n' are omitted if
|
|
2887 `upper_bound' is 1, though.) */
|
|
2888 else
|
|
2889 { /* If the upper bound is > 1, we need to insert
|
|
2890 more at the end of the loop. */
|
|
2891 unsigned nbytes = 10 + (upper_bound > 1) * 10;
|
|
2892
|
|
2893 GET_BUFFER_SPACE (nbytes);
|
|
2894
|
|
2895 /* Initialize lower bound of the `succeed_n', even
|
|
2896 though it will be set during matching by its
|
|
2897 attendant `set_number_at' (inserted next),
|
|
2898 because `re_compile_fastmap' needs to know.
|
|
2899 Jump to the `jump_n' we might insert below. */
|
|
2900 INSERT_JUMP2 (succeed_n, laststart,
|
|
2901 b + 5 + (upper_bound > 1) * 5,
|
|
2902 lower_bound);
|
|
2903 b += 5;
|
|
2904
|
|
2905 /* Code to initialize the lower bound. Insert
|
|
2906 before the `succeed_n'. The `5' is the last two
|
|
2907 bytes of this `set_number_at', plus 3 bytes of
|
|
2908 the following `succeed_n'. */
|
|
2909 insert_op2 (set_number_at, laststart, 5, lower_bound, b);
|
|
2910 b += 5;
|
|
2911
|
|
2912 if (upper_bound > 1)
|
|
2913 { /* More than one repetition is allowed, so
|
|
2914 append a backward jump to the `succeed_n'
|
|
2915 that starts this interval.
|
|
2916
|
|
2917 When we've reached this during matching,
|
|
2918 we'll have matched the interval once, so
|
|
2919 jump back only `upper_bound - 1' times. */
|
|
2920 STORE_JUMP2 (jump_n, b, laststart + 5,
|
|
2921 upper_bound - 1);
|
|
2922 b += 5;
|
|
2923
|
|
2924 /* The location we want to set is the second
|
|
2925 parameter of the `jump_n'; that is `b-2' as
|
|
2926 an absolute address. `laststart' will be
|
|
2927 the `set_number_at' we're about to insert;
|
|
2928 `laststart+3' the number to set, the source
|
|
2929 for the relative address. But we are
|
|
2930 inserting into the middle of the pattern --
|
|
2931 so everything is getting moved up by 5.
|
|
2932 Conclusion: (b - 2) - (laststart + 3) + 5,
|
|
2933 i.e., b - laststart.
|
|
2934
|
|
2935 We insert this at the beginning of the loop
|
|
2936 so that if we fail during matching, we'll
|
|
2937 reinitialize the bounds. */
|
|
2938 insert_op2 (set_number_at, laststart, b - laststart,
|
|
2939 upper_bound - 1, b);
|
|
2940 b += 5;
|
|
2941 }
|
|
2942 }
|
|
2943 pending_exact = 0;
|
|
2944 beg_interval = NULL;
|
|
2945 }
|
|
2946 break;
|
|
2947
|
|
2948 unfetch_interval:
|
|
2949 /* If an invalid interval, match the characters as literals. */
|
|
2950 assert (beg_interval);
|
|
2951 p = beg_interval;
|
|
2952 beg_interval = NULL;
|
|
2953
|
|
2954 /* normal_char and normal_backslash need `c'. */
|
|
2955 PATFETCH (c);
|
|
2956
|
|
2957 if (!(syntax & RE_NO_BK_BRACES))
|
|
2958 {
|
|
2959 if (p > pattern && p[-1] == '\\')
|
|
2960 goto normal_backslash;
|
|
2961 }
|
|
2962 goto normal_char;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2963
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2964 #ifdef emacs
|
18262
|
2965 /* There is no way to specify the before_dot and after_dot
|
|
2966 operators. rms says this is ok. --karl */
|
|
2967 case '=':
|
|
2968 BUF_PUSH (at_dot);
|
|
2969 break;
|
|
2970
|
|
2971 case 's':
|
|
2972 laststart = b;
|
|
2973 PATFETCH (c);
|
|
2974 BUF_PUSH_2 (syntaxspec, syntax_spec_code[c]);
|
|
2975 break;
|
|
2976
|
|
2977 case 'S':
|
|
2978 laststart = b;
|
|
2979 PATFETCH (c);
|
|
2980 BUF_PUSH_2 (notsyntaxspec, syntax_spec_code[c]);
|
|
2981 break;
|
18260
|
2982
|
|
2983 case 'c':
|
16010
|
2984 laststart = b;
|
18260
|
2985 PATFETCH_RAW (c);
|
|
2986 BUF_PUSH_2 (categoryspec, c);
|
16010
|
2987 break;
|
|
2988
|
18260
|
2989 case 'C':
|
16010
|
2990 laststart = b;
|
18260
|
2991 PATFETCH_RAW (c);
|
|
2992 BUF_PUSH_2 (notcategoryspec, c);
|
16010
|
2993 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2994 #endif /* emacs */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2995
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2996
|
18262
|
2997 case 'w':
|
|
2998 laststart = b;
|
|
2999 BUF_PUSH (wordchar);
|
|
3000 break;
|
|
3001
|
|
3002
|
|
3003 case 'W':
|
|
3004 laststart = b;
|
|
3005 BUF_PUSH (notwordchar);
|
|
3006 break;
|
|
3007
|
|
3008
|
|
3009 case '<':
|
|
3010 BUF_PUSH (wordbeg);
|
|
3011 break;
|
|
3012
|
|
3013 case '>':
|
|
3014 BUF_PUSH (wordend);
|
|
3015 break;
|
|
3016
|
|
3017 case 'b':
|
|
3018 BUF_PUSH (wordbound);
|
|
3019 break;
|
|
3020
|
|
3021 case 'B':
|
|
3022 BUF_PUSH (notwordbound);
|
|
3023 break;
|
|
3024
|
|
3025 case '`':
|
|
3026 BUF_PUSH (begbuf);
|
|
3027 break;
|
|
3028
|
|
3029 case '\'':
|
|
3030 BUF_PUSH (endbuf);
|
|
3031 break;
|
|
3032
|
|
3033 case '1': case '2': case '3': case '4': case '5':
|
|
3034 case '6': case '7': case '8': case '9':
|
|
3035 if (syntax & RE_NO_BK_REFS)
|
|
3036 goto normal_char;
|
|
3037
|
|
3038 c1 = c - '0';
|
|
3039
|
|
3040 if (c1 > regnum)
|
|
3041 FREE_STACK_RETURN (REG_ESUBREG);
|
|
3042
|
|
3043 /* Can't back reference to a subexpression if inside of it. */
|
|
3044 if (group_in_compile_stack (compile_stack, c1))
|
|
3045 goto normal_char;
|
|
3046
|
|
3047 laststart = b;
|
|
3048 BUF_PUSH_2 (duplicate, c1);
|
|
3049 break;
|
|
3050
|
|
3051
|
|
3052 case '+':
|
|
3053 case '?':
|
|
3054 if (syntax & RE_BK_PLUS_QM)
|
|
3055 goto handle_plus;
|
|
3056 else
|
|
3057 goto normal_backslash;
|
|
3058
|
|
3059 default:
|
|
3060 normal_backslash:
|
|
3061 /* You might think it would be useful for \ to mean
|
|
3062 not to translate; but if we don't translate it
|
|
3063 it will never match anything. */
|
|
3064 c = TRANSLATE (c);
|
|
3065 goto normal_char;
|
|
3066 }
|
|
3067 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3068
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3069
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3070 default:
|
18262
|
3071 /* Expects the character in `c'. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3072 normal_char:
|
18260
|
3073 p1 = p - 1; /* P1 points the head of C. */
|
|
3074 #ifdef emacs
|
|
3075 if (bufp->multibyte)
|
23670
|
3076 {
|
|
3077 c = STRING_CHAR (p1, pend - p1);
|
|
3078 c = TRANSLATE (c);
|
|
3079 /* Set P to the next character boundary. */
|
|
3080 p += MULTIBYTE_FORM_LENGTH (p1, pend - p1) - 1;
|
|
3081 }
|
18260
|
3082 #endif
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3083 /* If no exactn currently being built. */
|
18262
|
3084 if (!pending_exact
|
|
3085
|
|
3086 /* If last exactn not at current position. */
|
|
3087 || pending_exact + *pending_exact + 1 != b
|
|
3088
|
|
3089 /* We have only one byte following the exactn for the count. */
|
18260
|
3090 || *pending_exact >= (1 << BYTEWIDTH) - (p - p1)
|
|
3091
|
18262
|
3092 /* If followed by a repetition operator. */
|
21963
|
3093 || (p != pend && (*p == '*' || *p == '^'))
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3094 || ((syntax & RE_BK_PLUS_QM)
|
21963
|
3095 ? p + 1 < pend && *p == '\\' && (p[1] == '+' || p[1] == '?')
|
|
3096 : p != pend && (*p == '+' || *p == '?'))
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3097 || ((syntax & RE_INTERVALS)
|
18262
|
3098 && ((syntax & RE_NO_BK_BRACES)
|
21963
|
3099 ? p != pend && *p == '{'
|
|
3100 : p + 1 < pend && p[0] == '\\' && p[1] == '{')))
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3101 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3102 /* Start building a new exactn. */
|
13565
|
3103
|
18262
|
3104 laststart = b;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3105
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3106 BUF_PUSH_2 (exactn, 0);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3107 pending_exact = b - 1;
|
18262
|
3108 }
|
18260
|
3109
|
23670
|
3110 #ifdef emacs
|
|
3111 if (! SINGLE_BYTE_CHAR_P (c))
|
|
3112 {
|
|
3113 unsigned char work[4], *str;
|
|
3114 int i = CHAR_STRING (c, work, str);
|
|
3115 int j;
|
|
3116 for (j = 0; j < i; j++)
|
|
3117 {
|
|
3118 BUF_PUSH (str[j]);
|
|
3119 (*pending_exact)++;
|
|
3120 }
|
|
3121 }
|
|
3122 else
|
|
3123 #endif
|
18260
|
3124 {
|
21348
|
3125 BUF_PUSH (c);
|
|
3126 (*pending_exact)++;
|
18260
|
3127 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3128 break;
|
18262
|
3129 } /* switch (c) */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3130 } /* while p != pend */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3131
|
13565
|
3132
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3133 /* Through the pattern now. */
|
13565
|
3134
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3135 if (fixup_alt_jump)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3136 STORE_JUMP (jump_past_alt, fixup_alt_jump, b);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3137
|
13565
|
3138 if (!COMPILE_STACK_EMPTY)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3139 FREE_STACK_RETURN (REG_EPAREN);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3140
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3141 /* If we don't want backtracking, force success
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3142 the first time we reach the end of the compiled pattern. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3143 if (syntax & RE_NO_POSIX_BACKTRACKING)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3144 BUF_PUSH (succeed);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3145
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3146 free (compile_stack.stack);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3147
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3148 /* We have succeeded; set the length of the buffer. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3149 bufp->used = b - bufp->buffer;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3150
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3151 #ifdef DEBUG
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3152 if (debug)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3153 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3154 DEBUG_PRINT1 ("\nCompiled pattern: \n");
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3155 print_compiled_pattern (bufp);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3156 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3157 #endif /* DEBUG */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3158
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3159 #ifndef MATCH_MAY_ALLOCATE
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3160 /* Initialize the failure stack to the largest possible stack. This
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3161 isn't necessary unless we're trying to avoid calling alloca in
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3162 the search and match routines. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3163 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3164 int num_regs = bufp->re_nsub + 1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3165
|
20449
|
3166 if (fail_stack.size < re_max_failures * TYPICAL_FAILURE_SIZE)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3167 {
|
21352
|
3168 fail_stack.size = re_max_failures * TYPICAL_FAILURE_SIZE;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3169
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3170 #ifdef emacs
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3171 if (! fail_stack.stack)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3172 fail_stack.stack
|
13565
|
3173 = (fail_stack_elt_t *) xmalloc (fail_stack.size
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3174 * sizeof (fail_stack_elt_t));
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3175 else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3176 fail_stack.stack
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3177 = (fail_stack_elt_t *) xrealloc (fail_stack.stack,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3178 (fail_stack.size
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3179 * sizeof (fail_stack_elt_t)));
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3180 #else /* not emacs */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3181 if (! fail_stack.stack)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3182 fail_stack.stack
|
13565
|
3183 = (fail_stack_elt_t *) malloc (fail_stack.size
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3184 * sizeof (fail_stack_elt_t));
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3185 else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3186 fail_stack.stack
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3187 = (fail_stack_elt_t *) realloc (fail_stack.stack,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3188 (fail_stack.size
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3189 * sizeof (fail_stack_elt_t)));
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3190 #endif /* not emacs */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3191 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3192
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3193 regex_grow_registers (num_regs);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3194 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3195 #endif /* not MATCH_MAY_ALLOCATE */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3196
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3197 return REG_NOERROR;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3198 } /* regex_compile */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3199
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3200 /* Subroutines for `regex_compile'. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3201
|
18262
|
3202 /* Store OP at LOC followed by two-byte integer parameter ARG. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3203
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3204 static void
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3205 store_op1 (op, loc, arg)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3206 re_opcode_t op;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3207 unsigned char *loc;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3208 int arg;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3209 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3210 *loc = (unsigned char) op;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3211 STORE_NUMBER (loc + 1, arg);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3212 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3213
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3214
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3215 /* Like `store_op1', but for two two-byte parameters ARG1 and ARG2. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3216
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3217 static void
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3218 store_op2 (op, loc, arg1, arg2)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3219 re_opcode_t op;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3220 unsigned char *loc;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3221 int arg1, arg2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3222 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3223 *loc = (unsigned char) op;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3224 STORE_NUMBER (loc + 1, arg1);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3225 STORE_NUMBER (loc + 3, arg2);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3226 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3227
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3228
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3229 /* Copy the bytes from LOC to END to open up three bytes of space at LOC
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3230 for OP followed by two-byte integer parameter ARG. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3231
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3232 static void
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3233 insert_op1 (op, loc, arg, end)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3234 re_opcode_t op;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3235 unsigned char *loc;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3236 int arg;
|
13565
|
3237 unsigned char *end;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3238 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3239 register unsigned char *pfrom = end;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3240 register unsigned char *pto = end + 3;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3241
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3242 while (pfrom != loc)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3243 *--pto = *--pfrom;
|
13565
|
3244
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3245 store_op1 (op, loc, arg);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3246 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3247
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3248
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3249 /* Like `insert_op1', but for two two-byte parameters ARG1 and ARG2. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3250
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3251 static void
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3252 insert_op2 (op, loc, arg1, arg2, end)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3253 re_opcode_t op;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3254 unsigned char *loc;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3255 int arg1, arg2;
|
13565
|
3256 unsigned char *end;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3257 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3258 register unsigned char *pfrom = end;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3259 register unsigned char *pto = end + 5;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3260
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3261 while (pfrom != loc)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3262 *--pto = *--pfrom;
|
13565
|
3263
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3264 store_op2 (op, loc, arg1, arg2);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3265 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3266
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3267
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3268 /* P points to just after a ^ in PATTERN. Return true if that ^ comes
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3269 after an alternative or a begin-subexpression. We assume there is at
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3270 least one character before the ^. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3271
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3272 static boolean
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3273 at_begline_loc_p (pattern, p, syntax)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3274 const char *pattern, *p;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3275 reg_syntax_t syntax;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3276 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3277 const char *prev = p - 2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3278 boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\';
|
13565
|
3279
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3280 return
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3281 /* After a subexpression? */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3282 (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash))
|
18262
|
3283 /* After an alternative? */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3284 || (*prev == '|' && (syntax & RE_NO_BK_VBAR || prev_prev_backslash));
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3285 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3286
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3287
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3288 /* The dual of at_begline_loc_p. This one is for $. We assume there is
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3289 at least one character after the $, i.e., `P < PEND'. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3290
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3291 static boolean
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3292 at_endline_loc_p (p, pend, syntax)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3293 const char *p, *pend;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3294 int syntax;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3295 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3296 const char *next = p;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3297 boolean next_backslash = *next == '\\';
|
11974
|
3298 const char *next_next = p + 1 < pend ? p + 1 : 0;
|
13565
|
3299
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3300 return
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3301 /* Before a subexpression? */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3302 (syntax & RE_NO_BK_PARENS ? *next == ')'
|
18262
|
3303 : next_backslash && next_next && *next_next == ')')
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3304 /* Before an alternative? */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3305 || (syntax & RE_NO_BK_VBAR ? *next == '|'
|
18262
|
3306 : next_backslash && next_next && *next_next == '|');
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3307 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3308
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3309
|
13565
|
3310 /* Returns true if REGNUM is in one of COMPILE_STACK's elements and
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3311 false if it's not. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3312
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3313 static boolean
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3314 group_in_compile_stack (compile_stack, regnum)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3315 compile_stack_type compile_stack;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3316 regnum_t regnum;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3317 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3318 int this_element;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3319
|
13565
|
3320 for (this_element = compile_stack.avail - 1;
|
|
3321 this_element >= 0;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3322 this_element--)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3323 if (compile_stack.stack[this_element].regnum == regnum)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3324 return true;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3325
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3326 return false;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3327 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3328
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3329 /* re_compile_fastmap computes a ``fastmap'' for the compiled pattern in
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3330 BUFP. A fastmap records which of the (1 << BYTEWIDTH) possible
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3331 characters can start a string that matches the pattern. This fastmap
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3332 is used by re_search to skip quickly over impossible starting points.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3333
|
25440
|
3334 Character codes above (1 << BYTEWIDTH) are not represented in the
|
|
3335 fastmap, but the leading codes are represented. Thus, the fastmap
|
|
3336 indicates which character sets could start a match.
|
|
3337
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3338 The caller must supply the address of a (1 << BYTEWIDTH)-byte data
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3339 area as BUFP->fastmap.
|
13565
|
3340
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3341 We set the `fastmap', `fastmap_accurate', and `can_be_null' fields in
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3342 the pattern buffer.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3343
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3344 Returns 0 if we succeed, -2 if an internal error. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3345
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3346 int
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3347 re_compile_fastmap (bufp)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3348 struct re_pattern_buffer *bufp;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3349 {
|
18260
|
3350 int i, j, k;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3351 #ifdef MATCH_MAY_ALLOCATE
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3352 fail_stack_type fail_stack;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3353 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3354 #ifndef REGEX_MALLOC
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3355 char *destination;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3356 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3357 /* We don't push any register information onto the failure stack. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3358 unsigned num_regs = 0;
|
13565
|
3359
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3360 register char *fastmap = bufp->fastmap;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3361 unsigned char *pattern = bufp->buffer;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3362 unsigned long size = bufp->used;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3363 unsigned char *p = pattern;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3364 register unsigned char *pend = pattern + size;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3365
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3366 /* This holds the pointer to the failure stack, when
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3367 it is allocated relocatably. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3368 fail_stack_elt_t *failure_stack_ptr;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3369
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3370 /* Assume that each path through the pattern can be null until
|
18262
|
3371 proven otherwise. We set this false at the bottom of switch
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3372 statement, to which we get only if a particular path doesn't
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3373 match the empty string. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3374 boolean path_can_be_null = true;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3375
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3376 /* We aren't doing a `succeed_n' to begin with. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3377 boolean succeed_n_p = false;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3378
|
18260
|
3379 /* If all elements for base leading-codes in fastmap is set, this
|
18262
|
3380 flag is set true. */
|
18260
|
3381 boolean match_any_multibyte_characters = false;
|
|
3382
|
|
3383 /* Maximum code of simple (single byte) character. */
|
|
3384 int simple_char_max;
|
|
3385
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3386 assert (fastmap != NULL && p != NULL);
|
13565
|
3387
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3388 INIT_FAIL_STACK ();
|
18262
|
3389 bzero (fastmap, 1 << BYTEWIDTH); /* Assume nothing's valid. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3390 bufp->fastmap_accurate = 1; /* It will be when we're done. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3391 bufp->can_be_null = 0;
|
13565
|
3392
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3393 while (1)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3394 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3395 if (p == pend || *p == succeed)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3396 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3397 /* We have reached the (effective) end of pattern. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3398 if (!FAIL_STACK_EMPTY ())
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3399 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3400 bufp->can_be_null |= path_can_be_null;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3401
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3402 /* Reset for next path. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3403 path_can_be_null = true;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3404
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3405 p = fail_stack.stack[--fail_stack.avail].pointer;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3406
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3407 continue;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3408 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3409 else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3410 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3411 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3412
|
18262
|
3413 /* We should never be about to go beyond the end of the pattern. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3414 assert (p < pend);
|
13565
|
3415
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3416 switch (SWITCH_ENUM_CAST ((re_opcode_t) *p++))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3417 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3418
|
18262
|
3419 /* I guess the idea here is to simply not bother with a fastmap
|
|
3420 if a backreference is used, since it's too hard to figure out
|
|
3421 the fastmap for the corresponding group. Setting
|
|
3422 `can_be_null' stops `re_search_2' from using the fastmap, so
|
|
3423 that is all we do. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3424 case duplicate:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3425 bufp->can_be_null = 1;
|
18262
|
3426 goto done;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3427
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3428
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3429 /* Following are the cases which match a character. These end
|
18262
|
3430 with `break'. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3431
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3432 case exactn:
|
18262
|
3433 fastmap[p[1]] = 1;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3434 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3435
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3436
|
18260
|
3437 #ifndef emacs
|
18262
|
3438 case charset:
|
25440
|
3439 {
|
|
3440 int length = (*p & 0x7f);;
|
|
3441 p++;
|
|
3442
|
|
3443 for (j = length * BYTEWIDTH - 1; j >= 0; j--)
|
|
3444 if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))
|
|
3445 fastmap[j] = 1;
|
|
3446 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3447 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3448
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3449 case charset_not:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3450 /* Chars beyond end of map must be allowed. */
|
25440
|
3451 {
|
|
3452 int length = (*p & 0x7f);;
|
|
3453 p++;
|
|
3454
|
|
3455 for (j = length * BYTEWIDTH; j < (1 << BYTEWIDTH); j++)
|
18262
|
3456 fastmap[j] = 1;
|
25440
|
3457
|
|
3458 for (j = length * BYTEWIDTH - 1; j >= 0; j--)
|
|
3459 if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))))
|
|
3460 fastmap[j] = 1;
|
|
3461 }
|
18262
|
3462 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3463
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3464 case wordchar:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3465 for (j = 0; j < (1 << BYTEWIDTH); j++)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3466 if (SYNTAX (j) == Sword)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3467 fastmap[j] = 1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3468 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3469
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3470
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3471 case notwordchar:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3472 for (j = 0; j < (1 << BYTEWIDTH); j++)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3473 if (SYNTAX (j) != Sword)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3474 fastmap[j] = 1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3475 break;
|
18260
|
3476 #else /* emacs */
|
|
3477 case charset:
|
|
3478 for (j = CHARSET_BITMAP_SIZE (&p[-1]) * BYTEWIDTH - 1, p++;
|
|
3479 j >= 0; j--)
|
|
3480 if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))
|
|
3481 fastmap[j] = 1;
|
|
3482
|
25877
|
3483 /* If we can match a character class, we can match
|
25440
|
3484 any character set. */
|
|
3485 if (CHARSET_RANGE_TABLE_EXISTS_P (&p[-2])
|
|
3486 && CHARSET_RANGE_TABLE_BITS (&p[-2]) != 0)
|
|
3487 goto set_fastmap_for_multibyte_characters;
|
|
3488
|
18260
|
3489 if (CHARSET_RANGE_TABLE_EXISTS_P (&p[-2])
|
|
3490 && match_any_multibyte_characters == false)
|
|
3491 {
|
|
3492 /* Set fastmap[I] 1 where I is a base leading code of each
|
|
3493 multibyte character in the range table. */
|
|
3494 int c, count;
|
|
3495
|
|
3496 /* Make P points the range table. */
|
|
3497 p += CHARSET_BITMAP_SIZE (&p[-2]);
|
|
3498
|
25877
|
3499 /* Extract the number of ranges in range table into COUNT. */
|
18260
|
3500 EXTRACT_NUMBER_AND_INCR (count, p);
|
|
3501 for (; count > 0; count--, p += 2 * 3) /* XXX */
|
|
3502 {
|
|
3503 /* Extract the start of each range. */
|
|
3504 EXTRACT_CHARACTER (c, p);
|
|
3505 j = CHAR_CHARSET (c);
|
|
3506 fastmap[CHARSET_LEADING_CODE_BASE (j)] = 1;
|
|
3507 }
|
|
3508 }
|
|
3509 break;
|
|
3510
|
|
3511
|
|
3512 case charset_not:
|
23964
|
3513 /* Chars beyond end of bitmap are possible matches.
|
|
3514 All the single-byte codes can occur in multibyte buffers.
|
|
3515 So any that are not listed in the charset
|
|
3516 are possible matches, even in multibyte buffers. */
|
|
3517 simple_char_max = (1 << BYTEWIDTH);
|
18260
|
3518 for (j = CHARSET_BITMAP_SIZE (&p[-1]) * BYTEWIDTH;
|
|
3519 j < simple_char_max; j++)
|
|
3520 fastmap[j] = 1;
|
|
3521
|
|
3522 for (j = CHARSET_BITMAP_SIZE (&p[-1]) * BYTEWIDTH - 1, p++;
|
|
3523 j >= 0; j--)
|
|
3524 if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))))
|
|
3525 fastmap[j] = 1;
|
|
3526
|
|
3527 if (bufp->multibyte)
|
|
3528 /* Any character set can possibly contain a character
|
|
3529 which doesn't match the specified set of characters. */
|
|
3530 {
|
|
3531 set_fastmap_for_multibyte_characters:
|
|
3532 if (match_any_multibyte_characters == false)
|
|
3533 {
|
|
3534 for (j = 0x80; j < 0xA0; j++) /* XXX */
|
|
3535 if (BASE_LEADING_CODE_P (j))
|
|
3536 fastmap[j] = 1;
|
|
3537 match_any_multibyte_characters = true;
|
|
3538 }
|
|
3539 }
|
|
3540 break;
|
|
3541
|
|
3542
|
|
3543 case wordchar:
|
23964
|
3544 /* All the single-byte codes can occur in multibyte buffers,
|
|
3545 and they may have word syntax. So do consider them. */
|
|
3546 simple_char_max = (1 << BYTEWIDTH);
|
18260
|
3547 for (j = 0; j < simple_char_max; j++)
|
|
3548 if (SYNTAX (j) == Sword)
|
|
3549 fastmap[j] = 1;
|
|
3550
|
|
3551 if (bufp->multibyte)
|
|
3552 /* Any character set can possibly contain a character
|
18262
|
3553 whose syntax is `Sword'. */
|
18260
|
3554 goto set_fastmap_for_multibyte_characters;
|
|
3555 break;
|
|
3556
|
|
3557
|
|
3558 case notwordchar:
|
23964
|
3559 /* All the single-byte codes can occur in multibyte buffers,
|
|
3560 and they may not have word syntax. So do consider them. */
|
|
3561 simple_char_max = (1 << BYTEWIDTH);
|
18260
|
3562 for (j = 0; j < simple_char_max; j++)
|
|
3563 if (SYNTAX (j) != Sword)
|
|
3564 fastmap[j] = 1;
|
|
3565
|
|
3566 if (bufp->multibyte)
|
|
3567 /* Any character set can possibly contain a character
|
|
3568 whose syntax is not `Sword'. */
|
|
3569 goto set_fastmap_for_multibyte_characters;
|
|
3570 break;
|
|
3571 #endif
|
|
3572
|
18262
|
3573 case anychar:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3574 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3575 int fastmap_newline = fastmap['\n'];
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3576
|
23846
|
3577 /* `.' matches anything, except perhaps newline.
|
|
3578 Even in a multibyte buffer, it should match any
|
|
3579 conceivable byte value for the fastmap. */
|
18260
|
3580 if (bufp->multibyte)
|
23846
|
3581 match_any_multibyte_characters = true;
|
|
3582
|
|
3583 simple_char_max = (1 << BYTEWIDTH);
|
18260
|
3584 for (j = 0; j < simple_char_max; j++)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3585 fastmap[j] = 1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3586
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3587 /* ... except perhaps newline. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3588 if (!(bufp->syntax & RE_DOT_NEWLINE))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3589 fastmap['\n'] = fastmap_newline;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3590
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3591 /* Return if we have already set `can_be_null'; if we have,
|
18262
|
3592 then the fastmap is irrelevant. Something's wrong here. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3593 else if (bufp->can_be_null)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3594 goto done;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3595
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3596 /* Otherwise, have to check alternative paths. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3597 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3598 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3599
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3600 #ifdef emacs
|
18260
|
3601 case wordbound:
|
|
3602 case notwordbound:
|
|
3603 case wordbeg:
|
|
3604 case wordend:
|
|
3605 case notsyntaxspec:
|
18262
|
3606 case syntaxspec:
|
18260
|
3607 /* This match depends on text properties. These end with
|
|
3608 aborting optimizations. */
|
|
3609 bufp->can_be_null = 1;
|
18262
|
3610 goto done;
|
18260
|
3611 #if 0
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3612 k = *p++;
|
18260
|
3613 simple_char_max = bufp->multibyte ? 0x80 : (1 << BYTEWIDTH);
|
|
3614 for (j = 0; j < simple_char_max; j++)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3615 if (SYNTAX (j) == (enum syntaxcode) k)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3616 fastmap[j] = 1;
|
18260
|
3617
|
|
3618 if (bufp->multibyte)
|
|
3619 /* Any character set can possibly contain a character
|
|
3620 whose syntax is K. */
|
|
3621 goto set_fastmap_for_multibyte_characters;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3622 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3623
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3624 case notsyntaxspec:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3625 k = *p++;
|
18260
|
3626 simple_char_max = bufp->multibyte ? 0x80 : (1 << BYTEWIDTH);
|
|
3627 for (j = 0; j < simple_char_max; j++)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3628 if (SYNTAX (j) != (enum syntaxcode) k)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3629 fastmap[j] = 1;
|
18260
|
3630
|
|
3631 if (bufp->multibyte)
|
|
3632 /* Any character set can possibly contain a character
|
|
3633 whose syntax is not K. */
|
|
3634 goto set_fastmap_for_multibyte_characters;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3635 break;
|
18260
|
3636 #endif
|
|
3637
|
|
3638
|
|
3639 case categoryspec:
|
|
3640 k = *p++;
|
23964
|
3641 simple_char_max = (1 << BYTEWIDTH);
|
18260
|
3642 for (j = 0; j < simple_char_max; j++)
|
|
3643 if (CHAR_HAS_CATEGORY (j, k))
|
|
3644 fastmap[j] = 1;
|
|
3645
|
|
3646 if (bufp->multibyte)
|
|
3647 /* Any character set can possibly contain a character
|
|
3648 whose category is K. */
|
|
3649 goto set_fastmap_for_multibyte_characters;
|
|
3650 break;
|
|
3651
|
|
3652
|
|
3653 case notcategoryspec:
|
|
3654 k = *p++;
|
23964
|
3655 simple_char_max = (1 << BYTEWIDTH);
|
18260
|
3656 for (j = 0; j < simple_char_max; j++)
|
|
3657 if (!CHAR_HAS_CATEGORY (j, k))
|
|
3658 fastmap[j] = 1;
|
|
3659
|
|
3660 if (bufp->multibyte)
|
|
3661 /* Any character set can possibly contain a character
|
18262
|
3662 whose category is not K. */
|
18260
|
3663 goto set_fastmap_for_multibyte_characters;
|
|
3664 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3665
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3666 /* All cases after this match the empty string. These end with
|
18262
|
3667 `continue'. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3668
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3669
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3670 case before_dot:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3671 case at_dot:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3672 case after_dot:
|
18262
|
3673 continue;
|
12983
|
3674 #endif /* emacs */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3675
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3676
|
18262
|
3677 case no_op:
|
|
3678 case begline:
|
|
3679 case endline:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3680 case begbuf:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3681 case endbuf:
|
18260
|
3682 #ifndef emacs
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3683 case wordbound:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3684 case notwordbound:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3685 case wordbeg:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3686 case wordend:
|
18262
|
3687 #endif
|
|
3688 case push_dummy_failure:
|
|
3689 continue;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3690
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3691
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3692 case jump_n:
|
18262
|
3693 case pop_failure_jump:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3694 case maybe_pop_jump:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3695 case jump:
|
18262
|
3696 case jump_past_alt:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3697 case dummy_failure_jump:
|
18262
|
3698 EXTRACT_NUMBER_AND_INCR (j, p);
|
13565
|
3699 p += j;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3700 if (j > 0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3701 continue;
|
13565
|
3702
|
18262
|
3703 /* Jump backward implies we just went through the body of a
|
|
3704 loop and matched nothing. Opcode jumped to should be
|
|
3705 `on_failure_jump' or `succeed_n'. Just treat it like an
|
|
3706 ordinary jump. For a * loop, it has pushed its failure
|
|
3707 point already; if so, discard that as redundant. */
|
|
3708 if ((re_opcode_t) *p != on_failure_jump
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3709 && (re_opcode_t) *p != succeed_n)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3710 continue;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3711
|
18262
|
3712 p++;
|
|
3713 EXTRACT_NUMBER_AND_INCR (j, p);
|
|
3714 p += j;
|
|
3715
|
|
3716 /* If what's on the stack is where we are now, pop it. */
|
|
3717 if (!FAIL_STACK_EMPTY ()
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3718 && fail_stack.stack[fail_stack.avail - 1].pointer == p)
|
18262
|
3719 fail_stack.avail--;
|
|
3720
|
|
3721 continue;
|
|
3722
|
|
3723
|
|
3724 case on_failure_jump:
|
|
3725 case on_failure_keep_string_jump:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3726 handle_on_failure_jump:
|
18262
|
3727 EXTRACT_NUMBER_AND_INCR (j, p);
|
|
3728
|
|
3729 /* For some patterns, e.g., `(a?)?', `p+j' here points to the
|
|
3730 end of the pattern. We don't want to push such a point,
|
|
3731 since when we restore it above, entering the switch will
|
|
3732 increment `p' past the end of the pattern. We don't need
|
|
3733 to push such a point since we obviously won't find any more
|
|
3734 fastmap entries beyond `pend'. Such a pattern can match
|
|
3735 the null string, though. */
|
|
3736 if (p + j < pend)
|
|
3737 {
|
|
3738 if (!PUSH_PATTERN_OP (p + j, fail_stack))
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3739 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3740 RESET_FAIL_STACK ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3741 return -2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3742 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3743 }
|
18262
|
3744 else
|
|
3745 bufp->can_be_null = 1;
|
|
3746
|
|
3747 if (succeed_n_p)
|
|
3748 {
|
|
3749 EXTRACT_NUMBER_AND_INCR (k, p); /* Skip the n. */
|
|
3750 succeed_n_p = false;
|
|
3751 }
|
|
3752
|
|
3753 continue;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3754
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3755
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3756 case succeed_n:
|
18262
|
3757 /* Get to the number of times to succeed. */
|
|
3758 p += 2;
|
|
3759
|
|
3760 /* Increment p past the n for when k != 0. */
|
|
3761 EXTRACT_NUMBER_AND_INCR (k, p);
|
|
3762 if (k == 0)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3763 {
|
18262
|
3764 p -= 4;
|
|
3765 succeed_n_p = true; /* Spaghetti code alert. */
|
|
3766 goto handle_on_failure_jump;
|
|
3767 }
|
|
3768 continue;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3769
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3770
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3771 case set_number_at:
|
18262
|
3772 p += 4;
|
|
3773 continue;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3774
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3775
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3776 case start_memory:
|
18262
|
3777 case stop_memory:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3778 p += 2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3779 continue;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3780
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3781
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3782 default:
|
18262
|
3783 abort (); /* We have listed all the cases. */
|
|
3784 } /* switch *p++ */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3785
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3786 /* Getting here means we have found the possible starting
|
18262
|
3787 characters for one path of the pattern -- and that the empty
|
|
3788 string does not match. We need not follow this path further.
|
|
3789 Instead, look at the next alternative (remembered on the
|
|
3790 stack), or quit if no more. The test at the top of the loop
|
|
3791 does these things. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3792 path_can_be_null = false;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3793 p = pend;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3794 } /* while p */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3795
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3796 /* Set `can_be_null' for the last path (also the first path, if the
|
18262
|
3797 pattern is empty). */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3798 bufp->can_be_null |= path_can_be_null;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3799
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3800 done:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3801 RESET_FAIL_STACK ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3802 return 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3803 } /* re_compile_fastmap */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3804
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3805 /* Set REGS to hold NUM_REGS registers, storing them in STARTS and
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3806 ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3807 this memory for recording register information. STARTS and ENDS
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3808 must be allocated using the malloc library routine, and must each
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3809 be at least NUM_REGS * sizeof (regoff_t) bytes long.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3810
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3811 If NUM_REGS == 0, then subsequent matches should allocate their own
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3812 register data.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3813
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3814 Unless this function is called, the first search or match using
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3815 PATTERN_BUFFER will allocate its own register data, without
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3816 freeing the old data. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3817
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3818 void
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3819 re_set_registers (bufp, regs, num_regs, starts, ends)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3820 struct re_pattern_buffer *bufp;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3821 struct re_registers *regs;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3822 unsigned num_regs;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3823 regoff_t *starts, *ends;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3824 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3825 if (num_regs)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3826 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3827 bufp->regs_allocated = REGS_REALLOCATE;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3828 regs->num_regs = num_regs;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3829 regs->start = starts;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3830 regs->end = ends;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3831 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3832 else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3833 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3834 bufp->regs_allocated = REGS_UNALLOCATED;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3835 regs->num_regs = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3836 regs->start = regs->end = (regoff_t *) 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3837 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3838 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3839
|
18262
|
3840 /* Searching routines. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3841
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3842 /* Like re_search_2, below, but only one string is specified, and
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3843 doesn't let you say where to stop matching. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3844
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3845 int
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3846 re_search (bufp, string, size, startpos, range, regs)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3847 struct re_pattern_buffer *bufp;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3848 const char *string;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3849 int size, startpos, range;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3850 struct re_registers *regs;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3851 {
|
13565
|
3852 return re_search_2 (bufp, NULL, 0, string, size, startpos, range,
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3853 regs, size);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3854 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3855
|
18260
|
3856 /* End address of virtual concatenation of string. */
|
|
3857 #define STOP_ADDR_VSTRING(P) \
|
|
3858 (((P) >= size1 ? string2 + size2 : string1 + size1))
|
|
3859
|
|
3860 /* Address of POS in the concatenation of virtual string. */
|
|
3861 #define POS_ADDR_VSTRING(POS) \
|
|
3862 (((POS) >= size1 ? string2 - size1 : string1) + (POS))
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3863
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3864 /* Using the compiled pattern in BUFP->buffer, first tries to match the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3865 virtual concatenation of STRING1 and STRING2, starting first at index
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3866 STARTPOS, then at STARTPOS + 1, and so on.
|
13565
|
3867
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3868 STRING1 and STRING2 have length SIZE1 and SIZE2, respectively.
|
13565
|
3869
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3870 RANGE is how far to scan while trying to match. RANGE = 0 means try
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3871 only at STARTPOS; in general, the last start tried is STARTPOS +
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3872 RANGE.
|
13565
|
3873
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3874 In REGS, return the indices of the virtual concatenation of STRING1
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3875 and STRING2 that matched the entire BUFP->buffer and its contained
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3876 subexpressions.
|
13565
|
3877
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3878 Do not consider matching one past the index STOP in the virtual
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3879 concatenation of STRING1 and STRING2.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3880
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3881 We return either the position in the strings at which the match was
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3882 found, -1 if no match, or -2 if error (such as failure
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3883 stack overflow). */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3884
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3885 int
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3886 re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3887 struct re_pattern_buffer *bufp;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3888 const char *string1, *string2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3889 int size1, size2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3890 int startpos;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3891 int range;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3892 struct re_registers *regs;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3893 int stop;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3894 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3895 int val;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3896 register char *fastmap = bufp->fastmap;
|
13250
|
3897 register RE_TRANSLATE_TYPE translate = bufp->translate;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3898 int total_size = size1 + size2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3899 int endpos = startpos + range;
|
16009
|
3900 int anchored_start = 0;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3901
|
18262
|
3902 /* Nonzero if we have to concern multibyte character. */
|
18260
|
3903 int multibyte = bufp->multibyte;
|
|
3904
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3905 /* Check for out-of-range STARTPOS. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3906 if (startpos < 0 || startpos > total_size)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3907 return -1;
|
13565
|
3908
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3909 /* Fix up RANGE if it might eventually take us outside
|
13100
|
3910 the virtual concatenation of STRING1 and STRING2.
|
13565
|
3911 Make sure we won't move STARTPOS below 0 or above TOTAL_SIZE. */
|
13100
|
3912 if (endpos < 0)
|
|
3913 range = 0 - startpos;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3914 else if (endpos > total_size)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3915 range = total_size - startpos;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3916
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3917 /* If the search isn't to be a backwards one, don't waste time in a
|
21760
|
3918 search for a pattern anchored at beginning of buffer. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3919 if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == begbuf && range > 0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3920 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3921 if (startpos > 0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3922 return -1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3923 else
|
21760
|
3924 range = 0;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3925 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3926
|
12983
|
3927 #ifdef emacs
|
|
3928 /* In a forward search for something that starts with \=.
|
|
3929 don't keep searching past point. */
|
|
3930 if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == at_dot && range > 0)
|
|
3931 {
|
21760
|
3932 range = PT_BYTE - BEGV_BYTE - startpos;
|
|
3933 if (range < 0)
|
12983
|
3934 return -1;
|
|
3935 }
|
|
3936 #endif /* emacs */
|
|
3937
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3938 /* Update the fastmap now if not correct already. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3939 if (fastmap && !bufp->fastmap_accurate)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3940 if (re_compile_fastmap (bufp) == -2)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3941 return -2;
|
13565
|
3942
|
16009
|
3943 /* See whether the pattern is anchored. */
|
|
3944 if (bufp->buffer[0] == begline)
|
|
3945 anchored_start = 1;
|
|
3946
|
18260
|
3947 #ifdef emacs
|
21482
|
3948 gl_state.object = re_match_object;
|
|
3949 {
|
22372
|
3950 int adjpos = NILP (re_match_object) || BUFFERP (re_match_object);
|
|
3951 int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (startpos + adjpos);
|
21482
|
3952
|
|
3953 SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, charpos, 1);
|
|
3954 }
|
18260
|
3955 #endif
|
|
3956
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3957 /* Loop through the string, looking for a place to start matching. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3958 for (;;)
|
13565
|
3959 {
|
16009
|
3960 /* If the pattern is anchored,
|
|
3961 skip quickly past places we cannot match.
|
|
3962 We don't bother to treat startpos == 0 specially
|
|
3963 because that case doesn't repeat. */
|
|
3964 if (anchored_start && startpos > 0)
|
|
3965 {
|
|
3966 if (! (bufp->newline_anchor
|
|
3967 && ((startpos <= size1 ? string1[startpos - 1]
|
|
3968 : string2[startpos - size1 - 1])
|
|
3969 == '\n')))
|
|
3970 goto advance;
|
|
3971 }
|
|
3972
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3973 /* If a fastmap is supplied, skip quickly over characters that
|
18262
|
3974 cannot be the start of a match. If the pattern can match the
|
|
3975 null string, however, we don't need to skip characters; we want
|
|
3976 the first null string. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3977 if (fastmap && startpos < total_size && !bufp->can_be_null)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3978 {
|
21348
|
3979 register const char *d;
|
|
3980 register unsigned int buf_ch;
|
|
3981
|
|
3982 d = POS_ADDR_VSTRING (startpos);
|
|
3983
|
18262
|
3984 if (range > 0) /* Searching forwards. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3985 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3986 register int lim = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3987 int irange = range;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
3988
|
18262
|
3989 if (startpos < size1 && startpos + range >= size1)
|
|
3990 lim = range - (size1 - startpos);
|
18260
|
3991
|
18262
|
3992 /* Written out as an if-else to avoid testing `translate'
|
|
3993 inside the loop. */
|
21838
|
3994 if (RE_TRANSLATE_P (translate))
|
|
3995 {
|
21348
|
3996 if (multibyte)
|
|
3997 while (range > lim)
|
|
3998 {
|
|
3999 int buf_charlen;
|
|
4000
|
|
4001 buf_ch = STRING_CHAR_AND_LENGTH (d, range - lim,
|
|
4002 buf_charlen);
|
|
4003
|
|
4004 buf_ch = RE_TRANSLATE (translate, buf_ch);
|
|
4005 if (buf_ch >= 0400
|
|
4006 || fastmap[buf_ch])
|
|
4007 break;
|
|
4008
|
|
4009 range -= buf_charlen;
|
|
4010 d += buf_charlen;
|
|
4011 }
|
|
4012 else
|
|
4013 while (range > lim
|
|
4014 && !fastmap[(unsigned char)
|
22237
|
4015 RE_TRANSLATE (translate, (unsigned char) *d)])
|
|
4016 {
|
|
4017 d++;
|
|
4018 range--;
|
|
4019 }
|
21348
|
4020 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4021 else
|
22237
|
4022 while (range > lim && !fastmap[(unsigned char) *d])
|
|
4023 {
|
|
4024 d++;
|
|
4025 range--;
|
|
4026 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4027
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4028 startpos += irange - range;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4029 }
|
18262
|
4030 else /* Searching backwards. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4031 {
|
21348
|
4032 int room = (size1 == 0 || startpos >= size1
|
|
4033 ? size2 + size1 - startpos
|
|
4034 : size1 - startpos);
|
|
4035
|
|
4036 buf_ch = STRING_CHAR (d, room);
|
21562
|
4037 if (RE_TRANSLATE_P (translate))
|
21348
|
4038 buf_ch = RE_TRANSLATE (translate, buf_ch);
|
|
4039
|
|
4040 if (! (buf_ch >= 0400
|
|
4041 || fastmap[buf_ch]))
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4042 goto advance;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4043 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4044 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4045
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4046 /* If can't match the null string, and that's all we have left, fail. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4047 if (range >= 0 && startpos == total_size && fastmap
|
18262
|
4048 && !bufp->can_be_null)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4049 return -1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4050
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4051 val = re_match_2_internal (bufp, string1, size1, string2, size2,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4052 startpos, regs, stop);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4053 #ifndef REGEX_MALLOC
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4054 #ifdef C_ALLOCA
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4055 alloca (0);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4056 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4057 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4058
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4059 if (val >= 0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4060 return startpos;
|
13565
|
4061
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4062 if (val == -2)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4063 return -2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4064
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4065 advance:
|
13565
|
4066 if (!range)
|
18262
|
4067 break;
|
13565
|
4068 else if (range > 0)
|
18262
|
4069 {
|
18260
|
4070 /* Update STARTPOS to the next character boundary. */
|
|
4071 if (multibyte)
|
|
4072 {
|
18532
|
4073 const unsigned char *p
|
|
4074 = (const unsigned char *) POS_ADDR_VSTRING (startpos);
|
|
4075 const unsigned char *pend
|
|
4076 = (const unsigned char *) STOP_ADDR_VSTRING (startpos);
|
18260
|
4077 int len = MULTIBYTE_FORM_LENGTH (p, pend - p);
|
|
4078
|
|
4079 range -= len;
|
|
4080 if (range < 0)
|
|
4081 break;
|
|
4082 startpos += len;
|
|
4083 }
|
|
4084 else
|
|
4085 {
|
18532
|
4086 range--;
|
|
4087 startpos++;
|
|
4088 }
|
16010
|
4089 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4090 else
|
18262
|
4091 {
|
|
4092 range++;
|
|
4093 startpos--;
|
18260
|
4094
|
|
4095 /* Update STARTPOS to the previous character boundary. */
|
|
4096 if (multibyte)
|
|
4097 {
|
18532
|
4098 const unsigned char *p
|
|
4099 = (const unsigned char *) POS_ADDR_VSTRING (startpos);
|
18260
|
4100 int len = 0;
|
|
4101
|
|
4102 /* Find the head of multibyte form. */
|
20633
|
4103 while (!CHAR_HEAD_P (*p))
|
18260
|
4104 p--, len++;
|
|
4105
|
|
4106 /* Adjust it. */
|
|
4107 #if 0 /* XXX */
|
|
4108 if (MULTIBYTE_FORM_LENGTH (p, len + 1) != (len + 1))
|
|
4109 ;
|
|
4110 else
|
|
4111 #endif
|
|
4112 {
|
|
4113 range += len;
|
|
4114 if (range > 0)
|
|
4115 break;
|
|
4116
|
|
4117 startpos -= len;
|
|
4118 }
|
|
4119 }
|
18262
|
4120 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4121 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4122 return -1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4123 } /* re_search_2 */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4124
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4125 /* Declarations and macros for re_match_2. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4126
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4127 static int bcmp_translate ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4128 static boolean alt_match_null_string_p (),
|
18262
|
4129 common_op_match_null_string_p (),
|
|
4130 group_match_null_string_p ();
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4131
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4132 /* This converts PTR, a pointer into one of the search strings `string1'
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4133 and `string2' into an offset from the beginning of that string. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4134 #define POINTER_TO_OFFSET(ptr) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4135 (FIRST_STRING_P (ptr) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4136 ? ((regoff_t) ((ptr) - string1)) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4137 : ((regoff_t) ((ptr) - string2 + size1)))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4138
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4139 /* Macros for dealing with the split strings in re_match_2. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4140
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4141 #define MATCHING_IN_FIRST_STRING (dend == end_match_1)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4142
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4143 /* Call before fetching a character with *d. This switches over to
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4144 string2 if necessary. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4145 #define PREFETCH() \
|
18262
|
4146 while (d == dend) \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4147 { \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4148 /* End of string2 => fail. */ \
|
18262
|
4149 if (dend == end_match_2) \
|
|
4150 goto fail; \
|
|
4151 /* End of string1 => advance to string2. */ \
|
|
4152 d = string2; \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4153 dend = end_match_2; \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4154 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4155
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4156
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4157 /* Test if at very beginning or at very end of the virtual concatenation
|
18262
|
4158 of `string1' and `string2'. If only one string, it's `string2'. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4159 #define AT_STRINGS_BEG(d) ((d) == (size1 ? string1 : string2) || !size2)
|
13565
|
4160 #define AT_STRINGS_END(d) ((d) == end2)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4161
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4162
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4163 /* Test if D points to a character which is word-constituent. We have
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4164 two special cases to check for: if past the end of string1, look at
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4165 the first character in string2; and if before the beginning of
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4166 string2, look at the last character in string1. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4167 #define WORDCHAR_P(d) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4168 (SYNTAX ((d) == end1 ? *string2 \
|
18262
|
4169 : (d) == string2 - 1 ? *(end1 - 1) : *(d)) \
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4170 == Sword)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4171
|
13722
|
4172 /* Disabled due to a compiler bug -- see comment at case wordbound */
|
18260
|
4173
|
|
4174 /* The comment at case wordbound is following one, but we don't use
|
|
4175 AT_WORD_BOUNDARY anymore to support multibyte form.
|
|
4176
|
|
4177 The DEC Alpha C compiler 3.x generates incorrect code for the
|
18262
|
4178 test WORDCHAR_P (d - 1) != WORDCHAR_P (d) in the expansion of
|
|
4179 AT_WORD_BOUNDARY, so this code is disabled. Expanding the
|
18260
|
4180 macro and introducing temporary variables works around the bug. */
|
|
4181
|
13722
|
4182 #if 0
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4183 /* Test if the character before D and the one at D differ with respect
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4184 to being word-constituent. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4185 #define AT_WORD_BOUNDARY(d) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4186 (AT_STRINGS_BEG (d) || AT_STRINGS_END (d) \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4187 || WORDCHAR_P (d - 1) != WORDCHAR_P (d))
|
13722
|
4188 #endif
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4189
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4190 /* Free everything we malloc. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4191 #ifdef MATCH_MAY_ALLOCATE
|
18263
|
4192 #define FREE_VAR(var) if (var) { REGEX_FREE (var); var = NULL; } else
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4193 #define FREE_VARIABLES() \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4194 do { \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4195 REGEX_FREE_STACK (fail_stack.stack); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4196 FREE_VAR (regstart); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4197 FREE_VAR (regend); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4198 FREE_VAR (old_regstart); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4199 FREE_VAR (old_regend); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4200 FREE_VAR (best_regstart); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4201 FREE_VAR (best_regend); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4202 FREE_VAR (reg_info); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4203 FREE_VAR (reg_dummy); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4204 FREE_VAR (reg_info_dummy); \
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4205 } while (0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4206 #else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4207 #define FREE_VARIABLES() ((void)0) /* Do nothing! But inhibit gcc warning. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4208 #endif /* not MATCH_MAY_ALLOCATE */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4209
|
18262
|
4210 /* These values must meet several constraints. They must not be valid
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4211 register values; since we have a limit of 255 registers (because
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4212 we use only one byte in the pattern for the register number), we can
|
18262
|
4213 use numbers larger than 255. They must differ by 1, because of
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4214 NUM_FAILURE_ITEMS above. And the value for the lowest register must
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4215 be larger than the value for the highest register, so we do not try
|
18262
|
4216 to actually save any registers when none are active. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4217 #define NO_HIGHEST_ACTIVE_REG (1 << BYTEWIDTH)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4218 #define NO_LOWEST_ACTIVE_REG (NO_HIGHEST_ACTIVE_REG + 1)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4219
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4220 /* Matching routines. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4221
|
18262
|
4222 #ifndef emacs /* Emacs never uses this. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4223 /* re_match is like re_match_2 except it takes only a single string. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4224
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4225 int
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4226 re_match (bufp, string, size, pos, regs)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4227 struct re_pattern_buffer *bufp;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4228 const char *string;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4229 int size, pos;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4230 struct re_registers *regs;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4231 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4232 int result = re_match_2_internal (bufp, NULL, 0, string, size,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4233 pos, regs, size);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4234 alloca (0);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4235 return result;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4236 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4237 #endif /* not emacs */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4238
|
18260
|
4239 #ifdef emacs
|
|
4240 /* In Emacs, this is the string or buffer in which we
|
18262
|
4241 are matching. It is used for looking up syntax properties. */
|
18260
|
4242 Lisp_Object re_match_object;
|
|
4243 #endif
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4244
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4245 /* re_match_2 matches the compiled pattern in BUFP against the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4246 the (virtual) concatenation of STRING1 and STRING2 (of length SIZE1
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4247 and SIZE2, respectively). We start matching at POS, and stop
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4248 matching at STOP.
|
13565
|
4249
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4250 If REGS is non-null and the `no_sub' field of BUFP is nonzero, we
|
18262
|
4251 store offsets for the substring each group matched in REGS. See the
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4252 documentation for exactly how many groups we fill.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4253
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4254 We return -1 if no match, -2 if an internal error (such as the
|
18262
|
4255 failure stack overflowing). Otherwise, we return the length of the
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4256 matched substring. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4257
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4258 int
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4259 re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4260 struct re_pattern_buffer *bufp;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4261 const char *string1, *string2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4262 int size1, size2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4263 int pos;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4264 struct re_registers *regs;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4265 int stop;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4266 {
|
18260
|
4267 int result;
|
18262
|
4268
|
18260
|
4269 #ifdef emacs
|
21482
|
4270 int charpos;
|
22372
|
4271 int adjpos = NILP (re_match_object) || BUFFERP (re_match_object);
|
21482
|
4272 gl_state.object = re_match_object;
|
22372
|
4273 charpos = SYNTAX_TABLE_BYTE_TO_CHAR (pos + adjpos);
|
21482
|
4274 SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, charpos, 1);
|
18260
|
4275 #endif
|
|
4276
|
|
4277 result = re_match_2_internal (bufp, string1, size1, string2, size2,
|
21482
|
4278 pos, regs, stop);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4279 alloca (0);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4280 return result;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4281 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4282
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4283 /* This is a separate function so that we can force an alloca cleanup
|
18262
|
4284 afterwards. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4285 static int
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4286 re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4287 struct re_pattern_buffer *bufp;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4288 const char *string1, *string2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4289 int size1, size2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4290 int pos;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4291 struct re_registers *regs;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4292 int stop;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4293 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4294 /* General temporaries. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4295 int mcnt;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4296 unsigned char *p1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4297
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4298 /* Just past the end of the corresponding string. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4299 const char *end1, *end2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4300
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4301 /* Pointers into string1 and string2, just past the last characters in
|
18262
|
4302 each to consider matching. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4303 const char *end_match_1, *end_match_2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4304
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4305 /* Where we are in the data, and the end of the current string. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4306 const char *d, *dend;
|
13565
|
4307
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4308 /* Where we are in the pattern, and the end of the pattern. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4309 unsigned char *p = bufp->buffer;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4310 register unsigned char *pend = p + bufp->used;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4311
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4312 /* Mark the opcode just after a start_memory, so we can test for an
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4313 empty subpattern when we get to the stop_memory. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4314 unsigned char *just_past_start_mem = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4315
|
18262
|
4316 /* We use this to map every character in the string. */
|
13250
|
4317 RE_TRANSLATE_TYPE translate = bufp->translate;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4318
|
18262
|
4319 /* Nonzero if we have to concern multibyte character. */
|
18260
|
4320 int multibyte = bufp->multibyte;
|
|
4321
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4322 /* Failure point stack. Each place that can handle a failure further
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4323 down the line pushes a failure point on this stack. It consists of
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4324 restart, regend, and reg_info for all registers corresponding to
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4325 the subexpressions we're currently inside, plus the number of such
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4326 registers, and, finally, two char *'s. The first char * is where
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4327 to resume scanning the pattern; the second one is where to resume
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4328 scanning the strings. If the latter is zero, the failure point is
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4329 a ``dummy''; if a failure happens and the failure point is a dummy,
|
18262
|
4330 it gets discarded and the next next one is tried. */
|
|
4331 #ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4332 fail_stack_type fail_stack;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4333 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4334 #ifdef DEBUG
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4335 static unsigned failure_id = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4336 unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4337 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4338
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4339 /* This holds the pointer to the failure stack, when
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4340 it is allocated relocatably. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4341 fail_stack_elt_t *failure_stack_ptr;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4342
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4343 /* We fill all the registers internally, independent of what we
|
18262
|
4344 return, for use in backreferences. The number here includes
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4345 an element for register zero. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4346 unsigned num_regs = bufp->re_nsub + 1;
|
13565
|
4347
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4348 /* The currently active registers. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4349 unsigned lowest_active_reg = NO_LOWEST_ACTIVE_REG;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4350 unsigned highest_active_reg = NO_HIGHEST_ACTIVE_REG;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4351
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4352 /* Information on the contents of registers. These are pointers into
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4353 the input strings; they record just what was matched (on this
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4354 attempt) by a subexpression part of the pattern, that is, the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4355 regnum-th regstart pointer points to where in the pattern we began
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4356 matching and the regnum-th regend points to right after where we
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4357 stopped matching the regnum-th subexpression. (The zeroth register
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4358 keeps track of what the whole pattern matches.) */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4359 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4360 const char **regstart, **regend;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4361 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4362
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4363 /* If a group that's operated upon by a repetition operator fails to
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4364 match anything, then the register for its start will need to be
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4365 restored because it will have been set to wherever in the string we
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4366 are when we last see its open-group operator. Similarly for a
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4367 register's end. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4368 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4369 const char **old_regstart, **old_regend;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4370 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4371
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4372 /* The is_active field of reg_info helps us keep track of which (possibly
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4373 nested) subexpressions we are currently in. The matched_something
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4374 field of reg_info[reg_num] helps us tell whether or not we have
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4375 matched any of the pattern so far this time through the reg_num-th
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4376 subexpression. These two fields get reset each time through any
|
18262
|
4377 loop their register is in. */
|
|
4378 #ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */
|
13565
|
4379 register_info_type *reg_info;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4380 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4381
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4382 /* The following record the register info as found in the above
|
13565
|
4383 variables when we find a match better than any we've seen before.
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4384 This happens as we backtrack through the failure points, which in
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4385 turn happens only if we have not yet matched the entire string. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4386 unsigned best_regs_set = false;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4387 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4388 const char **best_regstart, **best_regend;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4389 #endif
|
13565
|
4390
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4391 /* Logically, this is `best_regend[0]'. But we don't want to have to
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4392 allocate space for that if we're not allocating space for anything
|
18262
|
4393 else (see below). Also, we never need info about register 0 for
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4394 any of the other register vectors, and it seems rather a kludge to
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4395 treat `best_regend' differently than the rest. So we keep track of
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4396 the end of the best match so far in a separate variable. We
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4397 initialize this to NULL so that when we backtrack the first time
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4398 and need to test it, it's not garbage. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4399 const char *match_end = NULL;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4400
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4401 /* This helps SET_REGS_MATCHED avoid doing redundant work. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4402 int set_regs_matched_done = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4403
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4404 /* Used when we pop values we don't care about. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4405 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4406 const char **reg_dummy;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4407 register_info_type *reg_info_dummy;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4408 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4409
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4410 #ifdef DEBUG
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4411 /* Counts the total number of registers pushed. */
|
13565
|
4412 unsigned num_regs_pushed = 0;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4413 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4414
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4415 DEBUG_PRINT1 ("\n\nEntering re_match_2.\n");
|
13565
|
4416
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4417 INIT_FAIL_STACK ();
|
13565
|
4418
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4419 #ifdef MATCH_MAY_ALLOCATE
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4420 /* Do not bother to initialize all the register variables if there are
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4421 no groups in the pattern, as it takes a fair amount of time. If
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4422 there are groups, we include space for register 0 (the whole
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4423 pattern), even though we never use it, since it simplifies the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4424 array indexing. We should fix this. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4425 if (bufp->re_nsub)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4426 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4427 regstart = REGEX_TALLOC (num_regs, const char *);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4428 regend = REGEX_TALLOC (num_regs, const char *);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4429 old_regstart = REGEX_TALLOC (num_regs, const char *);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4430 old_regend = REGEX_TALLOC (num_regs, const char *);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4431 best_regstart = REGEX_TALLOC (num_regs, const char *);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4432 best_regend = REGEX_TALLOC (num_regs, const char *);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4433 reg_info = REGEX_TALLOC (num_regs, register_info_type);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4434 reg_dummy = REGEX_TALLOC (num_regs, const char *);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4435 reg_info_dummy = REGEX_TALLOC (num_regs, register_info_type);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4436
|
13565
|
4437 if (!(regstart && regend && old_regstart && old_regend && reg_info
|
18262
|
4438 && best_regstart && best_regend && reg_dummy && reg_info_dummy))
|
|
4439 {
|
|
4440 FREE_VARIABLES ();
|
|
4441 return -2;
|
|
4442 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4443 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4444 else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4445 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4446 /* We must initialize all our variables to NULL, so that
|
18262
|
4447 `FREE_VARIABLES' doesn't try to free them. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4448 regstart = regend = old_regstart = old_regend = best_regstart
|
18262
|
4449 = best_regend = reg_dummy = NULL;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4450 reg_info = reg_info_dummy = (register_info_type *) NULL;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4451 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4452 #endif /* MATCH_MAY_ALLOCATE */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4453
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4454 /* The starting position is bogus. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4455 if (pos < 0 || pos > size1 + size2)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4456 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4457 FREE_VARIABLES ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4458 return -1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4459 }
|
13565
|
4460
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4461 /* Initialize subexpression text positions to -1 to mark ones that no
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4462 start_memory/stop_memory has been seen for. Also initialize the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4463 register information struct. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4464 for (mcnt = 1; mcnt < num_regs; mcnt++)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4465 {
|
13565
|
4466 regstart[mcnt] = regend[mcnt]
|
18262
|
4467 = old_regstart[mcnt] = old_regend[mcnt] = REG_UNSET_VALUE;
|
13565
|
4468
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4469 REG_MATCH_NULL_STRING_P (reg_info[mcnt]) = MATCH_NULL_UNSET_VALUE;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4470 IS_ACTIVE (reg_info[mcnt]) = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4471 MATCHED_SOMETHING (reg_info[mcnt]) = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4472 EVER_MATCHED_SOMETHING (reg_info[mcnt]) = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4473 }
|
13565
|
4474
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4475 /* We move `string1' into `string2' if the latter's empty -- but not if
|
18262
|
4476 `string1' is null. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4477 if (size2 == 0 && string1 != NULL)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4478 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4479 string2 = string1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4480 size2 = size1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4481 string1 = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4482 size1 = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4483 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4484 end1 = string1 + size1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4485 end2 = string2 + size2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4486
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4487 /* Compute where to stop matching, within the two strings. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4488 if (stop <= size1)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4489 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4490 end_match_1 = string1 + stop;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4491 end_match_2 = string2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4492 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4493 else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4494 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4495 end_match_1 = end1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4496 end_match_2 = string2 + stop - size1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4497 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4498
|
13565
|
4499 /* `p' scans through the pattern as `d' scans through the data.
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4500 `dend' is the end of the input string that `d' points within. `d'
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4501 is advanced into the following input string whenever necessary, but
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4502 this happens before fetching; therefore, at the beginning of the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4503 loop, `d' can be pointing at the end of a string, but it cannot
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4504 equal `string2'. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4505 if (size1 > 0 && pos <= size1)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4506 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4507 d = string1 + pos;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4508 dend = end_match_1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4509 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4510 else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4511 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4512 d = string2 + pos - size1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4513 dend = end_match_2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4514 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4515
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4516 DEBUG_PRINT1 ("The compiled pattern is: ");
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4517 DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4518 DEBUG_PRINT1 ("The string to match is: `");
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4519 DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4520 DEBUG_PRINT1 ("'\n");
|
13565
|
4521
|
18262
|
4522 /* This loops over pattern commands. It exits by returning from the
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4523 function if the match is complete, or it drops through if the match
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4524 fails at this starting point in the input data. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4525 for (;;)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4526 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4527 DEBUG_PRINT2 ("\n0x%x: ", p);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4528
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4529 if (p == pend)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4530 { /* End of pattern means we might have succeeded. */
|
18262
|
4531 DEBUG_PRINT1 ("end of pattern ... ");
|
13565
|
4532
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4533 /* If we haven't matched the entire string, and we want the
|
18262
|
4534 longest match, try backtracking. */
|
|
4535 if (d != end_match_2)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4536 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4537 /* 1 if this match ends in the same string (string1 or string2)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4538 as the best previous match. */
|
13565
|
4539 boolean same_str_p = (FIRST_STRING_P (match_end)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4540 == MATCHING_IN_FIRST_STRING);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4541 /* 1 if this match is the best seen so far. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4542 boolean best_match_p;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4543
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4544 /* AIX compiler got confused when this was combined
|
18262
|
4545 with the previous declaration. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4546 if (same_str_p)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4547 best_match_p = d > match_end;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4548 else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4549 best_match_p = !MATCHING_IN_FIRST_STRING;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4550
|
18262
|
4551 DEBUG_PRINT1 ("backtracking.\n");
|
|
4552
|
|
4553 if (!FAIL_STACK_EMPTY ())
|
|
4554 { /* More failure points to try. */
|
|
4555
|
|
4556 /* If exceeds best match so far, save it. */
|
|
4557 if (!best_regs_set || best_match_p)
|
|
4558 {
|
|
4559 best_regs_set = true;
|
|
4560 match_end = d;
|
|
4561
|
|
4562 DEBUG_PRINT1 ("\nSAVING match as best so far.\n");
|
|
4563
|
|
4564 for (mcnt = 1; mcnt < num_regs; mcnt++)
|
|
4565 {
|
|
4566 best_regstart[mcnt] = regstart[mcnt];
|
|
4567 best_regend[mcnt] = regend[mcnt];
|
|
4568 }
|
|
4569 }
|
|
4570 goto fail;
|
|
4571 }
|
|
4572
|
|
4573 /* If no failure points, don't restore garbage. And if
|
|
4574 last match is real best match, don't restore second
|
|
4575 best one. */
|
|
4576 else if (best_regs_set && !best_match_p)
|
|
4577 {
|
|
4578 restore_best_regs:
|
|
4579 /* Restore best match. It may happen that `dend ==
|
|
4580 end_match_1' while the restored d is in string2.
|
|
4581 For example, the pattern `x.*y.*z' against the
|
|
4582 strings `x-' and `y-z-', if the two strings are
|
|
4583 not consecutive in memory. */
|
|
4584 DEBUG_PRINT1 ("Restoring best registers.\n");
|
|
4585
|
|
4586 d = match_end;
|
|
4587 dend = ((d >= string1 && d <= end1)
|
|
4588 ? end_match_1 : end_match_2);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4589
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4590 for (mcnt = 1; mcnt < num_regs; mcnt++)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4591 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4592 regstart[mcnt] = best_regstart[mcnt];
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4593 regend[mcnt] = best_regend[mcnt];
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4594 }
|
18262
|
4595 }
|
|
4596 } /* d != end_match_2 */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4597
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4598 succeed_label:
|
18262
|
4599 DEBUG_PRINT1 ("Accepting match.\n");
|
|
4600
|
|
4601 /* If caller wants register contents data back, do it. */
|
|
4602 if (regs && !bufp->no_sub)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4603 {
|
18262
|
4604 /* Have the register data arrays been allocated? */
|
|
4605 if (bufp->regs_allocated == REGS_UNALLOCATED)
|
|
4606 { /* No. So allocate them with malloc. We need one
|
|
4607 extra element beyond `num_regs' for the `-1' marker
|
|
4608 GNU code uses. */
|
|
4609 regs->num_regs = MAX (RE_NREGS, num_regs + 1);
|
|
4610 regs->start = TALLOC (regs->num_regs, regoff_t);
|
|
4611 regs->end = TALLOC (regs->num_regs, regoff_t);
|
|
4612 if (regs->start == NULL || regs->end == NULL)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4613 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4614 FREE_VARIABLES ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4615 return -2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4616 }
|
18262
|
4617 bufp->regs_allocated = REGS_REALLOCATE;
|
|
4618 }
|
|
4619 else if (bufp->regs_allocated == REGS_REALLOCATE)
|
|
4620 { /* Yes. If we need more elements than were already
|
|
4621 allocated, reallocate them. If we need fewer, just
|
|
4622 leave it alone. */
|
|
4623 if (regs->num_regs < num_regs + 1)
|
|
4624 {
|
|
4625 regs->num_regs = num_regs + 1;
|
|
4626 RETALLOC (regs->start, regs->num_regs, regoff_t);
|
|
4627 RETALLOC (regs->end, regs->num_regs, regoff_t);
|
|
4628 if (regs->start == NULL || regs->end == NULL)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4629 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4630 FREE_VARIABLES ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4631 return -2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4632 }
|
18262
|
4633 }
|
|
4634 }
|
|
4635 else
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4636 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4637 /* These braces fend off a "empty body in an else-statement"
|
18262
|
4638 warning under GCC when assert expands to nothing. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4639 assert (bufp->regs_allocated == REGS_FIXED);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4640 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4641
|
18262
|
4642 /* Convert the pointer data in `regstart' and `regend' to
|
|
4643 indices. Register zero has to be set differently,
|
|
4644 since we haven't kept track of any info for it. */
|
|
4645 if (regs->num_regs > 0)
|
|
4646 {
|
|
4647 regs->start[0] = pos;
|
|
4648 regs->end[0] = (MATCHING_IN_FIRST_STRING
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4649 ? ((regoff_t) (d - string1))
|
18262
|
4650 : ((regoff_t) (d - string2 + size1)));
|
|
4651 }
|
|
4652
|
|
4653 /* Go through the first `min (num_regs, regs->num_regs)'
|
|
4654 registers, since that is all we initialized. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4655 for (mcnt = 1; mcnt < MIN (num_regs, regs->num_regs); mcnt++)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4656 {
|
18262
|
4657 if (REG_UNSET (regstart[mcnt]) || REG_UNSET (regend[mcnt]))
|
|
4658 regs->start[mcnt] = regs->end[mcnt] = -1;
|
|
4659 else
|
|
4660 {
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4661 regs->start[mcnt]
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4662 = (regoff_t) POINTER_TO_OFFSET (regstart[mcnt]);
|
18262
|
4663 regs->end[mcnt]
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4664 = (regoff_t) POINTER_TO_OFFSET (regend[mcnt]);
|
18262
|
4665 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4666 }
|
13565
|
4667
|
18262
|
4668 /* If the regs structure we return has more elements than
|
|
4669 were in the pattern, set the extra elements to -1. If
|
|
4670 we (re)allocated the registers, this is the case,
|
|
4671 because we always allocate enough to have at least one
|
|
4672 -1 at the end. */
|
|
4673 for (mcnt = num_regs; mcnt < regs->num_regs; mcnt++)
|
|
4674 regs->start[mcnt] = regs->end[mcnt] = -1;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4675 } /* regs && !bufp->no_sub */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4676
|
18262
|
4677 DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n",
|
|
4678 nfailure_points_pushed, nfailure_points_popped,
|
|
4679 nfailure_points_pushed - nfailure_points_popped);
|
|
4680 DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed);
|
|
4681
|
|
4682 mcnt = d - pos - (MATCHING_IN_FIRST_STRING
|
13565
|
4683 ? string1
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4684 : string2 - size1);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4685
|
18262
|
4686 DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt);
|
|
4687
|
|
4688 FREE_VARIABLES ();
|
|
4689 return mcnt;
|
|
4690 }
|
|
4691
|
|
4692 /* Otherwise match next pattern command. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4693 switch (SWITCH_ENUM_CAST ((re_opcode_t) *p++))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4694 {
|
18262
|
4695 /* Ignore these. Used to ignore the n of succeed_n's which
|
|
4696 currently have n == 0. */
|
|
4697 case no_op:
|
|
4698 DEBUG_PRINT1 ("EXECUTING no_op.\n");
|
|
4699 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4700
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4701 case succeed:
|
18262
|
4702 DEBUG_PRINT1 ("EXECUTING succeed.\n");
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4703 goto succeed_label;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4704
|
18262
|
4705 /* Match the next n pattern characters exactly. The following
|
|
4706 byte in the pattern defines n, and the n bytes after that
|
|
4707 are the characters to match. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4708 case exactn:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4709 mcnt = *p++;
|
18262
|
4710 DEBUG_PRINT2 ("EXECUTING exactn %d.\n", mcnt);
|
|
4711
|
|
4712 /* This is written out as an if-else so we don't waste time
|
|
4713 testing `translate' inside the loop. */
|
21562
|
4714 if (RE_TRANSLATE_P (translate))
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4715 {
|
21348
|
4716 #ifdef emacs
|
|
4717 if (multibyte)
|
|
4718 do
|
|
4719 {
|
|
4720 int pat_charlen, buf_charlen;
|
21401
|
4721 unsigned int pat_ch, buf_ch;
|
21348
|
4722
|
|
4723 PREFETCH ();
|
|
4724 pat_ch = STRING_CHAR_AND_LENGTH (p, pend - p, pat_charlen);
|
|
4725 buf_ch = STRING_CHAR_AND_LENGTH (d, dend - d, buf_charlen);
|
|
4726
|
|
4727 if (RE_TRANSLATE (translate, buf_ch)
|
|
4728 != pat_ch)
|
|
4729 goto fail;
|
|
4730
|
|
4731 p += pat_charlen;
|
|
4732 d += buf_charlen;
|
|
4733 mcnt -= pat_charlen;
|
|
4734 }
|
|
4735 while (mcnt > 0);
|
|
4736 else
|
|
4737 #endif /* not emacs */
|
|
4738 do
|
|
4739 {
|
|
4740 PREFETCH ();
|
22237
|
4741 if ((unsigned char) RE_TRANSLATE (translate, (unsigned char) *d)
|
21348
|
4742 != (unsigned char) *p++)
|
|
4743 goto fail;
|
22237
|
4744 d++;
|
21348
|
4745 }
|
|
4746 while (--mcnt);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4747 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4748 else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4749 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4750 do
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4751 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4752 PREFETCH ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4753 if (*d++ != (char) *p++) goto fail;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4754 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4755 while (--mcnt);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4756 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4757 SET_REGS_MATCHED ();
|
18262
|
4758 break;
|
|
4759
|
|
4760
|
|
4761 /* Match any character except possibly a newline or a null. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4762 case anychar:
|
21348
|
4763 {
|
|
4764 int buf_charlen;
|
21401
|
4765 unsigned int buf_ch;
|
21348
|
4766
|
|
4767 DEBUG_PRINT1 ("EXECUTING anychar.\n");
|
|
4768
|
|
4769 PREFETCH ();
|
|
4770
|
|
4771 #ifdef emacs
|
|
4772 if (multibyte)
|
|
4773 buf_ch = STRING_CHAR_AND_LENGTH (d, dend - d, buf_charlen);
|
|
4774 else
|
|
4775 #endif /* not emacs */
|
|
4776 {
|
21404
|
4777 buf_ch = (unsigned char) *d;
|
21348
|
4778 buf_charlen = 1;
|
|
4779 }
|
|
4780
|
|
4781 buf_ch = TRANSLATE (buf_ch);
|
|
4782
|
|
4783 if ((!(bufp->syntax & RE_DOT_NEWLINE)
|
|
4784 && buf_ch == '\n')
|
|
4785 || ((bufp->syntax & RE_DOT_NOT_NULL)
|
|
4786 && buf_ch == '\000'))
|
|
4787 goto fail;
|
|
4788
|
|
4789 SET_REGS_MATCHED ();
|
|
4790 DEBUG_PRINT2 (" Matched `%d'.\n", *d);
|
|
4791 d += buf_charlen;
|
|
4792 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4793 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4794
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4795
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4796 case charset:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4797 case charset_not:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4798 {
|
18260
|
4799 register unsigned int c;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4800 boolean not = (re_opcode_t) *(p - 1) == charset_not;
|
18260
|
4801 int len;
|
|
4802
|
|
4803 /* Start of actual range_table, or end of bitmap if there is no
|
|
4804 range table. */
|
|
4805 unsigned char *range_table;
|
|
4806
|
25440
|
4807 /* Nonzero if there is a range table. */
|
18260
|
4808 int range_table_exists;
|
|
4809
|
25440
|
4810 /* Number of ranges of range table. This is not included
|
|
4811 in the initial byte-length of the command. */
|
|
4812 int count = 0;
|
18260
|
4813
|
18262
|
4814 DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : "");
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4815
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4816 PREFETCH ();
|
18260
|
4817 c = (unsigned char) *d;
|
|
4818
|
|
4819 range_table_exists = CHARSET_RANGE_TABLE_EXISTS_P (&p[-1]);
|
25440
|
4820
|
|
4821 #ifdef emacs
|
18260
|
4822 if (range_table_exists)
|
25440
|
4823 {
|
|
4824 range_table = CHARSET_RANGE_TABLE (&p[-1]); /* Past the bitmap. */
|
|
4825 EXTRACT_NUMBER_AND_INCR (count, range_table);
|
|
4826 }
|
18260
|
4827
|
|
4828 if (multibyte && BASE_LEADING_CODE_P (c))
|
|
4829 c = STRING_CHAR_AND_LENGTH (d, dend - d, len);
|
25440
|
4830 #endif /* emacs */
|
18260
|
4831
|
|
4832 if (SINGLE_BYTE_CHAR_P (c))
|
|
4833 { /* Lookup bitmap. */
|
|
4834 c = TRANSLATE (c); /* The character to match. */
|
|
4835 len = 1;
|
|
4836
|
|
4837 /* Cast to `unsigned' instead of `unsigned char' in
|
|
4838 case the bit list is a full 32 bytes long. */
|
|
4839 if (c < (unsigned) (CHARSET_BITMAP_SIZE (&p[-1]) * BYTEWIDTH)
|
25440
|
4840 && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
|
|
4841 not = !not;
|
18260
|
4842 }
|
25440
|
4843 #ifdef emacs
|
18260
|
4844 else if (range_table_exists)
|
25440
|
4845 {
|
|
4846 int class_bits = CHARSET_RANGE_TABLE_BITS (&p[-1]);
|
|
4847
|
|
4848 if ( (class_bits & BIT_ALNUM && ISALNUM (c))
|
|
4849 | (class_bits & BIT_ALPHA && ISALPHA (c))
|
25877
|
4850 | (class_bits & BIT_ASCII && IS_REAL_ASCII (c))
|
25440
|
4851 | (class_bits & BIT_GRAPH && ISGRAPH (c))
|
|
4852 | (class_bits & BIT_LOWER && ISLOWER (c))
|
25877
|
4853 | (class_bits & BIT_MULTIBYTE && !ISUNIBYTE (c))
|
|
4854 | (class_bits & BIT_NONASCII && !IS_REAL_ASCII (c))
|
25440
|
4855 | (class_bits & BIT_PRINT && ISPRINT (c))
|
|
4856 | (class_bits & BIT_PUNCT && ISPUNCT (c))
|
|
4857 | (class_bits & BIT_SPACE && ISSPACE (c))
|
25877
|
4858 | (class_bits & BIT_UNIBYTE && ISUNIBYTE (c))
|
25440
|
4859 | (class_bits & BIT_UPPER && ISUPPER (c))
|
|
4860 | (class_bits & BIT_WORD && ISWORD (c)))
|
|
4861 not = !not;
|
|
4862 else
|
|
4863 CHARSET_LOOKUP_RANGE_TABLE_RAW (not, c, range_table, count);
|
|
4864 }
|
|
4865 #endif /* emacs */
|
|
4866
|
|
4867 if (range_table_exists)
|
|
4868 p = CHARSET_RANGE_TABLE_END (range_table, count);
|
|
4869 else
|
|
4870 p += CHARSET_BITMAP_SIZE (&p[-1]) + 1;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4871
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4872 if (!not) goto fail;
|
13565
|
4873
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4874 SET_REGS_MATCHED ();
|
18260
|
4875 d += len;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4876 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4877 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4878
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4879
|
18262
|
4880 /* The beginning of a group is represented by start_memory.
|
|
4881 The arguments are the register number in the next byte, and the
|
|
4882 number of groups inner to this one in the next. The text
|
|
4883 matched within the group is recorded (in the internal
|
|
4884 registers data structure) under the register number. */
|
|
4885 case start_memory:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4886 DEBUG_PRINT3 ("EXECUTING start_memory %d (%d):\n", *p, p[1]);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4887
|
18262
|
4888 /* Find out if this group can match the empty string. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4889 p1 = p; /* To send to group_match_null_string_p. */
|
13565
|
4890
|
18262
|
4891 if (REG_MATCH_NULL_STRING_P (reg_info[*p]) == MATCH_NULL_UNSET_VALUE)
|
|
4892 REG_MATCH_NULL_STRING_P (reg_info[*p])
|
|
4893 = group_match_null_string_p (&p1, pend, reg_info);
|
|
4894
|
|
4895 /* Save the position in the string where we were the last time
|
|
4896 we were at this open-group operator in case the group is
|
|
4897 operated upon by a repetition operator, e.g., with `(a*)*b'
|
|
4898 against `ab'; then we want to ignore where we are now in
|
|
4899 the string in case this attempt to match fails. */
|
|
4900 old_regstart[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p])
|
|
4901 ? REG_UNSET (regstart[*p]) ? d : regstart[*p]
|
|
4902 : regstart[*p];
|
13565
|
4903 DEBUG_PRINT2 (" old_regstart: %d\n",
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4904 POINTER_TO_OFFSET (old_regstart[*p]));
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4905
|
18262
|
4906 regstart[*p] = d;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4907 DEBUG_PRINT2 (" regstart: %d\n", POINTER_TO_OFFSET (regstart[*p]));
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4908
|
18262
|
4909 IS_ACTIVE (reg_info[*p]) = 1;
|
|
4910 MATCHED_SOMETHING (reg_info[*p]) = 0;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4911
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4912 /* Clear this whenever we change the register activity status. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4913 set_regs_matched_done = 0;
|
13565
|
4914
|
18262
|
4915 /* This is the new highest active register. */
|
|
4916 highest_active_reg = *p;
|
|
4917
|
|
4918 /* If nothing was active before, this is the new lowest active
|
|
4919 register. */
|
|
4920 if (lowest_active_reg == NO_LOWEST_ACTIVE_REG)
|
|
4921 lowest_active_reg = *p;
|
|
4922
|
|
4923 /* Move past the register number and inner group count. */
|
|
4924 p += 2;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4925 just_past_start_mem = p;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4926
|
18262
|
4927 break;
|
|
4928
|
|
4929
|
|
4930 /* The stop_memory opcode represents the end of a group. Its
|
|
4931 arguments are the same as start_memory's: the register
|
|
4932 number, and the number of inner groups. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4933 case stop_memory:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4934 DEBUG_PRINT3 ("EXECUTING stop_memory %d (%d):\n", *p, p[1]);
|
13565
|
4935
|
18262
|
4936 /* We need to save the string position the last time we were at
|
|
4937 this close-group operator in case the group is operated
|
|
4938 upon by a repetition operator, e.g., with `((a*)*(b*)*)*'
|
|
4939 against `aba'; then we want to ignore where we are now in
|
|
4940 the string in case this attempt to match fails. */
|
|
4941 old_regend[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p])
|
|
4942 ? REG_UNSET (regend[*p]) ? d : regend[*p]
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4943 : regend[*p];
|
13565
|
4944 DEBUG_PRINT2 (" old_regend: %d\n",
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4945 POINTER_TO_OFFSET (old_regend[*p]));
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4946
|
18262
|
4947 regend[*p] = d;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4948 DEBUG_PRINT2 (" regend: %d\n", POINTER_TO_OFFSET (regend[*p]));
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4949
|
18262
|
4950 /* This register isn't active anymore. */
|
|
4951 IS_ACTIVE (reg_info[*p]) = 0;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4952
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4953 /* Clear this whenever we change the register activity status. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4954 set_regs_matched_done = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4955
|
18262
|
4956 /* If this was the only register active, nothing is active
|
|
4957 anymore. */
|
|
4958 if (lowest_active_reg == highest_active_reg)
|
|
4959 {
|
|
4960 lowest_active_reg = NO_LOWEST_ACTIVE_REG;
|
|
4961 highest_active_reg = NO_HIGHEST_ACTIVE_REG;
|
|
4962 }
|
|
4963 else
|
|
4964 { /* We must scan for the new highest active register, since
|
|
4965 it isn't necessarily one less than now: consider
|
|
4966 (a(b)c(d(e)f)g). When group 3 ends, after the f), the
|
|
4967 new highest active register is 1. */
|
|
4968 unsigned char r = *p - 1;
|
|
4969 while (r > 0 && !IS_ACTIVE (reg_info[r]))
|
|
4970 r--;
|
|
4971
|
|
4972 /* If we end up at register zero, that means that we saved
|
|
4973 the registers as the result of an `on_failure_jump', not
|
|
4974 a `start_memory', and we jumped to past the innermost
|
|
4975 `stop_memory'. For example, in ((.)*) we save
|
|
4976 registers 1 and 2 as a result of the *, but when we pop
|
|
4977 back to the second ), we are at the stop_memory 1.
|
|
4978 Thus, nothing is active. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
4979 if (r == 0)
|
18262
|
4980 {
|
|
4981 lowest_active_reg = NO_LOWEST_ACTIVE_REG;
|
|
4982 highest_active_reg = NO_HIGHEST_ACTIVE_REG;
|
|
4983 }
|
|
4984 else
|
|
4985 highest_active_reg = r;
|
|
4986 }
|
|
4987
|
|
4988 /* If just failed to match something this time around with a
|
|
4989 group that's operated on by a repetition operator, try to
|
|
4990 force exit from the ``loop'', and restore the register
|
|
4991 information for this group that we had before trying this
|
|
4992 last match. */
|
|
4993 if ((!MATCHED_SOMETHING (reg_info[*p])
|
|
4994 || just_past_start_mem == p - 1)
|
13565
|
4995 && (p + 2) < pend)
|
18262
|
4996 {
|
|
4997 boolean is_a_jump_n = false;
|
|
4998
|
|
4999 p1 = p + 2;
|
|
5000 mcnt = 0;
|
|
5001 switch ((re_opcode_t) *p1++)
|
|
5002 {
|
|
5003 case jump_n:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5004 is_a_jump_n = true;
|
18262
|
5005 case pop_failure_jump:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5006 case maybe_pop_jump:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5007 case jump:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5008 case dummy_failure_jump:
|
18262
|
5009 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5010 if (is_a_jump_n)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5011 p1 += 2;
|
18262
|
5012 break;
|
|
5013
|
|
5014 default:
|
|
5015 /* do nothing */ ;
|
|
5016 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5017 p1 += mcnt;
|
13565
|
5018
|
18262
|
5019 /* If the next operation is a jump backwards in the pattern
|
|
5020 to an on_failure_jump right before the start_memory
|
|
5021 corresponding to this stop_memory, exit from the loop
|
|
5022 by forcing a failure after pushing on the stack the
|
|
5023 on_failure_jump's jump in the pattern, and d. */
|
|
5024 if (mcnt < 0 && (re_opcode_t) *p1 == on_failure_jump
|
|
5025 && (re_opcode_t) p1[3] == start_memory && p1[4] == *p)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5026 {
|
18262
|
5027 /* If this group ever matched anything, then restore
|
|
5028 what its registers were before trying this last
|
|
5029 failed match, e.g., with `(a*)*b' against `ab' for
|
|
5030 regstart[1], and, e.g., with `((a*)*(b*)*)*'
|
|
5031 against `aba' for regend[3].
|
|
5032
|
|
5033 Also restore the registers for inner groups for,
|
|
5034 e.g., `((a*)(b*))*' against `aba' (register 3 would
|
|
5035 otherwise get trashed). */
|
|
5036
|
|
5037 if (EVER_MATCHED_SOMETHING (reg_info[*p]))
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5038 {
|
13565
|
5039 unsigned r;
|
|
5040
|
18262
|
5041 EVER_MATCHED_SOMETHING (reg_info[*p]) = 0;
|
13565
|
5042
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5043 /* Restore this and inner groups' (if any) registers. */
|
18262
|
5044 for (r = *p; r < *p + *(p + 1); r++)
|
|
5045 {
|
|
5046 regstart[r] = old_regstart[r];
|
|
5047
|
|
5048 /* xx why this test? */
|
|
5049 if (old_regend[r] >= regstart[r])
|
|
5050 regend[r] = old_regend[r];
|
|
5051 }
|
|
5052 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5053 p1++;
|
18262
|
5054 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
|
|
5055 PUSH_FAILURE_POINT (p1 + mcnt, d, -2);
|
|
5056
|
|
5057 goto fail;
|
|
5058 }
|
|
5059 }
|
|
5060
|
|
5061 /* Move past the register number and the inner group count. */
|
|
5062 p += 2;
|
|
5063 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5064
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5065
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5066 /* \<digit> has been turned into a `duplicate' command which is
|
18262
|
5067 followed by the numeric value of <digit> as the register number. */
|
|
5068 case duplicate:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5069 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5070 register const char *d2, *dend2;
|
18262
|
5071 int regno = *p++; /* Get which register to match against. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5072 DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5073
|
18262
|
5074 /* Can't back reference a group which we've never matched. */
|
|
5075 if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno]))
|
|
5076 goto fail;
|
|
5077
|
|
5078 /* Where in input to try to start matching. */
|
|
5079 d2 = regstart[regno];
|
|
5080
|
|
5081 /* Where to stop matching; if both the place to start and
|
|
5082 the place to stop matching are in the same string, then
|
|
5083 set to the place to stop, otherwise, for now have to use
|
|
5084 the end of the first string. */
|
|
5085
|
|
5086 dend2 = ((FIRST_STRING_P (regstart[regno])
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5087 == FIRST_STRING_P (regend[regno]))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5088 ? regend[regno] : end_match_1);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5089 for (;;)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5090 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5091 /* If necessary, advance to next segment in register
|
18262
|
5092 contents. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5093 while (d2 == dend2)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5094 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5095 if (dend2 == end_match_2) break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5096 if (dend2 == regend[regno]) break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5097
|
18262
|
5098 /* End of string1 => advance to string2. */
|
|
5099 d2 = string2;
|
|
5100 dend2 = regend[regno];
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5101 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5102 /* At end of register contents => success */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5103 if (d2 == dend2) break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5104
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5105 /* If necessary, advance to next segment in data. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5106 PREFETCH ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5107
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5108 /* How many characters left in this segment to match. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5109 mcnt = dend - d;
|
13565
|
5110
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5111 /* Want how many consecutive characters we can match in
|
18262
|
5112 one shot, so, if necessary, adjust the count. */
|
|
5113 if (mcnt > dend2 - d2)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5114 mcnt = dend2 - d2;
|
13565
|
5115
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5116 /* Compare that many; failure if mismatch, else move
|
18262
|
5117 past them. */
|
21562
|
5118 if (RE_TRANSLATE_P (translate)
|
18262
|
5119 ? bcmp_translate (d, d2, mcnt, translate)
|
|
5120 : bcmp (d, d2, mcnt))
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5121 goto fail;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5122 d += mcnt, d2 += mcnt;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5123
|
18262
|
5124 /* Do this because we've match some characters. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5125 SET_REGS_MATCHED ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5126 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5127 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5128 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5129
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5130
|
18262
|
5131 /* begline matches the empty string at the beginning of the string
|
|
5132 (unless `not_bol' is set in `bufp'), and, if
|
|
5133 `newline_anchor' is set, after newlines. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5134 case begline:
|
18262
|
5135 DEBUG_PRINT1 ("EXECUTING begline.\n");
|
|
5136
|
|
5137 if (AT_STRINGS_BEG (d))
|
|
5138 {
|
|
5139 if (!bufp->not_bol) break;
|
|
5140 }
|
|
5141 else if (d[-1] == '\n' && bufp->newline_anchor)
|
|
5142 {
|
|
5143 break;
|
|
5144 }
|
|
5145 /* In all other cases, we fail. */
|
|
5146 goto fail;
|
|
5147
|
|
5148
|
|
5149 /* endline is the dual of begline. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5150 case endline:
|
18262
|
5151 DEBUG_PRINT1 ("EXECUTING endline.\n");
|
|
5152
|
|
5153 if (AT_STRINGS_END (d))
|
|
5154 {
|
|
5155 if (!bufp->not_eol) break;
|
|
5156 }
|
|
5157
|
|
5158 /* We have to ``prefetch'' the next character. */
|
|
5159 else if ((d == end1 ? *string2 : *d) == '\n'
|
|
5160 && bufp->newline_anchor)
|
|
5161 {
|
|
5162 break;
|
|
5163 }
|
|
5164 goto fail;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5165
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5166
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5167 /* Match at the very beginning of the data. */
|
18262
|
5168 case begbuf:
|
|
5169 DEBUG_PRINT1 ("EXECUTING begbuf.\n");
|
|
5170 if (AT_STRINGS_BEG (d))
|
|
5171 break;
|
|
5172 goto fail;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5173
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5174
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5175 /* Match at the very end of the data. */
|
18262
|
5176 case endbuf:
|
|
5177 DEBUG_PRINT1 ("EXECUTING endbuf.\n");
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5178 if (AT_STRINGS_END (d))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5179 break;
|
18262
|
5180 goto fail;
|
|
5181
|
|
5182
|
|
5183 /* on_failure_keep_string_jump is used to optimize `.*\n'. It
|
|
5184 pushes NULL as the value for the string on the stack. Then
|
|
5185 `pop_failure_point' will keep the current value for the
|
|
5186 string, instead of restoring it. To see why, consider
|
|
5187 matching `foo\nbar' against `.*\n'. The .* matches the foo;
|
|
5188 then the . fails against the \n. But the next thing we want
|
|
5189 to do is match the \n against the \n; if we restored the
|
|
5190 string value, we would be back at the foo.
|
|
5191
|
|
5192 Because this is used only in specific cases, we don't need to
|
|
5193 check all the things that `on_failure_jump' does, to make
|
|
5194 sure the right things get saved on the stack. Hence we don't
|
|
5195 share its code. The only reason to push anything on the
|
|
5196 stack at all is that otherwise we would have to change
|
|
5197 `anychar's code to do something besides goto fail in this
|
|
5198 case; that seems worse than this. */
|
|
5199 case on_failure_keep_string_jump:
|
|
5200 DEBUG_PRINT1 ("EXECUTING on_failure_keep_string_jump");
|
|
5201
|
|
5202 EXTRACT_NUMBER_AND_INCR (mcnt, p);
|
|
5203 DEBUG_PRINT3 (" %d (to 0x%x):\n", mcnt, p + mcnt);
|
|
5204
|
|
5205 PUSH_FAILURE_POINT (p + mcnt, NULL, -2);
|
|
5206 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5207
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5208
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5209 /* Uses of on_failure_jump:
|
13565
|
5210
|
18262
|
5211 Each alternative starts with an on_failure_jump that points
|
|
5212 to the beginning of the next alternative. Each alternative
|
|
5213 except the last ends with a jump that in effect jumps past
|
|
5214 the rest of the alternatives. (They really jump to the
|
|
5215 ending jump of the following alternative, because tensioning
|
|
5216 these jumps is a hassle.)
|
|
5217
|
|
5218 Repeats start with an on_failure_jump that points past both
|
|
5219 the repetition text and either the following jump or
|
|
5220 pop_failure_jump back to this on_failure_jump. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5221 case on_failure_jump:
|
18262
|
5222 on_failure:
|
|
5223 DEBUG_PRINT1 ("EXECUTING on_failure_jump");
|
|
5224
|
24119
aceb3b94328d
(re_match_2_internal) [WINDOWSNT & emacs]: Insert QUIT at various places.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
5225 #if defined (WINDOWSNT) && defined (emacs)
|
aceb3b94328d
(re_match_2_internal) [WINDOWSNT & emacs]: Insert QUIT at various places.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
5226 QUIT;
|
aceb3b94328d
(re_match_2_internal) [WINDOWSNT & emacs]: Insert QUIT at various places.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
5227 #endif
|
aceb3b94328d
(re_match_2_internal) [WINDOWSNT & emacs]: Insert QUIT at various places.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
5228
|
18262
|
5229 EXTRACT_NUMBER_AND_INCR (mcnt, p);
|
|
5230 DEBUG_PRINT3 (" %d (to 0x%x)", mcnt, p + mcnt);
|
|
5231
|
|
5232 /* If this on_failure_jump comes right before a group (i.e.,
|
|
5233 the original * applied to a group), save the information
|
|
5234 for that group and all inner ones, so that if we fail back
|
|
5235 to this point, the group's information will be correct.
|
|
5236 For example, in \(a*\)*\1, we need the preceding group,
|
|
5237 and in \(zz\(a*\)b*\)\2, we need the inner group. */
|
|
5238
|
|
5239 /* We can't use `p' to check ahead because we push
|
|
5240 a failure point to `p + mcnt' after we do this. */
|
|
5241 p1 = p;
|
|
5242
|
|
5243 /* We need to skip no_op's before we look for the
|
|
5244 start_memory in case this on_failure_jump is happening as
|
|
5245 the result of a completed succeed_n, as in \(a\)\{1,3\}b\1
|
|
5246 against aba. */
|
|
5247 while (p1 < pend && (re_opcode_t) *p1 == no_op)
|
|
5248 p1++;
|
|
5249
|
|
5250 if (p1 < pend && (re_opcode_t) *p1 == start_memory)
|
|
5251 {
|
|
5252 /* We have a new highest active register now. This will
|
|
5253 get reset at the start_memory we are about to get to,
|
|
5254 but we will have saved all the registers relevant to
|
|
5255 this repetition op, as described above. */
|
|
5256 highest_active_reg = *(p1 + 1) + *(p1 + 2);
|
|
5257 if (lowest_active_reg == NO_LOWEST_ACTIVE_REG)
|
|
5258 lowest_active_reg = *(p1 + 1);
|
|
5259 }
|
|
5260
|
|
5261 DEBUG_PRINT1 (":\n");
|
|
5262 PUSH_FAILURE_POINT (p + mcnt, d, -2);
|
|
5263 break;
|
|
5264
|
|
5265
|
|
5266 /* A smart repeat ends with `maybe_pop_jump'.
|
|
5267 We change it to either `pop_failure_jump' or `jump'. */
|
|
5268 case maybe_pop_jump:
|
24119
aceb3b94328d
(re_match_2_internal) [WINDOWSNT & emacs]: Insert QUIT at various places.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
5269 #if defined (WINDOWSNT) && defined (emacs)
|
aceb3b94328d
(re_match_2_internal) [WINDOWSNT & emacs]: Insert QUIT at various places.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
5270 QUIT;
|
aceb3b94328d
(re_match_2_internal) [WINDOWSNT & emacs]: Insert QUIT at various places.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
5271 #endif
|
18262
|
5272 EXTRACT_NUMBER_AND_INCR (mcnt, p);
|
|
5273 DEBUG_PRINT2 ("EXECUTING maybe_pop_jump %d.\n", mcnt);
|
|
5274 {
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5275 register unsigned char *p2 = p;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5276
|
18262
|
5277 /* Compare the beginning of the repeat with what in the
|
|
5278 pattern follows its end. If we can establish that there
|
|
5279 is nothing that they would both match, i.e., that we
|
|
5280 would have to backtrack because of (as in, e.g., `a*a')
|
|
5281 then we can change to pop_failure_jump, because we'll
|
|
5282 never have to backtrack.
|
|
5283
|
|
5284 This is not true in the case of alternatives: in
|
|
5285 `(a|ab)*' we do need to backtrack to the `ab' alternative
|
|
5286 (e.g., if the string was `ab'). But instead of trying to
|
|
5287 detect that here, the alternative has put on a dummy
|
|
5288 failure point which is what we will end up popping. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5289
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5290 /* Skip over open/close-group commands.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5291 If what follows this loop is a ...+ construct,
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5292 look at what begins its body, since we will have to
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5293 match at least one of that. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5294 while (1)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5295 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5296 if (p2 + 2 < pend
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5297 && ((re_opcode_t) *p2 == stop_memory
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5298 || (re_opcode_t) *p2 == start_memory))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5299 p2 += 3;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5300 else if (p2 + 6 < pend
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5301 && (re_opcode_t) *p2 == dummy_failure_jump)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5302 p2 += 6;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5303 else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5304 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5305 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5306
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5307 p1 = p + mcnt;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5308 /* p1[0] ... p1[2] are the `on_failure_jump' corresponding
|
13565
|
5309 to the `maybe_finalize_jump' of this case. Examine what
|
18262
|
5310 follows. */
|
|
5311
|
|
5312 /* If we're at the end of the pattern, we can change. */
|
|
5313 if (p2 == pend)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5314 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5315 /* Consider what happens when matching ":\(.*\)"
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5316 against ":/". I don't really understand this code
|
18262
|
5317 yet. */
|
|
5318 p[-3] = (unsigned char) pop_failure_jump;
|
|
5319 DEBUG_PRINT1
|
|
5320 (" End of pattern: change to `pop_failure_jump'.\n");
|
|
5321 }
|
|
5322
|
|
5323 else if ((re_opcode_t) *p2 == exactn
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5324 || (bufp->newline_anchor && (re_opcode_t) *p2 == endline))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5325 {
|
18260
|
5326 register unsigned int c
|
18262
|
5327 = *p2 == (unsigned char) endline ? '\n' : p2[2];
|
18260
|
5328
|
|
5329 if ((re_opcode_t) p1[3] == exactn)
|
16010
|
5330 {
|
18260
|
5331 if (!(multibyte /* && (c != '\n') */
|
|
5332 && BASE_LEADING_CODE_P (c))
|
|
5333 ? c != p1[5]
|
|
5334 : (STRING_CHAR (&p2[2], pend - &p2[2])
|
|
5335 != STRING_CHAR (&p1[5], pend - &p1[5])))
|
18262
|
5336 {
|
|
5337 p[-3] = (unsigned char) pop_failure_jump;
|
|
5338 DEBUG_PRINT3 (" %c != %c => pop_failure_jump.\n",
|
|
5339 c, p1[5]);
|
|
5340 }
|
16010
|
5341 }
|
13565
|
5342
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5343 else if ((re_opcode_t) p1[3] == charset
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5344 || (re_opcode_t) p1[3] == charset_not)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5345 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5346 int not = (re_opcode_t) p1[3] == charset_not;
|
13565
|
5347
|
18260
|
5348 if (multibyte /* && (c != '\n') */
|
|
5349 && BASE_LEADING_CODE_P (c))
|
|
5350 c = STRING_CHAR (&p2[2], pend - &p2[2]);
|
|
5351
|
|
5352 /* Test if C is listed in charset (or charset_not)
|
|
5353 at `&p1[3]'. */
|
|
5354 if (SINGLE_BYTE_CHAR_P (c))
|
|
5355 {
|
|
5356 if (c < CHARSET_BITMAP_SIZE (&p1[3]) * BYTEWIDTH
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5357 && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5358 not = !not;
|
18260
|
5359 }
|
|
5360 else if (CHARSET_RANGE_TABLE_EXISTS_P (&p1[3]))
|
|
5361 CHARSET_LOOKUP_RANGE_TABLE (not, c, &p1[3]);
|
|
5362
|
18262
|
5363 /* `not' is equal to 1 if c would match, which means
|
|
5364 that we can't change to pop_failure_jump. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5365 if (!not)
|
18262
|
5366 {
|
|
5367 p[-3] = (unsigned char) pop_failure_jump;
|
|
5368 DEBUG_PRINT1 (" No match => pop_failure_jump.\n");
|
|
5369 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5370 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5371 }
|
18262
|
5372 else if ((re_opcode_t) *p2 == charset)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5373 {
|
18260
|
5374 if ((re_opcode_t) p1[3] == exactn)
|
16010
|
5375 {
|
18260
|
5376 register unsigned int c = p1[5];
|
|
5377 int not = 0;
|
|
5378
|
|
5379 if (multibyte && BASE_LEADING_CODE_P (c))
|
|
5380 c = STRING_CHAR (&p1[5], pend - &p1[5]);
|
|
5381
|
18262
|
5382 /* Test if C is listed in charset at `p2'. */
|
18260
|
5383 if (SINGLE_BYTE_CHAR_P (c))
|
|
5384 {
|
|
5385 if (c < CHARSET_BITMAP_SIZE (p2) * BYTEWIDTH
|
|
5386 && (p2[2 + c / BYTEWIDTH]
|
|
5387 & (1 << (c % BYTEWIDTH))))
|
|
5388 not = !not;
|
|
5389 }
|
|
5390 else if (CHARSET_RANGE_TABLE_EXISTS_P (p2))
|
|
5391 CHARSET_LOOKUP_RANGE_TABLE (not, c, p2);
|
|
5392
|
|
5393 if (!not)
|
18262
|
5394 {
|
|
5395 p[-3] = (unsigned char) pop_failure_jump;
|
|
5396 DEBUG_PRINT1 (" No match => pop_failure_jump.\n");
|
18260
|
5397 }
|
18262
|
5398 }
|
18260
|
5399
|
|
5400 /* It is hard to list up all the character in charset
|
|
5401 P2 if it includes multibyte character. Give up in
|
|
5402 such case. */
|
|
5403 else if (!multibyte || !CHARSET_RANGE_TABLE_EXISTS_P (p2))
|
|
5404 {
|
|
5405 /* Now, we are sure that P2 has no range table.
|
|
5406 So, for the size of bitmap in P2, `p2[1]' is
|
18262
|
5407 enough. But P1 may have range table, so the
|
18260
|
5408 size of bitmap table of P1 is extracted by
|
|
5409 using macro `CHARSET_BITMAP_SIZE'.
|
|
5410
|
|
5411 Since we know that all the character listed in
|
|
5412 P2 is ASCII, it is enough to test only bitmap
|
|
5413 table of P1. */
|
18262
|
5414
|
18260
|
5415 if ((re_opcode_t) p1[3] == charset_not)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5416 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5417 int idx;
|
18260
|
5418 /* We win if the charset_not inside the loop lists
|
18262
|
5419 every character listed in the charset after. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5420 for (idx = 0; idx < (int) p2[1]; idx++)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5421 if (! (p2[2 + idx] == 0
|
18260
|
5422 || (idx < CHARSET_BITMAP_SIZE (&p1[3])
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5423 && ((p2[2 + idx] & ~ p1[5 + idx]) == 0))))
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5424 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5425
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5426 if (idx == p2[1])
|
18262
|
5427 {
|
|
5428 p[-3] = (unsigned char) pop_failure_jump;
|
|
5429 DEBUG_PRINT1 (" No match => pop_failure_jump.\n");
|
|
5430 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5431 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5432 else if ((re_opcode_t) p1[3] == charset)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5433 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5434 int idx;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5435 /* We win if the charset inside the loop
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5436 has no overlap with the one after the loop. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5437 for (idx = 0;
|
18260
|
5438 (idx < (int) p2[1]
|
|
5439 && idx < CHARSET_BITMAP_SIZE (&p1[3]));
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5440 idx++)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5441 if ((p2[2 + idx] & p1[5 + idx]) != 0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5442 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5443
|
18260
|
5444 if (idx == p2[1]
|
|
5445 || idx == CHARSET_BITMAP_SIZE (&p1[3]))
|
18262
|
5446 {
|
|
5447 p[-3] = (unsigned char) pop_failure_jump;
|
|
5448 DEBUG_PRINT1 (" No match => pop_failure_jump.\n");
|
|
5449 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5450 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5451 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5452 }
|
18260
|
5453 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5454 p -= 2; /* Point at relative address again. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5455 if ((re_opcode_t) p[-1] != pop_failure_jump)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5456 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5457 p[-1] = (unsigned char) jump;
|
18262
|
5458 DEBUG_PRINT1 (" Match => jump.\n");
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5459 goto unconditional_jump;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5460 }
|
18262
|
5461 /* Note fall through. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5462
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5463
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5464 /* The end of a simple repeat has a pop_failure_jump back to
|
18262
|
5465 its matching on_failure_jump, where the latter will push a
|
|
5466 failure point. The pop_failure_jump takes off failure
|
|
5467 points put on by this pop_failure_jump's matching
|
|
5468 on_failure_jump; we got through the pattern to here from the
|
|
5469 matching on_failure_jump, so didn't fail. */
|
|
5470 case pop_failure_jump:
|
|
5471 {
|
|
5472 /* We need to pass separate storage for the lowest and
|
|
5473 highest registers, even though we don't care about the
|
|
5474 actual values. Otherwise, we will restore only one
|
|
5475 register from the stack, since lowest will == highest in
|
|
5476 `pop_failure_point'. */
|
|
5477 unsigned dummy_low_reg, dummy_high_reg;
|
|
5478 unsigned char *pdummy;
|
|
5479 const char *sdummy;
|
|
5480
|
|
5481 DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n");
|
|
5482 POP_FAILURE_POINT (sdummy, pdummy,
|
|
5483 dummy_low_reg, dummy_high_reg,
|
|
5484 reg_dummy, reg_dummy, reg_info_dummy);
|
|
5485 }
|
|
5486 /* Note fall through. */
|
|
5487
|
|
5488
|
|
5489 /* Unconditionally jump (without popping any failure points). */
|
|
5490 case jump:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5491 unconditional_jump:
|
24119
aceb3b94328d
(re_match_2_internal) [WINDOWSNT & emacs]: Insert QUIT at various places.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
5492 #if defined (WINDOWSNT) && defined (emacs)
|
aceb3b94328d
(re_match_2_internal) [WINDOWSNT & emacs]: Insert QUIT at various places.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
5493 QUIT;
|
aceb3b94328d
(re_match_2_internal) [WINDOWSNT & emacs]: Insert QUIT at various places.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
5494 #endif
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5495 EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */
|
18262
|
5496 DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt);
|
|
5497 p += mcnt; /* Do the jump. */
|
|
5498 DEBUG_PRINT2 ("(to 0x%x).\n", p);
|
|
5499 break;
|
|
5500
|
|
5501
|
|
5502 /* We need this opcode so we can detect where alternatives end
|
|
5503 in `group_match_null_string_p' et al. */
|
|
5504 case jump_past_alt:
|
|
5505 DEBUG_PRINT1 ("EXECUTING jump_past_alt.\n");
|
|
5506 goto unconditional_jump;
|
|
5507
|
|
5508
|
|
5509 /* Normally, the on_failure_jump pushes a failure point, which
|
|
5510 then gets popped at pop_failure_jump. We will end up at
|
|
5511 pop_failure_jump, also, and with a pattern of, say, `a+', we
|
|
5512 are skipping over the on_failure_jump, so we have to push
|
|
5513 something meaningless for pop_failure_jump to pop. */
|
|
5514 case dummy_failure_jump:
|
|
5515 DEBUG_PRINT1 ("EXECUTING dummy_failure_jump.\n");
|
|
5516 /* It doesn't matter what we push for the string here. What
|
|
5517 the code at `fail' tests is the value for the pattern. */
|
|
5518 PUSH_FAILURE_POINT (0, 0, -2);
|
|
5519 goto unconditional_jump;
|
|
5520
|
|
5521
|
|
5522 /* At the end of an alternative, we need to push a dummy failure
|
|
5523 point in case we are followed by a `pop_failure_jump', because
|
|
5524 we don't want the failure point for the alternative to be
|
|
5525 popped. For example, matching `(a|ab)*' against `aab'
|
|
5526 requires that we match the `ab' alternative. */
|
|
5527 case push_dummy_failure:
|
|
5528 DEBUG_PRINT1 ("EXECUTING push_dummy_failure.\n");
|
|
5529 /* See comments just above at `dummy_failure_jump' about the
|
|
5530 two zeroes. */
|
|
5531 PUSH_FAILURE_POINT (0, 0, -2);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5532 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5533
|
18262
|
5534 /* Have to succeed matching what follows at least n times.
|
|
5535 After that, handle like `on_failure_jump'. */
|
|
5536 case succeed_n:
|
|
5537 EXTRACT_NUMBER (mcnt, p + 2);
|
|
5538 DEBUG_PRINT2 ("EXECUTING succeed_n %d.\n", mcnt);
|
|
5539
|
|
5540 assert (mcnt >= 0);
|
|
5541 /* Originally, this is how many times we HAVE to succeed. */
|
|
5542 if (mcnt > 0)
|
|
5543 {
|
|
5544 mcnt--;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5545 p += 2;
|
18262
|
5546 STORE_NUMBER_AND_INCR (p, mcnt);
|
|
5547 DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p, mcnt);
|
|
5548 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5549 else if (mcnt == 0)
|
18262
|
5550 {
|
|
5551 DEBUG_PRINT2 (" Setting two bytes from 0x%x to no_op.\n", p+2);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5552 p[2] = (unsigned char) no_op;
|
18262
|
5553 p[3] = (unsigned char) no_op;
|
|
5554 goto on_failure;
|
|
5555 }
|
|
5556 break;
|
|
5557
|
|
5558 case jump_n:
|
|
5559 EXTRACT_NUMBER (mcnt, p + 2);
|
|
5560 DEBUG_PRINT2 ("EXECUTING jump_n %d.\n", mcnt);
|
|
5561
|
|
5562 /* Originally, this is how many times we CAN jump. */
|
|
5563 if (mcnt)
|
|
5564 {
|
|
5565 mcnt--;
|
|
5566 STORE_NUMBER (p + 2, mcnt);
|
13565
|
5567 goto unconditional_jump;
|
18262
|
5568 }
|
|
5569 /* If don't have to jump any more, skip over the rest of command. */
|
13565
|
5570 else
|
|
5571 p += 4;
|
18262
|
5572 break;
|
13565
|
5573
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5574 case set_number_at:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5575 {
|
18262
|
5576 DEBUG_PRINT1 ("EXECUTING set_number_at.\n");
|
|
5577
|
|
5578 EXTRACT_NUMBER_AND_INCR (mcnt, p);
|
|
5579 p1 = p + mcnt;
|
|
5580 EXTRACT_NUMBER_AND_INCR (mcnt, p);
|
|
5581 DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p1, mcnt);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5582 STORE_NUMBER (p1, mcnt);
|
18262
|
5583 break;
|
|
5584 }
|
13722
|
5585
|
|
5586 case wordbound:
|
|
5587 DEBUG_PRINT1 ("EXECUTING wordbound.\n");
|
18260
|
5588
|
|
5589 /* We SUCCEED in one of the following cases: */
|
|
5590
|
|
5591 /* Case 1: D is at the beginning or the end of string. */
|
13722
|
5592 if (AT_STRINGS_BEG (d) || AT_STRINGS_END (d))
|
|
5593 break;
|
18260
|
5594 else
|
|
5595 {
|
|
5596 /* C1 is the character before D, S1 is the syntax of C1, C2
|
|
5597 is the character at D, and S2 is the syntax of C2. */
|
|
5598 int c1, c2, s1, s2;
|
|
5599 int pos1 = PTR_TO_OFFSET (d - 1);
|
20633
|
5600 int charpos;
|
18260
|
5601
|
|
5602 GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2);
|
|
5603 GET_CHAR_AFTER_2 (c2, d, string1, end1, string2, end2);
|
|
5604 #ifdef emacs
|
22372
|
5605 charpos = SYNTAX_TABLE_BYTE_TO_CHAR (pos1);
|
20633
|
5606 UPDATE_SYNTAX_TABLE (charpos);
|
18262
|
5607 #endif
|
18260
|
5608 s1 = SYNTAX (c1);
|
|
5609 #ifdef emacs
|
20633
|
5610 UPDATE_SYNTAX_TABLE_FORWARD (charpos + 1);
|
18262
|
5611 #endif
|
18260
|
5612 s2 = SYNTAX (c2);
|
|
5613
|
|
5614 if (/* Case 2: Only one of S1 and S2 is Sword. */
|
|
5615 ((s1 == Sword) != (s2 == Sword))
|
|
5616 /* Case 3: Both of S1 and S2 are Sword, and macro
|
18262
|
5617 WORD_BOUNDARY_P (C1, C2) returns nonzero. */
|
18260
|
5618 || ((s1 == Sword) && WORD_BOUNDARY_P (c1, c2)))
|
13722
|
5619 break;
|
18260
|
5620 }
|
13722
|
5621 goto fail;
|
|
5622
|
|
5623 case notwordbound:
|
|
5624 DEBUG_PRINT1 ("EXECUTING notwordbound.\n");
|
18260
|
5625
|
|
5626 /* We FAIL in one of the following cases: */
|
|
5627
|
|
5628 /* Case 1: D is at the beginning or the end of string. */
|
13722
|
5629 if (AT_STRINGS_BEG (d) || AT_STRINGS_END (d))
|
|
5630 goto fail;
|
18260
|
5631 else
|
|
5632 {
|
|
5633 /* C1 is the character before D, S1 is the syntax of C1, C2
|
|
5634 is the character at D, and S2 is the syntax of C2. */
|
|
5635 int c1, c2, s1, s2;
|
|
5636 int pos1 = PTR_TO_OFFSET (d - 1);
|
20633
|
5637 int charpos;
|
18260
|
5638
|
|
5639 GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2);
|
|
5640 GET_CHAR_AFTER_2 (c2, d, string1, end1, string2, end2);
|
|
5641 #ifdef emacs
|
20650
|
5642 charpos = SYNTAX_TABLE_BYTE_TO_CHAR (pos1);
|
20633
|
5643 UPDATE_SYNTAX_TABLE (charpos);
|
18262
|
5644 #endif
|
18260
|
5645 s1 = SYNTAX (c1);
|
|
5646 #ifdef emacs
|
20633
|
5647 UPDATE_SYNTAX_TABLE_FORWARD (charpos + 1);
|
18262
|
5648 #endif
|
18260
|
5649 s2 = SYNTAX (c2);
|
|
5650
|
|
5651 if (/* Case 2: Only one of S1 and S2 is Sword. */
|
|
5652 ((s1 == Sword) != (s2 == Sword))
|
|
5653 /* Case 3: Both of S1 and S2 are Sword, and macro
|
18262
|
5654 WORD_BOUNDARY_P (C1, C2) returns nonzero. */
|
18260
|
5655 || ((s1 == Sword) && WORD_BOUNDARY_P (c1, c2)))
|
13722
|
5656 goto fail;
|
18260
|
5657 }
|
13722
|
5658 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5659
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5660 case wordbeg:
|
18262
|
5661 DEBUG_PRINT1 ("EXECUTING wordbeg.\n");
|
18260
|
5662
|
|
5663 /* We FAIL in one of the following cases: */
|
|
5664
|
18262
|
5665 /* Case 1: D is at the end of string. */
|
18260
|
5666 if (AT_STRINGS_END (d))
|
18262
|
5667 goto fail;
|
18260
|
5668 else
|
|
5669 {
|
|
5670 /* C1 is the character before D, S1 is the syntax of C1, C2
|
|
5671 is the character at D, and S2 is the syntax of C2. */
|
|
5672 int c1, c2, s1, s2;
|
|
5673 int pos1 = PTR_TO_OFFSET (d);
|
20633
|
5674 int charpos;
|
18260
|
5675
|
|
5676 GET_CHAR_AFTER_2 (c2, d, string1, end1, string2, end2);
|
|
5677 #ifdef emacs
|
20650
|
5678 charpos = SYNTAX_TABLE_BYTE_TO_CHAR (pos1);
|
|
5679 UPDATE_SYNTAX_TABLE (charpos);
|
18262
|
5680 #endif
|
18260
|
5681 s2 = SYNTAX (c2);
|
18262
|
5682
|
18260
|
5683 /* Case 2: S2 is not Sword. */
|
|
5684 if (s2 != Sword)
|
|
5685 goto fail;
|
|
5686
|
|
5687 /* Case 3: D is not at the beginning of string ... */
|
|
5688 if (!AT_STRINGS_BEG (d))
|
|
5689 {
|
|
5690 GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2);
|
|
5691 #ifdef emacs
|
20633
|
5692 UPDATE_SYNTAX_TABLE_BACKWARD (charpos - 1);
|
18262
|
5693 #endif
|
18260
|
5694 s1 = SYNTAX (c1);
|
|
5695
|
|
5696 /* ... and S1 is Sword, and WORD_BOUNDARY_P (C1, C2)
|
18262
|
5697 returns 0. */
|
18260
|
5698 if ((s1 == Sword) && !WORD_BOUNDARY_P (c1, c2))
|
|
5699 goto fail;
|
|
5700 }
|
|
5701 }
|
|
5702 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5703
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5704 case wordend:
|
18262
|
5705 DEBUG_PRINT1 ("EXECUTING wordend.\n");
|
18260
|
5706
|
|
5707 /* We FAIL in one of the following cases: */
|
|
5708
|
|
5709 /* Case 1: D is at the beginning of string. */
|
|
5710 if (AT_STRINGS_BEG (d))
|
|
5711 goto fail;
|
|
5712 else
|
|
5713 {
|
|
5714 /* C1 is the character before D, S1 is the syntax of C1, C2
|
|
5715 is the character at D, and S2 is the syntax of C2. */
|
|
5716 int c1, c2, s1, s2;
|
20633
|
5717 int pos1 = PTR_TO_OFFSET (d);
|
|
5718 int charpos;
|
18260
|
5719
|
|
5720 GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2);
|
20633
|
5721 #ifdef emacs
|
20650
|
5722 charpos = SYNTAX_TABLE_BYTE_TO_CHAR (pos1 - 1);
|
|
5723 UPDATE_SYNTAX_TABLE (charpos);
|
20633
|
5724 #endif
|
18260
|
5725 s1 = SYNTAX (c1);
|
|
5726
|
|
5727 /* Case 2: S1 is not Sword. */
|
|
5728 if (s1 != Sword)
|
|
5729 goto fail;
|
|
5730
|
|
5731 /* Case 3: D is not at the end of string ... */
|
|
5732 if (!AT_STRINGS_END (d))
|
|
5733 {
|
|
5734 GET_CHAR_AFTER_2 (c2, d, string1, end1, string2, end2);
|
20633
|
5735 #ifdef emacs
|
|
5736 UPDATE_SYNTAX_TABLE_FORWARD (charpos);
|
|
5737 #endif
|
18260
|
5738 s2 = SYNTAX (c2);
|
|
5739
|
|
5740 /* ... and S2 is Sword, and WORD_BOUNDARY_P (C1, C2)
|
18262
|
5741 returns 0. */
|
18260
|
5742 if ((s2 == Sword) && !WORD_BOUNDARY_P (c1, c2))
|
18262
|
5743 goto fail;
|
18260
|
5744 }
|
|
5745 }
|
|
5746 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5747
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5748 #ifdef emacs
|
18262
|
5749 case before_dot:
|
|
5750 DEBUG_PRINT1 ("EXECUTING before_dot.\n");
|
20633
|
5751 if (PTR_BYTE_POS ((unsigned char *) d) >= PT_BYTE)
|
18262
|
5752 goto fail;
|
|
5753 break;
|
|
5754
|
|
5755 case at_dot:
|
|
5756 DEBUG_PRINT1 ("EXECUTING at_dot.\n");
|
20633
|
5757 if (PTR_BYTE_POS ((unsigned char *) d) != PT_BYTE)
|
18262
|
5758 goto fail;
|
|
5759 break;
|
|
5760
|
|
5761 case after_dot:
|
|
5762 DEBUG_PRINT1 ("EXECUTING after_dot.\n");
|
20633
|
5763 if (PTR_BYTE_POS ((unsigned char *) d) <= PT_BYTE)
|
18262
|
5764 goto fail;
|
|
5765 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5766
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5767 case syntaxspec:
|
18262
|
5768 DEBUG_PRINT2 ("EXECUTING syntaxspec %d.\n", mcnt);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5769 mcnt = *p++;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5770 goto matchsyntax;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5771
|
18262
|
5772 case wordchar:
|
|
5773 DEBUG_PRINT1 ("EXECUTING Emacs wordchar.\n");
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5774 mcnt = (int) Sword;
|
18262
|
5775 matchsyntax:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5776 PREFETCH ();
|
18260
|
5777 #ifdef emacs
|
|
5778 {
|
20650
|
5779 int pos1 = SYNTAX_TABLE_BYTE_TO_CHAR (PTR_TO_OFFSET (d));
|
18260
|
5780 UPDATE_SYNTAX_TABLE (pos1);
|
|
5781 }
|
18262
|
5782 #endif
|
18260
|
5783 {
|
|
5784 int c, len;
|
|
5785
|
|
5786 if (multibyte)
|
|
5787 /* we must concern about multibyte form, ... */
|
|
5788 c = STRING_CHAR_AND_LENGTH (d, dend - d, len);
|
|
5789 else
|
|
5790 /* everything should be handled as ASCII, even though it
|
|
5791 looks like multibyte form. */
|
|
5792 c = *d, len = 1;
|
|
5793
|
|
5794 if (SYNTAX (c) != (enum syntaxcode) mcnt)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5795 goto fail;
|
18260
|
5796 d += len;
|
|
5797 }
|
18262
|
5798 SET_REGS_MATCHED ();
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5799 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5800
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5801 case notsyntaxspec:
|
18262
|
5802 DEBUG_PRINT2 ("EXECUTING notsyntaxspec %d.\n", mcnt);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5803 mcnt = *p++;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5804 goto matchnotsyntax;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5805
|
18262
|
5806 case notwordchar:
|
|
5807 DEBUG_PRINT1 ("EXECUTING Emacs notwordchar.\n");
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5808 mcnt = (int) Sword;
|
18262
|
5809 matchnotsyntax:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5810 PREFETCH ();
|
18260
|
5811 #ifdef emacs
|
|
5812 {
|
20650
|
5813 int pos1 = SYNTAX_TABLE_BYTE_TO_CHAR (PTR_TO_OFFSET (d));
|
18260
|
5814 UPDATE_SYNTAX_TABLE (pos1);
|
|
5815 }
|
18262
|
5816 #endif
|
18260
|
5817 {
|
|
5818 int c, len;
|
|
5819
|
|
5820 if (multibyte)
|
|
5821 c = STRING_CHAR_AND_LENGTH (d, dend - d, len);
|
|
5822 else
|
|
5823 c = *d, len = 1;
|
|
5824
|
|
5825 if (SYNTAX (c) == (enum syntaxcode) mcnt)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5826 goto fail;
|
18260
|
5827 d += len;
|
|
5828 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5829 SET_REGS_MATCHED ();
|
16010
|
5830 break;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5831
|
18260
|
5832 case categoryspec:
|
|
5833 DEBUG_PRINT2 ("EXECUTING categoryspec %d.\n", *p);
|
|
5834 mcnt = *p++;
|
|
5835 PREFETCH ();
|
|
5836 {
|
|
5837 int c, len;
|
|
5838
|
|
5839 if (multibyte)
|
|
5840 c = STRING_CHAR_AND_LENGTH (d, dend - d, len);
|
|
5841 else
|
|
5842 c = *d, len = 1;
|
|
5843
|
|
5844 if (!CHAR_HAS_CATEGORY (c, mcnt))
|
|
5845 goto fail;
|
|
5846 d += len;
|
|
5847 }
|
|
5848 SET_REGS_MATCHED ();
|
|
5849 break;
|
|
5850
|
|
5851 case notcategoryspec:
|
|
5852 DEBUG_PRINT2 ("EXECUTING notcategoryspec %d.\n", *p);
|
|
5853 mcnt = *p++;
|
|
5854 PREFETCH ();
|
|
5855 {
|
|
5856 int c, len;
|
|
5857
|
|
5858 if (multibyte)
|
|
5859 c = STRING_CHAR_AND_LENGTH (d, dend - d, len);
|
|
5860 else
|
|
5861 c = *d, len = 1;
|
|
5862
|
|
5863 if (CHAR_HAS_CATEGORY (c, mcnt))
|
|
5864 goto fail;
|
|
5865 d += len;
|
|
5866 }
|
|
5867 SET_REGS_MATCHED ();
|
|
5868 break;
|
|
5869
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5870 #else /* not emacs */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5871 case wordchar:
|
18260
|
5872 DEBUG_PRINT1 ("EXECUTING non-Emacs wordchar.\n");
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5873 PREFETCH ();
|
18260
|
5874 if (!WORDCHAR_P (d))
|
|
5875 goto fail;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5876 SET_REGS_MATCHED ();
|
18260
|
5877 d++;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5878 break;
|
13565
|
5879
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5880 case notwordchar:
|
18260
|
5881 DEBUG_PRINT1 ("EXECUTING non-Emacs notwordchar.\n");
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5882 PREFETCH ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5883 if (WORDCHAR_P (d))
|
18260
|
5884 goto fail;
|
|
5885 SET_REGS_MATCHED ();
|
|
5886 d++;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5887 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5888 #endif /* not emacs */
|
13565
|
5889
|
18260
|
5890 default:
|
|
5891 abort ();
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5892 }
|
18260
|
5893 continue; /* Successfully executed one pattern command; keep going. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5894
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5895
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5896 /* We goto here if a matching operation fails. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5897 fail:
|
24119
aceb3b94328d
(re_match_2_internal) [WINDOWSNT & emacs]: Insert QUIT at various places.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
5898 #if defined (WINDOWSNT) && defined (emacs)
|
aceb3b94328d
(re_match_2_internal) [WINDOWSNT & emacs]: Insert QUIT at various places.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
5899 QUIT;
|
aceb3b94328d
(re_match_2_internal) [WINDOWSNT & emacs]: Insert QUIT at various places.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
5900 #endif
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5901 if (!FAIL_STACK_EMPTY ())
|
18260
|
5902 { /* A restart point is known. Restore to that state. */
|
|
5903 DEBUG_PRINT1 ("\nFAIL:\n");
|
|
5904 POP_FAILURE_POINT (d, p,
|
|
5905 lowest_active_reg, highest_active_reg,
|
|
5906 regstart, regend, reg_info);
|
|
5907
|
|
5908 /* If this failure point is a dummy, try the next one. */
|
|
5909 if (!p)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5910 goto fail;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5911
|
18260
|
5912 /* If we failed to the end of the pattern, don't examine *p. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5913 assert (p <= pend);
|
18260
|
5914 if (p < pend)
|
|
5915 {
|
|
5916 boolean is_a_jump_n = false;
|
|
5917
|
|
5918 /* If failed to a backwards jump that's part of a repetition
|
|
5919 loop, need to pop this failure point and use the next one. */
|
|
5920 switch ((re_opcode_t) *p)
|
|
5921 {
|
|
5922 case jump_n:
|
|
5923 is_a_jump_n = true;
|
|
5924 case maybe_pop_jump:
|
|
5925 case pop_failure_jump:
|
|
5926 case jump:
|
|
5927 p1 = p + 1;
|
|
5928 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
|
|
5929 p1 += mcnt;
|
|
5930
|
|
5931 if ((is_a_jump_n && (re_opcode_t) *p1 == succeed_n)
|
|
5932 || (!is_a_jump_n
|
|
5933 && (re_opcode_t) *p1 == on_failure_jump))
|
|
5934 goto fail;
|
|
5935 break;
|
|
5936 default:
|
|
5937 /* do nothing */ ;
|
|
5938 }
|
|
5939 }
|
|
5940
|
|
5941 if (d >= string1 && d <= end1)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5942 dend = end_match_1;
|
18260
|
5943 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5944 else
|
18260
|
5945 break; /* Matching at this starting point really fails. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5946 } /* for (;;) */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5947
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5948 if (best_regs_set)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5949 goto restore_best_regs;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5950
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5951 FREE_VARIABLES ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5952
|
18260
|
5953 return -1; /* Failure to match. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5954 } /* re_match_2 */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5955
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5956 /* Subroutine definitions for re_match_2. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5957
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5958
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5959 /* We are passed P pointing to a register number after a start_memory.
|
13565
|
5960
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5961 Return true if the pattern up to the corresponding stop_memory can
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5962 match the empty string, and false otherwise.
|
13565
|
5963
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5964 If we find the matching stop_memory, sets P to point to one past its number.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5965 Otherwise, sets P to an undefined byte less than or equal to END.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5966
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5967 We don't handle duplicates properly (yet). */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5968
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5969 static boolean
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5970 group_match_null_string_p (p, end, reg_info)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5971 unsigned char **p, *end;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5972 register_info_type *reg_info;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5973 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5974 int mcnt;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5975 /* Point to after the args to the start_memory. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5976 unsigned char *p1 = *p + 2;
|
13565
|
5977
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5978 while (p1 < end)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5979 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5980 /* Skip over opcodes that can match nothing, and return true or
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5981 false, as appropriate, when we get to one that can't, or to the
|
18260
|
5982 matching stop_memory. */
|
13565
|
5983
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5984 switch ((re_opcode_t) *p1)
|
18260
|
5985 {
|
|
5986 /* Could be either a loop or a series of alternatives. */
|
|
5987 case on_failure_jump:
|
|
5988 p1++;
|
|
5989 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
|
|
5990
|
|
5991 /* If the next operation is not a jump backwards in the
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5992 pattern. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5993
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5994 if (mcnt >= 0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
5995 {
|
18260
|
5996 /* Go through the on_failure_jumps of the alternatives,
|
|
5997 seeing if any of the alternatives cannot match nothing.
|
|
5998 The last alternative starts with only a jump,
|
|
5999 whereas the rest start with on_failure_jump and end
|
|
6000 with a jump, e.g., here is the pattern for `a|b|c':
|
|
6001
|
|
6002 /on_failure_jump/0/6/exactn/1/a/jump_past_alt/0/6
|
|
6003 /on_failure_jump/0/6/exactn/1/b/jump_past_alt/0/3
|
|
6004 /exactn/1/c
|
|
6005
|
|
6006 So, we have to first go through the first (n-1)
|
|
6007 alternatives and then deal with the last one separately. */
|
|
6008
|
|
6009
|
|
6010 /* Deal with the first (n-1) alternatives, which start
|
|
6011 with an on_failure_jump (see above) that jumps to right
|
|
6012 past a jump_past_alt. */
|
|
6013
|
|
6014 while ((re_opcode_t) p1[mcnt-3] == jump_past_alt)
|
|
6015 {
|
|
6016 /* `mcnt' holds how many bytes long the alternative
|
|
6017 is, including the ending `jump_past_alt' and
|
|
6018 its number. */
|
|
6019
|
|
6020 if (!alt_match_null_string_p (p1, p1 + mcnt - 3,
|
|
6021 reg_info))
|
|
6022 return false;
|
|
6023
|
|
6024 /* Move to right after this alternative, including the
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6025 jump_past_alt. */
|
18260
|
6026 p1 += mcnt;
|
|
6027
|
|
6028 /* Break if it's the beginning of an n-th alternative
|
|
6029 that doesn't begin with an on_failure_jump. */
|
|
6030 if ((re_opcode_t) *p1 != on_failure_jump)
|
|
6031 break;
|
13565
|
6032
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6033 /* Still have to check that it's not an n-th
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6034 alternative that starts with an on_failure_jump. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6035 p1++;
|
18260
|
6036 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
|
|
6037 if ((re_opcode_t) p1[mcnt-3] != jump_past_alt)
|
|
6038 {
|
|
6039 /* Get to the beginning of the n-th alternative. */
|
|
6040 p1 -= 3;
|
|
6041 break;
|
|
6042 }
|
|
6043 }
|
|
6044
|
|
6045 /* Deal with the last alternative: go back and get number
|
|
6046 of the `jump_past_alt' just before it. `mcnt' contains
|
|
6047 the length of the alternative. */
|
|
6048 EXTRACT_NUMBER (mcnt, p1 - 2);
|
|
6049
|
|
6050 if (!alt_match_null_string_p (p1, p1 + mcnt, reg_info))
|
|
6051 return false;
|
|
6052
|
|
6053 p1 += mcnt; /* Get past the n-th alternative. */
|
|
6054 } /* if mcnt > 0 */
|
|
6055 break;
|
|
6056
|
|
6057
|
|
6058 case stop_memory:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6059 assert (p1[1] == **p);
|
18260
|
6060 *p = p1 + 2;
|
|
6061 return true;
|
|
6062
|
|
6063
|
|
6064 default:
|
|
6065 if (!common_op_match_null_string_p (&p1, end, reg_info))
|
|
6066 return false;
|
|
6067 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6068 } /* while p1 < end */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6069
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6070 return false;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6071 } /* group_match_null_string_p */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6072
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6073
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6074 /* Similar to group_match_null_string_p, but doesn't deal with alternatives:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6075 It expects P to be the first byte of a single alternative and END one
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6076 byte past the last. The alternative can contain groups. */
|
13565
|
6077
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6078 static boolean
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6079 alt_match_null_string_p (p, end, reg_info)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6080 unsigned char *p, *end;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6081 register_info_type *reg_info;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6082 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6083 int mcnt;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6084 unsigned char *p1 = p;
|
13565
|
6085
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6086 while (p1 < end)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6087 {
|
13565
|
6088 /* Skip over opcodes that can match nothing, and break when we get
|
18260
|
6089 to one that can't. */
|
13565
|
6090
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6091 switch ((re_opcode_t) *p1)
|
18260
|
6092 {
|
|
6093 /* It's a loop. */
|
|
6094 case on_failure_jump:
|
|
6095 p1++;
|
|
6096 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
|
|
6097 p1 += mcnt;
|
|
6098 break;
|
13565
|
6099
|
|
6100 default:
|
18260
|
6101 if (!common_op_match_null_string_p (&p1, end, reg_info))
|
|
6102 return false;
|
|
6103 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6104 } /* while p1 < end */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6105
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6106 return true;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6107 } /* alt_match_null_string_p */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6108
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6109
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6110 /* Deals with the ops common to group_match_null_string_p and
|
13565
|
6111 alt_match_null_string_p.
|
|
6112
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6113 Sets P to one after the op and its arguments, if any. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6114
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6115 static boolean
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6116 common_op_match_null_string_p (p, end, reg_info)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6117 unsigned char **p, *end;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6118 register_info_type *reg_info;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6119 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6120 int mcnt;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6121 boolean ret;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6122 int reg_no;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6123 unsigned char *p1 = *p;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6124
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6125 switch ((re_opcode_t) *p1++)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6126 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6127 case no_op:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6128 case begline:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6129 case endline:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6130 case begbuf:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6131 case endbuf:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6132 case wordbeg:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6133 case wordend:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6134 case wordbound:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6135 case notwordbound:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6136 #ifdef emacs
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6137 case before_dot:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6138 case at_dot:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6139 case after_dot:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6140 #endif
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6141 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6142
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6143 case start_memory:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6144 reg_no = *p1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6145 assert (reg_no > 0 && reg_no <= MAX_REGNUM);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6146 ret = group_match_null_string_p (&p1, end, reg_info);
|
13565
|
6147
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6148 /* Have to set this here in case we're checking a group which
|
18260
|
6149 contains a group and a back reference to it. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6150
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6151 if (REG_MATCH_NULL_STRING_P (reg_info[reg_no]) == MATCH_NULL_UNSET_VALUE)
|
18260
|
6152 REG_MATCH_NULL_STRING_P (reg_info[reg_no]) = ret;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6153
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6154 if (!ret)
|
18260
|
6155 return false;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6156 break;
|
13565
|
6157
|
18260
|
6158 /* If this is an optimized succeed_n for zero times, make the jump. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6159 case jump:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6160 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6161 if (mcnt >= 0)
|
18260
|
6162 p1 += mcnt;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6163 else
|
18260
|
6164 return false;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6165 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6166
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6167 case succeed_n:
|
18260
|
6168 /* Get to the number of times to succeed. */
|
13565
|
6169 p1 += 2;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6170 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6171
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6172 if (mcnt == 0)
|
18260
|
6173 {
|
|
6174 p1 -= 4;
|
|
6175 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
|
|
6176 p1 += mcnt;
|
|
6177 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6178 else
|
18260
|
6179 return false;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6180 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6181
|
13565
|
6182 case duplicate:
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6183 if (!REG_MATCH_NULL_STRING_P (reg_info[*p1]))
|
18260
|
6184 return false;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6185 break;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6186
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6187 case set_number_at:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6188 p1 += 4;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6189
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6190 default:
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6191 /* All other opcodes mean we cannot match the empty string. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6192 return false;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6193 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6194
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6195 *p = p1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6196 return true;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6197 } /* common_op_match_null_string_p */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6198
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6199
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6200 /* Return zero if TRANSLATE[S1] and TRANSLATE[S2] are identical for LEN
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6201 bytes; nonzero otherwise. */
|
13565
|
6202
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6203 static int
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6204 bcmp_translate (s1, s2, len, translate)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6205 unsigned char *s1, *s2;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6206 register int len;
|
13250
|
6207 RE_TRANSLATE_TYPE translate;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6208 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6209 register unsigned char *p1 = s1, *p2 = s2;
|
21348
|
6210 unsigned char *p1_end = s1 + len;
|
|
6211 unsigned char *p2_end = s2 + len;
|
|
6212
|
|
6213 while (p1 != p1_end && p2 != p2_end)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6214 {
|
21348
|
6215 int p1_charlen, p2_charlen;
|
|
6216 int p1_ch, p2_ch;
|
|
6217
|
|
6218 p1_ch = STRING_CHAR_AND_LENGTH (p1, p1_end - p1, p1_charlen);
|
|
6219 p2_ch = STRING_CHAR_AND_LENGTH (p2, p2_end - p2, p2_charlen);
|
|
6220
|
|
6221 if (RE_TRANSLATE (translate, p1_ch)
|
|
6222 != RE_TRANSLATE (translate, p2_ch))
|
18614
|
6223 return 1;
|
21348
|
6224
|
|
6225 p1 += p1_charlen, p2 += p2_charlen;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6226 }
|
21348
|
6227
|
|
6228 if (p1 != p1_end || p2 != p2_end)
|
|
6229 return 1;
|
|
6230
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6231 return 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6232 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6233
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6234 /* Entry points for GNU code. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6235
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6236 /* re_compile_pattern is the GNU regular expression compiler: it
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6237 compiles PATTERN (of length SIZE) and puts the result in BUFP.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6238 Returns 0 if the pattern was valid, otherwise an error string.
|
13565
|
6239
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6240 Assumes the `allocated' (and perhaps `buffer') and `translate' fields
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6241 are set in BUFP on entry.
|
13565
|
6242
|
18260
|
6243 We call regex_compile to do the actual compilation. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6244
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6245 const char *
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6246 re_compile_pattern (pattern, length, bufp)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6247 const char *pattern;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6248 int length;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6249 struct re_pattern_buffer *bufp;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6250 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6251 reg_errcode_t ret;
|
13565
|
6252
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6253 /* GNU code is written to assume at least RE_NREGS registers will be set
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6254 (and at least one extra will be -1). */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6255 bufp->regs_allocated = REGS_UNALLOCATED;
|
13565
|
6256
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6257 /* And GNU code determines whether or not to get register information
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6258 by passing null for the REGS argument to re_match, etc., not by
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6259 setting no_sub. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6260 bufp->no_sub = 0;
|
13565
|
6261
|
18260
|
6262 /* Match anchors at newline. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6263 bufp->newline_anchor = 1;
|
13565
|
6264
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6265 ret = regex_compile (pattern, length, re_syntax_options, bufp);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6266
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6267 if (!ret)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6268 return NULL;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6269 return gettext (re_error_msgid[(int) ret]);
|
13565
|
6270 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6271
|
18260
|
6272 /* Entry points compatible with 4.2 BSD regex library. We don't define
|
|
6273 them unless specifically requested. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6274
|
15285
c2b4f8533c55
Tue May 21 19:18:05 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
Roland McGrath <roland@gnu.org>
diff
changeset
|
6275 #if defined (_REGEX_RE_COMP) || defined (_LIBC)
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6276
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6277 /* BSD has one and only one pattern buffer. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6278 static struct re_pattern_buffer re_comp_buf;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6279
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6280 char *
|
15635
89f7ba4ccd22
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
diff
changeset
|
6281 #ifdef _LIBC
|
89f7ba4ccd22
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
diff
changeset
|
6282 /* Make these definitions weak in libc, so POSIX programs can redefine
|
89f7ba4ccd22
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
diff
changeset
|
6283 these names if they don't use our functions, and still use
|
89f7ba4ccd22
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
diff
changeset
|
6284 regcomp/regexec below without link errors. */
|
89f7ba4ccd22
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
diff
changeset
|
6285 weak_function
|
89f7ba4ccd22
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
diff
changeset
|
6286 #endif
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6287 re_comp (s)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6288 const char *s;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6289 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6290 reg_errcode_t ret;
|
13565
|
6291
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6292 if (!s)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6293 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6294 if (!re_comp_buf.buffer)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6295 return gettext ("No previous regular expression");
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6296 return 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6297 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6298
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6299 if (!re_comp_buf.buffer)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6300 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6301 re_comp_buf.buffer = (unsigned char *) malloc (200);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6302 if (re_comp_buf.buffer == NULL)
|
18260
|
6303 return gettext (re_error_msgid[(int) REG_ESPACE]);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6304 re_comp_buf.allocated = 200;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6305
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6306 re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6307 if (re_comp_buf.fastmap == NULL)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6308 return gettext (re_error_msgid[(int) REG_ESPACE]);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6309 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6310
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6311 /* Since `re_exec' always passes NULL for the `regs' argument, we
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6312 don't need to initialize the pattern buffer fields which affect it. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6313
|
18260
|
6314 /* Match anchors at newlines. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6315 re_comp_buf.newline_anchor = 1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6316
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6317 ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf);
|
13565
|
6318
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6319 if (!ret)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6320 return NULL;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6321
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6322 /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6323 return (char *) gettext (re_error_msgid[(int) ret]);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6324 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6325
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6326
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6327 int
|
15635
89f7ba4ccd22
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
diff
changeset
|
6328 #ifdef _LIBC
|
89f7ba4ccd22
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
diff
changeset
|
6329 weak_function
|
89f7ba4ccd22
[_LIBC] (re_comp, re_exec): Use `weak_function' keyword in defn instead of
Roland McGrath <roland@gnu.org>
diff
changeset
|
6330 #endif
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6331 re_exec (s)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6332 const char *s;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6333 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6334 const int len = strlen (s);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6335 return
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6336 0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6337 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6338 #endif /* _REGEX_RE_COMP */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6339
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6340 /* POSIX.2 functions. Don't define these for Emacs. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6341
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6342 #ifndef emacs
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6343
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6344 /* regcomp takes a regular expression as a string and compiles it.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6345
|
18260
|
6346 PREG is a regex_t *. We do not expect any fields to be initialized,
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6347 since POSIX says we shouldn't. Thus, we set
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6348
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6349 `buffer' to the compiled pattern;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6350 `used' to the length of the compiled pattern;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6351 `syntax' to RE_SYNTAX_POSIX_EXTENDED if the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6352 REG_EXTENDED bit in CFLAGS is set; otherwise, to
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6353 RE_SYNTAX_POSIX_BASIC;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6354 `newline_anchor' to REG_NEWLINE being set in CFLAGS;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6355 `fastmap' and `fastmap_accurate' to zero;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6356 `re_nsub' to the number of subexpressions in PATTERN.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6357
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6358 PATTERN is the address of the pattern string.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6359
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6360 CFLAGS is a series of bits which affect compilation.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6361
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6362 If REG_EXTENDED is set, we use POSIX extended syntax; otherwise, we
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6363 use POSIX basic syntax.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6364
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6365 If REG_NEWLINE is set, then . and [^...] don't match newline.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6366 Also, regexec will try a match beginning after every newline.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6367
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6368 If REG_ICASE is set, then we considers upper- and lowercase
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6369 versions of letters to be equivalent when matching.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6370
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6371 If REG_NOSUB is set, then when PREG is passed to regexec, that
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6372 routine will report only success or failure, and nothing about the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6373 registers.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6374
|
18260
|
6375 It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6376 the return codes and their meanings.) */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6377
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6378 int
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6379 regcomp (preg, pattern, cflags)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6380 regex_t *preg;
|
13565
|
6381 const char *pattern;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6382 int cflags;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6383 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6384 reg_errcode_t ret;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6385 unsigned syntax
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6386 = (cflags & REG_EXTENDED) ?
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6387 RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6388
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6389 /* regex_compile will allocate the space for the compiled pattern. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6390 preg->buffer = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6391 preg->allocated = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6392 preg->used = 0;
|
13565
|
6393
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6394 /* Don't bother to use a fastmap when searching. This simplifies the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6395 REG_NEWLINE case: if we used a fastmap, we'd have to put all the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6396 characters after newlines into the fastmap. This way, we just try
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6397 every character. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6398 preg->fastmap = 0;
|
13565
|
6399
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6400 if (cflags & REG_ICASE)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6401 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6402 unsigned i;
|
13565
|
6403
|
13250
|
6404 preg->translate
|
|
6405 = (RE_TRANSLATE_TYPE) malloc (CHAR_SET_SIZE
|
|
6406 * sizeof (*(RE_TRANSLATE_TYPE)0));
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6407 if (preg->translate == NULL)
|
18260
|
6408 return (int) REG_ESPACE;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6409
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6410 /* Map uppercase characters to corresponding lowercase ones. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6411 for (i = 0; i < CHAR_SET_SIZE; i++)
|
18260
|
6412 preg->translate[i] = ISUPPER (i) ? tolower (i) : i;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6413 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6414 else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6415 preg->translate = NULL;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6416
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6417 /* If REG_NEWLINE is set, newlines are treated differently. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6418 if (cflags & REG_NEWLINE)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6419 { /* REG_NEWLINE implies neither . nor [^...] match newline. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6420 syntax &= ~RE_DOT_NEWLINE;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6421 syntax |= RE_HAT_LISTS_NOT_NEWLINE;
|
18260
|
6422 /* It also changes the matching behavior. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6423 preg->newline_anchor = 1;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6424 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6425 else
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6426 preg->newline_anchor = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6427
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6428 preg->no_sub = !!(cflags & REG_NOSUB);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6429
|
13565
|
6430 /* POSIX says a null character in the pattern terminates it, so we
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6431 can use strlen here in compiling the pattern. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6432 ret = regex_compile (pattern, strlen (pattern), syntax, preg);
|
13565
|
6433
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6434 /* POSIX doesn't distinguish between an unmatched open-group and an
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6435 unmatched close-group: both are REG_EPAREN. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6436 if (ret == REG_ERPAREN) ret = REG_EPAREN;
|
13565
|
6437
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6438 return (int) ret;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6439 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6440
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6441
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6442 /* regexec searches for a given pattern, specified by PREG, in the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6443 string STRING.
|
13565
|
6444
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6445 If NMATCH is zero or REG_NOSUB was set in the cflags argument to
|
18260
|
6446 `regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6447 least NMATCH elements, and we set them to the offsets of the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6448 corresponding matched substrings.
|
13565
|
6449
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6450 EFLAGS specifies `execution flags' which affect matching: if
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6451 REG_NOTBOL is set, then ^ does not match at the beginning of the
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6452 string; if REG_NOTEOL is set, then $ does not match at the end.
|
13565
|
6453
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6454 We return 0 if we find a match and REG_NOMATCH if not. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6455
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6456 int
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6457 regexec (preg, string, nmatch, pmatch, eflags)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6458 const regex_t *preg;
|
13565
|
6459 const char *string;
|
|
6460 size_t nmatch;
|
|
6461 regmatch_t pmatch[];
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6462 int eflags;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6463 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6464 int ret;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6465 struct re_registers regs;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6466 regex_t private_preg;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6467 int len = strlen (string);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6468 boolean want_reg_info = !preg->no_sub && nmatch > 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6469
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6470 private_preg = *preg;
|
13565
|
6471
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6472 private_preg.not_bol = !!(eflags & REG_NOTBOL);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6473 private_preg.not_eol = !!(eflags & REG_NOTEOL);
|
13565
|
6474
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6475 /* The user has told us exactly how many registers to return
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6476 information about, via `nmatch'. We have to pass that on to the
|
18260
|
6477 matching routines. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6478 private_preg.regs_allocated = REGS_FIXED;
|
13565
|
6479
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6480 if (want_reg_info)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6481 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6482 regs.num_regs = nmatch;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6483 regs.start = TALLOC (nmatch, regoff_t);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6484 regs.end = TALLOC (nmatch, regoff_t);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6485 if (regs.start == NULL || regs.end == NULL)
|
18260
|
6486 return (int) REG_NOMATCH;
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6487 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6488
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6489 /* Perform the searching operation. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6490 ret = re_search (&private_preg, string, len,
|
18260
|
6491 /* start: */ 0, /* range: */ len,
|
|
6492 want_reg_info ? ®s : (struct re_registers *) 0);
|
13565
|
6493
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6494 /* Copy the register information to the POSIX structure. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6495 if (want_reg_info)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6496 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6497 if (ret >= 0)
|
18260
|
6498 {
|
|
6499 unsigned r;
|
|
6500
|
|
6501 for (r = 0; r < nmatch; r++)
|
|
6502 {
|
|
6503 pmatch[r].rm_so = regs.start[r];
|
|
6504 pmatch[r].rm_eo = regs.end[r];
|
|
6505 }
|
|
6506 }
|
|
6507
|
|
6508 /* If we needed the temporary register info, free the space now. */
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6509 free (regs.start);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6510 free (regs.end);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6511 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6512
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6513 /* We want zero return to mean success, unlike `re_search'. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6514 return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6515 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6516
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6517
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6518 /* Returns a message corresponding to an error code, ERRCODE, returned
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6519 from either regcomp or regexec. We don't use PREG here. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6520
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6521 size_t
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6522 regerror (errcode, preg, errbuf, errbuf_size)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6523 int errcode;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6524 const regex_t *preg;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6525 char *errbuf;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6526 size_t errbuf_size;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6527 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6528 const char *msg;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6529 size_t msg_size;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6530
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6531 if (errcode < 0
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6532 || errcode >= (sizeof (re_error_msgid) / sizeof (re_error_msgid[0])))
|
13565
|
6533 /* Only error codes returned by the rest of the code should be passed
|
18260
|
6534 to this routine. If we are given anything else, or if other regex
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6535 code generates an invalid error code, then the program has a bug.
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6536 Dump core so we can fix it. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6537 abort ();
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6538
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6539 msg = gettext (re_error_msgid[errcode]);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6540
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6541 msg_size = strlen (msg) + 1; /* Includes the null. */
|
13565
|
6542
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6543 if (errbuf_size != 0)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6544 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6545 if (msg_size > errbuf_size)
|
18260
|
6546 {
|
|
6547 strncpy (errbuf, msg, errbuf_size - 1);
|
|
6548 errbuf[errbuf_size - 1] = 0;
|
|
6549 }
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6550 else
|
18260
|
6551 strcpy (errbuf, msg);
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6552 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6553
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6554 return msg_size;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6555 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6556
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6557
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6558 /* Free dynamically allocated space used by PREG. */
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6559
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6560 void
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6561 regfree (preg)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6562 regex_t *preg;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6563 {
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6564 if (preg->buffer != NULL)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6565 free (preg->buffer);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6566 preg->buffer = NULL;
|
13565
|
6567
|
11864
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6568 preg->allocated = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6569 preg->used = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6570
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6571 if (preg->fastmap != NULL)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6572 free (preg->fastmap);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6573 preg->fastmap = NULL;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6574 preg->fastmap_accurate = 0;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6575
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6576 if (preg->translate != NULL)
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6577 free (preg->translate);
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6578 preg->translate = NULL;
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6579 }
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6580
|
620c7195b48f
Add `#ifdef _LIBC' in a few places, so this can be compiled in libc.
Roland McGrath <roland@gnu.org>
diff
changeset
|
6581 #endif /* not emacs */
|