annotate src/regex.c @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 8de8e3f6228a
children 576fb035e263
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Extended regular expression matching and search library,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 version 0.12, extended for XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 (Implements POSIX draft P10003.2/D11.2, except for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 internationalization features.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 Copyright (C) 1995 Sun Microsystems, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 Copyright (C) 1995 Ben Wing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 This program is free software; you can redistribute it and/or modify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 it under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 This program is distributed in the hope that it will be useful,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 GNU General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 along with this program; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 /* Synched up with: FSF 19.29. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 /* Changes made for XEmacs:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 (1) the REGEX_BEGLINE_CHECK code from the XEmacs v18 regex routines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 was added. This causes a huge speedup in font-locking.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 (2) Rel-alloc is disabled when the MMAP version of rel-alloc is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 being used, because it's too slow -- all those calls to mmap()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 add humongous overhead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 (3) Lots and lots of changes for Mule. They are bracketed by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 `#ifdef MULE' or with comments that have `XEmacs' in them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 #ifdef HAVE_CONFIG_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 #ifndef REGISTER /* Rigidly enforced as of 20.3 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 #define REGISTER
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 #ifndef _GNU_SOURCE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 #define _GNU_SOURCE 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 /* We assume non-Mule if emacs isn't defined. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 #ifndef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 #undef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 /* We need this for `regex.h', and perhaps for the Emacs include files. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 #include <sys/types.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 /* This is for other GNU distributions with internationalized messages. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 #if defined (I18N3) && (defined (HAVE_LIBINTL_H) || defined (_LIBC))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 # include <libintl.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 # define gettext(msgid) (msgid)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 /* XEmacs: define this to add in a speedup for patterns anchored at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 the beginning of a line. Keep the ifdefs so that it's easier to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 tell where/why this code has diverged from v19. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 #define REGEX_BEGLINE_CHECK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 /* XEmacs: the current mmap-based ralloc handles small blocks very
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 poorly, so we disable it here. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 #if (defined (REL_ALLOC) && defined (HAVE_MMAP)) || defined(DOUG_LEA_MALLOC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 # undef REL_ALLOC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 /* The `emacs' switch turns on certain matching commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 that make sense only in Emacs. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 #include "syntax.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 #if (defined (DEBUG_XEMACS) && !defined (DEBUG))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 #define DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 Lisp_Object Vthe_lisp_rangetab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 complex_vars_of_regex (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 Vthe_lisp_rangetab = Fmake_range_table ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 staticpro (&Vthe_lisp_rangetab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 #else /* not MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 complex_vars_of_regex (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 #endif /* not MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 #else /* not emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 /* If we are not linking with Emacs proper,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 we can't use the relocating allocator
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 even if config.h says that we can. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 #undef REL_ALLOC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 #if defined (STDC_HEADERS) || defined (_LIBC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 #include <stdlib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 char *malloc ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 char *realloc ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 #define charptr_emchar(str) ((Emchar) (str)[0])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 #if (LONGBITS > INTBITS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 # define EMACS_INT long
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 # define EMACS_INT int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 typedef int Emchar;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 #define INC_CHARPTR(p) ((p)++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 #define DEC_CHARPTR(p) ((p)--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 #include <string.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 /* Define the syntax stuff for \<, \>, etc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 /* This must be nonzero for the wordchar and notwordchar pattern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 commands in re_match_2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 #ifndef Sword
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 #define Sword 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 #ifdef SYNTAX_TABLE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 extern char *re_syntax_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 #else /* not SYNTAX_TABLE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 /* How many characters in the character set. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 #define CHAR_SET_SIZE 256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 static char re_syntax_table[CHAR_SET_SIZE];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 init_syntax_once (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 static int done = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 if (!done)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
164 const char *word_syntax_chars =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 memset (re_syntax_table, 0, sizeof (re_syntax_table));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 while (*word_syntax_chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 re_syntax_table[(unsigned int)(*word_syntax_chars++)] = Sword;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 done = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 #endif /* not SYNTAX_TABLE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 #define SYNTAX_UNSAFE(ignored, c) re_syntax_table[c]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 #endif /* not emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 /* Under XEmacs, this is needed because we don't define it elsewhere. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 #ifdef SWITCH_ENUM_BUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 #define SWITCH_ENUM_CAST(x) ((int)(x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 #define SWITCH_ENUM_CAST(x) (x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 /* Get the interface, including the syntax bits. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 #include "regex.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 /* isalpha etc. are used for the character classes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 #include <ctype.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 /* Jim Meyering writes:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 "... Some ctype macros are valid only for character codes that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 using /bin/cc or gcc but without giving an ansi option). So, all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 ctype uses should be through macros like ISPRINT... If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 STDC_HEADERS is defined, then autoconf has verified that the ctype
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 macros don't need to be guarded with references to isascii. ...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 Defining isascii to 1 should let any compiler worth its salt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 eliminate the && through constant folding." */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 #define ISASCII_1(c) 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 #define ISASCII_1(c) isascii(c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 /* The IS*() macros can be passed any character, including an extended
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 one. We need to make sure there are no crashes, which would occur
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 otherwise due to out-of-bounds array references. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 #define ISASCII(c) (((EMACS_UINT) (c)) < 0x100 && ISASCII_1 (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 #define ISASCII(c) ISASCII_1 (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 #ifdef isblank
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 #define ISBLANK(c) (ISASCII (c) && isblank (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 #define ISBLANK(c) ((c) == ' ' || (c) == '\t')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 #ifdef isgraph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 #define ISGRAPH(c) (ISASCII (c) && isgraph (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 #define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 #define ISPRINT(c) (ISASCII (c) && isprint (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 #define ISDIGIT(c) (ISASCII (c) && isdigit (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 #define ISALNUM(c) (ISASCII (c) && isalnum (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 #define ISALPHA(c) (ISASCII (c) && isalpha (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 #define ISCNTRL(c) (ISASCII (c) && iscntrl (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 #define ISLOWER(c) (ISASCII (c) && islower (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 #define ISPUNCT(c) (ISASCII (c) && ispunct (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 #define ISSPACE(c) (ISASCII (c) && isspace (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 #define ISUPPER(c) (ISASCII (c) && isupper (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 #define ISXDIGIT(c) (ISASCII (c) && isxdigit (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 #ifndef NULL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 #define NULL (void *)0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 /* We remove any previous definition of `SIGN_EXTEND_CHAR',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 since ours (we hope) works properly with all combinations of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 machines, compilers, `char' and `unsigned char' argument types.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 (Per Bothner suggested the basic approach.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 #undef SIGN_EXTEND_CHAR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 #if __STDC__
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 #define SIGN_EXTEND_CHAR(c) ((signed char) (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 #else /* not __STDC__ */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 /* As in Harbison and Steele. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 #define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 /* Should we use malloc or alloca? If REGEX_MALLOC is not defined, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 use `alloca' instead of `malloc'. This is because using malloc in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 re_search* or re_match* could cause memory leaks when C-g is used in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 Emacs; also, malloc is slower and causes storage fragmentation. On
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 the other hand, malloc is more portable, and easier to debug.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 Because we sometimes use alloca, some routines have to be macros,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 not functions -- `alloca'-allocated space disappears at the end of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 function it is called in. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 #ifdef REGEX_MALLOC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 #define REGEX_ALLOCATE malloc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 #define REGEX_REALLOCATE(source, osize, nsize) realloc (source, nsize)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 #define REGEX_FREE free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 #else /* not REGEX_MALLOC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 /* Emacs already defines alloca, sometimes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 #ifndef alloca
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 /* Make alloca work the best possible way. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 #ifdef __GNUC__
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 #define alloca __builtin_alloca
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 #else /* not __GNUC__ */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 #if HAVE_ALLOCA_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 #include <alloca.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 #else /* not __GNUC__ or HAVE_ALLOCA_H */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 #ifndef _AIX /* Already did AIX, up at the top. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 char *alloca ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 #endif /* not _AIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 #endif /* not HAVE_ALLOCA_H */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 #endif /* not __GNUC__ */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 #endif /* not alloca */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 #define REGEX_ALLOCATE alloca
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 /* Assumes a `char *destination' variable. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 #define REGEX_REALLOCATE(source, osize, nsize) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 (destination = (char *) alloca (nsize), \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 memmove (destination, source, osize), \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 destination)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 /* No need to do anything to free, after alloca. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 #define REGEX_FREE(arg) ((void)0) /* Do nothing! But inhibit gcc warning. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 #endif /* not REGEX_MALLOC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 /* Define how to allocate the failure stack. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 #ifdef REL_ALLOC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 #define REGEX_ALLOCATE_STACK(size) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 r_alloc ((char **) &failure_stack_ptr, (size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 #define REGEX_REALLOCATE_STACK(source, osize, nsize) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 r_re_alloc ((char **) &failure_stack_ptr, (nsize))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 #define REGEX_FREE_STACK(ptr) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 r_alloc_free ((void **) &failure_stack_ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 #else /* not REL_ALLOC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 #ifdef REGEX_MALLOC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 #define REGEX_ALLOCATE_STACK malloc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 #define REGEX_REALLOCATE_STACK(source, osize, nsize) realloc (source, nsize)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 #define REGEX_FREE_STACK free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 #else /* not REGEX_MALLOC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 #define REGEX_ALLOCATE_STACK alloca
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 #define REGEX_REALLOCATE_STACK(source, osize, nsize) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 REGEX_REALLOCATE (source, osize, nsize)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 /* No need to explicitly free anything. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 #define REGEX_FREE_STACK(arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 #endif /* not REGEX_MALLOC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 #endif /* not REL_ALLOC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 /* True if `size1' is non-NULL and PTR is pointing anywhere inside
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 `string1' or just past its end. This works if PTR is NULL, which is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 a good thing. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 #define FIRST_STRING_P(ptr) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 (size1 && string1 <= (ptr) && (ptr) <= string1 + size1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 /* (Re)Allocate N items of type T using malloc, or fail. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 #define TALLOC(n, t) ((t *) malloc ((n) * sizeof (t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 #define RETALLOC(addr, n, t) ((addr) = (t *) realloc (addr, (n) * sizeof (t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 #define RETALLOC_IF(addr, n, t) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 if (addr) RETALLOC((addr), (n), t); else (addr) = TALLOC ((n), t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 #define REGEX_TALLOC(n, t) ((t *) REGEX_ALLOCATE ((n) * sizeof (t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 #define BYTEWIDTH 8 /* In bits. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
355 #define STREQ(s1, s2) (strcmp (s1, s2) == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 #undef MAX
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 #undef MIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 #define MAX(a, b) ((a) > (b) ? (a) : (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 #define MIN(a, b) ((a) < (b) ? (a) : (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 typedef char boolean;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 #define false 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 #define true 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 /* These are the command codes that appear in compiled regular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 expressions. Some opcodes are followed by argument bytes. A
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 command code can specify any interpretation whatsoever for its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 arguments. Zero bytes may appear in the compiled regular expression. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 typedef enum
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 no_op = 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 /* Succeed right away--no more backtracking. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 succeed,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 /* Followed by one byte giving n, then by n literal bytes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 exactn,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 /* Matches any (more or less) character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 anychar,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 /* Matches any one char belonging to specified set. First
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 following byte is number of bitmap bytes. Then come bytes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 for a bitmap saying which chars are in. Bits in each byte
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 are ordered low-bit-first. A character is in the set if its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 bit is 1. A character too large to have a bit in the map is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 automatically not in the set. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 charset,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 /* Same parameters as charset, but match any character that is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 not one of those specified. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 charset_not,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 /* Start remembering the text that is matched, for storing in a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 register. Followed by one byte with the register number, in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 the range 0 to one less than the pattern buffer's re_nsub
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 field. Then followed by one byte with the number of groups
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 inner to this one. (This last has to be part of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 start_memory only because we need it in the on_failure_jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 of re_match_2.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 start_memory,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 /* Stop remembering the text that is matched and store it in a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 memory register. Followed by one byte with the register
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 number, in the range 0 to one less than `re_nsub' in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 pattern buffer, and one byte with the number of inner groups,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 just like `start_memory'. (We need the number of inner
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 groups here because we don't have any easy way of finding the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 corresponding start_memory when we're at a stop_memory.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 stop_memory,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 /* Match a duplicate of something remembered. Followed by one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 byte containing the register number. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 duplicate,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 /* Fail unless at beginning of line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 begline,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 /* Fail unless at end of line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 endline,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 /* Succeeds if at beginning of buffer (if emacs) or at beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 of string to be matched (if not). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 begbuf,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 /* Analogously, for end of buffer/string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 endbuf,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 /* Followed by two byte relative address to which to jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 jump,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 /* Same as jump, but marks the end of an alternative. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 jump_past_alt,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 /* Followed by two-byte relative address of place to resume at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 in case of failure. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 on_failure_jump,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 /* Like on_failure_jump, but pushes a placeholder instead of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 current string position when executed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 on_failure_keep_string_jump,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 /* Throw away latest failure point and then jump to following
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 two-byte relative address. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 pop_failure_jump,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 /* Change to pop_failure_jump if know won't have to backtrack to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 match; otherwise change to jump. This is used to jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 back to the beginning of a repeat. If what follows this jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 clearly won't match what the repeat does, such that we can be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 sure that there is no use backtracking out of repetitions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 already matched, then we change it to a pop_failure_jump.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 Followed by two-byte address. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 maybe_pop_jump,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 /* Jump to following two-byte address, and push a dummy failure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 point. This failure point will be thrown away if an attempt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 is made to use it for a failure. A `+' construct makes this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 before the first repeat. Also used as an intermediary kind
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 of jump when compiling an alternative. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 dummy_failure_jump,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 /* Push a dummy failure point and continue. Used at the end of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 alternatives. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 push_dummy_failure,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 /* Followed by two-byte relative address and two-byte number n.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 After matching N times, jump to the address upon failure. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 succeed_n,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 /* Followed by two-byte relative address, and two-byte number n.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 Jump to the address N times, then fail. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 jump_n,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 /* Set the following two-byte relative address to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 subsequent two-byte number. The address *includes* the two
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 bytes of number. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 set_number_at,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 wordchar, /* Matches any word-constituent character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 notwordchar, /* Matches any char that is not a word-constituent. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 wordbeg, /* Succeeds if at word beginning. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 wordend, /* Succeeds if at word end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 wordbound, /* Succeeds if at a word boundary. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 notwordbound /* Succeeds if not at a word boundary. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 ,before_dot, /* Succeeds if before point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 at_dot, /* Succeeds if at point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 after_dot, /* Succeeds if after point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 /* Matches any character whose syntax is specified. Followed by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 a byte which contains a syntax code, e.g., Sword. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 syntaxspec,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 /* Matches any character whose syntax is not that specified. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 notsyntaxspec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 #endif /* emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 /* need extra stuff to be able to properly work with XEmacs/Mule
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 characters (which may take up more than one byte) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 ,charset_mule, /* Matches any character belonging to specified set.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 The set is stored in "unified range-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 format"; see rangetab.c. Unlike the `charset'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 opcode, this can handle arbitrary characters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 charset_mule_not /* Same parameters as charset_mule, but match any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 character that is not one of those specified. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 /* 97/2/17 jhod: The following two were merged back in from the Mule
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 2.3 code to enable some language specific processing */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 ,categoryspec, /* Matches entries in the character category tables */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 notcategoryspec /* The opposite of the above */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 } re_opcode_t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 /* Common operations on the compiled pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 /* Store NUMBER in two contiguous bytes starting at DESTINATION. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 #define STORE_NUMBER(destination, number) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 (destination)[0] = (number) & 0377; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 (destination)[1] = (number) >> 8; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 /* Same as STORE_NUMBER, except increment DESTINATION to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 the byte after where the number is stored. Therefore, DESTINATION
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 must be an lvalue. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 #define STORE_NUMBER_AND_INCR(destination, number) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 STORE_NUMBER (destination, number); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 (destination) += 2; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 /* Put into DESTINATION a number stored in two contiguous bytes starting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 at SOURCE. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 #define EXTRACT_NUMBER(destination, source) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 (destination) = *(source) & 0377; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 extract_number (int *dest, unsigned char *source)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 int temp = SIGN_EXTEND_CHAR (*(source + 1));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 *dest = *source & 0377;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 *dest += temp << 8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 #ifndef EXTRACT_MACROS /* To debug the macros. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 #undef EXTRACT_NUMBER
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 #define EXTRACT_NUMBER(dest, src) extract_number (&dest, src)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 #endif /* not EXTRACT_MACROS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 #endif /* DEBUG */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 /* Same as EXTRACT_NUMBER, except increment SOURCE to after the number.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 SOURCE must be an lvalue. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 #define EXTRACT_NUMBER_AND_INCR(destination, source) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 EXTRACT_NUMBER (destination, source); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 (source) += 2; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 extract_number_and_incr (int *destination, unsigned char **source)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 extract_number (destination, *source);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 *source += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 #ifndef EXTRACT_MACROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 #undef EXTRACT_NUMBER_AND_INCR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 #define EXTRACT_NUMBER_AND_INCR(dest, src) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 extract_number_and_incr (&dest, &src)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 #endif /* not EXTRACT_MACROS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 #endif /* DEBUG */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 /* If DEBUG is defined, Regex prints many voluminous messages about what
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 it is doing (if the variable `debug' is nonzero). If linked with the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 main program in `iregex.c', you can enter patterns and strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 interactively. And if linked with the main program in `main.c' and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 the other test files, you can run the already-written tests. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 #if defined (DEBUG)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 /* We use standard I/O for debugging. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 #include <stdio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 #ifndef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 /* XEmacs provides its own version of assert() */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 /* It is useful to test things that ``must'' be true when debugging. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 #include <assert.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 static int debug = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 #define DEBUG_STATEMENT(e) e
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 #define DEBUG_PRINT1(x) if (debug) printf (x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 #define DEBUG_PRINT2(x1, x2) if (debug) printf (x1, x2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 #define DEBUG_PRINT3(x1, x2, x3) if (debug) printf (x1, x2, x3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 #define DEBUG_PRINT4(x1, x2, x3, x4) if (debug) printf (x1, x2, x3, x4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 #define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 if (debug) print_partial_compiled_pattern (s, e)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 #define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 if (debug) print_double_string (w, s1, sz1, s2, sz2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 /* Print the fastmap in human-readable form. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 print_fastmap (char *fastmap)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 unsigned was_a_range = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 unsigned i = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 while (i < (1 << BYTEWIDTH))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 if (fastmap[i++])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 was_a_range = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 putchar (i - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 while (i < (1 << BYTEWIDTH) && fastmap[i])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 was_a_range = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 i++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 if (was_a_range)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 putchar ('-');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 putchar (i - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 putchar ('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 /* Print a compiled pattern string in human-readable form, starting at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 the START pointer into it and ending just before the pointer END. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 print_partial_compiled_pattern (unsigned char *start, unsigned char *end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 int mcnt, mcnt2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 unsigned char *p = start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 unsigned char *pend = end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 if (start == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 puts ("(null)");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 /* Loop over pattern commands. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 while (p < pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 printf ("%ld:\t", (long)(p - start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 switch ((re_opcode_t) *p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 case no_op:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 printf ("/no_op");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 case exactn:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 printf ("/exactn/%d", mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 putchar ('/');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 putchar (*p++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 while (--mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 case start_memory:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 printf ("/start_memory/%d/%d", mcnt, *p++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 case stop_memory:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 printf ("/stop_memory/%d/%d", mcnt, *p++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 case duplicate:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 printf ("/duplicate/%d", *p++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 case anychar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 printf ("/anychar");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 case charset:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 case charset_not:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 REGISTER int c, last = -100;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 REGISTER int in_range = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 printf ("/charset [%s",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 (re_opcode_t) *(p - 1) == charset_not ? "^" : "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 assert (p + *p < pend);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 for (c = 0; c < 256; c++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 if (((unsigned char) (c / 8) < *p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 && (p[1 + (c/8)] & (1 << (c % 8))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 /* Are we starting a range? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 if (last + 1 == c && ! in_range)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 putchar ('-');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 in_range = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 /* Have we broken a range? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 else if (last + 1 != c && in_range)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 putchar (last);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 in_range = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 if (! in_range)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 putchar (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 last = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 if (in_range)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 putchar (last);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 putchar (']');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 p += 1 + *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 case charset_mule:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 case charset_mule_not:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 int nentries, i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 printf ("/charset_mule [%s",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 (re_opcode_t) *(p - 1) == charset_mule_not ? "^" : "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 nentries = unified_range_table_nentries (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 for (i = 0; i < nentries; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 EMACS_INT first, last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 Lisp_Object dummy_val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 unified_range_table_get_range (p, i, &first, &last,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 &dummy_val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 if (first < 0x100)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 putchar (first);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 printf ("(0x%lx)", (long)first);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 if (first != last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 putchar ('-');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 if (last < 0x100)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 putchar (last);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 printf ("(0x%lx)", (long)last);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 putchar (']');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 p += unified_range_table_bytes_used (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 case begline:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 printf ("/begline");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 case endline:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 printf ("/endline");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 case on_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 printf ("/on_failure_jump to %ld", (long)(p + mcnt - start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 case on_failure_keep_string_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 printf ("/on_failure_keep_string_jump to %ld", (long)(p + mcnt - start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 case dummy_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 printf ("/dummy_failure_jump to %ld", (long)(p + mcnt - start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 case push_dummy_failure:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 printf ("/push_dummy_failure");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 case maybe_pop_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 printf ("/maybe_pop_jump to %ld", (long)(p + mcnt - start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 case pop_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 printf ("/pop_failure_jump to %ld", (long)(p + mcnt - start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 case jump_past_alt:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 printf ("/jump_past_alt to %ld", (long)(p + mcnt - start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 case jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 printf ("/jump to %ld", (long)(p + mcnt - start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 case succeed_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 extract_number_and_incr (&mcnt2, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 printf ("/succeed_n to %ld, %d times", (long)(p + mcnt - start), mcnt2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 case jump_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 extract_number_and_incr (&mcnt2, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 printf ("/jump_n to %ld, %d times", (long)(p + mcnt - start), mcnt2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 case set_number_at:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 extract_number_and_incr (&mcnt2, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 printf ("/set_number_at location %ld to %d", (long)(p + mcnt - start), mcnt2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 case wordbound:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 printf ("/wordbound");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 case notwordbound:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 printf ("/notwordbound");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 case wordbeg:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 printf ("/wordbeg");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 case wordend:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 printf ("/wordend");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 case before_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 printf ("/before_dot");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 case at_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 printf ("/at_dot");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 case after_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 printf ("/after_dot");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 case syntaxspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 printf ("/syntaxspec");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 printf ("/%d", mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 case notsyntaxspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 printf ("/notsyntaxspec");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 printf ("/%d", mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 /* 97/2/17 jhod Mule category patch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 case categoryspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 printf ("/categoryspec");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 printf ("/%d", mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 case notcategoryspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 printf ("/notcategoryspec");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 printf ("/%d", mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 /* end of category patch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 #endif /* emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 case wordchar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 printf ("/wordchar");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 case notwordchar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 printf ("/notwordchar");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 case begbuf:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 printf ("/begbuf");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 case endbuf:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 printf ("/endbuf");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 printf ("?%d", *(p-1));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 putchar ('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 printf ("%ld:\tend of pattern.\n", (long)(p - start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 print_compiled_pattern (struct re_pattern_buffer *bufp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 unsigned char *buffer = bufp->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 print_partial_compiled_pattern (buffer, buffer + bufp->used);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 printf ("%ld bytes used/%ld bytes allocated.\n", bufp->used,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 bufp->allocated);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 if (bufp->fastmap_accurate && bufp->fastmap)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 printf ("fastmap: ");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 print_fastmap (bufp->fastmap);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 printf ("re_nsub: %ld\t", (long)bufp->re_nsub);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 printf ("regs_alloc: %d\t", bufp->regs_allocated);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 printf ("can_be_null: %d\t", bufp->can_be_null);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 printf ("newline_anchor: %d\n", bufp->newline_anchor);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 printf ("no_sub: %d\t", bufp->no_sub);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 printf ("not_bol: %d\t", bufp->not_bol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 printf ("not_eol: %d\t", bufp->not_eol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 printf ("syntax: %d\n", bufp->syntax);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 /* Perhaps we should print the translate table? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 /* and maybe the category table? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
968 print_double_string (const char *where, const char *string1, int size1,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
969 const char *string2, int size2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 if (where == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 printf ("(null)");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 unsigned int this_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 if (FIRST_STRING_P (where))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 for (this_char = where - string1; this_char < size1; this_char++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 putchar (string1[this_char]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 where = string2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 for (this_char = where - string2; this_char < size2; this_char++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 putchar (string2[this_char]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 #else /* not DEBUG */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 #undef assert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 #define assert(e)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 #define DEBUG_STATEMENT(e)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 #define DEBUG_PRINT1(x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 #define DEBUG_PRINT2(x1, x2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 #define DEBUG_PRINT3(x1, x2, x3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 #define DEBUG_PRINT4(x1, x2, x3, x4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 #define DEBUG_PRINT_COMPILED_PATTERN(p, s, e)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 #define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 #endif /* not DEBUG */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 /* Set by `re_set_syntax' to the current regexp syntax to recognize. Can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 also be assigned to arbitrarily: each pattern buffer stores its own
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 syntax, so it can be changed between regex compilations. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 /* This has no initializer because initialized variables in Emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 become read-only after dumping. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 reg_syntax_t re_syntax_options;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 /* Specify the precise syntax of regexps for compilation. This provides
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 for compatibility for various utilities which historically have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 different, incompatible syntaxes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 The argument SYNTAX is a bit mask comprised of the various bits
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 defined in regex.h. We return the old syntax. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 reg_syntax_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 re_set_syntax (reg_syntax_t syntax)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 reg_syntax_t ret = re_syntax_options;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 re_syntax_options = syntax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 return ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 /* This table gives an error message for each of the error codes listed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 in regex.h. Obviously the order here has to be same as there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 POSIX doesn't require that we do anything for REG_NOERROR,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 but why not be nice? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1034 static const char *re_error_msgid[] =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 "Success", /* REG_NOERROR */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 "No match", /* REG_NOMATCH */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 "Invalid regular expression", /* REG_BADPAT */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 "Invalid collation character", /* REG_ECOLLATE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 "Invalid character class name", /* REG_ECTYPE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 "Trailing backslash", /* REG_EESCAPE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 "Invalid back reference", /* REG_ESUBREG */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 "Unmatched [ or [^", /* REG_EBRACK */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 "Unmatched ( or \\(", /* REG_EPAREN */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 "Unmatched \\{", /* REG_EBRACE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 "Invalid content of \\{\\}", /* REG_BADBR */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 "Invalid range end", /* REG_ERANGE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 "Memory exhausted", /* REG_ESPACE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 "Invalid preceding regular expression", /* REG_BADRPT */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 "Premature end of regular expression", /* REG_EEND */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 "Regular expression too big", /* REG_ESIZE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 "Unmatched ) or \\)", /* REG_ERPAREN */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 "Invalid syntax designator", /* REG_ESYNTAX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 "Ranges may not span charsets", /* REG_ERANGESPAN */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 "Invalid category designator", /* REG_ECATEGORY */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 /* Avoiding alloca during matching, to placate r_alloc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 /* Define MATCH_MAY_ALLOCATE unless we need to make sure that the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 searching and matching functions should not call alloca. On some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 systems, alloca is implemented in terms of malloc, and if we're
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 using the relocating allocator routines, then malloc could cause a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 relocation, which might (if the strings being searched are in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 ralloc heap) shift the data out from underneath the regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 routines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 Here's another reason to avoid allocation: Emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 processes input from X in a signal handler; processing X input may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 call malloc; if input arrives while a matching routine is calling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 malloc, then we're scrod. But Emacs can't just block input while
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 calling matching routines; then we don't notice interrupts when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 they come in. So, Emacs blocks input around all regexp calls
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 except the matching calls, which it leaves unprotected, in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 faith that they will not malloc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 /* Normally, this is fine. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 #define MATCH_MAY_ALLOCATE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 /* When using GNU C, we are not REALLY using the C alloca, no matter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 what config.h may say. So don't take precautions for it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 #ifdef __GNUC__
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 #undef C_ALLOCA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 /* The match routines may not allocate if (1) they would do it with malloc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 and (2) it's not safe for them to use malloc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 Note that if REL_ALLOC is defined, matching would not use malloc for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 failure stack, but we would still use it for the register vectors;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 so REL_ALLOC should not affect this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 #if (defined (C_ALLOCA) || defined (REGEX_MALLOC)) && defined (emacs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 #undef MATCH_MAY_ALLOCATE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 /* Failure stack declarations and macros; both re_compile_fastmap and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 re_match_2 use a failure stack. These have to be macros because of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 REGEX_ALLOCATE_STACK. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 /* Number of failure points for which to initially allocate space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 when matching. If this number is exceeded, we allocate more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 space, so it is not a hard limit. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 #ifndef INIT_FAILURE_ALLOC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 #define INIT_FAILURE_ALLOC 5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 /* Roughly the maximum number of failure points on the stack. Would be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 exactly that if always used MAX_FAILURE_SPACE each time we failed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 This is a variable only so users of regex can assign to it; we never
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 change it ourselves. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 #if defined (MATCH_MAY_ALLOCATE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 /* 4400 was enough to cause a crash on Alpha OSF/1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 whose default stack limit is 2mb. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 int re_max_failures = 20000;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 int re_max_failures = 2000;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 union fail_stack_elt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 unsigned char *pointer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 int integer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 typedef union fail_stack_elt fail_stack_elt_t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 typedef struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 fail_stack_elt_t *stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 unsigned size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 unsigned avail; /* Offset of next open position. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 } fail_stack_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 #define FAIL_STACK_EMPTY() (fail_stack.avail == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 #define FAIL_STACK_PTR_EMPTY() (fail_stack_ptr->avail == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 #define FAIL_STACK_FULL() (fail_stack.avail == fail_stack.size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 /* Define macros to initialize and free the failure stack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 Do `return -2' if the alloc fails. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 #ifdef MATCH_MAY_ALLOCATE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 #define INIT_FAIL_STACK() \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 fail_stack.stack = (fail_stack_elt_t *) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 REGEX_ALLOCATE_STACK (INIT_FAILURE_ALLOC * sizeof (fail_stack_elt_t)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 if (fail_stack.stack == NULL) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 return -2; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 fail_stack.size = INIT_FAILURE_ALLOC; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 fail_stack.avail = 0; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 #define RESET_FAIL_STACK() REGEX_FREE_STACK (fail_stack.stack)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 #define INIT_FAIL_STACK() \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 fail_stack.avail = 0; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 #define RESET_FAIL_STACK()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 /* Double the size of FAIL_STACK, up to approximately `re_max_failures' items.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 Return 1 if succeeds, and 0 if either ran out of memory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 allocating space for it or it was already too large.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 REGEX_REALLOCATE_STACK requires `destination' be declared. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 #define DOUBLE_FAIL_STACK(fail_stack) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 ((fail_stack).size > re_max_failures * MAX_FAILURE_ITEMS \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 ? 0 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 : ((fail_stack).stack = (fail_stack_elt_t *) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 REGEX_REALLOCATE_STACK ((fail_stack).stack, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 (fail_stack).size * sizeof (fail_stack_elt_t), \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 ((fail_stack).size << 1) * sizeof (fail_stack_elt_t)), \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 (fail_stack).stack == NULL \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 ? 0 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 : ((fail_stack).size <<= 1, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 /* Push pointer POINTER on FAIL_STACK.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 Return 1 if was able to do so and 0 if ran out of memory allocating
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 space to do so. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 #define PUSH_PATTERN_OP(POINTER, FAIL_STACK) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 ((FAIL_STACK_FULL () \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 && !DOUBLE_FAIL_STACK (FAIL_STACK)) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 ? 0 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 : ((FAIL_STACK).stack[(FAIL_STACK).avail++].pointer = POINTER, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 /* Push a pointer value onto the failure stack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 Assumes the variable `fail_stack'. Probably should only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 be called from within `PUSH_FAILURE_POINT'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 #define PUSH_FAILURE_POINTER(item) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 fail_stack.stack[fail_stack.avail++].pointer = (unsigned char *) (item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 /* This pushes an integer-valued item onto the failure stack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 Assumes the variable `fail_stack'. Probably should only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 be called from within `PUSH_FAILURE_POINT'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 #define PUSH_FAILURE_INT(item) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 fail_stack.stack[fail_stack.avail++].integer = (item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 /* Push a fail_stack_elt_t value onto the failure stack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 Assumes the variable `fail_stack'. Probably should only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 be called from within `PUSH_FAILURE_POINT'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 #define PUSH_FAILURE_ELT(item) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 fail_stack.stack[fail_stack.avail++] = (item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 /* These three POP... operations complement the three PUSH... operations.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 All assume that `fail_stack' is nonempty. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 #define POP_FAILURE_POINTER() fail_stack.stack[--fail_stack.avail].pointer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 #define POP_FAILURE_INT() fail_stack.stack[--fail_stack.avail].integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 #define POP_FAILURE_ELT() fail_stack.stack[--fail_stack.avail]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 /* Used to omit pushing failure point id's when we're not debugging. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 #define DEBUG_PUSH PUSH_FAILURE_INT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 #define DEBUG_POP(item_addr) *(item_addr) = POP_FAILURE_INT ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 #define DEBUG_PUSH(item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 #define DEBUG_POP(item_addr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 /* Push the information about the state we will need
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 if we ever fail back to it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 Requires variables fail_stack, regstart, regend, reg_info, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 num_regs be declared. DOUBLE_FAIL_STACK requires `destination' be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 declared.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 Does `return FAILURE_CODE' if runs out of memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 #if !defined (REGEX_MALLOC) && !defined (REL_ALLOC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 #define DECLARE_DESTINATION char *destination;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 #define DECLARE_DESTINATION
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 #define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 DECLARE_DESTINATION \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 /* Must be int, so when we don't save any registers, the arithmetic \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 of 0 + -1 isn't done as unsigned. */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 int this_reg; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 DEBUG_STATEMENT (failure_id++); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 DEBUG_STATEMENT (nfailure_points_pushed++); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 DEBUG_PRINT2 ("\nPUSH_FAILURE_POINT #%u:\n", failure_id); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 DEBUG_PRINT2 (" Before push, next avail: %d\n", (fail_stack).avail);\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 DEBUG_PRINT2 (" size: %d\n", (fail_stack).size);\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 DEBUG_PRINT2 (" slots needed: %d\n", NUM_FAILURE_ITEMS); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 DEBUG_PRINT2 (" available: %d\n", REMAINING_AVAIL_SLOTS); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 /* Ensure we have enough space allocated for what we will push. */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 if (!DOUBLE_FAIL_STACK (fail_stack)) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 return failure_code; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 (fail_stack).size); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 DEBUG_PRINT2 (" slots available: %d\n", REMAINING_AVAIL_SLOTS);\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 /* Push the info, starting with the registers. */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 DEBUG_PRINT1 ("\n"); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 for (this_reg = lowest_active_reg; this_reg <= highest_active_reg; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 this_reg++) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 DEBUG_PRINT2 (" Pushing reg: %d\n", this_reg); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 DEBUG_STATEMENT (num_regs_pushed++); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 DEBUG_PRINT2 (" start: 0x%lx\n", (long) regstart[this_reg]); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 PUSH_FAILURE_POINTER (regstart[this_reg]); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 DEBUG_PRINT2 (" end: 0x%lx\n", (long) regend[this_reg]); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 PUSH_FAILURE_POINTER (regend[this_reg]); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 DEBUG_PRINT2 (" info: 0x%lx\n ", \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 * (long *) (&reg_info[this_reg])); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 DEBUG_PRINT2 (" match_null=%d", \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 REG_MATCH_NULL_STRING_P (reg_info[this_reg])); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 DEBUG_PRINT2 (" active=%d", IS_ACTIVE (reg_info[this_reg])); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 DEBUG_PRINT2 (" matched_something=%d", \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 MATCHED_SOMETHING (reg_info[this_reg])); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 DEBUG_PRINT2 (" ever_matched=%d", \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 EVER_MATCHED_SOMETHING (reg_info[this_reg])); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 DEBUG_PRINT1 ("\n"); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 PUSH_FAILURE_ELT (reg_info[this_reg].word); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 DEBUG_PRINT2 (" Pushing low active reg: %d\n", lowest_active_reg);\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 PUSH_FAILURE_INT (lowest_active_reg); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 DEBUG_PRINT2 (" Pushing high active reg: %d\n", highest_active_reg);\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 PUSH_FAILURE_INT (highest_active_reg); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 DEBUG_PRINT2 (" Pushing pattern 0x%lx: ", (long) pattern_place); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 PUSH_FAILURE_POINTER (pattern_place); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 DEBUG_PRINT2 (" Pushing string 0x%lx: `", (long) string_place); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 size2); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 DEBUG_PRINT1 ("'\n"); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 PUSH_FAILURE_POINTER (string_place); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 DEBUG_PRINT2 (" Pushing failure id: %u\n", failure_id); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 DEBUG_PUSH (failure_id); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 /* This is the number of items that are pushed and popped on the stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 for each register. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 #define NUM_REG_ITEMS 3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 /* Individual items aside from the registers. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 #define NUM_NONREG_ITEMS 5 /* Includes failure point id. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 #define NUM_NONREG_ITEMS 4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 /* We push at most this many items on the stack. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 /* We used to use (num_regs - 1), which is the number of registers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 this regexp will save; but that was changed to 5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 to avoid stack overflow for a regexp with lots of parens. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 #define MAX_FAILURE_ITEMS (5 * NUM_REG_ITEMS + NUM_NONREG_ITEMS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 /* We actually push this many items. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 #define NUM_FAILURE_ITEMS \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 ((highest_active_reg - lowest_active_reg + 1) * NUM_REG_ITEMS \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 + NUM_NONREG_ITEMS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 /* How many items can still be added to the stack without overflowing it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 #define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 /* Pops what PUSH_FAIL_STACK pushes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 We restore into the parameters, all of which should be lvalues:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 STR -- the saved data position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 PAT -- the saved pattern position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 LOW_REG, HIGH_REG -- the highest and lowest active registers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 REGSTART, REGEND -- arrays of string positions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 REG_INFO -- array of information about each subexpression.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 Also assumes the variables `fail_stack' and (if debugging), `bufp',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 `pend', `string1', `size1', `string2', and `size2'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 #define POP_FAILURE_POINT(str, pat, low_reg, high_reg, regstart, regend, reg_info)\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 DEBUG_STATEMENT (fail_stack_elt_t ffailure_id;) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 int this_reg; \
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1368 const unsigned char *string_temp; \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 assert (!FAIL_STACK_EMPTY ()); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 /* Remove failure points and point to how many regs pushed. */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 DEBUG_PRINT2 (" Before pop, next avail: %d\n", fail_stack.avail); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 DEBUG_PRINT2 (" size: %d\n", fail_stack.size); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 assert (fail_stack.avail >= NUM_NONREG_ITEMS); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 DEBUG_POP (&ffailure_id.integer); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 DEBUG_PRINT2 (" Popping failure id: %u\n", \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 * (unsigned int *) &ffailure_id); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 /* If the saved string location is NULL, it came from an \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 on_failure_keep_string_jump opcode, and we want to throw away the \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 saved NULL, thus retaining our current position in the string. */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 string_temp = POP_FAILURE_POINTER (); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 if (string_temp != NULL) \
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1388 str = (const char *) string_temp; \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 DEBUG_PRINT2 (" Popping string 0x%lx: `", (long) str); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 DEBUG_PRINT1 ("'\n"); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 pat = (unsigned char *) POP_FAILURE_POINTER (); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 DEBUG_PRINT2 (" Popping pattern 0x%lx: ", (long) pat); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 /* Restore register info. */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 high_reg = (unsigned) POP_FAILURE_INT (); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 DEBUG_PRINT2 (" Popping high active reg: %d\n", high_reg); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 low_reg = (unsigned) POP_FAILURE_INT (); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 DEBUG_PRINT2 (" Popping low active reg: %d\n", low_reg); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 for (this_reg = high_reg; this_reg >= low_reg; this_reg--) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 DEBUG_PRINT2 (" Popping reg: %d\n", this_reg); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 reg_info[this_reg].word = POP_FAILURE_ELT (); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 DEBUG_PRINT2 (" info: 0x%lx\n", \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 * (long *) &reg_info[this_reg]); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 \
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1413 regend[this_reg] = (const char *) POP_FAILURE_POINTER (); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 DEBUG_PRINT2 (" end: 0x%lx\n", (long) regend[this_reg]); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 \
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1416 regstart[this_reg] = (const char *) POP_FAILURE_POINTER (); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 DEBUG_PRINT2 (" start: 0x%lx\n", (long) regstart[this_reg]); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 set_regs_matched_done = 0; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 DEBUG_STATEMENT (nfailure_points_popped++); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 } /* POP_FAILURE_POINT */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 /* Structure for per-register (a.k.a. per-group) information.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 Other register information, such as the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 starting and ending positions (which are addresses), and the list of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 inner groups (which is a bits list) are maintained in separate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 variables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 We are making a (strictly speaking) nonportable assumption here: that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 the compiler will pack our bit fields into something that fits into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 the type of `word', i.e., is something that fits into one item on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 failure stack. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 typedef union
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 fail_stack_elt_t word;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 /* This field is one if this group can match the empty string,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 zero if not. If not yet determined, `MATCH_NULL_UNSET_VALUE'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 #define MATCH_NULL_UNSET_VALUE 3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 unsigned match_null_string_p : 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 unsigned is_active : 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 unsigned matched_something : 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 unsigned ever_matched_something : 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 } bits;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 } register_info_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 #define REG_MATCH_NULL_STRING_P(R) ((R).bits.match_null_string_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 #define IS_ACTIVE(R) ((R).bits.is_active)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 #define MATCHED_SOMETHING(R) ((R).bits.matched_something)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 #define EVER_MATCHED_SOMETHING(R) ((R).bits.ever_matched_something)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 /* Call this when have matched a real character; it sets `matched' flags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 for the subexpressions which we are currently inside. Also records
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 that those subexprs have matched. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 #define SET_REGS_MATCHED() \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462 do \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 if (!set_regs_matched_done) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 unsigned r; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 set_regs_matched_done = 1; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 for (r = lowest_active_reg; r <= highest_active_reg; r++) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 MATCHED_SOMETHING (reg_info[r]) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 = EVER_MATCHED_SOMETHING (reg_info[r]) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 = 1; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 /* Registers are set to a sentinel when they haven't yet matched. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 static char reg_unset_dummy;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 #define REG_UNSET_VALUE (&reg_unset_dummy)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 #define REG_UNSET(e) ((e) == REG_UNSET_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 /* Subroutine declarations and macros for regex_compile. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 /* Fetch the next character in the uncompiled pattern---translating it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 if necessary. Also cast from a signed character in the constant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 string passed to us by the user to an unsigned char that we can use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 as an array index (in, e.g., `translate'). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 #define PATFETCH(c) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 do {if (p == pend) return REG_EEND; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 assert (p < pend); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 c = (unsigned char) *p++; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 if (translate) c = (unsigned char) translate[c]; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 /* Fetch the next character in the uncompiled pattern, with no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 translation. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 #define PATFETCH_RAW(c) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 do {if (p == pend) return REG_EEND; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 assert (p < pend); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 c = (unsigned char) *p++; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 /* Go backwards one character in the pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 #define PATUNFETCH p--
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 #define PATFETCH_EXTENDED(emch) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 do {if (p == pend) return REG_EEND; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 assert (p < pend); \
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1512 emch = charptr_emchar ((const Bufbyte *) p); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 INC_CHARPTR (p); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 if (translate && emch < 0x80) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 emch = (Emchar) (unsigned char) translate[emch]; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 #define PATFETCH_RAW_EXTENDED(emch) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 do {if (p == pend) return REG_EEND; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 assert (p < pend); \
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1521 emch = charptr_emchar ((const Bufbyte *) p); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 INC_CHARPTR (p); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 #define PATUNFETCH_EXTENDED DEC_CHARPTR (p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 #define PATFETCH_EITHER(emch) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 if (has_extended_chars) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 PATFETCH_EXTENDED (emch); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 else \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 PATFETCH (emch); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 #define PATFETCH_RAW_EITHER(emch) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 if (has_extended_chars) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 PATFETCH_RAW_EXTENDED (emch); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 else \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 PATFETCH_RAW (emch); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 #define PATUNFETCH_EITHER \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 if (has_extended_chars) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 PATUNFETCH_EXTENDED (emch); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 else \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 PATUNFETCH (emch); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 #else /* not MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 #define PATFETCH_EITHER(emch) PATFETCH (emch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 #define PATFETCH_RAW_EITHER(emch) PATFETCH_RAW (emch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 #define PATUNFETCH_EITHER PATUNFETCH
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 #endif /* not MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 /* If `translate' is non-null, return translate[D], else just D. We
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 cast the subscript to translate because some data is declared as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561 `char *', to avoid warnings when a string constant is passed. But
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 when we use a character as a subscript we must make it unsigned. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 #define TRANSLATE(d) (translate ? translate[(unsigned char) (d)] : (d))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 #define TRANSLATE_EXTENDED_UNSAFE(emch) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 (translate && emch < 0x80 ? translate[emch] : (emch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 /* Macros for outputting the compiled pattern into `buffer'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574 /* If the buffer isn't allocated when it comes in, use this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575 #define INIT_BUF_SIZE 32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 /* Make sure we have at least N more bytes of space in buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578 #define GET_BUFFER_SPACE(n) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579 while (b - bufp->buffer + (n) > bufp->allocated) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580 EXTEND_BUFFER ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 /* Make sure we have one more byte of buffer space and then add C to it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 #define BUF_PUSH(c) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 GET_BUFFER_SPACE (1); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 *b++ = (unsigned char) (c); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590 /* Ensure we have two more bytes of buffer space and then append C1 and C2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 #define BUF_PUSH_2(c1, c2) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 GET_BUFFER_SPACE (2); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 *b++ = (unsigned char) (c1); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 *b++ = (unsigned char) (c2); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 /* As with BUF_PUSH_2, except for three bytes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 #define BUF_PUSH_3(c1, c2, c3) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 GET_BUFFER_SPACE (3); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 *b++ = (unsigned char) (c1); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 *b++ = (unsigned char) (c2); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 *b++ = (unsigned char) (c3); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 /* Store a jump with opcode OP at LOC to location TO. We store a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 relative address offset by the three bytes the jump itself occupies. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 #define STORE_JUMP(op, loc, to) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 store_op1 (op, loc, (to) - (loc) - 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614 /* Likewise, for a two-argument jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 #define STORE_JUMP2(op, loc, to, arg) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 store_op2 (op, loc, (to) - (loc) - 3, arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 /* Like `STORE_JUMP', but for inserting. Assume `b' is the buffer end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 #define INSERT_JUMP(op, loc, to) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620 insert_op1 (op, loc, (to) - (loc) - 3, b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 /* Like `STORE_JUMP2', but for inserting. Assume `b' is the buffer end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 #define INSERT_JUMP2(op, loc, to, arg) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 insert_op2 (op, loc, (to) - (loc) - 3, arg, b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627 /* This is not an arbitrary limit: the arguments which represent offsets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 into the pattern are two bytes long. So if 2^16 bytes turns out to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629 be too small, many things would have to change. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 #define MAX_BUF_SIZE (1L << 16)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 /* Extend the buffer by twice its current size via realloc and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 reset the pointers that pointed into the old block to point to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 correct places in the new one. If extending the buffer results in it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636 being larger than MAX_BUF_SIZE, then flag memory exhausted. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 #define EXTEND_BUFFER() \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639 unsigned char *old_buffer = bufp->buffer; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 if (bufp->allocated == MAX_BUF_SIZE) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 return REG_ESIZE; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642 bufp->allocated <<= 1; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 if (bufp->allocated > MAX_BUF_SIZE) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644 bufp->allocated = MAX_BUF_SIZE; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 bufp->buffer = (unsigned char *) realloc (bufp->buffer, bufp->allocated);\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646 if (bufp->buffer == NULL) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647 return REG_ESPACE; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 /* If the buffer moved, move all the pointers into it. */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649 if (old_buffer != bufp->buffer) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 b = (b - old_buffer) + bufp->buffer; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652 begalt = (begalt - old_buffer) + bufp->buffer; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 if (fixup_alt_jump) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654 fixup_alt_jump = (fixup_alt_jump - old_buffer) + bufp->buffer;\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 if (laststart) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 laststart = (laststart - old_buffer) + bufp->buffer; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657 if (pending_exact) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 pending_exact = (pending_exact - old_buffer) + bufp->buffer; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 /* Since we have one byte reserved for the register number argument to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 {start,stop}_memory, the maximum number of groups we can report
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 things about is what fits in that byte. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 #define MAX_REGNUM 255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 /* But patterns can have more than `MAX_REGNUM' registers. We just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 ignore the excess. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670 typedef unsigned regnum_t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 /* Macros for the compile stack. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 /* Since offsets can go either forwards or backwards, this type needs to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 be able to hold values from -(MAX_BUF_SIZE - 1) to MAX_BUF_SIZE - 1. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 typedef int pattern_offset_t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 typedef struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 pattern_offset_t begalt_offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 pattern_offset_t fixup_alt_jump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 pattern_offset_t inner_group_offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 pattern_offset_t laststart_offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 regnum_t regnum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 } compile_stack_elt_t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 typedef struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 compile_stack_elt_t *stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 unsigned size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 unsigned avail; /* Offset of next open position. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 } compile_stack_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 #define INIT_COMPILE_STACK_SIZE 32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 #define COMPILE_STACK_EMPTY (compile_stack.avail == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 #define COMPILE_STACK_FULL (compile_stack.avail == compile_stack.size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 /* The next available element. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 #define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 /* Set the bit for character C in a bit vector. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 #define SET_LIST_BIT(c) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 (b[((unsigned char) (c)) / BYTEWIDTH] \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 |= 1 << (((unsigned char) c) % BYTEWIDTH))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713 /* Set the "bit" for character C in a range table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 #define SET_RANGETAB_BIT(c) put_range_table (rtab, c, c, Qt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 /* Set the "bit" for character c in the appropriate table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 #define SET_EITHER_BIT(c) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719 if (has_extended_chars) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 SET_RANGETAB_BIT (c); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 else \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 SET_LIST_BIT (c); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 #else /* not MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 #define SET_EITHER_BIT(c) SET_LIST_BIT (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 /* Get the next unsigned number in the uncompiled pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 #define GET_UNSIGNED_NUMBER(num) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 { if (p != pend) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 PATFETCH (c); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 while (ISDIGIT (c)) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 if (num < 0) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740 num = 0; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741 num = num * 10 + c - '0'; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 if (p == pend) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 break; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 PATFETCH (c); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1747 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749 #define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1751 #define IS_CHAR_CLASS(string) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 (STREQ (string, "alpha") || STREQ (string, "upper") \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 || STREQ (string, "lower") || STREQ (string, "digit") \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 || STREQ (string, "alnum") || STREQ (string, "xdigit") \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 || STREQ (string, "space") || STREQ (string, "print") \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 || STREQ (string, "punct") || STREQ (string, "graph") \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 || STREQ (string, "cntrl") || STREQ (string, "blank"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759 static void store_op1 (re_opcode_t op, unsigned char *loc, int arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 static void store_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 static void insert_op1 (re_opcode_t op, unsigned char *loc, int arg,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 unsigned char *end);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 static void insert_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764 unsigned char *end);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1765 static boolean at_begline_loc_p (const char *pattern, const char *p,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 reg_syntax_t syntax);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1767 static boolean at_endline_loc_p (const char *p, const char *pend, int syntax);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1768 static boolean group_in_compile_stack (compile_stack_type compile_stack,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 regnum_t regnum);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1770 static reg_errcode_t compile_range (const char **p_ptr, const char *pend,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 char *translate, reg_syntax_t syntax,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 unsigned char *b);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 #ifdef MULE
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1774 static reg_errcode_t compile_extended_range (const char **p_ptr,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1775 const char *pend,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 char *translate,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 reg_syntax_t syntax,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778 Lisp_Object rtab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 static boolean group_match_null_string_p (unsigned char **p,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781 unsigned char *end,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 register_info_type *reg_info);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 static boolean alt_match_null_string_p (unsigned char *p, unsigned char *end,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784 register_info_type *reg_info);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 static boolean common_op_match_null_string_p (unsigned char **p,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 unsigned char *end,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 register_info_type *reg_info);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1788 static int bcmp_translate (const unsigned char *s1, const unsigned char *s2,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 REGISTER int len, char *translate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 static int re_match_2_internal (struct re_pattern_buffer *bufp,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1791 const char *string1, int size1,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1792 const char *string2, int size2, int pos,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 struct re_registers *regs, int stop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 #ifndef MATCH_MAY_ALLOCATE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 /* If we cannot allocate large objects within re_match_2_internal,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 we make the fail stack and register vectors global.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 The fail stack, we grow to the maximum size when a regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800 is compiled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801 The register vectors, we adjust in size each time we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802 compile a regexp, according to the number of registers it needs. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 static fail_stack_type fail_stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 /* Size with which the following vectors are currently allocated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 That is so we can make them bigger as needed,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808 but never make them smaller. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809 static int regs_allocated_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1811 static const char ** regstart, ** regend;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1812 static const char ** old_regstart, ** old_regend;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1813 static const char **best_regstart, **best_regend;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814 static register_info_type *reg_info;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1815 static const char **reg_dummy;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 static register_info_type *reg_info_dummy;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1818 /* Make the register vectors big enough for NUM_REGS registers,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819 but don't make them smaller. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 static
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822 regex_grow_registers (int num_regs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 if (num_regs > regs_allocated_size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1826 RETALLOC_IF (regstart, num_regs, const char *);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1827 RETALLOC_IF (regend, num_regs, const char *);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1828 RETALLOC_IF (old_regstart, num_regs, const char *);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1829 RETALLOC_IF (old_regend, num_regs, const char *);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1830 RETALLOC_IF (best_regstart, num_regs, const char *);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1831 RETALLOC_IF (best_regend, num_regs, const char *);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 RETALLOC_IF (reg_info, num_regs, register_info_type);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1833 RETALLOC_IF (reg_dummy, num_regs, const char *);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834 RETALLOC_IF (reg_info_dummy, num_regs, register_info_type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 regs_allocated_size = num_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840 #endif /* not MATCH_MAY_ALLOCATE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1841
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 /* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843 Returns one of error codes defined in `regex.h', or zero for success.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1844
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 Assumes the `allocated' (and perhaps `buffer') and `translate'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846 fields are set in BUFP on entry.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848 If it succeeds, results are put in BUFP (if it returns an error, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 contents of BUFP are undefined):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850 `buffer' is the compiled pattern;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 `syntax' is set to SYNTAX;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852 `used' is set to the length of the compiled pattern;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853 `fastmap_accurate' is zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854 `re_nsub' is the number of subexpressions in PATTERN;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 `not_bol' and `not_eol' are zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 The `fastmap' and `newline_anchor' fields are neither
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 examined nor set. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 /* Return, freeing storage we allocated. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 #define FREE_STACK_RETURN(value) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862 return (free (compile_stack.stack), value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 static reg_errcode_t
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1865 regex_compile (const char *pattern, int size, reg_syntax_t syntax,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 struct re_pattern_buffer *bufp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 /* We fetch characters from PATTERN here. We declare these as int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869 (or possibly long) so that chars above 127 can be used as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 array indices. The macros that fetch a character from the pattern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 make sure to coerce to unsigned char before assigning, so we won't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 get bitten by negative numbers here. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 /* XEmacs change: used to be unsigned char. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 REGISTER EMACS_INT c, c1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 /* A random temporary spot in PATTERN. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1877 const char *p1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879 /* Points to the end of the buffer, where we should append. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 REGISTER unsigned char *b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 /* Keeps track of unclosed groups. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883 compile_stack_type compile_stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 /* Points to the current (ending) position in the pattern. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1886 const char *p = pattern;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1887 const char *pend = pattern + size;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 /* How to translate the characters in the pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 char *translate = bufp->translate;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 /* Address of the count-byte of the most recently inserted `exactn'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893 command. This makes it possible to tell if a new exact-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 character can be added to that command or if the character requires
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 a new `exactn' command. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 unsigned char *pending_exact = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 /* Address of start of the most recently finished expression.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 This tells, e.g., postfix * where to find the start of its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 operand. Reset at the beginning of groups and alternatives. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 unsigned char *laststart = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903 /* Address of beginning of regexp, or inside of last group. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904 unsigned char *begalt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906 /* Place in the uncompiled pattern (i.e., the {) to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 which to go back if the interval is invalid. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1908 const char *beg_interval;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 /* Address of the place where a forward jump should go to the end of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911 the containing expression. Each alternative of an `or' -- except the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 last -- ends with a forward jump of this sort. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 unsigned char *fixup_alt_jump = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 /* Counts open-groups as they are encountered. Remembered for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 matching close-group on the compile stack, so the same register
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917 number is put in the stop_memory as the start_memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918 regnum_t regnum = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 DEBUG_PRINT1 ("\nCompiling pattern: ");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 if (debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 unsigned debug_count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 for (debug_count = 0; debug_count < size; debug_count++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 putchar (pattern[debug_count]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928 putchar ('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1929 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930 #endif /* DEBUG */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 /* Initialize the compile stack. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933 compile_stack.stack = TALLOC (INIT_COMPILE_STACK_SIZE, compile_stack_elt_t);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 if (compile_stack.stack == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 return REG_ESPACE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937 compile_stack.size = INIT_COMPILE_STACK_SIZE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938 compile_stack.avail = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940 /* Initialize the pattern buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 bufp->syntax = syntax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942 bufp->fastmap_accurate = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943 bufp->not_bol = bufp->not_eol = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 /* Set `used' to zero, so that if we return an error, the pattern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946 printer (for debugging) will think there's no pattern. We reset it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 at the end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 bufp->used = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 /* Always count groups, whether or not bufp->no_sub is set. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 bufp->re_nsub = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953 #if !defined (emacs) && !defined (SYNTAX_TABLE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 /* Initialize the syntax table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 init_syntax_once ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 if (bufp->allocated == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1959 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 if (bufp->buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 { /* If zero allocated, but buffer is non-null, try to realloc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 enough space. This loses if buffer's address is bogus, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 that is the user's responsibility. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 RETALLOC (bufp->buffer, INIT_BUF_SIZE, unsigned char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 { /* Caller did not allocate a buffer. Do it for them. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 if (!bufp->buffer) FREE_STACK_RETURN (REG_ESPACE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 bufp->allocated = INIT_BUF_SIZE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1974
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975 begalt = b = bufp->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 /* Loop through the uncompiled pattern until we're at the end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 while (p != pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 switch (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984 case '^':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986 if ( /* If at start of pattern, it's an operator. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987 p == pattern + 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988 /* If context independent, it's an operator. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 || syntax & RE_CONTEXT_INDEP_ANCHORS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 /* Otherwise, depends on what's come before. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991 || at_begline_loc_p (pattern, p, syntax))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992 BUF_PUSH (begline);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1993 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1994 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1996 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1997
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1999 case '$':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2000 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2001 if ( /* If at end of pattern, it's an operator. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2002 p == pend
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2003 /* If context independent, it's an operator. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2004 || syntax & RE_CONTEXT_INDEP_ANCHORS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005 /* Otherwise, depends on what's next. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2006 || at_endline_loc_p (p, pend, syntax))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2007 BUF_PUSH (endline);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2008 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2009 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2010 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2011 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2012
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2013
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2014 case '+':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2015 case '?':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2016 if ((syntax & RE_BK_PLUS_QM)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2017 || (syntax & RE_LIMITED_OPS))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2018 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019 handle_plus:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020 case '*':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 /* If there is no previous pattern... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2022 if (!laststart)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2023 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2024 if (syntax & RE_CONTEXT_INVALID_OPS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2025 FREE_STACK_RETURN (REG_BADRPT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2026 else if (!(syntax & RE_CONTEXT_INDEP_OPS))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2027 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2028 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2029
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2030 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2031 /* true means zero/many matches are allowed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2032 boolean zero_times_ok = c != '+';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2033 boolean many_times_ok = c != '?';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2034
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2035 /* true means match shortest string possible. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2036 boolean minimal = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2037
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2038 /* If there is a sequence of repetition chars, collapse it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2039 down to just one (the right one). We can't combine
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040 interval operators with these because of, e.g., `a{2}*',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041 which should only match an even number of `a's. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2042 while (p != pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2043 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2044 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046 if (c == '*' || (!(syntax & RE_BK_PLUS_QM)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2047 && (c == '+' || c == '?')))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2048 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2049
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050 else if (syntax & RE_BK_PLUS_QM && c == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2052 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2053
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054 PATFETCH (c1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2055 if (!(c1 == '+' || c1 == '?'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2056 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057 PATUNFETCH;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2058 PATUNFETCH;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2061
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2062 c = c1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2063 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2064 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2065 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2066 PATUNFETCH;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2067 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2068 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2069
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2070 /* If we get here, we found another repeat character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2071 if (!(syntax & RE_NO_MINIMAL_MATCHING))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2072 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
2073 /* "*?" and "+?" and "??" are okay (and mean match
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
2074 minimally), but other sequences (such as "*??" and
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
2075 "+++") are rejected (reserved for future use). */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2076 if (minimal || c != '?')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2077 FREE_STACK_RETURN (REG_BADRPT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2078 minimal = true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2079 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2080 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2081 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2082 zero_times_ok |= c != '+';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2083 many_times_ok |= c != '?';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2084 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2085 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2086
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2087 /* Star, etc. applied to an empty pattern is equivalent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2088 to an empty pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2089 if (!laststart)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2090 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2091
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2092 /* Now we know whether zero matches is allowed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2093 and whether two or more matches is allowed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2094 and whether we want minimal or maximal matching. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2095 if (minimal)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2096 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2097 if (!many_times_ok)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2098 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2099 /* "a??" becomes:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2100 0: /on_failure_jump to 6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2101 3: /jump to 9
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2102 6: /exactn/1/A
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2103 9: end of pattern.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2104 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2105 GET_BUFFER_SPACE (6);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2106 INSERT_JUMP (jump, laststart, b + 3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2107 b += 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2108 INSERT_JUMP (on_failure_jump, laststart, laststart + 6);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2109 b += 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2110 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2111 else if (zero_times_ok)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2112 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2113 /* "a*?" becomes:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2114 0: /jump to 6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2115 3: /exactn/1/A
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2116 6: /on_failure_jump to 3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2117 9: end of pattern.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2118 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2119 GET_BUFFER_SPACE (6);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2120 INSERT_JUMP (jump, laststart, b + 3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2121 b += 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2122 STORE_JUMP (on_failure_jump, b, laststart + 3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2123 b += 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2124 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2125 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2126 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2127 /* "a+?" becomes:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2128 0: /exactn/1/A
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2129 3: /on_failure_jump to 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2130 6: end of pattern.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2131 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2132 GET_BUFFER_SPACE (3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2133 STORE_JUMP (on_failure_jump, b, laststart);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2134 b += 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2135 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2136 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2137 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2138 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2139 /* Are we optimizing this jump? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2140 boolean keep_string_p = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2142 if (many_times_ok)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2143 { /* More than one repetition is allowed, so put in at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2144 end a backward relative jump from `b' to before the next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2145 jump we're going to put in below (which jumps from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2146 laststart to after this jump).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 But if we are at the `*' in the exact sequence `.*\n',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2149 insert an unconditional jump backwards to the .,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150 instead of the beginning of the loop. This way we only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2151 push a failure point once, instead of every time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2152 through the loop. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2153 assert (p - 1 > pattern);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2155 /* Allocate the space for the jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2156 GET_BUFFER_SPACE (3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2157
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2158 /* We know we are not at the first character of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2159 pattern, because laststart was nonzero. And we've
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2160 already incremented `p', by the way, to be the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2161 character after the `*'. Do we have to do something
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2162 analogous here for null bytes, because of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2163 RE_DOT_NOT_NULL? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2164 if (TRANSLATE (*(p - 2)) == TRANSLATE ('.')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2165 && zero_times_ok
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2166 && p < pend && TRANSLATE (*p) == TRANSLATE ('\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2167 && !(syntax & RE_DOT_NEWLINE))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2168 { /* We have .*\n. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2169 STORE_JUMP (jump, b, laststart);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2170 keep_string_p = true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2171 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2172 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2173 /* Anything else. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2174 STORE_JUMP (maybe_pop_jump, b, laststart - 3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2175
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2176 /* We've added more stuff to the buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2177 b += 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2178 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2180 /* On failure, jump from laststart to b + 3, which will be the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2181 end of the buffer after this jump is inserted. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2182 GET_BUFFER_SPACE (3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2183 INSERT_JUMP (keep_string_p ? on_failure_keep_string_jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184 : on_failure_jump,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2185 laststart, b + 3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186 b += 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 if (!zero_times_ok)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2189 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2190 /* At least one repetition is required, so insert a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2191 `dummy_failure_jump' before the initial
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2192 `on_failure_jump' instruction of the loop. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2193 effects a skip over that instruction the first time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2194 we hit that loop. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2195 GET_BUFFER_SPACE (3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2196 INSERT_JUMP (dummy_failure_jump, laststart, laststart + 6);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197 b += 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2198 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2199 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2200 pending_exact = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2201 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2202 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2203
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 case '.':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2206 laststart = b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2207 BUF_PUSH (anychar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2208 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2210
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2211 case '[':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2212 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2213 /* XEmacs change: this whole section */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2214 boolean had_char_class = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2215 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2216 boolean has_extended_chars = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2217 REGISTER Lisp_Object rtab = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2218 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2220 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2222 /* Ensure that we have enough space to push a charset: the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2223 opcode, the length count, and the bitset; 34 bytes in all. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2224 GET_BUFFER_SPACE (34);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2226 laststart = b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2227
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2228 /* We test `*p == '^' twice, instead of using an if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2229 statement, so we only need one BUF_PUSH. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2230 BUF_PUSH (*p == '^' ? charset_not : charset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2231 if (*p == '^')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2232 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2233
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2234 /* Remember the first position in the bracket expression. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2235 p1 = p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2236
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2237 /* Push the number of bytes in the bitmap. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2238 BUF_PUSH ((1 << BYTEWIDTH) / BYTEWIDTH);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2239
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2240 /* Clear the whole map. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2241 memset (b, 0, (1 << BYTEWIDTH) / BYTEWIDTH);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2243 /* charset_not matches newline according to a syntax bit. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2244 if ((re_opcode_t) b[-2] == charset_not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245 && (syntax & RE_HAT_LISTS_NOT_NEWLINE))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2246 SET_LIST_BIT ('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2248 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2249 start_over_with_extended:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2250 if (has_extended_chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2251 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2252 /* There are extended chars here, which means we need to start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2253 over and shift to unified range-table format. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2254 if (b[-2] == charset)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2255 b[-2] = charset_mule;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2256 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2257 b[-2] = charset_mule_not;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2258 b--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2259 p = p1; /* go back to the beginning of the charset, after
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2260 a possible ^. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2261 rtab = Vthe_lisp_rangetab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2262 Fclear_range_table (rtab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2264 /* charset_not matches newline according to a syntax bit. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2265 if ((re_opcode_t) b[-1] == charset_mule_not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2266 && (syntax & RE_HAT_LISTS_NOT_NEWLINE))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2267 SET_EITHER_BIT ('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2268 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2269 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2270
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2271 /* Read in characters and ranges, setting map bits. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2272 for (;;)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2273 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2274 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2276 PATFETCH_EITHER (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2278 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2279 if (c >= 0x80 && !has_extended_chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2280 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2281 has_extended_chars = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2282 /* Frumble-bumble, we've found some extended chars.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2283 Need to start over, process everything using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2284 the general extended-char mechanism, and need
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2285 to use charset_mule and charset_mule_not instead
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2286 of charset and charset_not. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2287 goto start_over_with_extended;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2288 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2289 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2290 /* \ might escape characters inside [...] and [^...]. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2291 if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2292 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2294
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2295 PATFETCH_EITHER (c1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2297 if (c1 >= 0x80 && !has_extended_chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2298 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2299 has_extended_chars = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2300 goto start_over_with_extended;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2301 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2302 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2303 SET_EITHER_BIT (c1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2304 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2305 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2307 /* Could be the end of the bracket expression. If it's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2308 not (i.e., when the bracket expression is `[]' so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2309 far), the ']' character bit gets set way below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2310 if (c == ']' && p != p1 + 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2311 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2312
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2313 /* Look ahead to see if it's a range when the last thing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2314 was a character class. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2315 if (had_char_class && c == '-' && *p != ']')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2316 FREE_STACK_RETURN (REG_ERANGE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2318 /* Look ahead to see if it's a range when the last thing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2319 was a character: if this is a hyphen not at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2320 beginning or the end of a list, then it's the range
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2321 operator. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2322 if (c == '-'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2323 && !(p - 2 >= pattern && p[-2] == '[')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324 && !(p - 3 >= pattern && p[-3] == '[' && p[-2] == '^')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2325 && *p != ']')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2326 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2327 reg_errcode_t ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2329 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2330 if (* (unsigned char *) p >= 0x80 && !has_extended_chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2331 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2332 has_extended_chars = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2333 goto start_over_with_extended;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2334 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2335 if (has_extended_chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2336 ret = compile_extended_range (&p, pend, translate,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2337 syntax, rtab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2338 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2339 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2340 ret = compile_range (&p, pend, translate, syntax, b);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2341 if (ret != REG_NOERROR) FREE_STACK_RETURN (ret);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2342 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2343
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2344 else if (p[0] == '-' && p[1] != ']')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2345 { /* This handles ranges made up of characters only. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2346 reg_errcode_t ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2347
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2348 /* Move past the `-'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2349 PATFETCH (c1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2351 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2352 if (* (unsigned char *) p >= 0x80 && !has_extended_chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2353 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2354 has_extended_chars = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2355 goto start_over_with_extended;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2356 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2357 if (has_extended_chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2358 ret = compile_extended_range (&p, pend, translate,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2359 syntax, rtab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2360 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2361 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2362 ret = compile_range (&p, pend, translate, syntax, b);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2363 if (ret != REG_NOERROR) FREE_STACK_RETURN (ret);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2364 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2365
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2366 /* See if we're at the beginning of a possible character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2367 class. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2368
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2369 else if (syntax & RE_CHAR_CLASSES && c == '[' && *p == ':')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2370 { /* Leave room for the null. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2371 char str[CHAR_CLASS_MAX_LENGTH + 1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2372
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2373 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2374 c1 = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2376 /* If pattern is `[[:'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2377 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2379 for (;;)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2380 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2381 /* Do not do PATFETCH_EITHER() here. We want
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2382 to just see if the bytes match particular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2383 strings, and we put them all back if not.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2384
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2385 #### May need to be changed once trt tables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2386 are working. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2387 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2388 if (c == ':' || c == ']' || p == pend
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2389 || c1 == CHAR_CLASS_MAX_LENGTH)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2390 break;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2391 str[c1++] = (char) c;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2392 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2393 str[c1] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2395 /* If isn't a word bracketed by `[:' and:`]':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2396 undo the ending character, the letters, and leave
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2397 the leading `:' and `[' (but set bits for them). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2398 if (c == ':' && *p == ']')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2399 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2400 int ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2401 boolean is_alnum = STREQ (str, "alnum");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2402 boolean is_alpha = STREQ (str, "alpha");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2403 boolean is_blank = STREQ (str, "blank");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2404 boolean is_cntrl = STREQ (str, "cntrl");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2405 boolean is_digit = STREQ (str, "digit");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2406 boolean is_graph = STREQ (str, "graph");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2407 boolean is_lower = STREQ (str, "lower");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2408 boolean is_print = STREQ (str, "print");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2409 boolean is_punct = STREQ (str, "punct");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2410 boolean is_space = STREQ (str, "space");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2411 boolean is_upper = STREQ (str, "upper");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2412 boolean is_xdigit = STREQ (str, "xdigit");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2414 if (!IS_CHAR_CLASS (str))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2415 FREE_STACK_RETURN (REG_ECTYPE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2416
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2417 /* Throw away the ] at the end of the character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2418 class. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2419 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2421 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2422
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2423 for (ch = 0; ch < 1 << BYTEWIDTH; ch++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2424 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2425 /* This was split into 3 if's to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2426 avoid an arbitrary limit in some compiler. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2427 if ( (is_alnum && ISALNUM (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2428 || (is_alpha && ISALPHA (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2429 || (is_blank && ISBLANK (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2430 || (is_cntrl && ISCNTRL (ch)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2431 SET_EITHER_BIT (ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2432 if ( (is_digit && ISDIGIT (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2433 || (is_graph && ISGRAPH (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2434 || (is_lower && ISLOWER (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2435 || (is_print && ISPRINT (ch)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2436 SET_EITHER_BIT (ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2437 if ( (is_punct && ISPUNCT (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2438 || (is_space && ISSPACE (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2439 || (is_upper && ISUPPER (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2440 || (is_xdigit && ISXDIGIT (ch)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2441 SET_EITHER_BIT (ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2442 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2443 had_char_class = true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2444 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2445 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2446 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2447 c1++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2448 while (c1--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2449 PATUNFETCH;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2450 SET_EITHER_BIT ('[');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2451 SET_EITHER_BIT (':');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2452 had_char_class = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2453 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2454 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2455 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2456 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2457 had_char_class = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2458 SET_EITHER_BIT (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2459 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2460 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2461
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2462 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2463 if (has_extended_chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2464 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2465 /* We have a range table, not a bit vector. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2466 int bytes_needed =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2467 unified_range_table_bytes_needed (rtab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2468 GET_BUFFER_SPACE (bytes_needed);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2469 unified_range_table_copy_data (rtab, b);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2470 b += unified_range_table_bytes_used (b);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2471 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2472 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2473 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2474 /* Discard any (non)matching list bytes that are all 0 at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2475 end of the map. Decrease the map-length byte too. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2476 while ((int) b[-1] > 0 && b[b[-1] - 1] == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2477 b[-1]--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2478 b += b[-1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2479 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2480 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2481
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2483 case '(':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2484 if (syntax & RE_NO_BK_PARENS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2485 goto handle_open;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2486 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2487 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2489
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2490 case ')':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2491 if (syntax & RE_NO_BK_PARENS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2492 goto handle_close;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2493 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2494 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2495
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2496
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2497 case '\n':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2498 if (syntax & RE_NEWLINE_ALT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2499 goto handle_alt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2500 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2501 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2502
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2503
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2504 case '|':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2505 if (syntax & RE_NO_BK_VBAR)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2506 goto handle_alt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2507 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2508 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2510
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2511 case '{':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2512 if (syntax & RE_INTERVALS && syntax & RE_NO_BK_BRACES)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2513 goto handle_interval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2514 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2515 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2516
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2517
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2518 case '\\':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2519 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2520
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2521 /* Do not translate the character after the \, so that we can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2522 distinguish, e.g., \B from \b, even if we normally would
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2523 translate, e.g., B to b. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2524 PATFETCH_RAW (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2525
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2526 switch (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2527 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2528 case '(':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2529 if (syntax & RE_NO_BK_PARENS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2530 goto normal_backslash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2531
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2532 handle_open:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2533 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2534 regnum_t r;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2535
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2536 if (!(syntax & RE_NO_SHY_GROUPS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2537 && p != pend
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2538 && TRANSLATE(*p) == TRANSLATE('?'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2539 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2540 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2541 PATFETCH(c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2542 switch (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2543 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2544 case ':': /* shy groups */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2545 r = MAX_REGNUM + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2546 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2547
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2548 /* All others are reserved for future constructs. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2549 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2550 FREE_STACK_RETURN (REG_BADPAT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2551 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2552 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2553 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2554 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2555 bufp->re_nsub++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2556 r = ++regnum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2557 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2558
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2559 if (COMPILE_STACK_FULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2560 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2561 RETALLOC (compile_stack.stack, compile_stack.size << 1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2562 compile_stack_elt_t);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2563 if (compile_stack.stack == NULL) return REG_ESPACE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2565 compile_stack.size <<= 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2566 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2567
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2568 /* These are the values to restore when we hit end of this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2569 group. They are all relative offsets, so that if the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2570 whole pattern moves because of realloc, they will still
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2571 be valid. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2572 COMPILE_STACK_TOP.begalt_offset = begalt - bufp->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2573 COMPILE_STACK_TOP.fixup_alt_jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2574 = fixup_alt_jump ? fixup_alt_jump - bufp->buffer + 1 : 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2575 COMPILE_STACK_TOP.laststart_offset = b - bufp->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2576 COMPILE_STACK_TOP.regnum = r;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2577
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2578 /* We will eventually replace the 0 with the number of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2579 groups inner to this one. But do not push a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2580 start_memory for groups beyond the last one we can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2581 represent in the compiled pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2582 if (r <= MAX_REGNUM)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2583 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2584 COMPILE_STACK_TOP.inner_group_offset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2585 = b - bufp->buffer + 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2586 BUF_PUSH_3 (start_memory, r, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2587 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2588
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2589 compile_stack.avail++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2590
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2591 fixup_alt_jump = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2592 laststart = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2593 begalt = b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2594 /* If we've reached MAX_REGNUM groups, then this open
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2595 won't actually generate any code, so we'll have to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2596 clear pending_exact explicitly. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2597 pending_exact = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2598 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2599 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2600
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2601
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2602 case ')':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2603 if (syntax & RE_NO_BK_PARENS) goto normal_backslash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2605 if (COMPILE_STACK_EMPTY) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2606 if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2607 goto normal_backslash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2608 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2609 FREE_STACK_RETURN (REG_ERPAREN);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2610 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2611
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2612 handle_close:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2613 if (fixup_alt_jump)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2614 { /* Push a dummy failure point at the end of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2615 alternative for a possible future
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2616 `pop_failure_jump' to pop. See comments at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2617 `push_dummy_failure' in `re_match_2'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2618 BUF_PUSH (push_dummy_failure);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2619
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2620 /* We allocated space for this jump when we assigned
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2621 to `fixup_alt_jump', in the `handle_alt' case below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2622 STORE_JUMP (jump_past_alt, fixup_alt_jump, b - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2623 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2624
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2625 /* See similar code for backslashed left paren above. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2626 if (COMPILE_STACK_EMPTY) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2627 if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2628 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2629 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2630 FREE_STACK_RETURN (REG_ERPAREN);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2631 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2632
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2633 /* Since we just checked for an empty stack above, this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2634 ``can't happen''. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2635 assert (compile_stack.avail != 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2636 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2637 /* We don't just want to restore into `regnum', because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2638 later groups should continue to be numbered higher,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2639 as in `(ab)c(de)' -- the second group is #2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2640 regnum_t this_group_regnum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2642 compile_stack.avail--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643 begalt = bufp->buffer + COMPILE_STACK_TOP.begalt_offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2644 fixup_alt_jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2645 = COMPILE_STACK_TOP.fixup_alt_jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2646 ? bufp->buffer + COMPILE_STACK_TOP.fixup_alt_jump - 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2647 : 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2648 laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2649 this_group_regnum = COMPILE_STACK_TOP.regnum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2650 /* If we've reached MAX_REGNUM groups, then this open
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2651 won't actually generate any code, so we'll have to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2652 clear pending_exact explicitly. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2653 pending_exact = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2654
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2655 /* We're at the end of the group, so now we know how many
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2656 groups were inside this one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2657 if (this_group_regnum <= MAX_REGNUM)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2658 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2659 unsigned char *inner_group_loc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2660 = bufp->buffer + COMPILE_STACK_TOP.inner_group_offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2661
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2662 *inner_group_loc = regnum - this_group_regnum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2663 BUF_PUSH_3 (stop_memory, this_group_regnum,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2664 regnum - this_group_regnum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2665 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2666 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2667 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2669
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2670 case '|': /* `\|'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2671 if (syntax & RE_LIMITED_OPS || syntax & RE_NO_BK_VBAR)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2672 goto normal_backslash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2673 handle_alt:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2674 if (syntax & RE_LIMITED_OPS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2675 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2676
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2677 /* Insert before the previous alternative a jump which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2678 jumps to this alternative if the former fails. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2679 GET_BUFFER_SPACE (3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2680 INSERT_JUMP (on_failure_jump, begalt, b + 6);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2681 pending_exact = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2682 b += 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2683
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2684 /* The alternative before this one has a jump after it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2685 which gets executed if it gets matched. Adjust that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2686 jump so it will jump to this alternative's analogous
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2687 jump (put in below, which in turn will jump to the next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2688 (if any) alternative's such jump, etc.). The last such
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2689 jump jumps to the correct final destination. A picture:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2690 _____ _____
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2691 | | | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2692 | v | v
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2693 a | b | c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2694
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2695 If we are at `b', then fixup_alt_jump right now points to a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2696 three-byte space after `a'. We'll put in the jump, set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2697 fixup_alt_jump to right after `b', and leave behind three
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2698 bytes which we'll fill in when we get to after `c'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2699
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2700 if (fixup_alt_jump)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2701 STORE_JUMP (jump_past_alt, fixup_alt_jump, b);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2702
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2703 /* Mark and leave space for a jump after this alternative,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2704 to be filled in later either by next alternative or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2705 when know we're at the end of a series of alternatives. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2706 fixup_alt_jump = b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2707 GET_BUFFER_SPACE (3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2708 b += 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2709
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2710 laststart = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2711 begalt = b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2712 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2713
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2714
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2715 case '{':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2716 /* If \{ is a literal. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2717 if (!(syntax & RE_INTERVALS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2718 /* If we're at `\{' and it's not the open-interval
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2719 operator. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2720 || ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2721 || (p - 2 == pattern && p == pend))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2722 goto normal_backslash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2723
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2724 handle_interval:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2725 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2726 /* If got here, then the syntax allows intervals. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2727
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2728 /* At least (most) this many matches must be made. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2729 int lower_bound = -1, upper_bound = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2731 beg_interval = p - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2732
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2733 if (p == pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2734 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2735 if (syntax & RE_NO_BK_BRACES)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2736 goto unfetch_interval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2737 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2738 FREE_STACK_RETURN (REG_EBRACE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2739 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2740
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2741 GET_UNSIGNED_NUMBER (lower_bound);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2742
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2743 if (c == ',')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2744 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2745 GET_UNSIGNED_NUMBER (upper_bound);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2746 if (upper_bound < 0) upper_bound = RE_DUP_MAX;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2747 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2748 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2749 /* Interval such as `{1}' => match exactly once. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2750 upper_bound = lower_bound;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2751
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2752 if (lower_bound < 0 || upper_bound > RE_DUP_MAX
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2753 || lower_bound > upper_bound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2754 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2755 if (syntax & RE_NO_BK_BRACES)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2756 goto unfetch_interval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2757 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2758 FREE_STACK_RETURN (REG_BADBR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2759 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2760
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2761 if (!(syntax & RE_NO_BK_BRACES))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2762 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2763 if (c != '\\') FREE_STACK_RETURN (REG_EBRACE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2764
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2765 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2766 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2767
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2768 if (c != '}')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2769 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2770 if (syntax & RE_NO_BK_BRACES)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2771 goto unfetch_interval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2772 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2773 FREE_STACK_RETURN (REG_BADBR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2774 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2775
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2776 /* We just parsed a valid interval. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2777
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2778 /* If it's invalid to have no preceding re. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2779 if (!laststart)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2780 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2781 if (syntax & RE_CONTEXT_INVALID_OPS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2782 FREE_STACK_RETURN (REG_BADRPT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2783 else if (syntax & RE_CONTEXT_INDEP_OPS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2784 laststart = b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2785 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2786 goto unfetch_interval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2787 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2788
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2789 /* If the upper bound is zero, don't want to succeed at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2790 all; jump from `laststart' to `b + 3', which will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2791 the end of the buffer after we insert the jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2792 if (upper_bound == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2793 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2794 GET_BUFFER_SPACE (3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2795 INSERT_JUMP (jump, laststart, b + 3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2796 b += 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2797 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2798
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2799 /* Otherwise, we have a nontrivial interval. When
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2800 we're all done, the pattern will look like:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2801 set_number_at <jump count> <upper bound>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2802 set_number_at <succeed_n count> <lower bound>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2803 succeed_n <after jump addr> <succeed_n count>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2804 <body of loop>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2805 jump_n <succeed_n addr> <jump count>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2806 (The upper bound and `jump_n' are omitted if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2807 `upper_bound' is 1, though.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2808 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2809 { /* If the upper bound is > 1, we need to insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2810 more at the end of the loop. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2811 unsigned nbytes = 10 + (upper_bound > 1) * 10;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2812
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2813 GET_BUFFER_SPACE (nbytes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2814
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2815 /* Initialize lower bound of the `succeed_n', even
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2816 though it will be set during matching by its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2817 attendant `set_number_at' (inserted next),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2818 because `re_compile_fastmap' needs to know.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2819 Jump to the `jump_n' we might insert below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2820 INSERT_JUMP2 (succeed_n, laststart,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2821 b + 5 + (upper_bound > 1) * 5,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2822 lower_bound);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2823 b += 5;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2824
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2825 /* Code to initialize the lower bound. Insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2826 before the `succeed_n'. The `5' is the last two
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2827 bytes of this `set_number_at', plus 3 bytes of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2828 the following `succeed_n'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2829 insert_op2 (set_number_at, laststart, 5, lower_bound, b);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2830 b += 5;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2831
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2832 if (upper_bound > 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2833 { /* More than one repetition is allowed, so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2834 append a backward jump to the `succeed_n'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2835 that starts this interval.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2836
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2837 When we've reached this during matching,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2838 we'll have matched the interval once, so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2839 jump back only `upper_bound - 1' times. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2840 STORE_JUMP2 (jump_n, b, laststart + 5,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2841 upper_bound - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2842 b += 5;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2843
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2844 /* The location we want to set is the second
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2845 parameter of the `jump_n'; that is `b-2' as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2846 an absolute address. `laststart' will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2847 the `set_number_at' we're about to insert;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2848 `laststart+3' the number to set, the source
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2849 for the relative address. But we are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2850 inserting into the middle of the pattern --
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2851 so everything is getting moved up by 5.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2852 Conclusion: (b - 2) - (laststart + 3) + 5,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2853 i.e., b - laststart.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2854
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2855 We insert this at the beginning of the loop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2856 so that if we fail during matching, we'll
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2857 reinitialize the bounds. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2858 insert_op2 (set_number_at, laststart, b - laststart,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2859 upper_bound - 1, b);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2860 b += 5;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2861 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2862 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2863 pending_exact = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2864 beg_interval = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2865 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2866 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2867
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2868 unfetch_interval:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2869 /* If an invalid interval, match the characters as literals. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2870 assert (beg_interval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2871 p = beg_interval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2872 beg_interval = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2873
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2874 /* normal_char and normal_backslash need `c'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2875 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2876
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2877 if (!(syntax & RE_NO_BK_BRACES))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2878 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2879 if (p > pattern && p[-1] == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2880 goto normal_backslash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2881 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2882 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2883
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2884 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2885 /* There is no way to specify the before_dot and after_dot
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2886 operators. rms says this is ok. --karl */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2887 case '=':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2888 BUF_PUSH (at_dot);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2889 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2890
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2891 case 's':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2892 laststart = b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2893 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2894 /* XEmacs addition */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2895 if (c >= 0x80 || syntax_spec_code[c] == 0377)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2896 FREE_STACK_RETURN (REG_ESYNTAX);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2897 BUF_PUSH_2 (syntaxspec, syntax_spec_code[c]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2898 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2899
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2900 case 'S':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2901 laststart = b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2902 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2903 /* XEmacs addition */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2904 if (c >= 0x80 || syntax_spec_code[c] == 0377)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2905 FREE_STACK_RETURN (REG_ESYNTAX);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2906 BUF_PUSH_2 (notsyntaxspec, syntax_spec_code[c]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2907 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2908
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2909 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2910 /* 97.2.17 jhod merged in to XEmacs from mule-2.3 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2911 case 'c':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2912 laststart = b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2913 PATFETCH_RAW (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 if (c < 32 || c > 127)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2915 FREE_STACK_RETURN (REG_ECATEGORY);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2916 BUF_PUSH_2 (categoryspec, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2917 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2918
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2919 case 'C':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2920 laststart = b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2921 PATFETCH_RAW (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2922 if (c < 32 || c > 127)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2923 FREE_STACK_RETURN (REG_ECATEGORY);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2924 BUF_PUSH_2 (notcategoryspec, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2925 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2926 /* end of category patch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2927 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2928 #endif /* emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2929
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2930
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2931 case 'w':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2932 laststart = b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2933 BUF_PUSH (wordchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2934 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2935
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2937 case 'W':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2938 laststart = b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2939 BUF_PUSH (notwordchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2940 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2941
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2942
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2943 case '<':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2944 BUF_PUSH (wordbeg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2945 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2946
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2947 case '>':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2948 BUF_PUSH (wordend);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2949 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2950
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2951 case 'b':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2952 BUF_PUSH (wordbound);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2953 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2954
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2955 case 'B':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2956 BUF_PUSH (notwordbound);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2957 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2958
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2959 case '`':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2960 BUF_PUSH (begbuf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2961 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2962
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2963 case '\'':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2964 BUF_PUSH (endbuf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2965 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2966
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2967 case '1': case '2': case '3': case '4': case '5':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2968 case '6': case '7': case '8': case '9':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2969 if (syntax & RE_NO_BK_REFS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2970 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2971
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2972 c1 = c - '0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2973
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2974 if (c1 > regnum)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2975 FREE_STACK_RETURN (REG_ESUBREG);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2976
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977 /* Can't back reference to a subexpression if inside of it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2978 if (group_in_compile_stack (compile_stack, c1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2980
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2981 laststart = b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982 BUF_PUSH_2 (duplicate, c1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2983 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2984
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2985
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2986 case '+':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2987 case '?':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2988 if (syntax & RE_BK_PLUS_QM)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989 goto handle_plus;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2990 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2991 goto normal_backslash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2992
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2993 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2994 normal_backslash:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2995 /* You might think it would be useful for \ to mean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2996 not to translate; but if we don't translate it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2997 it will never match anything. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2998 c = TRANSLATE (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2999 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3000 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3001 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3003
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3004 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3005 /* Expects the character in `c'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3006 /* `p' points to the location after where `c' came from. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3007 normal_char:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3008 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3009 /* XEmacs: modifications here for Mule. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3010 /* `q' points to the beginning of the next char. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3011 const char *q = p - 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012 INC_CHARPTR (q);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3013
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3014 /* If no exactn currently being built. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3015 if (!pending_exact
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3016
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3017 /* If last exactn not at current position. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3018 || pending_exact + *pending_exact + 1 != b
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3019
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3020 /* We have only one byte following the exactn for the count. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3021 || ((unsigned int) (*pending_exact + (q - p)) >=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3022 ((unsigned int) (1 << BYTEWIDTH) - 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3023
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3024 /* If followed by a repetition operator. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3025 || *q == '*' || *q == '^'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3026 || ((syntax & RE_BK_PLUS_QM)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3027 ? *q == '\\' && (q[1] == '+' || q[1] == '?')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3028 : (*q == '+' || *q == '?'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3029 || ((syntax & RE_INTERVALS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3030 && ((syntax & RE_NO_BK_BRACES)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3031 ? *q == '{'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3032 : (q[0] == '\\' && q[1] == '{'))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3033 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3034 /* Start building a new exactn. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3035
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3036 laststart = b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3037
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3038 BUF_PUSH_2 (exactn, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3039 pending_exact = b - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3040 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3041
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3042 BUF_PUSH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3043 (*pending_exact)++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3044
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3045 while (p < q)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3046 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3047 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3048 BUF_PUSH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3049 (*pending_exact)++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3050 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3051 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3052 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3053 } /* switch (c) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3054 } /* while p != pend */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3055
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3056
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3057 /* Through the pattern now. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3058
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3059 if (fixup_alt_jump)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3060 STORE_JUMP (jump_past_alt, fixup_alt_jump, b);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3061
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3062 if (!COMPILE_STACK_EMPTY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3063 FREE_STACK_RETURN (REG_EPAREN);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3064
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3065 /* If we don't want backtracking, force success
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3066 the first time we reach the end of the compiled pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3067 if (syntax & RE_NO_POSIX_BACKTRACKING)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3068 BUF_PUSH (succeed);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3069
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3070 free (compile_stack.stack);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3071
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3072 /* We have succeeded; set the length of the buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3073 bufp->used = b - bufp->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3074
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3075 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3076 if (debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3077 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3078 DEBUG_PRINT1 ("\nCompiled pattern: \n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3079 print_compiled_pattern (bufp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3080 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3081 #endif /* DEBUG */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3082
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3083 #ifndef MATCH_MAY_ALLOCATE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3084 /* Initialize the failure stack to the largest possible stack. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3085 isn't necessary unless we're trying to avoid calling alloca in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3086 the search and match routines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3087 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3088 int num_regs = bufp->re_nsub + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3089
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3090 /* Since DOUBLE_FAIL_STACK refuses to double only if the current size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3091 is strictly greater than re_max_failures, the largest possible stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3092 is 2 * re_max_failures failure points. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3093 if (fail_stack.size < (2 * re_max_failures * MAX_FAILURE_ITEMS))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3094 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3095 fail_stack.size = (2 * re_max_failures * MAX_FAILURE_ITEMS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3096
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3097 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3098 if (! fail_stack.stack)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3099 fail_stack.stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3100 = (fail_stack_elt_t *) xmalloc (fail_stack.size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3101 * sizeof (fail_stack_elt_t));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3102 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3103 fail_stack.stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3104 = (fail_stack_elt_t *) xrealloc (fail_stack.stack,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3105 (fail_stack.size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3106 * sizeof (fail_stack_elt_t)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3107 #else /* not emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3108 if (! fail_stack.stack)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3109 fail_stack.stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3110 = (fail_stack_elt_t *) malloc (fail_stack.size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3111 * sizeof (fail_stack_elt_t));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3112 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3113 fail_stack.stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3114 = (fail_stack_elt_t *) realloc (fail_stack.stack,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3115 (fail_stack.size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3116 * sizeof (fail_stack_elt_t)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3117 #endif /* not emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3118 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3120 regex_grow_registers (num_regs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3121 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3122 #endif /* not MATCH_MAY_ALLOCATE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3124 return REG_NOERROR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3125 } /* regex_compile */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3127 /* Subroutines for `regex_compile'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3129 /* Store OP at LOC followed by two-byte integer parameter ARG. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3130
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3131 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3132 store_op1 (re_opcode_t op, unsigned char *loc, int arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3133 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3134 *loc = (unsigned char) op;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3135 STORE_NUMBER (loc + 1, arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3136 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3139 /* Like `store_op1', but for two two-byte parameters ARG1 and ARG2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3140
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3141 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3142 store_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3143 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3144 *loc = (unsigned char) op;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3145 STORE_NUMBER (loc + 1, arg1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3146 STORE_NUMBER (loc + 3, arg2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3147 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3149
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3150 /* Copy the bytes from LOC to END to open up three bytes of space at LOC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3151 for OP followed by two-byte integer parameter ARG. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3152
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3153 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3154 insert_op1 (re_opcode_t op, unsigned char *loc, int arg, unsigned char *end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3155 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3156 REGISTER unsigned char *pfrom = end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3157 REGISTER unsigned char *pto = end + 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3159 while (pfrom != loc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3160 *--pto = *--pfrom;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3161
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3162 store_op1 (op, loc, arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3163 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3166 /* Like `insert_op1', but for two two-byte parameters ARG1 and ARG2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3168 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3169 insert_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3170 unsigned char *end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3171 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3172 REGISTER unsigned char *pfrom = end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3173 REGISTER unsigned char *pto = end + 5;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3175 while (pfrom != loc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3176 *--pto = *--pfrom;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3177
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3178 store_op2 (op, loc, arg1, arg2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3179 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3182 /* P points to just after a ^ in PATTERN. Return true if that ^ comes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3183 after an alternative or a begin-subexpression. We assume there is at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3184 least one character before the ^. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3186 static boolean
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3187 at_begline_loc_p (const char *pattern, const char *p, reg_syntax_t syntax)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3188 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3189 const char *prev = p - 2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3190 boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3192 return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3193 /* After a subexpression? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3194 (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3195 /* After an alternative? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3196 || (*prev == '|' && (syntax & RE_NO_BK_VBAR || prev_prev_backslash));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3197 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3200 /* The dual of at_begline_loc_p. This one is for $. We assume there is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3201 at least one character after the $, i.e., `P < PEND'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3202
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3203 static boolean
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3204 at_endline_loc_p (const char *p, const char *pend, int syntax)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3205 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3206 const char *next = p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3207 boolean next_backslash = *next == '\\';
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3208 const char *next_next = p + 1 < pend ? p + 1 : 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3210 return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3211 /* Before a subexpression? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3212 (syntax & RE_NO_BK_PARENS ? *next == ')'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3213 : next_backslash && next_next && *next_next == ')')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3214 /* Before an alternative? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3215 || (syntax & RE_NO_BK_VBAR ? *next == '|'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3216 : next_backslash && next_next && *next_next == '|');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3217 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3220 /* Returns true if REGNUM is in one of COMPILE_STACK's elements and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3221 false if it's not. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3223 static boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3224 group_in_compile_stack (compile_stack_type compile_stack, regnum_t regnum)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3225 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3226 int this_element;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3227
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3228 for (this_element = compile_stack.avail - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3229 this_element >= 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3230 this_element--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3231 if (compile_stack.stack[this_element].regnum == regnum)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3232 return true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3233
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3234 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3235 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3236
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3237
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3238 /* Read the ending character of a range (in a bracket expression) from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3239 uncompiled pattern *P_PTR (which ends at PEND). We assume the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3240 starting character is in `P[-2]'. (`P[-1]' is the character `-'.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3241 Then we set the translation of all bits between the starting and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3242 ending characters (inclusive) in the compiled pattern B.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3244 Return an error code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3246 We use these short variable names so we can use the same macros as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3247 `regex_compile' itself. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3248
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3249 static reg_errcode_t
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3250 compile_range (const char **p_ptr, const char *pend, char *translate,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3251 reg_syntax_t syntax, unsigned char *b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3252 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3253 unsigned this_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3254
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3255 const char *p = *p_ptr;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3256 int range_start, range_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3258 if (p == pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3259 return REG_ERANGE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3260
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3261 /* Even though the pattern is a signed `char *', we need to fetch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3262 with unsigned char *'s; if the high bit of the pattern character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3263 is set, the range endpoints will be negative if we fetch using a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3264 signed char *.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3266 We also want to fetch the endpoints without translating them; the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3267 appropriate translation is done in the bit-setting loop below. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3268 /* The SVR4 compiler on the 3B2 had trouble with unsigned const char *. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3269 range_start = ((const unsigned char *) p)[-2];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3270 range_end = ((const unsigned char *) p)[0];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3272 /* Have to increment the pointer into the pattern string, so the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3273 caller isn't still at the ending character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3274 (*p_ptr)++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3276 /* If the start is after the end, the range is empty. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3277 if (range_start > range_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3278 return syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3280 /* Here we see why `this_char' has to be larger than an `unsigned
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3281 char' -- the range is inclusive, so if `range_end' == 0xff
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3282 (assuming 8-bit characters), we would otherwise go into an infinite
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3283 loop, since all characters <= 0xff. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3284 for (this_char = range_start; this_char <= range_end; this_char++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3285 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3286 SET_LIST_BIT (TRANSLATE (this_char));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3287 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3288
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3289 return REG_NOERROR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3290 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3291
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3292 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3294 static reg_errcode_t
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3295 compile_extended_range (const char **p_ptr, const char *pend, char *translate,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3296 reg_syntax_t syntax, Lisp_Object rtab)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3297 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3298 Emchar this_char, range_start, range_end;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3299 const Bufbyte *p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3300
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3301 if (*p_ptr == pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3302 return REG_ERANGE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3303
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3304 p = (const Bufbyte *) *p_ptr;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3305 range_end = charptr_emchar (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3306 p--; /* back to '-' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3307 DEC_CHARPTR (p); /* back to start of range */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3308 /* We also want to fetch the endpoints without translating them; the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3309 appropriate translation is done in the bit-setting loop below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3310 range_start = charptr_emchar (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3311 INC_CHARPTR (*p_ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3312
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3313 /* If the start is after the end, the range is empty. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3314 if (range_start > range_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3315 return syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3316
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3317 /* Can't have ranges spanning different charsets, except maybe for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3318 ranges entirely within the first 256 chars. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3320 if ((range_start >= 0x100 || range_end >= 0x100)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3321 && CHAR_LEADING_BYTE (range_start) !=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3322 CHAR_LEADING_BYTE (range_end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3323 return REG_ERANGESPAN;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3324
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3325 /* As advertised, translations only work over the 0 - 0x7F range.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3326 Making this kind of stuff work generally is much harder.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3327 Iterating over the whole range like this would be way efficient
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3328 if the range encompasses 10,000 chars or something. You'd have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3329 to do something like this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3330
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3331 range_table a;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3332 range_table b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3333 map over translation table in [range_start, range_end] of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3334 (put the mapped range in a;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3335 put the translation in b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3336 invert the range in a and truncate to [range_start, range_end]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3337 compute the union of a, b
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3338 union the result into rtab
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3339 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3340 for (this_char = range_start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3341 this_char <= range_end && this_char < 0x80; this_char++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3342 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3343 SET_RANGETAB_BIT (TRANSLATE (this_char));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3344 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3345
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3346 if (this_char <= range_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3347 put_range_table (rtab, this_char, range_end, Qt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3348
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3349 return REG_NOERROR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3350 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3351
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3352 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3353
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3354 /* re_compile_fastmap computes a ``fastmap'' for the compiled pattern in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3355 BUFP. A fastmap records which of the (1 << BYTEWIDTH) possible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3356 characters can start a string that matches the pattern. This fastmap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3357 is used by re_search to skip quickly over impossible starting points.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3358
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3359 The caller must supply the address of a (1 << BYTEWIDTH)-byte data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3360 area as BUFP->fastmap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3361
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3362 We set the `fastmap', `fastmap_accurate', and `can_be_null' fields in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3363 the pattern buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3364
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3365 Returns 0 if we succeed, -2 if an internal error. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3367 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3368 re_compile_fastmap (struct re_pattern_buffer *bufp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3369 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3370 int j, k;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3371 #ifdef MATCH_MAY_ALLOCATE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3372 fail_stack_type fail_stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3373 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3374 DECLARE_DESTINATION
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3375 /* We don't push any register information onto the failure stack. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3376
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3377 REGISTER char *fastmap = bufp->fastmap;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3378 unsigned char *pattern = bufp->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3379 unsigned long size = bufp->used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3380 unsigned char *p = pattern;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3381 REGISTER unsigned char *pend = pattern + size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3382
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3383 #ifdef REL_ALLOC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3384 /* This holds the pointer to the failure stack, when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3385 it is allocated relocatably. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3386 fail_stack_elt_t *failure_stack_ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3387 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3388
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3389 /* Assume that each path through the pattern can be null until
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3390 proven otherwise. We set this false at the bottom of switch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3391 statement, to which we get only if a particular path doesn't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3392 match the empty string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3393 boolean path_can_be_null = true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3395 /* We aren't doing a `succeed_n' to begin with. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3396 boolean succeed_n_p = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3397
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3398 assert (fastmap != NULL && p != NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3399
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3400 INIT_FAIL_STACK ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3401 memset (fastmap, 0, 1 << BYTEWIDTH); /* Assume nothing's valid. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3402 bufp->fastmap_accurate = 1; /* It will be when we're done. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3403 bufp->can_be_null = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3405 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3406 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3407 if (p == pend || *p == succeed)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3408 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3409 /* We have reached the (effective) end of pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3410 if (!FAIL_STACK_EMPTY ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3411 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3412 bufp->can_be_null |= path_can_be_null;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3414 /* Reset for next path. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3415 path_can_be_null = true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3416
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3417 p = fail_stack.stack[--fail_stack.avail].pointer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3419 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3420 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3421 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3422 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3423 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3424
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3425 /* We should never be about to go beyond the end of the pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3426 assert (p < pend);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3427
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3428 switch (SWITCH_ENUM_CAST ((re_opcode_t) *p++))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3429 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3430
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3431 /* I guess the idea here is to simply not bother with a fastmap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3432 if a backreference is used, since it's too hard to figure out
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3433 the fastmap for the corresponding group. Setting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3434 `can_be_null' stops `re_search_2' from using the fastmap, so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3435 that is all we do. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3436 case duplicate:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3437 bufp->can_be_null = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3438 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3439
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3440
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3441 /* Following are the cases which match a character. These end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3442 with `break'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3443
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3444 case exactn:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3445 fastmap[p[1]] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3446 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3447
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3449 case charset:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3450 /* XEmacs: Under Mule, these bit vectors will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3451 only contain values for characters below 0x80. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3452 for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3453 if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3454 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3455 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3456
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3457
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3458 case charset_not:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3459 /* Chars beyond end of map must be allowed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3460 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3461 for (j = *p * BYTEWIDTH; j < 0x80; j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3462 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3463 /* And all extended characters must be allowed, too. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3464 for (j = 0x80; j < 0xA0; j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3465 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3466 #else /* ! MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3467 for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3468 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3469 #endif /* ! MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3470
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3471 for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3472 if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3473 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3474 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3475
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3476 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3477 case charset_mule:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3478 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3479 int nentries;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3480 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3481
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3482 nentries = unified_range_table_nentries (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3483 for (i = 0; i < nentries; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3484 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3485 EMACS_INT first, last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3486 Lisp_Object dummy_val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3487 int jj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3488 Bufbyte strr[MAX_EMCHAR_LEN];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3489
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3490 unified_range_table_get_range (p, i, &first, &last,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3491 &dummy_val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3492 for (jj = first; jj <= last && jj < 0x80; jj++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3493 fastmap[jj] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3494 /* Ranges below 0x100 can span charsets, but there
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3495 are only two (Control-1 and Latin-1), and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3496 either first or last has to be in them. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3497 set_charptr_emchar (strr, first);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3498 fastmap[*strr] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3499 if (last < 0x100)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3500 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3501 set_charptr_emchar (strr, last);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3502 fastmap[*strr] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3503 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3504 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3505 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3506 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3507
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3508 case charset_mule_not:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3509 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3510 int nentries;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3511 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3512
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3513 nentries = unified_range_table_nentries (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3514 for (i = 0; i < nentries; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3515 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3516 EMACS_INT first, last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3517 Lisp_Object dummy_val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3518 int jj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3519 int smallest_prev = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3520
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3521 unified_range_table_get_range (p, i, &first, &last,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3522 &dummy_val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3523 for (jj = smallest_prev; jj < first && jj < 0x80; jj++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3524 fastmap[jj] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3525 smallest_prev = last + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3526 if (smallest_prev >= 0x80)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3527 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3528 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3529 /* Calculating which leading bytes are actually allowed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3530 here is rather difficult, so we just punt and allow
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3531 all of them. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3532 for (i = 0x80; i < 0xA0; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3533 fastmap[i] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3534 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3535 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3536 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3537
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3538
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3539 case wordchar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3540 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3541 k = (int) Sword;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3542 goto matchsyntax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3543 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3544 for (j = 0; j < (1 << BYTEWIDTH); j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3545 if (SYNTAX_UNSAFE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3546 (XCHAR_TABLE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3547 (regex_emacs_buffer->mirror_syntax_table), j) == Sword)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3548 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3549 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3550 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3551
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3552
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3553 case notwordchar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3554 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3555 k = (int) Sword;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3556 goto matchnotsyntax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3557 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3558 for (j = 0; j < (1 << BYTEWIDTH); j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3559 if (SYNTAX_UNSAFE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3560 (XCHAR_TABLE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3561 (regex_emacs_buffer->mirror_syntax_table), j) != Sword)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3562 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3563 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3564 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3565
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3566
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3567 case anychar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3568 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3569 int fastmap_newline = fastmap['\n'];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3571 /* `.' matches anything ... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3572 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3573 /* "anything" only includes bytes that can be the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3574 first byte of a character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3575 for (j = 0; j < 0xA0; j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3576 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3577 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3578 for (j = 0; j < (1 << BYTEWIDTH); j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3579 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3580 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3581
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3582 /* ... except perhaps newline. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3583 if (!(bufp->syntax & RE_DOT_NEWLINE))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3584 fastmap['\n'] = fastmap_newline;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3585
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3586 /* Return if we have already set `can_be_null'; if we have,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3587 then the fastmap is irrelevant. Something's wrong here. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3588 else if (bufp->can_be_null)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3589 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3590
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3591 /* Otherwise, have to check alternative paths. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3592 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3593 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3595 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3596 case syntaxspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3597 k = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3598 matchsyntax:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3599 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3600 for (j = 0; j < 0x80; j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3601 if (SYNTAX_UNSAFE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3602 (XCHAR_TABLE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3603 (regex_emacs_buffer->mirror_syntax_table), j) ==
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3604 (enum syntaxcode) k)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3605 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3606 for (j = 0x80; j < 0xA0; j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3607 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3608 if (LEADING_BYTE_PREFIX_P(j))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3609 /* too complicated to calculate this right */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3610 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3611 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3612 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3613 int multi_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3614 Lisp_Object cset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3615
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3616 cset = CHARSET_BY_LEADING_BYTE (j);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3617 if (CHARSETP (cset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3618 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3619 if (charset_syntax (regex_emacs_buffer, cset,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3620 &multi_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3621 == Sword || multi_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3622 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3623 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3624 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3625 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3626 #else /* ! MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3627 for (j = 0; j < (1 << BYTEWIDTH); j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3628 if (SYNTAX_UNSAFE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3629 (XCHAR_TABLE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3630 (regex_emacs_buffer->mirror_syntax_table), j) ==
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3631 (enum syntaxcode) k)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3632 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3633 #endif /* ! MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3634 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3635
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3637 case notsyntaxspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3638 k = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3639 matchnotsyntax:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3640 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3641 for (j = 0; j < 0x80; j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3642 if (SYNTAX_UNSAFE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3643 (XCHAR_TABLE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3644 (regex_emacs_buffer->mirror_syntax_table), j) !=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3645 (enum syntaxcode) k)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3646 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3647 for (j = 0x80; j < 0xA0; j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3648 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3649 if (LEADING_BYTE_PREFIX_P(j))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3650 /* too complicated to calculate this right */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3651 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3652 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3653 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3654 int multi_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3655 Lisp_Object cset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3657 cset = CHARSET_BY_LEADING_BYTE (j);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3658 if (CHARSETP (cset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3659 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3660 if (charset_syntax (regex_emacs_buffer, cset,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3661 &multi_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3662 != Sword || multi_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3663 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3664 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3665 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3666 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3667 #else /* ! MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3668 for (j = 0; j < (1 << BYTEWIDTH); j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3669 if (SYNTAX_UNSAFE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3670 (XCHAR_TABLE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3671 (regex_emacs_buffer->mirror_syntax_table), j) !=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3672 (enum syntaxcode) k)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3673 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3674 #endif /* ! MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3675 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3676
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3677 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3678 /* 97/2/17 jhod category patch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3679 case categoryspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3680 case notcategoryspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3681 bufp->can_be_null = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3682 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3683 /* end if category patch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3684 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3685
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3686 /* All cases after this match the empty string. These end with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3687 `continue'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3688
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3689
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3690 case before_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3691 case at_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3692 case after_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3693 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3694 #endif /* not emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3695
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3696
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3697 case no_op:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3698 case begline:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3699 case endline:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3700 case begbuf:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3701 case endbuf:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3702 case wordbound:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3703 case notwordbound:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3704 case wordbeg:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3705 case wordend:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3706 case push_dummy_failure:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3707 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3708
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3709
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3710 case jump_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3711 case pop_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3712 case maybe_pop_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3713 case jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3714 case jump_past_alt:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3715 case dummy_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3716 EXTRACT_NUMBER_AND_INCR (j, p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3717 p += j;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3718 if (j > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3719 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3720
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3721 /* Jump backward implies we just went through the body of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3722 loop and matched nothing. Opcode jumped to should be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3723 `on_failure_jump' or `succeed_n'. Just treat it like an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3724 ordinary jump. For a * loop, it has pushed its failure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3725 point already; if so, discard that as redundant. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3726 if ((re_opcode_t) *p != on_failure_jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3727 && (re_opcode_t) *p != succeed_n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3728 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3729
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3730 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3731 EXTRACT_NUMBER_AND_INCR (j, p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3732 p += j;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3733
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3734 /* If what's on the stack is where we are now, pop it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3735 if (!FAIL_STACK_EMPTY ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3736 && fail_stack.stack[fail_stack.avail - 1].pointer == p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3737 fail_stack.avail--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3739 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3740
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3741
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3742 case on_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3743 case on_failure_keep_string_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3744 handle_on_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3745 EXTRACT_NUMBER_AND_INCR (j, p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3746
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3747 /* For some patterns, e.g., `(a?)?', `p+j' here points to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3748 end of the pattern. We don't want to push such a point,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3749 since when we restore it above, entering the switch will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3750 increment `p' past the end of the pattern. We don't need
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3751 to push such a point since we obviously won't find any more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3752 fastmap entries beyond `pend'. Such a pattern can match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3753 the null string, though. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3754 if (p + j < pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3755 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3756 if (!PUSH_PATTERN_OP (p + j, fail_stack))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3757 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3758 RESET_FAIL_STACK ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3759 return -2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3760 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3761 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3762 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3763 bufp->can_be_null = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3764
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3765 if (succeed_n_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3766 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3767 EXTRACT_NUMBER_AND_INCR (k, p); /* Skip the n. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3768 succeed_n_p = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3769 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3770
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3771 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3772
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3773
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3774 case succeed_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3775 /* Get to the number of times to succeed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3776 p += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3777
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3778 /* Increment p past the n for when k != 0. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3779 EXTRACT_NUMBER_AND_INCR (k, p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3780 if (k == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3781 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3782 p -= 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3783 succeed_n_p = true; /* Spaghetti code alert. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3784 goto handle_on_failure_jump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3785 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3786 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3787
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3788
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3789 case set_number_at:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3790 p += 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3791 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3792
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3794 case start_memory:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3795 case stop_memory:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3796 p += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3797 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3798
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3799
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3800 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3801 abort (); /* We have listed all the cases. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3802 } /* switch *p++ */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3803
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3804 /* Getting here means we have found the possible starting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3805 characters for one path of the pattern -- and that the empty
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3806 string does not match. We need not follow this path further.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3807 Instead, look at the next alternative (remembered on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3808 stack), or quit if no more. The test at the top of the loop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3809 does these things. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3810 path_can_be_null = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3811 p = pend;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3812 } /* while p */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3813
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3814 /* Set `can_be_null' for the last path (also the first path, if the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3815 pattern is empty). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3816 bufp->can_be_null |= path_can_be_null;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3817
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3818 done:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3819 RESET_FAIL_STACK ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3820 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3821 } /* re_compile_fastmap */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3822
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3823 /* Set REGS to hold NUM_REGS registers, storing them in STARTS and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3824 ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3825 this memory for recording register information. STARTS and ENDS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3826 must be allocated using the malloc library routine, and must each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3827 be at least NUM_REGS * sizeof (regoff_t) bytes long.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3828
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3829 If NUM_REGS == 0, then subsequent matches should allocate their own
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3830 register data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3831
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3832 Unless this function is called, the first search or match using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3833 PATTERN_BUFFER will allocate its own register data, without
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3834 freeing the old data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3835
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3836 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3837 re_set_registers (struct re_pattern_buffer *bufp, struct re_registers *regs,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3838 unsigned num_regs, regoff_t *starts, regoff_t *ends)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3839 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3840 if (num_regs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3841 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3842 bufp->regs_allocated = REGS_REALLOCATE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3843 regs->num_regs = num_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3844 regs->start = starts;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3845 regs->end = ends;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3846 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3847 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3848 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3849 bufp->regs_allocated = REGS_UNALLOCATED;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3850 regs->num_regs = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3851 regs->start = regs->end = (regoff_t *) 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3852 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3853 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3854
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3855 /* Searching routines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3856
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3857 /* Like re_search_2, below, but only one string is specified, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3858 doesn't let you say where to stop matching. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3859
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3860 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3861 re_search (struct re_pattern_buffer *bufp, const char *string, int size,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3862 int startpos, int range, struct re_registers *regs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3863 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3864 return re_search_2 (bufp, NULL, 0, string, size, startpos, range,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3865 regs, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3866 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3867
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3868 #ifndef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3869 /* Snarfed from src/lisp.h, needed for compiling [ce]tags. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3870 # define bytecount_to_charcount(ptr, len) (len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3871 # define charcount_to_bytecount(ptr, len) (len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3872 typedef int Charcount;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3873 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3874
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3875 /* Using the compiled pattern in BUFP->buffer, first tries to match the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3876 virtual concatenation of STRING1 and STRING2, starting first at index
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3877 STARTPOS, then at STARTPOS + 1, and so on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3879 With MULE, STARTPOS is a byte position, not a char position. And the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3880 search will increment STARTPOS by the width of the current leading
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3881 character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3882
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3883 STRING1 and STRING2 have length SIZE1 and SIZE2, respectively.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3884
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3885 RANGE is how far to scan while trying to match. RANGE = 0 means try
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3886 only at STARTPOS; in general, the last start tried is STARTPOS +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3887 RANGE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3888
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3889 With MULE, RANGE is a byte position, not a char position. The last
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3890 start tried is the character starting <= STARTPOS + RANGE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3891
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3892 In REGS, return the indices of the virtual concatenation of STRING1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3893 and STRING2 that matched the entire BUFP->buffer and its contained
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3894 subexpressions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3895
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3896 Do not consider matching one past the index STOP in the virtual
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3897 concatenation of STRING1 and STRING2.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3898
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3899 We return either the position in the strings at which the match was
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3900 found, -1 if no match, or -2 if error (such as failure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3901 stack overflow). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3902
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3903 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3904 re_search_2 (struct re_pattern_buffer *bufp, const char *string1,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3905 int size1, const char *string2, int size2, int startpos,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3906 int range, struct re_registers *regs, int stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3907 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3908 int val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3909 REGISTER char *fastmap = bufp->fastmap;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3910 REGISTER char *translate = bufp->translate;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3911 int total_size = size1 + size2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3912 int endpos = startpos + range;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3913 #ifdef REGEX_BEGLINE_CHECK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3914 int anchored_at_begline = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3915 #endif
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3916 const unsigned char *d;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3917 Charcount d_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3918
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3919 /* Check for out-of-range STARTPOS. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3920 if (startpos < 0 || startpos > total_size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3921 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3922
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3923 /* Fix up RANGE if it might eventually take us outside
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3924 the virtual concatenation of STRING1 and STRING2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3925 if (endpos < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3926 range = 0 - startpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3927 else if (endpos > total_size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3928 range = total_size - startpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3929
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3930 /* If the search isn't to be a backwards one, don't waste time in a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3931 search for a pattern that must be anchored. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3932 if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == begbuf && range > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3933 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3934 if (startpos > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3935 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3936 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3937 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3938 d = ((const unsigned char *)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3939 (startpos >= size1 ? string2 - size1 : string1) + startpos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3940 range = charcount_to_bytecount (d, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3941 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3942 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3944 /* Update the fastmap now if not correct already. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3945 if (fastmap && !bufp->fastmap_accurate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3946 if (re_compile_fastmap (bufp) == -2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3947 return -2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3948
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3949 #ifdef REGEX_BEGLINE_CHECK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3950 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3951 int i = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3952
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3953 while (i < bufp->used)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3954 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3955 if (bufp->buffer[i] == start_memory ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3956 bufp->buffer[i] == stop_memory)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3957 i += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3958 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3959 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3960 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3961 anchored_at_begline = i < bufp->used && bufp->buffer[i] == begline;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3962 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3963 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3964
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3965 /* Loop through the string, looking for a place to start matching. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3966 for (;;)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3967 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3968 #ifdef REGEX_BEGLINE_CHECK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3969 /* If the regex is anchored at the beginning of a line (i.e. with a ^),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3970 then we can speed things up by skipping to the next beginning-of-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3971 line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3972 if (anchored_at_begline && startpos > 0 && startpos != size1 &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3973 range > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3974 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3975 /* whose stupid idea was it anyway to make this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3976 function take two strings to match?? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3977 int lim = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3978 int irange = range;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3979
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3980 if (startpos < size1 && startpos + range >= size1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3981 lim = range - (size1 - startpos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3982
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3983 d = ((const unsigned char *)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3984 (startpos >= size1 ? string2 - size1 : string1) + startpos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3985 DEC_CHARPTR(d); /* Ok, since startpos != size1. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3986 d_size = charcount_to_bytecount (d, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3987
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3988 if (translate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3989 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3990 while (range > lim && (*d >= 0x80 || translate[*d] != '\n'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3991 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3992 while (range > lim && translate[*d] != '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3993 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3994 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3995 d += d_size; /* Speedier INC_CHARPTR(d) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3996 d_size = charcount_to_bytecount (d, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3997 range -= d_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3998 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3999 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4000 while (range > lim && *d != '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4001 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4002 d += d_size; /* Speedier INC_CHARPTR(d) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4003 d_size = charcount_to_bytecount (d, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4004 range -= d_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4005 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4006
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4007 startpos += irange - range;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4008 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4009 #endif /* REGEX_BEGLINE_CHECK */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4010
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4011 /* If a fastmap is supplied, skip quickly over characters that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4012 cannot be the start of a match. If the pattern can match the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4013 null string, however, we don't need to skip characters; we want
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4014 the first null string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4015 if (fastmap && startpos < total_size && !bufp->can_be_null)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4016 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4017 if (range > 0) /* Searching forwards. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4018 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4019 int lim = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4020 int irange = range;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4021
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4022 if (startpos < size1 && startpos + range >= size1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4023 lim = range - (size1 - startpos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4024
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4025 d = ((const unsigned char *)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4026 (startpos >= size1 ? string2 - size1 : string1) + startpos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4027
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4028 /* Written out as an if-else to avoid testing `translate'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4029 inside the loop. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4030 if (translate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4031 while (range > lim &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4032 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4033 *d < 0x80 &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4034 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4035 !fastmap[(unsigned char)translate[*d]])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4036 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4037 d_size = charcount_to_bytecount (d, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4038 range -= d_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4039 d += d_size; /* Speedier INC_CHARPTR(d) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4040 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4041 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4042 while (range > lim && !fastmap[*d])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4043 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4044 d_size = charcount_to_bytecount (d, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4045 range -= d_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4046 d += d_size; /* Speedier INC_CHARPTR(d) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4047 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4048
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4049 startpos += irange - range;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4050 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4051 else /* Searching backwards. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4052 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4053 unsigned char c = (size1 == 0 || startpos >= size1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4054 ? string2[startpos - size1]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4055 : string1[startpos]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4056 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4057 if (c < 0x80 && !fastmap[(unsigned char) TRANSLATE (c)])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4058 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4059 if (!fastmap[(unsigned char) TRANSLATE (c)])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4060 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4061 goto advance;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4062 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4063 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4064
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4065 /* If can't match the null string, and that's all we have left, fail. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4066 if (range >= 0 && startpos == total_size && fastmap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4067 && !bufp->can_be_null)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4068 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4069
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4070 #ifdef emacs /* XEmacs added, w/removal of immediate_quit */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4071 if (!no_quit_in_re_search)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4072 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4073 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4074 val = re_match_2_internal (bufp, string1, size1, string2, size2,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4075 startpos, regs, stop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4076 #ifndef REGEX_MALLOC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4077 #ifdef C_ALLOCA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4078 alloca (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4079 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4080 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4081
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4082 if (val >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4083 return startpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4084
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4085 if (val == -2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4086 return -2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4087
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4088 advance:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4089 if (!range)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4090 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4091 else if (range > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4092 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4093 d = ((const unsigned char *)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4094 (startpos >= size1 ? string2 - size1 : string1) + startpos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4095 d_size = charcount_to_bytecount (d, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4096 range -= d_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4097 startpos += d_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4098 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4099 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4100 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4101 /* Note startpos > size1 not >=. If we are on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4102 string1/string2 boundary, we want to backup into string1. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4103 d = ((const unsigned char *)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4104 (startpos > size1 ? string2 - size1 : string1) + startpos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4105 DEC_CHARPTR(d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4106 d_size = charcount_to_bytecount (d, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4107 range += d_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4108 startpos -= d_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4109 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4110 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4111 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4112 } /* re_search_2 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4114 /* Declarations and macros for re_match_2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4116 /* This converts PTR, a pointer into one of the search strings `string1'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4117 and `string2' into an offset from the beginning of that string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4118 #define POINTER_TO_OFFSET(ptr) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4119 (FIRST_STRING_P (ptr) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4120 ? ((regoff_t) ((ptr) - string1)) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4121 : ((regoff_t) ((ptr) - string2 + size1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4122
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4123 /* Macros for dealing with the split strings in re_match_2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4125 #define MATCHING_IN_FIRST_STRING (dend == end_match_1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4127 /* Call before fetching a character with *d. This switches over to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4128 string2 if necessary. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4129 #define PREFETCH() \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4130 while (d == dend) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4131 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4132 /* End of string2 => fail. */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4133 if (dend == end_match_2) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4134 goto fail; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4135 /* End of string1 => advance to string2. */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4136 d = string2; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4137 dend = end_match_2; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4138 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4140
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4141 /* Test if at very beginning or at very end of the virtual concatenation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4142 of `string1' and `string2'. If only one string, it's `string2'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4143 #define AT_STRINGS_BEG(d) ((d) == (size1 ? string1 : string2) || !size2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4144 #define AT_STRINGS_END(d) ((d) == end2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4146 /* XEmacs change:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4147 If the given position straddles the string gap, return the equivalent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4148 position that is before or after the gap, respectively; otherwise,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4149 return the same position. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4150 #define POS_BEFORE_GAP_UNSAFE(d) ((d) == string2 ? end1 : (d))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4151 #define POS_AFTER_GAP_UNSAFE(d) ((d) == end1 ? string2 : (d))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4152
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4153 /* Test if CH is a word-constituent character. (XEmacs change) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4154 #define WORDCHAR_P_UNSAFE(ch) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4155 (SYNTAX_UNSAFE (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table), \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4156 ch) == Sword)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4157
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4158 /* Free everything we malloc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4159 #ifdef MATCH_MAY_ALLOCATE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4160 #define FREE_VAR(var) if (var) REGEX_FREE (var); var = NULL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4161 #define FREE_VARIABLES() \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4162 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4163 REGEX_FREE_STACK (fail_stack.stack); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4164 FREE_VAR (regstart); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4165 FREE_VAR (regend); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4166 FREE_VAR (old_regstart); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4167 FREE_VAR (old_regend); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4168 FREE_VAR (best_regstart); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4169 FREE_VAR (best_regend); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4170 FREE_VAR (reg_info); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4171 FREE_VAR (reg_dummy); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4172 FREE_VAR (reg_info_dummy); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4173 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4174 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4175 #define FREE_VARIABLES() ((void)0) /* Do nothing! But inhibit gcc warning. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4176 #endif /* not MATCH_MAY_ALLOCATE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4177
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4178 /* These values must meet several constraints. They must not be valid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4179 register values; since we have a limit of 255 registers (because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4180 we use only one byte in the pattern for the register number), we can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4181 use numbers larger than 255. They must differ by 1, because of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4182 NUM_FAILURE_ITEMS above. And the value for the lowest register must
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4183 be larger than the value for the highest register, so we do not try
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4184 to actually save any registers when none are active. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4185 #define NO_HIGHEST_ACTIVE_REG (1 << BYTEWIDTH)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4186 #define NO_LOWEST_ACTIVE_REG (NO_HIGHEST_ACTIVE_REG + 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4188 /* Matching routines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4190 #ifndef emacs /* Emacs never uses this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4191 /* re_match is like re_match_2 except it takes only a single string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4192
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4193 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4194 re_match (struct re_pattern_buffer *bufp, const char *string, int size,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4195 int pos, struct re_registers *regs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4196 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4197 int result = re_match_2_internal (bufp, NULL, 0, string, size,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4198 pos, regs, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4199 alloca (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4200 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4201 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4202 #endif /* not emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4203
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4205 /* re_match_2 matches the compiled pattern in BUFP against the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4206 (virtual) concatenation of STRING1 and STRING2 (of length SIZE1 and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4207 SIZE2, respectively). We start matching at POS, and stop matching
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4208 at STOP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4210 If REGS is non-null and the `no_sub' field of BUFP is nonzero, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4211 store offsets for the substring each group matched in REGS. See the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4212 documentation for exactly how many groups we fill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4214 We return -1 if no match, -2 if an internal error (such as the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4215 failure stack overflowing). Otherwise, we return the length of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4216 matched substring. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4217
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4218 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4219 re_match_2 (struct re_pattern_buffer *bufp, const char *string1,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4220 int size1, const char *string2, int size2, int pos,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4221 struct re_registers *regs, int stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4222 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4223 int result = re_match_2_internal (bufp, string1, size1, string2, size2,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4224 pos, regs, stop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4225 alloca (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4226 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4227 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4229 /* This is a separate function so that we can force an alloca cleanup
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4230 afterwards. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4231 static int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4232 re_match_2_internal (struct re_pattern_buffer *bufp, const char *string1,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4233 int size1, const char *string2, int size2, int pos,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4234 struct re_registers *regs, int stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4235 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4236 /* General temporaries. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4237 int mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4238 unsigned char *p1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4239 int should_succeed; /* XEmacs change */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4241 /* Just past the end of the corresponding string. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4242 const char *end1, *end2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4244 /* Pointers into string1 and string2, just past the last characters in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4245 each to consider matching. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4246 const char *end_match_1, *end_match_2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4248 /* Where we are in the data, and the end of the current string. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4249 const char *d, *dend;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4251 /* Where we are in the pattern, and the end of the pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4252 unsigned char *p = bufp->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4253 REGISTER unsigned char *pend = p + bufp->used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4255 /* Mark the opcode just after a start_memory, so we can test for an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4256 empty subpattern when we get to the stop_memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4257 unsigned char *just_past_start_mem = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4259 /* We use this to map every character in the string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4260 char *translate = bufp->translate;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4261
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4262 /* Failure point stack. Each place that can handle a failure further
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4263 down the line pushes a failure point on this stack. It consists of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4264 restart, regend, and reg_info for all registers corresponding to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4265 the subexpressions we're currently inside, plus the number of such
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4266 registers, and, finally, two char *'s. The first char * is where
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4267 to resume scanning the pattern; the second one is where to resume
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4268 scanning the strings. If the latter is zero, the failure point is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4269 a ``dummy''; if a failure happens and the failure point is a dummy,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4270 it gets discarded and the next one is tried. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4271 #ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4272 fail_stack_type fail_stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4273 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4274 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4275 static unsigned failure_id;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4276 unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4277 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4279 #ifdef REL_ALLOC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4280 /* This holds the pointer to the failure stack, when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4281 it is allocated relocatably. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4282 fail_stack_elt_t *failure_stack_ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4283 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4284
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4285 /* We fill all the registers internally, independent of what we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4286 return, for use in backreferences. The number here includes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4287 an element for register zero. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4288 unsigned num_regs = bufp->re_nsub + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4290 /* The currently active registers. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4291 unsigned lowest_active_reg = NO_LOWEST_ACTIVE_REG;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4292 unsigned highest_active_reg = NO_HIGHEST_ACTIVE_REG;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4294 /* Information on the contents of registers. These are pointers into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4295 the input strings; they record just what was matched (on this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4296 attempt) by a subexpression part of the pattern, that is, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4297 regnum-th regstart pointer points to where in the pattern we began
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4298 matching and the regnum-th regend points to right after where we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4299 stopped matching the regnum-th subexpression. (The zeroth register
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4300 keeps track of what the whole pattern matches.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4301 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4302 const char **regstart, **regend;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4303 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4305 /* If a group that's operated upon by a repetition operator fails to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4306 match anything, then the register for its start will need to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4307 restored because it will have been set to wherever in the string we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4308 are when we last see its open-group operator. Similarly for a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4309 register's end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4310 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4311 const char **old_regstart, **old_regend;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4312 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4313
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4314 /* The is_active field of reg_info helps us keep track of which (possibly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4315 nested) subexpressions we are currently in. The matched_something
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4316 field of reg_info[reg_num] helps us tell whether or not we have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4317 matched any of the pattern so far this time through the reg_num-th
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4318 subexpression. These two fields get reset each time through any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4319 loop their register is in. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4320 #ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4321 register_info_type *reg_info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4322 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4323
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4324 /* The following record the register info as found in the above
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4325 variables when we find a match better than any we've seen before.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4326 This happens as we backtrack through the failure points, which in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4327 turn happens only if we have not yet matched the entire string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4328 unsigned best_regs_set = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4329 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4330 const char **best_regstart, **best_regend;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4331 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4332
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4333 /* Logically, this is `best_regend[0]'. But we don't want to have to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4334 allocate space for that if we're not allocating space for anything
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4335 else (see below). Also, we never need info about register 0 for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4336 any of the other register vectors, and it seems rather a kludge to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4337 treat `best_regend' differently than the rest. So we keep track of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4338 the end of the best match so far in a separate variable. We
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4339 initialize this to NULL so that when we backtrack the first time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4340 and need to test it, it's not garbage. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4341 const char *match_end = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4343 /* This helps SET_REGS_MATCHED avoid doing redundant work. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4344 int set_regs_matched_done = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4345
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4346 /* Used when we pop values we don't care about. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4347 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4348 const char **reg_dummy;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4349 register_info_type *reg_info_dummy;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4350 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4351
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4352 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4353 /* Counts the total number of registers pushed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4354 unsigned num_regs_pushed = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4355 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4357 /* 1 if this match ends in the same string (string1 or string2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4358 as the best previous match. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4359 boolean same_str_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4360
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4361 /* 1 if this match is the best seen so far. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4362 boolean best_match_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4364 DEBUG_PRINT1 ("\n\nEntering re_match_2.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4365
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4366 INIT_FAIL_STACK ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4367
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4368 #ifdef MATCH_MAY_ALLOCATE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4369 /* Do not bother to initialize all the register variables if there are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4370 no groups in the pattern, as it takes a fair amount of time. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4371 there are groups, we include space for register 0 (the whole
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4372 pattern), even though we never use it, since it simplifies the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4373 array indexing. We should fix this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4374 if (bufp->re_nsub)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4375 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4376 regstart = REGEX_TALLOC (num_regs, const char *);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4377 regend = REGEX_TALLOC (num_regs, const char *);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4378 old_regstart = REGEX_TALLOC (num_regs, const char *);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4379 old_regend = REGEX_TALLOC (num_regs, const char *);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4380 best_regstart = REGEX_TALLOC (num_regs, const char *);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4381 best_regend = REGEX_TALLOC (num_regs, const char *);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4382 reg_info = REGEX_TALLOC (num_regs, register_info_type);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4383 reg_dummy = REGEX_TALLOC (num_regs, const char *);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4384 reg_info_dummy = REGEX_TALLOC (num_regs, register_info_type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4385
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4386 if (!(regstart && regend && old_regstart && old_regend && reg_info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4387 && best_regstart && best_regend && reg_dummy && reg_info_dummy))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4388 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4389 FREE_VARIABLES ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4390 return -2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4391 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4392 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4393 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4394 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4395 /* We must initialize all our variables to NULL, so that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4396 `FREE_VARIABLES' doesn't try to free them. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4397 regstart = regend = old_regstart = old_regend = best_regstart
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4398 = best_regend = reg_dummy = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4399 reg_info = reg_info_dummy = (register_info_type *) NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4400 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4401 #endif /* MATCH_MAY_ALLOCATE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4402
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4403 /* The starting position is bogus. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4404 if (pos < 0 || pos > size1 + size2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4405 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4406 FREE_VARIABLES ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4407 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4408 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4410 /* Initialize subexpression text positions to -1 to mark ones that no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4411 start_memory/stop_memory has been seen for. Also initialize the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4412 register information struct. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4413 for (mcnt = 1; mcnt < num_regs; mcnt++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4414 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4415 regstart[mcnt] = regend[mcnt]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4416 = old_regstart[mcnt] = old_regend[mcnt] = REG_UNSET_VALUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4417
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4418 REG_MATCH_NULL_STRING_P (reg_info[mcnt]) = MATCH_NULL_UNSET_VALUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4419 IS_ACTIVE (reg_info[mcnt]) = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4420 MATCHED_SOMETHING (reg_info[mcnt]) = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4421 EVER_MATCHED_SOMETHING (reg_info[mcnt]) = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4422 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4423
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4424 /* We move `string1' into `string2' if the latter's empty -- but not if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4425 `string1' is null. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4426 if (size2 == 0 && string1 != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4427 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4428 string2 = string1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4429 size2 = size1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4430 string1 = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4431 size1 = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4432 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4433 end1 = string1 + size1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4434 end2 = string2 + size2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4435
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4436 /* Compute where to stop matching, within the two strings. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4437 if (stop <= size1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4438 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4439 end_match_1 = string1 + stop;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4440 end_match_2 = string2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4441 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4442 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4443 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4444 end_match_1 = end1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4445 end_match_2 = string2 + stop - size1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4446 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4447
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4448 /* `p' scans through the pattern as `d' scans through the data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4449 `dend' is the end of the input string that `d' points within. `d'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4450 is advanced into the following input string whenever necessary, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4451 this happens before fetching; therefore, at the beginning of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4452 loop, `d' can be pointing at the end of a string, but it cannot
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4453 equal `string2'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4454 if (size1 > 0 && pos <= size1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4455 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4456 d = string1 + pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4457 dend = end_match_1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4458 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4459 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4460 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4461 d = string2 + pos - size1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4462 dend = end_match_2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4463 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4464
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4465 DEBUG_PRINT1 ("The compiled pattern is: ");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4466 DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4467 DEBUG_PRINT1 ("The string to match is: `");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4468 DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4469 DEBUG_PRINT1 ("'\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4470
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4471 /* This loops over pattern commands. It exits by returning from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4472 function if the match is complete, or it drops through if the match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4473 fails at this starting point in the input data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4474 for (;;)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4475 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4476 DEBUG_PRINT2 ("\n0x%lx: ", (long) p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4477 #ifdef emacs /* XEmacs added, w/removal of immediate_quit */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4478 if (!no_quit_in_re_search)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4479 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4480 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4481
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4482 if (p == pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4483 { /* End of pattern means we might have succeeded. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4484 DEBUG_PRINT1 ("end of pattern ... ");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4485
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4486 /* If we haven't matched the entire string, and we want the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4487 longest match, try backtracking. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4488 if (d != end_match_2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4489 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4490 same_str_p = (FIRST_STRING_P (match_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4491 == MATCHING_IN_FIRST_STRING);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4493 /* AIX compiler got confused when this was combined
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4494 with the previous declaration. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4495 if (same_str_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4496 best_match_p = d > match_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4497 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4498 best_match_p = !MATCHING_IN_FIRST_STRING;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4499
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4500 DEBUG_PRINT1 ("backtracking.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4501
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4502 if (!FAIL_STACK_EMPTY ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4503 { /* More failure points to try. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4504
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4505 /* If exceeds best match so far, save it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4506 if (!best_regs_set || best_match_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4507 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4508 best_regs_set = true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4509 match_end = d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4510
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4511 DEBUG_PRINT1 ("\nSAVING match as best so far.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4512
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4513 for (mcnt = 1; mcnt < num_regs; mcnt++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4514 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4515 best_regstart[mcnt] = regstart[mcnt];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4516 best_regend[mcnt] = regend[mcnt];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4517 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4518 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4519 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4520 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4521
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4522 /* If no failure points, don't restore garbage. And if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4523 last match is real best match, don't restore second
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4524 best one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4525 else if (best_regs_set && !best_match_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4526 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4527 restore_best_regs:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4528 /* Restore best match. It may happen that `dend ==
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4529 end_match_1' while the restored d is in string2.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4530 For example, the pattern `x.*y.*z' against the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4531 strings `x-' and `y-z-', if the two strings are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4532 not consecutive in memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4533 DEBUG_PRINT1 ("Restoring best registers.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4534
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4535 d = match_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4536 dend = ((d >= string1 && d <= end1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4537 ? end_match_1 : end_match_2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4538
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4539 for (mcnt = 1; mcnt < num_regs; mcnt++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4540 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4541 regstart[mcnt] = best_regstart[mcnt];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4542 regend[mcnt] = best_regend[mcnt];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4543 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4544 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4545 } /* d != end_match_2 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4547 succeed_label:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4548 DEBUG_PRINT1 ("Accepting match.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4550 /* If caller wants register contents data back, do it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4551 if (regs && !bufp->no_sub)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4552 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4553 /* Have the register data arrays been allocated? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4554 if (bufp->regs_allocated == REGS_UNALLOCATED)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4555 { /* No. So allocate them with malloc. We need one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4556 extra element beyond `num_regs' for the `-1' marker
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4557 GNU code uses. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4558 regs->num_regs = MAX (RE_NREGS, num_regs + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4559 regs->start = TALLOC (regs->num_regs, regoff_t);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4560 regs->end = TALLOC (regs->num_regs, regoff_t);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4561 if (regs->start == NULL || regs->end == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4562 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4563 FREE_VARIABLES ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4564 return -2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4565 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4566 bufp->regs_allocated = REGS_REALLOCATE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4567 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4568 else if (bufp->regs_allocated == REGS_REALLOCATE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4569 { /* Yes. If we need more elements than were already
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4570 allocated, reallocate them. If we need fewer, just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4571 leave it alone. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4572 if (regs->num_regs < num_regs + 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4573 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4574 regs->num_regs = num_regs + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4575 RETALLOC (regs->start, regs->num_regs, regoff_t);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4576 RETALLOC (regs->end, regs->num_regs, regoff_t);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4577 if (regs->start == NULL || regs->end == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4578 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4579 FREE_VARIABLES ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4580 return -2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4581 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4582 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4583 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4584 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4585 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4586 /* These braces fend off a "empty body in an else-statement"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4587 warning under GCC when assert expands to nothing. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4588 assert (bufp->regs_allocated == REGS_FIXED);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4589 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4590
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4591 /* Convert the pointer data in `regstart' and `regend' to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4592 indices. Register zero has to be set differently,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4593 since we haven't kept track of any info for it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4594 if (regs->num_regs > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4595 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4596 regs->start[0] = pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4597 regs->end[0] = (MATCHING_IN_FIRST_STRING
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4598 ? ((regoff_t) (d - string1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4599 : ((regoff_t) (d - string2 + size1)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4600 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4601
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4602 /* Go through the first `min (num_regs, regs->num_regs)'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4603 registers, since that is all we initialized. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4604 for (mcnt = 1; mcnt < MIN (num_regs, regs->num_regs); mcnt++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4605 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4606 if (REG_UNSET (regstart[mcnt]) || REG_UNSET (regend[mcnt]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4607 regs->start[mcnt] = regs->end[mcnt] = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4608 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4609 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4610 regs->start[mcnt]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4611 = (regoff_t) POINTER_TO_OFFSET (regstart[mcnt]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4612 regs->end[mcnt]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4613 = (regoff_t) POINTER_TO_OFFSET (regend[mcnt]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4614 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4615 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4616
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4617 /* If the regs structure we return has more elements than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4618 were in the pattern, set the extra elements to -1. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4619 we (re)allocated the registers, this is the case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4620 because we always allocate enough to have at least one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4621 -1 at the end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4622 for (mcnt = num_regs; mcnt < regs->num_regs; mcnt++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4623 regs->start[mcnt] = regs->end[mcnt] = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4624 } /* regs && !bufp->no_sub */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4626 DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4627 nfailure_points_pushed, nfailure_points_popped,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4628 nfailure_points_pushed - nfailure_points_popped);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4629 DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4631 mcnt = d - pos - (MATCHING_IN_FIRST_STRING
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4632 ? string1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4633 : string2 - size1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4634
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4635 DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4637 FREE_VARIABLES ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4638 return mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4639 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4641 /* Otherwise match next pattern command. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4642 switch (SWITCH_ENUM_CAST ((re_opcode_t) *p++))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4643 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4644 /* Ignore these. Used to ignore the n of succeed_n's which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4645 currently have n == 0. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4646 case no_op:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4647 DEBUG_PRINT1 ("EXECUTING no_op.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4648 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4649
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4650 case succeed:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4651 DEBUG_PRINT1 ("EXECUTING succeed.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4652 goto succeed_label;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4653
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4654 /* Match the next n pattern characters exactly. The following
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4655 byte in the pattern defines n, and the n bytes after that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4656 are the characters to match. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4657 case exactn:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4658 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4659 DEBUG_PRINT2 ("EXECUTING exactn %d.\n", mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4661 /* This is written out as an if-else so we don't waste time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4662 testing `translate' inside the loop. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4663 if (translate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4664 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4665 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4666 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4667 PREFETCH ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4668 if (translate[(unsigned char) *d++] != (char) *p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4669 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4670 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4671 while (--mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4672 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4673 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4674 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4675 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4676 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4677 PREFETCH ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4678 if (*d++ != (char) *p++) goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4679 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4680 while (--mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4681 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4682 SET_REGS_MATCHED ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4683 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4684
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4685
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4686 /* Match any character except possibly a newline or a null. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4687 case anychar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4688 DEBUG_PRINT1 ("EXECUTING anychar.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4689
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4690 PREFETCH ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4691
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4692 if ((!(bufp->syntax & RE_DOT_NEWLINE) && TRANSLATE (*d) == '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4693 || (bufp->syntax & RE_DOT_NOT_NULL && TRANSLATE (*d) == '\000'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4694 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4695
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4696 SET_REGS_MATCHED ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4697 DEBUG_PRINT2 (" Matched `%d'.\n", *d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4698 INC_CHARPTR (d); /* XEmacs change */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4699 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4700
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4701
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4702 case charset:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4703 case charset_not:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4704 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4705 REGISTER unsigned char c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4706 boolean not = (re_opcode_t) *(p - 1) == charset_not;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4707
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4708 DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4709
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4710 PREFETCH ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4711 c = TRANSLATE (*d); /* The character to match. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4712
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4713 /* Cast to `unsigned' instead of `unsigned char' in case the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4714 bit list is a full 32 bytes long. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4715 if (c < (unsigned) (*p * BYTEWIDTH)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4716 && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4717 not = !not;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4718
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4719 p += 1 + *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4720
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4721 if (!not) goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4722
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4723 SET_REGS_MATCHED ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4724 INC_CHARPTR (d); /* XEmacs change */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4725 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4726 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4727
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4728 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4729 case charset_mule:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4730 case charset_mule_not:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4731 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4732 REGISTER Emchar c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4733 boolean not = (re_opcode_t) *(p - 1) == charset_mule_not;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4734
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4735 DEBUG_PRINT2 ("EXECUTING charset_mule%s.\n", not ? "_not" : "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4736
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4737 PREFETCH ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4738 c = charptr_emchar ((const Bufbyte *) d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4739 c = TRANSLATE_EXTENDED_UNSAFE (c); /* The character to match. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4740
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4741 if (EQ (Qt, unified_range_table_lookup (p, c, Qnil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4742 not = !not;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4743
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4744 p += unified_range_table_bytes_used (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4745
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4746 if (!not) goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4747
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4748 SET_REGS_MATCHED ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4749 INC_CHARPTR (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4750 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4751 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4752 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4753
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4754
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4755 /* The beginning of a group is represented by start_memory.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4756 The arguments are the register number in the next byte, and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4757 number of groups inner to this one in the next. The text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4758 matched within the group is recorded (in the internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4759 registers data structure) under the register number. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4760 case start_memory:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4761 DEBUG_PRINT3 ("EXECUTING start_memory %d (%d):\n", *p, p[1]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4762
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4763 /* Find out if this group can match the empty string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4764 p1 = p; /* To send to group_match_null_string_p. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4765
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4766 if (REG_MATCH_NULL_STRING_P (reg_info[*p]) == MATCH_NULL_UNSET_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4767 REG_MATCH_NULL_STRING_P (reg_info[*p])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4768 = group_match_null_string_p (&p1, pend, reg_info);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4769
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4770 /* Save the position in the string where we were the last time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4771 we were at this open-group operator in case the group is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4772 operated upon by a repetition operator, e.g., with `(a*)*b'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4773 against `ab'; then we want to ignore where we are now in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4774 the string in case this attempt to match fails. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4775 old_regstart[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4776 ? REG_UNSET (regstart[*p]) ? d : regstart[*p]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4777 : regstart[*p];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4778 DEBUG_PRINT2 (" old_regstart: %d\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4779 POINTER_TO_OFFSET (old_regstart[*p]));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4780
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4781 regstart[*p] = d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4782 DEBUG_PRINT2 (" regstart: %d\n", POINTER_TO_OFFSET (regstart[*p]));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4783
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4784 IS_ACTIVE (reg_info[*p]) = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4785 MATCHED_SOMETHING (reg_info[*p]) = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4786
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4787 /* Clear this whenever we change the register activity status. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4788 set_regs_matched_done = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4789
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4790 /* This is the new highest active register. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4791 highest_active_reg = *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4792
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4793 /* If nothing was active before, this is the new lowest active
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4794 register. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4795 if (lowest_active_reg == NO_LOWEST_ACTIVE_REG)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4796 lowest_active_reg = *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4797
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4798 /* Move past the register number and inner group count. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4799 p += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4800 just_past_start_mem = p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4801
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4802 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4803
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4804
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4805 /* The stop_memory opcode represents the end of a group. Its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4806 arguments are the same as start_memory's: the register
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4807 number, and the number of inner groups. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4808 case stop_memory:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4809 DEBUG_PRINT3 ("EXECUTING stop_memory %d (%d):\n", *p, p[1]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4810
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4811 /* We need to save the string position the last time we were at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4812 this close-group operator in case the group is operated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4813 upon by a repetition operator, e.g., with `((a*)*(b*)*)*'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4814 against `aba'; then we want to ignore where we are now in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4815 the string in case this attempt to match fails. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4816 old_regend[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4817 ? REG_UNSET (regend[*p]) ? d : regend[*p]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4818 : regend[*p];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4819 DEBUG_PRINT2 (" old_regend: %d\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4820 POINTER_TO_OFFSET (old_regend[*p]));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4821
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4822 regend[*p] = d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4823 DEBUG_PRINT2 (" regend: %d\n", POINTER_TO_OFFSET (regend[*p]));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4824
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4825 /* This register isn't active anymore. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4826 IS_ACTIVE (reg_info[*p]) = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4828 /* Clear this whenever we change the register activity status. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4829 set_regs_matched_done = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4830
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4831 /* If this was the only register active, nothing is active
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4832 anymore. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4833 if (lowest_active_reg == highest_active_reg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4834 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4835 lowest_active_reg = NO_LOWEST_ACTIVE_REG;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4836 highest_active_reg = NO_HIGHEST_ACTIVE_REG;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4837 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4838 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4839 { /* We must scan for the new highest active register, since
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4840 it isn't necessarily one less than now: consider
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4841 (a(b)c(d(e)f)g). When group 3 ends, after the f), the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4842 new highest active register is 1. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4843 unsigned char r = *p - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4844 while (r > 0 && !IS_ACTIVE (reg_info[r]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4845 r--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4846
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4847 /* If we end up at register zero, that means that we saved
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4848 the registers as the result of an `on_failure_jump', not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4849 a `start_memory', and we jumped to past the innermost
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4850 `stop_memory'. For example, in ((.)*) we save
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4851 registers 1 and 2 as a result of the *, but when we pop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4852 back to the second ), we are at the stop_memory 1.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4853 Thus, nothing is active. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4854 if (r == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4855 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4856 lowest_active_reg = NO_LOWEST_ACTIVE_REG;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4857 highest_active_reg = NO_HIGHEST_ACTIVE_REG;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4858 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4859 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4860 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4861 highest_active_reg = r;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4863 /* 98/9/21 jhod: We've also gotta set lowest_active_reg, don't we? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4864 r = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4865 while (r < highest_active_reg && !IS_ACTIVE(reg_info[r]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4866 r++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4867 lowest_active_reg = r;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4868 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4869 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4870
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4871 /* If just failed to match something this time around with a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4872 group that's operated on by a repetition operator, try to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4873 force exit from the ``loop'', and restore the register
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4874 information for this group that we had before trying this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4875 last match. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4876 if ((!MATCHED_SOMETHING (reg_info[*p])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4877 || just_past_start_mem == p - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4878 && (p + 2) < pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4879 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4880 boolean is_a_jump_n = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4881
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4882 p1 = p + 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4883 mcnt = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4884 switch ((re_opcode_t) *p1++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4885 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4886 case jump_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4887 is_a_jump_n = true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4888 case pop_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4889 case maybe_pop_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4890 case jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4891 case dummy_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4892 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4893 if (is_a_jump_n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4894 p1 += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4895 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4896
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4897 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4898 /* do nothing */ ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4899 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4900 p1 += mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4901
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4902 /* If the next operation is a jump backwards in the pattern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4903 to an on_failure_jump right before the start_memory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4904 corresponding to this stop_memory, exit from the loop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4905 by forcing a failure after pushing on the stack the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4906 on_failure_jump's jump in the pattern, and d. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4907 if (mcnt < 0 && (re_opcode_t) *p1 == on_failure_jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4908 && (re_opcode_t) p1[3] == start_memory && p1[4] == *p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4909 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4910 /* If this group ever matched anything, then restore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4911 what its registers were before trying this last
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4912 failed match, e.g., with `(a*)*b' against `ab' for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4913 regstart[1], and, e.g., with `((a*)*(b*)*)*'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4914 against `aba' for regend[3].
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4915
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4916 Also restore the registers for inner groups for,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4917 e.g., `((a*)(b*))*' against `aba' (register 3 would
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4918 otherwise get trashed). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4919
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4920 if (EVER_MATCHED_SOMETHING (reg_info[*p]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4921 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4922 unsigned r;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4923
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4924 EVER_MATCHED_SOMETHING (reg_info[*p]) = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4925
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4926 /* Restore this and inner groups' (if any) registers. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4927 for (r = *p; r < *p + *(p + 1); r++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4928 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4929 regstart[r] = old_regstart[r];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4930
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4931 /* xx why this test? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4932 if (old_regend[r] >= regstart[r])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4933 regend[r] = old_regend[r];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4934 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4935 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4936 p1++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4937 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4938 PUSH_FAILURE_POINT (p1 + mcnt, d, -2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4939
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4940 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4941 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4942 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4944 /* Move past the register number and the inner group count. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4945 p += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4946 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4947
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4948
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4949 /* \<digit> has been turned into a `duplicate' command which is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4950 followed by the numeric value of <digit> as the register number. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4951 case duplicate:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4952 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4953 REGISTER const char *d2, *dend2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4954 int regno = *p++; /* Get which register to match against. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4955 DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4956
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4957 /* Can't back reference a group which we've never matched. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4958 if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4959 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4960
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4961 /* Where in input to try to start matching. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4962 d2 = regstart[regno];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4963
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4964 /* Where to stop matching; if both the place to start and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4965 the place to stop matching are in the same string, then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4966 set to the place to stop, otherwise, for now have to use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4967 the end of the first string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4968
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4969 dend2 = ((FIRST_STRING_P (regstart[regno])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4970 == FIRST_STRING_P (regend[regno]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4971 ? regend[regno] : end_match_1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4972 for (;;)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4973 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4974 /* If necessary, advance to next segment in register
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4975 contents. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4976 while (d2 == dend2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4977 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4978 if (dend2 == end_match_2) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4979 if (dend2 == regend[regno]) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4980
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4981 /* End of string1 => advance to string2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4982 d2 = string2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4983 dend2 = regend[regno];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4984 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4985 /* At end of register contents => success */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4986 if (d2 == dend2) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4987
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4988 /* If necessary, advance to next segment in data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4989 PREFETCH ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4990
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4991 /* How many characters left in this segment to match. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4992 mcnt = dend - d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4993
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4994 /* Want how many consecutive characters we can match in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4995 one shot, so, if necessary, adjust the count. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4996 if (mcnt > dend2 - d2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4997 mcnt = dend2 - d2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4999 /* Compare that many; failure if mismatch, else move
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5000 past them. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5001 if (translate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5002 ? bcmp_translate ((unsigned char *) d,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5003 (unsigned char *) d2, mcnt, translate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5004 : memcmp (d, d2, mcnt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5005 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5006 d += mcnt, d2 += mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5007
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5008 /* Do this because we've match some characters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5009 SET_REGS_MATCHED ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5010 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5011 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5012 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5013
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5014
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5015 /* begline matches the empty string at the beginning of the string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5016 (unless `not_bol' is set in `bufp'), and, if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5017 `newline_anchor' is set, after newlines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5018 case begline:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5019 DEBUG_PRINT1 ("EXECUTING begline.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5020
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5021 if (AT_STRINGS_BEG (d))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5022 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5023 if (!bufp->not_bol) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5024 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5025 else if (d[-1] == '\n' && bufp->newline_anchor)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5026 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5027 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5028 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5029 /* In all other cases, we fail. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5030 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5031
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5032
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5033 /* endline is the dual of begline. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5034 case endline:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5035 DEBUG_PRINT1 ("EXECUTING endline.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5036
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5037 if (AT_STRINGS_END (d))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5038 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5039 if (!bufp->not_eol) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5040 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5041
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5042 /* We have to ``prefetch'' the next character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5043 else if ((d == end1 ? *string2 : *d) == '\n'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5044 && bufp->newline_anchor)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5045 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5046 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5047 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5048 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5049
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5050
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5051 /* Match at the very beginning of the data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5052 case begbuf:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5053 DEBUG_PRINT1 ("EXECUTING begbuf.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5054 if (AT_STRINGS_BEG (d))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5055 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5056 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5057
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5058
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5059 /* Match at the very end of the data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5060 case endbuf:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5061 DEBUG_PRINT1 ("EXECUTING endbuf.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5062 if (AT_STRINGS_END (d))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5063 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5064 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5065
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5066
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5067 /* on_failure_keep_string_jump is used to optimize `.*\n'. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5068 pushes NULL as the value for the string on the stack. Then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5069 `pop_failure_point' will keep the current value for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5070 string, instead of restoring it. To see why, consider
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5071 matching `foo\nbar' against `.*\n'. The .* matches the foo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5072 then the . fails against the \n. But the next thing we want
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5073 to do is match the \n against the \n; if we restored the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5074 string value, we would be back at the foo.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5075
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5076 Because this is used only in specific cases, we don't need to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5077 check all the things that `on_failure_jump' does, to make
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5078 sure the right things get saved on the stack. Hence we don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5079 share its code. The only reason to push anything on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5080 stack at all is that otherwise we would have to change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5081 `anychar's code to do something besides goto fail in this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5082 case; that seems worse than this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5083 case on_failure_keep_string_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5084 DEBUG_PRINT1 ("EXECUTING on_failure_keep_string_jump");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5085
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5086 EXTRACT_NUMBER_AND_INCR (mcnt, p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5087 DEBUG_PRINT3 (" %d (to 0x%lx):\n", mcnt, (long) (p + mcnt));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5088
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5089 PUSH_FAILURE_POINT (p + mcnt, (char *) 0, -2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5090 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5091
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5092
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5093 /* Uses of on_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5094
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5095 Each alternative starts with an on_failure_jump that points
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5096 to the beginning of the next alternative. Each alternative
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5097 except the last ends with a jump that in effect jumps past
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5098 the rest of the alternatives. (They really jump to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5099 ending jump of the following alternative, because tensioning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5100 these jumps is a hassle.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5102 Repeats start with an on_failure_jump that points past both
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5103 the repetition text and either the following jump or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5104 pop_failure_jump back to this on_failure_jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5105 case on_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5106 on_failure:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5107 DEBUG_PRINT1 ("EXECUTING on_failure_jump");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5109 EXTRACT_NUMBER_AND_INCR (mcnt, p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5110 DEBUG_PRINT3 (" %d (to 0x%lx)", mcnt, (long) (p + mcnt));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5112 /* If this on_failure_jump comes right before a group (i.e.,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5113 the original * applied to a group), save the information
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5114 for that group and all inner ones, so that if we fail back
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5115 to this point, the group's information will be correct.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5116 For example, in \(a*\)*\1, we need the preceding group,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5117 and in \(\(a*\)b*\)\2, we need the inner group. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5119 /* We can't use `p' to check ahead because we push
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5120 a failure point to `p + mcnt' after we do this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5121 p1 = p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5122
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5123 /* We need to skip no_op's before we look for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5124 start_memory in case this on_failure_jump is happening as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5125 the result of a completed succeed_n, as in \(a\)\{1,3\}b\1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5126 against aba. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5127 while (p1 < pend && (re_opcode_t) *p1 == no_op)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5128 p1++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5130 if (p1 < pend && (re_opcode_t) *p1 == start_memory)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5131 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5132 /* We have a new highest active register now. This will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5133 get reset at the start_memory we are about to get to,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5134 but we will have saved all the registers relevant to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5135 this repetition op, as described above. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5136 highest_active_reg = *(p1 + 1) + *(p1 + 2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5137 if (lowest_active_reg == NO_LOWEST_ACTIVE_REG)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5138 lowest_active_reg = *(p1 + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5139 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5140
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5141 DEBUG_PRINT1 (":\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5142 PUSH_FAILURE_POINT (p + mcnt, d, -2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5143 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5144
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5146 /* A smart repeat ends with `maybe_pop_jump'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5147 We change it to either `pop_failure_jump' or `jump'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5148 case maybe_pop_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5149 EXTRACT_NUMBER_AND_INCR (mcnt, p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5150 DEBUG_PRINT2 ("EXECUTING maybe_pop_jump %d.\n", mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5151 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5152 REGISTER unsigned char *p2 = p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5154 /* Compare the beginning of the repeat with what in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5155 pattern follows its end. If we can establish that there
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5156 is nothing that they would both match, i.e., that we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5157 would have to backtrack because of (as in, e.g., `a*a')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5158 then we can change to pop_failure_jump, because we'll
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5159 never have to backtrack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5161 This is not true in the case of alternatives: in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5162 `(a|ab)*' we do need to backtrack to the `ab' alternative
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5163 (e.g., if the string was `ab'). But instead of trying to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5164 detect that here, the alternative has put on a dummy
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5165 failure point which is what we will end up popping. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5167 /* Skip over open/close-group commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5168 If what follows this loop is a ...+ construct,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5169 look at what begins its body, since we will have to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5170 match at least one of that. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5171 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5172 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5173 if (p2 + 2 < pend
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5174 && ((re_opcode_t) *p2 == stop_memory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5175 || (re_opcode_t) *p2 == start_memory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5176 p2 += 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5177 else if (p2 + 6 < pend
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5178 && (re_opcode_t) *p2 == dummy_failure_jump)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5179 p2 += 6;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5180 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5181 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5182 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5183
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5184 p1 = p + mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5185 /* p1[0] ... p1[2] are the `on_failure_jump' corresponding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5186 to the `maybe_finalize_jump' of this case. Examine what
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5187 follows. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5188
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5189 /* If we're at the end of the pattern, we can change. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5190 if (p2 == pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5191 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5192 /* Consider what happens when matching ":\(.*\)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5193 against ":/". I don't really understand this code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5194 yet. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5195 p[-3] = (unsigned char) pop_failure_jump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5196 DEBUG_PRINT1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5197 (" End of pattern: change to `pop_failure_jump'.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5198 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5200 else if ((re_opcode_t) *p2 == exactn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5201 || (bufp->newline_anchor && (re_opcode_t) *p2 == endline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5202 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5203 REGISTER unsigned char c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5204 = *p2 == (unsigned char) endline ? '\n' : p2[2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5205
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5206 if ((re_opcode_t) p1[3] == exactn && p1[5] != c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5207 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5208 p[-3] = (unsigned char) pop_failure_jump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5209 DEBUG_PRINT3 (" %c != %c => pop_failure_jump.\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5210 c, p1[5]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5211 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5212
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5213 else if ((re_opcode_t) p1[3] == charset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5214 || (re_opcode_t) p1[3] == charset_not)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5215 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5216 int not = (re_opcode_t) p1[3] == charset_not;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5217
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5218 if (c < (unsigned char) (p1[4] * BYTEWIDTH)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5219 && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5220 not = !not;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5222 /* `not' is equal to 1 if c would match, which means
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5223 that we can't change to pop_failure_jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5224 if (!not)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5225 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5226 p[-3] = (unsigned char) pop_failure_jump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5227 DEBUG_PRINT1 (" No match => pop_failure_jump.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5228 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5229 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5230 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5231 else if ((re_opcode_t) *p2 == charset)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5232 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5233 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5234 REGISTER unsigned char c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5235 = *p2 == (unsigned char) endline ? '\n' : p2[2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5236 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5237
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5238 if ((re_opcode_t) p1[3] == exactn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5239 && ! ((int) p2[1] * BYTEWIDTH > (int) p1[5]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5240 && (p2[2 + p1[5] / BYTEWIDTH]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5241 & (1 << (p1[5] % BYTEWIDTH)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5242 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5243 p[-3] = (unsigned char) pop_failure_jump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5244 DEBUG_PRINT3 (" %c != %c => pop_failure_jump.\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5245 c, p1[5]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5246 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5248 else if ((re_opcode_t) p1[3] == charset_not)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5249 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5250 int idx;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5251 /* We win if the charset_not inside the loop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5252 lists every character listed in the charset after. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5253 for (idx = 0; idx < (int) p2[1]; idx++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5254 if (! (p2[2 + idx] == 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5255 || (idx < (int) p1[4]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5256 && ((p2[2 + idx] & ~ p1[5 + idx]) == 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5257 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5259 if (idx == p2[1])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5260 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5261 p[-3] = (unsigned char) pop_failure_jump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5262 DEBUG_PRINT1 (" No match => pop_failure_jump.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5263 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5264 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5265 else if ((re_opcode_t) p1[3] == charset)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5266 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5267 int idx;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5268 /* We win if the charset inside the loop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5269 has no overlap with the one after the loop. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5270 for (idx = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5271 idx < (int) p2[1] && idx < (int) p1[4];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5272 idx++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5273 if ((p2[2 + idx] & p1[5 + idx]) != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5274 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5276 if (idx == p2[1] || idx == p1[4])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5277 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5278 p[-3] = (unsigned char) pop_failure_jump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5279 DEBUG_PRINT1 (" No match => pop_failure_jump.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5280 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5281 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5282 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5283 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5284 p -= 2; /* Point at relative address again. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5285 if ((re_opcode_t) p[-1] != pop_failure_jump)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5286 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5287 p[-1] = (unsigned char) jump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5288 DEBUG_PRINT1 (" Match => jump.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5289 goto unconditional_jump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5290 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5291 /* Note fall through. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5292
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5294 /* The end of a simple repeat has a pop_failure_jump back to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5295 its matching on_failure_jump, where the latter will push a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5296 failure point. The pop_failure_jump takes off failure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5297 points put on by this pop_failure_jump's matching
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5298 on_failure_jump; we got through the pattern to here from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5299 matching on_failure_jump, so didn't fail. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5300 case pop_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5301 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5302 /* We need to pass separate storage for the lowest and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5303 highest registers, even though we don't care about the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5304 actual values. Otherwise, we will restore only one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5305 register from the stack, since lowest will == highest in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5306 `pop_failure_point'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5307 unsigned dummy_low_reg, dummy_high_reg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5308 unsigned char *pdummy;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5309 const char *sdummy = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5311 DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5312 POP_FAILURE_POINT (sdummy, pdummy,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5313 dummy_low_reg, dummy_high_reg,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5314 reg_dummy, reg_dummy, reg_info_dummy);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5315 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5316 /* Note fall through. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5318
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5319 /* Unconditionally jump (without popping any failure points). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5320 case jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5321 unconditional_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5322 EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5323 DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5324 p += mcnt; /* Do the jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5325 DEBUG_PRINT2 ("(to 0x%lx).\n", (long) p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5326 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5329 /* We need this opcode so we can detect where alternatives end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5330 in `group_match_null_string_p' et al. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5331 case jump_past_alt:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5332 DEBUG_PRINT1 ("EXECUTING jump_past_alt.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5333 goto unconditional_jump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5334
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5335
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5336 /* Normally, the on_failure_jump pushes a failure point, which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5337 then gets popped at pop_failure_jump. We will end up at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5338 pop_failure_jump, also, and with a pattern of, say, `a+', we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5339 are skipping over the on_failure_jump, so we have to push
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5340 something meaningless for pop_failure_jump to pop. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5341 case dummy_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5342 DEBUG_PRINT1 ("EXECUTING dummy_failure_jump.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5343 /* It doesn't matter what we push for the string here. What
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5344 the code at `fail' tests is the value for the pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5345 PUSH_FAILURE_POINT ((unsigned char *) 0, (char *) 0, -2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5346 goto unconditional_jump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5347
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5348
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5349 /* At the end of an alternative, we need to push a dummy failure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5350 point in case we are followed by a `pop_failure_jump', because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5351 we don't want the failure point for the alternative to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5352 popped. For example, matching `(a|ab)*' against `aab'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5353 requires that we match the `ab' alternative. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5354 case push_dummy_failure:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5355 DEBUG_PRINT1 ("EXECUTING push_dummy_failure.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5356 /* See comments just above at `dummy_failure_jump' about the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5357 two zeroes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5358 PUSH_FAILURE_POINT ((unsigned char *) 0, (char *) 0, -2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5359 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5360
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5361 /* Have to succeed matching what follows at least n times.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5362 After that, handle like `on_failure_jump'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5363 case succeed_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5364 EXTRACT_NUMBER (mcnt, p + 2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5365 DEBUG_PRINT2 ("EXECUTING succeed_n %d.\n", mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5367 assert (mcnt >= 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5368 /* Originally, this is how many times we HAVE to succeed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5369 if (mcnt > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5370 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5371 mcnt--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5372 p += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5373 STORE_NUMBER_AND_INCR (p, mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5374 DEBUG_PRINT3 (" Setting 0x%lx to %d.\n", (long) p, mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5375 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5376 else if (mcnt == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5377 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5378 DEBUG_PRINT2 (" Setting two bytes from 0x%lx to no_op.\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5379 (long) (p+2));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5380 p[2] = (unsigned char) no_op;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5381 p[3] = (unsigned char) no_op;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5382 goto on_failure;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5383 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5384 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5385
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5386 case jump_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5387 EXTRACT_NUMBER (mcnt, p + 2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5388 DEBUG_PRINT2 ("EXECUTING jump_n %d.\n", mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5389
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5390 /* Originally, this is how many times we CAN jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5391 if (mcnt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5392 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5393 mcnt--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5394 STORE_NUMBER (p + 2, mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5395 goto unconditional_jump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5396 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5397 /* If don't have to jump any more, skip over the rest of command. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5398 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5399 p += 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5400 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5402 case set_number_at:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5403 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5404 DEBUG_PRINT1 ("EXECUTING set_number_at.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5406 EXTRACT_NUMBER_AND_INCR (mcnt, p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5407 p1 = p + mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5408 EXTRACT_NUMBER_AND_INCR (mcnt, p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5409 DEBUG_PRINT3 (" Setting 0x%lx to %d.\n", (long) p1, mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5410 STORE_NUMBER (p1, mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5411 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5412 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5414 case wordbound:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5415 DEBUG_PRINT1 ("EXECUTING wordbound.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5416 should_succeed = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5417 matchwordbound:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5418 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5419 /* XEmacs change */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5420 int result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5421 if (AT_STRINGS_BEG (d) || AT_STRINGS_END (d))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5422 result = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5423 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5424 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5425 const unsigned char *d_before =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5426 (const unsigned char *) POS_BEFORE_GAP_UNSAFE (d);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5427 const unsigned char *d_after =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5428 (const unsigned char *) POS_AFTER_GAP_UNSAFE (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5429 Emchar emch1, emch2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5430
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5431 DEC_CHARPTR (d_before);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5432 emch1 = charptr_emchar (d_before);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5433 emch2 = charptr_emchar (d_after);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5434 result = (WORDCHAR_P_UNSAFE (emch1) !=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5435 WORDCHAR_P_UNSAFE (emch2));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5436 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5437 if (result == should_succeed)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5438 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5439 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5440 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5441
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5442 case notwordbound:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5443 DEBUG_PRINT1 ("EXECUTING notwordbound.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5444 should_succeed = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5445 goto matchwordbound;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5446
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5447 case wordbeg:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5448 DEBUG_PRINT1 ("EXECUTING wordbeg.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5449 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5450 /* XEmacs: this originally read:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5452 if (WORDCHAR_P (d) && (AT_STRINGS_BEG (d) || !WORDCHAR_P (d - 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5453 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5454
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5455 */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5456 const unsigned char *dtmp =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5457 (const unsigned char *) POS_AFTER_GAP_UNSAFE (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5458 Emchar emch = charptr_emchar (dtmp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5459 if (!WORDCHAR_P_UNSAFE (emch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5460 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5461 if (AT_STRINGS_BEG (d))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5462 break;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5463 dtmp = (const unsigned char *) POS_BEFORE_GAP_UNSAFE (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5464 DEC_CHARPTR (dtmp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5465 emch = charptr_emchar (dtmp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5466 if (!WORDCHAR_P_UNSAFE (emch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5467 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5468 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5469 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5470
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5471 case wordend:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5472 DEBUG_PRINT1 ("EXECUTING wordend.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5473 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5474 /* XEmacs: this originally read:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5475
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5476 if (!AT_STRINGS_BEG (d) && WORDCHAR_P (d - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5477 && (!WORDCHAR_P (d) || AT_STRINGS_END (d)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5478 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5479
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5480 The or condition is incorrect (reversed).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5481 */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5482 const unsigned char *dtmp;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5483 Emchar emch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5484 if (AT_STRINGS_BEG (d))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5485 goto fail;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5486 dtmp = (const unsigned char *) POS_BEFORE_GAP_UNSAFE (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5487 DEC_CHARPTR (dtmp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5488 emch = charptr_emchar (dtmp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5489 if (!WORDCHAR_P_UNSAFE (emch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5490 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5491 if (AT_STRINGS_END (d))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5492 break;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5493 dtmp = (const unsigned char *) POS_AFTER_GAP_UNSAFE (d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5494 emch = charptr_emchar (dtmp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5495 if (!WORDCHAR_P_UNSAFE (emch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5496 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5497 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5498 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5499
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5500 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5501 case before_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5502 DEBUG_PRINT1 ("EXECUTING before_dot.\n");
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5503 if (!regex_emacs_buffer_p
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5504 || (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5505 >= BUF_PT (regex_emacs_buffer)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5506 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5507 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5508
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5509 case at_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5510 DEBUG_PRINT1 ("EXECUTING at_dot.\n");
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5511 if (!regex_emacs_buffer_p
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5512 || (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5513 != BUF_PT (regex_emacs_buffer)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5514 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5515 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5516
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5517 case after_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5518 DEBUG_PRINT1 ("EXECUTING after_dot.\n");
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5519 if (!regex_emacs_buffer_p
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5520 || (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5521 <= BUF_PT (regex_emacs_buffer)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5522 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5523 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5524 #if 0 /* not emacs19 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5525 case at_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5526 DEBUG_PRINT1 ("EXECUTING at_dot.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5527 if (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d) + 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5528 != BUF_PT (regex_emacs_buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5529 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5530 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5531 #endif /* not emacs19 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5532
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5533 case syntaxspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5534 DEBUG_PRINT2 ("EXECUTING syntaxspec %d.\n", mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5535 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5536 goto matchsyntax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5537
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5538 case wordchar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5539 DEBUG_PRINT1 ("EXECUTING Emacs wordchar.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5540 mcnt = (int) Sword;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5541 matchsyntax:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5542 should_succeed = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5543 matchornotsyntax:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5544 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5545 int matches;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5546 Emchar emch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5547
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5548 PREFETCH ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5549 emch = charptr_emchar ((const Bufbyte *) d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5550 matches = (SYNTAX_UNSAFE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5551 (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5552 emch) == (enum syntaxcode) mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5553 INC_CHARPTR (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5554 if (matches != should_succeed)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5555 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5556 SET_REGS_MATCHED ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5557 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5558 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5560 case notsyntaxspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5561 DEBUG_PRINT2 ("EXECUTING notsyntaxspec %d.\n", mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5562 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5563 goto matchnotsyntax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5565 case notwordchar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5566 DEBUG_PRINT1 ("EXECUTING Emacs notwordchar.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5567 mcnt = (int) Sword;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5568 matchnotsyntax:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5569 should_succeed = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5570 goto matchornotsyntax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5571
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5572 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5573 /* 97/2/17 jhod Mule category code patch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5574 case categoryspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5575 should_succeed = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5576 matchornotcategory:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5577 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5578 Emchar emch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5579
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5580 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5581 PREFETCH ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5582 emch = charptr_emchar ((const Bufbyte *) d);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5583 INC_CHARPTR (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5584 if (check_category_char(emch, regex_emacs_buffer->category_table,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5585 mcnt, should_succeed))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5586 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5587 SET_REGS_MATCHED ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5588 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5589 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5590
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5591 case notcategoryspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5592 should_succeed = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5593 goto matchornotcategory;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5594 /* end of category patch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5595 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5596 #else /* not emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5597 case wordchar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5598 DEBUG_PRINT1 ("EXECUTING non-Emacs wordchar.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5599 PREFETCH ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5600 if (!WORDCHAR_P_UNSAFE ((int) (*d)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5601 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5602 SET_REGS_MATCHED ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5603 d++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5604 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5605
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5606 case notwordchar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5607 DEBUG_PRINT1 ("EXECUTING non-Emacs notwordchar.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5608 PREFETCH ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5609 if (!WORDCHAR_P_UNSAFE ((int) (*d)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5610 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5611 SET_REGS_MATCHED ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5612 d++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5613 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5614 #endif /* not emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5615
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5616 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5617 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5618 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5619 continue; /* Successfully executed one pattern command; keep going. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5620
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5621
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5622 /* We goto here if a matching operation fails. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5623 fail:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5624 if (!FAIL_STACK_EMPTY ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5625 { /* A restart point is known. Restore to that state. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5626 DEBUG_PRINT1 ("\nFAIL:\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5627 POP_FAILURE_POINT (d, p,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5628 lowest_active_reg, highest_active_reg,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5629 regstart, regend, reg_info);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5631 /* If this failure point is a dummy, try the next one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5632 if (!p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5633 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5634
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5635 /* If we failed to the end of the pattern, don't examine *p. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5636 assert (p <= pend);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5637 if (p < pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5638 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5639 boolean is_a_jump_n = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5641 /* If failed to a backwards jump that's part of a repetition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5642 loop, need to pop this failure point and use the next one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5643 switch ((re_opcode_t) *p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5644 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5645 case jump_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5646 is_a_jump_n = true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5647 case maybe_pop_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5648 case pop_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5649 case jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5650 p1 = p + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5651 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5652 p1 += mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5653
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5654 if ((is_a_jump_n && (re_opcode_t) *p1 == succeed_n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5655 || (!is_a_jump_n
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5656 && (re_opcode_t) *p1 == on_failure_jump))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5657 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5658 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5659 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5660 /* do nothing */ ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5661 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5662 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5663
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5664 if (d >= string1 && d <= end1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5665 dend = end_match_1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5666 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5667 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5668 break; /* Matching at this starting point really fails. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5669 } /* for (;;) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5671 if (best_regs_set)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5672 goto restore_best_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5673
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5674 FREE_VARIABLES ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5675
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5676 return -1; /* Failure to match. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5677 } /* re_match_2 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5678
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5679 /* Subroutine definitions for re_match_2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5680
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5681
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5682 /* We are passed P pointing to a register number after a start_memory.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5683
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5684 Return true if the pattern up to the corresponding stop_memory can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5685 match the empty string, and false otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5686
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5687 If we find the matching stop_memory, sets P to point to one past its number.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5688 Otherwise, sets P to an undefined byte less than or equal to END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5689
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5690 We don't handle duplicates properly (yet). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5691
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5692 static boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5693 group_match_null_string_p (unsigned char **p, unsigned char *end,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5694 register_info_type *reg_info)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5695 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5696 int mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5697 /* Point to after the args to the start_memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5698 unsigned char *p1 = *p + 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5699
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5700 while (p1 < end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5701 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5702 /* Skip over opcodes that can match nothing, and return true or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5703 false, as appropriate, when we get to one that can't, or to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5704 matching stop_memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5706 switch ((re_opcode_t) *p1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5707 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5708 /* Could be either a loop or a series of alternatives. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5709 case on_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5710 p1++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5711 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5712
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5713 /* If the next operation is not a jump backwards in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5714 pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5715
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5716 if (mcnt >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5717 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5718 /* Go through the on_failure_jumps of the alternatives,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5719 seeing if any of the alternatives cannot match nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5720 The last alternative starts with only a jump,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5721 whereas the rest start with on_failure_jump and end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5722 with a jump, e.g., here is the pattern for `a|b|c':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5723
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5724 /on_failure_jump/0/6/exactn/1/a/jump_past_alt/0/6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5725 /on_failure_jump/0/6/exactn/1/b/jump_past_alt/0/3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5726 /exactn/1/c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5727
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5728 So, we have to first go through the first (n-1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5729 alternatives and then deal with the last one separately. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5731
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5732 /* Deal with the first (n-1) alternatives, which start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5733 with an on_failure_jump (see above) that jumps to right
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5734 past a jump_past_alt. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5735
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5736 while ((re_opcode_t) p1[mcnt-3] == jump_past_alt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5737 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5738 /* `mcnt' holds how many bytes long the alternative
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5739 is, including the ending `jump_past_alt' and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5740 its number. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5741
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5742 if (!alt_match_null_string_p (p1, p1 + mcnt - 3,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5743 reg_info))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5744 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5745
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5746 /* Move to right after this alternative, including the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5747 jump_past_alt. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5748 p1 += mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5749
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5750 /* Break if it's the beginning of an n-th alternative
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5751 that doesn't begin with an on_failure_jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5752 if ((re_opcode_t) *p1 != on_failure_jump)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5753 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5754
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5755 /* Still have to check that it's not an n-th
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5756 alternative that starts with an on_failure_jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5757 p1++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5758 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5759 if ((re_opcode_t) p1[mcnt-3] != jump_past_alt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5760 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5761 /* Get to the beginning of the n-th alternative. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5762 p1 -= 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5763 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5764 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5765 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5766
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5767 /* Deal with the last alternative: go back and get number
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5768 of the `jump_past_alt' just before it. `mcnt' contains
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5769 the length of the alternative. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5770 EXTRACT_NUMBER (mcnt, p1 - 2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5771
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5772 if (!alt_match_null_string_p (p1, p1 + mcnt, reg_info))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5773 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5774
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5775 p1 += mcnt; /* Get past the n-th alternative. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5776 } /* if mcnt > 0 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5777 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5778
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5779
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5780 case stop_memory:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5781 assert (p1[1] == **p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5782 *p = p1 + 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5783 return true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5785
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5786 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5787 if (!common_op_match_null_string_p (&p1, end, reg_info))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5788 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5789 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5790 } /* while p1 < end */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5791
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5792 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5793 } /* group_match_null_string_p */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5794
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5795
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5796 /* Similar to group_match_null_string_p, but doesn't deal with alternatives:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5797 It expects P to be the first byte of a single alternative and END one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5798 byte past the last. The alternative can contain groups. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5799
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5800 static boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5801 alt_match_null_string_p (unsigned char *p, unsigned char *end,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5802 register_info_type *reg_info)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5803 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5804 int mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5805 unsigned char *p1 = p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5806
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5807 while (p1 < end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5808 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5809 /* Skip over opcodes that can match nothing, and break when we get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5810 to one that can't. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5811
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5812 switch ((re_opcode_t) *p1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5813 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5814 /* It's a loop. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5815 case on_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5816 p1++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5817 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5818 p1 += mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5819 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5820
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5821 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5822 if (!common_op_match_null_string_p (&p1, end, reg_info))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5823 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5824 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5825 } /* while p1 < end */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5826
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5827 return true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5828 } /* alt_match_null_string_p */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5829
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5830
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5831 /* Deals with the ops common to group_match_null_string_p and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5832 alt_match_null_string_p.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5833
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5834 Sets P to one after the op and its arguments, if any. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5835
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5836 static boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5837 common_op_match_null_string_p (unsigned char **p, unsigned char *end,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5838 register_info_type *reg_info)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5839 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5840 int mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5841 boolean ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5842 int reg_no;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5843 unsigned char *p1 = *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5844
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5845 switch ((re_opcode_t) *p1++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5846 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5847 case no_op:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5848 case begline:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5849 case endline:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5850 case begbuf:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5851 case endbuf:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5852 case wordbeg:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5853 case wordend:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5854 case wordbound:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5855 case notwordbound:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5856 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5857 case before_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5858 case at_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5859 case after_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5860 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5861 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5863 case start_memory:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5864 reg_no = *p1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5865 assert (reg_no > 0 && reg_no <= MAX_REGNUM);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5866 ret = group_match_null_string_p (&p1, end, reg_info);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5867
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5868 /* Have to set this here in case we're checking a group which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5869 contains a group and a back reference to it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5870
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5871 if (REG_MATCH_NULL_STRING_P (reg_info[reg_no]) == MATCH_NULL_UNSET_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5872 REG_MATCH_NULL_STRING_P (reg_info[reg_no]) = ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5873
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5874 if (!ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5875 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5876 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5877
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5878 /* If this is an optimized succeed_n for zero times, make the jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5879 case jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5880 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5881 if (mcnt >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5882 p1 += mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5883 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5884 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5885 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5886
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5887 case succeed_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5888 /* Get to the number of times to succeed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5889 p1 += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5890 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5891
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5892 if (mcnt == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5893 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5894 p1 -= 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5895 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5896 p1 += mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5897 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5898 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5899 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5900 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5901
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5902 case duplicate:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5903 if (!REG_MATCH_NULL_STRING_P (reg_info[*p1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5904 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5905 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5906
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5907 case set_number_at:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5908 p1 += 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5909
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5910 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5911 /* All other opcodes mean we cannot match the empty string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5912 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5913 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5914
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5915 *p = p1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5916 return true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5917 } /* common_op_match_null_string_p */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5918
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5919
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5920 /* Return zero if TRANSLATE[S1] and TRANSLATE[S2] are identical for LEN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5921 bytes; nonzero otherwise. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5922
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5923 static int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5924 bcmp_translate (const unsigned char *s1, const unsigned char *s2,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5925 REGISTER int len, char *translate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5926 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5927 REGISTER const unsigned char *p1 = s1, *p2 = s2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5928 while (len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5929 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5930 if (translate[*p1++] != translate[*p2++]) return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5931 len--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5932 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5933 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5934 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5935
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5936 /* Entry points for GNU code. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5937
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5938 /* re_compile_pattern is the GNU regular expression compiler: it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5939 compiles PATTERN (of length SIZE) and puts the result in BUFP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5940 Returns 0 if the pattern was valid, otherwise an error string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5941
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5942 Assumes the `allocated' (and perhaps `buffer') and `translate' fields
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5943 are set in BUFP on entry.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5944
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5945 We call regex_compile to do the actual compilation. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5946
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5947 const char *
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5948 re_compile_pattern (const char *pattern, int length,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5949 struct re_pattern_buffer *bufp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5950 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5951 reg_errcode_t ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5952
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5953 /* GNU code is written to assume at least RE_NREGS registers will be set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5954 (and at least one extra will be -1). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5955 bufp->regs_allocated = REGS_UNALLOCATED;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5956
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5957 /* And GNU code determines whether or not to get register information
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5958 by passing null for the REGS argument to re_match, etc., not by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5959 setting no_sub. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5960 bufp->no_sub = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5961
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5962 /* Match anchors at newline. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5963 bufp->newline_anchor = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5964
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5965 ret = regex_compile (pattern, length, re_syntax_options, bufp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5966
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5967 if (!ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5968 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5969 return gettext (re_error_msgid[(int) ret]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5970 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5971
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5972 /* Entry points compatible with 4.2 BSD regex library. We don't define
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5973 them unless specifically requested. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5974
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5975 #ifdef _REGEX_RE_COMP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5976
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5977 /* BSD has one and only one pattern buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5978 static struct re_pattern_buffer re_comp_buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5979
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5980 char *
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5981 re_comp (const char *s)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5982 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5983 reg_errcode_t ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5984
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5985 if (!s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5986 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5987 if (!re_comp_buf.buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5988 return gettext ("No previous regular expression");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5989 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5990 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5991
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5992 if (!re_comp_buf.buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5993 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5994 re_comp_buf.buffer = (unsigned char *) malloc (200);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5995 if (re_comp_buf.buffer == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5996 return gettext (re_error_msgid[(int) REG_ESPACE]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5997 re_comp_buf.allocated = 200;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5999 re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6000 if (re_comp_buf.fastmap == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6001 return gettext (re_error_msgid[(int) REG_ESPACE]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6002 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6003
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6004 /* Since `re_exec' always passes NULL for the `regs' argument, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6005 don't need to initialize the pattern buffer fields which affect it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6006
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6007 /* Match anchors at newlines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6008 re_comp_buf.newline_anchor = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6009
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6010 ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6011
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6012 if (!ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6013 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6014
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6015 /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6016 return (char *) gettext (re_error_msgid[(int) ret]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6017 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6018
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6019
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6020 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6021 re_exec (const char *s)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6022 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6023 const int len = strlen (s);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6024 return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6025 0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6026 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6027 #endif /* _REGEX_RE_COMP */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6028
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6029 /* POSIX.2 functions. Don't define these for Emacs. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6030
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6031 #ifndef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6032
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6033 /* regcomp takes a regular expression as a string and compiles it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6034
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6035 PREG is a regex_t *. We do not expect any fields to be initialized,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6036 since POSIX says we shouldn't. Thus, we set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6037
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6038 `buffer' to the compiled pattern;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6039 `used' to the length of the compiled pattern;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6040 `syntax' to RE_SYNTAX_POSIX_EXTENDED if the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6041 REG_EXTENDED bit in CFLAGS is set; otherwise, to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6042 RE_SYNTAX_POSIX_BASIC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6043 `newline_anchor' to REG_NEWLINE being set in CFLAGS;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6044 `fastmap' and `fastmap_accurate' to zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6045 `re_nsub' to the number of subexpressions in PATTERN.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6046
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6047 PATTERN is the address of the pattern string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6048
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6049 CFLAGS is a series of bits which affect compilation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6050
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6051 If REG_EXTENDED is set, we use POSIX extended syntax; otherwise, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6052 use POSIX basic syntax.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6053
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6054 If REG_NEWLINE is set, then . and [^...] don't match newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6055 Also, regexec will try a match beginning after every newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6056
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6057 If REG_ICASE is set, then we considers upper- and lowercase
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6058 versions of letters to be equivalent when matching.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6059
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6060 If REG_NOSUB is set, then when PREG is passed to regexec, that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6061 routine will report only success or failure, and nothing about the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6062 registers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6063
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6064 It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6065 the return codes and their meanings.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6066
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6067 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6068 regcomp (regex_t *preg, const char *pattern, int cflags)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6069 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6070 reg_errcode_t ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6071 unsigned syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6072 = (cflags & REG_EXTENDED) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6073 RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6074
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6075 /* regex_compile will allocate the space for the compiled pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6076 preg->buffer = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6077 preg->allocated = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6078 preg->used = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6079
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6080 /* Don't bother to use a fastmap when searching. This simplifies the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6081 REG_NEWLINE case: if we used a fastmap, we'd have to put all the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6082 characters after newlines into the fastmap. This way, we just try
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6083 every character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6084 preg->fastmap = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6085
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6086 if (cflags & REG_ICASE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6087 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6088 unsigned i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6089
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6090 preg->translate = (char *) malloc (CHAR_SET_SIZE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6091 if (preg->translate == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6092 return (int) REG_ESPACE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6093
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6094 /* Map uppercase characters to corresponding lowercase ones. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6095 for (i = 0; i < CHAR_SET_SIZE; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6096 preg->translate[i] = ISUPPER (i) ? tolower (i) : i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6097 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6098 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6099 preg->translate = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6101 /* If REG_NEWLINE is set, newlines are treated differently. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6102 if (cflags & REG_NEWLINE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6103 { /* REG_NEWLINE implies neither . nor [^...] match newline. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6104 syntax &= ~RE_DOT_NEWLINE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6105 syntax |= RE_HAT_LISTS_NOT_NEWLINE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6106 /* It also changes the matching behavior. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6107 preg->newline_anchor = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6108 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6109 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6110 preg->newline_anchor = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6112 preg->no_sub = !!(cflags & REG_NOSUB);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6114 /* POSIX says a null character in the pattern terminates it, so we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6115 can use strlen here in compiling the pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6116 ret = regex_compile (pattern, strlen (pattern), syntax, preg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6118 /* POSIX doesn't distinguish between an unmatched open-group and an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6119 unmatched close-group: both are REG_EPAREN. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6120 if (ret == REG_ERPAREN) ret = REG_EPAREN;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6122 return (int) ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6123 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6126 /* regexec searches for a given pattern, specified by PREG, in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6127 string STRING.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6129 If NMATCH is zero or REG_NOSUB was set in the cflags argument to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6130 `regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6131 least NMATCH elements, and we set them to the offsets of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6132 corresponding matched substrings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6134 EFLAGS specifies `execution flags' which affect matching: if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6135 REG_NOTBOL is set, then ^ does not match at the beginning of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6136 string; if REG_NOTEOL is set, then $ does not match at the end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6138 We return 0 if we find a match and REG_NOMATCH if not. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6140 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6141 regexec (const regex_t *preg, const char *string, size_t nmatch,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6142 regmatch_t pmatch[], int eflags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6143 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6144 int ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6145 struct re_registers regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6146 regex_t private_preg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6147 int len = strlen (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6148 boolean want_reg_info = !preg->no_sub && nmatch > 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6149
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6150 private_preg = *preg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6151
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6152 private_preg.not_bol = !!(eflags & REG_NOTBOL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6153 private_preg.not_eol = !!(eflags & REG_NOTEOL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6155 /* The user has told us exactly how many registers to return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6156 information about, via `nmatch'. We have to pass that on to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6157 matching routines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6158 private_preg.regs_allocated = REGS_FIXED;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6160 if (want_reg_info)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6161 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6162 regs.num_regs = nmatch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6163 regs.start = TALLOC (nmatch, regoff_t);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6164 regs.end = TALLOC (nmatch, regoff_t);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6165 if (regs.start == NULL || regs.end == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6166 return (int) REG_NOMATCH;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6167 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6169 /* Perform the searching operation. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6170 ret = re_search (&private_preg, string, len,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6171 /* start: */ 0, /* range: */ len,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6172 want_reg_info ? &regs : (struct re_registers *) 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6173
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6174 /* Copy the register information to the POSIX structure. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6175 if (want_reg_info)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6176 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6177 if (ret >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6178 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6179 unsigned r;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6181 for (r = 0; r < nmatch; r++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6182 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6183 pmatch[r].rm_so = regs.start[r];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6184 pmatch[r].rm_eo = regs.end[r];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6185 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6186 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6188 /* If we needed the temporary register info, free the space now. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6189 free (regs.start);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6190 free (regs.end);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6191 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6192
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6193 /* We want zero return to mean success, unlike `re_search'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6194 return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6195 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6197
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6198 /* Returns a message corresponding to an error code, ERRCODE, returned
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6199 from either regcomp or regexec. We don't use PREG here. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6200
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6201 size_t
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6202 regerror (int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6203 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6204 const char *msg;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6205 size_t msg_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6206
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6207 if (errcode < 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6208 || errcode >= (sizeof (re_error_msgid) / sizeof (re_error_msgid[0])))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6209 /* Only error codes returned by the rest of the code should be passed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6210 to this routine. If we are given anything else, or if other regex
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6211 code generates an invalid error code, then the program has a bug.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6212 Dump core so we can fix it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6213 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6215 msg = gettext (re_error_msgid[errcode]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6216
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6217 msg_size = strlen (msg) + 1; /* Includes the null. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6219 if (errbuf_size != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6220 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6221 if (msg_size > errbuf_size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6222 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6223 strncpy (errbuf, msg, errbuf_size - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6224 errbuf[errbuf_size - 1] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6225 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6226 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6227 strcpy (errbuf, msg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6228 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6230 return msg_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6231 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6233
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6234 /* Free dynamically allocated space used by PREG. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6236 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6237 regfree (regex_t *preg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6238 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6239 if (preg->buffer != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6240 free (preg->buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6241 preg->buffer = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6243 preg->allocated = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6244 preg->used = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6246 if (preg->fastmap != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6247 free (preg->fastmap);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6248 preg->fastmap = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6249 preg->fastmap_accurate = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6251 if (preg->translate != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6252 free (preg->translate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6253 preg->translate = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6254 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6256 #endif /* not emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6258 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6259 Local variables:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6260 make-backup-files: t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6261 version-control: t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6262 trim-versions-without-asking: nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6263 End:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6264 */