annotate src/regex.c @ 5534:68db75473fc6

Merge.
author Mats Lidell <mats.lidell@cag.se>
date Sun, 07 Aug 2011 23:22:59 +0200
parents 308d34e9f07d
children 3f4a234f4672
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.
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
8 Copyright (C) 1995, 2001, 2002, 2003, 2010 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5041
diff changeset
10 This file is part of XEmacs.
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5041
diff changeset
11
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5041
diff changeset
12 XEmacs is free software: you can redistribute it and/or modify it
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5041
diff changeset
13 under the terms of the GNU General Public License as published by the
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5041
diff changeset
14 Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5041
diff changeset
15 option) any later version.
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5041
diff changeset
16
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5041
diff changeset
17 XEmacs is distributed in the hope that it will be useful, but WITHOUT
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5041
diff changeset
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5041
diff changeset
19 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5041
diff changeset
20 for more details.
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5041
diff changeset
21
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5041
diff changeset
23 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 /* Synched up with: FSF 19.29. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 #ifdef HAVE_CONFIG_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 #ifndef _GNU_SOURCE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #define _GNU_SOURCE 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 /* We assume non-Mule if emacs isn't defined. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #ifndef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 #undef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
39 /* XEmacs addition */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
40 #ifdef REL_ALLOC
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
41 #define REGEX_REL_ALLOC /* may be undefined below */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
42 #endif
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
43
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 /* XEmacs: define this to add in a speedup for patterns anchored at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 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
46 tell where/why this code has diverged from v19. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 #define REGEX_BEGLINE_CHECK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 /* XEmacs: the current mmap-based ralloc handles small blocks very
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 poorly, so we disable it here. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
52 #if defined (HAVE_MMAP) || defined (DOUG_LEA_MALLOC)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
53 # undef REGEX_REL_ALLOC
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 /* The `emacs' switch turns on certain matching commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 that make sense only in Emacs. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 #include "syntax.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 #if (defined (DEBUG_XEMACS) && !defined (DEBUG))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 #define DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
68 #define RE_TRANSLATE_1(ch) TRT_TABLE_OF (translate, (Ichar) ch)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
69 #define TRANSLATE_P(tr) (!NILP (tr))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
71 /* Converts the pointer to the char to BEG-based offset from the start. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
72 #define PTR_TO_OFFSET(d) (MATCHING_IN_FIRST_STRING \
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
73 ? (d) - string1 : (d) - (string2 - size1))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
74
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 #else /* not emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2333
diff changeset
77 #include <stdlib.h>
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2333
diff changeset
78 #include <sys/types.h>
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2333
diff changeset
79 #include <stddef.h> /* needed for ptrdiff_t under Solaris */
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2333
diff changeset
80 #include <string.h>
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2333
diff changeset
81
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2201
diff changeset
82 #include "compiler.h" /* Get compiler-specific definitions like UNUSED */
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2201
diff changeset
83
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2421
diff changeset
84 #define ABORT abort
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2421
diff changeset
85
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 /* If we are not linking with Emacs proper,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 we can't use the relocating allocator
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 even if config.h says that we can. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
89 #undef REGEX_REL_ALLOC
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90
544
ffd4d00ff0b6 [xemacs-hg @ 2001-05-17 13:55:46 by stephent]
stephent
parents: 523
diff changeset
91 /* defined in lisp.h */
ffd4d00ff0b6 [xemacs-hg @ 2001-05-17 13:55:46 by stephent]
stephent
parents: 523
diff changeset
92 #ifdef REGEX_MALLOC
ffd4d00ff0b6 [xemacs-hg @ 2001-05-17 13:55:46 by stephent]
stephent
parents: 523
diff changeset
93 #ifndef DECLARE_NOTHING
ffd4d00ff0b6 [xemacs-hg @ 2001-05-17 13:55:46 by stephent]
stephent
parents: 523
diff changeset
94 #define DECLARE_NOTHING struct nosuchstruct
ffd4d00ff0b6 [xemacs-hg @ 2001-05-17 13:55:46 by stephent]
stephent
parents: 523
diff changeset
95 #endif
ffd4d00ff0b6 [xemacs-hg @ 2001-05-17 13:55:46 by stephent]
stephent
parents: 523
diff changeset
96 #endif
ffd4d00ff0b6 [xemacs-hg @ 2001-05-17 13:55:46 by stephent]
stephent
parents: 523
diff changeset
97
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
98 #define itext_ichar(str) ((Ichar) (str)[0])
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
99 #define itext_ichar_fmt(str, fmt, object) ((Ichar) (str)[0])
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
100 #define itext_ichar_ascii_fmt(str, fmt, object) ((Ichar) (str)[0])
428
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 #if (LONGBITS > INTBITS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 # define EMACS_INT long
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 # define EMACS_INT int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
108 typedef int Ichar;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
109
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
110 #define INC_IBYTEPTR(p) ((p)++)
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
111 #define INC_IBYTEPTR_FMT(p, fmt) ((p)++)
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
112 #define DEC_IBYTEPTR(p) ((p)--)
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
113 #define DEC_IBYTEPTR_FMT(p, fmt) ((p)--)
4750
b5f21bb36684 Fix crash in regex.c (closes issue630).
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4527
diff changeset
114 #define MAX_ICHAR_LEN 1
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
115 #define itext_ichar_len(ptr) 1
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
116 #define itext_ichar_len_fmt(ptr, fmt) 1
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 /* Define the syntax stuff for \<, \>, etc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 /* This must be nonzero for the wordchar and notwordchar pattern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 commands in re_match_2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 #ifndef Sword
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 #define Sword 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 #ifdef SYNTAX_TABLE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 extern char *re_syntax_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 #else /* not SYNTAX_TABLE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 /* How many characters in the character set. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 #define CHAR_SET_SIZE 256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 static char re_syntax_table[CHAR_SET_SIZE];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 init_syntax_once (void)
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 static int done = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 if (!done)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
144 const char *word_syntax_chars =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 memset (re_syntax_table, 0, sizeof (re_syntax_table));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 while (*word_syntax_chars)
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
150 re_syntax_table[(unsigned int) (*word_syntax_chars++)] = Sword;
428
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 done = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 }
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
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
156 #endif /* SYNTAX_TABLE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
158 #define SYNTAX(ignored, c) re_syntax_table[c]
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
159 #undef SYNTAX_FROM_CACHE
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
160 #define SYNTAX_FROM_CACHE SYNTAX
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
161
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
162 #define RE_TRANSLATE_1(c) translate[(unsigned char) (c)]
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
163 #define TRANSLATE_P(tr) tr
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
164
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
165 #endif /* emacs */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166
2201
8e39301eac59 [xemacs-hg @ 2004-08-04 19:45:16 by james]
james
parents: 2200
diff changeset
167 /* This is for other GNU distributions with internationalized messages. */
8e39301eac59 [xemacs-hg @ 2004-08-04 19:45:16 by james]
james
parents: 2200
diff changeset
168 #if defined (I18N3) && (defined (HAVE_LIBINTL_H) || defined (_LIBC))
8e39301eac59 [xemacs-hg @ 2004-08-04 19:45:16 by james]
james
parents: 2200
diff changeset
169 # include <libintl.h>
8e39301eac59 [xemacs-hg @ 2004-08-04 19:45:16 by james]
james
parents: 2200
diff changeset
170 #else
8e39301eac59 [xemacs-hg @ 2004-08-04 19:45:16 by james]
james
parents: 2200
diff changeset
171 # define gettext(msgid) (msgid)
8e39301eac59 [xemacs-hg @ 2004-08-04 19:45:16 by james]
james
parents: 2200
diff changeset
172 #endif
8e39301eac59 [xemacs-hg @ 2004-08-04 19:45:16 by james]
james
parents: 2200
diff changeset
173
428
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 /* Get the interface, including the syntax bits. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 #include "regex.h"
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 /* isalpha etc. are used for the character classes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 #include <ctype.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 /* Jim Meyering writes:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 "... Some ctype macros are valid only for character codes that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 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
185 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
186 ctype uses should be through macros like ISPRINT... If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 STDC_HEADERS is defined, then autoconf has verified that the ctype
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 macros don't need to be guarded with references to isascii. ...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 Defining isascii to 1 should let any compiler worth its salt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 eliminate the && through constant folding." */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 #define ISASCII_1(c) 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 #define ISASCII_1(c) isascii(c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 #endif
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 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 /* The IS*() macros can be passed any character, including an extended
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 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
201 otherwise due to out-of-bounds array references. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 #define ISASCII(c) (((EMACS_UINT) (c)) < 0x100 && ISASCII_1 (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 #define ISASCII(c) ISASCII_1 (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 #endif /* MULE */
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 #ifdef isblank
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 #define ISBLANK(c) (ISASCII (c) && isblank (c))
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 ISBLANK(c) ((c) == ' ' || (c) == '\t')
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 #ifdef isgraph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 #define ISGRAPH(c) (ISASCII (c) && isgraph (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 #define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 #define ISPRINT(c) (ISASCII (c) && isprint (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 #define ISDIGIT(c) (ISASCII (c) && isdigit (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 #define ISALNUM(c) (ISASCII (c) && isalnum (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 #define ISALPHA(c) (ISASCII (c) && isalpha (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 #define ISCNTRL(c) (ISASCII (c) && iscntrl (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 #define ISLOWER(c) (ISASCII (c) && islower (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 #define ISPUNCT(c) (ISASCII (c) && ispunct (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 #define ISSPACE(c) (ISASCII (c) && isspace (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 #define ISUPPER(c) (ISASCII (c) && isupper (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 #define ISXDIGIT(c) (ISASCII (c) && isxdigit (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 #ifndef NULL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 #define NULL (void *)0
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 /* We remove any previous definition of `SIGN_EXTEND_CHAR',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 since ours (we hope) works properly with all combinations of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 machines, compilers, `char' and `unsigned char' argument types.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (Per Bothner suggested the basic approach.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 #undef SIGN_EXTEND_CHAR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 #if __STDC__
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 #define SIGN_EXTEND_CHAR(c) ((signed char) (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 #else /* not __STDC__ */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 /* As in Harbison and Steele. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 #define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 /* 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
246 use `alloca' instead of `malloc'. This is because using malloc in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 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
248 Emacs; also, malloc is slower and causes storage fragmentation. On
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 the other hand, malloc is more portable, and easier to debug.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 Because we sometimes use alloca, some routines have to be macros,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 not functions -- `alloca'-allocated space disappears at the end of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 function it is called in. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
255 #ifndef emacs
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
256 #define ALLOCA alloca
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
257 #define xmalloc malloc
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
258 #define xrealloc realloc
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4832
diff changeset
259 #define xfree free
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
260 #endif
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
261
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
262 #ifdef emacs
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
263 #define ALLOCA_GARBAGE_COLLECT() \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
264 do \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
265 { \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
266 if (need_to_check_c_alloca) \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
267 xemacs_c_alloca (0); \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
268 } while (0)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
269 #elif defined (C_ALLOCA)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
270 #define ALLOCA_GARBAGE_COLLECT() alloca (0)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
271 #else
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
272 #define ALLOCA_GARBAGE_COLLECT()
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
273 #endif
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
274
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
275 #ifndef emacs
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
276 /* So we can use just it to conditionalize on */
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
277 #undef ERROR_CHECK_MALLOC
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
278 #endif
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
279
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
280 #ifdef ERROR_CHECK_MALLOC
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
281 /* When REL_ALLOC, malloc() is problematic because it could potentially
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
282 cause all rel-alloc()ed data -- including buffer text -- to be relocated.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
283 We deal with this by checking for such relocation whenever we have
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
284 executed a statement that may call malloc() -- or alloca(), which may
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
285 end up calling malloc() in some circumstances -- and recomputing all
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
286 of our string pointers in re_match_2_internal() and re_search_2().
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
287 However, if malloc() or alloca() happens and we don't know about it,
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
288 we could still be screwed. So we set up a system where we indicate all
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
289 places where we are prepared for malloc() or alloca(), and in any
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
290 other circumstances, calls to those functions (from anywhere inside of
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2421
diff changeset
291 XEmacs!) will ABORT(). We do this even when REL_ALLOC is not defined
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
292 so that we catch these problems sooner, since many developers and beta
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
293 testers will not be running with REL_ALLOC. */
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
294 int regex_malloc_disallowed;
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
295 #define BEGIN_REGEX_MALLOC_OK() regex_malloc_disallowed = 0
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
296 #define END_REGEX_MALLOC_OK() regex_malloc_disallowed = 1
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
297 #define UNBIND_REGEX_MALLOC_CHECK() unbind_to (depth)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
298 #else
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
299 #define BEGIN_REGEX_MALLOC_OK()
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
300 #define END_REGEX_MALLOC_OK()
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
301 #define UNBIND_REGEX_MALLOC_CHECK()
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
302 #endif
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
303
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
304
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 #ifdef REGEX_MALLOC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
307 #define REGEX_ALLOCATE xmalloc
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
308 #define REGEX_REALLOCATE(source, osize, nsize) xrealloc (source, nsize)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
309 #define REGEX_FREE xfree
428
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 #else /* not REGEX_MALLOC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 /* Emacs already defines alloca, sometimes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 #ifndef alloca
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 /* Make alloca work the best possible way. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 #ifdef __GNUC__
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 #define alloca __builtin_alloca
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
319 #elif defined (__DECC) /* XEmacs: added next 3 lines, similar to config.h.in */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
320 #include <alloca.h>
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
321 #pragma intrinsic(alloca)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 #else /* not __GNUC__ */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 #if HAVE_ALLOCA_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 #include <alloca.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 #else /* not __GNUC__ or HAVE_ALLOCA_H */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 #ifndef _AIX /* Already did AIX, up at the top. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
327 void *alloca ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 #endif /* not _AIX */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
329 #endif /* HAVE_ALLOCA_H */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
330 #endif /* __GNUC__ */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 #endif /* not alloca */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
334 #define REGEX_ALLOCATE ALLOCA
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2333
diff changeset
336 /* !!#### Needs review */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 /* Assumes a `char *destination' variable. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 #define REGEX_REALLOCATE(source, osize, nsize) \
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
339 (destination = (char *) ALLOCA (nsize), \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 memmove (destination, source, osize), \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 destination)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342
1726
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 1497
diff changeset
343 /* No need to do anything to free, after alloca.
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 1497
diff changeset
344 Do nothing! But inhibit gcc warning. */
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 1497
diff changeset
345 #define REGEX_FREE(arg,type) ((void)0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
347 #endif /* REGEX_MALLOC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 /* Define how to allocate the failure stack. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
351 #ifdef REGEX_REL_ALLOC
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 #define REGEX_ALLOCATE_STACK(size) \
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
353 r_alloc ((unsigned char **) &failure_stack_ptr, (size))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 #define REGEX_REALLOCATE_STACK(source, osize, nsize) \
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
355 r_re_alloc ((unsigned char **) &failure_stack_ptr, (nsize))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 #define REGEX_FREE_STACK(ptr) \
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
357 r_alloc_free ((unsigned char **) &failure_stack_ptr)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
359 #else /* not REGEX_REL_ALLOC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 #ifdef REGEX_MALLOC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
363 #define REGEX_ALLOCATE_STACK xmalloc
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
364 #define REGEX_REALLOCATE_STACK(source, osize, nsize) xrealloc (source, nsize)
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4832
diff changeset
365 #define REGEX_FREE_STACK(arg) xfree (arg)
428
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 #else /* not REGEX_MALLOC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
369 #define REGEX_ALLOCATE_STACK ALLOCA
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 #define REGEX_REALLOCATE_STACK(source, osize, nsize) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 REGEX_REALLOCATE (source, osize, nsize)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 /* No need to explicitly free anything. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 #define REGEX_FREE_STACK(arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
376 #endif /* REGEX_MALLOC */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
377 #endif /* REGEX_REL_ALLOC */
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 /* True if `size1' is non-NULL and PTR is pointing anywhere inside
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 `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
382 a good thing. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 #define FIRST_STRING_P(ptr) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 (size1 && string1 <= (ptr) && (ptr) <= string1 + size1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 /* (Re)Allocate N items of type T using malloc, or fail. */
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
387 #define TALLOC(n, t) ((t *) xmalloc ((n) * sizeof (t)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
388 #define RETALLOC(addr, n, t) ((addr) = (t *) xrealloc (addr, (n) * sizeof (t)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 #define REGEX_TALLOC(n, t) ((t *) REGEX_ALLOCATE ((n) * sizeof (t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 #define BYTEWIDTH 8 /* In bits. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
393 #define STREQ(s1, s2) (strcmp (s1, s2) == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 #undef MAX
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 #undef MIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 #define MAX(a, b) ((a) > (b) ? (a) : (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 #define MIN(a, b) ((a) < (b) ? (a) : (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
400 /* Type of source-pattern and string chars. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
401 typedef const unsigned char re_char;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
402
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
403 typedef char re_bool;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 #define false 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 #define true 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
408 #ifdef emacs
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
409
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
410 #ifdef MULE
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
411
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
412 Lisp_Object Vthe_lisp_rangetab;
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
413
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
414 void
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
415 vars_of_regex (void)
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
416 {
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
417 Vthe_lisp_rangetab = Fmake_range_table (Qstart_closed_end_closed);
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
418 staticpro (&Vthe_lisp_rangetab);
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
419 }
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
420
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
421 #else /* not MULE */
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
422
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
423 void
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
424 vars_of_regex (void)
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
425 {
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
426 }
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
427
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
428 #endif /* MULE */
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
429
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
430 /* Convert an offset from the start of the logical text string formed by
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
431 concatenating the two strings together into a character position in the
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
432 Lisp buffer or string that the text represents. Knows that
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
433 when handling buffer text, the "string" we're passed in is always
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
434 BEGV - ZV. */
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
435
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
436 static Charxpos
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
437 offset_to_charxpos (Lisp_Object lispobj, int off)
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
438 {
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
439 if (STRINGP (lispobj))
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
440 return string_index_byte_to_char (lispobj, off);
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
441 else if (BUFFERP (lispobj))
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
442 return bytebpos_to_charbpos (XBUFFER (lispobj),
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
443 off + BYTE_BUF_BEGV (XBUFFER (lispobj)));
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
444 else
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
445 return 0;
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
446 }
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
447
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
448 #ifdef REL_ALLOC
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
449
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
450 /* STRING1 is the value of STRING1 given to re_match_2(). LISPOBJ is
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
451 the Lisp object (if any) from which the string is taken. If LISPOBJ
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
452 is a buffer, return a relocation offset to be added to all pointers to
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
453 string data so that they will be accurate again, after an allocation or
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
454 reallocation that potentially relocated the buffer data.
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
455 */
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
456 static Bytecount
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
457 offset_post_relocation (Lisp_Object lispobj, Ibyte *orig_buftext)
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
458 {
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
459 if (!BUFFERP (lispobj))
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
460 return 0;
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
461 return (BYTE_BUF_BYTE_ADDRESS (XBUFFER (lispobj),
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
462 BYTE_BUF_BEGV (XBUFFER (lispobj))) -
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
463 orig_buftext);
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
464 }
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
465
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
466 #endif /* REL_ALLOC */
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
467
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
468 #ifdef ERROR_CHECK_MALLOC
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
469
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
470 /* NOTE that this can run malloc() so you need to adjust afterwards. */
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
471
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
472 static int
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
473 bind_regex_malloc_disallowed (int value)
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
474 {
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
475 /* Tricky, because the act of binding can run malloc(). */
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
476 int old_regex_malloc_disallowed = regex_malloc_disallowed;
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
477 int depth;
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
478 regex_malloc_disallowed = 0;
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
479 depth = record_unwind_protect_restoring_int (&regex_malloc_disallowed,
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
480 old_regex_malloc_disallowed);
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
481 regex_malloc_disallowed = value;
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
482 return depth;
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
483 }
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
484
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
485 #endif /* ERROR_CHECK_MALLOC */
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
486
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
487 #endif /* emacs */
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
488
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
489
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 /* These are the command codes that appear in compiled regular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 expressions. Some opcodes are followed by argument bytes. A
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 command code can specify any interpretation whatsoever for its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 arguments. Zero bytes may appear in the compiled regular expression. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 typedef enum
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 no_op = 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 /* Succeed right away--no more backtracking. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 succeed,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 /* Followed by one byte giving n, then by n literal bytes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 exactn,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 /* Matches any (more or less) character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 anychar,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 /* Matches any one char belonging to specified set. First
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 following byte is number of bitmap bytes. Then come bytes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 for a bitmap saying which chars are in. Bits in each byte
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 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
512 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
513 automatically not in the set. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 charset,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 /* Same parameters as charset, but match any character that is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 not one of those specified. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 charset_not,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 /* Start remembering the text that is matched, for storing in a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 register. Followed by one byte with the register number, in
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
522 the range 1 to the pattern buffer's re_ngroups
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 field. Then followed by one byte with the number of groups
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 inner to this one. (This last has to be part of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 start_memory only because we need it in the on_failure_jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 of re_match_2.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 start_memory,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 /* Stop remembering the text that is matched and store it in a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 memory register. Followed by one byte with the register
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
531 number, in the range 1 to `re_ngroups' in the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 pattern buffer, and one byte with the number of inner groups,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 just like `start_memory'. (We need the number of inner
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 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
535 corresponding start_memory when we're at a stop_memory.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 stop_memory,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 /* Match a duplicate of something remembered. Followed by one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 byte containing the register number. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 duplicate,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 /* Fail unless at beginning of line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 begline,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 /* Fail unless at end of line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 endline,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 /* Succeeds if at beginning of buffer (if emacs) or at beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 of string to be matched (if not). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 begbuf,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 /* Analogously, for end of buffer/string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 endbuf,
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 /* Followed by two byte relative address to which to jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 jump,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 /* Same as jump, but marks the end of an alternative. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 jump_past_alt,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 /* Followed by two-byte relative address of place to resume at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 in case of failure. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 on_failure_jump,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 /* Like on_failure_jump, but pushes a placeholder instead of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 current string position when executed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 on_failure_keep_string_jump,
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 /* Throw away latest failure point and then jump to following
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 two-byte relative address. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 pop_failure_jump,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 /* 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
574 match; otherwise change to jump. This is used to jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 back to the beginning of a repeat. If what follows this jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 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
577 sure that there is no use backtracking out of repetitions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 already matched, then we change it to a pop_failure_jump.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 Followed by two-byte address. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 maybe_pop_jump,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 /* Jump to following two-byte address, and push a dummy failure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 point. This failure point will be thrown away if an attempt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 is made to use it for a failure. A `+' construct makes this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 before the first repeat. Also used as an intermediary kind
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 of jump when compiling an alternative. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 dummy_failure_jump,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 /* Push a dummy failure point and continue. Used at the end of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 alternatives. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 push_dummy_failure,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 /* Followed by two-byte relative address and two-byte number n.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 After matching N times, jump to the address upon failure. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 succeed_n,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 /* Followed by two-byte relative address, and two-byte number n.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 Jump to the address N times, then fail. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 jump_n,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 /* Set the following two-byte relative address to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 subsequent two-byte number. The address *includes* the two
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 bytes of number. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 set_number_at,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 wordchar, /* Matches any word-constituent character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 notwordchar, /* Matches any char that is not a word-constituent. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 wordbeg, /* Succeeds if at word beginning. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 wordend, /* Succeeds if at word end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 wordbound, /* Succeeds if at a word boundary. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 notwordbound /* Succeeds if not at a word boundary. */
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 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 ,before_dot, /* Succeeds if before point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 at_dot, /* Succeeds if at point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 after_dot, /* Succeeds if after point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 /* Matches any character whose syntax is specified. Followed by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 a byte which contains a syntax code, e.g., Sword. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 syntaxspec,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 /* Matches any character whose syntax is not that specified. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 notsyntaxspec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 #endif /* emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 /* need extra stuff to be able to properly work with XEmacs/Mule
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 characters (which may take up more than one byte) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 ,charset_mule, /* Matches any character belonging to specified set.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 The set is stored in "unified range-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 format"; see rangetab.c. Unlike the `charset'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 opcode, this can handle arbitrary characters. */
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 charset_mule_not /* Same parameters as charset_mule, but match any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 character that is not one of those specified. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 /* 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
642 2.3 code to enable some language specific processing */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 ,categoryspec, /* Matches entries in the character category tables */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 notcategoryspec /* The opposite of the above */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 #endif /* MULE */
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 } re_opcode_t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 /* Common operations on the compiled pattern. */
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 /* Store NUMBER in two contiguous bytes starting at DESTINATION. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 #define STORE_NUMBER(destination, number) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 (destination)[0] = (number) & 0377; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 (destination)[1] = (number) >> 8; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 } while (0)
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 /* Same as STORE_NUMBER, except increment DESTINATION to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 the byte after where the number is stored. Therefore, DESTINATION
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 must be an lvalue. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 #define STORE_NUMBER_AND_INCR(destination, number) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 STORE_NUMBER (destination, number); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 (destination) += 2; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 /* Put into DESTINATION a number stored in two contiguous bytes starting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 at SOURCE. */
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 #define EXTRACT_NUMBER(destination, source) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 (destination) = *(source) & 0377; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 static void
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
680 extract_number (int *dest, re_char *source)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 int temp = SIGN_EXTEND_CHAR (*(source + 1));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 *dest = *source & 0377;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 *dest += temp << 8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 #ifndef EXTRACT_MACROS /* To debug the macros. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 #undef EXTRACT_NUMBER
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 #define EXTRACT_NUMBER(dest, src) extract_number (&dest, src)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 #endif /* not EXTRACT_MACROS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 #endif /* DEBUG */
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 /* Same as EXTRACT_NUMBER, except increment SOURCE to after the number.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 SOURCE must be an lvalue. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 #define EXTRACT_NUMBER_AND_INCR(destination, source) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 EXTRACT_NUMBER (destination, source); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 (source) += 2; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 extract_number_and_incr (int *destination, unsigned char **source)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 extract_number (destination, *source);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 *source += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 #ifndef EXTRACT_MACROS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 #undef EXTRACT_NUMBER_AND_INCR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 #define EXTRACT_NUMBER_AND_INCR(dest, src) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 extract_number_and_incr (&dest, &src)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 #endif /* not EXTRACT_MACROS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 #endif /* DEBUG */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 /* If DEBUG is defined, Regex prints many voluminous messages about what
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 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
721 main program in `iregex.c', you can enter patterns and strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 interactively. And if linked with the main program in `main.c' and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 the other test files, you can run the already-written tests. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 #if defined (DEBUG)
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 /* We use standard I/O for debugging. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 #include <stdio.h>
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 #ifndef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 /* XEmacs provides its own version of assert() */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 /* It is useful to test things that ``must'' be true when debugging. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 #include <assert.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
736 extern int debug_regexps;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 #define DEBUG_STATEMENT(e) e
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
739
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
740 #define DEBUG_PRINT1(x) if (debug_regexps) printf (x)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
741 #define DEBUG_PRINT2(x1, x2) if (debug_regexps) printf (x1, x2)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
742 #define DEBUG_PRINT3(x1, x2, x3) if (debug_regexps) printf (x1, x2, x3)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
743 #define DEBUG_PRINT4(x1, x2, x3, x4) if (debug_regexps) printf (x1, x2, x3, x4)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 #define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
745 if (debug_regexps) print_partial_compiled_pattern (s, e)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 #define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
747 if (debug_regexps) print_double_string (w, s1, sz1, s2, sz2)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
748
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
749 #define DEBUG_FAIL_PRINT1(x) \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
750 if (debug_regexps & RE_DEBUG_FAILURE_POINT) printf (x)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
751 #define DEBUG_FAIL_PRINT2(x1, x2) \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
752 if (debug_regexps & RE_DEBUG_FAILURE_POINT) printf (x1, x2)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
753 #define DEBUG_FAIL_PRINT3(x1, x2, x3) \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
754 if (debug_regexps & RE_DEBUG_FAILURE_POINT) printf (x1, x2, x3)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
755 #define DEBUG_FAIL_PRINT4(x1, x2, x3, x4) \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
756 if (debug_regexps & RE_DEBUG_FAILURE_POINT) printf (x1, x2, x3, x4)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
757 #define DEBUG_FAIL_PRINT_COMPILED_PATTERN(p, s, e) \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
758 if (debug_regexps & RE_DEBUG_FAILURE_POINT) \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
759 print_partial_compiled_pattern (s, e)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
760 #define DEBUG_FAIL_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
761 if (debug_regexps & RE_DEBUG_FAILURE_POINT) \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
762 print_double_string (w, s1, sz1, s2, sz2)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
763
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
764 #define DEBUG_MATCH_PRINT1(x) \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
765 if (debug_regexps & RE_DEBUG_MATCHING) printf (x)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
766 #define DEBUG_MATCH_PRINT2(x1, x2) \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
767 if (debug_regexps & RE_DEBUG_MATCHING) printf (x1, x2)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
768 #define DEBUG_MATCH_PRINT3(x1, x2, x3) \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
769 if (debug_regexps & RE_DEBUG_MATCHING) printf (x1, x2, x3)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
770 #define DEBUG_MATCH_PRINT4(x1, x2, x3, x4) \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
771 if (debug_regexps & RE_DEBUG_MATCHING) printf (x1, x2, x3, x4)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
772 #define DEBUG_MATCH_PRINT_COMPILED_PATTERN(p, s, e) \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
773 if (debug_regexps & RE_DEBUG_MATCHING) \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
774 print_partial_compiled_pattern (s, e)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
775 #define DEBUG_MATCH_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
776 if (debug_regexps & RE_DEBUG_MATCHING) \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
777 print_double_string (w, s1, sz1, s2, sz2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 /* Print the fastmap in human-readable form. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 print_fastmap (char *fastmap)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
785 int was_a_range = 0;
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
786 int i = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 while (i < (1 << BYTEWIDTH))
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 if (fastmap[i++])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 was_a_range = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 putchar (i - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 while (i < (1 << BYTEWIDTH) && fastmap[i])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 was_a_range = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 i++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 if (was_a_range)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 putchar ('-');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 putchar (i - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 putchar ('\n');
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 /* Print a compiled pattern string in human-readable form, starting at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 the START pointer into it and ending just before the pointer END. */
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 static void
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
814 print_partial_compiled_pattern (re_char *start, re_char *end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 int mcnt, mcnt2;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
817 unsigned char *p = (unsigned char *) start;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
818 re_char *pend = end;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 if (start == NULL)
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 puts ("(null)");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 /* Loop over pattern commands. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 while (p < pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 printf ("%ld:\t", (long)(p - start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 switch ((re_opcode_t) *p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 case no_op:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 printf ("/no_op");
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 exactn:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 printf ("/exactn/%d", mcnt);
4750
b5f21bb36684 Fix crash in regex.c (closes issue630).
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4527
diff changeset
840 while (mcnt--)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 {
4750
b5f21bb36684 Fix crash in regex.c (closes issue630).
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4527
diff changeset
842 putchar ('/');
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 putchar (*p++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 case start_memory:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 printf ("/start_memory/%d/%d", mcnt, *p++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 case stop_memory:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 printf ("/stop_memory/%d/%d", mcnt, *p++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 case duplicate:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 printf ("/duplicate/%d", *p++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 case anychar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 printf ("/anychar");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 case charset:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 case charset_not:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 REGISTER int c, last = -100;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 REGISTER int in_range = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 printf ("/charset [%s",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 (re_opcode_t) *(p - 1) == charset_not ? "^" : "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 assert (p + *p < pend);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 for (c = 0; c < 256; c++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 if (((unsigned char) (c / 8) < *p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 && (p[1 + (c/8)] & (1 << (c % 8))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 /* Are we starting a range? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 if (last + 1 == c && ! in_range)
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 putchar ('-');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 in_range = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 /* Have we broken a range? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 else if (last + 1 != c && in_range)
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 putchar (last);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 in_range = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 if (! in_range)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 putchar (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 last = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 if (in_range)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 putchar (last);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 putchar (']');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 p += 1 + *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 case charset_mule:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 case charset_mule_not:
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 int nentries, i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 printf ("/charset_mule [%s",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 (re_opcode_t) *(p - 1) == charset_mule_not ? "^" : "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 nentries = unified_range_table_nentries (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 for (i = 0; i < nentries; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 EMACS_INT first, last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 Lisp_Object dummy_val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 unified_range_table_get_range (p, i, &first, &last,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 &dummy_val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 if (first < 0x100)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 putchar (first);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 printf ("(0x%lx)", (long)first);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 if (first != last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 putchar ('-');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 if (last < 0x100)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 putchar (last);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 printf ("(0x%lx)", (long)last);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 }
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 putchar (']');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 p += unified_range_table_bytes_used (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 case begline:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 printf ("/begline");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 case endline:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 printf ("/endline");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 case on_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 printf ("/on_failure_jump to %ld", (long)(p + mcnt - start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 case on_failure_keep_string_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 printf ("/on_failure_keep_string_jump to %ld", (long)(p + mcnt - start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 case dummy_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 printf ("/dummy_failure_jump to %ld", (long)(p + mcnt - start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 break;
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 case push_dummy_failure:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 printf ("/push_dummy_failure");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 case maybe_pop_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 printf ("/maybe_pop_jump to %ld", (long)(p + mcnt - start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 break;
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 case pop_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 printf ("/pop_failure_jump to %ld", (long)(p + mcnt - start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 case jump_past_alt:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 printf ("/jump_past_alt to %ld", (long)(p + mcnt - start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 break;
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 case jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 printf ("/jump to %ld", (long)(p + mcnt - start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 break;
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 case succeed_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 extract_number_and_incr (&mcnt2, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 printf ("/succeed_n to %ld, %d times", (long)(p + mcnt - start), mcnt2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 case jump_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 extract_number_and_incr (&mcnt2, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 printf ("/jump_n to %ld, %d times", (long)(p + mcnt - start), mcnt2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 case set_number_at:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 extract_number_and_incr (&mcnt, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 extract_number_and_incr (&mcnt2, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 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
1006 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 case wordbound:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 printf ("/wordbound");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 break;
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 case notwordbound:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 printf ("/notwordbound");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 case wordbeg:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 printf ("/wordbeg");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 break;
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 case wordend:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 printf ("/wordend");
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 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 case before_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 printf ("/before_dot");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 break;
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 case at_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 printf ("/at_dot");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 case after_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 printf ("/after_dot");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 break;
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 case syntaxspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 printf ("/syntaxspec");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 printf ("/%d", mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 case notsyntaxspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 printf ("/notsyntaxspec");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 printf ("/%d", mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 /* 97/2/17 jhod Mule category patch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 case categoryspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 printf ("/categoryspec");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 printf ("/%d", mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 case notcategoryspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 printf ("/notcategoryspec");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 printf ("/%d", mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 /* end of category patch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 #endif /* emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 case wordchar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 printf ("/wordchar");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 case notwordchar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 printf ("/notwordchar");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 case begbuf:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 printf ("/begbuf");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 case endbuf:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 printf ("/endbuf");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 break;
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 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 printf ("?%d", *(p-1));
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 putchar ('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 printf ("%ld:\tend of pattern.\n", (long)(p - start));
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 print_compiled_pattern (struct re_pattern_buffer *bufp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1095 re_char *buffer = bufp->buffer;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 print_partial_compiled_pattern (buffer, buffer + bufp->used);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 printf ("%ld bytes used/%ld bytes allocated.\n", bufp->used,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 bufp->allocated);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 if (bufp->fastmap_accurate && bufp->fastmap)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 printf ("fastmap: ");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 print_fastmap (bufp->fastmap);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 printf ("re_nsub: %ld\t", (long)bufp->re_nsub);
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1108 printf ("re_ngroups: %ld\t", (long)bufp->re_ngroups);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 printf ("regs_alloc: %d\t", bufp->regs_allocated);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 printf ("can_be_null: %d\t", bufp->can_be_null);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 printf ("newline_anchor: %d\n", bufp->newline_anchor);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 printf ("no_sub: %d\t", bufp->no_sub);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 printf ("not_bol: %d\t", bufp->not_bol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 printf ("not_eol: %d\t", bufp->not_eol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 printf ("syntax: %d\n", bufp->syntax);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 /* Perhaps we should print the translate table? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 /* and maybe the category table? */
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1118
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1119 if (bufp->external_to_internal_register)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1120 {
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1121 int i;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1122
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1123 printf ("external_to_internal_register:\n");
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1124 for (i = 0; i <= bufp->re_nsub; i++)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1125 {
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1126 if (i > 0)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1127 printf (", ");
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1128 printf ("%d -> %d", i, bufp->external_to_internal_register[i]);
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1129 }
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1130 printf ("\n");
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1131 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 static void
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1136 print_double_string (re_char *where, re_char *string1, int size1,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1137 re_char *string2, int size2)
428
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 if (where == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 printf ("(null)");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1143 int this_char;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 if (FIRST_STRING_P (where))
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 for (this_char = where - string1; this_char < size1; this_char++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 putchar (string1[this_char]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 where = string2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 }
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 for (this_char = where - string2; this_char < size2; this_char++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 putchar (string2[this_char]);
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 #else /* not DEBUG */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1160 #ifndef emacs
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 #undef assert
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1162 #define assert(e) ((void) (1))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1163 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 #define DEBUG_STATEMENT(e)
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1166
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 #define DEBUG_PRINT1(x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 #define DEBUG_PRINT2(x1, x2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 #define DEBUG_PRINT3(x1, x2, x3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 #define DEBUG_PRINT4(x1, x2, x3, x4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 #define DEBUG_PRINT_COMPILED_PATTERN(p, s, e)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 #define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1174 #define DEBUG_FAIL_PRINT1(x)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1175 #define DEBUG_FAIL_PRINT2(x1, x2)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1176 #define DEBUG_FAIL_PRINT3(x1, x2, x3)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1177 #define DEBUG_FAIL_PRINT4(x1, x2, x3, x4)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1178 #define DEBUG_FAIL_PRINT_COMPILED_PATTERN(p, s, e)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1179 #define DEBUG_FAIL_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1180
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1181 #define DEBUG_MATCH_PRINT1(x)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1182 #define DEBUG_MATCH_PRINT2(x1, x2)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1183 #define DEBUG_MATCH_PRINT3(x1, x2, x3)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1184 #define DEBUG_MATCH_PRINT4(x1, x2, x3, x4)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1185 #define DEBUG_MATCH_PRINT_COMPILED_PATTERN(p, s, e)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1186 #define DEBUG_MATCH_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1187
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1188 #endif /* DEBUG */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 /* 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
1191 also be assigned to arbitrarily: each pattern buffer stores its own
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 syntax, so it can be changed between regex compilations. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 /* This has no initializer because initialized variables in Emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 become read-only after dumping. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 reg_syntax_t re_syntax_options;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 /* Specify the precise syntax of regexps for compilation. This provides
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 for compatibility for various utilities which historically have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 different, incompatible syntaxes.
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 The argument SYNTAX is a bit mask comprised of the various bits
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 defined in regex.h. We return the old syntax. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 reg_syntax_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 re_set_syntax (reg_syntax_t syntax)
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 reg_syntax_t ret = re_syntax_options;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 re_syntax_options = syntax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 return ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 }
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 /* 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
1215 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
1216 POSIX doesn't require that we do anything for REG_NOERROR,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 but why not be nice? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1219 static const char *re_error_msgid[] =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 "Success", /* REG_NOERROR */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 "No match", /* REG_NOMATCH */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 "Invalid regular expression", /* REG_BADPAT */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 "Invalid collation character", /* REG_ECOLLATE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 "Invalid character class name", /* REG_ECTYPE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 "Trailing backslash", /* REG_EESCAPE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 "Invalid back reference", /* REG_ESUBREG */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 "Unmatched [ or [^", /* REG_EBRACK */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 "Unmatched ( or \\(", /* REG_EPAREN */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 "Unmatched \\{", /* REG_EBRACE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 "Invalid content of \\{\\}", /* REG_BADBR */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 "Invalid range end", /* REG_ERANGE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 "Memory exhausted", /* REG_ESPACE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 "Invalid preceding regular expression", /* REG_BADRPT */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 "Premature end of regular expression", /* REG_EEND */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 "Regular expression too big", /* REG_ESIZE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 "Unmatched ) or \\)", /* REG_ERPAREN */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 "Invalid syntax designator", /* REG_ESYNTAX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 "Ranges may not span charsets", /* REG_ERANGESPAN */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 "Invalid category designator", /* REG_ECATEGORY */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 /* Avoiding alloca during matching, to placate r_alloc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1249 /* About these various flags:
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1250
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1251 MATCH_MAY_ALLOCATE indicates that it's OK to do allocation in the
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1252 searching and matching functions. In this case, we use local variables
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1253 to hold the values allocated. If not, we use *global* variables, which
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1254 are pre-allocated. NOTE: XEmacs ***MUST*** run with MATCH_MAY_ALLOCATE,
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1255 because the regexp routines may get called reentrantly as a result of
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1256 QUIT processing (e.g. under Windows: re_match -> QUIT -> quit_p -> drain
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1257 events -> process WM_INITMENU -> call filter -> re_match; see stack
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1258 trace in signal.c), so we cannot have any global variables (unless we do
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1259 lots of trickiness including some unwind-protects, which isn't worth it
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1260 at this point).
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1261
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1262 REL_ALLOC means that the relocating allocator is in use, for buffers
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1263 and such. REGEX_REL_ALLOC means that we use rel-alloc to manage the
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1264 fail stack, which may grow quite large. REGEX_MALLOC means we use
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1265 malloc() in place of alloca() to allocate the fail stack -- only
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1266 applicable if REGEX_REL_ALLOC is not defined.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1267 */
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1268
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 /* Define MATCH_MAY_ALLOCATE unless we need to make sure that the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 searching and matching functions should not call alloca. On some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 systems, alloca is implemented in terms of malloc, and if we're
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 using the relocating allocator routines, then malloc could cause a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 relocation, which might (if the strings being searched are in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 ralloc heap) shift the data out from underneath the regexp
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1275 routines. [To clarify: The purpose of rel-alloc is to allow data to
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1276 be moved in memory from one place to another so that all data
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1277 blocks can be consolidated together and excess memory released back
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1278 to the operating system. This requires that all the blocks that
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1279 are managed by rel-alloc go at the very end of the program's heap,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1280 after all regularly malloc()ed data. malloc(), however, is used to
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1281 owning the end of the heap, so that when more memory is needed, it
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1282 just expands the heap using sbrk(). This is reconciled by using a
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1283 malloc() (such as malloc.c, gmalloc.c, or recent versions of
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1284 malloc() in libc) where the sbrk() call can be replaced with a
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1285 user-specified call -- in this case, to rel-alloc's r_alloc_sbrk()
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1286 routine. This routine calls the real sbrk(), but then shifts all
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1287 the rel-alloc-managed blocks forward to the end of the heap again,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1288 so that malloc() gets the memory it needs in the location it needs
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1289 it at. The regex routines may well have pointers to buffer data as
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1290 their arguments, and buffers are managed by rel-alloc if rel-alloc
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1291 has been enabled, so calling malloc() may potentially screw things
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1292 up badly if it runs out of space and asks for more from the OS.]
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1293
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1294 [[Here's another reason to avoid allocation: Emacs processes input
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1295 from X in a signal handler; processing X input may call malloc; if
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1296 input arrives while a matching routine is calling malloc, then
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1297 we're scrod. But Emacs can't just block input while calling
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1298 matching routines; then we don't notice interrupts when they come
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1299 in. So, Emacs blocks input around all regexp calls except the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1300 matching calls, which it leaves unprotected, in the faith that they
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1301 will not malloc.]] This previous paragraph is irrelevant under XEmacs,
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1302 as we *do not* do anything so stupid as process input from within a
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1303 signal handler.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1304
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1305 However, the regexp routines may get called reentrantly as a result of
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1306 QUIT processing (e.g. under Windows: re_match -> QUIT -> quit_p -> drain
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1307 events -> process WM_INITMENU -> call filter -> re_match; see stack
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1308 trace in signal.c), so we cannot have any global variables (unless we do
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1309 lots of trickiness including some unwind-protects, which isn't worth it
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1310 at this point). Hence we MUST have MATCH_MAY_ALLOCATE defined.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1311
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1312 Also, the first paragraph does not make complete sense to me -- what
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1313 about the use of rel-alloc to handle the fail stacks? Shouldn't these
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1314 reallocations potentially cause buffer data to be relocated as well? I
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1315 must be missing something, though -- perhaps the writer above is
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1316 assuming that the failure stack(s) will always be allocated after the
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1317 buffer data, and thus reallocating them with rel-alloc won't move buffer
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1318 data. (In fact, a cursory glance at the code in ralloc.c seems to
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1319 confirm this.) --ben */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 /* Normally, this is fine. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 #define MATCH_MAY_ALLOCATE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 /* 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
1325 what config.h may say. So don't take precautions for it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 #ifdef __GNUC__
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 #undef C_ALLOCA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 #endif
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 /* 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
1331 and (2) it's not safe for them to use malloc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 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
1333 failure stack, but we would still use it for the register vectors;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 so REL_ALLOC should not affect this. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1335
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1336 /* XEmacs can handle REL_ALLOC and malloc() OK */
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1337 #if !defined (emacs) && (defined (C_ALLOCA) || defined (REGEX_MALLOC)) && defined (REL_ALLOC)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 #undef MATCH_MAY_ALLOCATE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1341 #if !defined (MATCH_MAY_ALLOCATE) && defined (emacs)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1342 #error regex must be handle reentrancy; MATCH_MAY_ALLOCATE must be defined
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1343 #endif
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1344
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 /* Failure stack declarations and macros; both re_compile_fastmap and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 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
1348 REGEX_ALLOCATE_STACK. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349
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 /* Number of failure points for which to initially allocate space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 when matching. If this number is exceeded, we allocate more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 space, so it is not a hard limit. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 #ifndef INIT_FAILURE_ALLOC
3300
a034c4bd7877 [xemacs-hg @ 2006-03-25 11:27:43 by malcolmp]
malcolmp
parents: 2639
diff changeset
1355 #define INIT_FAILURE_ALLOC 20
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 /* Roughly the maximum number of failure points on the stack. Would be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 exactly that if always used MAX_FAILURE_SPACE each time we failed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 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
1361 change it ourselves. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 #if defined (MATCH_MAY_ALLOCATE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 /* 4400 was enough to cause a crash on Alpha OSF/1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 whose default stack limit is 2mb. */
3300
a034c4bd7877 [xemacs-hg @ 2006-03-25 11:27:43 by malcolmp]
malcolmp
parents: 2639
diff changeset
1365 int re_max_failures = 40000;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 #else
3300
a034c4bd7877 [xemacs-hg @ 2006-03-25 11:27:43 by malcolmp]
malcolmp
parents: 2639
diff changeset
1367 int re_max_failures = 4000;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 #endif
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 union fail_stack_elt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1372 re_char *pointer;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 int integer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 typedef union fail_stack_elt fail_stack_elt_t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 typedef struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 fail_stack_elt_t *stack;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 648
diff changeset
1381 Elemcount size;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 648
diff changeset
1382 Elemcount avail; /* Offset of next open position. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 } fail_stack_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 #define FAIL_STACK_EMPTY() (fail_stack.avail == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 #define FAIL_STACK_PTR_EMPTY() (fail_stack_ptr->avail == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 #define FAIL_STACK_FULL() (fail_stack.avail == fail_stack.size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388
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 /* Define macros to initialize and free the failure stack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 Do `return -2' if the alloc fails. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 #ifdef MATCH_MAY_ALLOCATE
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1394 #define INIT_FAIL_STACK() \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1395 do { \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1396 fail_stack.stack = (fail_stack_elt_t *) \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1397 REGEX_ALLOCATE_STACK (INIT_FAILURE_ALLOC * \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1398 sizeof (fail_stack_elt_t)); \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1399 \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1400 if (fail_stack.stack == NULL) \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1401 { \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1402 UNBIND_REGEX_MALLOC_CHECK (); \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1403 return -2; \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1404 } \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1405 \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1406 fail_stack.size = INIT_FAILURE_ALLOC; \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1407 fail_stack.avail = 0; \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 #define RESET_FAIL_STACK() REGEX_FREE_STACK (fail_stack.stack)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 #define INIT_FAIL_STACK() \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 fail_stack.avail = 0; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 #define RESET_FAIL_STACK()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 #endif
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 /* 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
1422
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 Return 1 if succeeds, and 0 if either ran out of memory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 allocating space for it or it was already too large.
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 REGEX_REALLOCATE_STACK requires `destination' be declared. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 #define DOUBLE_FAIL_STACK(fail_stack) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 ((fail_stack).size > re_max_failures * MAX_FAILURE_ITEMS \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 ? 0 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 : ((fail_stack).stack = (fail_stack_elt_t *) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 REGEX_REALLOCATE_STACK ((fail_stack).stack, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 (fail_stack).size * sizeof (fail_stack_elt_t), \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 ((fail_stack).size << 1) * sizeof (fail_stack_elt_t)), \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 (fail_stack).stack == NULL \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 ? 0 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 : ((fail_stack).size <<= 1, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1441 #if !defined (emacs) || !defined (REL_ALLOC)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1442 #define RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS()
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1443 #else
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1444 /* Don't change NULL pointers */
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1445 #define ADD_IF_NZ(val) if (val) val += rmdp_offset
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1446 #define RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS() \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1447 do \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1448 { \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1449 Bytecount rmdp_offset = offset_post_relocation (lispobj, orig_buftext); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1450 \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1451 if (rmdp_offset) \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1452 { \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1453 int i; \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1454 \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1455 ADD_IF_NZ (string1); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1456 ADD_IF_NZ (string2); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1457 ADD_IF_NZ (d); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1458 ADD_IF_NZ (dend); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1459 ADD_IF_NZ (end1); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1460 ADD_IF_NZ (end2); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1461 ADD_IF_NZ (end_match_1); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1462 ADD_IF_NZ (end_match_2); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1463 \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1464 if (bufp->re_ngroups) \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1465 { \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1466 for (i = 0; i < num_regs; i++) \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1467 { \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1468 ADD_IF_NZ (regstart[i]); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1469 ADD_IF_NZ (regend[i]); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1470 ADD_IF_NZ (old_regstart[i]); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1471 ADD_IF_NZ (old_regend[i]); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1472 ADD_IF_NZ (best_regstart[i]); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1473 ADD_IF_NZ (best_regend[i]); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1474 ADD_IF_NZ (reg_dummy[i]); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1475 } \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1476 } \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1477 \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1478 ADD_IF_NZ (match_end); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1479 } \
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1480 } while (0)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1481 #endif /* !defined (emacs) || !defined (REL_ALLOC) */
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1482
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1483 #if !defined (emacs) || !defined (REL_ALLOC)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1484 #define RE_SEARCH_RELOCATE_MOVEABLE_DATA_POINTERS()
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1485 #else
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1486 #define RE_SEARCH_RELOCATE_MOVEABLE_DATA_POINTERS() \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1487 do \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1488 { \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1489 Bytecount rmdp_offset = offset_post_relocation (lispobj, orig_buftext); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1490 \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1491 if (rmdp_offset) \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1492 { \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1493 ADD_IF_NZ (str1); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1494 ADD_IF_NZ (str2); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1495 ADD_IF_NZ (string1); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1496 ADD_IF_NZ (string2); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1497 ADD_IF_NZ (d); \
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
1498 } \
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1499 } while (0)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1500
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1501 #endif /* emacs */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 /* Push pointer POINTER on FAIL_STACK.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 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
1505 space to do so. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 #define PUSH_PATTERN_OP(POINTER, FAIL_STACK) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 ((FAIL_STACK_FULL () \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 && !DOUBLE_FAIL_STACK (FAIL_STACK)) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 ? 0 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 : ((FAIL_STACK).stack[(FAIL_STACK).avail++].pointer = POINTER, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 /* Push a pointer value onto the failure stack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 Assumes the variable `fail_stack'. Probably should only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 be called from within `PUSH_FAILURE_POINT'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 #define PUSH_FAILURE_POINTER(item) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 fail_stack.stack[fail_stack.avail++].pointer = (unsigned char *) (item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 /* This pushes an integer-valued item onto the failure stack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 Assumes the variable `fail_stack'. Probably should only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 be called from within `PUSH_FAILURE_POINT'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 #define PUSH_FAILURE_INT(item) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 fail_stack.stack[fail_stack.avail++].integer = (item)
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 /* Push a fail_stack_elt_t value onto the failure stack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526 Assumes the variable `fail_stack'. Probably should only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 be called from within `PUSH_FAILURE_POINT'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 #define PUSH_FAILURE_ELT(item) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 fail_stack.stack[fail_stack.avail++] = (item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 /* These three POP... operations complement the three PUSH... operations.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 All assume that `fail_stack' is nonempty. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533 #define POP_FAILURE_POINTER() fail_stack.stack[--fail_stack.avail].pointer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 #define POP_FAILURE_INT() fail_stack.stack[--fail_stack.avail].integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 #define POP_FAILURE_ELT() fail_stack.stack[--fail_stack.avail]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 /* 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
1538 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 #define DEBUG_PUSH PUSH_FAILURE_INT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 #define DEBUG_POP(item_addr) *(item_addr) = POP_FAILURE_INT ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 #define DEBUG_PUSH(item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 #define DEBUG_POP(item_addr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 /* Push the information about the state we will need
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 if we ever fail back to it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 Requires variables fail_stack, regstart, regend, reg_info, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 num_regs be declared. DOUBLE_FAIL_STACK requires `destination' be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 declared.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 Does `return FAILURE_CODE' if runs out of memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1556 #if !defined (REGEX_MALLOC) && !defined (REGEX_REL_ALLOC)
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1557 #define DECLARE_DESTINATION char *destination
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 #else
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1559 #define DECLARE_DESTINATION DECLARE_NOTHING
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 #define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code) \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1563 do { \
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1564 DECLARE_DESTINATION; \
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1565 /* Must be int, so when we don't save any registers, the arithmetic \
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1566 of 0 + -1 isn't done as unsigned. */ \
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1567 int this_reg; \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1569 DEBUG_STATEMENT (failure_id++); \
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1570 DEBUG_STATEMENT (nfailure_points_pushed++); \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1571 DEBUG_FAIL_PRINT2 ("\nPUSH_FAILURE_POINT #%d:\n", failure_id); \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1572 DEBUG_FAIL_PRINT2 (" Before push, next avail: %ld\n", \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1573 (long) (fail_stack).avail); \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1574 DEBUG_FAIL_PRINT2 (" size: %ld\n", \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1575 (long) (fail_stack).size); \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1576 \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1577 DEBUG_FAIL_PRINT2 (" slots needed: %d\n", NUM_FAILURE_ITEMS); \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1578 DEBUG_FAIL_PRINT2 (" available: %ld\n", \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1579 (long) REMAINING_AVAIL_SLOTS); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580 \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1581 /* Ensure we have enough space allocated for what we will push. */ \
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1582 while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS) \
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1583 { \
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1584 BEGIN_REGEX_MALLOC_OK (); \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1585 if (!DOUBLE_FAIL_STACK (fail_stack)) \
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1586 { \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1587 END_REGEX_MALLOC_OK (); \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1588 UNBIND_REGEX_MALLOC_CHECK (); \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1589 return failure_code; \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1590 } \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1591 END_REGEX_MALLOC_OK (); \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1592 DEBUG_FAIL_PRINT2 ("\n Doubled stack; size now: %ld\n", \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1593 (long) (fail_stack).size); \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1594 DEBUG_FAIL_PRINT2 (" slots available: %ld\n", \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1595 (long) REMAINING_AVAIL_SLOTS); \
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1596 \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1597 RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS (); \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1598 } \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1600 /* Push the info, starting with the registers. */ \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1601 DEBUG_FAIL_PRINT1 ("\n"); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1603 for (this_reg = lowest_active_reg; this_reg <= highest_active_reg; \
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1604 this_reg++) \
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1605 { \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1606 DEBUG_FAIL_PRINT2 (" Pushing reg: %d\n", this_reg); \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1607 DEBUG_STATEMENT (num_regs_pushed++); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1609 DEBUG_FAIL_PRINT2 (" start: 0x%lx\n", (long) regstart[this_reg]); \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1610 PUSH_FAILURE_POINTER (regstart[this_reg]); \
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1611 \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1612 DEBUG_FAIL_PRINT2 (" end: 0x%lx\n", (long) regend[this_reg]); \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1613 PUSH_FAILURE_POINTER (regend[this_reg]); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614 \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1615 DEBUG_FAIL_PRINT2 (" info: 0x%lx\n ", \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1616 * (long *) (&reg_info[this_reg])); \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1617 DEBUG_FAIL_PRINT2 (" match_null=%d", \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1618 REG_MATCH_NULL_STRING_P (reg_info[this_reg])); \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1619 DEBUG_FAIL_PRINT2 (" active=%d", IS_ACTIVE (reg_info[this_reg])); \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1620 DEBUG_FAIL_PRINT2 (" matched_something=%d", \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1621 MATCHED_SOMETHING (reg_info[this_reg])); \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1622 DEBUG_FAIL_PRINT2 (" ever_matched_something=%d", \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1623 EVER_MATCHED_SOMETHING (reg_info[this_reg])); \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1624 DEBUG_FAIL_PRINT1 ("\n"); \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1625 PUSH_FAILURE_ELT (reg_info[this_reg].word); \
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1626 } \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627 \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1628 DEBUG_FAIL_PRINT2 (" Pushing low active reg: %d\n", lowest_active_reg); \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1629 PUSH_FAILURE_INT (lowest_active_reg); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1631 DEBUG_FAIL_PRINT2 (" Pushing high active reg: %d\n", highest_active_reg); \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1632 PUSH_FAILURE_INT (highest_active_reg); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1634 DEBUG_FAIL_PRINT2 (" Pushing pattern 0x%lx: \n", (long) pattern_place); \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1635 DEBUG_FAIL_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend); \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1636 PUSH_FAILURE_POINTER (pattern_place); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1638 DEBUG_FAIL_PRINT2 (" Pushing string 0x%lx: `", (long) string_place); \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1639 DEBUG_FAIL_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1640 size2); \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1641 DEBUG_FAIL_PRINT1 ("'\n"); \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1642 PUSH_FAILURE_POINTER (string_place); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1644 DEBUG_FAIL_PRINT2 (" Pushing failure id: %u\n", failure_id); \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1645 DEBUG_PUSH (failure_id); \
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1646 } while (0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 /* 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
1649 for each register. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650 #define NUM_REG_ITEMS 3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652 /* Individual items aside from the registers. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654 #define NUM_NONREG_ITEMS 5 /* Includes failure point id. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 #define NUM_NONREG_ITEMS 4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 /* We push at most this many items on the stack. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 /* 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
1661 this regexp will save; but that was changed to 5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 to avoid stack overflow for a regexp with lots of parens. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 #define MAX_FAILURE_ITEMS (5 * NUM_REG_ITEMS + NUM_NONREG_ITEMS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 /* We actually push this many items. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 #define NUM_FAILURE_ITEMS \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 ((highest_active_reg - lowest_active_reg + 1) * NUM_REG_ITEMS \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 + NUM_NONREG_ITEMS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670 /* 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
1671 #define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail)
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 /* Pops what PUSH_FAIL_STACK pushes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 We restore into the parameters, all of which should be lvalues:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 STR -- the saved data position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 PAT -- the saved pattern position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 LOW_REG, HIGH_REG -- the highest and lowest active registers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 REGSTART, REGEND -- arrays of string positions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 REG_INFO -- array of information about each subexpression.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 Also assumes the variables `fail_stack' and (if debugging), `bufp',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 `pend', `string1', `size1', `string2', and `size2'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1686 #define POP_FAILURE_POINT(str, pat, low_reg, high_reg, \
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1687 regstart, regend, reg_info) \
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1688 do { \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 DEBUG_STATEMENT (fail_stack_elt_t ffailure_id;) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 int this_reg; \
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1691 const unsigned char *string_temp; \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 assert (!FAIL_STACK_EMPTY ()); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 /* Remove failure points and point to how many regs pushed. */ \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1696 DEBUG_FAIL_PRINT1 ("POP_FAILURE_POINT:\n"); \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1697 DEBUG_FAIL_PRINT2 (" Before pop, next avail: %ld\n", \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1698 (long) fail_stack.avail); \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1699 DEBUG_FAIL_PRINT2 (" size: %ld\n", \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1700 (long) fail_stack.size); \
428
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 assert (fail_stack.avail >= NUM_NONREG_ITEMS); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 DEBUG_POP (&ffailure_id.integer); \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1705 DEBUG_FAIL_PRINT2 (" Popping failure id: %d\n", \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1706 * (int *) &ffailure_id); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 /* If the saved string location is NULL, it came from an \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 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
1710 saved NULL, thus retaining our current position in the string. */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 string_temp = POP_FAILURE_POINTER (); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 if (string_temp != NULL) \
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1713 str = string_temp; \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1715 DEBUG_FAIL_PRINT2 (" Popping string 0x%lx: `", (long) str); \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1716 DEBUG_FAIL_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1717 DEBUG_FAIL_PRINT1 ("'\n"); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719 pat = (unsigned char *) POP_FAILURE_POINTER (); \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1720 DEBUG_FAIL_PRINT2 (" Popping pattern 0x%lx: ", (long) pat); \
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1721 DEBUG_FAIL_PRINT_COMPILED_PATTERN (bufp, pat, pend); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 /* Restore register info. */ \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1724 high_reg = POP_FAILURE_INT (); \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1725 DEBUG_FAIL_PRINT2 (" Popping high active reg: %d\n", high_reg); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1727 low_reg = POP_FAILURE_INT (); \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1728 DEBUG_FAIL_PRINT2 (" Popping low active reg: %d\n", low_reg); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 for (this_reg = high_reg; this_reg >= low_reg; this_reg--) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731 { \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1732 DEBUG_FAIL_PRINT2 (" Popping reg: %d\n", this_reg); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 reg_info[this_reg].word = POP_FAILURE_ELT (); \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1735 DEBUG_FAIL_PRINT2 (" info: 0x%lx\n", \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 * (long *) &reg_info[this_reg]); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 \
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1738 regend[this_reg] = POP_FAILURE_POINTER (); \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1739 DEBUG_FAIL_PRINT2 (" end: 0x%lx\n", (long) regend[this_reg]); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740 \
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1741 regstart[this_reg] = POP_FAILURE_POINTER (); \
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1742 DEBUG_FAIL_PRINT2 (" start: 0x%lx\n", (long) regstart[this_reg]); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 set_regs_matched_done = 0; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746 DEBUG_STATEMENT (nfailure_points_popped++); \
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
1747 } while (0) /* POP_FAILURE_POINT */
428
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
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 /* Structure for per-register (a.k.a. per-group) information.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 Other register information, such as the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 starting and ending positions (which are addresses), and the list of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 inner groups (which is a bits list) are maintained in separate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 variables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 We are making a (strictly speaking) nonportable assumption here: that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 the compiler will pack our bit fields into something that fits into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759 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
1760 failure stack. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 typedef union
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764 fail_stack_elt_t word;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1767 /* This field is one if this group can match the empty string,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1768 zero if not. If not yet determined, `MATCH_NULL_UNSET_VALUE'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 #define MATCH_NULL_UNSET_VALUE 3
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1770 unsigned int match_null_string_p : 2;
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1771 unsigned int is_active : 1;
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1772 unsigned int matched_something : 1;
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1773 unsigned int ever_matched_something : 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774 } bits;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775 } register_info_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 #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
1778 #define IS_ACTIVE(R) ((R).bits.is_active)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 #define MATCHED_SOMETHING(R) ((R).bits.matched_something)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 #define EVER_MATCHED_SOMETHING(R) ((R).bits.ever_matched_something)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 /* Call this when have matched a real character; it sets `matched' flags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784 for the subexpressions which we are currently inside. Also records
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 that those subexprs have matched. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 #define SET_REGS_MATCHED() \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 do \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 if (!set_regs_matched_done) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 { \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1791 int r; \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 set_regs_matched_done = 1; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 for (r = lowest_active_reg; r <= highest_active_reg; r++) \
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 MATCHED_SOMETHING (reg_info[r]) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796 = EVER_MATCHED_SOMETHING (reg_info[r]) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 = 1; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801 while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 /* Registers are set to a sentinel when they haven't yet matched. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1804 static unsigned char reg_unset_dummy;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805 #define REG_UNSET_VALUE (&reg_unset_dummy)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 #define REG_UNSET(e) ((e) == REG_UNSET_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808 /* Subroutine declarations and macros for regex_compile. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 /* Fetch the next character in the uncompiled pattern---translating it
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1811 if necessary. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 #define PATFETCH(c) \
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1813 do { \
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1814 PATFETCH_RAW (c); \
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1815 c = RE_TRANSLATE (c); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 } while (0)
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 /* Fetch the next character in the uncompiled pattern, with no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819 translation. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820 #define PATFETCH_RAW(c) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 do {if (p == pend) return REG_EEND; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822 assert (p < pend); \
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
1823 c = itext_ichar (p); \
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
1824 INC_IBYTEPTR (p); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827 /* Go backwards one character in the pattern. */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
1828 #define PATUNFETCH DEC_IBYTEPTR (p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 /* If `translate' is non-null, return translate[D], else just D. We
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 cast the subscript to translate because some data is declared as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 `char *', to avoid warnings when a string constant is passed. But
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833 when we use a character as a subscript we must make it unsigned. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1834 #define RE_TRANSLATE(d) \
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1835 (TRANSLATE_P (translate) ? RE_TRANSLATE_1 (d) : (d))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837 /* Macros for outputting the compiled pattern into `buffer'. */
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 /* If the buffer isn't allocated when it comes in, use this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840 #define INIT_BUF_SIZE 32
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 /* 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
1843 #define GET_BUFFER_SPACE(n) \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1844 while (buf_end - bufp->buffer + (n) > (ptrdiff_t) bufp->allocated) \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 EXTEND_BUFFER ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847 /* 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
1848 #define BUF_PUSH(c) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850 GET_BUFFER_SPACE (1); \
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1851 *buf_end++ = (unsigned char) (c); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 /* 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
1856 #define BUF_PUSH_2(c1, c2) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 GET_BUFFER_SPACE (2); \
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1859 *buf_end++ = (unsigned char) (c1); \
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1860 *buf_end++ = (unsigned char) (c2); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862
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 /* As with BUF_PUSH_2, except for three bytes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 #define BUF_PUSH_3(c1, c2, c3) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 GET_BUFFER_SPACE (3); \
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1868 *buf_end++ = (unsigned char) (c1); \
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1869 *buf_end++ = (unsigned char) (c2); \
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1870 *buf_end++ = (unsigned char) (c3); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 /* 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
1875 relative address offset by the three bytes the jump itself occupies. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 #define STORE_JUMP(op, loc, to) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 store_op1 (op, loc, (to) - (loc) - 3)
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 /* Likewise, for a two-argument jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 #define STORE_JUMP2(op, loc, to, arg) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 store_op2 (op, loc, (to) - (loc) - 3, arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1883 /* Like `STORE_JUMP', but for inserting. Assume `buf_end' is the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1884 buffer end. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 #define INSERT_JUMP(op, loc, to) \
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1886 insert_op1 (op, loc, (to) - (loc) - 3, buf_end)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1887
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1888 /* Like `STORE_JUMP2', but for inserting. Assume `buf_end' is the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1889 buffer end. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 #define INSERT_JUMP2(op, loc, to, arg) \
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1891 insert_op2 (op, loc, (to) - (loc) - 3, arg, buf_end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 /* This is not an arbitrary limit: the arguments which represent offsets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 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
1896 be too small, many things would have to change. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 #define MAX_BUF_SIZE (1L << 16)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 /* Extend the buffer by twice its current size via realloc and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 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
1902 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
1903 being larger than MAX_BUF_SIZE, then flag memory exhausted. */
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1904 #define EXTEND_BUFFER() \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1905 do { \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1906 re_char *old_buffer = bufp->buffer; \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1907 if (bufp->allocated == MAX_BUF_SIZE) \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1908 return REG_ESIZE; \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1909 bufp->allocated <<= 1; \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1910 if (bufp->allocated > MAX_BUF_SIZE) \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1911 bufp->allocated = MAX_BUF_SIZE; \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1912 bufp->buffer = \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1913 (unsigned char *) xrealloc (bufp->buffer, bufp->allocated); \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1914 if (bufp->buffer == NULL) \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1915 return REG_ESPACE; \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1916 /* If the buffer moved, move all the pointers into it. */ \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1917 if (old_buffer != bufp->buffer) \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1918 { \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1919 buf_end = (buf_end - old_buffer) + bufp->buffer; \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1920 begalt = (begalt - old_buffer) + bufp->buffer; \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1921 if (fixup_alt_jump) \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1922 fixup_alt_jump = (fixup_alt_jump - old_buffer) + bufp->buffer; \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1923 if (laststart) \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1924 laststart = (laststart - old_buffer) + bufp->buffer; \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1925 if (pending_exact) \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1926 pending_exact = (pending_exact - old_buffer) + bufp->buffer; \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
1927 } \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928 } while (0)
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931 /* Since we have one byte reserved for the register number argument to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 {start,stop}_memory, the maximum number of groups we can report
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933 things about is what fits in that byte. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 #define MAX_REGNUM 255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936 /* But patterns can have more than `MAX_REGNUM' registers. We just
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1937 ignore the excess.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1938 #### not true! groups past this will fail in lots of ways, if we
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1939 ever have to backtrack.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1940 */
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1941 typedef int regnum_t;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
1943 #define INIT_REG_TRANSLATE_SIZE 5
428
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 /* Macros for the compile stack. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 /* Since offsets can go either forwards or backwards, this type needs to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 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
1949 typedef int pattern_offset_t;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 typedef struct
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 pattern_offset_t begalt_offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 pattern_offset_t fixup_alt_jump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 pattern_offset_t inner_group_offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956 pattern_offset_t laststart_offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957 regnum_t regnum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 } compile_stack_elt_t;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 typedef struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 compile_stack_elt_t *stack;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1964 int size;
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
1965 int avail; /* Offset of next open position. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 } compile_stack_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 #define INIT_COMPILE_STACK_SIZE 32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971 #define COMPILE_STACK_EMPTY (compile_stack.avail == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 #define COMPILE_STACK_FULL (compile_stack.avail == compile_stack.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 /* The next available element. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975 #define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail])
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 /* Set the bit for character C in a bit vector. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 #define SET_LIST_BIT(c) \
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1980 (buf_end[((unsigned char) (c)) / BYTEWIDTH] \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981 |= 1 << (((unsigned char) c) % BYTEWIDTH))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 /* Set the "bit" for character C in a range table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986 #define SET_RANGETAB_BIT(c) put_range_table (rtab, c, c, Qt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988 /* Set the "bit" for character c in the appropriate table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 #define SET_EITHER_BIT(c) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991 if (has_extended_chars) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992 SET_RANGETAB_BIT (c); \
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 SET_LIST_BIT (c); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1996
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1997 #else /* not MULE */
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 #define SET_EITHER_BIT(c) SET_LIST_BIT (c)
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 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2002
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2003
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2004 /* Get the next unsigned number in the uncompiled pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005 #define GET_UNSIGNED_NUMBER(num) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2006 { if (p != pend) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2007 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2008 PATFETCH (c); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2009 while (ISDIGIT (c)) \
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 if (num < 0) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2012 num = 0; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2013 num = num * 10 + c - '0'; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2014 if (p == pend) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2015 break; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2016 PATFETCH (c); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2017 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2018 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 #define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2022
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2023 #define IS_CHAR_CLASS(string) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2024 (STREQ (string, "alpha") || STREQ (string, "upper") \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2025 || STREQ (string, "lower") || STREQ (string, "digit") \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2026 || STREQ (string, "alnum") || STREQ (string, "xdigit") \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2027 || STREQ (string, "space") || STREQ (string, "print") \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2028 || STREQ (string, "punct") || STREQ (string, "graph") \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2029 || STREQ (string, "cntrl") || STREQ (string, "blank"))
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 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
2032 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
2033 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
2034 unsigned char *end);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2035 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
2036 unsigned char *end);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2037 static re_bool at_begline_loc_p (re_char *pattern, re_char *p,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2038 reg_syntax_t syntax);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2039 static re_bool at_endline_loc_p (re_char *p, re_char *pend, int syntax);
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2040 static re_bool group_in_compile_stack (compile_stack_type compile_stack,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041 regnum_t regnum);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2042 static reg_errcode_t compile_range (re_char **p_ptr, re_char *pend,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2043 RE_TRANSLATE_TYPE translate,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2044 reg_syntax_t syntax,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045 unsigned char *b);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046 #ifdef MULE
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2047 static reg_errcode_t compile_extended_range (re_char **p_ptr,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2048 re_char *pend,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2049 RE_TRANSLATE_TYPE translate,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050 reg_syntax_t syntax,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051 Lisp_Object rtab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2052 #endif /* MULE */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2053 static re_bool group_match_null_string_p (unsigned char **p,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054 unsigned char *end,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2055 register_info_type *reg_info);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2056 static re_bool alt_match_null_string_p (unsigned char *p, unsigned char *end,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057 register_info_type *reg_info);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2058 static re_bool common_op_match_null_string_p (unsigned char **p,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059 unsigned char *end,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060 register_info_type *reg_info);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2061 static int bcmp_translate (re_char *s1, re_char *s2,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2062 REGISTER int len, RE_TRANSLATE_TYPE translate
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2063 #ifdef emacs
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2064 , Internal_Format fmt, Lisp_Object lispobj
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2065 #endif
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2066 );
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2067 static int re_match_2_internal (struct re_pattern_buffer *bufp,
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2068 re_char *string1, int size1,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2069 re_char *string2, int size2, int pos,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2070 struct re_registers *regs, int stop
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2071 RE_LISP_CONTEXT_ARGS_DECL);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2072
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2073 #ifndef MATCH_MAY_ALLOCATE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2074
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2075 /* If we cannot allocate large objects within re_match_2_internal,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2076 we make the fail stack and register vectors global.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2077 The fail stack, we grow to the maximum size when a regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2078 is compiled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2079 The register vectors, we adjust in size each time we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2080 compile a regexp, according to the number of registers it needs. */
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 static fail_stack_type fail_stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2083
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2084 /* Size with which the following vectors are currently allocated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2085 That is so we can make them bigger as needed,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2086 but never make them smaller. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2087 static int regs_allocated_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2088
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2089 static re_char ** regstart, ** regend;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2090 static re_char ** old_regstart, ** old_regend;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2091 static re_char **best_regstart, **best_regend;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2092 static register_info_type *reg_info;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2093 static re_char **reg_dummy;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2094 static register_info_type *reg_info_dummy;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2095
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2096 /* Make the register vectors big enough for NUM_REGS registers,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2097 but don't make them smaller. */
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 static
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2100 regex_grow_registers (int num_regs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2101 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2102 if (num_regs > regs_allocated_size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2103 {
551
e9a3f8b4de53 [xemacs-hg @ 2001-05-21 05:26:06 by martinb]
martinb
parents: 544
diff changeset
2104 RETALLOC (regstart, num_regs, re_char *);
e9a3f8b4de53 [xemacs-hg @ 2001-05-21 05:26:06 by martinb]
martinb
parents: 544
diff changeset
2105 RETALLOC (regend, num_regs, re_char *);
e9a3f8b4de53 [xemacs-hg @ 2001-05-21 05:26:06 by martinb]
martinb
parents: 544
diff changeset
2106 RETALLOC (old_regstart, num_regs, re_char *);
e9a3f8b4de53 [xemacs-hg @ 2001-05-21 05:26:06 by martinb]
martinb
parents: 544
diff changeset
2107 RETALLOC (old_regend, num_regs, re_char *);
e9a3f8b4de53 [xemacs-hg @ 2001-05-21 05:26:06 by martinb]
martinb
parents: 544
diff changeset
2108 RETALLOC (best_regstart, num_regs, re_char *);
e9a3f8b4de53 [xemacs-hg @ 2001-05-21 05:26:06 by martinb]
martinb
parents: 544
diff changeset
2109 RETALLOC (best_regend, num_regs, re_char *);
e9a3f8b4de53 [xemacs-hg @ 2001-05-21 05:26:06 by martinb]
martinb
parents: 544
diff changeset
2110 RETALLOC (reg_info, num_regs, register_info_type);
e9a3f8b4de53 [xemacs-hg @ 2001-05-21 05:26:06 by martinb]
martinb
parents: 544
diff changeset
2111 RETALLOC (reg_dummy, num_regs, re_char *);
e9a3f8b4de53 [xemacs-hg @ 2001-05-21 05:26:06 by martinb]
martinb
parents: 544
diff changeset
2112 RETALLOC (reg_info_dummy, num_regs, register_info_type);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2114 regs_allocated_size = num_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2115 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2116 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2118 #endif /* not MATCH_MAY_ALLOCATE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2120 /* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2121 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
2122
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2123 Assumes the `allocated' (and perhaps `buffer') and `translate'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2124 fields are set in BUFP on entry.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2126 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
2127 contents of BUFP are undefined):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2128 `buffer' is the compiled pattern;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2129 `syntax' is set to SYNTAX;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2130 `used' is set to the length of the compiled pattern;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2131 `fastmap_accurate' is zero;
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2132 `re_ngroups' is the number of groups/subexpressions (including shy
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2133 groups) in PATTERN;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2134 `re_nsub' is the number of non-shy groups in PATTERN;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2135 `not_bol' and `not_eol' are zero;
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 The `fastmap' and `newline_anchor' fields are neither
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2138 examined nor set. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2140 /* Return, freeing storage we allocated. */
1726
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 1497
diff changeset
2141 #define FREE_STACK_RETURN(value) \
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 1497
diff changeset
2142 do \
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 1497
diff changeset
2143 { \
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4832
diff changeset
2144 xfree (compile_stack.stack); \
1726
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 1497
diff changeset
2145 return value; \
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
2146 } while (0)
428
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 static reg_errcode_t
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2149 regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150 struct re_pattern_buffer *bufp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2151 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2152 /* We fetch characters from PATTERN here. We declare these as int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2153 (or possibly long) so that chars above 127 can be used as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2154 array indices. The macros that fetch a character from the pattern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2155 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
2156 get bitten by negative numbers here. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2157 /* XEmacs change: used to be unsigned char. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2158 REGISTER EMACS_INT c, c1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2160 /* A random temporary spot in PATTERN. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2161 re_char *p1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2163 /* Points to the end of the buffer, where we should append. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2164 REGISTER unsigned char *buf_end;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2166 /* Keeps track of unclosed groups. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2167 compile_stack_type compile_stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2169 /* Points to the current (ending) position in the pattern. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2170 re_char *p = pattern;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2171 re_char *pend = pattern + size;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2173 /* How to translate the characters in the pattern. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2174 RE_TRANSLATE_TYPE translate = bufp->translate;
428
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 /* Address of the count-byte of the most recently inserted `exactn'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2177 command. This makes it possible to tell if a new exact-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2178 character can be added to that command or if the character requires
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2179 a new `exactn' command. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2180 unsigned char *pending_exact = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2182 /* Address of start of the most recently finished expression.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2183 This tells, e.g., postfix * where to find the start of its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184 operand. Reset at the beginning of groups and alternatives. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2185 unsigned char *laststart = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187 /* Address of beginning of regexp, or inside of last group. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 unsigned char *begalt;
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 /* Place in the uncompiled pattern (i.e., the {) to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2191 which to go back if the interval is invalid. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2192 re_char *beg_interval;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2194 /* 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
2195 the containing expression. Each alternative of an `or' -- except the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2196 last -- ends with a forward jump of this sort. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197 unsigned char *fixup_alt_jump = 0;
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 /* Counts open-groups as they are encountered. Remembered for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2200 matching close-group on the compile stack, so the same register
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2201 number is put in the stop_memory as the start_memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2202 regnum_t regnum = 0;
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 #ifdef DEBUG
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
2205 if (debug_regexps & RE_DEBUG_COMPILATION)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2206 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
2207 int debug_count;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2208
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
2209 DEBUG_PRINT1 ("\nCompiling pattern: ");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2210 for (debug_count = 0; debug_count < size; debug_count++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2211 putchar (pattern[debug_count]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2212 putchar ('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2213 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2214 #endif /* DEBUG */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2215
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2216 /* Initialize the compile stack. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2217 compile_stack.stack = TALLOC (INIT_COMPILE_STACK_SIZE, compile_stack_elt_t);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2218 if (compile_stack.stack == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2219 return REG_ESPACE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2221 compile_stack.size = INIT_COMPILE_STACK_SIZE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2222 compile_stack.avail = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2224 /* Initialize the pattern buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2225 bufp->syntax = syntax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2226 bufp->fastmap_accurate = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2227 bufp->not_bol = bufp->not_eol = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2229 /* 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
2230 printer (for debugging) will think there's no pattern. We reset it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2231 at the end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2232 bufp->used = 0;
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 /* Always count groups, whether or not bufp->no_sub is set. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2235 bufp->re_nsub = 0;
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2236 bufp->re_ngroups = 0;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2237
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2238 bufp->warned_about_incompatible_back_references = 0;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2239
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2240 if (bufp->external_to_internal_register == 0)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2241 {
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2242 bufp->external_to_internal_register_size = INIT_REG_TRANSLATE_SIZE;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2243 RETALLOC (bufp->external_to_internal_register,
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2244 bufp->external_to_internal_register_size,
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2245 int);
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2246 }
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2247
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2248 {
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2249 int i;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2250
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2251 bufp->external_to_internal_register[0] = 0;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2252 for (i = 1; i < bufp->external_to_internal_register_size; i++)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2253 bufp->external_to_internal_register[i] = (int) 0xDEADBEEF;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2254 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2256 #if !defined (emacs) && !defined (SYNTAX_TABLE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2257 /* Initialize the syntax table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2258 init_syntax_once ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2259 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2260
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2261 if (bufp->allocated == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2262 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2263 if (bufp->buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2264 { /* If zero allocated, but buffer is non-null, try to realloc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2265 enough space. This loses if buffer's address is bogus, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2266 that is the user's responsibility. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2267 RETALLOC (bufp->buffer, INIT_BUF_SIZE, unsigned char);
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2270 { /* Caller did not allocate a buffer. Do it for them. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2271 bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2272 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2273 if (!bufp->buffer) FREE_STACK_RETURN (REG_ESPACE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2275 bufp->allocated = INIT_BUF_SIZE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2276 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2277
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2278 begalt = buf_end = bufp->buffer;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2280 /* Loop through the uncompiled pattern until we're at the end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2281 while (p != pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2282 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2283 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2284
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2285 switch (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2286 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2287 case '^':
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 if ( /* If at start of pattern, it's an operator. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2290 p == pattern + 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2291 /* If context independent, it's an operator. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2292 || syntax & RE_CONTEXT_INDEP_ANCHORS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293 /* Otherwise, depends on what's come before. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2294 || at_begline_loc_p (pattern, p, syntax))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2295 BUF_PUSH (begline);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2297 goto normal_char;
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 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2300
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 case '$':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2303 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2304 if ( /* If at end of pattern, it's an operator. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2305 p == pend
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2306 /* If context independent, it's an operator. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2307 || syntax & RE_CONTEXT_INDEP_ANCHORS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2308 /* Otherwise, depends on what's next. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2309 || at_endline_loc_p (p, pend, syntax))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2310 BUF_PUSH (endline);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2311 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2312 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2313 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2314 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2315
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2316
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2317 case '+':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2318 case '?':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2319 if ((syntax & RE_BK_PLUS_QM)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2320 || (syntax & RE_LIMITED_OPS))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2321 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2322 handle_plus:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2323 case '*':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324 /* If there is no previous pattern... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2325 if (!laststart)
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 if (syntax & RE_CONTEXT_INVALID_OPS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2328 FREE_STACK_RETURN (REG_BADRPT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2329 else if (!(syntax & RE_CONTEXT_INDEP_OPS))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2330 goto normal_char;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2333 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2334 /* true means zero/many matches are allowed. */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2335 re_bool zero_times_ok = c != '+';
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2336 re_bool many_times_ok = c != '?';
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2338 /* true means match shortest string possible. */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2339 re_bool minimal = false;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2341 /* If there is a sequence of repetition chars, collapse it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2342 down to just one (the right one). We can't combine
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2343 interval operators with these because of, e.g., `a{2}*',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2344 which should only match an even number of `a's. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2345 while (p != pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2346 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2347 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2348
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2349 if (c == '*' || (!(syntax & RE_BK_PLUS_QM)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2350 && (c == '+' || c == '?')))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2351 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2352
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2353 else if (syntax & RE_BK_PLUS_QM && c == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2354 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2355 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
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 PATFETCH (c1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2358 if (!(c1 == '+' || c1 == '?'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2359 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2360 PATUNFETCH;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2361 PATUNFETCH;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2362 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2363 }
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 c = c1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2366 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2367 else
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 PATUNFETCH;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2370 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2371 }
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 /* If we get here, we found another repeat character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2374 if (!(syntax & RE_NO_MINIMAL_MATCHING))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2375 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
2376 /* "*?" and "+?" and "??" are okay (and mean match
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
2377 minimally), but other sequences (such as "*??" and
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
2378 "+++") are rejected (reserved for future use). */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2379 if (minimal || c != '?')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2380 FREE_STACK_RETURN (REG_BADRPT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2381 minimal = true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2382 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2383 else
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 zero_times_ok |= c != '+';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2386 many_times_ok |= c != '?';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2387 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2388 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2389
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2390 /* Star, etc. applied to an empty pattern is equivalent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2391 to an empty pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2392 if (!laststart)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2393 break;
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 /* Now we know whether zero matches is allowed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2396 and whether two or more matches is allowed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2397 and whether we want minimal or maximal matching. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2398 if (minimal)
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 if (!many_times_ok)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2401 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2402 /* "a??" becomes:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2403 0: /on_failure_jump to 6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2404 3: /jump to 9
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2405 6: /exactn/1/A
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2406 9: end of pattern.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2407 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2408 GET_BUFFER_SPACE (6);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2409 INSERT_JUMP (jump, laststart, buf_end + 3);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2410 buf_end += 3;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2411 INSERT_JUMP (on_failure_jump, laststart, laststart + 6);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2412 buf_end += 3;
428
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 else if (zero_times_ok)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2415 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2416 /* "a*?" becomes:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2417 0: /jump to 6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2418 3: /exactn/1/A
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2419 6: /on_failure_jump to 3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2420 9: end of pattern.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2421 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2422 GET_BUFFER_SPACE (6);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2423 INSERT_JUMP (jump, laststart, buf_end + 3);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2424 buf_end += 3;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2425 STORE_JUMP (on_failure_jump, buf_end, laststart + 3);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2426 buf_end += 3;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2427 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2428 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2429 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2430 /* "a+?" becomes:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2431 0: /exactn/1/A
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2432 3: /on_failure_jump to 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2433 6: end of pattern.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2434 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2435 GET_BUFFER_SPACE (3);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2436 STORE_JUMP (on_failure_jump, buf_end, laststart);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2437 buf_end += 3;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2438 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2439 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2440 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2441 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2442 /* Are we optimizing this jump? */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2443 re_bool keep_string_p = false;
428
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 if (many_times_ok)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2446 { /* More than one repetition is allowed, so put in
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2447 at the end a backward relative jump from
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2448 `buf_end' to before the next jump we're going
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2449 to put in below (which jumps from laststart to
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2450 after this jump).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2452 But if we are at the `*' in the exact sequence `.*\n',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2453 insert an unconditional jump backwards to the .,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2454 instead of the beginning of the loop. This way we only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2455 push a failure point once, instead of every time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2456 through the loop. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2457 assert (p - 1 > pattern);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2458
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2459 /* Allocate the space for the jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2460 GET_BUFFER_SPACE (3);
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 /* We know we are not at the first character of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2463 pattern, because laststart was nonzero. And we've
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2464 already incremented `p', by the way, to be the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2465 character after the `*'. Do we have to do something
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2466 analogous here for null bytes, because of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2467 RE_DOT_NOT_NULL? */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2468 if (*(p - 2) == '.'
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2469 && zero_times_ok
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2470 && p < pend && *p == '\n'
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2471 && !(syntax & RE_DOT_NEWLINE))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2472 { /* We have .*\n. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2473 STORE_JUMP (jump, buf_end, laststart);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2474 keep_string_p = true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2475 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2476 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2477 /* Anything else. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2478 STORE_JUMP (maybe_pop_jump, buf_end, laststart - 3);
428
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 /* We've added more stuff to the buffer. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2481 buf_end += 3;
428
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
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2484 /* On failure, jump from laststart to buf_end + 3,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2485 which will be the end of the buffer after this jump
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2486 is inserted. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2487 GET_BUFFER_SPACE (3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2488 INSERT_JUMP (keep_string_p ? on_failure_keep_string_jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2489 : on_failure_jump,
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2490 laststart, buf_end + 3);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2491 buf_end += 3;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2493 if (!zero_times_ok)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2494 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2495 /* At least one repetition is required, so insert a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2496 `dummy_failure_jump' before the initial
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2497 `on_failure_jump' instruction of the loop. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2498 effects a skip over that instruction the first time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2499 we hit that loop. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2500 GET_BUFFER_SPACE (3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2501 INSERT_JUMP (dummy_failure_jump, laststart, laststart + 6);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2502 buf_end += 3;
428
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2505 pending_exact = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2506 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2507 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2508
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 case '.':
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2511 laststart = buf_end;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2512 BUF_PUSH (anychar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2513 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2514
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2515
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2516 case '[':
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 /* XEmacs change: this whole section */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2519 re_bool had_char_class = false;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2520 #ifdef MULE
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2521 re_bool has_extended_chars = false;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2522 REGISTER Lisp_Object rtab = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2523 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2524
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2525 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2527 /* Ensure that we have enough space to push a charset: the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2528 opcode, the length count, and the bitset; 34 bytes in all. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2529 GET_BUFFER_SPACE (34);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2530
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2531 laststart = buf_end;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2532
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2533 /* We test `*p == '^' twice, instead of using an if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2534 statement, so we only need one BUF_PUSH. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2535 BUF_PUSH (*p == '^' ? charset_not : charset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2536 if (*p == '^')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2537 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2538
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2539 /* Remember the first position in the bracket expression. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2540 p1 = p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2541
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2542 /* Push the number of bytes in the bitmap. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2543 BUF_PUSH ((1 << BYTEWIDTH) / BYTEWIDTH);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2544
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2545 /* Clear the whole map. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2546 memset (buf_end, 0, (1 << BYTEWIDTH) / BYTEWIDTH);
428
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 /* charset_not matches newline according to a syntax bit. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2549 if ((re_opcode_t) buf_end[-2] == charset_not
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2550 && (syntax & RE_HAT_LISTS_NOT_NEWLINE))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2551 SET_LIST_BIT ('\n');
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 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2554 start_over_with_extended:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2555 if (has_extended_chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2556 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2557 /* There are extended chars here, which means we need to start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2558 over and shift to unified range-table format. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2559 if (buf_end[-2] == charset)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2560 buf_end[-2] = charset_mule;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2561 else
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2562 buf_end[-2] = charset_mule_not;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2563 buf_end--;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2564 p = p1; /* go back to the beginning of the charset, after
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2565 a possible ^. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2566 rtab = Vthe_lisp_rangetab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2567 Fclear_range_table (rtab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2568
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2569 /* charset_not matches newline according to a syntax bit. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2570 if ((re_opcode_t) buf_end[-1] == charset_mule_not
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2571 && (syntax & RE_HAT_LISTS_NOT_NEWLINE))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2572 SET_EITHER_BIT ('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2573 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2574 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2576 /* Read in characters and ranges, setting map bits. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2577 for (;;)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2578 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2579 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2580
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2581 PATFETCH (c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2582
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2583 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2584 if (c >= 0x80 && !has_extended_chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2585 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2586 has_extended_chars = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2587 /* Frumble-bumble, we've found some extended chars.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2588 Need to start over, process everything using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2589 the general extended-char mechanism, and need
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2590 to use charset_mule and charset_mule_not instead
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2591 of charset and charset_not. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2592 goto start_over_with_extended;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2593 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2594 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2595 /* \ might escape characters inside [...] and [^...]. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2596 if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2597 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2598 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2599
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2600 PATFETCH (c1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2601 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2602 if (c1 >= 0x80 && !has_extended_chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2603 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2604 has_extended_chars = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2605 goto start_over_with_extended;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2606 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2607 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2608 SET_EITHER_BIT (c1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2609 continue;
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 /* Could be the end of the bracket expression. If it's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2613 not (i.e., when the bracket expression is `[]' so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2614 far), the ']' character bit gets set way below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2615 if (c == ']' && p != p1 + 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2616 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2617
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2618 /* 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
2619 was a character class. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2620 if (had_char_class && c == '-' && *p != ']')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2621 FREE_STACK_RETURN (REG_ERANGE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2622
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2623 /* 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
2624 was a character: if this is a hyphen not at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2625 beginning or the end of a list, then it's the range
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2626 operator. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2627 if (c == '-'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2628 && !(p - 2 >= pattern && p[-2] == '[')
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2629 && !(p - 3 >= pattern && p[-3] == '[' && p[-2] == '^')
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2630 && *p != ']')
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 reg_errcode_t ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2633
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2634 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2635 if (* (unsigned char *) p >= 0x80 && !has_extended_chars)
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 has_extended_chars = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2638 goto start_over_with_extended;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2639 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2640 if (has_extended_chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641 ret = compile_extended_range (&p, pend, translate,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2642 syntax, rtab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2644 #endif /* MULE */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2645 ret = compile_range (&p, pend, translate, syntax, buf_end);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2646 if (ret != REG_NOERROR) FREE_STACK_RETURN (ret);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2647 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2649 else if (p[0] == '-' && p[1] != ']')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2650 { /* This handles ranges made up of characters only. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2651 reg_errcode_t ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2652
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2653 /* Move past the `-'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2654 PATFETCH (c1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2655
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2656 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2657 if (* (unsigned char *) p >= 0x80 && !has_extended_chars)
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 has_extended_chars = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2660 goto start_over_with_extended;
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 if (has_extended_chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2663 ret = compile_extended_range (&p, pend, translate,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2664 syntax, rtab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2665 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2666 #endif /* MULE */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2667 ret = compile_range (&p, pend, translate, syntax, buf_end);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2668 if (ret != REG_NOERROR) FREE_STACK_RETURN (ret);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2671 /* See if we're at the beginning of a possible character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2672 class. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2673
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2674 else if (syntax & RE_CHAR_CLASSES && c == '[' && *p == ':')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2675 { /* Leave room for the null. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2676 char str[CHAR_CLASS_MAX_LENGTH + 1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2677
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2678 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2679 c1 = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2680
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2681 /* If pattern is `[[:'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2682 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
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 for (;;)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2685 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2686 /* #### This code is unused.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2687 Correctness is not checked after TRT
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2688 table change. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2689 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2690 if (c == ':' || c == ']' || p == pend
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2691 || c1 == CHAR_CLASS_MAX_LENGTH)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2692 break;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2693 str[c1++] = (char) c;
428
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 str[c1] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2696
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2697 /* If isn't a word bracketed by `[:' and `:]':
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2698 undo the ending character, the letters, and leave
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2699 the leading `:' and `[' (but set bits for them). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2700 if (c == ':' && *p == ']')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2701 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2702 int ch;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2703 re_bool is_alnum = STREQ (str, "alnum");
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2704 re_bool is_alpha = STREQ (str, "alpha");
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2705 re_bool is_blank = STREQ (str, "blank");
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2706 re_bool is_cntrl = STREQ (str, "cntrl");
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2707 re_bool is_digit = STREQ (str, "digit");
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2708 re_bool is_graph = STREQ (str, "graph");
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2709 re_bool is_lower = STREQ (str, "lower");
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2710 re_bool is_print = STREQ (str, "print");
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2711 re_bool is_punct = STREQ (str, "punct");
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2712 re_bool is_space = STREQ (str, "space");
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2713 re_bool is_upper = STREQ (str, "upper");
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
2714 re_bool is_xdigit = STREQ (str, "xdigit");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2715
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2716 if (!IS_CHAR_CLASS (str))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2717 FREE_STACK_RETURN (REG_ECTYPE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2718
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2719 /* Throw away the ] at the end of the character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2720 class. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2721 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2722
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2723 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2725 for (ch = 0; ch < 1 << BYTEWIDTH; ch++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2726 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2727 /* This was split into 3 if's to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2728 avoid an arbitrary limit in some compiler. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2729 if ( (is_alnum && ISALNUM (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2730 || (is_alpha && ISALPHA (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2731 || (is_blank && ISBLANK (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2732 || (is_cntrl && ISCNTRL (ch)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2733 SET_EITHER_BIT (ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2734 if ( (is_digit && ISDIGIT (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2735 || (is_graph && ISGRAPH (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2736 || (is_lower && ISLOWER (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2737 || (is_print && ISPRINT (ch)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2738 SET_EITHER_BIT (ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2739 if ( (is_punct && ISPUNCT (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2740 || (is_space && ISSPACE (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2741 || (is_upper && ISUPPER (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2742 || (is_xdigit && ISXDIGIT (ch)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2743 SET_EITHER_BIT (ch);
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 had_char_class = true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2746 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2747 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2748 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2749 c1++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2750 while (c1--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2751 PATUNFETCH;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2752 SET_EITHER_BIT ('[');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2753 SET_EITHER_BIT (':');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2754 had_char_class = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2755 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2756 }
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 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2759 had_char_class = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2760 SET_EITHER_BIT (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2761 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2764 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2765 if (has_extended_chars)
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 /* We have a range table, not a bit vector. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2768 int bytes_needed =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2769 unified_range_table_bytes_needed (rtab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2770 GET_BUFFER_SPACE (bytes_needed);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2771 unified_range_table_copy_data (rtab, buf_end);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2772 buf_end += unified_range_table_bytes_used (buf_end);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2773 break;
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 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2776 /* Discard any (non)matching list bytes that are all 0 at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2777 end of the map. Decrease the map-length byte too. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2778 while ((int) buf_end[-1] > 0 && buf_end[buf_end[-1] - 1] == 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2779 buf_end[-1]--;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2780 buf_end += buf_end[-1];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2781 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2782 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2783
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2785 case '(':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2786 if (syntax & RE_NO_BK_PARENS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2787 goto handle_open;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2788 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2789 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2790
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2791
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2792 case ')':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2793 if (syntax & RE_NO_BK_PARENS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2794 goto handle_close;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2795 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2796 goto normal_char;
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 case '\n':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2800 if (syntax & RE_NEWLINE_ALT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2801 goto handle_alt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2802 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2803 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2804
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2805
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2806 case '|':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2807 if (syntax & RE_NO_BK_VBAR)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2808 goto handle_alt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2809 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2810 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2811
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 case '{':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2814 if (syntax & RE_INTERVALS && syntax & RE_NO_BK_BRACES)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2815 goto handle_interval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2816 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2817 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2818
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2819
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2820 case '\\':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2821 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2822
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2823 /* Do not translate the character after the \, so that we can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2824 distinguish, e.g., \B from \b, even if we normally would
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2825 translate, e.g., B to b. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2826 PATFETCH_RAW (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2828 switch (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2829 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2830 case '(':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2831 if (syntax & RE_NO_BK_PARENS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2832 goto normal_backslash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2833
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2834 handle_open:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2835 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2836 regnum_t r;
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2837 int shy = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2838
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2839 if (!(syntax & RE_NO_SHY_GROUPS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2840 && p != pend
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2841 && *p == '?')
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2842 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2843 p++;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2844 PATFETCH (c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2845 switch (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2846 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2847 case ':': /* shy groups */
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2848 shy = 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2849 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2850
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2851 /* All others are reserved for future constructs. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2852 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2853 FREE_STACK_RETURN (REG_BADPAT);
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 }
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2856
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2857 r = ++regnum;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2858 bufp->re_ngroups++;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2859 if (!shy)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2860 {
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2861 bufp->re_nsub++;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2862 while (bufp->external_to_internal_register_size <=
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2863 bufp->re_nsub)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2864 {
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2865 int i;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2866 int old_size =
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2867 bufp->external_to_internal_register_size;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2868 bufp->external_to_internal_register_size += 5;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2869 RETALLOC (bufp->external_to_internal_register,
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2870 bufp->external_to_internal_register_size,
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2871 int);
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2872 /* debugging */
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2873 for (i = old_size;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2874 i < bufp->external_to_internal_register_size; i++)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2875 bufp->external_to_internal_register[i] =
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2876 (int) 0xDEADBEEF;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2877 }
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2878
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2879 bufp->external_to_internal_register[bufp->re_nsub] =
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2880 bufp->re_ngroups;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2881 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2882
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2883 if (COMPILE_STACK_FULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2884 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2885 RETALLOC (compile_stack.stack, compile_stack.size << 1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2886 compile_stack_elt_t);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2887 if (compile_stack.stack == NULL) return REG_ESPACE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2888
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2889 compile_stack.size <<= 1;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2892 /* These are the values to restore when we hit end of this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2893 group. They are all relative offsets, so that if the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2894 whole pattern moves because of realloc, they will still
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2895 be valid. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2896 COMPILE_STACK_TOP.begalt_offset = begalt - bufp->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2897 COMPILE_STACK_TOP.fixup_alt_jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2898 = fixup_alt_jump ? fixup_alt_jump - bufp->buffer + 1 : 0;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2899 COMPILE_STACK_TOP.laststart_offset = buf_end - bufp->buffer;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2900 COMPILE_STACK_TOP.regnum = r;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2901
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2902 /* We will eventually replace the 0 with the number of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2903 groups inner to this one. But do not push a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2904 start_memory for groups beyond the last one we can
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2905 represent in the compiled pattern.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2906 #### bad bad bad. this will fail in lots of ways, if we
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2907 ever have to backtrack for these groups.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
2908 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2909 if (r <= MAX_REGNUM)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2910 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2911 COMPILE_STACK_TOP.inner_group_offset
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2912 = buf_end - bufp->buffer + 2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2913 BUF_PUSH_3 (start_memory, r, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2915
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2916 compile_stack.avail++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2917
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2918 fixup_alt_jump = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2919 laststart = 0;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2920 begalt = buf_end;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2921 /* If we've reached MAX_REGNUM groups, then this open
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2922 won't actually generate any code, so we'll have to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2923 clear pending_exact explicitly. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2924 pending_exact = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2925 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2926 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2927
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2928
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2929 case ')':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2930 if (syntax & RE_NO_BK_PARENS) goto normal_backslash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2931
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2932 if (COMPILE_STACK_EMPTY) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2933 if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2934 goto normal_backslash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2935 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2936 FREE_STACK_RETURN (REG_ERPAREN);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2937 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2938
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2939 handle_close:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2940 if (fixup_alt_jump)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2941 { /* Push a dummy failure point at the end of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2942 alternative for a possible future
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2943 `pop_failure_jump' to pop. See comments at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2944 `push_dummy_failure' in `re_match_2'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2945 BUF_PUSH (push_dummy_failure);
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 /* We allocated space for this jump when we assigned
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2948 to `fixup_alt_jump', in the `handle_alt' case below. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2949 STORE_JUMP (jump_past_alt, fixup_alt_jump, buf_end - 1);
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2952 /* See similar code for backslashed left paren above. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2953 if (COMPILE_STACK_EMPTY) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2954 if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2955 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2956 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2957 FREE_STACK_RETURN (REG_ERPAREN);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2960 /* Since we just checked for an empty stack above, this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2961 ``can't happen''. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2962 assert (compile_stack.avail != 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2963 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2964 /* We don't just want to restore into `regnum', because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2965 later groups should continue to be numbered higher,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2966 as in `(ab)c(de)' -- the second group is #2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2967 regnum_t this_group_regnum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2968
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2969 compile_stack.avail--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2970 begalt = bufp->buffer + COMPILE_STACK_TOP.begalt_offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2971 fixup_alt_jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2972 = COMPILE_STACK_TOP.fixup_alt_jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2973 ? bufp->buffer + COMPILE_STACK_TOP.fixup_alt_jump - 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2974 : 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2975 laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2976 this_group_regnum = COMPILE_STACK_TOP.regnum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977 /* If we've reached MAX_REGNUM groups, then this open
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2978 won't actually generate any code, so we'll have to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979 clear pending_exact explicitly. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2980 pending_exact = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2981
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982 /* 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
2983 groups were inside this one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2984 if (this_group_regnum <= MAX_REGNUM)
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 unsigned char *inner_group_loc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2987 = bufp->buffer + COMPILE_STACK_TOP.inner_group_offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2988
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989 *inner_group_loc = regnum - this_group_regnum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2990 BUF_PUSH_3 (stop_memory, this_group_regnum,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2991 regnum - this_group_regnum);
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2994 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2996
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2997 case '|': /* `\|'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2998 if (syntax & RE_LIMITED_OPS || syntax & RE_NO_BK_VBAR)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2999 goto normal_backslash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3000 handle_alt:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3001 if (syntax & RE_LIMITED_OPS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002 goto normal_char;
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 /* Insert before the previous alternative a jump which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3005 jumps to this alternative if the former fails. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3006 GET_BUFFER_SPACE (3);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3007 INSERT_JUMP (on_failure_jump, begalt, buf_end + 6);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3008 pending_exact = 0;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3009 buf_end += 3;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3010
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3011 /* The alternative before this one has a jump after it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012 which gets executed if it gets matched. Adjust that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3013 jump so it will jump to this alternative's analogous
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3014 jump (put in below, which in turn will jump to the next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3015 (if any) alternative's such jump, etc.). The last such
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3016 jump jumps to the correct final destination. A picture:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3017 _____ _____
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3018 | | | |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3019 | v | v
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3020 a | b | c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3021
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3022 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
3023 three-byte space after `a'. We'll put in the jump, set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3024 fixup_alt_jump to right after `b', and leave behind three
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3025 bytes which we'll fill in when we get to after `c'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3026
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3027 if (fixup_alt_jump)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3028 STORE_JUMP (jump_past_alt, fixup_alt_jump, buf_end);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3029
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3030 /* Mark and leave space for a jump after this alternative,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3031 to be filled in later either by next alternative or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3032 when know we're at the end of a series of alternatives. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3033 fixup_alt_jump = buf_end;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3034 GET_BUFFER_SPACE (3);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3035 buf_end += 3;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3036
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3037 laststart = 0;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3038 begalt = buf_end;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3039 break;
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 case '{':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3043 /* If \{ is a literal. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3044 if (!(syntax & RE_INTERVALS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3045 /* If we're at `\{' and it's not the open-interval
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3046 operator. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3047 || ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3048 || (p - 2 == pattern && p == pend))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3049 goto normal_backslash;
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 handle_interval:
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 /* If got here, then the syntax allows intervals. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3054
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3055 /* At least (most) this many matches must be made. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3056 int lower_bound = -1, upper_bound = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3057
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3058 beg_interval = p - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3059
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3060 if (p == pend)
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 (syntax & RE_NO_BK_BRACES)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3063 goto unfetch_interval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3064 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3065 FREE_STACK_RETURN (REG_EBRACE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3066 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3067
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3068 GET_UNSIGNED_NUMBER (lower_bound);
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 if (c == ',')
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 GET_UNSIGNED_NUMBER (upper_bound);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3073 if (upper_bound < 0) upper_bound = RE_DUP_MAX;
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3076 /* Interval such as `{1}' => match exactly once. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3077 upper_bound = lower_bound;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3078
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3079 if (lower_bound < 0 || upper_bound > RE_DUP_MAX
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3080 || lower_bound > upper_bound)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3081 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3082 if (syntax & RE_NO_BK_BRACES)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3083 goto unfetch_interval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3084 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3085 FREE_STACK_RETURN (REG_BADBR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3086 }
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 if (!(syntax & RE_NO_BK_BRACES))
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 if (c != '\\') FREE_STACK_RETURN (REG_EBRACE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3091
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3092 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3093 }
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 if (c != '}')
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 if (syntax & RE_NO_BK_BRACES)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3098 goto unfetch_interval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3099 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3100 FREE_STACK_RETURN (REG_BADBR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3101 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3102
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3103 /* We just parsed a valid interval. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3104
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3105 /* If it's invalid to have no preceding re. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3106 if (!laststart)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3107 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3108 if (syntax & RE_CONTEXT_INVALID_OPS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3109 FREE_STACK_RETURN (REG_BADRPT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3110 else if (syntax & RE_CONTEXT_INDEP_OPS)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3111 laststart = buf_end;
428
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 goto unfetch_interval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3114 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3116 /* If the upper bound is zero, don't want to succeed at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3117 all; jump from `laststart' to `b + 3', which will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3118 the end of the buffer after we insert the jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3119 if (upper_bound == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3120 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3121 GET_BUFFER_SPACE (3);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3122 INSERT_JUMP (jump, laststart, buf_end + 3);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3123 buf_end += 3;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3124 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3126 /* Otherwise, we have a nontrivial interval. When
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3127 we're all done, the pattern will look like:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3128 set_number_at <jump count> <upper bound>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3129 set_number_at <succeed_n count> <lower bound>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3130 succeed_n <after jump addr> <succeed_n count>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3131 <body of loop>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3132 jump_n <succeed_n addr> <jump count>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3133 (The upper bound and `jump_n' are omitted if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3134 `upper_bound' is 1, though.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3135 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3136 { /* If the upper bound is > 1, we need to insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3137 more at the end of the loop. */
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
3138 int nbytes = 10 + (upper_bound > 1) * 10;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3140 GET_BUFFER_SPACE (nbytes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3142 /* Initialize lower bound of the `succeed_n', even
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3143 though it will be set during matching by its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3144 attendant `set_number_at' (inserted next),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3145 because `re_compile_fastmap' needs to know.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3146 Jump to the `jump_n' we might insert below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3147 INSERT_JUMP2 (succeed_n, laststart,
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3148 buf_end + 5 + (upper_bound > 1) * 5,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3149 lower_bound);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3150 buf_end += 5;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3151
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3152 /* Code to initialize the lower bound. Insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3153 before the `succeed_n'. The `5' is the last two
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3154 bytes of this `set_number_at', plus 3 bytes of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3155 the following `succeed_n'. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3156 insert_op2 (set_number_at, laststart, 5, lower_bound, buf_end);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3157 buf_end += 5;
428
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 if (upper_bound > 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3160 { /* More than one repetition is allowed, so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3161 append a backward jump to the `succeed_n'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3162 that starts this interval.
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 When we've reached this during matching,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3165 we'll have matched the interval once, so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3166 jump back only `upper_bound - 1' times. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3167 STORE_JUMP2 (jump_n, buf_end, laststart + 5,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3168 upper_bound - 1);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3169 buf_end += 5;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3171 /* The location we want to set is the second
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3172 parameter of the `jump_n'; that is `b-2' as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3173 an absolute address. `laststart' will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3174 the `set_number_at' we're about to insert;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3175 `laststart+3' the number to set, the source
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3176 for the relative address. But we are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3177 inserting into the middle of the pattern --
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3178 so everything is getting moved up by 5.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3179 Conclusion: (b - 2) - (laststart + 3) + 5,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3180 i.e., b - laststart.
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 We insert this at the beginning of the loop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3183 so that if we fail during matching, we'll
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3184 reinitialize the bounds. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3185 insert_op2 (set_number_at, laststart,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3186 buf_end - laststart,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3187 upper_bound - 1, buf_end);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3188 buf_end += 5;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3189 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3190 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3191 pending_exact = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3192 beg_interval = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3193 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3194 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3195
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3196 unfetch_interval:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3197 /* If an invalid interval, match the characters as literals. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3198 assert (beg_interval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3199 p = beg_interval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3200 beg_interval = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3202 /* normal_char and normal_backslash need `c'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3203 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3205 if (!(syntax & RE_NO_BK_BRACES))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3206 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3207 if (p > pattern && p[-1] == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3208 goto normal_backslash;
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 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3211
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3212 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3213 /* There is no way to specify the before_dot and after_dot
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3214 operators. rms says this is ok. --karl */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3215 case '=':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3216 BUF_PUSH (at_dot);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3217 break;
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 case 's':
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3220 laststart = buf_end;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3221 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3222 /* XEmacs addition */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3223 if (c >= 0x80 || syntax_spec_code[c] == 0377)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3224 FREE_STACK_RETURN (REG_ESYNTAX);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3225 BUF_PUSH_2 (syntaxspec, syntax_spec_code[c]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3226 break;
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 case 'S':
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3229 laststart = buf_end;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3230 PATFETCH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3231 /* XEmacs addition */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3232 if (c >= 0x80 || syntax_spec_code[c] == 0377)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3233 FREE_STACK_RETURN (REG_ESYNTAX);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3234 BUF_PUSH_2 (notsyntaxspec, syntax_spec_code[c]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3235 break;
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 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3238 /* 97.2.17 jhod merged in to XEmacs from mule-2.3 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3239 case 'c':
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3240 laststart = buf_end;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3241 PATFETCH_RAW (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3242 if (c < 32 || c > 127)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3243 FREE_STACK_RETURN (REG_ECATEGORY);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3244 BUF_PUSH_2 (categoryspec, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3245 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3247 case 'C':
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3248 laststart = buf_end;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3249 PATFETCH_RAW (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3250 if (c < 32 || c > 127)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3251 FREE_STACK_RETURN (REG_ECATEGORY);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3252 BUF_PUSH_2 (notcategoryspec, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3253 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3254 /* end of category patch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3255 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3256 #endif /* emacs */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3259 case 'w':
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3260 laststart = buf_end;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3261 BUF_PUSH (wordchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3262 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3264
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3265 case 'W':
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3266 laststart = buf_end;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3267 BUF_PUSH (notwordchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3268 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3269
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3270
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3271 case '<':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3272 BUF_PUSH (wordbeg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3273 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3275 case '>':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3276 BUF_PUSH (wordend);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3277 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3279 case 'b':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3280 BUF_PUSH (wordbound);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3281 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3282
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3283 case 'B':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3284 BUF_PUSH (notwordbound);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3285 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3286
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3287 case '`':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3288 BUF_PUSH (begbuf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3289 break;
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 case '\'':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3292 BUF_PUSH (endbuf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3293 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3294
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3295 case '1': case '2': case '3': case '4': case '5':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3296 case '6': case '7': case '8': case '9':
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3297 {
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3298 regnum_t reg, regint;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3299 int may_need_to_unfetch = 0;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3300 if (syntax & RE_NO_BK_REFS)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3301 goto normal_char;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3302
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3303 /* This only goes up to 99. It could be extended to work
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3304 up to 255 (the maximum number of registers that can be
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3305 handled by the current regexp engine, because it stores
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3306 its register numbers in the compiled pattern as one byte,
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3307 ugh). Doing that's a bit trickier, because you might
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3308 have the case where \25 a back-ref but \255 is not, ... */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3309 reg = c - '0';
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3310 if (p < pend)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3311 {
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3312 PATFETCH (c);
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3313 if (c >= '0' && c <= '9')
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3314 {
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3315 regnum_t new_reg = reg * 10 + c - '0';
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3316 if (new_reg <= bufp->re_nsub)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3317 {
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3318 reg = new_reg;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3319 may_need_to_unfetch = 1;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3320 }
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3321 else
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3322 PATUNFETCH;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3323 }
523
cd662ad69f40 [xemacs-hg @ 2001-05-09 13:43:49 by ben]
ben
parents: 502
diff changeset
3324 else
cd662ad69f40 [xemacs-hg @ 2001-05-09 13:43:49 by ben]
ben
parents: 502
diff changeset
3325 PATUNFETCH;
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3326 }
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3327
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3328 if (reg > bufp->re_nsub)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3329 FREE_STACK_RETURN (REG_ESUBREG);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3330
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3331 regint = bufp->external_to_internal_register[reg];
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3332 /* Can't back reference to a subexpression if inside of it. */
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3333 if (group_in_compile_stack (compile_stack, regint))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3334 {
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3335 if (may_need_to_unfetch)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3336 PATUNFETCH;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3337 goto normal_char;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3338 }
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3339
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3340 #ifdef emacs
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3341 if (reg > 9 &&
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3342 bufp->warned_about_incompatible_back_references == 0)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3343 {
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3344 bufp->warned_about_incompatible_back_references = 1;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3345 warn_when_safe (intern ("regex"), Qinfo,
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3346 "Back reference \\%d now has new "
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3347 "semantics in %s", reg, pattern);
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3348 }
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3349 #endif
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3350
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3351 laststart = buf_end;
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3352 BUF_PUSH_2 (duplicate, regint);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3353 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3354 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3355
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3357 case '+':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3358 case '?':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3359 if (syntax & RE_BK_PLUS_QM)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3360 goto handle_plus;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3361 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3362 goto normal_backslash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3364 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3365 normal_backslash:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3366 /* You might think it would be useful for \ to mean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3367 not to translate; but if we don't translate it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3368 it will never match anything. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3369 c = RE_TRANSLATE (c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3370 goto normal_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3371 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3372 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3374
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3375 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3376 /* Expects the character in `c'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3377 /* `p' points to the location after where `c' came from. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3378 normal_char:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3379 {
4750
b5f21bb36684 Fix crash in regex.c (closes issue630).
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4527
diff changeset
3380 /* The following conditional synced to GNU Emacs 22.1. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3381 /* If no exactn currently being built. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3382 if (!pending_exact
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3383
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3384 /* If last exactn not at current position. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3385 || pending_exact + *pending_exact + 1 != buf_end
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3387 /* We have only one byte following the exactn for the count. */
4750
b5f21bb36684 Fix crash in regex.c (closes issue630).
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4527
diff changeset
3388 || *pending_exact >= (1 << BYTEWIDTH) - MAX_ICHAR_LEN
b5f21bb36684 Fix crash in regex.c (closes issue630).
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4527
diff changeset
3389
b5f21bb36684 Fix crash in regex.c (closes issue630).
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4527
diff changeset
3390 /* If followed by a repetition operator.
b5f21bb36684 Fix crash in regex.c (closes issue630).
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4527
diff changeset
3391 If the lookahead fails because of end of pattern, any
b5f21bb36684 Fix crash in regex.c (closes issue630).
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4527
diff changeset
3392 trailing backslash will get caught later. */
b5f21bb36684 Fix crash in regex.c (closes issue630).
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4527
diff changeset
3393 || (p != pend && (*p == '*' || *p == '^'))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3394 || ((syntax & RE_BK_PLUS_QM)
4750
b5f21bb36684 Fix crash in regex.c (closes issue630).
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4527
diff changeset
3395 ? p + 1 < pend && *p == '\\' && (p[1] == '+' || p[1] == '?')
b5f21bb36684 Fix crash in regex.c (closes issue630).
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4527
diff changeset
3396 : p != pend && (*p == '+' || *p == '?'))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3397 || ((syntax & RE_INTERVALS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3398 && ((syntax & RE_NO_BK_BRACES)
4750
b5f21bb36684 Fix crash in regex.c (closes issue630).
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4527
diff changeset
3399 ? p != pend && *p == '{'
b5f21bb36684 Fix crash in regex.c (closes issue630).
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4527
diff changeset
3400 : p + 1 < pend && (p[0] == '\\' && p[1] == '{'))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3401 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3402 /* Start building a new exactn. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3403
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3404 laststart = buf_end;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3406 BUF_PUSH_2 (exactn, 0);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3407 pending_exact = buf_end - 1;
428
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
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3410 #ifndef MULE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3411 BUF_PUSH (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3412 (*pending_exact)++;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3413 #else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3414 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3415 Bytecount bt_count;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
3416 Ibyte tmp_buf[MAX_ICHAR_LEN];
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3417 int i;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3418
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
3419 bt_count = set_itext_ichar (tmp_buf, c);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3420
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3421 for (i = 0; i < bt_count; i++)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3422 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3423 BUF_PUSH (tmp_buf[i]);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3424 (*pending_exact)++;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3425 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3426 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3427 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3428 break;
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 } /* switch (c) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3431 } /* while p != pend */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3432
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3434 /* Through the pattern now. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3435
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3436 if (fixup_alt_jump)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3437 STORE_JUMP (jump_past_alt, fixup_alt_jump, buf_end);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3438
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3439 if (!COMPILE_STACK_EMPTY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3440 FREE_STACK_RETURN (REG_EPAREN);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3441
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3442 /* If we don't want backtracking, force success
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3443 the first time we reach the end of the compiled pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3444 if (syntax & RE_NO_POSIX_BACKTRACKING)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3445 BUF_PUSH (succeed);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3446
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4832
diff changeset
3447 xfree (compile_stack.stack);
428
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 /* We have succeeded; set the length of the buffer. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3450 bufp->used = buf_end - bufp->buffer;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3452 #ifdef DEBUG
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
3453 if (debug_regexps & RE_DEBUG_COMPILATION)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3454 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3455 DEBUG_PRINT1 ("\nCompiled pattern: \n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3456 print_compiled_pattern (bufp);
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 #endif /* DEBUG */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3459
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3460 #ifndef MATCH_MAY_ALLOCATE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3461 /* Initialize the failure stack to the largest possible stack. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3462 isn't necessary unless we're trying to avoid calling alloca in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3463 the search and match routines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3464 {
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
3465 int num_regs = bufp->re_ngroups + 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3466
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3467 /* Since DOUBLE_FAIL_STACK refuses to double only if the current size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3468 is strictly greater than re_max_failures, the largest possible stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3469 is 2 * re_max_failures failure points. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3470 if (fail_stack.size < (2 * re_max_failures * MAX_FAILURE_ITEMS))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3471 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3472 fail_stack.size = (2 * re_max_failures * MAX_FAILURE_ITEMS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3473
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3474 if (! fail_stack.stack)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3475 fail_stack.stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3476 = (fail_stack_elt_t *) xmalloc (fail_stack.size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3477 * sizeof (fail_stack_elt_t));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3478 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3479 fail_stack.stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3480 = (fail_stack_elt_t *) xrealloc (fail_stack.stack,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3481 (fail_stack.size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3482 * sizeof (fail_stack_elt_t)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3483 }
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 regex_grow_registers (num_regs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3486 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3487 #endif /* not MATCH_MAY_ALLOCATE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3489 return REG_NOERROR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3490 } /* regex_compile */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3492 /* Subroutines for `regex_compile'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3494 /* Store OP at LOC followed by two-byte integer parameter ARG. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3495
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3496 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3497 store_op1 (re_opcode_t op, unsigned char *loc, int arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3498 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3499 *loc = (unsigned char) op;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3500 STORE_NUMBER (loc + 1, arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3501 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3502
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 /* Like `store_op1', but for two two-byte parameters ARG1 and ARG2. */
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 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3507 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
3508 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3509 *loc = (unsigned char) op;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3510 STORE_NUMBER (loc + 1, arg1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3511 STORE_NUMBER (loc + 3, arg2);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3514
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3515 /* 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
3516 for OP followed by two-byte integer parameter ARG. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3517
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3518 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3519 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
3520 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3521 REGISTER unsigned char *pfrom = end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3522 REGISTER unsigned char *pto = end + 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3523
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3524 while (pfrom != loc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3525 *--pto = *--pfrom;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3527 store_op1 (op, loc, arg);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3530
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3531 /* Like `insert_op1', but for two two-byte parameters ARG1 and ARG2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3532
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3533 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3534 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
3535 unsigned char *end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3536 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3537 REGISTER unsigned char *pfrom = end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3538 REGISTER unsigned char *pto = end + 5;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3539
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3540 while (pfrom != loc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3541 *--pto = *--pfrom;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3542
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3543 store_op2 (op, loc, arg1, arg2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3544 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3547 /* 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
3548 after an alternative or a begin-subexpression. We assume there is at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3549 least one character before the ^. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3550
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
3551 static re_bool
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3552 at_begline_loc_p (re_char *pattern, re_char *p, reg_syntax_t syntax)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3553 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3554 re_char *prev = p - 2;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
3555 re_bool prev_prev_backslash = prev > pattern && prev[-1] == '\\';
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3557 return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3558 /* After a subexpression? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3559 (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3560 /* After an alternative? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3561 || (*prev == '|' && (syntax & RE_NO_BK_VBAR || prev_prev_backslash));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3562 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3563
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3565 /* 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
3566 at least one character after the $, i.e., `P < PEND'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3567
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
3568 static re_bool
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3569 at_endline_loc_p (re_char *p, re_char *pend, int syntax)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3570 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3571 re_char *next = p;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
3572 re_bool next_backslash = *next == '\\';
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3573 re_char *next_next = p + 1 < pend ? p + 1 : 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3574
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3575 return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3576 /* Before a subexpression? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3577 (syntax & RE_NO_BK_PARENS ? *next == ')'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3578 : next_backslash && next_next && *next_next == ')')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3579 /* Before an alternative? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3580 || (syntax & RE_NO_BK_VBAR ? *next == '|'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3581 : next_backslash && next_next && *next_next == '|');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3582 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3583
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3585 /* 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
3586 false if it's not. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3587
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
3588 static re_bool
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3589 group_in_compile_stack (compile_stack_type compile_stack, regnum_t regnum)
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 int this_element;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3592
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3593 for (this_element = compile_stack.avail - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3594 this_element >= 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3595 this_element--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3596 if (compile_stack.stack[this_element].regnum == regnum)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3597 return true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3598
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3599 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3600 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3601
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3602
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3603 /* 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
3604 uncompiled pattern *P_PTR (which ends at PEND). We assume the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3605 starting character is in `P[-2]'. (`P[-1]' is the character `-'.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3606 Then we set the translation of all bits between the starting and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3607 ending characters (inclusive) in the compiled pattern B.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3608
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3609 Return an error code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3610
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3611 We use these short variable names so we can use the same macros as
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3612 `regex_compile' itself.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3613
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3614 Under Mule, this is only called when both chars of the range are
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3615 ASCII. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3616
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3617 static reg_errcode_t
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3618 compile_range (re_char **p_ptr, re_char *pend, RE_TRANSLATE_TYPE translate,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3619 reg_syntax_t syntax, unsigned char *buf_end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3620 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
3621 Ichar this_char;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3622
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3623 re_char *p = *p_ptr;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3624 int range_start, range_end;
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 if (p == pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3627 return REG_ERANGE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3628
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3629 /* Even though the pattern is a signed `char *', we need to fetch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3630 with unsigned char *'s; if the high bit of the pattern character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3631 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
3632 signed char *.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3633
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3634 We also want to fetch the endpoints without translating them; the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3635 appropriate translation is done in the bit-setting loop below. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3636 /* 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
3637 range_start = ((const unsigned char *) p)[-2];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3638 range_end = ((const unsigned char *) p)[0];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3639
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3640 /* Have to increment the pointer into the pattern string, so the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3641 caller isn't still at the ending character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3642 (*p_ptr)++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3643
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3644 /* If the start is after the end, the range is empty. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3645 if (range_start > range_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3646 return syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3648 /* 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
3649 char' -- the range is inclusive, so if `range_end' == 0xff
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3650 (assuming 8-bit characters), we would otherwise go into an infinite
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3651 loop, since all characters <= 0xff. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3652 for (this_char = range_start; this_char <= range_end; this_char++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3653 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3654 SET_LIST_BIT (RE_TRANSLATE (this_char));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3655 }
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 return REG_NOERROR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3658 }
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 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3661
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3662 static reg_errcode_t
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3663 compile_extended_range (re_char **p_ptr, re_char *pend,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3664 RE_TRANSLATE_TYPE translate,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3665 reg_syntax_t syntax, Lisp_Object rtab)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3666 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
3667 Ichar this_char, range_start, range_end;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
3668 const Ibyte *p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3669
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3670 if (*p_ptr == pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3671 return REG_ERANGE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3672
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
3673 p = (const Ibyte *) *p_ptr;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
3674 range_end = itext_ichar (p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3675 p--; /* back to '-' */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
3676 DEC_IBYTEPTR (p); /* back to start of range */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3677 /* We also want to fetch the endpoints without translating them; the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3678 appropriate translation is done in the bit-setting loop below. */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
3679 range_start = itext_ichar (p);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
3680 INC_IBYTEPTR (*p_ptr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3681
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3682 /* If the start is after the end, the range is empty. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3683 if (range_start > range_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3684 return syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR;
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 /* Can't have ranges spanning different charsets, except maybe for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3687 ranges entirely within the first 256 chars. */
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 if ((range_start >= 0x100 || range_end >= 0x100)
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
3690 && ichar_leading_byte (range_start) !=
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
3691 ichar_leading_byte (range_end))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3692 return REG_ERANGESPAN;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3693
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3694 /* #### This might be way inefficient if the range encompasses 10,000
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3695 chars or something. To be efficient, you'd have to do something like
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3696 this:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3697
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3698 range_table a;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3699 range_table b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3700 map over translation table in [range_start, range_end] of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3701 (put the mapped range in a;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3702 put the translation in b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3703 invert the range in a and truncate to [range_start, range_end]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3704 compute the union of a, b
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3705 union the result into rtab
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3706 */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3707 for (this_char = range_start; this_char <= range_end; this_char++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3708 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3709 SET_RANGETAB_BIT (RE_TRANSLATE (this_char));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3710 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3711
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3712 if (this_char <= range_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3713 put_range_table (rtab, this_char, range_end, Qt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3714
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3715 return REG_NOERROR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3716 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3717
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3718 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3719
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3720 /* re_compile_fastmap computes a ``fastmap'' for the compiled pattern in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3721 BUFP. A fastmap records which of the (1 << BYTEWIDTH) possible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3722 characters can start a string that matches the pattern. This fastmap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3723 is used by re_search to skip quickly over impossible starting points.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3725 The caller must supply the address of a (1 << BYTEWIDTH)-byte data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3726 area as BUFP->fastmap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3727
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3728 We set the `fastmap', `fastmap_accurate', and `can_be_null' fields in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3729 the pattern buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3731 Returns 0 if we succeed, -2 if an internal error. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3732
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3733 int
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3734 re_compile_fastmap (struct re_pattern_buffer *bufp
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3735 RE_LISP_SHORT_CONTEXT_ARGS_DECL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3736 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3737 int j, k;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3738 #ifdef MATCH_MAY_ALLOCATE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3739 fail_stack_type fail_stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3740 #endif
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 450
diff changeset
3741 DECLARE_DESTINATION;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3742 /* We don't push any register information onto the failure stack. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3743
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3744 /* &&#### this should be changed for 8-bit-fixed, for efficiency. see
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3745 comment marked with &&#### in re_search_2. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3746
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3747 REGISTER char *fastmap = bufp->fastmap;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3748 unsigned char *pattern = bufp->buffer;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
3749 long size = bufp->used;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3750 unsigned char *p = pattern;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3751 REGISTER unsigned char *pend = pattern + size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3752
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3753 #ifdef REGEX_REL_ALLOC
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3754 /* This holds the pointer to the failure stack, when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3755 it is allocated relocatably. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3756 fail_stack_elt_t *failure_stack_ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3757 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3758
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3759 /* Assume that each path through the pattern can be null until
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3760 proven otherwise. We set this false at the bottom of switch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3761 statement, to which we get only if a particular path doesn't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3762 match the empty string. */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
3763 re_bool path_can_be_null = true;
428
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 /* We aren't doing a `succeed_n' to begin with. */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
3766 re_bool succeed_n_p = false;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3767
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
3768 #ifdef ERROR_CHECK_MALLOC
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
3769 /* The pattern comes from string data, not buffer data. We don't access
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
3770 any buffer data, so we don't have to worry about malloc() (but the
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
3771 disallowed flag may have been set by a caller). */
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
3772 int depth = bind_regex_malloc_disallowed (0);
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
3773 #endif
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
3774
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3775 assert (fastmap != NULL && p != NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3776
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3777 INIT_FAIL_STACK ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3778 memset (fastmap, 0, 1 << BYTEWIDTH); /* Assume nothing's valid. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3779 bufp->fastmap_accurate = 1; /* It will be when we're done. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3780 bufp->can_be_null = 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 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3783 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3784 if (p == pend || *p == succeed)
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 /* We have reached the (effective) end of pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3787 if (!FAIL_STACK_EMPTY ())
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 bufp->can_be_null |= path_can_be_null;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3790
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3791 /* Reset for next path. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3792 path_can_be_null = true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3793
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3794 p = (unsigned char *) fail_stack.stack[--fail_stack.avail].pointer;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3795
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3796 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3797 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3798 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3799 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3800 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3801
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3802 /* 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
3803 assert (p < pend);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3804
4759
aa5ed11f473b Remove support for obsolete systems. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 4750
diff changeset
3805 switch ((re_opcode_t) *p++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3806 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3807
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3808 /* 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
3809 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
3810 the fastmap for the corresponding group. Setting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3811 `can_be_null' stops `re_search_2' from using the fastmap, so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3812 that is all we do. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3813 case duplicate:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3814 bufp->can_be_null = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3815 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3816
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 /* Following are the cases which match a character. These end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3819 with `break'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3820
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3821 case exactn:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3822 fastmap[p[1]] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3823 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3824
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3825
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3826 case charset:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3827 /* XEmacs: Under Mule, these bit vectors will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3828 only contain values for characters below 0x80. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3829 for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3830 if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3831 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3832 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3833
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3834
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3835 case charset_not:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3836 /* Chars beyond end of map must be allowed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3837 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3838 for (j = *p * BYTEWIDTH; j < 0x80; j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3839 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3840 /* And all extended characters must be allowed, too. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3841 for (j = 0x80; j < 0xA0; j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3842 fastmap[j] = 1;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3843 #else /* not MULE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3844 for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3845 fastmap[j] = 1;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3846 #endif /* MULE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3847
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3848 for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3849 if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3850 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3851 break;
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 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3854 case charset_mule:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3855 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3856 int nentries;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3857 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3858
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3859 nentries = unified_range_table_nentries (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3860 for (i = 0; i < nentries; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3861 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3862 EMACS_INT first, last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3863 Lisp_Object dummy_val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3864 int jj;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
3865 Ibyte strr[MAX_ICHAR_LEN];
428
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 unified_range_table_get_range (p, i, &first, &last,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3868 &dummy_val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3869 for (jj = first; jj <= last && jj < 0x80; jj++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3870 fastmap[jj] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3871 /* Ranges below 0x100 can span charsets, but there
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3872 are only two (Control-1 and Latin-1), and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3873 either first or last has to be in them. */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
3874 set_itext_ichar (strr, first);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3875 fastmap[*strr] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3876 if (last < 0x100)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3877 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
3878 set_itext_ichar (strr, last);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3879 fastmap[*strr] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3880 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3881 }
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 break;
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 case charset_mule_not:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3886 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3887 int nentries;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3888 int i;
4832
07fa38c30fdf fix messed-up fastmap calculation in charset_mule_not
Ben Wing <ben@xemacs.org>
parents: 4759
diff changeset
3889 int smallest_prev = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3890
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3891 nentries = unified_range_table_nentries (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3892 for (i = 0; i < nentries; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3893 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3894 EMACS_INT first, last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3895 Lisp_Object dummy_val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3896 int jj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3897
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3898 unified_range_table_get_range (p, i, &first, &last,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3899 &dummy_val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3900 for (jj = smallest_prev; jj < first && jj < 0x80; jj++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3901 fastmap[jj] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3902 smallest_prev = last + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3903 if (smallest_prev >= 0x80)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3904 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3905 }
4832
07fa38c30fdf fix messed-up fastmap calculation in charset_mule_not
Ben Wing <ben@xemacs.org>
parents: 4759
diff changeset
3906
07fa38c30fdf fix messed-up fastmap calculation in charset_mule_not
Ben Wing <ben@xemacs.org>
parents: 4759
diff changeset
3907 /* Also set lead bytes after the end */
07fa38c30fdf fix messed-up fastmap calculation in charset_mule_not
Ben Wing <ben@xemacs.org>
parents: 4759
diff changeset
3908 for (i = smallest_prev; i < 0x80; i++)
07fa38c30fdf fix messed-up fastmap calculation in charset_mule_not
Ben Wing <ben@xemacs.org>
parents: 4759
diff changeset
3909 fastmap[i] = 1;
07fa38c30fdf fix messed-up fastmap calculation in charset_mule_not
Ben Wing <ben@xemacs.org>
parents: 4759
diff changeset
3910
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3911 /* Calculating which leading bytes are actually allowed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3912 here is rather difficult, so we just punt and allow
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3913 all of them. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3914 for (i = 0x80; i < 0xA0; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3915 fastmap[i] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3916 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3917 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3918 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3919
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3920
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3921 case anychar:
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 int fastmap_newline = fastmap['\n'];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3924
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3925 /* `.' matches anything ... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3926 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3927 /* "anything" only includes bytes that can be the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3928 first byte of a character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3929 for (j = 0; j < 0xA0; j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3930 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3931 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3932 for (j = 0; j < (1 << BYTEWIDTH); j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3933 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3934 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3935
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3936 /* ... except perhaps newline. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3937 if (!(bufp->syntax & RE_DOT_NEWLINE))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3938 fastmap['\n'] = fastmap_newline;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3939
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3940 /* Return if we have already set `can_be_null'; if we have,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3941 then the fastmap is irrelevant. Something's wrong here. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3942 else if (bufp->can_be_null)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3943 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3944
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3945 /* Otherwise, have to check alternative paths. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3946 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3947 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3948
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3949 #ifndef emacs
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3950 case wordchar:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3951 for (j = 0; j < (1 << BYTEWIDTH); j++)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3952 if (SYNTAX (ignored, j) == Sword)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3953 fastmap[j] = 1;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3954 break;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3955
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3956 case notwordchar:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3957 for (j = 0; j < (1 << BYTEWIDTH); j++)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3958 if (SYNTAX (ignored, j) != Sword)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3959 fastmap[j] = 1;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3960 break;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3961 #else /* emacs */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3962 case wordchar:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3963 case notwordchar:
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
3964 case wordbound:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
3965 case notwordbound:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
3966 case wordbeg:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
3967 case wordend:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
3968 case notsyntaxspec:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
3969 case syntaxspec:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
3970 /* This match depends on text properties. These end with
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
3971 aborting optimizations. */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
3972 bufp->can_be_null = 1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
3973 goto done;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3974 #if 0 /* all of the following code is unused now that the `syntax-table'
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3975 property exists -- it's trickier to do this than just look in
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3976 the buffer. &&#### but we could just use the syntax-cache stuff
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3977 instead; why don't we? --ben */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3978 case wordchar:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3979 k = (int) Sword;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3980 goto matchsyntax;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3981
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3982 case notwordchar:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3983 k = (int) Sword;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3984 goto matchnotsyntax;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3985
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3986 case syntaxspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3987 k = *p++;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3988 matchsyntax:
428
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 for (j = 0; j < 0x80; j++)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3991 if (SYNTAX
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3992 (XCHAR_TABLE (BUFFER_MIRROR_SYNTAX_TABLE (lispbuf)), j) ==
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3993 (enum syntaxcode) k)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3994 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3995 for (j = 0x80; j < 0xA0; j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3996 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
3997 if (leading_byte_prefix_p ((unsigned char) j))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3998 /* too complicated to calculate this right */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3999 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4000 else
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 int multi_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4003 Lisp_Object cset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4004
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4005 cset = charset_by_leading_byte (j);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4006 if (CHARSETP (cset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4007 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4008 if (charset_syntax (lispbuf, cset, &multi_p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4009 == Sword || multi_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4010 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4011 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4012 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4013 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4014 #else /* not MULE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4015 for (j = 0; j < (1 << BYTEWIDTH); j++)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4016 if (SYNTAX
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4017 (XCHAR_TABLE (BUFFER_MIRROR_SYNTAX_TABLE (lispbuf)), j) ==
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4018 (enum syntaxcode) k)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4019 fastmap[j] = 1;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4020 #endif /* MULE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4021 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4022
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4023
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4024 case notsyntaxspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4025 k = *p++;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4026 matchnotsyntax:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4027 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4028 for (j = 0; j < 0x80; j++)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4029 if (SYNTAX
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4030 (XCHAR_TABLE
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4031 (BUFFER_MIRROR_SYNTAX_TABLE (lispbuf)), j) !=
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4032 (enum syntaxcode) k)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4033 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4034 for (j = 0x80; j < 0xA0; j++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4035 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4036 if (leading_byte_prefix_p ((unsigned char) j))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4037 /* too complicated to calculate this right */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4038 fastmap[j] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4039 else
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 int multi_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4042 Lisp_Object cset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4043
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4044 cset = charset_by_leading_byte (j);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4045 if (CHARSETP (cset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4046 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4047 if (charset_syntax (lispbuf, cset, &multi_p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4048 != Sword || multi_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4049 fastmap[j] = 1;
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4052 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4053 #else /* not MULE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4054 for (j = 0; j < (1 << BYTEWIDTH); j++)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4055 if (SYNTAX
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4056 (XCHAR_TABLE
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4057 (BUFFER_MIRROR_SYNTAX_TABLE (lispbuf)), j) !=
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4058 (enum syntaxcode) k)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4059 fastmap[j] = 1;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4060 #endif /* MULE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4061 break;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4062 #endif /* 0 */
428
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 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4065 /* 97/2/17 jhod category patch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4066 case categoryspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4067 case notcategoryspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4068 bufp->can_be_null = 1;
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4069 UNBIND_REGEX_MALLOC_CHECK ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4070 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4071 /* end if category patch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4072 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4073
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4074 /* All cases after this match the empty string. These end with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4075 `continue'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4076 case before_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4077 case at_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4078 case after_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4079 continue;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4080 #endif /* emacs */
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4083 case no_op:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4084 case begline:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4085 case endline:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4086 case begbuf:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4087 case endbuf:
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4088 #ifndef emacs
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4089 case wordbound:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4090 case notwordbound:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4091 case wordbeg:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4092 case wordend:
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4093 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4094 case push_dummy_failure:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4095 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4096
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4097
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4098 case jump_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4099 case pop_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4100 case maybe_pop_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4101 case jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4102 case jump_past_alt:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4103 case dummy_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4104 EXTRACT_NUMBER_AND_INCR (j, p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4105 p += j;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4106 if (j > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4107 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4109 /* Jump backward implies we just went through the body of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4110 loop and matched nothing. Opcode jumped to should be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4111 `on_failure_jump' or `succeed_n'. Just treat it like an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4112 ordinary jump. For a * loop, it has pushed its failure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4113 point already; if so, discard that as redundant. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4114 if ((re_opcode_t) *p != on_failure_jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4115 && (re_opcode_t) *p != succeed_n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4116 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4118 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4119 EXTRACT_NUMBER_AND_INCR (j, p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4120 p += j;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4122 /* 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
4123 if (!FAIL_STACK_EMPTY ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4124 && fail_stack.stack[fail_stack.avail - 1].pointer == p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4125 fail_stack.avail--;
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 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4130 case on_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4131 case on_failure_keep_string_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4132 handle_on_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4133 EXTRACT_NUMBER_AND_INCR (j, p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4134
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4135 /* For some patterns, e.g., `(a?)?', `p+j' here points to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4136 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
4137 since when we restore it above, entering the switch will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4138 increment `p' past the end of the pattern. We don't need
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4139 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
4140 fastmap entries beyond `pend'. Such a pattern can match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4141 the null string, though. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4142 if (p + j < pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4143 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4144 if (!PUSH_PATTERN_OP (p + j, fail_stack))
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 RESET_FAIL_STACK ();
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4147 UNBIND_REGEX_MALLOC_CHECK ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4148 return -2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4149 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4150 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4151 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4152 bufp->can_be_null = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4154 if (succeed_n_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4155 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4156 EXTRACT_NUMBER_AND_INCR (k, p); /* Skip the n. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4157 succeed_n_p = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4158 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4160 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4161
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4163 case succeed_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4164 /* Get to the number of times to succeed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4165 p += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4167 /* Increment p past the n for when k != 0. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4168 EXTRACT_NUMBER_AND_INCR (k, p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4169 if (k == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4170 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4171 p -= 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4172 succeed_n_p = true; /* Spaghetti code alert. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4173 goto handle_on_failure_jump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4174 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4175 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4176
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 case set_number_at:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4179 p += 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4180 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4183 case start_memory:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4184 case stop_memory:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4185 p += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4186 continue;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4189 default:
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2421
diff changeset
4190 ABORT (); /* We have listed all the cases. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4191 } /* switch *p++ */
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 /* Getting here means we have found the possible starting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4194 characters for one path of the pattern -- and that the empty
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4195 string does not match. We need not follow this path further.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4196 Instead, look at the next alternative (remembered on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4197 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
4198 does these things. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4199 path_can_be_null = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4200 p = pend;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4201 } /* while p */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4202
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4203 /* 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
4204 pattern is empty). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4205 bufp->can_be_null |= path_can_be_null;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4206
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4207 done:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4208 RESET_FAIL_STACK ();
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4209 UNBIND_REGEX_MALLOC_CHECK ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4210 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4211 } /* re_compile_fastmap */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4212
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4213 /* Set REGS to hold NUM_REGS registers, storing them in STARTS and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4214 ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4215 this memory for recording register information. STARTS and ENDS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4216 must be allocated using the malloc library routine, and must each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4217 be at least NUM_REGS * sizeof (regoff_t) bytes long.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4219 If NUM_REGS == 0, then subsequent matches should allocate their own
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4220 register data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4222 Unless this function is called, the first search or match using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4223 PATTERN_BUFFER will allocate its own register data, without
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4224 freeing the old data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4226 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4227 re_set_registers (struct re_pattern_buffer *bufp, struct re_registers *regs,
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
4228 int num_regs, regoff_t *starts, regoff_t *ends)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4229 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4230 if (num_regs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4231 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4232 bufp->regs_allocated = REGS_REALLOCATE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4233 regs->num_regs = num_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4234 regs->start = starts;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4235 regs->end = ends;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4236 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4237 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4238 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4239 bufp->regs_allocated = REGS_UNALLOCATED;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4240 regs->num_regs = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4241 regs->start = regs->end = (regoff_t *) 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4242 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4245 /* Searching routines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4247 /* Like re_search_2, below, but only one string is specified, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4248 doesn't let you say where to stop matching. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4249
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4250 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4251 re_search (struct re_pattern_buffer *bufp, const char *string, int size,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4252 int startpos, int range, struct re_registers *regs
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4253 RE_LISP_CONTEXT_ARGS_DECL)
428
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 return re_search_2 (bufp, NULL, 0, string, size, startpos, range,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4256 regs, size RE_LISP_CONTEXT_ARGS);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4257 }
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 /* Using the compiled pattern in BUFP->buffer, first tries to match the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4260 virtual concatenation of STRING1 and STRING2, starting first at index
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4261 STARTPOS, then at STARTPOS + 1, and so on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4262
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4263 STRING1 and STRING2 have length SIZE1 and SIZE2, respectively.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4264
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4265 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
4266 only at STARTPOS; in general, the last start tried is STARTPOS +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4267 RANGE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4268
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4269 All sizes and positions refer to bytes (not chars); under Mule, the code
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4270 knows about the format of the text and will only check at positions
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4271 where a character starts.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4272
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4273 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
4274 start tried is the character starting <= STARTPOS + RANGE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4276 In REGS, return the indices of the virtual concatenation of STRING1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4277 and STRING2 that matched the entire BUFP->buffer and its contained
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4278 subexpressions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4280 Do not consider matching one past the index STOP in the virtual
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4281 concatenation of STRING1 and STRING2.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4282
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4283 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
4284 found, -1 if no match, or -2 if error (such as failure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4285 stack overflow). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4286
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4287 int
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4288 re_search_2 (struct re_pattern_buffer *bufp, const char *str1,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4289 int size1, const char *str2, int size2, int startpos,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4290 int range, struct re_registers *regs, int stop
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4291 RE_LISP_CONTEXT_ARGS_DECL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4292 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4293 int val;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4294 re_char *string1 = (re_char *) str1;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4295 re_char *string2 = (re_char *) str2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4296 REGISTER char *fastmap = bufp->fastmap;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4297 REGISTER RE_TRANSLATE_TYPE translate = bufp->translate;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4298 int total_size = size1 + size2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4299 int endpos = startpos + range;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4300 #ifdef REGEX_BEGLINE_CHECK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4301 int anchored_at_begline = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4302 #endif
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4303 re_char *d;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4304 #ifdef emacs
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4305 Internal_Format fmt = buffer_or_other_internal_format (lispobj);
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4306 #ifdef REL_ALLOC
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4307 Ibyte *orig_buftext =
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4308 BUFFERP (lispobj) ?
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4309 BYTE_BUF_BYTE_ADDRESS (XBUFFER (lispobj),
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4310 BYTE_BUF_BEGV (XBUFFER (lispobj))) :
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4311 0;
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4312 #endif
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4313 #ifdef ERROR_CHECK_MALLOC
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4314 int depth;
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4315 #endif
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4316 #endif /* emacs */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4317 #if 1
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4318 int forward_search_p;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4319 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4320
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4321 /* Check for out-of-range STARTPOS. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4322 if (startpos < 0 || startpos > total_size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4323 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4324
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4325 /* Fix up RANGE if it might eventually take us outside
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4326 the virtual concatenation of STRING1 and STRING2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4327 if (endpos < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4328 range = 0 - startpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4329 else if (endpos > total_size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4330 range = total_size - startpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4331
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4332 #if 1
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4333 forward_search_p = range > 0;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4334 #endif
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4335
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4336 /* 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
4337 search for a pattern that must be anchored. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4338 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
4339 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4340 if (startpos > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4341 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4342 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4343 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4344 d = ((const unsigned char *)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4345 (startpos >= size1 ? string2 - size1 : string1) + startpos);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4346 range = itext_ichar_len_fmt (d, fmt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4347 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4348 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4349
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4350 #ifdef emacs
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4351 /* In a forward search for something that starts with \=.
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4352 don't keep searching past point. */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4353 if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == at_dot && range > 0)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4354 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4355 if (!BUFFERP (lispobj))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4356 return -1;
4527
8418d1ad4944 Fix at_dot regex under Mule. <87hc6rv53v.fsf@uwakimon.sk.tsukuba.ac.jp>
Stephen J. Turnbull <stephen@xemacs.org>
parents: 3300
diff changeset
4357 range = (BYTE_BUF_PT (XBUFFER (lispobj))
8418d1ad4944 Fix at_dot regex under Mule. <87hc6rv53v.fsf@uwakimon.sk.tsukuba.ac.jp>
Stephen J. Turnbull <stephen@xemacs.org>
parents: 3300
diff changeset
4358 - BYTE_BUF_BEGV (XBUFFER (lispobj)) - startpos);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4359 if (range < 0)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4360 return -1;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4361 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4362 #endif /* emacs */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4363
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4364 #ifdef ERROR_CHECK_MALLOC
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4365 /* Do this after the above return()s. */
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4366 depth = bind_regex_malloc_disallowed (1);
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4367 #endif
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4368
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4369 /* Update the fastmap now if not correct already. */
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4370 BEGIN_REGEX_MALLOC_OK ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4371 if (fastmap && !bufp->fastmap_accurate)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4372 if (re_compile_fastmap (bufp RE_LISP_SHORT_CONTEXT_ARGS) == -2)
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4373 {
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4374 END_REGEX_MALLOC_OK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4375 UNBIND_REGEX_MALLOC_CHECK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4376 return -2;
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4377 }
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4378
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4379 END_REGEX_MALLOC_OK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4380 RE_SEARCH_RELOCATE_MOVEABLE_DATA_POINTERS ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4382 #ifdef REGEX_BEGLINE_CHECK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4383 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
4384 long i = 0;
428
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 while (i < bufp->used)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4387 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4388 if (bufp->buffer[i] == start_memory ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4389 bufp->buffer[i] == stop_memory)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4390 i += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4391 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4392 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4393 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4394 anchored_at_begline = i < bufp->used && bufp->buffer[i] == begline;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4395 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4396 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4397
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4398 #ifdef emacs
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4399 BEGIN_REGEX_MALLOC_OK ();
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4400 scache = setup_syntax_cache (scache, lispobj, lispbuf,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4401 offset_to_charxpos (lispobj, startpos),
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4402 1);
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4403 END_REGEX_MALLOC_OK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4404 RE_SEARCH_RELOCATE_MOVEABLE_DATA_POINTERS ();
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4405 #endif
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4406
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4407 /* Loop through the string, looking for a place to start matching. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4408 for (;;)
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 #ifdef REGEX_BEGLINE_CHECK
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4411 /* If the regex is anchored at the beginning of a line (i.e. with a
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4412 ^), then we can speed things up by skipping to the next
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4413 beginning-of-line. However, to determine "beginning of line" we
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4414 need to look at the previous char, so can't do this check if at
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4415 beginning of either string. (Well, we could if at the beginning of
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4416 the second string, but it would require additional code, and this
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4417 is just an optimization.) */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4418 if (anchored_at_begline && startpos > 0 && startpos != size1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4419 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4420 if (range > 0)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4421 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4422 /* whose stupid idea was it anyway to make this
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4423 function take two strings to match?? */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4424 int lim = 0;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4425 re_char *orig_d;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4426 re_char *stop_d;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4427
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4428 /* Compute limit as below in fastmap code, so we are guaranteed
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4429 to remain within a single string. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4430 if (startpos < size1 && startpos + range >= size1)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4431 lim = range - (size1 - startpos);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4432
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4433 d = ((const unsigned char *)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4434 (startpos >= size1 ? string2 - size1 : string1) + startpos);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4435 orig_d = d;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4436 stop_d = d + range - lim;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4437
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4438 /* We want to find the next location (including the current
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4439 one) where the previous char is a newline, so back up one
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4440 and search forward for a newline. */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4441 DEC_IBYTEPTR_FMT (d, fmt); /* Ok, since startpos != size1. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4442
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4443 /* Written out as an if-else to avoid testing `translate'
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4444 inside the loop. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4445 if (TRANSLATE_P (translate))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4446 while (d < stop_d &&
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4447 RE_TRANSLATE_1 (itext_ichar_fmt (d, fmt, lispobj))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4448 != '\n')
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4449 INC_IBYTEPTR_FMT (d, fmt);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4450 else
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4451 while (d < stop_d &&
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4452 itext_ichar_ascii_fmt (d, fmt, lispobj) != '\n')
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4453 INC_IBYTEPTR_FMT (d, fmt);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4454
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4455 /* If we were stopped by a newline, skip forward over it.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4456 Otherwise we will get in an infloop when our start position
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4457 was at begline. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4458 if (d < stop_d)
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4459 INC_IBYTEPTR_FMT (d, fmt);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4460 range -= d - orig_d;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4461 startpos += d - orig_d;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4462 #if 1
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4463 assert (!forward_search_p || range >= 0);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4464 #endif
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4465 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4466 else if (range < 0)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4467 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4468 /* We're lazy, like in the fastmap code below */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4469 Ichar c;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4470
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4471 d = ((const unsigned char *)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4472 (startpos >= size1 ? string2 - size1 : string1) + startpos);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4473 DEC_IBYTEPTR_FMT (d, fmt);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4474 c = itext_ichar_fmt (d, fmt, lispobj);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4475 c = RE_TRANSLATE (c);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4476 if (c != '\n')
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4477 goto advance;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4478 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4479 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4480 #endif /* REGEX_BEGLINE_CHECK */
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 a fastmap is supplied, skip quickly over characters that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4483 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
4484 null string, however, we don't need to skip characters; we want
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4485 the first null string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4486 if (fastmap && startpos < total_size && !bufp->can_be_null)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4487 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4488 /* For the moment, fastmap always works as if buffer
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4489 is in default format, so convert chars in the search strings
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4490 into default format as we go along, if necessary.
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4491
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4492 &&#### fastmap needs rethinking for 8-bit-fixed so
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4493 it's faster. We need it to reflect the raw
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4494 8-bit-fixed values. That isn't so hard if we assume
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4495 that the top 96 bytes represent a single 1-byte
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4496 charset. For 16-bit/32-bit stuff it's probably not
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4497 worth it to make the fastmap represent the raw, due to
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4498 its nature -- we'd have to use the LSB for the
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4499 fastmap, and that causes lots of problems with Mule
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4500 chars, where it essentially wipes out the usefulness
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4501 of the fastmap entirely. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4502 if (range > 0) /* Searching forwards. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4503 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4504 int lim = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4505 int irange = range;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4506
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4507 if (startpos < size1 && startpos + range >= size1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4508 lim = range - (size1 - startpos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4509
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4510 d = ((const unsigned char *)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4511 (startpos >= size1 ? string2 - size1 : string1) + startpos);
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 /* Written out as an if-else to avoid testing `translate'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4514 inside the loop. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4515 if (TRANSLATE_P (translate))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4516 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4517 while (range > lim)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4518 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4519 re_char *old_d = d;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4520 #ifdef MULE
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4521 Ibyte tempch[MAX_ICHAR_LEN];
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4522 Ichar buf_ch =
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4523 RE_TRANSLATE_1 (itext_ichar_fmt (d, fmt, lispobj));
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4524 set_itext_ichar (tempch, buf_ch);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4525 if (fastmap[*tempch])
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4526 break;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4527 #else
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4528 if (fastmap[(unsigned char) RE_TRANSLATE_1 (*d)])
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4529 break;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4530 #endif /* MULE */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4531 INC_IBYTEPTR_FMT (d, fmt);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4532 range -= (d - old_d);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4533 #if 1
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4534 assert (!forward_search_p || range >= 0);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4535 #endif
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4536 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4537 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4538 #ifdef MULE
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4539 else if (fmt != FORMAT_DEFAULT)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4540 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4541 while (range > lim)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4542 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4543 re_char *old_d = d;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4544 Ibyte tempch[MAX_ICHAR_LEN];
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4545 Ichar buf_ch = itext_ichar_fmt (d, fmt, lispobj);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4546 set_itext_ichar (tempch, buf_ch);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4547 if (fastmap[*tempch])
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4548 break;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4549 INC_IBYTEPTR_FMT (d, fmt);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4550 range -= (d - old_d);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4551 #if 1
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4552 assert (!forward_search_p || range >= 0);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4553 #endif
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4554 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4555 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4556 #endif /* MULE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4557 else
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4558 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4559 while (range > lim && !fastmap[*d])
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4560 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4561 re_char *old_d = d;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4562 INC_IBYTEPTR (d);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4563 range -= (d - old_d);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4564 #if 1
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4565 assert (!forward_search_p || range >= 0);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4566 #endif
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4567 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4568 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4569
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4570 startpos += irange - range;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4571 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4572 else /* Searching backwards. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4573 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4574 /* #### It's not clear why we don't just write a loop, like
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4575 for the moving-forward case. Perhaps the writer got lazy,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4576 since backward searches aren't so common. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4577 d = ((const unsigned char *)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4578 (startpos >= size1 ? string2 - size1 : string1) + startpos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4579 #ifdef MULE
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4580 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4581 Ibyte tempch[MAX_ICHAR_LEN];
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4582 Ichar buf_ch =
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4583 RE_TRANSLATE (itext_ichar_fmt (d, fmt, lispobj));
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4584 set_itext_ichar (tempch, buf_ch);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4585 if (!fastmap[*tempch])
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4586 goto advance;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4587 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4588 #else
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4589 if (!fastmap[(unsigned char) RE_TRANSLATE (*d)])
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4590 goto advance;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4591 #endif /* MULE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4592 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4593 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4595 /* 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
4596 if (range >= 0 && startpos == total_size && fastmap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4597 && !bufp->can_be_null)
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4598 {
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4599 UNBIND_REGEX_MALLOC_CHECK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4600 return -1;
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4601 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4602
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4603 #ifdef emacs /* XEmacs added, w/removal of immediate_quit */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4604 if (!no_quit_in_re_search)
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4605 {
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4606 BEGIN_REGEX_MALLOC_OK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4607 QUIT;
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4608 END_REGEX_MALLOC_OK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4609 RE_SEARCH_RELOCATE_MOVEABLE_DATA_POINTERS ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4610 }
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4611
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4612 #endif
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4613 BEGIN_REGEX_MALLOC_OK ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4614 val = re_match_2_internal (bufp, string1, size1, string2, size2,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4615 startpos, regs, stop
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4616 RE_LISP_CONTEXT_ARGS);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4617 #ifndef REGEX_MALLOC
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4618 ALLOCA_GARBAGE_COLLECT ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4619 #endif
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4620 END_REGEX_MALLOC_OK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4621 RE_SEARCH_RELOCATE_MOVEABLE_DATA_POINTERS ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4622
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4623 if (val >= 0)
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4624 {
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4625 UNBIND_REGEX_MALLOC_CHECK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4626 return startpos;
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4627 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4628
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4629 if (val == -2)
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4630 {
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4631 UNBIND_REGEX_MALLOC_CHECK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4632 return -2;
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4633 }
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4634
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4635 RE_SEARCH_RELOCATE_MOVEABLE_DATA_POINTERS ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4636 advance:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4637 if (!range)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4638 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4639 else if (range > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4640 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4641 Bytecount d_size;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4642 d = ((const unsigned char *)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4643 (startpos >= size1 ? string2 - size1 : string1) + startpos);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4644 d_size = itext_ichar_len_fmt (d, fmt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4645 range -= d_size;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4646 #if 1
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4647 assert (!forward_search_p || range >= 0);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4648 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4649 startpos += d_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4650 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4651 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4652 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4653 Bytecount d_size;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4654 /* Note startpos > size1 not >=. If we are on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4655 string1/string2 boundary, we want to backup into string1. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4656 d = ((const unsigned char *)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4657 (startpos > size1 ? string2 - size1 : string1) + startpos);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4658 DEC_IBYTEPTR_FMT (d, fmt);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
4659 d_size = itext_ichar_len_fmt (d, fmt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4660 range += d_size;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4661 #if 1
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4662 assert (!forward_search_p || range >= 0);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4663 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4664 startpos -= d_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4665 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4666 }
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4667 UNBIND_REGEX_MALLOC_CHECK ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4668 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4669 } /* re_search_2 */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4670
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4672 /* Declarations and macros for re_match_2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4673
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4674 /* This converts PTR, a pointer into one of the search strings `string1'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4675 and `string2' into an offset from the beginning of that string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4676 #define POINTER_TO_OFFSET(ptr) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4677 (FIRST_STRING_P (ptr) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4678 ? ((regoff_t) ((ptr) - string1)) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4679 : ((regoff_t) ((ptr) - string2 + size1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4680
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4681 /* Macros for dealing with the split strings in re_match_2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4683 #define MATCHING_IN_FIRST_STRING (dend == end_match_1)
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 /* Call before fetching a character with *d. This switches over to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4686 string2 if necessary. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4687 #define REGEX_PREFETCH() \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4688 while (d == dend) \
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 /* End of string2 => fail. */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4691 if (dend == end_match_2) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4692 goto fail; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4693 /* End of string1 => advance to string2. */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4694 d = string2; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4695 dend = end_match_2; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4696 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4697
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4698
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4699 /* 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
4700 of `string1' and `string2'. If only one string, it's `string2'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4701 #define AT_STRINGS_BEG(d) ((d) == (size1 ? string1 : string2) || !size2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4702 #define AT_STRINGS_END(d) ((d) == end2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4703
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4704 /* XEmacs change:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4705 If the given position straddles the string gap, return the equivalent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4706 position that is before or after the gap, respectively; otherwise,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4707 return the same position. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4708 #define POS_BEFORE_GAP_UNSAFE(d) ((d) == string2 ? end1 : (d))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4709 #define POS_AFTER_GAP_UNSAFE(d) ((d) == end1 ? string2 : (d))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4710
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4711 /* Test if CH is a word-constituent character. (XEmacs change) */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4712 #define WORDCHAR_P(ch) \
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4713 (SYNTAX (BUFFER_MIRROR_SYNTAX_TABLE (lispbuf), ch) == Sword)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4714
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4715 /* Free everything we malloc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4716 #ifdef MATCH_MAY_ALLOCATE
1726
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 1497
diff changeset
4717 #define FREE_VAR(var,type) if (var) REGEX_FREE (var, type); var = NULL
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4718 #define FREE_VARIABLES() \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4719 do { \
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4720 UNBIND_REGEX_MALLOC_CHECK (); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4721 REGEX_FREE_STACK (fail_stack.stack); \
1726
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 1497
diff changeset
4722 FREE_VAR (regstart, re_char **); \
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 1497
diff changeset
4723 FREE_VAR (regend, re_char **); \
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 1497
diff changeset
4724 FREE_VAR (old_regstart, re_char **); \
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 1497
diff changeset
4725 FREE_VAR (old_regend, re_char **); \
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 1497
diff changeset
4726 FREE_VAR (best_regstart, re_char **); \
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 1497
diff changeset
4727 FREE_VAR (best_regend, re_char **); \
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 1497
diff changeset
4728 FREE_VAR (reg_info, register_info_type *); \
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 1497
diff changeset
4729 FREE_VAR (reg_dummy, re_char **); \
a8d8f419b459 [xemacs-hg @ 2003-09-30 15:26:34 by james]
james
parents: 1497
diff changeset
4730 FREE_VAR (reg_info_dummy, register_info_type *); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4731 } while (0)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4732 #else /* not MATCH_MAY_ALLOCATE */
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4733 #define FREE_VARIABLES() \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4734 do { \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4735 UNBIND_REGEX_MALLOC_CHECK (); \
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4736 } while (0)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4737 #endif /* MATCH_MAY_ALLOCATE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4739 /* These values must meet several constraints. They must not be valid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4740 register values; since we have a limit of 255 registers (because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4741 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
4742 use numbers larger than 255. They must differ by 1, because of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4743 NUM_FAILURE_ITEMS above. And the value for the lowest register must
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4744 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
4745 to actually save any registers when none are active. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4746 #define NO_HIGHEST_ACTIVE_REG (1 << BYTEWIDTH)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4747 #define NO_LOWEST_ACTIVE_REG (NO_HIGHEST_ACTIVE_REG + 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4748
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4749 /* Matching routines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4750
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4751 #ifndef emacs /* XEmacs never uses this. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4752 /* 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
4753
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4754 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4755 re_match (struct re_pattern_buffer *bufp, const char *string, int size,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4756 int pos, struct re_registers *regs
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4757 RE_LISP_CONTEXT_ARGS_DECL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4758 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4759 int result = re_match_2_internal (bufp, NULL, 0, (re_char *) string, size,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4760 pos, regs, size
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4761 RE_LISP_CONTEXT_ARGS);
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4762 ALLOCA_GARBAGE_COLLECT ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4763 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4764 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4765 #endif /* not emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4766
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4767 /* re_match_2 matches the compiled pattern in BUFP against the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4768 (virtual) concatenation of STRING1 and STRING2 (of length SIZE1 and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4769 SIZE2, respectively). We start matching at POS, and stop matching
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4770 at STOP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4771
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4772 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
4773 store offsets for the substring each group matched in REGS. See the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4774 documentation for exactly how many groups we fill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4775
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4776 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
4777 failure stack overflowing). Otherwise, we return the length of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4778 matched substring. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4779
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4780 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4781 re_match_2 (struct re_pattern_buffer *bufp, const char *string1,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4782 int size1, const char *string2, int size2, int pos,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4783 struct re_registers *regs, int stop
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4784 RE_LISP_CONTEXT_ARGS_DECL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4785 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4786 int result;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4787
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4788 #ifdef emacs
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4789 scache = setup_syntax_cache (scache, lispobj, lispbuf,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4790 offset_to_charxpos (lispobj, pos),
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4791 1);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4792 #endif
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4793
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4794 result = re_match_2_internal (bufp, (re_char *) string1, size1,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4795 (re_char *) string2, size2,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4796 pos, regs, stop
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4797 RE_LISP_CONTEXT_ARGS);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4798
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4799 ALLOCA_GARBAGE_COLLECT ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4800 return result;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4803 /* 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
4804 afterwards. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4805 static int
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4806 re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4807 int size1, re_char *string2, int size2, int pos,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4808 struct re_registers *regs, int stop
2333
ba4677f54a05 [xemacs-hg @ 2004-10-14 17:26:18 by james]
james
parents: 2286
diff changeset
4809 RE_LISP_CONTEXT_ARGS_MULE_DECL)
428
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 /* General temporaries. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4812 int mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4813 unsigned char *p1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4814 int should_succeed; /* XEmacs change */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4815
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4816 /* Just past the end of the corresponding string. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4817 re_char *end1, *end2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4818
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4819 /* Pointers into string1 and string2, just past the last characters in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4820 each to consider matching. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4821 re_char *end_match_1, *end_match_2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4822
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4823 /* Where we are in the data, and the end of the current string. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4824 re_char *d, *dend;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4825
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4826 /* Where we are in the pattern, and the end of the pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4827 unsigned char *p = bufp->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4828 REGISTER unsigned char *pend = p + bufp->used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4829
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4830 /* 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
4831 empty subpattern when we get to the stop_memory. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4832 re_char *just_past_start_mem = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4833
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4834 /* We use this to map every character in the string. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4835 RE_TRANSLATE_TYPE translate = bufp->translate;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4836
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4837 /* Failure point stack. Each place that can handle a failure further
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4838 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
4839 restart, regend, and reg_info for all registers corresponding to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4840 the subexpressions we're currently inside, plus the number of such
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4841 registers, and, finally, two char *'s. The first char * is where
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4842 to resume scanning the pattern; the second one is where to resume
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4843 scanning the strings. If the latter is zero, the failure point is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4844 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
4845 it gets discarded and the next one is tried. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4846 #ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4847 fail_stack_type fail_stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4848 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4849 #ifdef DEBUG
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
4850 static int failure_id;
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
4851 int nfailure_points_pushed = 0, nfailure_points_popped = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4852 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4853
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4854 #ifdef REGEX_REL_ALLOC
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4855 /* This holds the pointer to the failure stack, when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4856 it is allocated relocatably. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4857 fail_stack_elt_t *failure_stack_ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4858 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4859
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4860 /* We fill all the registers internally, independent of what we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4861 return, for use in backreferences. The number here includes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4862 an element for register zero. */
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
4863 int num_regs = bufp->re_ngroups + 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4864
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4865 /* The currently active registers. */
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
4866 int lowest_active_reg = NO_LOWEST_ACTIVE_REG;
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
4867 int highest_active_reg = NO_HIGHEST_ACTIVE_REG;
428
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 /* Information on the contents of registers. These are pointers into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4870 the input strings; they record just what was matched (on this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4871 attempt) by a subexpression part of the pattern, that is, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4872 regnum-th regstart pointer points to where in the pattern we began
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4873 matching and the regnum-th regend points to right after where we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4874 stopped matching the regnum-th subexpression. (The zeroth register
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4875 keeps track of what the whole pattern matches.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4876 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4877 re_char **regstart, **regend;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4878 #endif
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 /* 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
4881 match anything, then the register for its start will need to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4882 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
4883 are when we last see its open-group operator. Similarly for a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4884 register's end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4885 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4886 re_char **old_regstart, **old_regend;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4887 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4888
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4889 /* 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
4890 nested) subexpressions we are currently in. The matched_something
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4891 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
4892 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
4893 subexpression. These two fields get reset each time through any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4894 loop their register is in. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4895 #ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4896 register_info_type *reg_info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4897 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4898
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4899 /* The following record the register info as found in the above
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4900 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
4901 This happens as we backtrack through the failure points, which in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4902 turn happens only if we have not yet matched the entire string. */
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
4903 int best_regs_set = false;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4904 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4905 re_char **best_regstart, **best_regend;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4906 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4907
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4908 /* 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
4909 allocate space for that if we're not allocating space for anything
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4910 else (see below). Also, we never need info about register 0 for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4911 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
4912 treat `best_regend' differently than the rest. So we keep track of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4913 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
4914 initialize this to NULL so that when we backtrack the first time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4915 and need to test it, it's not garbage. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4916 re_char *match_end = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4917
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4918 /* This helps SET_REGS_MATCHED avoid doing redundant work. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4919 int set_regs_matched_done = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4920
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4921 /* Used when we pop values we don't care about. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4922 #ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4923 re_char **reg_dummy;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4924 register_info_type *reg_info_dummy;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4925 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4926
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4927 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4928 /* Counts the total number of registers pushed. */
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
4929 int num_regs_pushed = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4930 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4931
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4932 /* 1 if this match ends in the same string (string1 or string2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4933 as the best previous match. */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4934 re_bool same_str_p;
428
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 /* 1 if this match is the best seen so far. */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
4937 re_bool best_match_p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4938
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4939 #ifdef emacs
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4940 Internal_Format fmt = buffer_or_other_internal_format (lispobj);
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4941 #ifdef REL_ALLOC
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4942 Ibyte *orig_buftext =
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4943 BUFFERP (lispobj) ?
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4944 BYTE_BUF_BYTE_ADDRESS (XBUFFER (lispobj),
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4945 BYTE_BUF_BEGV (XBUFFER (lispobj))) :
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4946 0;
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4947 #endif
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4948
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4949 #ifdef ERROR_CHECK_MALLOC
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4950 int depth = bind_regex_malloc_disallowed (1);
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4951 #endif
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
4952 #endif /* emacs */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4953
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
4954 DEBUG_MATCH_PRINT1 ("\n\nEntering re_match_2.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4955
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4956 BEGIN_REGEX_MALLOC_OK ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4957 INIT_FAIL_STACK ();
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4958 END_REGEX_MALLOC_OK ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4959
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4960 #ifdef MATCH_MAY_ALLOCATE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4961 /* Do not bother to initialize all the register variables if there are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4962 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
4963 there are groups, we include space for register 0 (the whole
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4964 pattern), even though we never use it, since it simplifies the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4965 array indexing. We should fix this. */
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
4966 if (bufp->re_ngroups)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4967 {
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4968 BEGIN_REGEX_MALLOC_OK ();
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4969 regstart = REGEX_TALLOC (num_regs, re_char *);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4970 regend = REGEX_TALLOC (num_regs, re_char *);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4971 old_regstart = REGEX_TALLOC (num_regs, re_char *);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4972 old_regend = REGEX_TALLOC (num_regs, re_char *);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4973 best_regstart = REGEX_TALLOC (num_regs, re_char *);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4974 best_regend = REGEX_TALLOC (num_regs, re_char *);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4975 reg_info = REGEX_TALLOC (num_regs, register_info_type);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
4976 reg_dummy = REGEX_TALLOC (num_regs, re_char *);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4977 reg_info_dummy = REGEX_TALLOC (num_regs, register_info_type);
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4978 END_REGEX_MALLOC_OK ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4979
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4980 if (!(regstart && regend && old_regstart && old_regend && reg_info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4981 && best_regstart && best_regend && reg_dummy && reg_info_dummy))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4982 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4983 FREE_VARIABLES ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4984 return -2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4985 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4986 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4987 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4988 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4989 /* We must initialize all our variables to NULL, so that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4990 `FREE_VARIABLES' doesn't try to free them. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4991 regstart = regend = old_regstart = old_regend = best_regstart
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4992 = best_regend = reg_dummy = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4993 reg_info = reg_info_dummy = (register_info_type *) NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4994 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4995 #endif /* MATCH_MAY_ALLOCATE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4996
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4997 #if defined (emacs) && defined (REL_ALLOC)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4998 {
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
4999 /* If the allocations above (or the call to setup_syntax_cache() in
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5000 re_match_2) caused a rel-alloc relocation, then fix up the data
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5001 pointers */
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
5002 Bytecount offset = offset_post_relocation (lispobj, orig_buftext);
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5003 if (offset)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5004 {
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5005 string1 += offset;
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5006 string2 += offset;
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5007 }
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5008 }
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5009 #endif /* defined (emacs) && defined (REL_ALLOC) */
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5010
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5011 /* The starting position is bogus. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5012 if (pos < 0 || pos > size1 + size2)
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 FREE_VARIABLES ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5015 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5016 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5017
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5018 /* Initialize subexpression text positions to -1 to mark ones that no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5019 start_memory/stop_memory has been seen for. Also initialize the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5020 register information struct. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5021 for (mcnt = 1; mcnt < num_regs; mcnt++)
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 regstart[mcnt] = regend[mcnt]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5024 = old_regstart[mcnt] = old_regend[mcnt] = REG_UNSET_VALUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5025
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5026 REG_MATCH_NULL_STRING_P (reg_info[mcnt]) = MATCH_NULL_UNSET_VALUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5027 IS_ACTIVE (reg_info[mcnt]) = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5028 MATCHED_SOMETHING (reg_info[mcnt]) = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5029 EVER_MATCHED_SOMETHING (reg_info[mcnt]) = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5030 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5031 /* 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
5032 `string1' is null. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5033 if (size2 == 0 && string1 != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5034 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5035 string2 = string1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5036 size2 = size1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5037 string1 = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5038 size1 = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5039 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5040 end1 = string1 + size1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5041 end2 = string2 + size2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5042
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5043 /* Compute where to stop matching, within the two strings. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5044 if (stop <= size1)
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 end_match_1 = string1 + stop;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5047 end_match_2 = string2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5048 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5049 else
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 end_match_1 = end1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5052 end_match_2 = string2 + stop - size1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5053 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5054
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5055 /* `p' scans through the pattern as `d' scans through the data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5056 `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
5057 is advanced into the following input string whenever necessary, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5058 this happens before fetching; therefore, at the beginning of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5059 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
5060 equal `string2'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5061 if (size1 > 0 && pos <= size1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5062 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5063 d = string1 + pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5064 dend = end_match_1;
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5067 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5068 d = string2 + pos - size1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5069 dend = end_match_2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5070 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5071
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5072 DEBUG_MATCH_PRINT1 ("The compiled pattern is: \n");
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5073 DEBUG_MATCH_PRINT_COMPILED_PATTERN (bufp, p, pend);
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5074 DEBUG_MATCH_PRINT1 ("The string to match is: `");
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5075 DEBUG_MATCH_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2);
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5076 DEBUG_MATCH_PRINT1 ("'\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5077
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5078 /* This loops over pattern commands. It exits by returning from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5079 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
5080 fails at this starting point in the input data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5081 for (;;)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5082 {
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5083 DEBUG_MATCH_PRINT2 ("\n0x%lx: ", (long) p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5084 #ifdef emacs /* XEmacs added, w/removal of immediate_quit */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5085 if (!no_quit_in_re_search)
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5086 {
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5087 BEGIN_REGEX_MALLOC_OK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5088 QUIT;
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5089 END_REGEX_MALLOC_OK ();
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
5090 RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS ();
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5091 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5092 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5093
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5094 if (p == pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5095 { /* End of pattern means we might have succeeded. */
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5096 DEBUG_MATCH_PRINT1 ("end of pattern ... ");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5097
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5098 /* If we haven't matched the entire string, and we want the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5099 longest match, try backtracking. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5100 if (d != end_match_2)
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 same_str_p = (FIRST_STRING_P (match_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5103 == MATCHING_IN_FIRST_STRING);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5104
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5105 /* AIX compiler got confused when this was combined
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5106 with the previous declaration. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5107 if (same_str_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5108 best_match_p = d > match_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5109 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5110 best_match_p = !MATCHING_IN_FIRST_STRING;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5111
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5112 DEBUG_MATCH_PRINT1 ("backtracking.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5114 if (!FAIL_STACK_EMPTY ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5115 { /* More failure points to try. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5117 /* If exceeds best match so far, save it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5118 if (!best_regs_set || best_match_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5119 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5120 best_regs_set = true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5121 match_end = d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5122
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5123 DEBUG_MATCH_PRINT1 ("\nSAVING match as best so far.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5125 for (mcnt = 1; mcnt < num_regs; mcnt++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5126 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5127 best_regstart[mcnt] = regstart[mcnt];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5128 best_regend[mcnt] = regend[mcnt];
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5131 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5132 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5134 /* If no failure points, don't restore garbage. And if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5135 last match is real best match, don't restore second
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5136 best one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5137 else if (best_regs_set && !best_match_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5138 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5139 restore_best_regs:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5140 /* Restore best match. It may happen that `dend ==
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5141 end_match_1' while the restored d is in string2.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5142 For example, the pattern `x.*y.*z' against the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5143 strings `x-' and `y-z-', if the two strings are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5144 not consecutive in memory. */
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5145 DEBUG_MATCH_PRINT1 ("Restoring best registers.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5147 d = match_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5148 dend = ((d >= string1 && d <= end1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5149 ? end_match_1 : end_match_2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5150
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5151 for (mcnt = 1; mcnt < num_regs; mcnt++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5152 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5153 regstart[mcnt] = best_regstart[mcnt];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5154 regend[mcnt] = best_regend[mcnt];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5155 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5156 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5157 } /* d != end_match_2 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5159 succeed_label:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5160 DEBUG_MATCH_PRINT1 ("Accepting match.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5161
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5162 /* If caller wants register contents data back, do it. */
1028
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5163 {
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5164 int num_nonshy_regs = bufp->re_nsub + 1;
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5165 if (regs && !bufp->no_sub)
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5166 {
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5167 /* Have the register data arrays been allocated? */
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5168 if (bufp->regs_allocated == REGS_UNALLOCATED)
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5169 { /* No. So allocate them with malloc. We need one
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5170 extra element beyond `num_regs' for the `-1' marker
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5171 GNU code uses. */
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5172 regs->num_regs = MAX (RE_NREGS, num_nonshy_regs + 1);
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5173 BEGIN_REGEX_MALLOC_OK ();
1028
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5174 regs->start = TALLOC (regs->num_regs, regoff_t);
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5175 regs->end = TALLOC (regs->num_regs, regoff_t);
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5176 END_REGEX_MALLOC_OK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5177 RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS ();
1028
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5178 if (regs->start == NULL || regs->end == NULL)
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5179 {
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5180 FREE_VARIABLES ();
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5181 return -2;
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5182 }
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5183 bufp->regs_allocated = REGS_REALLOCATE;
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5184 }
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5185 else if (bufp->regs_allocated == REGS_REALLOCATE)
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5186 { /* Yes. If we need more elements than were already
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5187 allocated, reallocate them. If we need fewer, just
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5188 leave it alone. */
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5189 if (regs->num_regs < num_nonshy_regs + 1)
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5190 {
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5191 regs->num_regs = num_nonshy_regs + 1;
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5192 BEGIN_REGEX_MALLOC_OK ();
1028
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5193 RETALLOC (regs->start, regs->num_regs, regoff_t);
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5194 RETALLOC (regs->end, regs->num_regs, regoff_t);
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5195 END_REGEX_MALLOC_OK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
5196 RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS ();
1028
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5197 if (regs->start == NULL || regs->end == NULL)
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5198 {
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5199 FREE_VARIABLES ();
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5200 return -2;
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5201 }
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5202 }
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5203 }
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5204 else
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5205 {
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5206 /* The braces fend off a "empty body in an else-statement"
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5207 warning under GCC when assert expands to nothing. */
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5208 assert (bufp->regs_allocated == REGS_FIXED);
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5209 }
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5210
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5211 /* Convert the pointer data in `regstart' and `regend' to
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5212 indices. Register zero has to be set differently,
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5213 since we haven't kept track of any info for it. */
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5214 if (regs->num_regs > 0)
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5215 {
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5216 regs->start[0] = pos;
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5217 regs->end[0] = (MATCHING_IN_FIRST_STRING
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5218 ? ((regoff_t) (d - string1))
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5219 : ((regoff_t) (d - string2 + size1)));
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5220 }
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5221
2639
cd00e5eeb22a [xemacs-hg @ 2005-03-09 04:59:25 by stephent]
stephent
parents: 2500
diff changeset
5222 /* Map over the NUM_NONSHY_REGS non-shy internal registers.
cd00e5eeb22a [xemacs-hg @ 2005-03-09 04:59:25 by stephent]
stephent
parents: 2500
diff changeset
5223 Copy each into the corresponding external register.
cd00e5eeb22a [xemacs-hg @ 2005-03-09 04:59:25 by stephent]
stephent
parents: 2500
diff changeset
5224 MCNT indexes external registers. */
1028
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5225 for (mcnt = 1; mcnt < MIN (num_nonshy_regs, regs->num_regs);
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5226 mcnt++)
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5227 {
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5228 int internal_reg = bufp->external_to_internal_register[mcnt];
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5229 if (REG_UNSET (regstart[internal_reg]) ||
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5230 REG_UNSET (regend[internal_reg]))
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5231 regs->start[mcnt] = regs->end[mcnt] = -1;
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5232 else
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5233 {
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5234 regs->start[mcnt] =
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5235 (regoff_t) POINTER_TO_OFFSET (regstart[internal_reg]);
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5236 regs->end[mcnt] =
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5237 (regoff_t) POINTER_TO_OFFSET (regend[internal_reg]);
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5238 }
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5239 }
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5240 } /* regs && !bufp->no_sub */
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5241
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5242 /* If we have regs and the regs structure has more elements than
2639
cd00e5eeb22a [xemacs-hg @ 2005-03-09 04:59:25 by stephent]
stephent
parents: 2500
diff changeset
5243 were in the pattern, set the extra elements starting with
cd00e5eeb22a [xemacs-hg @ 2005-03-09 04:59:25 by stephent]
stephent
parents: 2500
diff changeset
5244 NUM_NONSHY_REGS to -1. If we (re)allocated the registers,
cd00e5eeb22a [xemacs-hg @ 2005-03-09 04:59:25 by stephent]
stephent
parents: 2500
diff changeset
5245 this is the case, because we always allocate enough to have
cd00e5eeb22a [xemacs-hg @ 2005-03-09 04:59:25 by stephent]
stephent
parents: 2500
diff changeset
5246 at least one -1 at the end.
1028
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5247
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5248 We do this even when no_sub is set because some applications
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5249 (XEmacs) reuse register structures which may contain stale
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5250 information, and permit attempts to access those registers.
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5251
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5252 It would be possible to require the caller to do this, but we'd
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5253 have to change the API for this function to reflect that, and
1425
74cb069b8417 [xemacs-hg @ 2003-04-23 15:42:44 by stephent]
stephent
parents: 1414
diff changeset
5254 audit all callers. Note: as of 2003-04-17 callers in XEmacs
74cb069b8417 [xemacs-hg @ 2003-04-23 15:42:44 by stephent]
stephent
parents: 1414
diff changeset
5255 do clear the registers, but it's safer to leave this code in
74cb069b8417 [xemacs-hg @ 2003-04-23 15:42:44 by stephent]
stephent
parents: 1414
diff changeset
5256 because of reallocation.
74cb069b8417 [xemacs-hg @ 2003-04-23 15:42:44 by stephent]
stephent
parents: 1414
diff changeset
5257 */
1028
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5258 if (regs && regs->num_regs > 0)
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5259 for (mcnt = num_nonshy_regs; mcnt < regs->num_regs; mcnt++)
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5260 regs->start[mcnt] = regs->end[mcnt] = -1;
b03923afd851 [xemacs-hg @ 2002-10-03 18:08:18 by stephent]
stephent
parents: 1024
diff changeset
5261 }
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5262 DEBUG_MATCH_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n",
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5263 nfailure_points_pushed, nfailure_points_popped,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5264 nfailure_points_pushed - nfailure_points_popped);
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5265 DEBUG_MATCH_PRINT2 ("%u registers pushed.\n", num_regs_pushed);
428
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 mcnt = d - pos - (MATCHING_IN_FIRST_STRING
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5268 ? string1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5269 : string2 - size1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5270
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5271 DEBUG_MATCH_PRINT2 ("Returning %d from re_match_2.\n", mcnt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5272
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5273 FREE_VARIABLES ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5274 return mcnt;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5277 /* Otherwise match next pattern command. */
4759
aa5ed11f473b Remove support for obsolete systems. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 4750
diff changeset
5278 switch ((re_opcode_t) *p++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5279 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5280 /* Ignore these. Used to ignore the n of succeed_n's which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5281 currently have n == 0. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5282 case no_op:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5283 DEBUG_MATCH_PRINT1 ("EXECUTING no_op.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5284 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5286 case succeed:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5287 DEBUG_MATCH_PRINT1 ("EXECUTING succeed.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5288 goto succeed_label;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5289
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5290 /* Match exactly a string of length n in the pattern. The
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5291 following byte in the pattern defines n, and the n bytes after
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5292 that make up the string to match. (Under Mule, this will be in
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5293 the default internal format.) */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5294 case exactn:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5295 mcnt = *p++;
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5296 DEBUG_MATCH_PRINT2 ("EXECUTING exactn %d.\n", mcnt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5298 /* 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
5299 testing `translate' inside the loop. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
5300 if (TRANSLATE_P (translate))
428
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 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5303 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
5304 #ifdef MULE
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
5305 Bytecount pat_len;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
5306
450
98528da0b7fc Import from CVS: tag r21-2-40
cvs
parents: 446
diff changeset
5307 REGEX_PREFETCH ();
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5308 if (RE_TRANSLATE_1 (itext_ichar_fmt (d, fmt, lispobj))
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5309 != itext_ichar (p))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5310 goto fail;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
5311
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5312 pat_len = itext_ichar_len (p);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
5313 p += pat_len;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5314 INC_IBYTEPTR_FMT (d, fmt);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
5315
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
5316 mcnt -= pat_len;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
5317 #else /* not MULE */
450
98528da0b7fc Import from CVS: tag r21-2-40
cvs
parents: 446
diff changeset
5318 REGEX_PREFETCH ();
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5319 if ((unsigned char) RE_TRANSLATE_1 (*d++) != *p++)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
5320 goto fail;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
5321 mcnt--;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
5322 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5323 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
5324 while (mcnt > 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5325 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5326 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5327 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5328 #ifdef MULE
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5329 /* If buffer format is default, then we can shortcut and just
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5330 compare the text directly, byte by byte. Otherwise, we
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5331 need to go character by character. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5332 if (fmt != FORMAT_DEFAULT)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5333 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5334 do
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5335 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5336 Bytecount pat_len;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5337
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5338 REGEX_PREFETCH ();
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5339 if (itext_ichar_fmt (d, fmt, lispobj) !=
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5340 itext_ichar (p))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5341 goto fail;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5342
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5343 pat_len = itext_ichar_len (p);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5344 p += pat_len;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5345 INC_IBYTEPTR_FMT (d, fmt);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5346
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5347 mcnt -= pat_len;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5348 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5349 while (mcnt > 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5350 }
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5351 else
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5352 #endif
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5353 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5354 do
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5355 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5356 REGEX_PREFETCH ();
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5357 if (*d++ != *p++) goto fail;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5358 mcnt--;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5359 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5360 while (mcnt > 0);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5361 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5362 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5363 SET_REGS_MATCHED ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5364 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5365
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 /* Match any character except possibly a newline or a null. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5368 case anychar:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5369 DEBUG_MATCH_PRINT1 ("EXECUTING anychar.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5370
450
98528da0b7fc Import from CVS: tag r21-2-40
cvs
parents: 446
diff changeset
5371 REGEX_PREFETCH ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5372
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5373 if ((!(bufp->syntax & RE_DOT_NEWLINE) &&
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5374 RE_TRANSLATE (itext_ichar_fmt (d, fmt, lispobj)) == '\n')
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5375 || (bufp->syntax & RE_DOT_NOT_NULL &&
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5376 RE_TRANSLATE (itext_ichar_fmt (d, fmt, lispobj)) ==
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5377 '\000'))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5378 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5379
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5380 SET_REGS_MATCHED ();
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5381 DEBUG_MATCH_PRINT2 (" Matched `%d'.\n", *d);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5382 INC_IBYTEPTR_FMT (d, fmt); /* XEmacs change */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5383 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5384
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 charset:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5387 case charset_not:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5388 {
1414
56496b493888 [xemacs-hg @ 2003-04-15 16:09:46 by stephent]
stephent
parents: 1377
diff changeset
5389 REGISTER Ichar c;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
5390 re_bool not_p = (re_opcode_t) *(p - 1) == charset_not;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
5391
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5392 DEBUG_MATCH_PRINT2 ("EXECUTING charset%s.\n", not_p ? "_not" : "");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5393
450
98528da0b7fc Import from CVS: tag r21-2-40
cvs
parents: 446
diff changeset
5394 REGEX_PREFETCH ();
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5395 c = itext_ichar_fmt (d, fmt, lispobj);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5396 c = RE_TRANSLATE (c); /* The character to match. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5397
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
5398 /* Cast to `unsigned int' instead of `unsigned char' in case the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5399 bit list is a full 32 bytes long. */
1414
56496b493888 [xemacs-hg @ 2003-04-15 16:09:46 by stephent]
stephent
parents: 1377
diff changeset
5400 if ((unsigned int)c < (unsigned int) (*p * BYTEWIDTH)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5401 && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
5402 not_p = !not_p;
428
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 p += 1 + *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5405
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
5406 if (!not_p) goto fail;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5407
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5408 SET_REGS_MATCHED ();
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5409 INC_IBYTEPTR_FMT (d, fmt); /* XEmacs change */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5410 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5411 }
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 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5414 case charset_mule:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5415 case charset_mule_not:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5416 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5417 REGISTER Ichar c;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
5418 re_bool not_p = (re_opcode_t) *(p - 1) == charset_mule_not;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
5419
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5420 DEBUG_MATCH_PRINT2 ("EXECUTING charset_mule%s.\n", not_p ? "_not" : "");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5421
450
98528da0b7fc Import from CVS: tag r21-2-40
cvs
parents: 446
diff changeset
5422 REGEX_PREFETCH ();
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5423 c = itext_ichar_fmt (d, fmt, lispobj);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5424 c = RE_TRANSLATE (c); /* The character to match. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5426 if (EQ (Qt, unified_range_table_lookup (p, c, Qnil)))
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
5427 not_p = !not_p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5429 p += unified_range_table_bytes_used (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5430
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
5431 if (!not_p) goto fail;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5432
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5433 SET_REGS_MATCHED ();
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5434 INC_IBYTEPTR_FMT (d, fmt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5435 break;
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 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5438
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5439
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5440 /* The beginning of a group is represented by start_memory.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5441 The arguments are the register number in the next byte, and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5442 number of groups inner to this one in the next. The text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5443 matched within the group is recorded (in the internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5444 registers data structure) under the register number. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5445 case start_memory:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5446 DEBUG_MATCH_PRINT3 ("EXECUTING start_memory %d (%d):\n", *p, p[1]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5447
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5448 /* Find out if this group can match the empty string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5449 p1 = p; /* To send to group_match_null_string_p. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5450
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5451 if (REG_MATCH_NULL_STRING_P (reg_info[*p]) == MATCH_NULL_UNSET_VALUE)
2639
cd00e5eeb22a [xemacs-hg @ 2005-03-09 04:59:25 by stephent]
stephent
parents: 2500
diff changeset
5452 REG_MATCH_NULL_STRING_P (reg_info[*p])
cd00e5eeb22a [xemacs-hg @ 2005-03-09 04:59:25 by stephent]
stephent
parents: 2500
diff changeset
5453 = group_match_null_string_p (&p1, pend, reg_info);
cd00e5eeb22a [xemacs-hg @ 2005-03-09 04:59:25 by stephent]
stephent
parents: 2500
diff changeset
5454
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5455 DEBUG_MATCH_PRINT2 (" group CAN%s match null string\n",
2639
cd00e5eeb22a [xemacs-hg @ 2005-03-09 04:59:25 by stephent]
stephent
parents: 2500
diff changeset
5456 REG_MATCH_NULL_STRING_P (reg_info[*p]) ? "NOT" : "");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5457
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5458 /* Save the position in the string where we were the last time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5459 we were at this open-group operator in case the group is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5460 operated upon by a repetition operator, e.g., with `(a*)*b'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5461 against `ab'; then we want to ignore where we are now in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5462 the string in case this attempt to match fails. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5463 old_regstart[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5464 ? REG_UNSET (regstart[*p]) ? d : regstart[*p]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5465 : regstart[*p];
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5466 DEBUG_MATCH_PRINT2 (" old_regstart: %d\n",
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5467 POINTER_TO_OFFSET (old_regstart[*p]));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5468
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5469 regstart[*p] = d;
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5470 DEBUG_MATCH_PRINT2 (" regstart: %d\n", POINTER_TO_OFFSET (regstart[*p]));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5471
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5472 IS_ACTIVE (reg_info[*p]) = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5473 MATCHED_SOMETHING (reg_info[*p]) = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5474
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5475 /* Clear this whenever we change the register activity status. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5476 set_regs_matched_done = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5477
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5478 /* This is the new highest active register. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5479 highest_active_reg = *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5481 /* If nothing was active before, this is the new lowest active
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5482 register. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5483 if (lowest_active_reg == NO_LOWEST_ACTIVE_REG)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5484 lowest_active_reg = *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5485
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5486 /* Move past the register number and inner group count. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5487 p += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5488 just_past_start_mem = p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5489
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5490 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5493 /* The stop_memory opcode represents the end of a group. Its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5494 arguments are the same as start_memory's: the register
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5495 number, and the number of inner groups. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5496 case stop_memory:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5497 DEBUG_MATCH_PRINT3 ("EXECUTING stop_memory %d (%d):\n", *p, p[1]);
428
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 /* 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
5500 this close-group operator in case the group is operated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5501 upon by a repetition operator, e.g., with `((a*)*(b*)*)*'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5502 against `aba'; then we want to ignore where we are now in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5503 the string in case this attempt to match fails. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5504 old_regend[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5505 ? REG_UNSET (regend[*p]) ? d : regend[*p]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5506 : regend[*p];
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5507 DEBUG_MATCH_PRINT2 (" old_regend: %d\n",
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5508 POINTER_TO_OFFSET (old_regend[*p]));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5510 regend[*p] = d;
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5511 DEBUG_MATCH_PRINT2 (" regend: %d\n", POINTER_TO_OFFSET (regend[*p]));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5512
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5513 /* This register isn't active anymore. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5514 IS_ACTIVE (reg_info[*p]) = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5515
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5516 /* Clear this whenever we change the register activity status. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5517 set_regs_matched_done = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5519 /* If this was the only register active, nothing is active
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5520 anymore. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5521 if (lowest_active_reg == highest_active_reg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5522 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5523 lowest_active_reg = NO_LOWEST_ACTIVE_REG;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5524 highest_active_reg = NO_HIGHEST_ACTIVE_REG;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5525 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5526 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5527 { /* We must scan for the new highest active register, since
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5528 it isn't necessarily one less than now: consider
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5529 (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
5530 new highest active register is 1. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5531 unsigned char r = *p - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5532 while (r > 0 && !IS_ACTIVE (reg_info[r]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5533 r--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5534
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5535 /* If we end up at register zero, that means that we saved
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5536 the registers as the result of an `on_failure_jump', not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5537 a `start_memory', and we jumped to past the innermost
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5538 `stop_memory'. For example, in ((.)*) we save
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5539 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
5540 back to the second ), we are at the stop_memory 1.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5541 Thus, nothing is active. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5542 if (r == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5543 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5544 lowest_active_reg = NO_LOWEST_ACTIVE_REG;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5545 highest_active_reg = NO_HIGHEST_ACTIVE_REG;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5546 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5547 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5548 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5549 highest_active_reg = r;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5550
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5551 /* 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
5552 r = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5553 while (r < highest_active_reg && !IS_ACTIVE(reg_info[r]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5554 r++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5555 lowest_active_reg = r;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5556 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5559 /* If just failed to match something this time around with a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5560 group that's operated on by a repetition operator, try to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5561 force exit from the ``loop'', and restore the register
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5562 information for this group that we had before trying this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5563 last match. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5564 if ((!MATCHED_SOMETHING (reg_info[*p])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5565 || just_past_start_mem == p - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5566 && (p + 2) < pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5567 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
5568 re_bool is_a_jump_n = false;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5569
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5570 p1 = p + 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5571 mcnt = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5572 switch ((re_opcode_t) *p1++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5573 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5574 case jump_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5575 is_a_jump_n = true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5576 case pop_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5577 case maybe_pop_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5578 case jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5579 case dummy_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5580 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5581 if (is_a_jump_n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5582 p1 += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5583 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5585 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5586 /* do nothing */ ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5587 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5588 p1 += mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5589
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5590 /* If the next operation is a jump backwards in the pattern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5591 to an on_failure_jump right before the start_memory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5592 corresponding to this stop_memory, exit from the loop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5593 by forcing a failure after pushing on the stack the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5594 on_failure_jump's jump in the pattern, and d. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5595 if (mcnt < 0 && (re_opcode_t) *p1 == on_failure_jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5596 && (re_opcode_t) p1[3] == start_memory && p1[4] == *p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5597 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5598 /* If this group ever matched anything, then restore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5599 what its registers were before trying this last
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5600 failed match, e.g., with `(a*)*b' against `ab' for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5601 regstart[1], and, e.g., with `((a*)*(b*)*)*'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5602 against `aba' for regend[3].
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5603
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5604 Also restore the registers for inner groups for,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5605 e.g., `((a*)(b*))*' against `aba' (register 3 would
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5606 otherwise get trashed). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5607
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5608 if (EVER_MATCHED_SOMETHING (reg_info[*p]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5609 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
5610 int r;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5611
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5612 EVER_MATCHED_SOMETHING (reg_info[*p]) = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5613
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5614 /* Restore this and inner groups' (if any) registers. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5615 for (r = *p; r < *p + *(p + 1); r++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5616 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5617 regstart[r] = old_regstart[r];
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 /* xx why this test? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5620 if (old_regend[r] >= regstart[r])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5621 regend[r] = old_regend[r];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5622 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5623 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5624 p1++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5625 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5626 PUSH_FAILURE_POINT (p1 + mcnt, d, -2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5628 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5629 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5632 /* Move past the register number and the inner group count. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5633 p += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5634 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5635
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5637 /* \<digit> has been turned into a `duplicate' command which is
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
5638 followed by the numeric value of <digit> as the register number.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
5639 (Already passed through external-to-internal-register mapping,
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
5640 so it refers to the actual group number, not the non-shy-only
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
5641 numbering used in the external world.) */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5642 case duplicate:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5643 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
5644 REGISTER re_char *d2, *dend2;
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
5645 /* Get which register to match against. */
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
5646 int regno = *p++;
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5647 DEBUG_MATCH_PRINT2 ("EXECUTING duplicate %d.\n", regno);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5649 /* Can't back reference a group which we've never matched. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5650 if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5651 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5652
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5653 /* Where in input to try to start matching. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5654 d2 = regstart[regno];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5655
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5656 /* Where to stop matching; if both the place to start and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5657 the place to stop matching are in the same string, then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5658 set to the place to stop, otherwise, for now have to use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5659 the end of the first string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5661 dend2 = ((FIRST_STRING_P (regstart[regno])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5662 == FIRST_STRING_P (regend[regno]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5663 ? regend[regno] : end_match_1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5664 for (;;)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5665 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5666 /* If necessary, advance to next segment in register
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5667 contents. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5668 while (d2 == dend2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5669 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5670 if (dend2 == end_match_2) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5671 if (dend2 == regend[regno]) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5672
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5673 /* End of string1 => advance to string2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5674 d2 = string2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5675 dend2 = regend[regno];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5676 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5677 /* At end of register contents => success */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5678 if (d2 == dend2) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5679
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5680 /* If necessary, advance to next segment in data. */
450
98528da0b7fc Import from CVS: tag r21-2-40
cvs
parents: 446
diff changeset
5681 REGEX_PREFETCH ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5683 /* How many characters left in this segment to match. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5684 mcnt = dend - d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5685
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5686 /* Want how many consecutive characters we can match in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5687 one shot, so, if necessary, adjust the count. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5688 if (mcnt > dend2 - d2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5689 mcnt = dend2 - d2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5690
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5691 /* Compare that many; failure if mismatch, else move
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5692 past them. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
5693 if (TRANSLATE_P (translate)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5694 ? bcmp_translate (d, d2, mcnt, translate
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5695 #ifdef emacs
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5696 , fmt, lispobj
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5697 #endif
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5698 )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5699 : memcmp (d, d2, mcnt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5700 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5701 d += mcnt, d2 += mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5702
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5703 /* Do this because we've match some characters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5704 SET_REGS_MATCHED ();
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5707 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5708
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5709
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5710 /* begline matches the empty string at the beginning of the string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5711 (unless `not_bol' is set in `bufp'), and, if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5712 `newline_anchor' is set, after newlines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5713 case begline:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5714 DEBUG_MATCH_PRINT1 ("EXECUTING begline.\n");
428
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 (AT_STRINGS_BEG (d))
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 if (!bufp->not_bol) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5719 }
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5720 else
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5721 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5722 re_char *d2 = d;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5723 DEC_IBYTEPTR (d2);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5724 if (itext_ichar_ascii_fmt (d2, fmt, lispobj) == '\n' &&
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5725 bufp->newline_anchor)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5726 break;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5727 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5728 /* In all other cases, we fail. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5729 goto fail;
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 /* endline is the dual of begline. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5733 case endline:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5734 DEBUG_MATCH_PRINT1 ("EXECUTING endline.\n");
428
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 if (AT_STRINGS_END (d))
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 if (!bufp->not_eol) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5739 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5740
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5741 /* We have to ``prefetch'' the next character. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
5742 else if ((d == end1 ?
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5743 itext_ichar_ascii_fmt (string2, fmt, lispobj) :
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
5744 itext_ichar_ascii_fmt (d, fmt, lispobj)) == '\n'
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5745 && bufp->newline_anchor)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5746 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5747 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5748 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5749 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5750
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5751
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5752 /* Match at the very beginning of the data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5753 case begbuf:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5754 DEBUG_MATCH_PRINT1 ("EXECUTING begbuf.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5755 if (AT_STRINGS_BEG (d))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5756 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5757 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5758
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5759
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5760 /* Match at the very end of the data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5761 case endbuf:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5762 DEBUG_MATCH_PRINT1 ("EXECUTING endbuf.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5763 if (AT_STRINGS_END (d))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5764 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5765 goto fail;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5768 /* on_failure_keep_string_jump is used to optimize `.*\n'. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5769 pushes NULL as the value for the string on the stack. Then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5770 `pop_failure_point' will keep the current value for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5771 string, instead of restoring it. To see why, consider
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5772 matching `foo\nbar' against `.*\n'. The .* matches the foo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5773 then the . fails against the \n. But the next thing we want
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5774 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
5775 string value, we would be back at the foo.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5776
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5777 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
5778 check all the things that `on_failure_jump' does, to make
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5779 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
5780 share its code. The only reason to push anything on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5781 stack at all is that otherwise we would have to change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5782 `anychar's code to do something besides goto fail in this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5783 case; that seems worse than this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5784 case on_failure_keep_string_jump:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5785 DEBUG_MATCH_PRINT1 ("EXECUTING on_failure_keep_string_jump");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5786
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5787 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5788 DEBUG_MATCH_PRINT3 (" %d (to 0x%lx):\n", mcnt, (long) (p + mcnt));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5789
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
5790 PUSH_FAILURE_POINT (p + mcnt, (unsigned char *) 0, -2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5791 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5792
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5794 /* Uses of on_failure_jump:
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 Each alternative starts with an on_failure_jump that points
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5797 to the beginning of the next alternative. Each alternative
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5798 except the last ends with a jump that in effect jumps past
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5799 the rest of the alternatives. (They really jump to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5800 ending jump of the following alternative, because tensioning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5801 these jumps is a hassle.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5802
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5803 Repeats start with an on_failure_jump that points past both
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5804 the repetition text and either the following jump or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5805 pop_failure_jump back to this on_failure_jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5806 case on_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5807 on_failure:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5808 DEBUG_MATCH_PRINT1 ("EXECUTING on_failure_jump");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5809
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5810 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5811 DEBUG_MATCH_PRINT3 (" %d (to 0x%lx)", mcnt, (long) (p + mcnt));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5812
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5813 /* If this on_failure_jump comes right before a group (i.e.,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5814 the original * applied to a group), save the information
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5815 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
5816 to this point, the group's information will be correct.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5817 For example, in \(a*\)*\1, we need the preceding group,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5818 and in \(\(a*\)b*\)\2, we need the inner group. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5819
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5820 /* We can't use `p' to check ahead because we push
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5821 a failure point to `p + mcnt' after we do this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5822 p1 = p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5823
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5824 /* We need to skip no_op's before we look for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5825 start_memory in case this on_failure_jump is happening as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5826 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
5827 against aba. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5828 while (p1 < pend && (re_opcode_t) *p1 == no_op)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5829 p1++;
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 if (p1 < pend && (re_opcode_t) *p1 == start_memory)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5832 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5833 /* We have a new highest active register now. This will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5834 get reset at the start_memory we are about to get to,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5835 but we will have saved all the registers relevant to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5836 this repetition op, as described above. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5837 highest_active_reg = *(p1 + 1) + *(p1 + 2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5838 if (lowest_active_reg == NO_LOWEST_ACTIVE_REG)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5839 lowest_active_reg = *(p1 + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5840 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5841
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5842 DEBUG_MATCH_PRINT1 (":\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5843 PUSH_FAILURE_POINT (p + mcnt, d, -2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5844 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5845
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 /* A smart repeat ends with `maybe_pop_jump'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5848 We change it to either `pop_failure_jump' or `jump'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5849 case maybe_pop_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5850 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5851 DEBUG_MATCH_PRINT2 ("EXECUTING maybe_pop_jump %d.\n", mcnt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5852 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5853 REGISTER unsigned char *p2 = p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5854
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5855 /* Compare the beginning of the repeat with what in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5856 pattern follows its end. If we can establish that there
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5857 is nothing that they would both match, i.e., that we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5858 would have to backtrack because of (as in, e.g., `a*a')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5859 then we can change to pop_failure_jump, because we'll
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5860 never have to backtrack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5861
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5862 This is not true in the case of alternatives: in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5863 `(a|ab)*' we do need to backtrack to the `ab' alternative
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5864 (e.g., if the string was `ab'). But instead of trying to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5865 detect that here, the alternative has put on a dummy
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5866 failure point which is what we will end up popping. */
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 /* Skip over open/close-group commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5869 If what follows this loop is a ...+ construct,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5870 look at what begins its body, since we will have to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5871 match at least one of that. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5872 while (1)
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 (p2 + 2 < pend
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5875 && ((re_opcode_t) *p2 == stop_memory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5876 || (re_opcode_t) *p2 == start_memory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5877 p2 += 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5878 else if (p2 + 6 < pend
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5879 && (re_opcode_t) *p2 == dummy_failure_jump)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5880 p2 += 6;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5881 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5882 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5883 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5884
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5885 p1 = p + mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5886 /* p1[0] ... p1[2] are the `on_failure_jump' corresponding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5887 to the `maybe_finalize_jump' of this case. Examine what
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5888 follows. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5889
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5890 /* If we're at the end of the pattern, we can change. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5891 if (p2 == pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5892 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5893 /* Consider what happens when matching ":\(.*\)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5894 against ":/". I don't really understand this code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5895 yet. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5896 p[-3] = (unsigned char) pop_failure_jump;
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5897 DEBUG_MATCH_PRINT1
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5898 (" End of pattern: change to `pop_failure_jump'.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5899 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5900
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5901 else if ((re_opcode_t) *p2 == exactn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5902 || (bufp->newline_anchor && (re_opcode_t) *p2 == endline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5903 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5904 REGISTER unsigned char c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5905 = *p2 == (unsigned char) endline ? '\n' : p2[2];
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 if ((re_opcode_t) p1[3] == exactn && p1[5] != c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5908 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5909 p[-3] = (unsigned char) pop_failure_jump;
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5910 DEBUG_MATCH_PRINT3 (" %c != %c => pop_failure_jump.\n",
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5911 c, p1[5]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5912 }
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 else if ((re_opcode_t) p1[3] == charset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5915 || (re_opcode_t) p1[3] == charset_not)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5916 {
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
5917 int not_p = (re_opcode_t) p1[3] == charset_not;
428
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 if (c < (unsigned char) (p1[4] * BYTEWIDTH)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5920 && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
5921 not_p = !not_p;
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
5922
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
5923 /* `not_p' is equal to 1 if c would match, which means
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5924 that we can't change to pop_failure_jump. */
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
5925 if (!not_p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5926 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5927 p[-3] = (unsigned char) pop_failure_jump;
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5928 DEBUG_MATCH_PRINT1 (" No match => pop_failure_jump.\n");
428
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5931 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5932 else if ((re_opcode_t) *p2 == charset)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5933 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5934 #ifdef DEBUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5935 REGISTER unsigned char c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5936 = *p2 == (unsigned char) endline ? '\n' : p2[2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5937 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5938
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5939 if ((re_opcode_t) p1[3] == exactn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5940 && ! ((int) p2[1] * BYTEWIDTH > (int) p1[5]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5941 && (p2[2 + p1[5] / BYTEWIDTH]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5942 & (1 << (p1[5] % BYTEWIDTH)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5943 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5944 p[-3] = (unsigned char) pop_failure_jump;
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5945 DEBUG_MATCH_PRINT3 (" %c != %c => pop_failure_jump.\n",
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5946 c, p1[5]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5947 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5948
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5949 else if ((re_opcode_t) p1[3] == charset_not)
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 int idx;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5952 /* We win if the charset_not inside the loop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5953 lists every character listed in the charset after. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5954 for (idx = 0; idx < (int) p2[1]; idx++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5955 if (! (p2[2 + idx] == 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5956 || (idx < (int) p1[4]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5957 && ((p2[2 + idx] & ~ p1[5 + idx]) == 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5958 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5959
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5960 if (idx == p2[1])
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 p[-3] = (unsigned char) pop_failure_jump;
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5963 DEBUG_MATCH_PRINT1 (" No match => pop_failure_jump.\n");
428
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5966 else if ((re_opcode_t) p1[3] == charset)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5967 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5968 int idx;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5969 /* We win if the charset inside the loop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5970 has no overlap with the one after the loop. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5971 for (idx = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5972 idx < (int) p2[1] && idx < (int) p1[4];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5973 idx++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5974 if ((p2[2 + idx] & p1[5 + idx]) != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5975 break;
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 if (idx == p2[1] || idx == p1[4])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5978 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5979 p[-3] = (unsigned char) pop_failure_jump;
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5980 DEBUG_MATCH_PRINT1 (" No match => pop_failure_jump.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5981 }
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 }
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 p -= 2; /* Point at relative address again. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5986 if ((re_opcode_t) p[-1] != pop_failure_jump)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5987 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5988 p[-1] = (unsigned char) jump;
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
5989 DEBUG_MATCH_PRINT1 (" Match => jump.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5990 goto unconditional_jump;
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 /* Note fall through. */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5995 /* 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
5996 its matching on_failure_jump, where the latter will push a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5997 failure point. The pop_failure_jump takes off failure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5998 points put on by this pop_failure_jump's matching
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5999 on_failure_jump; we got through the pattern to here from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6000 matching on_failure_jump, so didn't fail. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6001 case pop_failure_jump:
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 /* We need to pass separate storage for the lowest and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6004 highest registers, even though we don't care about the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6005 actual values. Otherwise, we will restore only one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6006 register from the stack, since lowest will == highest in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6007 `pop_failure_point'. */
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
6008 int dummy_low_reg, dummy_high_reg;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6009 unsigned char *pdummy;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
6010 re_char *sdummy = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6011
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6012 DEBUG_MATCH_PRINT1 ("EXECUTING pop_failure_jump.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6013 POP_FAILURE_POINT (sdummy, pdummy,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6014 dummy_low_reg, dummy_high_reg,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6015 reg_dummy, reg_dummy, reg_info_dummy);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6016 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6017 /* Note fall through. */
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 /* Unconditionally jump (without popping any failure points). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6021 case jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6022 unconditional_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6023 EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6024 DEBUG_MATCH_PRINT2 ("EXECUTING jump %d ", mcnt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6025 p += mcnt; /* Do the jump. */
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6026 DEBUG_MATCH_PRINT2 ("(to 0x%lx).\n", (long) p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6027 break;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6030 /* We need this opcode so we can detect where alternatives end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6031 in `group_match_null_string_p' et al. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6032 case jump_past_alt:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6033 DEBUG_MATCH_PRINT1 ("EXECUTING jump_past_alt.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6034 goto unconditional_jump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6035
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6036
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6037 /* Normally, the on_failure_jump pushes a failure point, which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6038 then gets popped at pop_failure_jump. We will end up at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6039 pop_failure_jump, also, and with a pattern of, say, `a+', we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6040 are skipping over the on_failure_jump, so we have to push
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6041 something meaningless for pop_failure_jump to pop. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6042 case dummy_failure_jump:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6043 DEBUG_MATCH_PRINT1 ("EXECUTING dummy_failure_jump.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6044 /* It doesn't matter what we push for the string here. What
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6045 the code at `fail' tests is the value for the pattern. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
6046 PUSH_FAILURE_POINT ((unsigned char *) 0, (unsigned char *) 0, -2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6047 goto unconditional_jump;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6050 /* 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
6051 point in case we are followed by a `pop_failure_jump', because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6052 we don't want the failure point for the alternative to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6053 popped. For example, matching `(a|ab)*' against `aab'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6054 requires that we match the `ab' alternative. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6055 case push_dummy_failure:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6056 DEBUG_MATCH_PRINT1 ("EXECUTING push_dummy_failure.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6057 /* See comments just above at `dummy_failure_jump' about the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6058 two zeroes. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
6059 PUSH_FAILURE_POINT ((unsigned char *) 0, (unsigned char *) 0, -2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6060 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6061
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6062 /* Have to succeed matching what follows at least n times.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6063 After that, handle like `on_failure_jump'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6064 case succeed_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6065 EXTRACT_NUMBER (mcnt, p + 2);
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6066 DEBUG_MATCH_PRINT2 ("EXECUTING succeed_n %d.\n", mcnt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6067
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6068 assert (mcnt >= 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6069 /* Originally, this is how many times we HAVE to succeed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6070 if (mcnt > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6071 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6072 mcnt--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6073 p += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6074 STORE_NUMBER_AND_INCR (p, mcnt);
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6075 DEBUG_MATCH_PRINT3 (" Setting 0x%lx to %d.\n", (long) p, mcnt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6076 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6077 else if (mcnt == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6078 {
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6079 DEBUG_MATCH_PRINT2 (" Setting two bytes from 0x%lx to no_op.\n",
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6080 (long) (p+2));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6081 p[2] = (unsigned char) no_op;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6082 p[3] = (unsigned char) no_op;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6083 goto on_failure;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6084 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6085 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6086
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6087 case jump_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6088 EXTRACT_NUMBER (mcnt, p + 2);
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6089 DEBUG_MATCH_PRINT2 ("EXECUTING jump_n %d.\n", mcnt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6090
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6091 /* Originally, this is how many times we CAN jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6092 if (mcnt)
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 mcnt--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6095 STORE_NUMBER (p + 2, mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6096 goto unconditional_jump;
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 /* 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
6099 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6100 p += 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6101 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6102
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6103 case set_number_at:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6104 {
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6105 DEBUG_MATCH_PRINT1 ("EXECUTING set_number_at.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6107 EXTRACT_NUMBER_AND_INCR (mcnt, p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6108 p1 = p + mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6109 EXTRACT_NUMBER_AND_INCR (mcnt, p);
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6110 DEBUG_MATCH_PRINT3 (" Setting 0x%lx to %d.\n", (long) p1, mcnt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6111 STORE_NUMBER (p1, mcnt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6112 break;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6115 case wordbound:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6116 DEBUG_MATCH_PRINT1 ("EXECUTING wordbound.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6117 should_succeed = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6118 matchwordbound:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6119 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6120 /* XEmacs change */
1377
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6121 /* Straightforward and (I hope) correct implementation.
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6122 Probably should be optimized by arranging to compute
1497
0ad2242c43a4 [xemacs-hg @ 2003-05-22 10:18:55 by stephent]
stephent
parents: 1468
diff changeset
6123 charpos only once. */
1377
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6124 /* emch1 is the character before d, syn1 is the syntax of
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6125 emch1, emch2 is the character at d, and syn2 is the
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6126 syntax of emch2. */
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6127 Ichar emch1, emch2;
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
6128 int syn1 = 0,
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
6129 syn2 = 0;
1377
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6130 re_char *d_before, *d_after;
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6131 int result,
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6132 at_beg = AT_STRINGS_BEG (d),
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6133 at_end = AT_STRINGS_END (d);
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6134 #ifdef emacs
1497
0ad2242c43a4 [xemacs-hg @ 2003-05-22 10:18:55 by stephent]
stephent
parents: 1468
diff changeset
6135 Charxpos charpos;
1377
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6136 #endif
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6137
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6138 if (at_beg && at_end)
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6139 {
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6140 result = 0;
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6141 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6142 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6143 {
1377
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6144 if (!at_beg)
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6145 {
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6146 d_before = POS_BEFORE_GAP_UNSAFE (d);
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6147 DEC_IBYTEPTR_FMT (d_before, fmt);
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6148 emch1 = itext_ichar_fmt (d_before, fmt, lispobj);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6149 #ifdef emacs
1497
0ad2242c43a4 [xemacs-hg @ 2003-05-22 10:18:55 by stephent]
stephent
parents: 1468
diff changeset
6150 charpos = offset_to_charxpos (lispobj,
0ad2242c43a4 [xemacs-hg @ 2003-05-22 10:18:55 by stephent]
stephent
parents: 1468
diff changeset
6151 PTR_TO_OFFSET (d)) - 1;
1377
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6152 BEGIN_REGEX_MALLOC_OK ();
1497
0ad2242c43a4 [xemacs-hg @ 2003-05-22 10:18:55 by stephent]
stephent
parents: 1468
diff changeset
6153 UPDATE_SYNTAX_CACHE (scache, charpos);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6154 #endif
1377
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6155 syn1 = SYNTAX_FROM_CACHE (scache, emch1);
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6156 END_REGEX_MALLOC_OK ();
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6157 }
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6158 if (!at_end)
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6159 {
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6160 d_after = POS_AFTER_GAP_UNSAFE (d);
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6161 emch2 = itext_ichar_fmt (d_after, fmt, lispobj);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6162 #ifdef emacs
1497
0ad2242c43a4 [xemacs-hg @ 2003-05-22 10:18:55 by stephent]
stephent
parents: 1468
diff changeset
6163 charpos = offset_to_charxpos (lispobj, PTR_TO_OFFSET (d));
1377
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6164 BEGIN_REGEX_MALLOC_OK ();
1497
0ad2242c43a4 [xemacs-hg @ 2003-05-22 10:18:55 by stephent]
stephent
parents: 1468
diff changeset
6165 UPDATE_SYNTAX_CACHE_FORWARD (scache, charpos);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6166 #endif
1377
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6167 syn2 = SYNTAX_FROM_CACHE (scache, emch2);
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6168 END_REGEX_MALLOC_OK ();
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6169 }
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6170 RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS ();
1377
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6171
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6172 if (at_beg)
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6173 result = (syn2 == Sword);
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6174 else if (at_end)
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6175 result = (syn1 == Sword);
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6176 else
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6177 result = ((syn1 == Sword) != (syn2 == Sword));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6178 }
1377
19738a2a5138 [xemacs-hg @ 2003-03-24 15:01:47 by stephent]
stephent
parents: 1347
diff changeset
6179
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6180 if (result == should_succeed)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6181 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6182 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6183 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6185 case notwordbound:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6186 DEBUG_MATCH_PRINT1 ("EXECUTING notwordbound.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6187 should_succeed = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6188 goto matchwordbound;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6190 case wordbeg:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6191 DEBUG_MATCH_PRINT1 ("EXECUTING wordbeg.\n");
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6192 if (AT_STRINGS_END (d))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6193 goto fail;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6194 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6195 /* XEmacs: this originally read:
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 if (WORDCHAR_P (d) && (AT_STRINGS_BEG (d) || !WORDCHAR_P (d - 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6198 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6200 */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6201 re_char *dtmp = POS_AFTER_GAP_UNSAFE (d);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6202 Ichar emch = itext_ichar_fmt (dtmp, fmt, lispobj);
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6203 int tempres;
1347
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1346
diff changeset
6204 #ifdef emacs
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1346
diff changeset
6205 Charxpos charpos = offset_to_charxpos (lispobj, PTR_TO_OFFSET (d));
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1346
diff changeset
6206 #endif
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6207 BEGIN_REGEX_MALLOC_OK ();
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6208 #ifdef emacs
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6209 UPDATE_SYNTAX_CACHE (scache, charpos);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6210 #endif
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6211 tempres = (SYNTAX_FROM_CACHE (scache, emch) != Sword);
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6212 END_REGEX_MALLOC_OK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6213 RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6214 if (tempres)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6215 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6216 if (AT_STRINGS_BEG (d))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6217 break;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6218 dtmp = POS_BEFORE_GAP_UNSAFE (d);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6219 DEC_IBYTEPTR_FMT (dtmp, fmt);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6220 emch = itext_ichar_fmt (dtmp, fmt, lispobj);
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6221 BEGIN_REGEX_MALLOC_OK ();
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6222 #ifdef emacs
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6223 UPDATE_SYNTAX_CACHE_BACKWARD (scache, charpos - 1);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6224 #endif
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6225 tempres = (SYNTAX_FROM_CACHE (scache, emch) != Sword);
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6226 END_REGEX_MALLOC_OK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6227 RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6228 if (tempres)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6229 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6230 goto fail;
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 case wordend:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6234 DEBUG_MATCH_PRINT1 ("EXECUTING wordend.\n");
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6235 if (AT_STRINGS_BEG (d))
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6236 goto fail;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6237 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6238 /* XEmacs: this originally read:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6239
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6240 if (!AT_STRINGS_BEG (d) && WORDCHAR_P (d - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6241 && (!WORDCHAR_P (d) || AT_STRINGS_END (d)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6242 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6244 The or condition is incorrect (reversed).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6245 */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6246 re_char *dtmp;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6247 Ichar emch;
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6248 int tempres;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6249 #ifdef emacs
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6250 Charxpos charpos = offset_to_charxpos (lispobj, PTR_TO_OFFSET (d));
1347
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1346
diff changeset
6251 BEGIN_REGEX_MALLOC_OK ();
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6252 UPDATE_SYNTAX_CACHE (scache, charpos);
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6253 END_REGEX_MALLOC_OK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6254 RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS ();
1347
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1346
diff changeset
6255 #endif
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6256 dtmp = POS_BEFORE_GAP_UNSAFE (d);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6257 DEC_IBYTEPTR_FMT (dtmp, fmt);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6258 emch = itext_ichar_fmt (dtmp, fmt, lispobj);
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6259 BEGIN_REGEX_MALLOC_OK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6260 tempres = (SYNTAX_FROM_CACHE (scache, emch) != Sword);
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6261 END_REGEX_MALLOC_OK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6262 RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6263 if (tempres)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6264 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6265 if (AT_STRINGS_END (d))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6266 break;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6267 dtmp = POS_AFTER_GAP_UNSAFE (d);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6268 emch = itext_ichar_fmt (dtmp, fmt, lispobj);
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6269 BEGIN_REGEX_MALLOC_OK ();
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6270 #ifdef emacs
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6271 UPDATE_SYNTAX_CACHE_FORWARD (scache, charpos + 1);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6272 #endif
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6273 tempres = (SYNTAX_FROM_CACHE (scache, emch) != Sword);
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6274 END_REGEX_MALLOC_OK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6275 RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6276 if (tempres)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6277 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6278 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6279 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6281 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6282 case before_dot:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6283 DEBUG_MATCH_PRINT1 ("EXECUTING before_dot.\n");
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6284 if (!BUFFERP (lispobj)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6285 || (BUF_PTR_BYTE_POS (XBUFFER (lispobj), (unsigned char *) d)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6286 >= BUF_PT (XBUFFER (lispobj))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6287 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6288 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6290 case at_dot:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6291 DEBUG_MATCH_PRINT1 ("EXECUTING at_dot.\n");
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6292 if (!BUFFERP (lispobj)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6293 || (BUF_PTR_BYTE_POS (XBUFFER (lispobj), (unsigned char *) d)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6294 != BUF_PT (XBUFFER (lispobj))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6295 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6296 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6298 case after_dot:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6299 DEBUG_MATCH_PRINT1 ("EXECUTING after_dot.\n");
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6300 if (!BUFFERP (lispobj)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6301 || (BUF_PTR_BYTE_POS (XBUFFER (lispobj), (unsigned char *) d)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6302 <= BUF_PT (XBUFFER (lispobj))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6303 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6304 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6305
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6306 case syntaxspec:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6307 DEBUG_MATCH_PRINT2 ("EXECUTING syntaxspec %d.\n", mcnt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6308 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6309 goto matchsyntax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6311 case wordchar:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6312 DEBUG_MATCH_PRINT1 ("EXECUTING Emacs wordchar.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6313 mcnt = (int) Sword;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6314 matchsyntax:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6315 should_succeed = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6316 matchornotsyntax:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6317 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6318 int matches;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6319 Ichar emch;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6320
450
98528da0b7fc Import from CVS: tag r21-2-40
cvs
parents: 446
diff changeset
6321 REGEX_PREFETCH ();
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6322 BEGIN_REGEX_MALLOC_OK ();
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6323 UPDATE_SYNTAX_CACHE
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6324 (scache, offset_to_charxpos (lispobj, PTR_TO_OFFSET (d)));
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6325 END_REGEX_MALLOC_OK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6326 RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS ();
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6327
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6328 emch = itext_ichar_fmt (d, fmt, lispobj);
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6329 BEGIN_REGEX_MALLOC_OK ();
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6330 matches = (SYNTAX_FROM_CACHE (scache, emch) ==
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6331 (enum syntaxcode) mcnt);
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6332 END_REGEX_MALLOC_OK ();
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6333 RE_MATCH_RELOCATE_MOVEABLE_DATA_POINTERS ();
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6334 INC_IBYTEPTR_FMT (d, fmt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6335 if (matches != should_succeed)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6336 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6337 SET_REGS_MATCHED ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6338 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6339 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6341 case notsyntaxspec:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6342 DEBUG_MATCH_PRINT2 ("EXECUTING notsyntaxspec %d.\n", mcnt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6343 mcnt = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6344 goto matchnotsyntax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6345
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6346 case notwordchar:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6347 DEBUG_MATCH_PRINT1 ("EXECUTING Emacs notwordchar.\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6348 mcnt = (int) Sword;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6349 matchnotsyntax:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6350 should_succeed = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6351 goto matchornotsyntax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6352
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6353 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6354 /* 97/2/17 jhod Mule category code patch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6355 case categoryspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6356 should_succeed = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6357 matchornotcategory:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6358 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6359 Ichar emch;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6360
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6361 mcnt = *p++;
450
98528da0b7fc Import from CVS: tag r21-2-40
cvs
parents: 446
diff changeset
6362 REGEX_PREFETCH ();
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6363 emch = itext_ichar_fmt (d, fmt, lispobj);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6364 INC_IBYTEPTR_FMT (d, fmt);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6365 if (check_category_char (emch, BUFFER_CATEGORY_TABLE (lispbuf),
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6366 mcnt, should_succeed))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6367 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6368 SET_REGS_MATCHED ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6369 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6370 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6371
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6372 case notcategoryspec:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6373 should_succeed = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6374 goto matchornotcategory;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6375 /* end of category patch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6376 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6377 #else /* not emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6378 case wordchar:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6379 DEBUG_MATCH_PRINT1 ("EXECUTING non-Emacs wordchar.\n");
450
98528da0b7fc Import from CVS: tag r21-2-40
cvs
parents: 446
diff changeset
6380 REGEX_PREFETCH ();
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6381 if (!WORDCHAR_P ((int) (*d)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6382 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6383 SET_REGS_MATCHED ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6384 d++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6385 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6387 case notwordchar:
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6388 DEBUG_MATCH_PRINT1 ("EXECUTING non-Emacs notwordchar.\n");
450
98528da0b7fc Import from CVS: tag r21-2-40
cvs
parents: 446
diff changeset
6389 REGEX_PREFETCH ();
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6390 if (!WORDCHAR_P ((int) (*d)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6391 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6392 SET_REGS_MATCHED ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6393 d++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6394 break;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
6395 #endif /* emacs */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6396
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6397 default:
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2421
diff changeset
6398 ABORT ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6399 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6400 continue; /* Successfully executed one pattern command; keep going. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6402
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6403 /* We goto here if a matching operation fails. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6404 fail:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6405 if (!FAIL_STACK_EMPTY ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6406 { /* A restart point is known. Restore to that state. */
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
6407 DEBUG_MATCH_PRINT1 ("\nFAIL:\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6408 POP_FAILURE_POINT (d, p,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6409 lowest_active_reg, highest_active_reg,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6410 regstart, regend, reg_info);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6411
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6412 /* If this failure point is a dummy, try the next one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6413 if (!p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6414 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6415
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6416 /* 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
6417 assert (p <= pend);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6418 if (p < pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6419 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6420 re_bool is_a_jump_n = false;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6421
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6422 /* If failed to a backwards jump that's part of a repetition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6423 loop, need to pop this failure point and use the next one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6424 switch ((re_opcode_t) *p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6425 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6426 case jump_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6427 is_a_jump_n = true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6428 case maybe_pop_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6429 case pop_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6430 case jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6431 p1 = p + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6432 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6433 p1 += mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6435 if ((is_a_jump_n && (re_opcode_t) *p1 == succeed_n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6436 || (!is_a_jump_n
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6437 && (re_opcode_t) *p1 == on_failure_jump))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6438 goto fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6439 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6440 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6441 /* do nothing */ ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6442 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6443 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6444
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6445 if (d >= string1 && d <= end1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6446 dend = end_match_1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6447 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6448 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6449 break; /* Matching at this starting point really fails. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6450 } /* for (;;) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6452 if (best_regs_set)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6453 goto restore_best_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6454
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6455 FREE_VARIABLES ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6456
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6457 return -1; /* Failure to match. */
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6458 } /* re_match_2_internal */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6459
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6460 /* Subroutine definitions for re_match_2. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6461
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6462
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6463 /* 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
6464
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6465 Return true if the pattern up to the corresponding stop_memory can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6466 match the empty string, and false otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6467
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6468 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
6469 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
6470
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6471 We don't handle duplicates properly (yet). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6472
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6473 static re_bool
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6474 group_match_null_string_p (unsigned char **p, unsigned char *end,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6475 register_info_type *reg_info)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6476 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6477 int mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6478 /* Point to after the args to the start_memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6479 unsigned char *p1 = *p + 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6481 while (p1 < end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6482 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6483 /* Skip over opcodes that can match nothing, and return true or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6484 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
6485 matching stop_memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6486
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6487 switch ((re_opcode_t) *p1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6488 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6489 /* Could be either a loop or a series of alternatives. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6490 case on_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6491 p1++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6492 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6494 /* If the next operation is not a jump backwards in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6495 pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6496
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6497 if (mcnt >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6498 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6499 /* Go through the on_failure_jumps of the alternatives,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6500 seeing if any of the alternatives cannot match nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6501 The last alternative starts with only a jump,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6502 whereas the rest start with on_failure_jump and end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6503 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
6504
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6505 /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
6506 /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
6507 /exactn/1/c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6508
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6509 So, we have to first go through the first (n-1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6510 alternatives and then deal with the last one separately. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6511
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6512
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6513 /* Deal with the first (n-1) alternatives, which start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6514 with an on_failure_jump (see above) that jumps to right
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6515 past a jump_past_alt. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6516
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6517 while ((re_opcode_t) p1[mcnt-3] == jump_past_alt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6518 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6519 /* `mcnt' holds how many bytes long the alternative
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6520 is, including the ending `jump_past_alt' and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6521 its number. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6522
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6523 if (!alt_match_null_string_p (p1, p1 + mcnt - 3,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6524 reg_info))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6525 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6527 /* Move to right after this alternative, including the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6528 jump_past_alt. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6529 p1 += mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6530
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6531 /* Break if it's the beginning of an n-th alternative
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6532 that doesn't begin with an on_failure_jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6533 if ((re_opcode_t) *p1 != on_failure_jump)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6534 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6535
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6536 /* Still have to check that it's not an n-th
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6537 alternative that starts with an on_failure_jump. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6538 p1++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6539 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6540 if ((re_opcode_t) p1[mcnt-3] != jump_past_alt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6541 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6542 /* Get to the beginning of the n-th alternative. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6543 p1 -= 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6544 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6545 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6546 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6547
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6548 /* Deal with the last alternative: go back and get number
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6549 of the `jump_past_alt' just before it. `mcnt' contains
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6550 the length of the alternative. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6551 EXTRACT_NUMBER (mcnt, p1 - 2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6552
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6553 if (!alt_match_null_string_p (p1, p1 + mcnt, reg_info))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6554 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6555
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6556 p1 += mcnt; /* Get past the n-th alternative. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6557 } /* if mcnt > 0 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6558 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6560
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6561 case stop_memory:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6562 assert (p1[1] == **p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6563 *p = p1 + 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6564 return true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6565
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6566
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6567 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6568 if (!common_op_match_null_string_p (&p1, end, reg_info))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6569 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6570 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6571 } /* while p1 < end */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6573 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6574 } /* group_match_null_string_p */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6576
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6577 /* 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
6578 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
6579 byte past the last. The alternative can contain groups. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6580
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6581 static re_bool
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6582 alt_match_null_string_p (unsigned char *p, unsigned char *end,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6583 register_info_type *reg_info)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6584 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6585 int mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6586 unsigned char *p1 = p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6587
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6588 while (p1 < end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6589 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6590 /* Skip over opcodes that can match nothing, and break when we get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6591 to one that can't. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6592
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6593 switch ((re_opcode_t) *p1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6594 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6595 /* It's a loop. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6596 case on_failure_jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6597 p1++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6598 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6599 p1 += mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6600 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6601
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6602 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6603 if (!common_op_match_null_string_p (&p1, end, reg_info))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6604 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6605 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6606 } /* while p1 < end */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6607
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6608 return true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6609 } /* alt_match_null_string_p */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6610
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6611
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6612 /* Deals with the ops common to group_match_null_string_p and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6613 alt_match_null_string_p.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6615 Sets P to one after the op and its arguments, if any. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6616
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6617 static re_bool
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6618 common_op_match_null_string_p (unsigned char **p, unsigned char *end,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6619 register_info_type *reg_info)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6620 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6621 int mcnt;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6622 re_bool ret;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6623 int reg_no;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6624 unsigned char *p1 = *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6626 switch ((re_opcode_t) *p1++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6627 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6628 case no_op:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6629 case begline:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6630 case endline:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6631 case begbuf:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6632 case endbuf:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6633 case wordbeg:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6634 case wordend:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6635 case wordbound:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6636 case notwordbound:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6637 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6638 case before_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6639 case at_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6640 case after_dot:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6641 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6642 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6643
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6644 case start_memory:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6645 reg_no = *p1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6646 assert (reg_no > 0 && reg_no <= MAX_REGNUM);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6647 ret = group_match_null_string_p (&p1, end, reg_info);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6649 /* 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
6650 contains a group and a back reference to it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6651
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6652 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
6653 REG_MATCH_NULL_STRING_P (reg_info[reg_no]) = ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6654
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6655 if (!ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6656 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6657 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6658
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6659 /* 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
6660 case jump:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6661 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6662 if (mcnt >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6663 p1 += mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6664 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6665 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6666 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6667
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6668 case succeed_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6669 /* Get to the number of times to succeed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6670 p1 += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6671 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6672
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6673 if (mcnt == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6674 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6675 p1 -= 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6676 EXTRACT_NUMBER_AND_INCR (mcnt, p1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6677 p1 += mcnt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6678 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6679 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6680 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6681 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6683 case duplicate:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6684 if (!REG_MATCH_NULL_STRING_P (reg_info[*p1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6685 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6686 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6687
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6688 case set_number_at:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6689 p1 += 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6690
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6691 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6692 /* All other opcodes mean we cannot match the empty string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6693 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6694 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6695
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6696 *p = p1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6697 return true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6698 } /* common_op_match_null_string_p */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6699
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6700
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6701 /* Return zero if TRANSLATE[S1] and TRANSLATE[S2] are identical for LEN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6702 bytes; nonzero otherwise. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6703
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6704 static int
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
6705 bcmp_translate (re_char *s1, re_char *s2,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6706 REGISTER int len, RE_TRANSLATE_TYPE translate
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6707 #ifdef emacs
2333
ba4677f54a05 [xemacs-hg @ 2004-10-14 17:26:18 by james]
james
parents: 2286
diff changeset
6708 , Internal_Format USED_IF_MULE (fmt),
ba4677f54a05 [xemacs-hg @ 2004-10-14 17:26:18 by james]
james
parents: 2286
diff changeset
6709 Lisp_Object USED_IF_MULE (lispobj)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6710 #endif
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6711 )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6712 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6713 REGISTER re_char *p1 = s1, *p2 = s2;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
6714 #ifdef MULE
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6715 re_char *p1_end = s1 + len;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6716 re_char *p2_end = s2 + len;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
6717
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
6718 while (p1 != p1_end && p2 != p2_end)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
6719 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6720 Ichar p1_ch, p2_ch;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6721
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6722 p1_ch = itext_ichar_fmt (p1, fmt, lispobj);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6723 p2_ch = itext_ichar_fmt (p2, fmt, lispobj);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6724
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6725 if (RE_TRANSLATE_1 (p1_ch)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6726 != RE_TRANSLATE_1 (p2_ch))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
6727 return 1;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6728 INC_IBYTEPTR_FMT (p1, fmt);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 826
diff changeset
6729 INC_IBYTEPTR_FMT (p2, fmt);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
6730 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
6731 #else /* not MULE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6732 while (len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6733 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6734 if (RE_TRANSLATE_1 (*p1++) != RE_TRANSLATE_1 (*p2++)) return 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6735 len--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6736 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
6737 #endif /* MULE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6738 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6739 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6740
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6741 /* Entry points for GNU code. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6742
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6743 /* re_compile_pattern is the GNU regular expression compiler: it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6744 compiles PATTERN (of length SIZE) and puts the result in BUFP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6745 Returns 0 if the pattern was valid, otherwise an error string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6746
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6747 Assumes the `allocated' (and perhaps `buffer') and `translate' fields
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6748 are set in BUFP on entry.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6749
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6750 We call regex_compile to do the actual compilation. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6751
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6752 const char *
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6753 re_compile_pattern (const char *pattern, int length,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6754 struct re_pattern_buffer *bufp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6755 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6756 reg_errcode_t ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6757
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6758 /* 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
6759 (and at least one extra will be -1). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6760 bufp->regs_allocated = REGS_UNALLOCATED;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6761
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6762 /* And GNU code determines whether or not to get register information
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6763 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
6764 setting no_sub. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6765 bufp->no_sub = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6766
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6767 /* Match anchors at newline. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6768 bufp->newline_anchor = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6769
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6770 ret = regex_compile ((unsigned char *) pattern, length, re_syntax_options,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6771 bufp);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6772
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6773 if (!ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6774 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6775 return gettext (re_error_msgid[(int) ret]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6776 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6777
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6778 /* 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
6779 them unless specifically requested. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6780
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6781 #ifdef _REGEX_RE_COMP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6782
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6783 /* BSD has one and only one pattern buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6784 static struct re_pattern_buffer re_comp_buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6785
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6786 char *
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6787 re_comp (const char *s)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6788 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6789 reg_errcode_t ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6790
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6791 if (!s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6792 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6793 if (!re_comp_buf.buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6794 return gettext ("No previous regular expression");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6795 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6796 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6797
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6798 if (!re_comp_buf.buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6799 {
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6800 re_comp_buf.buffer = (unsigned char *) xmalloc (200);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6801 if (re_comp_buf.buffer == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6802 return gettext (re_error_msgid[(int) REG_ESPACE]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6803 re_comp_buf.allocated = 200;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6804
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6805 re_comp_buf.fastmap = (char *) xmalloc (1 << BYTEWIDTH);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6806 if (re_comp_buf.fastmap == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6807 return gettext (re_error_msgid[(int) REG_ESPACE]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6808 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6809
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6810 /* Since `re_exec' always passes NULL for the `regs' argument, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6811 don't need to initialize the pattern buffer fields which affect it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6812
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6813 /* Match anchors at newlines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6814 re_comp_buf.newline_anchor = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6815
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6816 ret = regex_compile ((unsigned char *)s, strlen (s), re_syntax_options,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
6817 &re_comp_buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6818
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6819 if (!ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6820 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6821
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6822 /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6823 return (char *) gettext (re_error_msgid[(int) ret]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6824 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6825
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6826
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6827 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6828 re_exec (const char *s)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6829 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6830 const int len = strlen (s);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6831 return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6832 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
6833 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6834 #endif /* _REGEX_RE_COMP */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6835
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6836 /* POSIX.2 functions. Don't define these for Emacs. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6837
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6838 #ifndef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6839
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6840 /* regcomp takes a regular expression as a string and compiles it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6841
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6842 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
6843 since POSIX says we shouldn't. Thus, we set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6844
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6845 `buffer' to the compiled pattern;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6846 `used' to the length of the compiled pattern;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6847 `syntax' to RE_SYNTAX_POSIX_EXTENDED if the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6848 REG_EXTENDED bit in CFLAGS is set; otherwise, to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6849 RE_SYNTAX_POSIX_BASIC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6850 `newline_anchor' to REG_NEWLINE being set in CFLAGS;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6851 `fastmap' and `fastmap_accurate' to zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6852 `re_nsub' to the number of subexpressions in PATTERN.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
6853 (non-shy of course. POSIX probably doesn't know about
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
6854 shy ones, and in any case they should be invisible.)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6855
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6856 PATTERN is the address of the pattern string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6857
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6858 CFLAGS is a series of bits which affect compilation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6859
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6860 If REG_EXTENDED is set, we use POSIX extended syntax; otherwise, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6861 use POSIX basic syntax.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6863 If REG_NEWLINE is set, then . and [^...] don't match newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6864 Also, regexec will try a match beginning after every newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6865
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6866 If REG_ICASE is set, then we considers upper- and lowercase
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6867 versions of letters to be equivalent when matching.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6868
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6869 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
6870 routine will report only success or failure, and nothing about the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6871 registers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6872
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6873 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
6874 the return codes and their meanings.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6875
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6876 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6877 regcomp (regex_t *preg, const char *pattern, int cflags)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6878 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6879 reg_errcode_t ret;
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
6880 unsigned int syntax
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6881 = (cflags & REG_EXTENDED) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6882 RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6883
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6884 /* regex_compile will allocate the space for the compiled pattern. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6885 preg->buffer = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6886 preg->allocated = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6887 preg->used = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6888
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6889 /* Don't bother to use a fastmap when searching. This simplifies the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6890 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
6891 characters after newlines into the fastmap. This way, we just try
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6892 every character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6893 preg->fastmap = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6894
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6895 if (cflags & REG_ICASE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6896 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
6897 int i;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6898
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1028
diff changeset
6899 preg->translate = (char *) xmalloc (CHAR_SET_SIZE);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6900 if (preg->translate == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6901 return (int) REG_ESPACE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6902
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6903 /* Map uppercase characters to corresponding lowercase ones. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6904 for (i = 0; i < CHAR_SET_SIZE; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6905 preg->translate[i] = ISUPPER (i) ? tolower (i) : i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6906 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6907 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6908 preg->translate = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6909
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6910 /* If REG_NEWLINE is set, newlines are treated differently. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6911 if (cflags & REG_NEWLINE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6912 { /* REG_NEWLINE implies neither . nor [^...] match newline. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6913 syntax &= ~RE_DOT_NEWLINE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6914 syntax |= RE_HAT_LISTS_NOT_NEWLINE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6915 /* It also changes the matching behavior. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6916 preg->newline_anchor = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6917 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6918 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6919 preg->newline_anchor = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6920
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6921 preg->no_sub = !!(cflags & REG_NOSUB);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6922
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6923 /* POSIX says a null character in the pattern terminates it, so we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6924 can use strlen here in compiling the pattern. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
6925 ret = regex_compile ((unsigned char *) pattern, strlen (pattern), syntax, preg);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6926
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6927 /* POSIX doesn't distinguish between an unmatched open-group and an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6928 unmatched close-group: both are REG_EPAREN. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6929 if (ret == REG_ERPAREN) ret = REG_EPAREN;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6930
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6931 return (int) ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6932 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6933
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6934
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6935 /* regexec searches for a given pattern, specified by PREG, in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6936 string STRING.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6937
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6938 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
6939 `regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6940 least NMATCH elements, and we set them to the offsets of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6941 corresponding matched substrings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6942
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6943 EFLAGS specifies `execution flags' which affect matching: if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6944 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
6945 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
6946
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6947 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
6948
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6949 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6950 regexec (const regex_t *preg, const char *string, size_t nmatch,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6951 regmatch_t pmatch[], int eflags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6952 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6953 int ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6954 struct re_registers regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6955 regex_t private_preg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6956 int len = strlen (string);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 458
diff changeset
6957 re_bool want_reg_info = !preg->no_sub && nmatch > 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6958
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6959 private_preg = *preg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6960
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6961 private_preg.not_bol = !!(eflags & REG_NOTBOL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6962 private_preg.not_eol = !!(eflags & REG_NOTEOL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6963
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6964 /* The user has told us exactly how many registers to return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6965 information about, via `nmatch'. We have to pass that on to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6966 matching routines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6967 private_preg.regs_allocated = REGS_FIXED;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6968
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6969 if (want_reg_info)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6970 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
6971 regs.num_regs = (int) nmatch;
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
6972 regs.start = TALLOC ((int) nmatch, regoff_t);
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
6973 regs.end = TALLOC ((int) nmatch, regoff_t);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6974 if (regs.start == NULL || regs.end == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6975 return (int) REG_NOMATCH;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6976 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6977
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6978 /* Perform the searching operation. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6979 ret = re_search (&private_preg, string, len,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6980 /* start: */ 0, /* range: */ len,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6981 want_reg_info ? &regs : (struct re_registers *) 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6982
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6983 /* Copy the register information to the POSIX structure. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6984 if (want_reg_info)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6985 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6986 if (ret >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6987 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
6988 int r;
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
6989
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
6990 for (r = 0; r < (int) nmatch; r++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6991 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6992 pmatch[r].rm_so = regs.start[r];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6993 pmatch[r].rm_eo = regs.end[r];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6994 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6995 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6996
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6997 /* If we needed the temporary register info, free the space now. */
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4832
diff changeset
6998 xfree (regs.start);
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4832
diff changeset
6999 xfree (regs.end);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7000 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7001
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7002 /* We want zero return to mean success, unlike `re_search'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7003 return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7004 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7005
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7006
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7007 /* Returns a message corresponding to an error code, ERRCODE, returned
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7008 from either regcomp or regexec. We don't use PREG here. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7009
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7010 size_t
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2201
diff changeset
7011 regerror (int errcode, const regex_t *UNUSED (preg), char *errbuf,
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
7012 size_t errbuf_size)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7013 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
7014 const char *msg;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 648
diff changeset
7015 Bytecount msg_size;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7016
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7017 if (errcode < 0
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
7018 || errcode >= (int) (sizeof (re_error_msgid) /
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
7019 sizeof (re_error_msgid[0])))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7020 /* 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
7021 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
7022 code generates an invalid error code, then the program has a bug.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7023 Dump core so we can fix it. */
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2421
diff changeset
7024 ABORT ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7025
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7026 msg = gettext (re_error_msgid[errcode]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7027
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7028 msg_size = strlen (msg) + 1; /* Includes the null. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7029
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7030 if (errbuf_size != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7031 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 648
diff changeset
7032 if (msg_size > (Bytecount) errbuf_size)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7033 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7034 strncpy (errbuf, msg, errbuf_size - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7035 errbuf[errbuf_size - 1] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7036 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7037 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7038 strcpy (errbuf, msg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7039 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7040
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 551
diff changeset
7041 return (size_t) msg_size;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7042 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7043
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7044
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7045 /* Free dynamically allocated space used by PREG. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7046
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7047 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7048 regfree (regex_t *preg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7049 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7050 if (preg->buffer != NULL)
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4832
diff changeset
7051 xfree (preg->buffer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7052 preg->buffer = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7053
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7054 preg->allocated = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7055 preg->used = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7056
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7057 if (preg->fastmap != NULL)
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4832
diff changeset
7058 xfree (preg->fastmap);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7059 preg->fastmap = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7060 preg->fastmap_accurate = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7061
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7062 if (preg->translate != NULL)
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4832
diff changeset
7063 xfree (preg->translate);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7064 preg->translate = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7065 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7066
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7067 #endif /* not emacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7068