annotate src/regex.c @ 209:41ff10fd062f r20-4b3

Import from CVS: tag r20-4b3
author cvs
date Mon, 13 Aug 2007 10:04:58 +0200
parents 850242ba4a81
children 52952cbfc5b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Extended regular expression matching and search library,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 version 0.12, extended for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 (Implements POSIX draft P10003.2/D11.2, except for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 internationalization features.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 Copyright (C) 1995 Sun Microsystems, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 Copyright (C) 1995 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 This program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 along with this program; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 /* Synched up with: FSF 19.29. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 /* Changes made for XEmacs:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 (1) the REGEX_BEGLINE_CHECK code from the XEmacs v18 regex routines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 was added. This causes a huge speedup in font-locking.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (2) Rel-alloc is disabled when the MMAP version of rel-alloc is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 being used, because it's too slow -- all those calls to mmap()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 add humongous overhead.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
34 (3) Lots and lots of changes for Mule. They are bracketed by
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
35 `#ifdef MULE' or with comments that have `XEmacs' in them.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #ifdef HAVE_CONFIG_H
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
42 #ifndef REGISTER /* Rigidly enforced as of 20.3 */
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
43 #define REGISTER
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
44 #endif
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
45
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
46 #ifndef _GNU_SOURCE
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
47 #define _GNU_SOURCE 1
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
48 #endif
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
49
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
50 /* We assume non-Mule if emacs isn't defined. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
51 #ifndef emacs
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
52 #undef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
53 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
54
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 /* We need this for `regex.h', and perhaps for the Emacs include files. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 /* This is for other GNU distributions with internationalized messages. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 #if defined (I18N3) && (defined (HAVE_LIBINTL_H) || defined (_LIBC))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 # include <libintl.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 # define gettext(msgid) (msgid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 /* XEmacs: define this to add in a speedup for patterns anchored at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 the beginning of a line. Keep the ifdefs so that it's easier to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 tell where/why this code has diverged from v19. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 #define REGEX_BEGLINE_CHECK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 /* XEmacs: the current mmap-based ralloc handles small blocks very
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 poorly, so we disable it here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 #if defined (REL_ALLOC) && defined (HAVE_MMAP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 # undef REL_ALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 /* The `emacs' switch turns on certain matching commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 that make sense only in Emacs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 #include "syntax.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 #if (defined (DEBUG_XEMACS) && !defined (DEBUG))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 #define DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
89 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
90
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
91 Lisp_Object Vthe_lisp_rangetab;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
92
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
93 void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
94 complex_vars_of_regex (void)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
95 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
96 Vthe_lisp_rangetab = Fmake_range_table ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
97 staticpro (&Vthe_lisp_rangetab);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
98 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
99
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
100 #else /* not MULE */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
101
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 complex_vars_of_regex (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
107 #endif /* not MULE */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
108
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 #else /* not emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 /* If we are not linking with Emacs proper,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 we can't use the relocating allocator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 even if config.h says that we can. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 #undef REL_ALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 #if defined (STDC_HEADERS) || defined (_LIBC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 #include <stdlib.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 char *malloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 char *realloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 #define charptr_emchar(str) ((Emchar) (str)[0])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 #if (LONGBITS > INTBITS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 # define EMACS_INT long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 # define EMACS_INT int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 typedef int Emchar;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 #define INC_CHARPTR(p) ((p)++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 #define DEC_CHARPTR(p) ((p)--)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 /* When used in Emacs's lib-src, we need to get bzero and bcopy somehow.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 If nothing else has been done, use the method below. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 #ifdef INHIBIT_STRING_HEADER
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 #if !(defined (HAVE_BZERO) && defined (HAVE_BCOPY))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 #if !defined (bzero) && !defined (bcopy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 #undef INHIBIT_STRING_HEADER
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 /* This is the normal way of making sure we have a bcopy and a bzero.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 This is used in most programs--a few other programs avoid this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 by defining INHIBIT_STRING_HEADER. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 #ifndef INHIBIT_STRING_HEADER
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 #if defined (HAVE_STRING_H) || defined (STDC_HEADERS) || defined (_LIBC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 #include <string.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 #ifndef bcmp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 #define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 #ifndef bcopy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 #define bcopy(s, d, n) memcpy ((d), (s), (n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 #ifndef bzero
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 #define bzero(s, n) memset ((s), 0, (n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 #include <strings.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 /* Define the syntax stuff for \<, \>, etc. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 /* This must be nonzero for the wordchar and notwordchar pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 commands in re_match_2. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
171 #ifndef Sword
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 #define Sword 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 #ifdef SYNTAX_TABLE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 extern char *re_syntax_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 #else /* not SYNTAX_TABLE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 /* How many characters in the character set. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 #define CHAR_SET_SIZE 256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 static char re_syntax_table[CHAR_SET_SIZE];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 init_syntax_once (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 {
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
189 REGISTER int c;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 static int done = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 if (done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
195 memset (re_syntax_table, 0, sizeof (re_syntax_table));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 for (c = 'a'; c <= 'z'; c++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 re_syntax_table[c] = Sword;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 for (c = 'A'; c <= 'Z'; c++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 re_syntax_table[c] = Sword;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 for (c = '0'; c <= '9'; c++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 re_syntax_table[c] = Sword;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 re_syntax_table['_'] = Sword;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 done = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 #endif /* not SYNTAX_TABLE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 #define SYNTAX_UNSAFE(ignored, c) re_syntax_table[c]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 #endif /* not emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 /* Under XEmacs, this is needed because we don't define it elsewhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 #ifdef SWITCH_ENUM_BUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 #define SWITCH_ENUM_CAST(x) ((int)(x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 #define SWITCH_ENUM_CAST(x) (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 /* Get the interface, including the syntax bits. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 #include "regex.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 /* isalpha etc. are used for the character classes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 #include <ctype.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 /* Jim Meyering writes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 "... Some ctype macros are valid only for character codes that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 using /bin/cc or gcc but without giving an ansi option). So, all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ctype uses should be through macros like ISPRINT... If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 STDC_HEADERS is defined, then autoconf has verified that the ctype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 macros don't need to be guarded with references to isascii. ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 Defining isascii to 1 should let any compiler worth its salt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 eliminate the && through constant folding." */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 #define ISASCII_1(c) 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 #define ISASCII_1(c) isascii(c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
248 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
249 /* The IS*() macros can be passed any character, including an extended
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
250 one. We need to make sure there are no crashes, which would occur
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
251 otherwise due to out-of-bounds array references. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
252 #define ISASCII(c) (((unsigned EMACS_INT) (c)) < 0x100 && ISASCII_1 (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
253 #else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 #define ISASCII(c) ISASCII_1 (c)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
255 #endif /* MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 #ifdef isblank
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 #define ISBLANK(c) (ISASCII (c) && isblank (c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 #define ISBLANK(c) ((c) == ' ' || (c) == '\t')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 #ifdef isgraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 #define ISGRAPH(c) (ISASCII (c) && isgraph (c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 #define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 #define ISPRINT(c) (ISASCII (c) && isprint (c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 #define ISDIGIT(c) (ISASCII (c) && isdigit (c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 #define ISALNUM(c) (ISASCII (c) && isalnum (c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 #define ISALPHA(c) (ISASCII (c) && isalpha (c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 #define ISCNTRL(c) (ISASCII (c) && iscntrl (c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 #define ISLOWER(c) (ISASCII (c) && islower (c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 #define ISPUNCT(c) (ISASCII (c) && ispunct (c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 #define ISSPACE(c) (ISASCII (c) && isspace (c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 #define ISUPPER(c) (ISASCII (c) && isupper (c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 #define ISXDIGIT(c) (ISASCII (c) && isxdigit (c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 #ifndef NULL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 #define NULL (void *)0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 /* We remove any previous definition of `SIGN_EXTEND_CHAR',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 since ours (we hope) works properly with all combinations of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 machines, compilers, `char' and `unsigned char' argument types.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (Per Bothner suggested the basic approach.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 #undef SIGN_EXTEND_CHAR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 #if __STDC__
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 #define SIGN_EXTEND_CHAR(c) ((signed char) (c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 #else /* not __STDC__ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 /* As in Harbison and Steele. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 #define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 /* Should we use malloc or alloca? If REGEX_MALLOC is not defined, we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 use `alloca' instead of `malloc'. This is because using malloc in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 re_search* or re_match* could cause memory leaks when C-g is used in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 Emacs; also, malloc is slower and causes storage fragmentation. On
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
299 the other hand, malloc is more portable, and easier to debug.
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
300
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 Because we sometimes use alloca, some routines have to be macros,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 not functions -- `alloca'-allocated space disappears at the end of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 function it is called in. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 #ifdef REGEX_MALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 #define REGEX_ALLOCATE malloc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 #define REGEX_REALLOCATE(source, osize, nsize) realloc (source, nsize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 #define REGEX_FREE free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 #else /* not REGEX_MALLOC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 /* Emacs already defines alloca, sometimes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 #ifndef alloca
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 /* Make alloca work the best possible way. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 #ifdef __GNUC__
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 #define alloca __builtin_alloca
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 #else /* not __GNUC__ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 #if HAVE_ALLOCA_H
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 #include <alloca.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 #else /* not __GNUC__ or HAVE_ALLOCA_H */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 #ifndef _AIX /* Already did AIX, up at the top. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 char *alloca ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 #endif /* not _AIX */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
326 #endif /* not HAVE_ALLOCA_H */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 #endif /* not __GNUC__ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 #endif /* not alloca */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 #define REGEX_ALLOCATE alloca
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 /* Assumes a `char *destination' variable. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 #define REGEX_REALLOCATE(source, osize, nsize) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (destination = (char *) alloca (nsize), \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 memmove (destination, source, osize), \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 destination)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 /* No need to do anything to free, after alloca. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 #define REGEX_FREE(arg) ((void)0) /* Do nothing! But inhibit gcc warning. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 #endif /* not REGEX_MALLOC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 /* Define how to allocate the failure stack. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 #ifdef REL_ALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 #define REGEX_ALLOCATE_STACK(size) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 r_alloc ((char **) &failure_stack_ptr, (size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 #define REGEX_REALLOCATE_STACK(source, osize, nsize) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 r_re_alloc ((char **) &failure_stack_ptr, (nsize))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 #define REGEX_FREE_STACK(ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 r_alloc_free ((void **) &failure_stack_ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 #else /* not REL_ALLOC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 #ifdef REGEX_MALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 #define REGEX_ALLOCATE_STACK malloc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 #define REGEX_REALLOCATE_STACK(source, osize, nsize) realloc (source, nsize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 #define REGEX_FREE_STACK free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 #else /* not REGEX_MALLOC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 #define REGEX_ALLOCATE_STACK alloca
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 #define REGEX_REALLOCATE_STACK(source, osize, nsize) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 REGEX_REALLOCATE (source, osize, nsize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 /* No need to explicitly free anything. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 #define REGEX_FREE_STACK(arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 #endif /* not REGEX_MALLOC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 #endif /* not REL_ALLOC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 /* True if `size1' is non-NULL and PTR is pointing anywhere inside
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 `string1' or just past its end. This works if PTR is NULL, which is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 a good thing. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 #define FIRST_STRING_P(ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (size1 && string1 <= (ptr) && (ptr) <= string1 + size1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 /* (Re)Allocate N items of type T using malloc, or fail. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 #define TALLOC(n, t) ((t *) malloc ((n) * sizeof (t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 #define RETALLOC(addr, n, t) ((addr) = (t *) realloc (addr, (n) * sizeof (t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 #define RETALLOC_IF(addr, n, t) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 if (addr) RETALLOC((addr), (n), t); else (addr) = TALLOC ((n), t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 #define REGEX_TALLOC(n, t) ((t *) REGEX_ALLOCATE ((n) * sizeof (t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 #define BYTEWIDTH 8 /* In bits. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 #define STREQ(s1, s2) ((strcmp (s1, s2) == 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 #undef MAX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 #undef MIN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 #define MAX(a, b) ((a) > (b) ? (a) : (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 #define MIN(a, b) ((a) < (b) ? (a) : (b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 typedef char boolean;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 #define false 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 #define true 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 /* These are the command codes that appear in compiled regular
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 expressions. Some opcodes are followed by argument bytes. A
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 command code can specify any interpretation whatsoever for its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 arguments. Zero bytes may appear in the compiled regular expression. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 typedef enum
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 no_op = 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 /* Succeed right away--no more backtracking. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 succeed,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 /* Followed by one byte giving n, then by n literal bytes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 exactn,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 /* Matches any (more or less) character. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 anychar,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 /* Matches any one char belonging to specified set. First
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 following byte is number of bitmap bytes. Then come bytes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 for a bitmap saying which chars are in. Bits in each byte
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 are ordered low-bit-first. A character is in the set if its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 bit is 1. A character too large to have a bit in the map is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 automatically not in the set. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 charset,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 /* Same parameters as charset, but match any character that is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 not one of those specified. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 charset_not,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 /* Start remembering the text that is matched, for storing in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 register. Followed by one byte with the register number, in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 the range 0 to one less than the pattern buffer's re_nsub
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 field. Then followed by one byte with the number of groups
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 inner to this one. (This last has to be part of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 start_memory only because we need it in the on_failure_jump
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 of re_match_2.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 start_memory,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 /* Stop remembering the text that is matched and store it in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 memory register. Followed by one byte with the register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 number, in the range 0 to one less than `re_nsub' in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 pattern buffer, and one byte with the number of inner groups,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 just like `start_memory'. (We need the number of inner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 groups here because we don't have any easy way of finding the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 corresponding start_memory when we're at a stop_memory.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 stop_memory,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 /* Match a duplicate of something remembered. Followed by one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 byte containing the register number. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 duplicate,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 /* Fail unless at beginning of line. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 begline,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 /* Fail unless at end of line. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 endline,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 /* Succeeds if at beginning of buffer (if emacs) or at beginning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 of string to be matched (if not). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 begbuf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 /* Analogously, for end of buffer/string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 endbuf,
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
466
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 /* Followed by two byte relative address to which to jump. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
468 jump,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 /* Same as jump, but marks the end of an alternative. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 jump_past_alt,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 /* Followed by two-byte relative address of place to resume at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 in case of failure. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 on_failure_jump,
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
476
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 /* Like on_failure_jump, but pushes a placeholder instead of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 current string position when executed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 on_failure_keep_string_jump,
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
480
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 /* Throw away latest failure point and then jump to following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 two-byte relative address. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 pop_failure_jump,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 /* Change to pop_failure_jump if know won't have to backtrack to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 match; otherwise change to jump. This is used to jump
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 back to the beginning of a repeat. If what follows this jump
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 clearly won't match what the repeat does, such that we can be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 sure that there is no use backtracking out of repetitions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 already matched, then we change it to a pop_failure_jump.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 Followed by two-byte address. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 maybe_pop_jump,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 /* Jump to following two-byte address, and push a dummy failure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 point. This failure point will be thrown away if an attempt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 is made to use it for a failure. A `+' construct makes this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 before the first repeat. Also used as an intermediary kind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 of jump when compiling an alternative. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 dummy_failure_jump,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 /* Push a dummy failure point and continue. Used at the end of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 alternatives. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 push_dummy_failure,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 /* Followed by two-byte relative address and two-byte number n.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 After matching N times, jump to the address upon failure. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 succeed_n,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 /* Followed by two-byte relative address, and two-byte number n.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 Jump to the address N times, then fail. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 jump_n,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 /* Set the following two-byte relative address to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 subsequent two-byte number. The address *includes* the two
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 bytes of number. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 set_number_at,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 wordchar, /* Matches any word-constituent character. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 notwordchar, /* Matches any char that is not a word-constituent. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 wordbeg, /* Succeeds if at word beginning. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 wordend, /* Succeeds if at word end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 wordbound, /* Succeeds if at a word boundary. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 notwordbound /* Succeeds if not at a word boundary. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ,before_dot, /* Succeeds if before point. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 at_dot, /* Succeeds if at point. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 after_dot, /* Succeeds if after point. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 /* Matches any character whose syntax is specified. Followed by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 a byte which contains a syntax code, e.g., Sword. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 syntaxspec,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 /* Matches any character whose syntax is not that specified. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 notsyntaxspec
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
538
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 #endif /* emacs */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
540
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
541 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
542 /* need extra stuff to be able to properly work with XEmacs/Mule
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
543 characters (which may take up more than one byte) */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
544
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
545 ,charset_mule, /* Matches any character belonging to specified set.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
546 The set is stored in "unified range-table
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
547 format"; see rangetab.c. Unlike the `charset'
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
548 opcode, this can handle arbitrary characters. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
549
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
550 charset_mule_not /* Same parameters as charset_mule, but match any
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
551 character that is not one of those specified. */
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
552
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
553 /* 97/2/17 jhod: The following two were merged back in from the Mule
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
554 2.3 code to enable some language specific processing */
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
555 ,categoryspec, /* Matches entries in the character category tables */
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
556 notcategoryspec /* The opposite of the above */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
557 #endif /* MULE */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
558
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 } re_opcode_t;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 /* Common operations on the compiled pattern. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 /* Store NUMBER in two contiguous bytes starting at DESTINATION. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 #define STORE_NUMBER(destination, number) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (destination)[0] = (number) & 0377; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (destination)[1] = (number) >> 8; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 /* Same as STORE_NUMBER, except increment DESTINATION to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 the byte after where the number is stored. Therefore, DESTINATION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 must be an lvalue. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 #define STORE_NUMBER_AND_INCR(destination, number) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 STORE_NUMBER (destination, number); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (destination) += 2; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 /* Put into DESTINATION a number stored in two contiguous bytes starting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 at SOURCE. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 #define EXTRACT_NUMBER(destination, source) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (destination) = *(source) & 0377; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 extract_number (int *dest, unsigned char *source)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 {
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
594 int temp = SIGN_EXTEND_CHAR (*(source + 1));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 *dest = *source & 0377;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 *dest += temp << 8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 #ifndef EXTRACT_MACROS /* To debug the macros. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 #undef EXTRACT_NUMBER
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 #define EXTRACT_NUMBER(dest, src) extract_number (&dest, src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 #endif /* not EXTRACT_MACROS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 #endif /* DEBUG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 /* Same as EXTRACT_NUMBER, except increment SOURCE to after the number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 SOURCE must be an lvalue. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 #define EXTRACT_NUMBER_AND_INCR(destination, source) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 EXTRACT_NUMBER (destination, source); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (source) += 2; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 extract_number_and_incr (int *destination, unsigned char **source)
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
618 {
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 extract_number (destination, *source);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 *source += 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 #ifndef EXTRACT_MACROS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 #undef EXTRACT_NUMBER_AND_INCR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 #define EXTRACT_NUMBER_AND_INCR(dest, src) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 extract_number_and_incr (&dest, &src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 #endif /* not EXTRACT_MACROS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 #endif /* DEBUG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 /* If DEBUG is defined, Regex prints many voluminous messages about what
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 it is doing (if the variable `debug' is nonzero). If linked with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 main program in `iregex.c', you can enter patterns and strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 interactively. And if linked with the main program in `main.c' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 the other test files, you can run the already-written tests. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 #if defined (DEBUG)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 /* We use standard I/O for debugging. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 #ifndef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 /* XEmacs provides its own version of assert() */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 /* It is useful to test things that ``must'' be true when debugging. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 #include <assert.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 static int debug = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 #define DEBUG_STATEMENT(e) e
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 #define DEBUG_PRINT1(x) if (debug) printf (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 #define DEBUG_PRINT2(x1, x2) if (debug) printf (x1, x2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 #define DEBUG_PRINT3(x1, x2, x3) if (debug) printf (x1, x2, x3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 #define DEBUG_PRINT4(x1, x2, x3, x4) if (debug) printf (x1, x2, x3, x4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 #define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 if (debug) print_partial_compiled_pattern (s, e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 #define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 if (debug) print_double_string (w, s1, sz1, s2, sz2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 /* Print the fastmap in human-readable form. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 print_fastmap (char *fastmap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 unsigned was_a_range = 0;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
667 unsigned i = 0;
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
668
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 while (i < (1 << BYTEWIDTH))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 if (fastmap[i++])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 was_a_range = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 putchar (i - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 while (i < (1 << BYTEWIDTH) && fastmap[i])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 was_a_range = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 i++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 if (was_a_range)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 printf ("-");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 putchar (i - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
687 putchar ('\n');
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 /* Print a compiled pattern string in human-readable form, starting at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 the START pointer into it and ending just before the pointer END. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 print_partial_compiled_pattern (unsigned char *start, unsigned char *end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 int mcnt, mcnt2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 unsigned char *p = start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 unsigned char *pend = end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 if (start == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 printf ("(null)\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
706
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 /* Loop over pattern commands. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 while (p < pend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 printf ("%d:\t", p - start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 switch ((re_opcode_t) *p++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 case no_op:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 printf ("/no_op");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 case exactn:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 mcnt = *p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 printf ("/exactn/%d", mcnt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 putchar ('/');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 putchar (*p++);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 while (--mcnt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 case start_memory:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 mcnt = *p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 printf ("/start_memory/%d/%d", mcnt, *p++);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 case stop_memory:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 mcnt = *p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 printf ("/stop_memory/%d/%d", mcnt, *p++);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 case duplicate:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 printf ("/duplicate/%d", *p++);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 case anychar:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 printf ("/anychar");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 case charset:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 case charset_not:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 {
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
750 REGISTER int c, last = -100;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
751 REGISTER int in_range = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 printf ("/charset [%s",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (re_opcode_t) *(p - 1) == charset_not ? "^" : "");
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
755
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 assert (p + *p < pend);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 for (c = 0; c < 256; c++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 if (((unsigned char) (c / 8) < *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 && (p[1 + (c/8)] & (1 << (c % 8))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 /* Are we starting a range? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 if (last + 1 == c && ! in_range)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 putchar ('-');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 in_range = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 /* Have we broken a range? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 else if (last + 1 != c && in_range)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 putchar (last);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 in_range = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
774
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 if (! in_range)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 putchar (c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 last = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 if (in_range)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 putchar (last);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 putchar (']');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 p += 1 + *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
790 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
791 case charset_mule:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
792 case charset_mule_not:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
793 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
794 int nentries, i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
795
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
796 printf ("/charset_mule [%s",
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
797 (re_opcode_t) *(p - 1) == charset_mule_not ? "^" : "");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
798 nentries = unified_range_table_nentries (p);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
799 for (i = 0; i < nentries; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
800 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
801 EMACS_INT first, last;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
802 Lisp_Object dummy_val;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
803
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
804 unified_range_table_get_range (p, i, &first, &last,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
805 &dummy_val);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
806 if (first < 0x100)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
807 putchar (first);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
808 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
809 printf ("(0x%x)", first);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
810 if (first != last)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
811 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
812 putchar ('-');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
813 if (last < 0x100)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
814 putchar (last);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
815 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
816 printf ("(0x%x)", last);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
817 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
818 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
819 putchar (']');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
820 p += unified_range_table_bytes_used (p);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
821 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
822 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
823 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
824
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 case begline:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 printf ("/begline");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 case endline:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 printf ("/endline");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 case on_failure_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 extract_number_and_incr (&mcnt, &p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 printf ("/on_failure_jump to %d", p + mcnt - start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 case on_failure_keep_string_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 extract_number_and_incr (&mcnt, &p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 printf ("/on_failure_keep_string_jump to %d", p + mcnt - start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 case dummy_failure_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 extract_number_and_incr (&mcnt, &p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 printf ("/dummy_failure_jump to %d", p + mcnt - start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 case push_dummy_failure:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 printf ("/push_dummy_failure");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
851
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 case maybe_pop_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 extract_number_and_incr (&mcnt, &p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 printf ("/maybe_pop_jump to %d", p + mcnt - start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 case pop_failure_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 extract_number_and_incr (&mcnt, &p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 printf ("/pop_failure_jump to %d", p + mcnt - start);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
860 break;
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
861
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 case jump_past_alt:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 extract_number_and_incr (&mcnt, &p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 printf ("/jump_past_alt to %d", p + mcnt - start);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
865 break;
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
866
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 case jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 extract_number_and_incr (&mcnt, &p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 printf ("/jump to %d", p + mcnt - start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
872 case succeed_n:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 extract_number_and_incr (&mcnt, &p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 extract_number_and_incr (&mcnt2, &p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 printf ("/succeed_n to %d, %d times", p + mcnt - start, mcnt2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
877
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
878 case jump_n:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 extract_number_and_incr (&mcnt, &p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 extract_number_and_incr (&mcnt2, &p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 printf ("/jump_n to %d, %d times", p + mcnt - start, mcnt2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
883
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
884 case set_number_at:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 extract_number_and_incr (&mcnt, &p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 extract_number_and_incr (&mcnt2, &p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 printf ("/set_number_at location %d to %d", p + mcnt - start, mcnt2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
889
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 case wordbound:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 printf ("/wordbound");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 case notwordbound:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 printf ("/notwordbound");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 case wordbeg:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 printf ("/wordbeg");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
901
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 case wordend:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 printf ("/wordend");
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
904
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 case before_dot:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 printf ("/before_dot");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 case at_dot:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 printf ("/at_dot");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 case after_dot:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 printf ("/after_dot");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 case syntaxspec:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 printf ("/syntaxspec");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 mcnt = *p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 printf ("/%d", mcnt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
923
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 case notsyntaxspec:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 printf ("/notsyntaxspec");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 mcnt = *p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 printf ("/%d", mcnt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
929
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
930 #ifdef MULE
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
931 /* 97/2/17 jhod Mule category patch */
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
932 case categoryspec:
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
933 printf ("/categoryspec");
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
934 mcnt = *p++;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
935 printf ("/%d", mcnt);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
936 break;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
937
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
938 case notcategoryspec:
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
939 printf ("/notcategoryspec");
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
940 mcnt = *p++;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
941 printf ("/%d", mcnt);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
942 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
943 /* end of category patch */
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
944 #endif /* MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 #endif /* emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 case wordchar:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 printf ("/wordchar");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
950
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 case notwordchar:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 printf ("/notwordchar");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 case begbuf:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 printf ("/begbuf");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 case endbuf:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 printf ("/endbuf");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 printf ("?%d", *(p-1));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 putchar ('\n');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 printf ("%d:\tend of pattern.\n", p - start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 print_compiled_pattern (struct re_pattern_buffer *bufp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 unsigned char *buffer = bufp->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 print_partial_compiled_pattern (buffer, buffer + bufp->used);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 printf ("%ld bytes used/%ld bytes allocated.\n", bufp->used,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 bufp->allocated);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 if (bufp->fastmap_accurate && bufp->fastmap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 printf ("fastmap: ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 print_fastmap (bufp->fastmap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 printf ("re_nsub: %ld\t", (long)bufp->re_nsub);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 printf ("regs_alloc: %d\t", bufp->regs_allocated);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 printf ("can_be_null: %d\t", bufp->can_be_null);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 printf ("newline_anchor: %d\n", bufp->newline_anchor);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 printf ("no_sub: %d\t", bufp->no_sub);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 printf ("not_bol: %d\t", bufp->not_bol);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 printf ("not_eol: %d\t", bufp->not_eol);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 printf ("syntax: %d\n", bufp->syntax);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 /* Perhaps we should print the translate table? */
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
998 /* and maybe the category table? */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 print_double_string (CONST char *where, CONST char *string1, int size1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 CONST char *string2, int size2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 unsigned this_char;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1007
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 if (where == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 printf ("(null)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 if (FIRST_STRING_P (where))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 for (this_char = where - string1; this_char < size1; this_char++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 putchar (string1[this_char]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1017 where = string2;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 for (this_char = where - string2; this_char < size2; this_char++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 putchar (string2[this_char]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 #else /* not DEBUG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 #undef assert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 #define assert(e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 #define DEBUG_STATEMENT(e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 #define DEBUG_PRINT1(x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 #define DEBUG_PRINT2(x1, x2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 #define DEBUG_PRINT3(x1, x2, x3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 #define DEBUG_PRINT4(x1, x2, x3, x4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 #define DEBUG_PRINT_COMPILED_PATTERN(p, s, e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 #define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 #endif /* not DEBUG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 /* Set by `re_set_syntax' to the current regexp syntax to recognize. Can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 also be assigned to arbitrarily: each pattern buffer stores its own
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 syntax, so it can be changed between regex compilations. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 /* This has no initializer because initialized variables in Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 become read-only after dumping. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 reg_syntax_t re_syntax_options;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 /* Specify the precise syntax of regexps for compilation. This provides
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 for compatibility for various utilities which historically have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 different, incompatible syntaxes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 The argument SYNTAX is a bit mask comprised of the various bits
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 defined in regex.h. We return the old syntax. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 reg_syntax_t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 re_set_syntax (reg_syntax_t syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 reg_syntax_t ret = re_syntax_options;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1059
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 re_syntax_options = syntax;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 return ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 /* This table gives an error message for each of the error codes listed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 in regex.h. Obviously the order here has to be same as there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 POSIX doesn't require that we do anything for REG_NOERROR,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 but why not be nice? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 static CONST char *re_error_msgid[] =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 { "Success", /* REG_NOERROR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 "No match", /* REG_NOMATCH */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 "Invalid regular expression", /* REG_BADPAT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 "Invalid collation character", /* REG_ECOLLATE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 "Invalid character class name", /* REG_ECTYPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 "Trailing backslash", /* REG_EESCAPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 "Invalid back reference", /* REG_ESUBREG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 "Unmatched [ or [^", /* REG_EBRACK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 "Unmatched ( or \\(", /* REG_EPAREN */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 "Unmatched \\{", /* REG_EBRACE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 "Invalid content of \\{\\}", /* REG_BADBR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 "Invalid range end", /* REG_ERANGE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 "Memory exhausted", /* REG_ESPACE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 "Invalid preceding regular expression", /* REG_BADRPT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 "Premature end of regular expression", /* REG_EEND */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 "Regular expression too big", /* REG_ESIZE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 "Unmatched ) or \\)", /* REG_ERPAREN */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 "Invalid syntax designator", /* REG_ESYNTAX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 #endif
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1090 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1091 "Ranges may not span charsets", /* REG_ERANGESPAN */
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
1092 "Invalid category designator", /* REG_ECATEGORY */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1093 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 /* Avoiding alloca during matching, to placate r_alloc. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 /* Define MATCH_MAY_ALLOCATE unless we need to make sure that the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 searching and matching functions should not call alloca. On some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 systems, alloca is implemented in terms of malloc, and if we're
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 using the relocating allocator routines, then malloc could cause a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 relocation, which might (if the strings being searched are in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 ralloc heap) shift the data out from underneath the regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 routines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1106 Here's another reason to avoid allocation: Emacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 processes input from X in a signal handler; processing X input may
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 call malloc; if input arrives while a matching routine is calling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 malloc, then we're scrod. But Emacs can't just block input while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 calling matching routines; then we don't notice interrupts when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 they come in. So, Emacs blocks input around all regexp calls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 except the matching calls, which it leaves unprotected, in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 faith that they will not malloc. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 /* Normally, this is fine. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 #define MATCH_MAY_ALLOCATE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 /* When using GNU C, we are not REALLY using the C alloca, no matter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 what config.h may say. So don't take precautions for it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 #ifdef __GNUC__
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 #undef C_ALLOCA
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 /* The match routines may not allocate if (1) they would do it with malloc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 and (2) it's not safe for them to use malloc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 Note that if REL_ALLOC is defined, matching would not use malloc for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 failure stack, but we would still use it for the register vectors;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 so REL_ALLOC should not affect this. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 #if (defined (C_ALLOCA) || defined (REGEX_MALLOC)) && defined (emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 #undef MATCH_MAY_ALLOCATE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 /* Failure stack declarations and macros; both re_compile_fastmap and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 re_match_2 use a failure stack. These have to be macros because of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 REGEX_ALLOCATE_STACK. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1137
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 /* Number of failure points for which to initially allocate space
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 when matching. If this number is exceeded, we allocate more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 space, so it is not a hard limit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 #ifndef INIT_FAILURE_ALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 #define INIT_FAILURE_ALLOC 5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 /* Roughly the maximum number of failure points on the stack. Would be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 exactly that if always used MAX_FAILURE_SPACE each time we failed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 This is a variable only so users of regex can assign to it; we never
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 change it ourselves. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 #if defined (MATCH_MAY_ALLOCATE)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1151 /* 4400 was enough to cause a crash on Alpha OSF/1,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1152 whose default stack limit is 2mb. */
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
1153 int re_max_failures = 20000;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 int re_max_failures = 2000;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 union fail_stack_elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 unsigned char *pointer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 int integer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 typedef union fail_stack_elt fail_stack_elt_t;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 typedef struct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 fail_stack_elt_t *stack;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 unsigned size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 unsigned avail; /* Offset of next open position. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 } fail_stack_type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 #define FAIL_STACK_EMPTY() (fail_stack.avail == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 #define FAIL_STACK_PTR_EMPTY() (fail_stack_ptr->avail == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 #define FAIL_STACK_FULL() (fail_stack.avail == fail_stack.size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 /* Define macros to initialize and free the failure stack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 Do `return -2' if the alloc fails. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 #ifdef MATCH_MAY_ALLOCATE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 #define INIT_FAIL_STACK() \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 fail_stack.stack = (fail_stack_elt_t *) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 REGEX_ALLOCATE_STACK (INIT_FAILURE_ALLOC * sizeof (fail_stack_elt_t)); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 if (fail_stack.stack == NULL) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 return -2; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 fail_stack.size = INIT_FAILURE_ALLOC; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 fail_stack.avail = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 #define RESET_FAIL_STACK() REGEX_FREE_STACK (fail_stack.stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 #define INIT_FAIL_STACK() \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 fail_stack.avail = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 #define RESET_FAIL_STACK()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 /* Double the size of FAIL_STACK, up to approximately `re_max_failures' items.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 Return 1 if succeeds, and 0 if either ran out of memory
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1208 allocating space for it or it was already too large.
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1209
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 REGEX_REALLOCATE_STACK requires `destination' be declared. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 #define DOUBLE_FAIL_STACK(fail_stack) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 ((fail_stack).size > re_max_failures * MAX_FAILURE_ITEMS \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 ? 0 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 : ((fail_stack).stack = (fail_stack_elt_t *) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 REGEX_REALLOCATE_STACK ((fail_stack).stack, \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 (fail_stack).size * sizeof (fail_stack_elt_t), \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 ((fail_stack).size << 1) * sizeof (fail_stack_elt_t)), \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 (fail_stack).stack == NULL \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 ? 0 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 : ((fail_stack).size <<= 1, \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1226 /* Push pointer POINTER on FAIL_STACK.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 Return 1 if was able to do so and 0 if ran out of memory allocating
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 space to do so. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 #define PUSH_PATTERN_OP(POINTER, FAIL_STACK) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 ((FAIL_STACK_FULL () \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 && !DOUBLE_FAIL_STACK (FAIL_STACK)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 ? 0 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 : ((FAIL_STACK).stack[(FAIL_STACK).avail++].pointer = POINTER, \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 /* Push a pointer value onto the failure stack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 Assumes the variable `fail_stack'. Probably should only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 be called from within `PUSH_FAILURE_POINT'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 #define PUSH_FAILURE_POINTER(item) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 fail_stack.stack[fail_stack.avail++].pointer = (unsigned char *) (item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 /* This pushes an integer-valued item onto the failure stack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 Assumes the variable `fail_stack'. Probably should only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 be called from within `PUSH_FAILURE_POINT'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 #define PUSH_FAILURE_INT(item) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 fail_stack.stack[fail_stack.avail++].integer = (item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 /* Push a fail_stack_elt_t value onto the failure stack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 Assumes the variable `fail_stack'. Probably should only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 be called from within `PUSH_FAILURE_POINT'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 #define PUSH_FAILURE_ELT(item) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 fail_stack.stack[fail_stack.avail++] = (item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 /* These three POP... operations complement the three PUSH... operations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 All assume that `fail_stack' is nonempty. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 #define POP_FAILURE_POINTER() fail_stack.stack[--fail_stack.avail].pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 #define POP_FAILURE_INT() fail_stack.stack[--fail_stack.avail].integer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 #define POP_FAILURE_ELT() fail_stack.stack[--fail_stack.avail]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 /* Used to omit pushing failure point id's when we're not debugging. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 #define DEBUG_PUSH PUSH_FAILURE_INT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 #define DEBUG_POP(item_addr) *(item_addr) = POP_FAILURE_INT ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 #define DEBUG_PUSH(item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 #define DEBUG_POP(item_addr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 /* Push the information about the state we will need
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1271 if we ever fail back to it.
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1272
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 Requires variables fail_stack, regstart, regend, reg_info, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 num_regs be declared. DOUBLE_FAIL_STACK requires `destination' be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 declared.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1276
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 Does `return FAILURE_CODE' if runs out of memory. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 #if !defined (REGEX_MALLOC) && !defined (REL_ALLOC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 #define DECLARE_DESTINATION char *destination;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 #define DECLARE_DESTINATION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 #define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 DECLARE_DESTINATION \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 /* Must be int, so when we don't save any registers, the arithmetic \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 of 0 + -1 isn't done as unsigned. */ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 int this_reg; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 DEBUG_STATEMENT (failure_id++); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 DEBUG_STATEMENT (nfailure_points_pushed++); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 DEBUG_PRINT2 ("\nPUSH_FAILURE_POINT #%u:\n", failure_id); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 DEBUG_PRINT2 (" Before push, next avail: %d\n", (fail_stack).avail);\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 DEBUG_PRINT2 (" size: %d\n", (fail_stack).size);\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 DEBUG_PRINT2 (" slots needed: %d\n", NUM_FAILURE_ITEMS); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 DEBUG_PRINT2 (" available: %d\n", REMAINING_AVAIL_SLOTS); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 /* Ensure we have enough space allocated for what we will push. */ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 if (!DOUBLE_FAIL_STACK (fail_stack)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 return failure_code; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 (fail_stack).size); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 DEBUG_PRINT2 (" slots available: %d\n", REMAINING_AVAIL_SLOTS);\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 /* Push the info, starting with the registers. */ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 DEBUG_PRINT1 ("\n"); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 for (this_reg = lowest_active_reg; this_reg <= highest_active_reg; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 this_reg++) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 DEBUG_PRINT2 (" Pushing reg: %d\n", this_reg); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 DEBUG_STATEMENT (num_regs_pushed++); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 \
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 169
diff changeset
1321 DEBUG_PRINT2 (" start: 0x%p\n", regstart[this_reg]); \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 PUSH_FAILURE_POINTER (regstart[this_reg]); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 \
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 169
diff changeset
1324 DEBUG_PRINT2 (" end: 0x%p\n", regend[this_reg]); \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 PUSH_FAILURE_POINTER (regend[this_reg]); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 DEBUG_PRINT2 (" info: 0x%lx\n ", \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 * (unsigned long *) (&reg_info[this_reg])); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 DEBUG_PRINT2 (" match_null=%d", \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 REG_MATCH_NULL_STRING_P (reg_info[this_reg])); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 DEBUG_PRINT2 (" active=%d", IS_ACTIVE (reg_info[this_reg])); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 DEBUG_PRINT2 (" matched_something=%d", \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 MATCHED_SOMETHING (reg_info[this_reg])); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 DEBUG_PRINT2 (" ever_matched=%d", \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 EVER_MATCHED_SOMETHING (reg_info[this_reg])); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 DEBUG_PRINT1 ("\n"); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 PUSH_FAILURE_ELT (reg_info[this_reg].word); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 DEBUG_PRINT2 (" Pushing low active reg: %d\n", lowest_active_reg);\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 PUSH_FAILURE_INT (lowest_active_reg); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 DEBUG_PRINT2 (" Pushing high active reg: %d\n", highest_active_reg);\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 PUSH_FAILURE_INT (highest_active_reg); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 \
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 169
diff changeset
1346 DEBUG_PRINT2 (" Pushing pattern 0x%p: ", pattern_place); \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 PUSH_FAILURE_POINTER (pattern_place); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 \
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 169
diff changeset
1350 DEBUG_PRINT2 (" Pushing string 0x%p: `", string_place); \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 size2); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 DEBUG_PRINT1 ("'\n"); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 PUSH_FAILURE_POINTER (string_place); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 DEBUG_PRINT2 (" Pushing failure id: %u\n", failure_id); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 DEBUG_PUSH (failure_id); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 /* This is the number of items that are pushed and popped on the stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 for each register. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 #define NUM_REG_ITEMS 3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 /* Individual items aside from the registers. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 #define NUM_NONREG_ITEMS 5 /* Includes failure point id. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 #define NUM_NONREG_ITEMS 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 /* We push at most this many items on the stack. */
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
1372 /* We used to use (num_regs - 1), which is the number of registers
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
1373 this regexp will save; but that was changed to 5
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
1374 to avoid stack overflow for a regexp with lots of parens. */
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
1375 #define MAX_FAILURE_ITEMS (5 * NUM_REG_ITEMS + NUM_NONREG_ITEMS)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 /* We actually push this many items. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 #define NUM_FAILURE_ITEMS \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 ((highest_active_reg - lowest_active_reg + 1) * NUM_REG_ITEMS \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 + NUM_NONREG_ITEMS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 /* How many items can still be added to the stack without overflowing it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 #define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 /* Pops what PUSH_FAIL_STACK pushes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 We restore into the parameters, all of which should be lvalues:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 STR -- the saved data position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 PAT -- the saved pattern position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 LOW_REG, HIGH_REG -- the highest and lowest active registers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 REGSTART, REGEND -- arrays of string positions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 REG_INFO -- array of information about each subexpression.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1394
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 Also assumes the variables `fail_stack' and (if debugging), `bufp',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 `pend', `string1', `size1', `string2', and `size2'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 #define POP_FAILURE_POINT(str, pat, low_reg, high_reg, regstart, regend, reg_info)\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 DEBUG_STATEMENT (fail_stack_elt_t ffailure_id;) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 int this_reg; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 CONST unsigned char *string_temp; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 assert (!FAIL_STACK_EMPTY ()); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 /* Remove failure points and point to how many regs pushed. */ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 DEBUG_PRINT2 (" Before pop, next avail: %d\n", fail_stack.avail); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 DEBUG_PRINT2 (" size: %d\n", fail_stack.size); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 assert (fail_stack.avail >= NUM_NONREG_ITEMS); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 DEBUG_POP (&ffailure_id.integer); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 DEBUG_PRINT2 (" Popping failure id: %u\n", \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 * (unsigned int *) &ffailure_id); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 /* If the saved string location is NULL, it came from an \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 on_failure_keep_string_jump opcode, and we want to throw away the \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 saved NULL, thus retaining our current position in the string. */ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 string_temp = POP_FAILURE_POINTER (); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 if (string_temp != NULL) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 str = (CONST char *) string_temp; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 \
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 169
diff changeset
1424 DEBUG_PRINT2 (" Popping string 0x%p: `", str); \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 DEBUG_PRINT1 ("'\n"); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 pat = (unsigned char *) POP_FAILURE_POINTER (); \
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 169
diff changeset
1429 DEBUG_PRINT2 (" Popping pattern 0x%p: ", pat); \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 /* Restore register info. */ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 high_reg = (unsigned) POP_FAILURE_INT (); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 DEBUG_PRINT2 (" Popping high active reg: %d\n", high_reg); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 low_reg = (unsigned) POP_FAILURE_INT (); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 DEBUG_PRINT2 (" Popping low active reg: %d\n", low_reg); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 for (this_reg = high_reg; this_reg >= low_reg; this_reg--) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 DEBUG_PRINT2 (" Popping reg: %d\n", this_reg); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 reg_info[this_reg].word = POP_FAILURE_ELT (); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 DEBUG_PRINT2 (" info: 0x%lx\n", \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 * (unsigned long *) &reg_info[this_reg]); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 regend[this_reg] = (CONST char *) POP_FAILURE_POINTER (); \
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 169
diff changeset
1448 DEBUG_PRINT2 (" end: 0x%p\n", regend[this_reg]); \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 regstart[this_reg] = (CONST char *) POP_FAILURE_POINTER (); \
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 169
diff changeset
1451 DEBUG_PRINT2 (" start: 0x%p\n", regstart[this_reg]); \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 set_regs_matched_done = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 DEBUG_STATEMENT (nfailure_points_popped++); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 } /* POP_FAILURE_POINT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 /* Structure for per-register (a.k.a. per-group) information.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 Other register information, such as the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 starting and ending positions (which are addresses), and the list of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 inner groups (which is a bits list) are maintained in separate
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1464 variables.
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1465
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 We are making a (strictly speaking) nonportable assumption here: that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 the compiler will pack our bit fields into something that fits into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 the type of `word', i.e., is something that fits into one item on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 failure stack. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 typedef union
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 fail_stack_elt_t word;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 struct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 /* This field is one if this group can match the empty string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 zero if not. If not yet determined, `MATCH_NULL_UNSET_VALUE'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 #define MATCH_NULL_UNSET_VALUE 3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 unsigned match_null_string_p : 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 unsigned is_active : 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 unsigned matched_something : 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 unsigned ever_matched_something : 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 } bits;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 } register_info_type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 #define REG_MATCH_NULL_STRING_P(R) ((R).bits.match_null_string_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 #define IS_ACTIVE(R) ((R).bits.is_active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 #define MATCHED_SOMETHING(R) ((R).bits.matched_something)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 #define EVER_MATCHED_SOMETHING(R) ((R).bits.ever_matched_something)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 /* Call this when have matched a real character; it sets `matched' flags
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 for the subexpressions which we are currently inside. Also records
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 that those subexprs have matched. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 #define SET_REGS_MATCHED() \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 do \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 if (!set_regs_matched_done) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 unsigned r; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 set_regs_matched_done = 1; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 for (r = lowest_active_reg; r <= highest_active_reg; r++) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 MATCHED_SOMETHING (reg_info[r]) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 = EVER_MATCHED_SOMETHING (reg_info[r]) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 = 1; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 /* Registers are set to a sentinel when they haven't yet matched. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 static char reg_unset_dummy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 #define REG_UNSET_VALUE (&reg_unset_dummy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 #define REG_UNSET(e) ((e) == REG_UNSET_VALUE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 /* Subroutine declarations and macros for regex_compile. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1519 /* Fetch the next character in the uncompiled pattern---translating it
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 if necessary. Also cast from a signed character in the constant
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 string passed to us by the user to an unsigned char that we can use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 as an array index (in, e.g., `translate'). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 #define PATFETCH(c) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 do {if (p == pend) return REG_EEND; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 assert (p < pend); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 c = (unsigned char) *p++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 if (translate) c = (unsigned char) translate[c]; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 /* Fetch the next character in the uncompiled pattern, with no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 translation. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 #define PATFETCH_RAW(c) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 do {if (p == pend) return REG_EEND; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 assert (p < pend); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 c = (unsigned char) *p++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 /* Go backwards one character in the pattern. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 #define PATUNFETCH p--
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1541 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1542
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1543 #define PATFETCH_EXTENDED(emch) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1544 do {if (p == pend) return REG_EEND; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1545 assert (p < pend); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1546 emch = charptr_emchar ((CONST Bufbyte *) p); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1547 INC_CHARPTR (p); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1548 if (translate && emch < 0x80) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1549 emch = (Emchar) (unsigned char) translate[emch]; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1550 } while (0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1551
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1552 #define PATFETCH_RAW_EXTENDED(emch) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1553 do {if (p == pend) return REG_EEND; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1554 assert (p < pend); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1555 emch = charptr_emchar ((CONST Bufbyte *) p); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1556 INC_CHARPTR (p); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1557 } while (0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1558
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1559 #define PATUNFETCH_EXTENDED DEC_CHARPTR (p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1560
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1561 #define PATFETCH_EITHER(emch) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1562 do { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1563 if (has_extended_chars) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1564 PATFETCH_EXTENDED (emch); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1565 else \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1566 PATFETCH (emch); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1567 } while (0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1568
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1569 #define PATFETCH_RAW_EITHER(emch) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1570 do { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1571 if (has_extended_chars) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1572 PATFETCH_RAW_EXTENDED (emch); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1573 else \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1574 PATFETCH_RAW (emch); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1575 } while (0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1576
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1577 #define PATUNFETCH_EITHER \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1578 do { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1579 if (has_extended_chars) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1580 PATUNFETCH_EXTENDED (emch); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1581 else \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1582 PATUNFETCH (emch); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1583 } while (0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1584
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1585 #else /* not MULE */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1586
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 #define PATFETCH_EITHER(emch) PATFETCH (emch)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 #define PATFETCH_RAW_EITHER(emch) PATFETCH_RAW (emch)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 #define PATUNFETCH_EITHER PATUNFETCH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1591 #endif /* not MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 /* If `translate' is non-null, return translate[D], else just D. We
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 cast the subscript to translate because some data is declared as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 `char *', to avoid warnings when a string constant is passed. But
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 when we use a character as a subscript we must make it unsigned. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 #define TRANSLATE(d) (translate ? translate[(unsigned char) (d)] : (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1599 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1600
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1601 #define TRANSLATE_EXTENDED_UNSAFE(emch) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1602 (translate && emch < 0x80 ? translate[emch] : (emch))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1603
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1604 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 /* Macros for outputting the compiled pattern into `buffer'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 /* If the buffer isn't allocated when it comes in, use this. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 #define INIT_BUF_SIZE 32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 /* Make sure we have at least N more bytes of space in buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 #define GET_BUFFER_SPACE(n) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 while (b - bufp->buffer + (n) > bufp->allocated) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 EXTEND_BUFFER ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 /* Make sure we have one more byte of buffer space and then add C to it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 #define BUF_PUSH(c) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 GET_BUFFER_SPACE (1); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 *b++ = (unsigned char) (c); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 /* Ensure we have two more bytes of buffer space and then append C1 and C2. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 #define BUF_PUSH_2(c1, c2) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 GET_BUFFER_SPACE (2); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 *b++ = (unsigned char) (c1); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 *b++ = (unsigned char) (c2); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 /* As with BUF_PUSH_2, except for three bytes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 #define BUF_PUSH_3(c1, c2, c3) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 GET_BUFFER_SPACE (3); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 *b++ = (unsigned char) (c1); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 *b++ = (unsigned char) (c2); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 *b++ = (unsigned char) (c3); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 /* Store a jump with opcode OP at LOC to location TO. We store a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 relative address offset by the three bytes the jump itself occupies. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 #define STORE_JUMP(op, loc, to) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 store_op1 (op, loc, (to) - (loc) - 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 /* Likewise, for a two-argument jump. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 #define STORE_JUMP2(op, loc, to, arg) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 store_op2 (op, loc, (to) - (loc) - 3, arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 /* Like `STORE_JUMP', but for inserting. Assume `b' is the buffer end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 #define INSERT_JUMP(op, loc, to) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 insert_op1 (op, loc, (to) - (loc) - 3, b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 /* Like `STORE_JUMP2', but for inserting. Assume `b' is the buffer end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 #define INSERT_JUMP2(op, loc, to, arg) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 insert_op2 (op, loc, (to) - (loc) - 3, arg, b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 /* This is not an arbitrary limit: the arguments which represent offsets
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 into the pattern are two bytes long. So if 2^16 bytes turns out to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 be too small, many things would have to change. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 #define MAX_BUF_SIZE (1L << 16)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 /* Extend the buffer by twice its current size via realloc and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 reset the pointers that pointed into the old block to point to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 correct places in the new one. If extending the buffer results in it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 being larger than MAX_BUF_SIZE, then flag memory exhausted. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 #define EXTEND_BUFFER() \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 unsigned char *old_buffer = bufp->buffer; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 if (bufp->allocated == MAX_BUF_SIZE) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 return REG_ESIZE; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 bufp->allocated <<= 1; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 if (bufp->allocated > MAX_BUF_SIZE) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 bufp->allocated = MAX_BUF_SIZE; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 bufp->buffer = (unsigned char *) realloc (bufp->buffer, bufp->allocated);\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 if (bufp->buffer == NULL) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 return REG_ESPACE; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 /* If the buffer moved, move all the pointers into it. */ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 if (old_buffer != bufp->buffer) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 b = (b - old_buffer) + bufp->buffer; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 begalt = (begalt - old_buffer) + bufp->buffer; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 if (fixup_alt_jump) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 fixup_alt_jump = (fixup_alt_jump - old_buffer) + bufp->buffer;\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 if (laststart) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 laststart = (laststart - old_buffer) + bufp->buffer; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 if (pending_exact) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 pending_exact = (pending_exact - old_buffer) + bufp->buffer; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 /* Since we have one byte reserved for the register number argument to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 {start,stop}_memory, the maximum number of groups we can report
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 things about is what fits in that byte. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 #define MAX_REGNUM 255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 /* But patterns can have more than `MAX_REGNUM' registers. We just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 ignore the excess. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 typedef unsigned regnum_t;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707 /* Macros for the compile stack. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 /* Since offsets can go either forwards or backwards, this type needs to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 be able to hold values from -(MAX_BUF_SIZE - 1) to MAX_BUF_SIZE - 1. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 typedef int pattern_offset_t;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 typedef struct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 pattern_offset_t begalt_offset;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 pattern_offset_t fixup_alt_jump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 pattern_offset_t inner_group_offset;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1718 pattern_offset_t laststart_offset;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 regnum_t regnum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 } compile_stack_elt_t;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 typedef struct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 compile_stack_elt_t *stack;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 unsigned size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 unsigned avail; /* Offset of next open position. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 } compile_stack_type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 #define INIT_COMPILE_STACK_SIZE 32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 #define COMPILE_STACK_EMPTY (compile_stack.avail == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 #define COMPILE_STACK_FULL (compile_stack.avail == compile_stack.size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 /* The next available element. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 #define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 /* Set the bit for character C in a bit vector. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 #define SET_LIST_BIT(c) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 (b[((unsigned char) (c)) / BYTEWIDTH] \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 |= 1 << (((unsigned char) c) % BYTEWIDTH))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1745 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1746
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1747 /* Set the "bit" for character C in a range table. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1748 #define SET_RANGETAB_BIT(c) put_range_table (rtab, c, c, Qt)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1749
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1750 /* Set the "bit" for character c in the appropriate table. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1751 #define SET_EITHER_BIT(c) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1752 do { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1753 if (has_extended_chars) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1754 SET_RANGETAB_BIT (c); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1755 else \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1756 SET_LIST_BIT (c); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1757 } while (0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1758
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1759 #else /* not MULE */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1760
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 #define SET_EITHER_BIT(c) SET_LIST_BIT (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1763 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 /* Get the next unsigned number in the uncompiled pattern. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 #define GET_UNSIGNED_NUMBER(num) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 { if (p != pend) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 PATFETCH (c); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 while (ISDIGIT (c)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 if (num < 0) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 num = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 num = num * 10 + c - '0'; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 if (p == pend) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 break; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 PATFETCH (c); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 } \
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1781 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 #define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 #define IS_CHAR_CLASS(string) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 (STREQ (string, "alpha") || STREQ (string, "upper") \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 || STREQ (string, "lower") || STREQ (string, "digit") \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 || STREQ (string, "alnum") || STREQ (string, "xdigit") \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 || STREQ (string, "space") || STREQ (string, "print") \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 || STREQ (string, "punct") || STREQ (string, "graph") \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 || STREQ (string, "cntrl") || STREQ (string, "blank"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 static void store_op1 (re_opcode_t op, unsigned char *loc, int arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 static void store_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 static void insert_op1 (re_opcode_t op, unsigned char *loc, int arg,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 unsigned char *end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 static void insert_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 unsigned char *end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 static boolean at_begline_loc_p (CONST char *pattern, CONST char *p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 reg_syntax_t syntax);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 static boolean at_endline_loc_p (CONST char *p, CONST char *pend, int syntax);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 static boolean group_in_compile_stack (compile_stack_type compile_stack,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 regnum_t regnum);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 static reg_errcode_t compile_range (CONST char **p_ptr, CONST char *pend,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 char *translate, reg_syntax_t syntax,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 unsigned char *b);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1807 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1808 static reg_errcode_t compile_extended_range (CONST char **p_ptr,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1809 CONST char *pend,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1810 char *translate,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1811 reg_syntax_t syntax,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
1812 Lisp_Object rtab);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1813 #endif /* MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 static boolean group_match_null_string_p (unsigned char **p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 unsigned char *end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 register_info_type *reg_info);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 static boolean alt_match_null_string_p (unsigned char *p, unsigned char *end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 register_info_type *reg_info);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 static boolean common_op_match_null_string_p (unsigned char **p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 unsigned char *end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 register_info_type *reg_info);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 static int bcmp_translate (CONST unsigned char *s1, CONST unsigned char *s2,
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
1823 REGISTER int len, char *translate);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 static int re_match_2_internal (struct re_pattern_buffer *bufp,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 CONST char *string1, int size1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 CONST char *string2, int size2, int pos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 struct re_registers *regs, int stop);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 #ifndef MATCH_MAY_ALLOCATE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 /* If we cannot allocate large objects within re_match_2_internal,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 we make the fail stack and register vectors global.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 The fail stack, we grow to the maximum size when a regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 is compiled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 The register vectors, we adjust in size each time we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 compile a regexp, according to the number of registers it needs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 static fail_stack_type fail_stack;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 /* Size with which the following vectors are currently allocated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 That is so we can make them bigger as needed,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 but never make them smaller. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 static int regs_allocated_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 static CONST char ** regstart, ** regend;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 static CONST char ** old_regstart, ** old_regend;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 static CONST char **best_regstart, **best_regend;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1848 static register_info_type *reg_info;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 static CONST char **reg_dummy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 static register_info_type *reg_info_dummy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 /* Make the register vectors big enough for NUM_REGS registers,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 but don't make them smaller. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 static
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 regex_grow_registers (int num_regs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 if (num_regs > regs_allocated_size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 {
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 163
diff changeset
1860 RETALLOC_IF (regstart, num_regs, CONST char *);
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 163
diff changeset
1861 RETALLOC_IF (regend, num_regs, CONST char *);
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 163
diff changeset
1862 RETALLOC_IF (old_regstart, num_regs, CONST char *);
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 163
diff changeset
1863 RETALLOC_IF (old_regend, num_regs, CONST char *);
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 163
diff changeset
1864 RETALLOC_IF (best_regstart, num_regs, CONST char *);
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 163
diff changeset
1865 RETALLOC_IF (best_regend, num_regs, CONST char *);
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 163
diff changeset
1866 RETALLOC_IF (reg_info, num_regs, register_info_type);
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 163
diff changeset
1867 RETALLOC_IF (reg_dummy, num_regs, CONST char *);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 RETALLOC_IF (reg_info_dummy, num_regs, register_info_type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 regs_allocated_size = num_regs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 #endif /* not MATCH_MAY_ALLOCATE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 /* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 Returns one of error codes defined in `regex.h', or zero for success.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 Assumes the `allocated' (and perhaps `buffer') and `translate'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 fields are set in BUFP on entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 If it succeeds, results are put in BUFP (if it returns an error, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 contents of BUFP are undefined):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 `buffer' is the compiled pattern;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 `syntax' is set to SYNTAX;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 `used' is set to the length of the compiled pattern;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 `fastmap_accurate' is zero;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 `re_nsub' is the number of subexpressions in PATTERN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 `not_bol' and `not_eol' are zero;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1890
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 The `fastmap' and `newline_anchor' fields are neither
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 examined nor set. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 /* Return, freeing storage we allocated. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 #define FREE_STACK_RETURN(value) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 return (free (compile_stack.stack), value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 static reg_errcode_t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 regex_compile (CONST char *pattern, int size, reg_syntax_t syntax,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 struct re_pattern_buffer *bufp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 /* We fetch characters from PATTERN here. We declare these as int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 (or possibly long) so that chars above 127 can be used as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 array indices. The macros that fetch a character from the pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 make sure to coerce to unsigned char before assigning, so we won't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 get bitten by negative numbers here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 /* XEmacs change: used to be unsigned char. */
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
1908 REGISTER EMACS_INT c, c1;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1909
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 /* A random temporary spot in PATTERN. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 CONST char *p1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 /* Points to the end of the buffer, where we should append. */
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
1914 REGISTER unsigned char *b;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1915
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 /* Keeps track of unclosed groups. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 compile_stack_type compile_stack;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 /* Points to the current (ending) position in the pattern. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 CONST char *p = pattern;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 CONST char *pend = pattern + size;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1922
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 /* How to translate the characters in the pattern. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 char *translate = bufp->translate;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 /* Address of the count-byte of the most recently inserted `exactn'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 command. This makes it possible to tell if a new exact-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 character can be added to that command or if the character requires
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 a new `exactn' command. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 unsigned char *pending_exact = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 /* Address of start of the most recently finished expression.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 This tells, e.g., postfix * where to find the start of its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 operand. Reset at the beginning of groups and alternatives. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 unsigned char *laststart = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 /* Address of beginning of regexp, or inside of last group. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 unsigned char *begalt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 /* Place in the uncompiled pattern (i.e., the {) to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 which to go back if the interval is invalid. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 CONST char *beg_interval;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1943
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 /* Address of the place where a forward jump should go to the end of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 the containing expression. Each alternative of an `or' -- except the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 last -- ends with a forward jump of this sort. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 unsigned char *fixup_alt_jump = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 /* Counts open-groups as they are encountered. Remembered for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 matching close-group on the compile stack, so the same register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 number is put in the stop_memory as the start_memory. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 regnum_t regnum = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 DEBUG_PRINT1 ("\nCompiling pattern: ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 if (debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 unsigned debug_count;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1959
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 for (debug_count = 0; debug_count < size; debug_count++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 putchar (pattern[debug_count]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 putchar ('\n');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 #endif /* DEBUG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 /* Initialize the compile stack. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 compile_stack.stack = TALLOC (INIT_COMPILE_STACK_SIZE, compile_stack_elt_t);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 if (compile_stack.stack == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 return REG_ESPACE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 compile_stack.size = INIT_COMPILE_STACK_SIZE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 compile_stack.avail = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 /* Initialize the pattern buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 bufp->syntax = syntax;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 bufp->fastmap_accurate = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 bufp->not_bol = bufp->not_eol = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 /* Set `used' to zero, so that if we return an error, the pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 printer (for debugging) will think there's no pattern. We reset it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 at the end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 bufp->used = 0;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1983
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 /* Always count groups, whether or not bufp->no_sub is set. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
1985 bufp->re_nsub = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 #if !defined (emacs) && !defined (SYNTAX_TABLE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 /* Initialize the syntax table. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 init_syntax_once ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 if (bufp->allocated == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 if (bufp->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 { /* If zero allocated, but buffer is non-null, try to realloc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 enough space. This loses if buffer's address is bogus, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 that is the user's responsibility. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 RETALLOC (bufp->buffer, INIT_BUF_SIZE, unsigned char);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 { /* Caller did not allocate a buffer. Do it for them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 if (!bufp->buffer) FREE_STACK_RETURN (REG_ESPACE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 bufp->allocated = INIT_BUF_SIZE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 begalt = b = bufp->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 /* Loop through the uncompiled pattern until we're at the end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 while (p != pend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 PATFETCH (c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 switch (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 case '^':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 if ( /* If at start of pattern, it's an operator. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 p == pattern + 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 /* If context independent, it's an operator. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 || syntax & RE_CONTEXT_INDEP_ANCHORS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 /* Otherwise, depends on what's come before. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 || at_begline_loc_p (pattern, p, syntax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 BUF_PUSH (begline);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 goto normal_char;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 case '$':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 if ( /* If at end of pattern, it's an operator. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2036 p == pend
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 /* If context independent, it's an operator. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 || syntax & RE_CONTEXT_INDEP_ANCHORS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 /* Otherwise, depends on what's next. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 || at_endline_loc_p (p, pend, syntax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 BUF_PUSH (endline);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 goto normal_char;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 case '+':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 case '?':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 if ((syntax & RE_BK_PLUS_QM)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 || (syntax & RE_LIMITED_OPS))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 goto normal_char;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 handle_plus:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 case '*':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 /* If there is no previous pattern... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 if (!laststart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 if (syntax & RE_CONTEXT_INVALID_OPS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 FREE_STACK_RETURN (REG_BADRPT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 else if (!(syntax & RE_CONTEXT_INDEP_OPS))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 goto normal_char;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2065 /* true means zero/many matches are allowed. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2066 boolean zero_times_ok = c != '+';
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2067 boolean many_times_ok = c != '?';
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2068
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2069 /* true means match shortest string possible. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2070 boolean minimal = false;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 /* If there is a sequence of repetition chars, collapse it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 down to just one (the right one). We can't combine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 interval operators with these because of, e.g., `a{2}*',
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2075 which should only match an even number of `a's. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2076 while (p != pend)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 PATFETCH (c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2080 if (c == '*' || (!(syntax & RE_BK_PLUS_QM)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2081 && (c == '+' || c == '?')))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2084 else if (syntax & RE_BK_PLUS_QM && c == '\\')
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 PATFETCH (c1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 if (!(c1 == '+' || c1 == '?'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 PATUNFETCH;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 PATUNFETCH;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 c = c1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 PATUNFETCH;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 /* If we get here, we found another repeat character. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2105 if (!(syntax & RE_NO_MINIMAL_MATCHING))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2106 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2107 /* `*?' and `+?' and `??' are okay (and mean match
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2108 minimally), but other sequences (such as `*??' and
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2109 `+++') are rejected (reserved for future use). */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2110 if (minimal || c != '?')
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2111 FREE_STACK_RETURN (REG_BADRPT);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2112 minimal = true;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2113 }
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2114 else
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2115 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2116 zero_times_ok |= c != '+';
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2117 many_times_ok |= c != '?';
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2118 }
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2119 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 /* Star, etc. applied to an empty pattern is equivalent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 to an empty pattern. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2123 if (!laststart)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2126 /* Now we know whether zero matches is allowed
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2127 and whether two or more matches is allowed
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2128 and whether we want minimal or maximal matching. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2129 if (minimal)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2130 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2131 if (!many_times_ok)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2132 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2133 /* "a??" becomes:
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2134 0: /on_failure_jump to 6
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2135 3: /jump to 9
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2136 6: /exactn/1/A
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2137 9: end of pattern.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2138 */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2139 GET_BUFFER_SPACE (6);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2140 INSERT_JUMP (jump, laststart, b + 3);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2141 b += 3;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2142 INSERT_JUMP (on_failure_jump, laststart, laststart + 6);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2143 b += 3;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2144 }
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2145 else if (zero_times_ok)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2146 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2147 /* "a*?" becomes:
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2148 0: /jump to 6
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2149 3: /exactn/1/A
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2150 6: /on_failure_jump to 3
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2151 9: end of pattern.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2152 */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2153 GET_BUFFER_SPACE (6);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2154 INSERT_JUMP (jump, laststart, b + 3);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2155 b += 3;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2156 STORE_JUMP (on_failure_jump, b, laststart + 3);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2157 b += 3;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 else
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2160 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2161 /* "a+?" becomes:
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2162 0: /exactn/1/A
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2163 3: /on_failure_jump to 0
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2164 6: end of pattern.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2165 */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2166 GET_BUFFER_SPACE (3);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2167 STORE_JUMP (on_failure_jump, b, laststart);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2168 b += 3;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2169 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2171 else
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2172 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2173 /* Are we optimizing this jump? */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2174 boolean keep_string_p = false;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2175
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2176 if (many_times_ok)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2177 { /* More than one repetition is allowed, so put in at the
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2178 end a backward relative jump from `b' to before the next
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2179 jump we're going to put in below (which jumps from
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2180 laststart to after this jump).
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2181
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2182 But if we are at the `*' in the exact sequence `.*\n',
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2183 insert an unconditional jump backwards to the .,
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2184 instead of the beginning of the loop. This way we only
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2185 push a failure point once, instead of every time
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2186 through the loop. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2187 assert (p - 1 > pattern);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2188
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2189 /* Allocate the space for the jump. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2190 GET_BUFFER_SPACE (3);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2191
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2192 /* We know we are not at the first character of the
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2193 pattern, because laststart was nonzero. And we've
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2194 already incremented `p', by the way, to be the
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2195 character after the `*'. Do we have to do something
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2196 analogous here for null bytes, because of
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2197 RE_DOT_NOT_NULL? */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2198 if (TRANSLATE (*(p - 2)) == TRANSLATE ('.')
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2199 && zero_times_ok
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2200 && p < pend && TRANSLATE (*p) == TRANSLATE ('\n')
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2201 && !(syntax & RE_DOT_NEWLINE))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2202 { /* We have .*\n. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2203 STORE_JUMP (jump, b, laststart);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2204 keep_string_p = true;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2205 }
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2206 else
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2207 /* Anything else. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2208 STORE_JUMP (maybe_pop_jump, b, laststart - 3);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2209
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2210 /* We've added more stuff to the buffer. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2211 b += 3;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2212 }
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2213
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2214 /* On failure, jump from laststart to b + 3, which will be the
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2215 end of the buffer after this jump is inserted. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2216 GET_BUFFER_SPACE (3);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2217 INSERT_JUMP (keep_string_p ? on_failure_keep_string_jump
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2218 : on_failure_jump,
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2219 laststart, b + 3);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2220 b += 3;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2221
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2222 if (!zero_times_ok)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2223 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2224 /* At least one repetition is required, so insert a
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2225 `dummy_failure_jump' before the initial
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2226 `on_failure_jump' instruction of the loop. This
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2227 effects a skip over that instruction the first time
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2228 we hit that loop. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2229 GET_BUFFER_SPACE (3);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2230 INSERT_JUMP (dummy_failure_jump, laststart, laststart + 6);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2231 b += 3;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2232 }
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2233 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 pending_exact = 0;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2235 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 case '.':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 laststart = b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 BUF_PUSH (anychar);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 case '[':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 /* XEmacs change: this whole section */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 boolean had_char_class = false;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2249 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2250 boolean has_extended_chars = false;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2251 REGISTER Lisp_Object rtab = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2252 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 /* Ensure that we have enough space to push a charset: the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 opcode, the length count, and the bitset; 34 bytes in all. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 GET_BUFFER_SPACE (34);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 laststart = b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 /* We test `*p == '^' twice, instead of using an if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 statement, so we only need one BUF_PUSH. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2264 BUF_PUSH (*p == '^' ? charset_not : charset);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 if (*p == '^')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 /* Remember the first position in the bracket expression. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 p1 = p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 /* Push the number of bytes in the bitmap. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 BUF_PUSH ((1 << BYTEWIDTH) / BYTEWIDTH);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 /* Clear the whole map. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 bzero (b, (1 << BYTEWIDTH) / BYTEWIDTH);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 /* charset_not matches newline according to a syntax bit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 if ((re_opcode_t) b[-2] == charset_not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 && (syntax & RE_HAT_LISTS_NOT_NEWLINE))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 SET_LIST_BIT ('\n');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2282 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2283 start_over_with_extended:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2284 if (has_extended_chars)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2285 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2286 /* There are extended chars here, which means we need to start
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2287 over and shift to unified range-table format. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2288 if (b[-2] == charset)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2289 b[-2] = charset_mule;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2290 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2291 b[-2] = charset_mule_not;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2292 b--;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2293 p = p1; /* go back to the beginning of the charset, after
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2294 a possible ^. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2295 rtab = Vthe_lisp_rangetab;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2296 Fclear_range_table (rtab);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2297
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2298 /* charset_not matches newline according to a syntax bit. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2299 if ((re_opcode_t) b[-1] == charset_mule_not
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2300 && (syntax & RE_HAT_LISTS_NOT_NEWLINE))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2301 SET_EITHER_BIT ('\n');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2302 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2303 #endif /* MULE */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2304
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 /* Read in characters and ranges, setting map bits. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 for (;;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 PATFETCH_EITHER (c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2312 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2313 if (c >= 0x80 && !has_extended_chars)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2314 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2315 has_extended_chars = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2316 /* Frumble-bumble, we've found some extended chars.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2317 Need to start over, process everything using
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2318 the general extended-char mechanism, and need
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2319 to use charset_mule and charset_mule_not instead
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2320 of charset and charset_not. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2321 goto start_over_with_extended;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2322 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2323 #endif /* MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 /* \ might escape characters inside [...] and [^...]. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 PATFETCH_EITHER (c1);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2330 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2331 if (c1 >= 0x80 && !has_extended_chars)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2332 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2333 has_extended_chars = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2334 goto start_over_with_extended;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2335 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2336 #endif /* MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 SET_EITHER_BIT (c1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 /* Could be the end of the bracket expression. If it's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 not (i.e., when the bracket expression is `[]' so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 far), the ']' character bit gets set way below. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 if (c == ']' && p != p1 + 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 /* Look ahead to see if it's a range when the last thing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 was a character class. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 if (had_char_class && c == '-' && *p != ']')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 FREE_STACK_RETURN (REG_ERANGE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 /* Look ahead to see if it's a range when the last thing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353 was a character: if this is a hyphen not at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 beginning or the end of a list, then it's the range
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 operator. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2356 if (c == '-'
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2357 && !(p - 2 >= pattern && p[-2] == '[')
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 && !(p - 3 >= pattern && p[-3] == '[' && p[-2] == '^')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 && *p != ']')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 reg_errcode_t ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2363 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2364 if (* (unsigned char *) p >= 0x80 && !has_extended_chars)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2365 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2366 has_extended_chars = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2367 goto start_over_with_extended;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2368 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2369 if (has_extended_chars)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2370 ret = compile_extended_range (&p, pend, translate,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2371 syntax, rtab);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2372 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2373 #endif /* MULE */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2374 ret = compile_range (&p, pend, translate, syntax, b);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 if (ret != REG_NOERROR) FREE_STACK_RETURN (ret);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 else if (p[0] == '-' && p[1] != ']')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 { /* This handles ranges made up of characters only. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 reg_errcode_t ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 /* Move past the `-'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 PATFETCH (c1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2385 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2386 if (* (unsigned char *) p >= 0x80 && !has_extended_chars)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2387 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2388 has_extended_chars = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2389 goto start_over_with_extended;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2390 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2391 if (has_extended_chars)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2392 ret = compile_extended_range (&p, pend, translate,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2393 syntax, rtab);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2394 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2395 #endif /* MULE */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2396 ret = compile_range (&p, pend, translate, syntax, b);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 if (ret != REG_NOERROR) FREE_STACK_RETURN (ret);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 /* See if we're at the beginning of a possible character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 class. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 else if (syntax & RE_CHAR_CLASSES && c == '[' && *p == ':')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 { /* Leave room for the null. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 char str[CHAR_CLASS_MAX_LENGTH + 1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 PATFETCH (c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 c1 = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 /* If pattern is `[[:'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 for (;;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 /* Do not do PATFETCH_EITHER() here. We want
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 to just see if the bytes match particular
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 strings, and we put them all back if not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 #### May need to be changed once trt tables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 are working. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 PATFETCH (c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 if (c == ':' || c == ']' || p == pend
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 || c1 == CHAR_CLASS_MAX_LENGTH)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425 str[c1++] = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 str[c1] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 /* If isn't a word bracketed by `[:' and:`]':
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2430 undo the ending character, the letters, and leave
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 the leading `:' and `[' (but set bits for them). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 if (c == ':' && *p == ']')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 int ch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 boolean is_alnum = STREQ (str, "alnum");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 boolean is_alpha = STREQ (str, "alpha");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 boolean is_blank = STREQ (str, "blank");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 boolean is_cntrl = STREQ (str, "cntrl");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 boolean is_digit = STREQ (str, "digit");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 boolean is_graph = STREQ (str, "graph");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 boolean is_lower = STREQ (str, "lower");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 boolean is_print = STREQ (str, "print");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443 boolean is_punct = STREQ (str, "punct");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 boolean is_space = STREQ (str, "space");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 boolean is_upper = STREQ (str, "upper");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 boolean is_xdigit = STREQ (str, "xdigit");
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2447
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 if (!IS_CHAR_CLASS (str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 FREE_STACK_RETURN (REG_ECTYPE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 /* Throw away the ] at the end of the character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 class. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2453 PATFETCH (c);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 for (ch = 0; ch < 1 << BYTEWIDTH; ch++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 /* This was split into 3 if's to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 avoid an arbitrary limit in some compiler. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 if ( (is_alnum && ISALNUM (ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 || (is_alpha && ISALPHA (ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 || (is_blank && ISBLANK (ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 || (is_cntrl && ISCNTRL (ch)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 SET_EITHER_BIT (ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 if ( (is_digit && ISDIGIT (ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 || (is_graph && ISGRAPH (ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 || (is_lower && ISLOWER (ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 || (is_print && ISPRINT (ch)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 SET_EITHER_BIT (ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 if ( (is_punct && ISPUNCT (ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 || (is_space && ISSPACE (ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 || (is_upper && ISUPPER (ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 || (is_xdigit && ISXDIGIT (ch)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 SET_EITHER_BIT (ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 had_char_class = true;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 c1++;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2482 while (c1--)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 PATUNFETCH;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 SET_EITHER_BIT ('[');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 SET_EITHER_BIT (':');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 had_char_class = false;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 had_char_class = false;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 SET_EITHER_BIT (c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2496 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2497 if (has_extended_chars)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2498 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2499 /* We have a range table, not a bit vector. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2500 int bytes_needed =
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2501 unified_range_table_bytes_needed (rtab);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2502 GET_BUFFER_SPACE (bytes_needed);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2503 unified_range_table_copy_data (rtab, b);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2504 b += unified_range_table_bytes_used (b);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2505 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2506 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
2507 #endif /* MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 /* Discard any (non)matching list bytes that are all 0 at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 end of the map. Decrease the map-length byte too. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2510 while ((int) b[-1] > 0 && b[b[-1] - 1] == 0)
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2511 b[-1]--;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 b += b[-1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 case '(':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 if (syntax & RE_NO_BK_PARENS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 goto handle_open;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 goto normal_char;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 case ')':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525 if (syntax & RE_NO_BK_PARENS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 goto handle_close;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 goto normal_char;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531 case '\n':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532 if (syntax & RE_NEWLINE_ALT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533 goto handle_alt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 goto normal_char;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 case '|':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 if (syntax & RE_NO_BK_VBAR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 goto handle_alt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 goto normal_char;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 case '{':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 if (syntax & RE_INTERVALS && syntax & RE_NO_BK_BRACES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 goto handle_interval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 goto normal_char;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552 case '\\':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 /* Do not translate the character after the \, so that we can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 distinguish, e.g., \B from \b, even if we normally would
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 translate, e.g., B to b. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 PATFETCH_RAW (c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 switch (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 case '(':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 if (syntax & RE_NO_BK_PARENS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 goto normal_backslash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 handle_open:
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2567 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2568 regnum_t r;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2569
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2570 if (!(syntax & RE_NO_SHY_GROUPS)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2571 && p != pend
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2572 && TRANSLATE(*p) == TRANSLATE('?'))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2573 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2574 p++;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2575 PATFETCH(c);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2576 switch (c)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2577 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2578 case ':': /* shy groups */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2579 r = MAX_REGNUM + 1;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2580 break;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2581
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2582 /* All others are reserved for future constructs. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2583 default:
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2584 FREE_STACK_RETURN (REG_BADPAT);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2585 }
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2586 }
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2587 else
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2588 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2589 bufp->re_nsub++;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2590 r = ++regnum;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2591 }
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2592
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2593 if (COMPILE_STACK_FULL)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2594 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2595 RETALLOC (compile_stack.stack, compile_stack.size << 1,
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2596 compile_stack_elt_t);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2597 if (compile_stack.stack == NULL) return REG_ESPACE;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2598
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2599 compile_stack.size <<= 1;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2600 }
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2601
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2602 /* These are the values to restore when we hit end of this
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2603 group. They are all relative offsets, so that if the
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2604 whole pattern moves because of realloc, they will still
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2605 be valid. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2606 COMPILE_STACK_TOP.begalt_offset = begalt - bufp->buffer;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2607 COMPILE_STACK_TOP.fixup_alt_jump
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2608 = fixup_alt_jump ? fixup_alt_jump - bufp->buffer + 1 : 0;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2609 COMPILE_STACK_TOP.laststart_offset = b - bufp->buffer;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2610 COMPILE_STACK_TOP.regnum = r;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2611
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2612 /* We will eventually replace the 0 with the number of
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2613 groups inner to this one. But do not push a
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2614 start_memory for groups beyond the last one we can
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2615 represent in the compiled pattern. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2616 if (r <= MAX_REGNUM)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2617 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2618 COMPILE_STACK_TOP.inner_group_offset
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2619 = b - bufp->buffer + 2;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2620 BUF_PUSH_3 (start_memory, r, 0);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2621 }
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2622
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2623 compile_stack.avail++;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2624
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2625 fixup_alt_jump = 0;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2626 laststart = 0;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2627 begalt = b;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2628 /* If we've reached MAX_REGNUM groups, then this open
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2629 won't actually generate any code, so we'll have to
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2630 clear pending_exact explicitly. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2631 pending_exact = 0;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2632 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 case ')':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 if (syntax & RE_NO_BK_PARENS) goto normal_backslash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 if (COMPILE_STACK_EMPTY)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 goto normal_backslash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 FREE_STACK_RETURN (REG_ERPAREN);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 handle_close:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 if (fixup_alt_jump)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 { /* Push a dummy failure point at the end of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 alternative for a possible future
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 `pop_failure_jump' to pop. See comments at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 `push_dummy_failure' in `re_match_2'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 BUF_PUSH (push_dummy_failure);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2652
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 /* We allocated space for this jump when we assigned
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 to `fixup_alt_jump', in the `handle_alt' case below. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 STORE_JUMP (jump_past_alt, fixup_alt_jump, b - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 /* See similar code for backslashed left paren above. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 if (COMPILE_STACK_EMPTY)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 goto normal_char;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 FREE_STACK_RETURN (REG_ERPAREN);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 /* Since we just checked for an empty stack above, this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 ``can't happen''. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 assert (compile_stack.avail != 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 /* We don't just want to restore into `regnum', because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 later groups should continue to be numbered higher,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 as in `(ab)c(de)' -- the second group is #2. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 regnum_t this_group_regnum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2674 compile_stack.avail--;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 begalt = bufp->buffer + COMPILE_STACK_TOP.begalt_offset;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 fixup_alt_jump
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 = COMPILE_STACK_TOP.fixup_alt_jump
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2678 ? bufp->buffer + COMPILE_STACK_TOP.fixup_alt_jump - 1
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 : 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 this_group_regnum = COMPILE_STACK_TOP.regnum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682 /* If we've reached MAX_REGNUM groups, then this open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 won't actually generate any code, so we'll have to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 clear pending_exact explicitly. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 pending_exact = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 /* We're at the end of the group, so now we know how many
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 groups were inside this one. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 if (this_group_regnum <= MAX_REGNUM)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691 unsigned char *inner_group_loc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 = bufp->buffer + COMPILE_STACK_TOP.inner_group_offset;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2693
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 *inner_group_loc = regnum - this_group_regnum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 BUF_PUSH_3 (stop_memory, this_group_regnum,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 regnum - this_group_regnum);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 case '|': /* `\|'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703 if (syntax & RE_LIMITED_OPS || syntax & RE_NO_BK_VBAR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704 goto normal_backslash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 handle_alt:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 if (syntax & RE_LIMITED_OPS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 goto normal_char;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 /* Insert before the previous alternative a jump which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 jumps to this alternative if the former fails. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 GET_BUFFER_SPACE (3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712 INSERT_JUMP (on_failure_jump, begalt, b + 6);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 pending_exact = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 b += 3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 /* The alternative before this one has a jump after it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717 which gets executed if it gets matched. Adjust that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 jump so it will jump to this alternative's analogous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 jump (put in below, which in turn will jump to the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 (if any) alternative's such jump, etc.). The last such
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721 jump jumps to the correct final destination. A picture:
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2722 _____ _____
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2723 | | | |
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2724 | v | v
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2725 a | b | c
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727 If we are at `b', then fixup_alt_jump right now points to a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 three-byte space after `a'. We'll put in the jump, set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 fixup_alt_jump to right after `b', and leave behind three
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 bytes which we'll fill in when we get to after `c'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 if (fixup_alt_jump)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 STORE_JUMP (jump_past_alt, fixup_alt_jump, b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 /* Mark and leave space for a jump after this alternative,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736 to be filled in later either by next alternative or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737 when know we're at the end of a series of alternatives. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 fixup_alt_jump = b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 GET_BUFFER_SPACE (3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740 b += 3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 laststart = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 begalt = b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2747 case '{':
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 /* If \{ is a literal. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749 if (!(syntax & RE_INTERVALS)
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2750 /* If we're at `\{' and it's not the open-interval
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 operator. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 || ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 || (p - 2 == pattern && p == pend))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 goto normal_backslash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756 handle_interval:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 /* If got here, then the syntax allows intervals. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 /* At least (most) this many matches must be made. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 int lower_bound = -1, upper_bound = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 beg_interval = p - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 if (p == pend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 if (syntax & RE_NO_BK_BRACES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 goto unfetch_interval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 FREE_STACK_RETURN (REG_EBRACE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773 GET_UNSIGNED_NUMBER (lower_bound);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775 if (c == ',')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777 GET_UNSIGNED_NUMBER (upper_bound);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778 if (upper_bound < 0) upper_bound = RE_DUP_MAX;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781 /* Interval such as `{1}' => match exactly once. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782 upper_bound = lower_bound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 if (lower_bound < 0 || upper_bound > RE_DUP_MAX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 || lower_bound > upper_bound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 if (syntax & RE_NO_BK_BRACES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 goto unfetch_interval;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2789 else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790 FREE_STACK_RETURN (REG_BADBR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2793 if (!(syntax & RE_NO_BK_BRACES))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795 if (c != '\\') FREE_STACK_RETURN (REG_EBRACE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2797 PATFETCH (c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800 if (c != '}')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 if (syntax & RE_NO_BK_BRACES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803 goto unfetch_interval;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2804 else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 FREE_STACK_RETURN (REG_BADBR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 /* We just parsed a valid interval. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 /* If it's invalid to have no preceding re. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 if (!laststart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813 if (syntax & RE_CONTEXT_INVALID_OPS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 FREE_STACK_RETURN (REG_BADRPT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815 else if (syntax & RE_CONTEXT_INDEP_OPS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 laststart = b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 goto unfetch_interval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2821 /* If the upper bound is zero, don't want to succeed at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2822 all; jump from `laststart' to `b + 3', which will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 the end of the buffer after we insert the jump. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2824 if (upper_bound == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826 GET_BUFFER_SPACE (3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 INSERT_JUMP (jump, laststart, b + 3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2828 b += 3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2829 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 /* Otherwise, we have a nontrivial interval. When
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 we're all done, the pattern will look like:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833 set_number_at <jump count> <upper bound>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 set_number_at <succeed_n count> <lower bound>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 succeed_n <after jump addr> <succeed_n count>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836 <body of loop>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 jump_n <succeed_n addr> <jump count>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 (The upper bound and `jump_n' are omitted if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 `upper_bound' is 1, though.) */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2840 else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 { /* If the upper bound is > 1, we need to insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 more at the end of the loop. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 unsigned nbytes = 10 + (upper_bound > 1) * 10;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 GET_BUFFER_SPACE (nbytes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 /* Initialize lower bound of the `succeed_n', even
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848 though it will be set during matching by its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 attendant `set_number_at' (inserted next),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 because `re_compile_fastmap' needs to know.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851 Jump to the `jump_n' we might insert below. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 INSERT_JUMP2 (succeed_n, laststart,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 b + 5 + (upper_bound > 1) * 5,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 lower_bound);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 b += 5;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2857 /* Code to initialize the lower bound. Insert
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 before the `succeed_n'. The `5' is the last two
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859 bytes of this `set_number_at', plus 3 bytes of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 the following `succeed_n'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 insert_op2 (set_number_at, laststart, 5, lower_bound, b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 b += 5;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 if (upper_bound > 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2865 { /* More than one repetition is allowed, so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866 append a backward jump to the `succeed_n'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 that starts this interval.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2868
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869 When we've reached this during matching,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 we'll have matched the interval once, so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 jump back only `upper_bound - 1' times. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2872 STORE_JUMP2 (jump_n, b, laststart + 5,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873 upper_bound - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2874 b += 5;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2875
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2876 /* The location we want to set is the second
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2877 parameter of the `jump_n'; that is `b-2' as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2878 an absolute address. `laststart' will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2879 the `set_number_at' we're about to insert;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2880 `laststart+3' the number to set, the source
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2881 for the relative address. But we are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2882 inserting into the middle of the pattern --
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2883 so everything is getting moved up by 5.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2884 Conclusion: (b - 2) - (laststart + 3) + 5,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2885 i.e., b - laststart.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2886
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2887 We insert this at the beginning of the loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2888 so that if we fail during matching, we'll
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2889 reinitialize the bounds. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2890 insert_op2 (set_number_at, laststart, b - laststart,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2891 upper_bound - 1, b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2892 b += 5;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2893 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2894 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2895 pending_exact = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2896 beg_interval = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2897 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2898 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2900 unfetch_interval:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2901 /* If an invalid interval, match the characters as literals. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2902 assert (beg_interval);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2903 p = beg_interval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2904 beg_interval = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2905
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2906 /* normal_char and normal_backslash need `c'. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2907 PATFETCH (c);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2908
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2909 if (!(syntax & RE_NO_BK_BRACES))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2910 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2911 if (p > pattern && p[-1] == '\\')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2912 goto normal_backslash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2913 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2914 goto normal_char;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2915
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2916 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2917 /* There is no way to specify the before_dot and after_dot
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2918 operators. rms says this is ok. --karl */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2919 case '=':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2920 BUF_PUSH (at_dot);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2923 case 's':
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2924 laststart = b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2925 PATFETCH (c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2926 /* XEmacs addition */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2927 if (c >= 0x80 || syntax_spec_code[c] == 0377)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2928 FREE_STACK_RETURN (REG_ESYNTAX);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2929 BUF_PUSH_2 (syntaxspec, syntax_spec_code[c]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2930 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2931
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2932 case 'S':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2933 laststart = b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2934 PATFETCH (c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2935 /* XEmacs addition */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2936 if (c >= 0x80 || syntax_spec_code[c] == 0377)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2937 FREE_STACK_RETURN (REG_ESYNTAX);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2938 BUF_PUSH_2 (notsyntaxspec, syntax_spec_code[c]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2939 break;
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2940
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2941 #ifdef MULE
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2942 /* 97.2.17 jhod merged in to XEmacs from mule-2.3 */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
2943 case 'c':
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2944 laststart = b;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2945 PATFETCH_RAW (c);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2946 if (c < 32 || c > 127)
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2947 FREE_STACK_RETURN (REG_ECATEGORY);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2948 BUF_PUSH_2 (categoryspec, c);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2949 break;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2950
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2951 case 'C':
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2952 laststart = b;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2953 PATFETCH_RAW (c);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2954 if (c < 32 || c > 127)
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2955 FREE_STACK_RETURN (REG_ECATEGORY);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2956 BUF_PUSH_2 (notcategoryspec, c);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2957 break;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2958 /* end of category patch */
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2959 #endif /* MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2960 #endif /* emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2961
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2962
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2963 case 'w':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2964 laststart = b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2965 BUF_PUSH (wordchar);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2966 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2967
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2968
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2969 case 'W':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2970 laststart = b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2971 BUF_PUSH (notwordchar);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2972 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2973
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2974
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2975 case '<':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2976 BUF_PUSH (wordbeg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2977 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2978
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2979 case '>':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2980 BUF_PUSH (wordend);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2981 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2982
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2983 case 'b':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2984 BUF_PUSH (wordbound);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2985 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2986
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2987 case 'B':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2988 BUF_PUSH (notwordbound);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2989 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2990
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2991 case '`':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2992 BUF_PUSH (begbuf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2993 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2995 case '\'':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2996 BUF_PUSH (endbuf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2999 case '1': case '2': case '3': case '4': case '5':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3000 case '6': case '7': case '8': case '9':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3001 if (syntax & RE_NO_BK_REFS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3002 goto normal_char;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3003
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3004 c1 = c - '0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3005
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3006 if (c1 > regnum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3007 FREE_STACK_RETURN (REG_ESUBREG);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3008
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3009 /* Can't back reference to a subexpression if inside of it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3010 if (group_in_compile_stack (compile_stack, c1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3011 goto normal_char;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3012
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3013 laststart = b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3014 BUF_PUSH_2 (duplicate, c1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3015 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3016
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3017
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3018 case '+':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3019 case '?':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3020 if (syntax & RE_BK_PLUS_QM)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3021 goto handle_plus;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3022 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3023 goto normal_backslash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3024
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026 normal_backslash:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027 /* You might think it would be useful for \ to mean
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3028 not to translate; but if we don't translate it,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3029 it will never match anything. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3030 c = TRANSLATE (c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3031 goto normal_char;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3033 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3034
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3035
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3036 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3037 /* Expects the character in `c'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3038 /* `p' points to the location after where `c' came from. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3039 normal_char:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3040 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3041 /* XEmacs: modifications here for Mule. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3042 /* `q' points to the beginning of the next char. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3043 CONST char *q = p - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3044 INC_CHARPTR (q);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3045
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3046 /* If no exactn currently being built. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3047 if (!pending_exact
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3049 /* If last exactn not at current position. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050 || pending_exact + *pending_exact + 1 != b
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3051
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052 /* We have only one byte following the exactn for the count. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3053 || ((unsigned int) (*pending_exact + (q - p)) >=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054 ((unsigned int) (1 << BYTEWIDTH) - 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3056 /* If followed by a repetition operator. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057 || *q == '*' || *q == '^'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058 || ((syntax & RE_BK_PLUS_QM)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059 ? *q == '\\' && (q[1] == '+' || q[1] == '?')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3060 : (*q == '+' || *q == '?'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061 || ((syntax & RE_INTERVALS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062 && ((syntax & RE_NO_BK_BRACES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 ? *q == '{'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064 : (q[0] == '\\' && q[1] == '{'))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 /* Start building a new exactn. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3067
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068 laststart = b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3069
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3070 BUF_PUSH_2 (exactn, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3071 pending_exact = b - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3073
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074 BUF_PUSH (c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3075 (*pending_exact)++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3076
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3077 while (p < q)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3078 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3079 PATFETCH (c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3080 BUF_PUSH (c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3081 (*pending_exact)++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3082 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3083 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3084 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3085 } /* switch (c) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3086 } /* while p != pend */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3087
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3088
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3089 /* Through the pattern now. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3090
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3091 if (fixup_alt_jump)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3092 STORE_JUMP (jump_past_alt, fixup_alt_jump, b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3093
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3094 if (!COMPILE_STACK_EMPTY)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3095 FREE_STACK_RETURN (REG_EPAREN);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3096
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3097 /* If we don't want backtracking, force success
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 the first time we reach the end of the compiled pattern. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3099 if (syntax & RE_NO_POSIX_BACKTRACKING)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3100 BUF_PUSH (succeed);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3102 free (compile_stack.stack);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3104 /* We have succeeded; set the length of the buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3105 bufp->used = b - bufp->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3107 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3108 if (debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3109 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3110 DEBUG_PRINT1 ("\nCompiled pattern: \n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3111 print_compiled_pattern (bufp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3112 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3113 #endif /* DEBUG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3115 #ifndef MATCH_MAY_ALLOCATE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3116 /* Initialize the failure stack to the largest possible stack. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3117 isn't necessary unless we're trying to avoid calling alloca in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3118 the search and match routines. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3119 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3120 int num_regs = bufp->re_nsub + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3122 /* Since DOUBLE_FAIL_STACK refuses to double only if the current size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3123 is strictly greater than re_max_failures, the largest possible stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3124 is 2 * re_max_failures failure points. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3125 if (fail_stack.size < (2 * re_max_failures * MAX_FAILURE_ITEMS))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3126 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3127 fail_stack.size = (2 * re_max_failures * MAX_FAILURE_ITEMS);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3129 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3130 if (! fail_stack.stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3131 fail_stack.stack
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3132 = (fail_stack_elt_t *) xmalloc (fail_stack.size
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3133 * sizeof (fail_stack_elt_t));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3134 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3135 fail_stack.stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3136 = (fail_stack_elt_t *) xrealloc (fail_stack.stack,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3137 (fail_stack.size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138 * sizeof (fail_stack_elt_t)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3139 #else /* not emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3140 if (! fail_stack.stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3141 fail_stack.stack
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3142 = (fail_stack_elt_t *) malloc (fail_stack.size
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3143 * sizeof (fail_stack_elt_t));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3144 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145 fail_stack.stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146 = (fail_stack_elt_t *) realloc (fail_stack.stack,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3147 (fail_stack.size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148 * sizeof (fail_stack_elt_t)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3149 #endif /* not emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3152 regex_grow_registers (num_regs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3153 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3154 #endif /* not MATCH_MAY_ALLOCATE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3156 return REG_NOERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3157 } /* regex_compile */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3159 /* Subroutines for `regex_compile'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3161 /* Store OP at LOC followed by two-byte integer parameter ARG. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3163 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3164 store_op1 (re_opcode_t op, unsigned char *loc, int arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3165 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3166 *loc = (unsigned char) op;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3167 STORE_NUMBER (loc + 1, arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3168 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171 /* Like `store_op1', but for two two-byte parameters ARG1 and ARG2. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174 store_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 *loc = (unsigned char) op;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177 STORE_NUMBER (loc + 1, arg1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3178 STORE_NUMBER (loc + 3, arg2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3182 /* Copy the bytes from LOC to END to open up three bytes of space at LOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3183 for OP followed by two-byte integer parameter ARG. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3185 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3186 insert_op1 (re_opcode_t op, unsigned char *loc, int arg, unsigned char *end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3187 {
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
3188 REGISTER unsigned char *pfrom = end;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
3189 REGISTER unsigned char *pto = end + 3;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3191 while (pfrom != loc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3192 *--pto = *--pfrom;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3193
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194 store_op1 (op, loc, arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198 /* Like `insert_op1', but for two two-byte parameters ARG1 and ARG2. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201 insert_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2,
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3202 unsigned char *end)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3203 {
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
3204 REGISTER unsigned char *pfrom = end;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
3205 REGISTER unsigned char *pto = end + 5;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3207 while (pfrom != loc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3208 *--pto = *--pfrom;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3209
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210 store_op2 (op, loc, arg1, arg2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3214 /* P points to just after a ^ in PATTERN. Return true if that ^ comes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 after an alternative or a begin-subexpression. We assume there is at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216 least one character before the ^. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218 static boolean
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219 at_begline_loc_p (CONST char *pattern, CONST char *p, reg_syntax_t syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221 CONST char *prev = p - 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\';
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3223
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3224 return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3225 /* After a subexpression? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226 (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3227 /* After an alternative? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 || (*prev == '|' && (syntax & RE_NO_BK_VBAR || prev_prev_backslash));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3232 /* The dual of at_begline_loc_p. This one is for $. We assume there is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233 at least one character after the $, i.e., `P < PEND'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3235 static boolean
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3236 at_endline_loc_p (CONST char *p, CONST char *pend, int syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3237 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3238 CONST char *next = p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3239 boolean next_backslash = *next == '\\';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3240 CONST char *next_next = p + 1 < pend ? p + 1 : 0;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3241
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3242 return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3243 /* Before a subexpression? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 (syntax & RE_NO_BK_PARENS ? *next == ')'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3245 : next_backslash && next_next && *next_next == ')')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3246 /* Before an alternative? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 || (syntax & RE_NO_BK_VBAR ? *next == '|'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248 : next_backslash && next_next && *next_next == '|');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3252 /* Returns true if REGNUM is in one of COMPILE_STACK's elements and
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253 false if it's not. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3255 static boolean
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256 group_in_compile_stack (compile_stack_type compile_stack, regnum_t regnum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3257 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3258 int this_element;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3259
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3260 for (this_element = compile_stack.avail - 1;
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3261 this_element >= 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3262 this_element--)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3263 if (compile_stack.stack[this_element].regnum == regnum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3264 return true;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3266 return false;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3267 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3270 /* Read the ending character of a range (in a bracket expression) from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3271 uncompiled pattern *P_PTR (which ends at PEND). We assume the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3272 starting character is in `P[-2]'. (`P[-1]' is the character `-'.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3273 Then we set the translation of all bits between the starting and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3274 ending characters (inclusive) in the compiled pattern B.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3275
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3276 Return an error code.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3277
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3278 We use these short variable names so we can use the same macros as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3279 `regex_compile' itself. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3281 static reg_errcode_t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3282 compile_range (CONST char **p_ptr, CONST char *pend, char *translate,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3283 reg_syntax_t syntax, unsigned char *b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3284 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3285 unsigned this_char;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3287 CONST char *p = *p_ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3288 int range_start, range_end;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3289
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3290 if (p == pend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3291 return REG_ERANGE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3293 /* Even though the pattern is a signed `char *', we need to fetch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3294 with unsigned char *'s; if the high bit of the pattern character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3295 is set, the range endpoints will be negative if we fetch using a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3296 signed char *.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3297
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3298 We also want to fetch the endpoints without translating them; the
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3299 appropriate translation is done in the bit-setting loop below. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3300 /* The SVR4 compiler on the 3B2 had trouble with unsigned CONST char *. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3301 range_start = ((CONST unsigned char *) p)[-2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3302 range_end = ((CONST unsigned char *) p)[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3304 /* Have to increment the pointer into the pattern string, so the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3305 caller isn't still at the ending character. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3306 (*p_ptr)++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3308 /* If the start is after the end, the range is empty. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3309 if (range_start > range_end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3310 return syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3312 /* Here we see why `this_char' has to be larger than an `unsigned
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3313 char' -- the range is inclusive, so if `range_end' == 0xff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3314 (assuming 8-bit characters), we would otherwise go into an infinite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3315 loop, since all characters <= 0xff. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3316 for (this_char = range_start; this_char <= range_end; this_char++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3317 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3318 SET_LIST_BIT (TRANSLATE (this_char));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3319 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3320
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3321 return REG_NOERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3322 }
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3323
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3324 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3325
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3326 static reg_errcode_t
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3327 compile_extended_range (CONST char **p_ptr, CONST char *pend, char *translate,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3328 reg_syntax_t syntax, Lisp_Object rtab)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3329 {
157
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 126
diff changeset
3330 Emchar this_char, range_start, range_end;
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 126
diff changeset
3331 CONST Bufbyte *p;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3332
157
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 126
diff changeset
3333 if (*p_ptr == pend)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3334 return REG_ERANGE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3335
157
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 126
diff changeset
3336 p = (CONST Bufbyte *) *p_ptr;
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 126
diff changeset
3337 range_end = charptr_emchar (p);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3338 p--; /* back to '-' */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3339 DEC_CHARPTR (p); /* back to start of range */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3340 /* We also want to fetch the endpoints without translating them; the
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3341 appropriate translation is done in the bit-setting loop below. */
157
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 126
diff changeset
3342 range_start = charptr_emchar (p);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3343 INC_CHARPTR (*p_ptr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3344
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3345 /* If the start is after the end, the range is empty. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3346 if (range_start > range_end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3347 return syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3348
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3349 /* Can't have ranges spanning different charsets, except maybe for
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3350 ranges entirely witin the first 256 chars. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3351
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3352 if ((range_start >= 0x100 || range_end >= 0x100)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3353 && CHAR_LEADING_BYTE (range_start) !=
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3354 CHAR_LEADING_BYTE (range_end))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3355 return REG_ERANGESPAN;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3356
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3357 /* As advertised, translations only work over the 0 - 0x7F range.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3358 Making this kind of stuff work generally is much harder.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3359 Iterating over the whole range like this would be way efficient
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3360 if the range encompasses 10,000 chars or something. You'd have
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3361 to do something like this:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3362
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3363 range_table a;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3364 range_table b;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3365 map over translation table in [range_start, range_end] of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3366 (put the mapped range in a;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3367 put the translation in b)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3368 invert the range in a and truncate to [range_start, range_end]
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3369 compute the union of a, b
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3370 union the result into rtab
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3371 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3372 for (this_char = range_start;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3373 this_char <= range_end && this_char < 0x80; this_char++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3374 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3375 SET_RANGETAB_BIT (TRANSLATE (this_char));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3376 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3377
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3378 if (this_char <= range_end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3379 put_range_table (rtab, this_char, range_end, Qt);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3380
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3381 return REG_NOERROR;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3382 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3383
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3384 #endif /* MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3386 /* re_compile_fastmap computes a ``fastmap'' for the compiled pattern in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3387 BUFP. A fastmap records which of the (1 << BYTEWIDTH) possible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3388 characters can start a string that matches the pattern. This fastmap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3389 is used by re_search to skip quickly over impossible starting points.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3391 The caller must supply the address of a (1 << BYTEWIDTH)-byte data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3392 area as BUFP->fastmap.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3393
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3394 We set the `fastmap', `fastmap_accurate', and `can_be_null' fields in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3395 the pattern buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3396
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3397 Returns 0 if we succeed, -2 if an internal error. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3399 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3400 re_compile_fastmap (struct re_pattern_buffer *bufp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3401 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3402 int j, k;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3403 #ifdef MATCH_MAY_ALLOCATE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3404 fail_stack_type fail_stack;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3405 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3406 DECLARE_DESTINATION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3407 /* We don't push any register information onto the failure stack. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3408
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
3409 REGISTER char *fastmap = bufp->fastmap;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3410 unsigned char *pattern = bufp->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3411 unsigned long size = bufp->used;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3412 unsigned char *p = pattern;
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
3413 REGISTER unsigned char *pend = pattern + size;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3415 #ifdef REL_ALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3416 /* This holds the pointer to the failure stack, when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3417 it is allocated relocatably. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3418 fail_stack_elt_t *failure_stack_ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3419 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3421 /* Assume that each path through the pattern can be null until
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3422 proven otherwise. We set this false at the bottom of switch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3423 statement, to which we get only if a particular path doesn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3424 match the empty string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3425 boolean path_can_be_null = true;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3427 /* We aren't doing a `succeed_n' to begin with. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3428 boolean succeed_n_p = false;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3430 assert (fastmap != NULL && p != NULL);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3431
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3432 INIT_FAIL_STACK ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3433 bzero (fastmap, 1 << BYTEWIDTH); /* Assume nothing's valid. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3434 bufp->fastmap_accurate = 1; /* It will be when we're done. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3435 bufp->can_be_null = 0;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3436
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3437 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3438 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3439 if (p == pend || *p == succeed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3440 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3441 /* We have reached the (effective) end of pattern. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3442 if (!FAIL_STACK_EMPTY ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3443 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3444 bufp->can_be_null |= path_can_be_null;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3446 /* Reset for next path. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3447 path_can_be_null = true;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3449 p = fail_stack.stack[--fail_stack.avail].pointer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3451 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3452 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3453 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3454 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3455 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3457 /* We should never be about to go beyond the end of the pattern. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3458 assert (p < pend);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3459
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3460 switch (SWITCH_ENUM_CAST ((re_opcode_t) *p++))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3461 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3463 /* I guess the idea here is to simply not bother with a fastmap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3464 if a backreference is used, since it's too hard to figure out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3465 the fastmap for the corresponding group. Setting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3466 `can_be_null' stops `re_search_2' from using the fastmap, so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3467 that is all we do. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3468 case duplicate:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3469 bufp->can_be_null = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3470 goto done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3471
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3472
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3473 /* Following are the cases which match a character. These end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3474 with `break'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3476 case exactn:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3477 fastmap[p[1]] = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3478 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3479
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3481 case charset:
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3482 /* XEmacs: Under Mule, these bit vectors will
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3483 only contain values for characters below 0x80. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3484 for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3485 if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3486 fastmap[j] = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3487 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3490 case charset_not:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3491 /* Chars beyond end of map must be allowed. */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3492 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3493 for (j = *p * BYTEWIDTH; j < 0x80; j++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3494 fastmap[j] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3495 /* And all extended characters must be allowed, too. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3496 for (j = 0x80; j < 0xA0; j++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3497 fastmap[j] = 1;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3498 #else /* ! MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3499 for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3500 fastmap[j] = 1;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3501 #endif /* ! MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3503 for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3504 if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3505 fastmap[j] = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3506 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3507
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3508 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3509 case charset_mule:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3510 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3511 int nentries;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3512 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3513
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3514 nentries = unified_range_table_nentries (p);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3515 for (i = 0; i < nentries; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3516 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3517 EMACS_INT first, last;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3518 Lisp_Object dummy_val;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3519 int jj;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3520 Bufbyte strr[MAX_EMCHAR_LEN];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3521
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3522 unified_range_table_get_range (p, i, &first, &last,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3523 &dummy_val);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3524 for (jj = first; jj <= last && jj < 0x80; jj++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3525 fastmap[jj] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3526 /* Ranges below 0x100 can span charsets, but there
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3527 are only two (Control-1 and Latin-1), and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3528 either first or last has to be in them. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3529 set_charptr_emchar (strr, first);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3530 fastmap[*strr] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3531 if (last < 0x100)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3532 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3533 set_charptr_emchar (strr, last);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3534 fastmap[*strr] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3535 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3536 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3537 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3538 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3539
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3540 case charset_mule_not:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3541 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3542 int nentries;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3543 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3544
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3545 nentries = unified_range_table_nentries (p);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3546 for (i = 0; i < nentries; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3547 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3548 EMACS_INT first, last;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3549 Lisp_Object dummy_val;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3550 int jj;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3551 int smallest_prev = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3552
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3553 unified_range_table_get_range (p, i, &first, &last,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3554 &dummy_val);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3555 for (jj = smallest_prev; jj < first && jj < 0x80; jj++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3556 fastmap[jj] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3557 smallest_prev = last + 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3558 if (smallest_prev >= 0x80)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3559 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3560 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3561 /* Calculating which leading bytes are actually allowed
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3562 here is rather difficult, so we just punt and allow
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3563 all of them. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3564 for (i = 0x80; i < 0xA0; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3565 fastmap[i] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3566 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3567 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3568 #endif /* MULE */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3569
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3571 case wordchar:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3572 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3573 k = (int) Sword;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3574 goto matchsyntax;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3575 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3576 for (j = 0; j < (1 << BYTEWIDTH); j++)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3577 if (SYNTAX_UNSAFE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3578 (XCHAR_TABLE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3579 (regex_emacs_buffer->mirror_syntax_table), j) == Sword)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3580 fastmap[j] = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3581 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3582 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3583
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3585 case notwordchar:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3586 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3587 k = (int) Sword;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3588 goto matchnotsyntax;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3589 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3590 for (j = 0; j < (1 << BYTEWIDTH); j++)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3591 if (SYNTAX_UNSAFE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3592 (XCHAR_TABLE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3593 (regex_emacs_buffer->mirror_syntax_table), j) != Sword)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3594 fastmap[j] = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3595 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3596 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3597
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3599 case anychar:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3600 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3601 int fastmap_newline = fastmap['\n'];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3602
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3603 /* `.' matches anything ... */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3604 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3605 /* "anything" only includes bytes that can be the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3606 first byte of a character. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3607 for (j = 0; j < 0xA0; j++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3608 fastmap[j] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3609 #else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3610 for (j = 0; j < (1 << BYTEWIDTH); j++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3611 fastmap[j] = 1;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3612 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3614 /* ... except perhaps newline. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3615 if (!(bufp->syntax & RE_DOT_NEWLINE))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3616 fastmap['\n'] = fastmap_newline;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3617
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3618 /* Return if we have already set `can_be_null'; if we have,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3619 then the fastmap is irrelevant. Something's wrong here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3620 else if (bufp->can_be_null)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3621 goto done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3623 /* Otherwise, have to check alternative paths. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3624 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3625 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3626
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3627 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3628 case syntaxspec:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3629 k = *p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3630 matchsyntax:
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3631 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3632 for (j = 0; j < 0x80; j++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3633 if (SYNTAX_UNSAFE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3634 (XCHAR_TABLE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3635 (regex_emacs_buffer->mirror_syntax_table), j) ==
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3636 (enum syntaxcode) k)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3637 fastmap[j] = 1;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3638 for (j = 0x80; j < 0xA0; j++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3639 {
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3640 if (LEADING_BYTE_PREFIX_P(j))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3641 /* too complicated to calculate this right */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3642 fastmap[j] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3643 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3644 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3645 int multi_p;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3646 Lisp_Object cset;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3647
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3648 cset = CHARSET_BY_LEADING_BYTE (j);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3649 if (CHARSETP (cset))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3650 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3651 if (charset_syntax (regex_emacs_buffer, cset,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3652 &multi_p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3653 == Sword || multi_p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3654 fastmap[j] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3655 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3656 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3657 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3658 #else /* ! MULE */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3659 for (j = 0; j < (1 << BYTEWIDTH); j++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3660 if (SYNTAX_UNSAFE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3661 (XCHAR_TABLE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3662 (regex_emacs_buffer->mirror_syntax_table), j) ==
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3663 (enum syntaxcode) k)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3664 fastmap[j] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3665 #endif /* ! MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3666 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3667
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3669 case notsyntaxspec:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3670 k = *p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3671 matchnotsyntax:
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3672 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3673 for (j = 0; j < 0x80; j++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3674 if (SYNTAX_UNSAFE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3675 (XCHAR_TABLE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3676 (regex_emacs_buffer->mirror_syntax_table), j) !=
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3677 (enum syntaxcode) k)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3678 fastmap[j] = 1;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3679 for (j = 0x80; j < 0xA0; j++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3680 {
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3681 if (LEADING_BYTE_PREFIX_P(j))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3682 /* too complicated to calculate this right */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3683 fastmap[j] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3684 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3685 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3686 int multi_p;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3687 Lisp_Object cset;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3688
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3689 cset = CHARSET_BY_LEADING_BYTE (j);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3690 if (CHARSETP (cset))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3691 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3692 if (charset_syntax (regex_emacs_buffer, cset,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3693 &multi_p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3694 != Sword || multi_p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3695 fastmap[j] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3696 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3697 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3698 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3699 #else /* ! MULE */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3700 for (j = 0; j < (1 << BYTEWIDTH); j++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3701 if (SYNTAX_UNSAFE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3702 (XCHAR_TABLE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3703 (regex_emacs_buffer->mirror_syntax_table), j) !=
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3704 (enum syntaxcode) k)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3705 fastmap[j] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
3706 #endif /* ! MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3707 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3708
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
3709 #ifdef MULE
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
3710 /* 97/2/17 jhod category patch */
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
3711 case categoryspec:
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
3712 case notcategoryspec:
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
3713 bufp->can_be_null = 1;
157
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 126
diff changeset
3714 return 0;
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
3715 /* end if category patch */
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
3716 #endif /* MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3718 /* All cases after this match the empty string. These end with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3719 `continue'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3720
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3722 case before_dot:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3723 case at_dot:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3724 case after_dot:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3725 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3726 #endif /* not emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3727
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3729 case no_op:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3730 case begline:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3731 case endline:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3732 case begbuf:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3733 case endbuf:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3734 case wordbound:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3735 case notwordbound:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3736 case wordbeg:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3737 case wordend:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3738 case push_dummy_failure:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3739 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3741
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3742 case jump_n:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3743 case pop_failure_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3744 case maybe_pop_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3745 case jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3746 case jump_past_alt:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3747 case dummy_failure_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3748 EXTRACT_NUMBER_AND_INCR (j, p);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3749 p += j;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3750 if (j > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3751 continue;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3752
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3753 /* Jump backward implies we just went through the body of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3754 loop and matched nothing. Opcode jumped to should be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3755 `on_failure_jump' or `succeed_n'. Just treat it like an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3756 ordinary jump. For a * loop, it has pushed its failure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3757 point already; if so, discard that as redundant. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3758 if ((re_opcode_t) *p != on_failure_jump
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3759 && (re_opcode_t) *p != succeed_n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3760 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3761
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3762 p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3763 EXTRACT_NUMBER_AND_INCR (j, p);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3764 p += j;
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3765
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3766 /* If what's on the stack is where we are now, pop it. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3767 if (!FAIL_STACK_EMPTY ()
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3768 && fail_stack.stack[fail_stack.avail - 1].pointer == p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3769 fail_stack.avail--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3770
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3771 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3773
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3774 case on_failure_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3775 case on_failure_keep_string_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3776 handle_on_failure_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3777 EXTRACT_NUMBER_AND_INCR (j, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3778
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3779 /* For some patterns, e.g., `(a?)?', `p+j' here points to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3780 end of the pattern. We don't want to push such a point,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3781 since when we restore it above, entering the switch will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3782 increment `p' past the end of the pattern. We don't need
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3783 to push such a point since we obviously won't find any more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3784 fastmap entries beyond `pend'. Such a pattern can match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3785 the null string, though. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3786 if (p + j < pend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3787 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3788 if (!PUSH_PATTERN_OP (p + j, fail_stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3789 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3790 RESET_FAIL_STACK ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3791 return -2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3792 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3793 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3794 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3795 bufp->can_be_null = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3797 if (succeed_n_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3798 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3799 EXTRACT_NUMBER_AND_INCR (k, p); /* Skip the n. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3800 succeed_n_p = false;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3801 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3802
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3803 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3804
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3805
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3806 case succeed_n:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3807 /* Get to the number of times to succeed. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3808 p += 2;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3809
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3810 /* Increment p past the n for when k != 0. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3811 EXTRACT_NUMBER_AND_INCR (k, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3812 if (k == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3813 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3814 p -= 4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3815 succeed_n_p = true; /* Spaghetti code alert. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3816 goto handle_on_failure_jump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3817 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3818 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3820
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3821 case set_number_at:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3822 p += 4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3823 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3824
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3825
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3826 case start_memory:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3827 case stop_memory:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3828 p += 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3829 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3830
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3831
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3832 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3833 abort (); /* We have listed all the cases. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3834 } /* switch *p++ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3835
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3836 /* Getting here means we have found the possible starting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3837 characters for one path of the pattern -- and that the empty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3838 string does not match. We need not follow this path further.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3839 Instead, look at the next alternative (remembered on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3840 stack), or quit if no more. The test at the top of the loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3841 does these things. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3842 path_can_be_null = false;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3843 p = pend;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3844 } /* while p */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3845
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3846 /* Set `can_be_null' for the last path (also the first path, if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3847 pattern is empty). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3848 bufp->can_be_null |= path_can_be_null;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3849
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3850 done:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3851 RESET_FAIL_STACK ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3852 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3853 } /* re_compile_fastmap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3854
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3855 /* Set REGS to hold NUM_REGS registers, storing them in STARTS and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3856 ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3857 this memory for recording register information. STARTS and ENDS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3858 must be allocated using the malloc library routine, and must each
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3859 be at least NUM_REGS * sizeof (regoff_t) bytes long.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3861 If NUM_REGS == 0, then subsequent matches should allocate their own
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3862 register data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3863
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3864 Unless this function is called, the first search or match using
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3865 PATTERN_BUFFER will allocate its own register data, without
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3866 freeing the old data. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3867
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3868 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3869 re_set_registers (struct re_pattern_buffer *bufp, struct re_registers *regs,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3870 unsigned num_regs, regoff_t *starts, regoff_t *ends)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3871 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3872 if (num_regs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3873 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3874 bufp->regs_allocated = REGS_REALLOCATE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3875 regs->num_regs = num_regs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3876 regs->start = starts;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3877 regs->end = ends;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3878 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3879 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3880 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3881 bufp->regs_allocated = REGS_UNALLOCATED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3882 regs->num_regs = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3883 regs->start = regs->end = (regoff_t *) 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3884 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3885 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3886
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3887 /* Searching routines. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3888
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3889 /* Like re_search_2, below, but only one string is specified, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3890 doesn't let you say where to stop matching. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3891
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3892 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3893 re_search (struct re_pattern_buffer *bufp, CONST char *string, int size,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3894 int startpos, int range, struct re_registers *regs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3895 {
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3896 return re_search_2 (bufp, NULL, 0, string, size, startpos, range,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3897 regs, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3898 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3899
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
3900 #ifndef emacs
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
3901 /* Snarfed from src/lisp.h, needed for compiling [ce]tags. */
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
3902 # define bytecount_to_charcount(ptr, len) (len)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
3903 # define charcount_to_bytecount(ptr, len) (len)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
3904 typedef int Charcount;
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
3905 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3906
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3907 /* Using the compiled pattern in BUFP->buffer, first tries to match the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3908 virtual concatenation of STRING1 and STRING2, starting first at index
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3909 STARTPOS, then at STARTPOS + 1, and so on.
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
3910
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
3911 With MULE, STARTPOS is a byte position, not a char position. And the
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
3912 search will increment STARTPOS by the width of the current leading
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
3913 character.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3914
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3915 STRING1 and STRING2 have length SIZE1 and SIZE2, respectively.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3916
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3917 RANGE is how far to scan while trying to match. RANGE = 0 means try
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3918 only at STARTPOS; in general, the last start tried is STARTPOS +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3919 RANGE.
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
3920
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
3921 With MULE, RANGE is a byte position, not a char position. The last
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
3922 start tried is the character starting <= STARTPOS + RANGE.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3923
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3924 In REGS, return the indices of the virtual concatenation of STRING1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3925 and STRING2 that matched the entire BUFP->buffer and its contained
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3926 subexpressions.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3927
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3928 Do not consider matching one past the index STOP in the virtual
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3929 concatenation of STRING1 and STRING2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3930
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3931 We return either the position in the strings at which the match was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3932 found, -1 if no match, or -2 if error (such as failure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3933 stack overflow). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3934
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3935 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3936 re_search_2 (struct re_pattern_buffer *bufp, CONST char *string1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3937 int size1, CONST char *string2, int size2, int startpos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3938 int range, struct re_registers *regs, int stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3939 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3940 int val;
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
3941 REGISTER char *fastmap = bufp->fastmap;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
3942 REGISTER char *translate = bufp->translate;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3943 int total_size = size1 + size2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3944 int endpos = startpos + range;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3945 #ifdef REGEX_BEGLINE_CHECK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3946 int anchored_at_begline = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3947 #endif
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
3948 CONST unsigned char *d;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
3949 Charcount d_size;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3950
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3951 /* Check for out-of-range STARTPOS. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3952 if (startpos < 0 || startpos > total_size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3953 return -1;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3954
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3955 /* Fix up RANGE if it might eventually take us outside
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3956 the virtual concatenation of STRING1 and STRING2. */
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
3957 if (endpos < 0)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
3958 range = 0 - startpos;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3959 else if (endpos > total_size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3960 range = total_size - startpos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3961
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3962 /* If the search isn't to be a backwards one, don't waste time in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3963 search for a pattern that must be anchored. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3964 if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == begbuf && range > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3965 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3966 if (startpos > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3967 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3968 else
126
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 110
diff changeset
3969 {
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 110
diff changeset
3970 d = ((CONST unsigned char *)
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 110
diff changeset
3971 (startpos >= size1 ? string2 - size1 : string1) + startpos);
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 110
diff changeset
3972 range = charcount_to_bytecount (d, 1);
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 110
diff changeset
3973 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3974 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3975
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3976 /* Update the fastmap now if not correct already. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3977 if (fastmap && !bufp->fastmap_accurate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3978 if (re_compile_fastmap (bufp) == -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3979 return -2;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3980
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3981 #ifdef REGEX_BEGLINE_CHECK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3982 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3983 int i = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3984
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3985 while (i < bufp->used)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3986 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3987 if (bufp->buffer[i] == start_memory ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3988 bufp->buffer[i] == stop_memory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3989 i += 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3990 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3991 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3992 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3993 anchored_at_begline = i < bufp->used && bufp->buffer[i] == begline;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3994 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3995 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3996
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3997 /* Loop through the string, looking for a place to start matching. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3998 for (;;)
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
3999 {
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4000 #ifdef REGEX_BEGLINE_CHECK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4001 /* If the regex is anchored at the beginning of a line (i.e. with a ^),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4002 then we can speed things up by skipping to the next beginning-of-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4003 line. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4004 if (anchored_at_begline && startpos > 0 && startpos != size1 &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4005 range > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4006 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4007 /* whose stupid idea was it anyway to make this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4008 function take two strings to match?? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4009 int lim = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4010 int irange = range;
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4011
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4012 if (startpos < size1 && startpos + range >= size1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4013 lim = range - (size1 - startpos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4014
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4015 d = ((CONST unsigned char *)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4016 (startpos >= size1 ? string2 - size1 : string1) + startpos);
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4017 DEC_CHARPTR(d); /* Ok, since startpos != size1. */
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4018 d_size = charcount_to_bytecount (d, 1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4019
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4020 if (translate)
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4021 #ifdef MULE
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4022 while (range > lim && (*d >= 0x80 || translate[*d] != '\n'))
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4023 #else
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4024 while (range > lim && translate[*d] != '\n')
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4025 #endif
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4026 {
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4027 d += d_size; /* Speedier INC_CHARPTR(d) */
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4028 d_size = charcount_to_bytecount (d, 1);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4029 range -= d_size;
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4030 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4031 else
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4032 while (range > lim && *d != '\n')
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4033 {
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4034 d += d_size; /* Speedier INC_CHARPTR(d) */
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4035 d_size = charcount_to_bytecount (d, 1);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4036 range -= d_size;
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4037 }
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4038
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4039 startpos += irange - range;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4040 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4041 #endif /* REGEX_BEGLINE_CHECK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4042
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4043 /* If a fastmap is supplied, skip quickly over characters that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4044 cannot be the start of a match. If the pattern can match the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4045 null string, however, we don't need to skip characters; we want
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4046 the first null string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4047 if (fastmap && startpos < total_size && !bufp->can_be_null)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4048 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4049 if (range > 0) /* Searching forwards. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4050 {
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4051 int lim = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4052 int irange = range;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4053
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4054 if (startpos < size1 && startpos + range >= size1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4055 lim = range - (size1 - startpos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4056
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4057 d = ((CONST unsigned char *)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4058 (startpos >= size1 ? string2 - size1 : string1) + startpos);
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4059
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4060 /* Written out as an if-else to avoid testing `translate'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4061 inside the loop. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4062 if (translate)
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4063 #ifdef MULE
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4064 while (range > lim && *d < 0x80 && !fastmap[translate[*d]])
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4065 #else
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 203
diff changeset
4066 while (range > lim && !fastmap[(unsigned char)translate[*d]])
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4067 #endif
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4068 {
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4069 d_size = charcount_to_bytecount (d, 1);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4070 range -= d_size;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4071 d += d_size; /* Speedier INC_CHARPTR(d) */
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4072 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4073 else
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4074 while (range > lim && !fastmap[*d])
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4075 {
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4076 d_size = charcount_to_bytecount (d, 1);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4077 range -= d_size;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4078 d += d_size; /* Speedier INC_CHARPTR(d) */
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4079 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4080
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4081 startpos += irange - range;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4082 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4083 else /* Searching backwards. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4084 {
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4085 unsigned char c = (size1 == 0 || startpos >= size1
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4086 ? string2[startpos - size1]
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4087 : string1[startpos]);
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4088 #ifdef MULE
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4089 if (c < 0x80 && !fastmap[(unsigned char) TRANSLATE (c)])
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4090 #else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4091 if (!fastmap[(unsigned char) TRANSLATE (c)])
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4092 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4093 goto advance;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4094 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4095 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4096
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4097 /* If can't match the null string, and that's all we have left, fail. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4098 if (range >= 0 && startpos == total_size && fastmap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4099 && !bufp->can_be_null)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4100 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4102 #ifdef emacs /* XEmacs added, w/removal of immediate_quit */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4103 if (!no_quit_in_re_search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4104 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4105 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4106 val = re_match_2_internal (bufp, string1, size1, string2, size2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4107 startpos, regs, stop);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4108 #ifndef REGEX_MALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4109 #ifdef C_ALLOCA
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4110 alloca (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4111 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4112 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4114 if (val >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4115 return startpos;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4116
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4117 if (val == -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4118 return -2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4120 advance:
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4121 if (!range)
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
4122 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4123 else if (range > 0)
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4124 {
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4125 d = ((CONST unsigned char *)
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4126 (startpos >= size1 ? string2 - size1 : string1) + startpos);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4127 d_size = charcount_to_bytecount (d, 1);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4128 range -= d_size;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4129 startpos += d_size;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4130 }
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4131 else
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4132 {
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4133 /* Note startpos > size1 not >=. If we are on the
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4134 string1/string2 boundary, we want to backup into string1. */
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4135 d = ((CONST unsigned char *)
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4136 (startpos > size1 ? string2 - size1 : string1) + startpos);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4137 DEC_CHARPTR(d);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4138 d_size = charcount_to_bytecount (d, 1);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4139 range += d_size;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4140 startpos -= d_size;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4141 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4142 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4143 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4144 } /* re_search_2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4146 /* Declarations and macros for re_match_2. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4148 /* This converts PTR, a pointer into one of the search strings `string1'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4149 and `string2' into an offset from the beginning of that string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4150 #define POINTER_TO_OFFSET(ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4151 (FIRST_STRING_P (ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4152 ? ((regoff_t) ((ptr) - string1)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4153 : ((regoff_t) ((ptr) - string2 + size1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4155 /* Macros for dealing with the split strings in re_match_2. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4157 #define MATCHING_IN_FIRST_STRING (dend == end_match_1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4159 /* Call before fetching a character with *d. This switches over to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4160 string2 if necessary. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4161 #define PREFETCH() \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4162 while (d == dend) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4163 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4164 /* End of string2 => fail. */ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4165 if (dend == end_match_2) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4166 goto fail; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4167 /* End of string1 => advance to string2. */ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4168 d = string2; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4169 dend = end_match_2; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4170 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4173 /* Test if at very beginning or at very end of the virtual concatenation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4174 of `string1' and `string2'. If only one string, it's `string2'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4175 #define AT_STRINGS_BEG(d) ((d) == (size1 ? string1 : string2) || !size2)
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4176 #define AT_STRINGS_END(d) ((d) == end2)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4178 /* XEmacs change:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4179 If the given position straddles the string gap, return the equivalent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4180 position that is before or after the gap, respectively; otherwise,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4181 return the same position. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4182 #define POS_BEFORE_GAP_UNSAFE(d) ((d) == string2 ? end1 : (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4183 #define POS_AFTER_GAP_UNSAFE(d) ((d) == end1 ? string2 : (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4185 /* Test if CH is a word-constituent character. (XEmacs change) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4186 #define WORDCHAR_P_UNSAFE(ch) \
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4187 (SYNTAX_UNSAFE (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table), \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4188 ch) == Sword)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4190 /* Free everything we malloc. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4191 #ifdef MATCH_MAY_ALLOCATE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4192 #define FREE_VAR(var) if (var) REGEX_FREE (var); var = NULL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4193 #define FREE_VARIABLES() \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4194 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4195 REGEX_FREE_STACK (fail_stack.stack); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4196 FREE_VAR (regstart); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4197 FREE_VAR (regend); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4198 FREE_VAR (old_regstart); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4199 FREE_VAR (old_regend); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4200 FREE_VAR (best_regstart); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4201 FREE_VAR (best_regend); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4202 FREE_VAR (reg_info); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4203 FREE_VAR (reg_dummy); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4204 FREE_VAR (reg_info_dummy); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4205 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4206 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4207 #define FREE_VARIABLES() ((void)0) /* Do nothing! But inhibit gcc warning. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4208 #endif /* not MATCH_MAY_ALLOCATE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4210 /* These values must meet several constraints. They must not be valid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4211 register values; since we have a limit of 255 registers (because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4212 we use only one byte in the pattern for the register number), we can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4213 use numbers larger than 255. They must differ by 1, because of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4214 NUM_FAILURE_ITEMS above. And the value for the lowest register must
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4215 be larger than the value for the highest register, so we do not try
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4216 to actually save any registers when none are active. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4217 #define NO_HIGHEST_ACTIVE_REG (1 << BYTEWIDTH)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4218 #define NO_LOWEST_ACTIVE_REG (NO_HIGHEST_ACTIVE_REG + 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4220 /* Matching routines. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4222 #ifndef emacs /* Emacs never uses this. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4223 /* re_match is like re_match_2 except it takes only a single string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4225 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4226 re_match (struct re_pattern_buffer *bufp, CONST char *string, int size,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4227 int pos, struct re_registers *regs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4228 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4229 int result = re_match_2_internal (bufp, NULL, 0, string, size,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4230 pos, regs, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4231 alloca (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4232 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4233 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4234 #endif /* not emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4237 /* re_match_2 matches the compiled pattern in BUFP against the
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4238 (virtual) concatenation of STRING1 and STRING2 (of length SIZE1 and
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4239 SIZE2, respectively). We start matching at POS, and stop matching
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4240 at STOP.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4241
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4242 If REGS is non-null and the `no_sub' field of BUFP is nonzero, we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4243 store offsets for the substring each group matched in REGS. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4244 documentation for exactly how many groups we fill.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4246 We return -1 if no match, -2 if an internal error (such as the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4247 failure stack overflowing). Otherwise, we return the length of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4248 matched substring. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4250 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4251 re_match_2 (struct re_pattern_buffer *bufp, CONST char *string1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4252 int size1, CONST char *string2, int size2, int pos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4253 struct re_registers *regs, int stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4254 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4255 int result = re_match_2_internal (bufp, string1, size1, string2, size2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4256 pos, regs, stop);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4257 alloca (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4258 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4259 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4261 /* This is a separate function so that we can force an alloca cleanup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4262 afterwards. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4263 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4264 re_match_2_internal (struct re_pattern_buffer *bufp, CONST char *string1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4265 int size1, CONST char *string2, int size2, int pos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4266 struct re_registers *regs, int stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4267 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4268 /* General temporaries. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4269 int mcnt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4270 unsigned char *p1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4271 int should_succeed; /* XEmacs change */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4273 /* Just past the end of the corresponding string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4274 CONST char *end1, *end2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4276 /* Pointers into string1 and string2, just past the last characters in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4277 each to consider matching. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4278 CONST char *end_match_1, *end_match_2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4280 /* Where we are in the data, and the end of the current string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4281 CONST char *d, *dend;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4282
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4283 /* Where we are in the pattern, and the end of the pattern. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4284 unsigned char *p = bufp->buffer;
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
4285 REGISTER unsigned char *pend = p + bufp->used;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4287 /* Mark the opcode just after a start_memory, so we can test for an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4288 empty subpattern when we get to the stop_memory. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4289 unsigned char *just_past_start_mem = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4291 /* We use this to map every character in the string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4292 char *translate = bufp->translate;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4294 /* Failure point stack. Each place that can handle a failure further
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4295 down the line pushes a failure point on this stack. It consists of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4296 restart, regend, and reg_info for all registers corresponding to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4297 the subexpressions we're currently inside, plus the number of such
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4298 registers, and, finally, two char *'s. The first char * is where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4299 to resume scanning the pattern; the second one is where to resume
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4300 scanning the strings. If the latter is zero, the failure point is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4301 a ``dummy''; if a failure happens and the failure point is a dummy,
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4302 it gets discarded and the next one is tried. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4303 #ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4304 fail_stack_type fail_stack;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4305 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4306 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4307 static unsigned failure_id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4308 unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4309 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4311 #ifdef REL_ALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4312 /* This holds the pointer to the failure stack, when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4313 it is allocated relocatably. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4314 fail_stack_elt_t *failure_stack_ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4315 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4317 /* We fill all the registers internally, independent of what we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4318 return, for use in backreferences. The number here includes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4319 an element for register zero. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4320 unsigned num_regs = bufp->re_nsub + 1;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4321
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4322 /* The currently active registers. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4323 unsigned lowest_active_reg = NO_LOWEST_ACTIVE_REG;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4324 unsigned highest_active_reg = NO_HIGHEST_ACTIVE_REG;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4326 /* Information on the contents of registers. These are pointers into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4327 the input strings; they record just what was matched (on this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4328 attempt) by a subexpression part of the pattern, that is, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4329 regnum-th regstart pointer points to where in the pattern we began
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4330 matching and the regnum-th regend points to right after where we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4331 stopped matching the regnum-th subexpression. (The zeroth register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4332 keeps track of what the whole pattern matches.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4333 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4334 CONST char **regstart, **regend;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4335 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4337 /* If a group that's operated upon by a repetition operator fails to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4338 match anything, then the register for its start will need to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4339 restored because it will have been set to wherever in the string we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4340 are when we last see its open-group operator. Similarly for a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4341 register's end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4342 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4343 CONST char **old_regstart, **old_regend;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4344 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4345
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4346 /* The is_active field of reg_info helps us keep track of which (possibly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4347 nested) subexpressions we are currently in. The matched_something
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4348 field of reg_info[reg_num] helps us tell whether or not we have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4349 matched any of the pattern so far this time through the reg_num-th
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4350 subexpression. These two fields get reset each time through any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4351 loop their register is in. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4352 #ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4353 register_info_type *reg_info;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4354 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4356 /* The following record the register info as found in the above
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4357 variables when we find a match better than any we've seen before.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4358 This happens as we backtrack through the failure points, which in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4359 turn happens only if we have not yet matched the entire string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4360 unsigned best_regs_set = false;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4361 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4362 CONST char **best_regstart, **best_regend;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4363 #endif
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4364
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4365 /* Logically, this is `best_regend[0]'. But we don't want to have to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4366 allocate space for that if we're not allocating space for anything
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4367 else (see below). Also, we never need info about register 0 for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4368 any of the other register vectors, and it seems rather a kludge to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4369 treat `best_regend' differently than the rest. So we keep track of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4370 the end of the best match so far in a separate variable. We
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4371 initialize this to NULL so that when we backtrack the first time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4372 and need to test it, it's not garbage. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4373 CONST char *match_end = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4375 /* This helps SET_REGS_MATCHED avoid doing redundant work. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4376 int set_regs_matched_done = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4378 /* Used when we pop values we don't care about. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4379 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4380 CONST char **reg_dummy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4381 register_info_type *reg_info_dummy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4382 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4384 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4385 /* Counts the total number of registers pushed. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4386 unsigned num_regs_pushed = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4387 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4388
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4389 /* 1 if this match ends in the same string (string1 or string2)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4390 as the best previous match. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4391 boolean same_str_p;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4392
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4393 /* 1 if this match is the best seen so far. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4394 boolean best_match_p;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4395
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4396 DEBUG_PRINT1 ("\n\nEntering re_match_2.\n");
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4397
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4398 INIT_FAIL_STACK ();
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4399
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4400 #ifdef MATCH_MAY_ALLOCATE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4401 /* Do not bother to initialize all the register variables if there are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4402 no groups in the pattern, as it takes a fair amount of time. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4403 there are groups, we include space for register 0 (the whole
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4404 pattern), even though we never use it, since it simplifies the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4405 array indexing. We should fix this. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4406 if (bufp->re_nsub)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4407 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4408 regstart = REGEX_TALLOC (num_regs, CONST char *);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4409 regend = REGEX_TALLOC (num_regs, CONST char *);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4410 old_regstart = REGEX_TALLOC (num_regs, CONST char *);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4411 old_regend = REGEX_TALLOC (num_regs, CONST char *);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4412 best_regstart = REGEX_TALLOC (num_regs, CONST char *);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4413 best_regend = REGEX_TALLOC (num_regs, CONST char *);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4414 reg_info = REGEX_TALLOC (num_regs, register_info_type);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4415 reg_dummy = REGEX_TALLOC (num_regs, CONST char *);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4416 reg_info_dummy = REGEX_TALLOC (num_regs, register_info_type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4417
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4418 if (!(regstart && regend && old_regstart && old_regend && reg_info
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4419 && best_regstart && best_regend && reg_dummy && reg_info_dummy))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4420 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4421 FREE_VARIABLES ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4422 return -2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4423 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4424 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4425 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4426 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4427 /* We must initialize all our variables to NULL, so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4428 `FREE_VARIABLES' doesn't try to free them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4429 regstart = regend = old_regstart = old_regend = best_regstart
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4430 = best_regend = reg_dummy = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4431 reg_info = reg_info_dummy = (register_info_type *) NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4432 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4433 #endif /* MATCH_MAY_ALLOCATE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4435 /* The starting position is bogus. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4436 if (pos < 0 || pos > size1 + size2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4437 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4438 FREE_VARIABLES ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4439 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4440 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4441
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4442 /* Initialize subexpression text positions to -1 to mark ones that no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4443 start_memory/stop_memory has been seen for. Also initialize the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4444 register information struct. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4445 for (mcnt = 1; mcnt < num_regs; mcnt++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4446 {
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4447 regstart[mcnt] = regend[mcnt]
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4448 = old_regstart[mcnt] = old_regend[mcnt] = REG_UNSET_VALUE;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4449
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4450 REG_MATCH_NULL_STRING_P (reg_info[mcnt]) = MATCH_NULL_UNSET_VALUE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4451 IS_ACTIVE (reg_info[mcnt]) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4452 MATCHED_SOMETHING (reg_info[mcnt]) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4453 EVER_MATCHED_SOMETHING (reg_info[mcnt]) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4454 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4455
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4456 /* We move `string1' into `string2' if the latter's empty -- but not if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4457 `string1' is null. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4458 if (size2 == 0 && string1 != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4459 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4460 string2 = string1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4461 size2 = size1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4462 string1 = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4463 size1 = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4464 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4465 end1 = string1 + size1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4466 end2 = string2 + size2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4467
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4468 /* Compute where to stop matching, within the two strings. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4469 if (stop <= size1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4470 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4471 end_match_1 = string1 + stop;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4472 end_match_2 = string2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4473 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4474 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4475 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4476 end_match_1 = end1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4477 end_match_2 = string2 + stop - size1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4478 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4479
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4480 /* `p' scans through the pattern as `d' scans through the data.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4481 `dend' is the end of the input string that `d' points within. `d'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4482 is advanced into the following input string whenever necessary, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4483 this happens before fetching; therefore, at the beginning of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4484 loop, `d' can be pointing at the end of a string, but it cannot
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4485 equal `string2'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4486 if (size1 > 0 && pos <= size1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4487 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4488 d = string1 + pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4489 dend = end_match_1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4490 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4491 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4492 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4493 d = string2 + pos - size1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4494 dend = end_match_2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4495 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4497 DEBUG_PRINT1 ("The compiled pattern is: ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4498 DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4499 DEBUG_PRINT1 ("The string to match is: `");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4500 DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4501 DEBUG_PRINT1 ("'\n");
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4502
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4503 /* This loops over pattern commands. It exits by returning from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4504 function if the match is complete, or it drops through if the match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4505 fails at this starting point in the input data. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4506 for (;;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4507 {
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 169
diff changeset
4508 DEBUG_PRINT2 ("\n0x%p: ", p);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4510 if (p == pend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4511 { /* End of pattern means we might have succeeded. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4512 DEBUG_PRINT1 ("end of pattern ... ");
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4513
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4514 /* If we haven't matched the entire string, and we want the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4515 longest match, try backtracking. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4516 if (d != end_match_2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4517 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4518 same_str_p = (FIRST_STRING_P (match_end)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4519 == MATCHING_IN_FIRST_STRING);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4521 /* AIX compiler got confused when this was combined
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4522 with the previous declaration. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4523 if (same_str_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4524 best_match_p = d > match_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4525 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4526 best_match_p = !MATCHING_IN_FIRST_STRING;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4527
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4528 DEBUG_PRINT1 ("backtracking.\n");
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4529
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4530 if (!FAIL_STACK_EMPTY ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4531 { /* More failure points to try. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4533 /* If exceeds best match so far, save it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4534 if (!best_regs_set || best_match_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4535 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4536 best_regs_set = true;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4537 match_end = d;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4538
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4539 DEBUG_PRINT1 ("\nSAVING match as best so far.\n");
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4540
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4541 for (mcnt = 1; mcnt < num_regs; mcnt++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4542 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4543 best_regstart[mcnt] = regstart[mcnt];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4544 best_regend[mcnt] = regend[mcnt];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4545 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4546 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4547 goto fail;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4548 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4550 /* If no failure points, don't restore garbage. And if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4551 last match is real best match, don't restore second
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4552 best one. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4553 else if (best_regs_set && !best_match_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4554 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4555 restore_best_regs:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4556 /* Restore best match. It may happen that `dend ==
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4557 end_match_1' while the restored d is in string2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4558 For example, the pattern `x.*y.*z' against the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4559 strings `x-' and `y-z-', if the two strings are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4560 not consecutive in memory. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4561 DEBUG_PRINT1 ("Restoring best registers.\n");
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4562
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4563 d = match_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4564 dend = ((d >= string1 && d <= end1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4565 ? end_match_1 : end_match_2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4567 for (mcnt = 1; mcnt < num_regs; mcnt++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4568 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4569 regstart[mcnt] = best_regstart[mcnt];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4570 regend[mcnt] = best_regend[mcnt];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4571 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4572 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4573 } /* d != end_match_2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4575 succeed_label:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4576 DEBUG_PRINT1 ("Accepting match.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4577
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4578 /* If caller wants register contents data back, do it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4579 if (regs && !bufp->no_sub)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4580 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4581 /* Have the register data arrays been allocated? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4582 if (bufp->regs_allocated == REGS_UNALLOCATED)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4583 { /* No. So allocate them with malloc. We need one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4584 extra element beyond `num_regs' for the `-1' marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4585 GNU code uses. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4586 regs->num_regs = MAX (RE_NREGS, num_regs + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4587 regs->start = TALLOC (regs->num_regs, regoff_t);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4588 regs->end = TALLOC (regs->num_regs, regoff_t);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4589 if (regs->start == NULL || regs->end == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4590 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4591 FREE_VARIABLES ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4592 return -2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4593 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4594 bufp->regs_allocated = REGS_REALLOCATE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4595 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4596 else if (bufp->regs_allocated == REGS_REALLOCATE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4597 { /* Yes. If we need more elements than were already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4598 allocated, reallocate them. If we need fewer, just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4599 leave it alone. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4600 if (regs->num_regs < num_regs + 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4601 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4602 regs->num_regs = num_regs + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4603 RETALLOC (regs->start, regs->num_regs, regoff_t);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4604 RETALLOC (regs->end, regs->num_regs, regoff_t);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4605 if (regs->start == NULL || regs->end == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4606 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4607 FREE_VARIABLES ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4608 return -2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4609 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4610 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4611 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4612 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4613 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4614 /* These braces fend off a "empty body in an else-statement"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4615 warning under GCC when assert expands to nothing. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4616 assert (bufp->regs_allocated == REGS_FIXED);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4617 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4618
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4619 /* Convert the pointer data in `regstart' and `regend' to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4620 indices. Register zero has to be set differently,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4621 since we haven't kept track of any info for it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4622 if (regs->num_regs > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4623 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4624 regs->start[0] = pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4625 regs->end[0] = (MATCHING_IN_FIRST_STRING
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4626 ? ((regoff_t) (d - string1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4627 : ((regoff_t) (d - string2 + size1)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4628 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4629
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4630 /* Go through the first `min (num_regs, regs->num_regs)'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4631 registers, since that is all we initialized. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4632 for (mcnt = 1; mcnt < MIN (num_regs, regs->num_regs); mcnt++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4633 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4634 if (REG_UNSET (regstart[mcnt]) || REG_UNSET (regend[mcnt]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4635 regs->start[mcnt] = regs->end[mcnt] = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4636 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4637 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4638 regs->start[mcnt]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4639 = (regoff_t) POINTER_TO_OFFSET (regstart[mcnt]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4640 regs->end[mcnt]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4641 = (regoff_t) POINTER_TO_OFFSET (regend[mcnt]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4642 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4643 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4644
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4645 /* If the regs structure we return has more elements than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4646 were in the pattern, set the extra elements to -1. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4647 we (re)allocated the registers, this is the case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4648 because we always allocate enough to have at least one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4649 -1 at the end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4650 for (mcnt = num_regs; mcnt < regs->num_regs; mcnt++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4651 regs->start[mcnt] = regs->end[mcnt] = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4652 } /* regs && !bufp->no_sub */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4654 DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4655 nfailure_points_pushed, nfailure_points_popped,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4656 nfailure_points_pushed - nfailure_points_popped);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4657 DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4658
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4659 mcnt = d - pos - (MATCHING_IN_FIRST_STRING
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4660 ? string1
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4661 : string2 - size1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4662
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4663 DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4664
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4665 FREE_VARIABLES ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4666 return mcnt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4667 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4669 /* Otherwise match next pattern command. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4670 switch (SWITCH_ENUM_CAST ((re_opcode_t) *p++))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4671 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4672 /* Ignore these. Used to ignore the n of succeed_n's which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4673 currently have n == 0. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4674 case no_op:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4675 DEBUG_PRINT1 ("EXECUTING no_op.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4676 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4677
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4678 case succeed:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4679 DEBUG_PRINT1 ("EXECUTING succeed.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4680 goto succeed_label;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4682 /* Match the next n pattern characters exactly. The following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4683 byte in the pattern defines n, and the n bytes after that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4684 are the characters to match. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4685 case exactn:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4686 mcnt = *p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4687 DEBUG_PRINT2 ("EXECUTING exactn %d.\n", mcnt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4689 /* This is written out as an if-else so we don't waste time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4690 testing `translate' inside the loop. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4691 if (translate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4692 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4693 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4694 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4695 PREFETCH ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4696 if (translate[(unsigned char) *d++] != (char) *p++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4697 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4698 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4699 while (--mcnt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4700 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4701 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4702 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4703 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4704 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4705 PREFETCH ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4706 if (*d++ != (char) *p++) goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4707 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4708 while (--mcnt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4709 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4710 SET_REGS_MATCHED ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4711 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4712
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4713
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4714 /* Match any character except possibly a newline or a null. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4715 case anychar:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4716 DEBUG_PRINT1 ("EXECUTING anychar.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4718 PREFETCH ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4719
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4720 if ((!(bufp->syntax & RE_DOT_NEWLINE) && TRANSLATE (*d) == '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4721 || (bufp->syntax & RE_DOT_NOT_NULL && TRANSLATE (*d) == '\000'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4722 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4723
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4724 SET_REGS_MATCHED ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4725 DEBUG_PRINT2 (" Matched `%d'.\n", *d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4726 INC_CHARPTR (d); /* XEmacs change */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4727 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4729
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4730 case charset:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4731 case charset_not:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4732 {
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
4733 REGISTER unsigned char c;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4734 boolean not = (re_opcode_t) *(p - 1) == charset_not;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4736 DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : "");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4737
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4738 PREFETCH ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4739 c = TRANSLATE (*d); /* The character to match. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4741 /* Cast to `unsigned' instead of `unsigned char' in case the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4742 bit list is a full 32 bytes long. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4743 if (c < (unsigned) (*p * BYTEWIDTH)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4744 && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4745 not = !not;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4746
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4747 p += 1 + *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4748
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4749 if (!not) goto fail;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4750
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4751 SET_REGS_MATCHED ();
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4752 INC_CHARPTR (d); /* XEmacs change */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4753 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4754 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4755
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4756 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4757 case charset_mule:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4758 case charset_mule_not:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4759 {
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
4760 REGISTER Emchar c;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4761 boolean not = (re_opcode_t) *(p - 1) == charset_mule_not;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4762
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4763 DEBUG_PRINT2 ("EXECUTING charset_mule%s.\n", not ? "_not" : "");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4764
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4765 PREFETCH ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4766 c = charptr_emchar ((CONST Bufbyte *) d);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4767 c = TRANSLATE_EXTENDED_UNSAFE (c); /* The character to match. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4768
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4769 if (EQ (Qt, unified_range_table_lookup (p, c, Qnil)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4770 not = !not;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4771
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4772 p += unified_range_table_bytes_used (p);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4773
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4774 if (!not) goto fail;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4775
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4776 SET_REGS_MATCHED ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4777 INC_CHARPTR (d);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4778 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4779 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4780 #endif /* MULE */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
4781
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4783 /* The beginning of a group is represented by start_memory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4784 The arguments are the register number in the next byte, and the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4785 number of groups inner to this one in the next. The text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4786 matched within the group is recorded (in the internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4787 registers data structure) under the register number. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4788 case start_memory:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4789 DEBUG_PRINT3 ("EXECUTING start_memory %d (%d):\n", *p, p[1]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4791 /* Find out if this group can match the empty string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4792 p1 = p; /* To send to group_match_null_string_p. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4793
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4794 if (REG_MATCH_NULL_STRING_P (reg_info[*p]) == MATCH_NULL_UNSET_VALUE)
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4795 REG_MATCH_NULL_STRING_P (reg_info[*p])
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4796 = group_match_null_string_p (&p1, pend, reg_info);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4798 /* Save the position in the string where we were the last time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4799 we were at this open-group operator in case the group is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4800 operated upon by a repetition operator, e.g., with `(a*)*b'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4801 against `ab'; then we want to ignore where we are now in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4802 the string in case this attempt to match fails. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4803 old_regstart[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4804 ? REG_UNSET (regstart[*p]) ? d : regstart[*p]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4805 : regstart[*p];
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4806 DEBUG_PRINT2 (" old_regstart: %d\n",
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4807 POINTER_TO_OFFSET (old_regstart[*p]));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4808
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4809 regstart[*p] = d;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4810 DEBUG_PRINT2 (" regstart: %d\n", POINTER_TO_OFFSET (regstart[*p]));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4812 IS_ACTIVE (reg_info[*p]) = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4813 MATCHED_SOMETHING (reg_info[*p]) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4814
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4815 /* Clear this whenever we change the register activity status. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4816 set_regs_matched_done = 0;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4817
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4818 /* This is the new highest active register. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4819 highest_active_reg = *p;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4820
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4821 /* If nothing was active before, this is the new lowest active
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4822 register. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4823 if (lowest_active_reg == NO_LOWEST_ACTIVE_REG)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4824 lowest_active_reg = *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4825
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4826 /* Move past the register number and inner group count. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4827 p += 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4828 just_past_start_mem = p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4829
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4830 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4831
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4832
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4833 /* The stop_memory opcode represents the end of a group. Its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4834 arguments are the same as start_memory's: the register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4835 number, and the number of inner groups. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4836 case stop_memory:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4837 DEBUG_PRINT3 ("EXECUTING stop_memory %d (%d):\n", *p, p[1]);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4838
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4839 /* We need to save the string position the last time we were at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4840 this close-group operator in case the group is operated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4841 upon by a repetition operator, e.g., with `((a*)*(b*)*)*'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4842 against `aba'; then we want to ignore where we are now in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4843 the string in case this attempt to match fails. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4844 old_regend[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4845 ? REG_UNSET (regend[*p]) ? d : regend[*p]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4846 : regend[*p];
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4847 DEBUG_PRINT2 (" old_regend: %d\n",
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4848 POINTER_TO_OFFSET (old_regend[*p]));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4849
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4850 regend[*p] = d;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4851 DEBUG_PRINT2 (" regend: %d\n", POINTER_TO_OFFSET (regend[*p]));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4852
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4853 /* This register isn't active anymore. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4854 IS_ACTIVE (reg_info[*p]) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4855
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4856 /* Clear this whenever we change the register activity status. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4857 set_regs_matched_done = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4858
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4859 /* If this was the only register active, nothing is active
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4860 anymore. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4861 if (lowest_active_reg == highest_active_reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4862 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4863 lowest_active_reg = NO_LOWEST_ACTIVE_REG;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4864 highest_active_reg = NO_HIGHEST_ACTIVE_REG;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4865 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4866 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4867 { /* We must scan for the new highest active register, since
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4868 it isn't necessarily one less than now: consider
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4869 (a(b)c(d(e)f)g). When group 3 ends, after the f), the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4870 new highest active register is 1. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4871 unsigned char r = *p - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4872 while (r > 0 && !IS_ACTIVE (reg_info[r]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4873 r--;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4874
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4875 /* If we end up at register zero, that means that we saved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4876 the registers as the result of an `on_failure_jump', not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4877 a `start_memory', and we jumped to past the innermost
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4878 `stop_memory'. For example, in ((.)*) we save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4879 registers 1 and 2 as a result of the *, but when we pop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4880 back to the second ), we are at the stop_memory 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4881 Thus, nothing is active. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4882 if (r == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4883 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4884 lowest_active_reg = NO_LOWEST_ACTIVE_REG;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4885 highest_active_reg = NO_HIGHEST_ACTIVE_REG;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4886 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4887 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4888 highest_active_reg = r;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4889 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4890
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4891 /* If just failed to match something this time around with a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4892 group that's operated on by a repetition operator, try to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4893 force exit from the ``loop'', and restore the register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4894 information for this group that we had before trying this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4895 last match. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4896 if ((!MATCHED_SOMETHING (reg_info[*p])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4897 || just_past_start_mem == p - 1)
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4898 && (p + 2) < pend)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4899 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4900 boolean is_a_jump_n = false;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4901
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4902 p1 = p + 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4903 mcnt = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4904 switch ((re_opcode_t) *p1++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4905 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4906 case jump_n:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4907 is_a_jump_n = true;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4908 case pop_failure_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4909 case maybe_pop_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4910 case jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4911 case dummy_failure_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4912 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4913 if (is_a_jump_n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4914 p1 += 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4915 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4916
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4917 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4918 /* do nothing */ ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4919 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4920 p1 += mcnt;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4921
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4922 /* If the next operation is a jump backwards in the pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4923 to an on_failure_jump right before the start_memory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4924 corresponding to this stop_memory, exit from the loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4925 by forcing a failure after pushing on the stack the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4926 on_failure_jump's jump in the pattern, and d. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4927 if (mcnt < 0 && (re_opcode_t) *p1 == on_failure_jump
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4928 && (re_opcode_t) p1[3] == start_memory && p1[4] == *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4929 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4930 /* If this group ever matched anything, then restore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4931 what its registers were before trying this last
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4932 failed match, e.g., with `(a*)*b' against `ab' for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4933 regstart[1], and, e.g., with `((a*)*(b*)*)*'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4934 against `aba' for regend[3].
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4935
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4936 Also restore the registers for inner groups for,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4937 e.g., `((a*)(b*))*' against `aba' (register 3 would
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4938 otherwise get trashed). */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4939
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4940 if (EVER_MATCHED_SOMETHING (reg_info[*p]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4941 {
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4942 unsigned r;
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4943
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4944 EVER_MATCHED_SOMETHING (reg_info[*p]) = 0;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4945
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4946 /* Restore this and inner groups' (if any) registers. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4947 for (r = *p; r < *p + *(p + 1); r++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4948 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4949 regstart[r] = old_regstart[r];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4950
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4951 /* xx why this test? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4952 if (old_regend[r] >= regstart[r])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4953 regend[r] = old_regend[r];
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4954 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4955 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4956 p1++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4957 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4958 PUSH_FAILURE_POINT (p1 + mcnt, d, -2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4959
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4960 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4961 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4962 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4963
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4964 /* Move past the register number and the inner group count. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4965 p += 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4966 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4967
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4968
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4969 /* \<digit> has been turned into a `duplicate' command which is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4970 followed by the numeric value of <digit> as the register number. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4971 case duplicate:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4972 {
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
4973 REGISTER CONST char *d2, *dend2;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4974 int regno = *p++; /* Get which register to match against. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4975 DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4976
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4977 /* Can't back reference a group which we've never matched. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4978 if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4979 goto fail;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4980
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4981 /* Where in input to try to start matching. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4982 d2 = regstart[regno];
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4983
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4984 /* Where to stop matching; if both the place to start and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4985 the place to stop matching are in the same string, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4986 set to the place to stop, otherwise, for now have to use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4987 the end of the first string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4988
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
4989 dend2 = ((FIRST_STRING_P (regstart[regno])
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4990 == FIRST_STRING_P (regend[regno]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4991 ? regend[regno] : end_match_1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4992 for (;;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4993 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4994 /* If necessary, advance to next segment in register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4995 contents. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4996 while (d2 == dend2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4997 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4998 if (dend2 == end_match_2) break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4999 if (dend2 == regend[regno]) break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5001 /* End of string1 => advance to string2. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5002 d2 = string2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5003 dend2 = regend[regno];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5004 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5005 /* At end of register contents => success */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5006 if (d2 == dend2) break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5007
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5008 /* If necessary, advance to next segment in data. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5009 PREFETCH ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5011 /* How many characters left in this segment to match. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5012 mcnt = dend - d;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5013
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5014 /* Want how many consecutive characters we can match in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5015 one shot, so, if necessary, adjust the count. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5016 if (mcnt > dend2 - d2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5017 mcnt = dend2 - d2;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5018
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5019 /* Compare that many; failure if mismatch, else move
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5020 past them. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5021 if (translate
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5022 ? bcmp_translate ((unsigned char *) d,
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5023 (unsigned char *) d2, mcnt, translate)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5024 : memcmp (d, d2, mcnt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5025 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5026 d += mcnt, d2 += mcnt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5027
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5028 /* Do this because we've match some characters. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5029 SET_REGS_MATCHED ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5030 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5031 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5032 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5033
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5034
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5035 /* begline matches the empty string at the beginning of the string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5036 (unless `not_bol' is set in `bufp'), and, if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5037 `newline_anchor' is set, after newlines. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5038 case begline:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5039 DEBUG_PRINT1 ("EXECUTING begline.\n");
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5040
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5041 if (AT_STRINGS_BEG (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5042 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5043 if (!bufp->not_bol) break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5044 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5045 else if (d[-1] == '\n' && bufp->newline_anchor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5046 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5047 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5048 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5049 /* In all other cases, we fail. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5050 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5051
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5052
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5053 /* endline is the dual of begline. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5054 case endline:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5055 DEBUG_PRINT1 ("EXECUTING endline.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5056
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5057 if (AT_STRINGS_END (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5058 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5059 if (!bufp->not_eol) break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5060 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5061
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5062 /* We have to ``prefetch'' the next character. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5063 else if ((d == end1 ? *string2 : *d) == '\n'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5064 && bufp->newline_anchor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5065 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5066 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5067 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5068 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5069
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5070
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5071 /* Match at the very beginning of the data. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5072 case begbuf:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5073 DEBUG_PRINT1 ("EXECUTING begbuf.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5074 if (AT_STRINGS_BEG (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5075 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5076 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5077
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5078
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5079 /* Match at the very end of the data. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5080 case endbuf:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5081 DEBUG_PRINT1 ("EXECUTING endbuf.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5082 if (AT_STRINGS_END (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5083 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5084 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5085
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5086
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5087 /* on_failure_keep_string_jump is used to optimize `.*\n'. It
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5088 pushes NULL as the value for the string on the stack. Then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5089 `pop_failure_point' will keep the current value for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5090 string, instead of restoring it. To see why, consider
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5091 matching `foo\nbar' against `.*\n'. The .* matches the foo;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5092 then the . fails against the \n. But the next thing we want
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5093 to do is match the \n against the \n; if we restored the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5094 string value, we would be back at the foo.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5095
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5096 Because this is used only in specific cases, we don't need to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5097 check all the things that `on_failure_jump' does, to make
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5098 sure the right things get saved on the stack. Hence we don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5099 share its code. The only reason to push anything on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5100 stack at all is that otherwise we would have to change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5101 `anychar's code to do something besides goto fail in this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5102 case; that seems worse than this. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5103 case on_failure_keep_string_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5104 DEBUG_PRINT1 ("EXECUTING on_failure_keep_string_jump");
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5105
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5106 EXTRACT_NUMBER_AND_INCR (mcnt, p);
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 169
diff changeset
5107 DEBUG_PRINT3 (" %d (to 0x%p):\n", mcnt, p + mcnt);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5108
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
5109 PUSH_FAILURE_POINT (p + mcnt, (char *) 0, -2);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5110 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5113 /* Uses of on_failure_jump:
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5114
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5115 Each alternative starts with an on_failure_jump that points
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5116 to the beginning of the next alternative. Each alternative
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5117 except the last ends with a jump that in effect jumps past
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5118 the rest of the alternatives. (They really jump to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5119 ending jump of the following alternative, because tensioning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5120 these jumps is a hassle.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5122 Repeats start with an on_failure_jump that points past both
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5123 the repetition text and either the following jump or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5124 pop_failure_jump back to this on_failure_jump. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5125 case on_failure_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5126 on_failure:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5127 DEBUG_PRINT1 ("EXECUTING on_failure_jump");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5129 EXTRACT_NUMBER_AND_INCR (mcnt, p);
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 169
diff changeset
5130 DEBUG_PRINT3 (" %d (to 0x%p)", mcnt, p + mcnt);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5132 /* If this on_failure_jump comes right before a group (i.e.,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5133 the original * applied to a group), save the information
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5134 for that group and all inner ones, so that if we fail back
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5135 to this point, the group's information will be correct.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5136 For example, in \(a*\)*\1, we need the preceding group,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5137 and in \(\(a*\)b*\)\2, we need the inner group. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5139 /* We can't use `p' to check ahead because we push
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5140 a failure point to `p + mcnt' after we do this. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5141 p1 = p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5143 /* We need to skip no_op's before we look for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5144 start_memory in case this on_failure_jump is happening as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5145 the result of a completed succeed_n, as in \(a\)\{1,3\}b\1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5146 against aba. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5147 while (p1 < pend && (re_opcode_t) *p1 == no_op)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5148 p1++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5150 if (p1 < pend && (re_opcode_t) *p1 == start_memory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5151 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5152 /* We have a new highest active register now. This will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5153 get reset at the start_memory we are about to get to,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5154 but we will have saved all the registers relevant to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5155 this repetition op, as described above. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5156 highest_active_reg = *(p1 + 1) + *(p1 + 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5157 if (lowest_active_reg == NO_LOWEST_ACTIVE_REG)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5158 lowest_active_reg = *(p1 + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5159 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5161 DEBUG_PRINT1 (":\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5162 PUSH_FAILURE_POINT (p + mcnt, d, -2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5163 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5166 /* A smart repeat ends with `maybe_pop_jump'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5167 We change it to either `pop_failure_jump' or `jump'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5168 case maybe_pop_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5169 EXTRACT_NUMBER_AND_INCR (mcnt, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5170 DEBUG_PRINT2 ("EXECUTING maybe_pop_jump %d.\n", mcnt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5171 {
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
5172 REGISTER unsigned char *p2 = p;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5174 /* Compare the beginning of the repeat with what in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5175 pattern follows its end. If we can establish that there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5176 is nothing that they would both match, i.e., that we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5177 would have to backtrack because of (as in, e.g., `a*a')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5178 then we can change to pop_failure_jump, because we'll
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5179 never have to backtrack.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5180
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5181 This is not true in the case of alternatives: in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5182 `(a|ab)*' we do need to backtrack to the `ab' alternative
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5183 (e.g., if the string was `ab'). But instead of trying to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5184 detect that here, the alternative has put on a dummy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5185 failure point which is what we will end up popping. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5187 /* Skip over open/close-group commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5188 If what follows this loop is a ...+ construct,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5189 look at what begins its body, since we will have to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5190 match at least one of that. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5191 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5192 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5193 if (p2 + 2 < pend
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5194 && ((re_opcode_t) *p2 == stop_memory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5195 || (re_opcode_t) *p2 == start_memory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5196 p2 += 3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5197 else if (p2 + 6 < pend
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5198 && (re_opcode_t) *p2 == dummy_failure_jump)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5199 p2 += 6;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5200 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5201 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5202 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5204 p1 = p + mcnt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5205 /* p1[0] ... p1[2] are the `on_failure_jump' corresponding
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5206 to the `maybe_finalize_jump' of this case. Examine what
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5207 follows. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5209 /* If we're at the end of the pattern, we can change. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5210 if (p2 == pend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5211 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5212 /* Consider what happens when matching ":\(.*\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5213 against ":/". I don't really understand this code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5214 yet. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5215 p[-3] = (unsigned char) pop_failure_jump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5216 DEBUG_PRINT1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5217 (" End of pattern: change to `pop_failure_jump'.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5218 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5220 else if ((re_opcode_t) *p2 == exactn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5221 || (bufp->newline_anchor && (re_opcode_t) *p2 == endline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5222 {
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
5223 REGISTER unsigned char c
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5224 = *p2 == (unsigned char) endline ? '\n' : p2[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5226 if ((re_opcode_t) p1[3] == exactn && p1[5] != c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5227 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5228 p[-3] = (unsigned char) pop_failure_jump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5229 DEBUG_PRINT3 (" %c != %c => pop_failure_jump.\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5230 c, p1[5]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5231 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5232
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5233 else if ((re_opcode_t) p1[3] == charset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5234 || (re_opcode_t) p1[3] == charset_not)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5235 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5236 int not = (re_opcode_t) p1[3] == charset_not;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5237
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5238 if (c < (unsigned char) (p1[4] * BYTEWIDTH)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5239 && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5240 not = !not;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5242 /* `not' is equal to 1 if c would match, which means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5243 that we can't change to pop_failure_jump. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5244 if (!not)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5245 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5246 p[-3] = (unsigned char) pop_failure_jump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5247 DEBUG_PRINT1 (" No match => pop_failure_jump.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5248 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5249 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5250 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5251 else if ((re_opcode_t) *p2 == charset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5252 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5253 #ifdef DEBUG
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
5254 REGISTER unsigned char c
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5255 = *p2 == (unsigned char) endline ? '\n' : p2[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5256 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5258 if ((re_opcode_t) p1[3] == exactn
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
5259 && ! ((int) p2[1] * BYTEWIDTH > (int) p1[5]
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
5260 && (p2[2 + p1[5] / BYTEWIDTH]
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
5261 & (1 << (p1[5] % BYTEWIDTH)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5262 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5263 p[-3] = (unsigned char) pop_failure_jump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5264 DEBUG_PRINT3 (" %c != %c => pop_failure_jump.\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5265 c, p1[5]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5266 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5267
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5268 else if ((re_opcode_t) p1[3] == charset_not)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5269 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5270 int idx;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5271 /* We win if the charset_not inside the loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5272 lists every character listed in the charset after. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5273 for (idx = 0; idx < (int) p2[1]; idx++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5274 if (! (p2[2 + idx] == 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5275 || (idx < (int) p1[4]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5276 && ((p2[2 + idx] & ~ p1[5 + idx]) == 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5277 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5279 if (idx == p2[1])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5280 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5281 p[-3] = (unsigned char) pop_failure_jump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5282 DEBUG_PRINT1 (" No match => pop_failure_jump.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5283 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5284 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5285 else if ((re_opcode_t) p1[3] == charset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5286 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5287 int idx;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5288 /* We win if the charset inside the loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5289 has no overlap with the one after the loop. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5290 for (idx = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5291 idx < (int) p2[1] && idx < (int) p1[4];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5292 idx++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5293 if ((p2[2 + idx] & p1[5 + idx]) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5294 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5296 if (idx == p2[1] || idx == p1[4])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5297 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5298 p[-3] = (unsigned char) pop_failure_jump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5299 DEBUG_PRINT1 (" No match => pop_failure_jump.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5300 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5301 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5302 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5303 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5304 p -= 2; /* Point at relative address again. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5305 if ((re_opcode_t) p[-1] != pop_failure_jump)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5306 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5307 p[-1] = (unsigned char) jump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5308 DEBUG_PRINT1 (" Match => jump.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5309 goto unconditional_jump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5310 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5311 /* Note fall through. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5314 /* The end of a simple repeat has a pop_failure_jump back to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5315 its matching on_failure_jump, where the latter will push a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5316 failure point. The pop_failure_jump takes off failure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5317 points put on by this pop_failure_jump's matching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5318 on_failure_jump; we got through the pattern to here from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5319 matching on_failure_jump, so didn't fail. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5320 case pop_failure_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5321 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5322 /* We need to pass separate storage for the lowest and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5323 highest registers, even though we don't care about the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5324 actual values. Otherwise, we will restore only one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5325 register from the stack, since lowest will == highest in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5326 `pop_failure_point'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5327 unsigned dummy_low_reg, dummy_high_reg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5328 unsigned char *pdummy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5329 CONST char *sdummy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5331 DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5332 POP_FAILURE_POINT (sdummy, pdummy,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5333 dummy_low_reg, dummy_high_reg,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5334 reg_dummy, reg_dummy, reg_info_dummy);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5335 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5336 /* Note fall through. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5337
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5338
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5339 /* Unconditionally jump (without popping any failure points). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5340 case jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5341 unconditional_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5342 EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5343 DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5344 p += mcnt; /* Do the jump. */
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 169
diff changeset
5345 DEBUG_PRINT2 ("(to 0x%p).\n", p);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5346 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5347
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5348
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5349 /* We need this opcode so we can detect where alternatives end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5350 in `group_match_null_string_p' et al. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5351 case jump_past_alt:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5352 DEBUG_PRINT1 ("EXECUTING jump_past_alt.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5353 goto unconditional_jump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5356 /* Normally, the on_failure_jump pushes a failure point, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5357 then gets popped at pop_failure_jump. We will end up at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5358 pop_failure_jump, also, and with a pattern of, say, `a+', we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5359 are skipping over the on_failure_jump, so we have to push
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5360 something meaningless for pop_failure_jump to pop. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5361 case dummy_failure_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5362 DEBUG_PRINT1 ("EXECUTING dummy_failure_jump.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5363 /* It doesn't matter what we push for the string here. What
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5364 the code at `fail' tests is the value for the pattern. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
5365 PUSH_FAILURE_POINT ((unsigned char *) 0, (char *) 0, -2);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5366 goto unconditional_jump;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5369 /* At the end of an alternative, we need to push a dummy failure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5370 point in case we are followed by a `pop_failure_jump', because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5371 we don't want the failure point for the alternative to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5372 popped. For example, matching `(a|ab)*' against `aab'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5373 requires that we match the `ab' alternative. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5374 case push_dummy_failure:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5375 DEBUG_PRINT1 ("EXECUTING push_dummy_failure.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5376 /* See comments just above at `dummy_failure_jump' about the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5377 two zeroes. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
5378 PUSH_FAILURE_POINT ((unsigned char *) 0, (char *) 0, -2);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5379 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5381 /* Have to succeed matching what follows at least n times.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5382 After that, handle like `on_failure_jump'. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5383 case succeed_n:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5384 EXTRACT_NUMBER (mcnt, p + 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5385 DEBUG_PRINT2 ("EXECUTING succeed_n %d.\n", mcnt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5387 assert (mcnt >= 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5388 /* Originally, this is how many times we HAVE to succeed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5389 if (mcnt > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5390 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5391 mcnt--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5392 p += 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5393 STORE_NUMBER_AND_INCR (p, mcnt);
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 169
diff changeset
5394 DEBUG_PRINT3 (" Setting 0x%p to %d.\n", p, mcnt);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5395 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5396 else if (mcnt == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5397 {
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 169
diff changeset
5398 DEBUG_PRINT2 (" Setting two bytes from 0x%p to no_op.\n", p+2);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5399 p[2] = (unsigned char) no_op;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5400 p[3] = (unsigned char) no_op;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5401 goto on_failure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5402 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5403 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5404
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5405 case jump_n:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5406 EXTRACT_NUMBER (mcnt, p + 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5407 DEBUG_PRINT2 ("EXECUTING jump_n %d.\n", mcnt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5409 /* Originally, this is how many times we CAN jump. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5410 if (mcnt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5411 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5412 mcnt--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5413 STORE_NUMBER (p + 2, mcnt);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5414 goto unconditional_jump;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5415 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5416 /* If don't have to jump any more, skip over the rest of command. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5417 else
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5418 p += 4;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5419 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5420
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5421 case set_number_at:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5422 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5423 DEBUG_PRINT1 ("EXECUTING set_number_at.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5425 EXTRACT_NUMBER_AND_INCR (mcnt, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5426 p1 = p + mcnt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5427 EXTRACT_NUMBER_AND_INCR (mcnt, p);
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 169
diff changeset
5428 DEBUG_PRINT3 (" Setting 0x%p to %d.\n", p1, mcnt);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5429 STORE_NUMBER (p1, mcnt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5430 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5431 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5433 case wordbound:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5434 DEBUG_PRINT1 ("EXECUTING wordbound.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5435 should_succeed = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5436 matchwordbound:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5437 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5438 /* XEmacs change */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5439 int result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5440 if (AT_STRINGS_BEG (d) || AT_STRINGS_END (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5441 result = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5442 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5443 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5444 CONST unsigned char *d_before =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5445 (CONST unsigned char *) POS_BEFORE_GAP_UNSAFE (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5446 CONST unsigned char *d_after =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5447 (CONST unsigned char *) POS_AFTER_GAP_UNSAFE (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5448 Emchar emch1, emch2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5450 DEC_CHARPTR (d_before);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5451 emch1 = charptr_emchar (d_before);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5452 emch2 = charptr_emchar (d_after);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5453 result = (WORDCHAR_P_UNSAFE (emch1) !=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5454 WORDCHAR_P_UNSAFE (emch2));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5455 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5456 if (result == should_succeed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5457 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5458 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5459 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5461 case notwordbound:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5462 DEBUG_PRINT1 ("EXECUTING notwordbound.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5463 should_succeed = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5464 goto matchwordbound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5466 case wordbeg:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5467 DEBUG_PRINT1 ("EXECUTING wordbeg.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5468 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5469 /* XEmacs: this originally read:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5470
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5471 if (WORDCHAR_P (d) && (AT_STRINGS_BEG (d) || !WORDCHAR_P (d - 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5472 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5473
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5474 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5475 CONST unsigned char *dtmp =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5476 (CONST unsigned char *) POS_AFTER_GAP_UNSAFE (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5477 Emchar emch = charptr_emchar (dtmp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5478 if (!WORDCHAR_P_UNSAFE (emch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5479 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5480 if (AT_STRINGS_BEG (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5481 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5482 dtmp = (CONST unsigned char *) POS_BEFORE_GAP_UNSAFE (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5483 DEC_CHARPTR (dtmp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5484 emch = charptr_emchar (dtmp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5485 if (!WORDCHAR_P_UNSAFE (emch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5486 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5487 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5488 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5490 case wordend:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5491 DEBUG_PRINT1 ("EXECUTING wordend.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5492 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5493 /* XEmacs: this originally read:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5495 if (!AT_STRINGS_BEG (d) && WORDCHAR_P (d - 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5496 && (!WORDCHAR_P (d) || AT_STRINGS_END (d)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5497 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5499 The or condition is incorrect (reversed).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5500 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5501 CONST unsigned char *dtmp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5502 Emchar emch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5503 if (AT_STRINGS_BEG (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5504 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5505 dtmp = (CONST unsigned char *) POS_BEFORE_GAP_UNSAFE (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5506 DEC_CHARPTR (dtmp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5507 emch = charptr_emchar (dtmp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5508 if (!WORDCHAR_P_UNSAFE (emch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5509 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5510 if (AT_STRINGS_END (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5511 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5512 dtmp = (CONST unsigned char *) POS_AFTER_GAP_UNSAFE (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5513 emch = charptr_emchar (dtmp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5514 if (!WORDCHAR_P_UNSAFE (emch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5515 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5516 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5517 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5519 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5520 case before_dot:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5521 DEBUG_PRINT1 ("EXECUTING before_dot.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5522 if (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d) >=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5523 BUF_PT (regex_emacs_buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5524 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5525 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5526
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5527 case at_dot:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5528 DEBUG_PRINT1 ("EXECUTING at_dot.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5529 if (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5530 != BUF_PT (regex_emacs_buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5531 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5532 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5533
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5534 case after_dot:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5535 DEBUG_PRINT1 ("EXECUTING after_dot.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5536 if (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5537 <= BUF_PT (regex_emacs_buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5538 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5539 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5540 #if 0 /* not emacs19 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5541 case at_dot:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5542 DEBUG_PRINT1 ("EXECUTING at_dot.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5543 if (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d) + 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5544 != BUF_PT (regex_emacs_buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5545 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5546 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5547 #endif /* not emacs19 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5549 case syntaxspec:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5550 DEBUG_PRINT2 ("EXECUTING syntaxspec %d.\n", mcnt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5551 mcnt = *p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5552 goto matchsyntax;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5554 case wordchar:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5555 DEBUG_PRINT1 ("EXECUTING Emacs wordchar.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5556 mcnt = (int) Sword;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5557 matchsyntax:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5558 should_succeed = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5559 matchornotsyntax:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5560 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5561 int matches;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5562 Emchar emch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5564 PREFETCH ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5565 emch = charptr_emchar ((CONST Bufbyte *) d);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
5566 matches = (SYNTAX_UNSAFE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
5567 (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
5568 emch) == (enum syntaxcode) mcnt);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5569 INC_CHARPTR (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5570 if (matches != should_succeed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5571 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5572 SET_REGS_MATCHED ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5573 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5574 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5575
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5576 case notsyntaxspec:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5577 DEBUG_PRINT2 ("EXECUTING notsyntaxspec %d.\n", mcnt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5578 mcnt = *p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5579 goto matchnotsyntax;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5580
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5581 case notwordchar:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5582 DEBUG_PRINT1 ("EXECUTING Emacs notwordchar.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5583 mcnt = (int) Sword;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5584 matchnotsyntax:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5585 should_succeed = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5586 goto matchornotsyntax;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5587
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5588 #ifdef MULE
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5589 /* 97/2/17 jhod Mule category code patch */
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5590 case categoryspec:
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5591 should_succeed = 1;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5592 matchornotcategory:
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5593 {
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5594 Emchar emch;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5595
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5596 mcnt = *p++;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5597 PREFETCH ();
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5598 emch = charptr_emchar ((CONST Bufbyte *) d);
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5599 INC_CHARPTR (d);
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 104
diff changeset
5600 if (check_category_char(emch, regex_emacs_buffer->category_table,
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 104
diff changeset
5601 mcnt, should_succeed))
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5602 goto fail;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5603 SET_REGS_MATCHED ();
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5604 }
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5605 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5606
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5607 case notcategoryspec:
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5608 should_succeed = 0;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5609 goto matchornotcategory;
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5610 /* end of category patch */
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
5611 #endif /* MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5612 #else /* not emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5613 case wordchar:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5614 DEBUG_PRINT1 ("EXECUTING non-Emacs wordchar.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5615 PREFETCH ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5616 if (!WORDCHAR_P_UNSAFE ((int) (*d)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5617 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5618 SET_REGS_MATCHED ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5619 d++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5620 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5621
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5622 case notwordchar:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5623 DEBUG_PRINT1 ("EXECUTING non-Emacs notwordchar.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5624 PREFETCH ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5625 if (!WORDCHAR_P_UNSAFE ((int) (*d)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5626 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5627 SET_REGS_MATCHED ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5628 d++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5629 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5630 #endif /* not emacs */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5631
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5632 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5633 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5634 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5635 continue; /* Successfully executed one pattern command; keep going. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5638 /* We goto here if a matching operation fails. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5639 fail:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5640 if (!FAIL_STACK_EMPTY ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5641 { /* A restart point is known. Restore to that state. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5642 DEBUG_PRINT1 ("\nFAIL:\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5643 POP_FAILURE_POINT (d, p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5644 lowest_active_reg, highest_active_reg,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5645 regstart, regend, reg_info);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5647 /* If this failure point is a dummy, try the next one. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5648 if (!p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5649 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5650
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5651 /* If we failed to the end of the pattern, don't examine *p. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5652 assert (p <= pend);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5653 if (p < pend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5654 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5655 boolean is_a_jump_n = false;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5656
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5657 /* If failed to a backwards jump that's part of a repetition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5658 loop, need to pop this failure point and use the next one. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5659 switch ((re_opcode_t) *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5660 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5661 case jump_n:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5662 is_a_jump_n = true;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5663 case maybe_pop_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5664 case pop_failure_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5665 case jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5666 p1 = p + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5667 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5668 p1 += mcnt;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5669
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5670 if ((is_a_jump_n && (re_opcode_t) *p1 == succeed_n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5671 || (!is_a_jump_n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5672 && (re_opcode_t) *p1 == on_failure_jump))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5673 goto fail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5674 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5675 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5676 /* do nothing */ ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5677 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5678 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5679
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5680 if (d >= string1 && d <= end1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5681 dend = end_match_1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5682 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5683 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5684 break; /* Matching at this starting point really fails. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5685 } /* for (;;) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5686
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5687 if (best_regs_set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5688 goto restore_best_regs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5690 FREE_VARIABLES ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5692 return -1; /* Failure to match. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5693 } /* re_match_2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5694
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5695 /* Subroutine definitions for re_match_2. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5698 /* We are passed P pointing to a register number after a start_memory.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5699
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5700 Return true if the pattern up to the corresponding stop_memory can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5701 match the empty string, and false otherwise.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5702
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5703 If we find the matching stop_memory, sets P to point to one past its number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5704 Otherwise, sets P to an undefined byte less than or equal to END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5705
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5706 We don't handle duplicates properly (yet). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5708 static boolean
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5709 group_match_null_string_p (unsigned char **p, unsigned char *end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5710 register_info_type *reg_info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5711 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5712 int mcnt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5713 /* Point to after the args to the start_memory. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5714 unsigned char *p1 = *p + 2;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5715
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5716 while (p1 < end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5717 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5718 /* Skip over opcodes that can match nothing, and return true or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5719 false, as appropriate, when we get to one that can't, or to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5720 matching stop_memory. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5721
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5722 switch ((re_opcode_t) *p1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5723 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5724 /* Could be either a loop or a series of alternatives. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5725 case on_failure_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5726 p1++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5727 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5728
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5729 /* If the next operation is not a jump backwards in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5730 pattern. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5731
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5732 if (mcnt >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5733 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5734 /* Go through the on_failure_jumps of the alternatives,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5735 seeing if any of the alternatives cannot match nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5736 The last alternative starts with only a jump,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5737 whereas the rest start with on_failure_jump and end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5738 with a jump, e.g., here is the pattern for `a|b|c':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5739
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5740 /on_failure_jump/0/6/exactn/1/a/jump_past_alt/0/6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5741 /on_failure_jump/0/6/exactn/1/b/jump_past_alt/0/3
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5742 /exactn/1/c
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5744 So, we have to first go through the first (n-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5745 alternatives and then deal with the last one separately. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5746
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5747
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5748 /* Deal with the first (n-1) alternatives, which start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5749 with an on_failure_jump (see above) that jumps to right
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5750 past a jump_past_alt. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5751
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5752 while ((re_opcode_t) p1[mcnt-3] == jump_past_alt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5753 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5754 /* `mcnt' holds how many bytes long the alternative
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5755 is, including the ending `jump_past_alt' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5756 its number. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5757
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5758 if (!alt_match_null_string_p (p1, p1 + mcnt - 3,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5759 reg_info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5760 return false;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5761
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5762 /* Move to right after this alternative, including the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5763 jump_past_alt. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5764 p1 += mcnt;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5765
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5766 /* Break if it's the beginning of an n-th alternative
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5767 that doesn't begin with an on_failure_jump. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5768 if ((re_opcode_t) *p1 != on_failure_jump)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5769 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5770
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5771 /* Still have to check that it's not an n-th
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5772 alternative that starts with an on_failure_jump. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5773 p1++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5774 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5775 if ((re_opcode_t) p1[mcnt-3] != jump_past_alt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5776 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5777 /* Get to the beginning of the n-th alternative. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5778 p1 -= 3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5779 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5780 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5781 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5783 /* Deal with the last alternative: go back and get number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5784 of the `jump_past_alt' just before it. `mcnt' contains
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5785 the length of the alternative. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5786 EXTRACT_NUMBER (mcnt, p1 - 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5788 if (!alt_match_null_string_p (p1, p1 + mcnt, reg_info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5789 return false;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5791 p1 += mcnt; /* Get past the n-th alternative. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5792 } /* if mcnt > 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5793 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5794
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5795
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5796 case stop_memory:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5797 assert (p1[1] == **p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5798 *p = p1 + 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5799 return true;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5800
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5801
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5802 default:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5803 if (!common_op_match_null_string_p (&p1, end, reg_info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5804 return false;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5805 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5806 } /* while p1 < end */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5808 return false;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5809 } /* group_match_null_string_p */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5810
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5812 /* Similar to group_match_null_string_p, but doesn't deal with alternatives:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5813 It expects P to be the first byte of a single alternative and END one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5814 byte past the last. The alternative can contain groups. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5815
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5816 static boolean
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5817 alt_match_null_string_p (unsigned char *p, unsigned char *end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5818 register_info_type *reg_info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5819 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5820 int mcnt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5821 unsigned char *p1 = p;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5822
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5823 while (p1 < end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5824 {
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5825 /* Skip over opcodes that can match nothing, and break when we get
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5826 to one that can't. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5827
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5828 switch ((re_opcode_t) *p1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5829 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5830 /* It's a loop. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5831 case on_failure_jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5832 p1++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5833 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5834 p1 += mcnt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5835 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5836
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5837 default:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5838 if (!common_op_match_null_string_p (&p1, end, reg_info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5839 return false;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5840 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5841 } /* while p1 < end */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5842
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5843 return true;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5844 } /* alt_match_null_string_p */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5845
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5846
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5847 /* Deals with the ops common to group_match_null_string_p and
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5848 alt_match_null_string_p.
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5849
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5850 Sets P to one after the op and its arguments, if any. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5851
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5852 static boolean
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5853 common_op_match_null_string_p (unsigned char **p, unsigned char *end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5854 register_info_type *reg_info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5855 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5856 int mcnt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5857 boolean ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5858 int reg_no;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5859 unsigned char *p1 = *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5861 switch ((re_opcode_t) *p1++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5862 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5863 case no_op:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5864 case begline:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5865 case endline:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5866 case begbuf:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5867 case endbuf:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5868 case wordbeg:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5869 case wordend:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5870 case wordbound:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5871 case notwordbound:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5872 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5873 case before_dot:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5874 case at_dot:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5875 case after_dot:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5876 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5877 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5878
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5879 case start_memory:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5880 reg_no = *p1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5881 assert (reg_no > 0 && reg_no <= MAX_REGNUM);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5882 ret = group_match_null_string_p (&p1, end, reg_info);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5883
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5884 /* Have to set this here in case we're checking a group which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5885 contains a group and a back reference to it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5886
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5887 if (REG_MATCH_NULL_STRING_P (reg_info[reg_no]) == MATCH_NULL_UNSET_VALUE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5888 REG_MATCH_NULL_STRING_P (reg_info[reg_no]) = ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5889
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5890 if (!ret)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5891 return false;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5892 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5893
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5894 /* If this is an optimized succeed_n for zero times, make the jump. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5895 case jump:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5896 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5897 if (mcnt >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5898 p1 += mcnt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5899 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5900 return false;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5901 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5902
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5903 case succeed_n:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5904 /* Get to the number of times to succeed. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5905 p1 += 2;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5906 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5907
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5908 if (mcnt == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5909 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5910 p1 -= 4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5911 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5912 p1 += mcnt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5913 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5914 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5915 return false;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5916 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5917
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5918 case duplicate:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5919 if (!REG_MATCH_NULL_STRING_P (reg_info[*p1]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5920 return false;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5921 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5922
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5923 case set_number_at:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5924 p1 += 4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5925
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5926 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5927 /* All other opcodes mean we cannot match the empty string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5928 return false;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5929 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5930
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5931 *p = p1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5932 return true;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5933 } /* common_op_match_null_string_p */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5934
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5935
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5936 /* Return zero if TRANSLATE[S1] and TRANSLATE[S2] are identical for LEN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5937 bytes; nonzero otherwise. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5938
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5939 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5940 bcmp_translate (CONST unsigned char *s1, CONST unsigned char *s2,
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
5941 REGISTER int len, char *translate)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5942 {
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 185
diff changeset
5943 REGISTER CONST unsigned char *p1 = s1, *p2 = s2;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5944 while (len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5945 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5946 if (translate[*p1++] != translate[*p2++]) return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5947 len--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5948 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5949 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5950 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5951
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5952 /* Entry points for GNU code. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5953
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5954 /* re_compile_pattern is the GNU regular expression compiler: it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5955 compiles PATTERN (of length SIZE) and puts the result in BUFP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5956 Returns 0 if the pattern was valid, otherwise an error string.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5957
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5958 Assumes the `allocated' (and perhaps `buffer') and `translate' fields
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5959 are set in BUFP on entry.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5960
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5961 We call regex_compile to do the actual compilation. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5962
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5963 CONST char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5964 re_compile_pattern (CONST char *pattern, int length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5965 struct re_pattern_buffer *bufp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5966 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5967 reg_errcode_t ret;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5968
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5969 /* GNU code is written to assume at least RE_NREGS registers will be set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5970 (and at least one extra will be -1). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5971 bufp->regs_allocated = REGS_UNALLOCATED;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5972
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5973 /* And GNU code determines whether or not to get register information
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5974 by passing null for the REGS argument to re_match, etc., not by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5975 setting no_sub. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5976 bufp->no_sub = 0;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5977
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5978 /* Match anchors at newline. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5979 bufp->newline_anchor = 1;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5980
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5981 ret = regex_compile (pattern, length, re_syntax_options, bufp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5982
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5983 if (!ret)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5984 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5985 return gettext (re_error_msgid[(int) ret]);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
5986 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5987
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5988 /* Entry points compatible with 4.2 BSD regex library. We don't define
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5989 them unless specifically requested. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5990
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5991 #ifdef _REGEX_RE_COMP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5993 /* BSD has one and only one pattern buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5994 static struct re_pattern_buffer re_comp_buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5996 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5997 re_comp (CONST char *s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5998 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5999 reg_errcode_t ret;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6000
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6001 if (!s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6002 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6003 if (!re_comp_buf.buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6004 return gettext ("No previous regular expression");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6005 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6006 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6007
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6008 if (!re_comp_buf.buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6009 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6010 re_comp_buf.buffer = (unsigned char *) malloc (200);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6011 if (re_comp_buf.buffer == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6012 return gettext (re_error_msgid[(int) REG_ESPACE]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6013 re_comp_buf.allocated = 200;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6014
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6015 re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6016 if (re_comp_buf.fastmap == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6017 return gettext (re_error_msgid[(int) REG_ESPACE]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6018 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6019
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6020 /* Since `re_exec' always passes NULL for the `regs' argument, we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6021 don't need to initialize the pattern buffer fields which affect it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6022
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6023 /* Match anchors at newlines. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6024 re_comp_buf.newline_anchor = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6025
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6026 ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6027
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6028 if (!ret)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6029 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6030
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6031 /* Yes, we're discarding `CONST' here if !HAVE_LIBINTL. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6032 return (char *) gettext (re_error_msgid[(int) ret]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6033 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6034
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6035
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6036 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6037 re_exec (CONST char *s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6038 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6039 CONST int len = strlen (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6040 return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6041 0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6042 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6043 #endif /* _REGEX_RE_COMP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6044
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6045 /* POSIX.2 functions. Don't define these for Emacs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6046
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6047 #ifndef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6048
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6049 /* regcomp takes a regular expression as a string and compiles it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6050
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6051 PREG is a regex_t *. We do not expect any fields to be initialized,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6052 since POSIX says we shouldn't. Thus, we set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6053
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6054 `buffer' to the compiled pattern;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6055 `used' to the length of the compiled pattern;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6056 `syntax' to RE_SYNTAX_POSIX_EXTENDED if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6057 REG_EXTENDED bit in CFLAGS is set; otherwise, to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6058 RE_SYNTAX_POSIX_BASIC;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6059 `newline_anchor' to REG_NEWLINE being set in CFLAGS;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6060 `fastmap' and `fastmap_accurate' to zero;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6061 `re_nsub' to the number of subexpressions in PATTERN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6062
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6063 PATTERN is the address of the pattern string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6064
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6065 CFLAGS is a series of bits which affect compilation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6066
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6067 If REG_EXTENDED is set, we use POSIX extended syntax; otherwise, we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6068 use POSIX basic syntax.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6069
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6070 If REG_NEWLINE is set, then . and [^...] don't match newline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6071 Also, regexec will try a match beginning after every newline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6072
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6073 If REG_ICASE is set, then we considers upper- and lowercase
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6074 versions of letters to be equivalent when matching.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6075
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6076 If REG_NOSUB is set, then when PREG is passed to regexec, that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6077 routine will report only success or failure, and nothing about the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6078 registers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6079
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6080 It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6081 the return codes and their meanings.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6082
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6083 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6084 regcomp (regex_t *preg, CONST char *pattern, int cflags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6085 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6086 reg_errcode_t ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6087 unsigned syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6088 = (cflags & REG_EXTENDED) ?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6089 RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6090
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6091 /* regex_compile will allocate the space for the compiled pattern. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6092 preg->buffer = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6093 preg->allocated = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6094 preg->used = 0;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6095
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6096 /* Don't bother to use a fastmap when searching. This simplifies the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6097 REG_NEWLINE case: if we used a fastmap, we'd have to put all the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6098 characters after newlines into the fastmap. This way, we just try
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6099 every character. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6100 preg->fastmap = 0;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6101
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6102 if (cflags & REG_ICASE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6103 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6104 unsigned i;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6105
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6106 preg->translate = (char *) malloc (CHAR_SET_SIZE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6107 if (preg->translate == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6108 return (int) REG_ESPACE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6110 /* Map uppercase characters to corresponding lowercase ones. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6111 for (i = 0; i < CHAR_SET_SIZE; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6112 preg->translate[i] = ISUPPER (i) ? tolower (i) : i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6113 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6114 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6115 preg->translate = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6117 /* If REG_NEWLINE is set, newlines are treated differently. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6118 if (cflags & REG_NEWLINE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6119 { /* REG_NEWLINE implies neither . nor [^...] match newline. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6120 syntax &= ~RE_DOT_NEWLINE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6121 syntax |= RE_HAT_LISTS_NOT_NEWLINE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6122 /* It also changes the matching behavior. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6123 preg->newline_anchor = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6124 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6125 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6126 preg->newline_anchor = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6128 preg->no_sub = !!(cflags & REG_NOSUB);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6129
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6130 /* POSIX says a null character in the pattern terminates it, so we
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6131 can use strlen here in compiling the pattern. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6132 ret = regex_compile (pattern, strlen (pattern), syntax, preg);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6133
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6134 /* POSIX doesn't distinguish between an unmatched open-group and an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6135 unmatched close-group: both are REG_EPAREN. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6136 if (ret == REG_ERPAREN) ret = REG_EPAREN;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6137
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6138 return (int) ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6139 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6142 /* regexec searches for a given pattern, specified by PREG, in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6143 string STRING.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6144
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6145 If NMATCH is zero or REG_NOSUB was set in the cflags argument to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6146 `regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6147 least NMATCH elements, and we set them to the offsets of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6148 corresponding matched substrings.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6149
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6150 EFLAGS specifies `execution flags' which affect matching: if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6151 REG_NOTBOL is set, then ^ does not match at the beginning of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6152 string; if REG_NOTEOL is set, then $ does not match at the end.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6153
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6154 We return 0 if we find a match and REG_NOMATCH if not. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6156 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6157 regexec (CONST regex_t *preg, CONST char *string, size_t nmatch,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6158 regmatch_t pmatch[], int eflags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6159 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6160 int ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6161 struct re_registers regs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6162 regex_t private_preg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6163 int len = strlen (string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6164 boolean want_reg_info = !preg->no_sub && nmatch > 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6166 private_preg = *preg;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6167
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6168 private_preg.not_bol = !!(eflags & REG_NOTBOL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6169 private_preg.not_eol = !!(eflags & REG_NOTEOL);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6170
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6171 /* The user has told us exactly how many registers to return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6172 information about, via `nmatch'. We have to pass that on to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6173 matching routines. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6174 private_preg.regs_allocated = REGS_FIXED;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6175
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6176 if (want_reg_info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6177 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6178 regs.num_regs = nmatch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6179 regs.start = TALLOC (nmatch, regoff_t);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6180 regs.end = TALLOC (nmatch, regoff_t);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6181 if (regs.start == NULL || regs.end == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6182 return (int) REG_NOMATCH;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6183 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6185 /* Perform the searching operation. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6186 ret = re_search (&private_preg, string, len,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6187 /* start: */ 0, /* range: */ len,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6188 want_reg_info ? &regs : (struct re_registers *) 0);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6189
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6190 /* Copy the register information to the POSIX structure. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6191 if (want_reg_info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6192 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6193 if (ret >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6194 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6195 unsigned r;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6197 for (r = 0; r < nmatch; r++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6198 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6199 pmatch[r].rm_so = regs.start[r];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6200 pmatch[r].rm_eo = regs.end[r];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6201 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6202 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6204 /* If we needed the temporary register info, free the space now. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6205 free (regs.start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6206 free (regs.end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6207 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6209 /* We want zero return to mean success, unlike `re_search'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6210 return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6211 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6214 /* Returns a message corresponding to an error code, ERRCODE, returned
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6215 from either regcomp or regexec. We don't use PREG here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6217 size_t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6218 regerror (int errcode, CONST regex_t *preg, char *errbuf, size_t errbuf_size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6219 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6220 CONST char *msg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6221 size_t msg_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6223 if (errcode < 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6224 || errcode >= (sizeof (re_error_msgid) / sizeof (re_error_msgid[0])))
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6225 /* Only error codes returned by the rest of the code should be passed
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6226 to this routine. If we are given anything else, or if other regex
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6227 code generates an invalid error code, then the program has a bug.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6228 Dump core so we can fix it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6229 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6231 msg = gettext (re_error_msgid[errcode]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6233 msg_size = strlen (msg) + 1; /* Includes the null. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6234
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6235 if (errbuf_size != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6236 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6237 if (msg_size > errbuf_size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6238 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6239 strncpy (errbuf, msg, errbuf_size - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6240 errbuf[errbuf_size - 1] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6241 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6242 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6243 strcpy (errbuf, msg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6244 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6246 return msg_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6247 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6250 /* Free dynamically allocated space used by PREG. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6252 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6253 regfree (regex_t *preg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6254 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6255 if (preg->buffer != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6256 free (preg->buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6257 preg->buffer = NULL;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 179
diff changeset
6258
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6259 preg->allocated = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6260 preg->used = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6262 if (preg->fastmap != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6263 free (preg->fastmap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6264 preg->fastmap = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6265 preg->fastmap_accurate = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6267 if (preg->translate != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6268 free (preg->translate);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6269 preg->translate = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6270 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6272 #endif /* not emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6274 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6275 Local variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6276 make-backup-files: t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6277 version-control: t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6278 trim-versions-without-asking: nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6279 End:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6280 */