annotate src/search.c @ 831:5d09ddada9ae

[xemacs-hg @ 2002-05-09 07:15:20 by ben] fix two bugs noted by Steve doprnt.c: Use make_int() not make_char() when error about bad charval, or abort will occur. extents.c: Loop over children, not ourself -- avoid infinite loop. lisp-disunion.h, lisp-union.h: Rename make_char() to make_char_1 for error-checking purposes. lread.c: Syntax error if escape is outside of ISO-8859-1 range. Remove hopelessly broken (and unworkable) FSF_KEYS code. mule-coding.c, search.c: Spacing changes. text.h: New make_char() -- verify that the char value is legal.
author ben
date Thu, 09 May 2002 07:16:38 +0000
parents 6728e641994e
children e7ee5f8bde58
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 /* String search routines for XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1987, 1992-1995 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
4 Copyright (C) 2001, 2002 Ben Wing.
428
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 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 /* Synched up with: FSF 19.29, except for region-cache stuff. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 /* Hacked on for Mule by Ben Wing, December 1994 and August 1995. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
27 /* This file has been Mule-ized. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 #include "insdel.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #include "opaque.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #ifdef REGION_CACHE_NEEDS_WORK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 #include "region-cache.h"
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 #include "syntax.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 #include <sys/types.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 #include "regex.h"
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
42 #include "casetab.h"
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
43 #include "chartab.h"
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
44
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
45 #define TRANSLATE(table, pos) \
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
46 (!NILP (table) ? TRT_TABLE_OF (table, (Emchar) pos) : pos)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 #define REGEXP_CACHE_SIZE 20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 /* If the regexp is non-nil, then the buffer contains the compiled form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 of that regexp, suitable for searching. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
52 struct regexp_cache
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
53 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 struct regexp_cache *next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 Lisp_Object regexp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 struct re_pattern_buffer buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 char fastmap[0400];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 /* Nonzero means regexp was compiled to do full POSIX backtracking. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 char posix;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 /* The instances of that struct. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 static struct regexp_cache searchbufs[REGEXP_CACHE_SIZE];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 /* The head of the linked list; points to the most recently used buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 static struct regexp_cache *searchbuf_head;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 /* Every call to re_match, etc., must pass &search_regs as the regs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 argument unless you can show it is unnecessary (i.e., if re_match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 is certainly going to be called again before region-around-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 can be called).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 Since the registers are now dynamically allocated, we need to make
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 sure not to refer to the Nth register before checking that it has
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 been allocated by checking search_regs.num_regs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 The regex code keeps track of whether it has allocated the search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 buffer using bits in the re_pattern_buffer. This means that whenever
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 you compile a new pattern, it completely forgets whether it has
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 allocated any registers, and will allocate new registers the next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 time you call a searching or matching function. Therefore, we need
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 to call re_set_registers after compiling a new pattern or after
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 setting the match registers, so that the regex functions will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 able to free or re-allocate it properly. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 /* Note: things get trickier under Mule because the values returned from
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
88 the regexp routines are in Bytebpos's but we need them to be in Charbpos's.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 We take the easy way out for the moment and just convert them immediately.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 We could be more clever by not converting them until necessary, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 that gets real ugly real fast since the buffer might have changed and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 the positions might be out of sync or out of range.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 static struct re_registers search_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 /* The buffer in which the last search was performed, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 Qt if the last search was done in a string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 Qnil if no searching has been done yet. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 static Lisp_Object last_thing_searched;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 /* error condition signalled when regexp compile_pattern fails */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 Lisp_Object Qinvalid_regexp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 /* Regular expressions used in forward/backward-word */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 Lisp_Object Vforward_word_regexp, Vbackward_word_regexp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107
507
167135c7a7ae [xemacs-hg @ 2001-05-05 10:10:36 by martinb]
martinb
parents: 502
diff changeset
108 Fixnum warn_about_possibly_incompatible_back_references;
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
109
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 /* range table for use with skip_chars. Only needed for Mule. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 Lisp_Object Vskip_chars_range_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
113 static void set_search_regs (struct buffer *buf, Charbpos beg, Charcount len);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 static void save_search_regs (void);
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
115 static Charbpos simple_search (struct buffer *buf, Intbyte *base_pat,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
116 Bytecount len, Bytebpos pos, Bytebpos lim,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
117 EMACS_INT n, Lisp_Object trt);
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
118 static Charbpos boyer_moore (struct buffer *buf, Intbyte *base_pat,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
119 Bytecount len, Bytebpos pos, Bytebpos lim,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
120 EMACS_INT n, Lisp_Object trt,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
121 Lisp_Object inverse_trt, int charset_base);
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
122 static Charbpos search_buffer (struct buffer *buf, Lisp_Object str,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
123 Charbpos charbpos, Charbpos buflim, EMACS_INT n,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
124 int RE, Lisp_Object trt,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
125 Lisp_Object inverse_trt, int posix);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
126
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 matcher_overflow (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 507
diff changeset
130 stack_overflow ("Stack overflow in regexp matcher", Qunbound);
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 /* Compile a regexp and signal a Lisp error if anything goes wrong.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 PATTERN is the pattern to compile.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 CP is the place to put the result.
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
136 TRANSLATE is a translation table for ignoring case, or Qnil for none.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 REGP is the structure that says where to store the "register"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 values that will result from matching this pattern.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 If it is 0, we should compile the pattern not to record any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 subexpression bounds.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 POSIX is nonzero if we want full backtracking (POSIX style)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 for this pattern. 0 means backtrack only enough to get a valid match. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
146 struct re_registers *regp, Lisp_Object translate,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
147 int posix, Error_Behavior errb)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
149 const char *val;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 reg_syntax_t old;
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 cp->regexp = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 cp->buf.translate = translate;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 cp->posix = posix;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 old = re_set_syntax (RE_SYNTAX_EMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 | (posix ? 0 : RE_NO_POSIX_BACKTRACKING));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
157 val = (const char *)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 re_compile_pattern ((char *) XSTRING_DATA (pattern),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 XSTRING_LENGTH (pattern), &cp->buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 re_set_syntax (old);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 if (val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 507
diff changeset
163 maybe_signal_error (Qinvalid_regexp, 0, build_string (val),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 Qsearch, errb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 cp->regexp = Fcopy_sequence (pattern);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 /* Compile a regexp if necessary, but first check to see if there's one in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 the cache.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 PATTERN is the pattern to compile.
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
175 TRANSLATE is a translation table for ignoring case, or Qnil for none.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 REGP is the structure that says where to store the "register"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 values that will result from matching this pattern.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 If it is 0, we should compile the pattern not to record any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 subexpression bounds.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 POSIX is nonzero if we want full backtracking (POSIX style)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 for this pattern. 0 means backtrack only enough to get a valid match. */
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 struct re_pattern_buffer *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 compile_pattern (Lisp_Object pattern, struct re_registers *regp,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
185 Lisp_Object translate, Lisp_Object searchobj,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
186 struct buffer *searchbuf, int posix, Error_Behavior errb)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 struct regexp_cache *cp, **cpp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 for (cpp = &searchbuf_head; ; cpp = &cp->next)
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 cp = *cpp;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
193 /* &&#### once we fix up the fastmap code in regex.c for 8-bit-fixed,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
194 we need to record and compare the buffer and format, since the
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
195 fastmap will reflect the state of the buffer -- and things get
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
196 more complicated if the buffer has changed formats or (esp.) has
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
197 kept the format but changed its interpretation! may need to have
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
198 the code that changes the interpretation go through and invalidate
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
199 cache entries for that buffer. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 if (!NILP (Fstring_equal (cp->regexp, pattern))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
201 && EQ (cp->buf.translate, translate)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 && cp->posix == posix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 /* If we're at the end of the cache, compile into the last cell. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 if (cp->next == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
208 if (!compile_pattern_1 (cp, pattern, regp, translate,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
209 posix, errb))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 /* When we get here, cp (aka *cpp) contains the compiled pattern,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 either because we found it in the cache or because we just compiled it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 Move it to the front of the queue to mark it as most recently used. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 *cpp = cp->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 cp->next = searchbuf_head;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 searchbuf_head = cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 /* Advise the searching functions about the space we have allocated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 for register data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 if (regp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 re_set_registers (&cp->buf, regp, regp->num_regs, regp->start, regp->end);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 return &cp->buf;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 /* Error condition used for failing searches */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 Lisp_Object Qsearch_failed;
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 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 signal_failure (Lisp_Object arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
236 for (;;)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
237 Fsignal (Qsearch_failed, list1 (arg));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
238 return Qnil; /* Not reached. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
241 /* Convert the search registers from Bytebpos's to Charbpos's. Needs to be
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 done after each regexp match that uses the search regs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 We could get a potential speedup by not converting the search registers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 until it's really necessary, e.g. when match-data or replace-match is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 called. However, this complexifies the code a lot (e.g. the buffer
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
247 could have changed and the Bytebpos's stored might be invalid) and is
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 probably not a great time-saver. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 fixup_search_regs_for_buffer (struct buffer *buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 int num_regs = search_regs.num_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 for (i = 0; i < num_regs; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 if (search_regs.start[i] >= 0)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
259 search_regs.start[i] = bytebpos_to_charbpos (buf,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
260 search_regs.start[i]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 if (search_regs.end[i] >= 0)
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
262 search_regs.end[i] = bytebpos_to_charbpos (buf, search_regs.end[i]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 /* Similar but for strings. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 fixup_search_regs_for_string (Lisp_Object string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 int num_regs = search_regs.num_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 /* #### bytecount_to_charcount() is not that efficient. This function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 could be faster if it did its own conversion (using INC_CHARPTR()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 and such), because the register ends are likely to be somewhat ordered.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (Even if not, you could sort them.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 Think about this if this function is a time hog, which it's probably
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 not. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 for (i = 0; i < num_regs; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 if (search_regs.start[i] > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 search_regs.start[i] =
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
285 string_index_byte_to_char (string, search_regs.start[i]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 if (search_regs.end[i] > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 search_regs.end[i] =
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
290 string_index_byte_to_char (string, search_regs.end[i]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 looking_at_1 (Lisp_Object string, struct buffer *buf, int posix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 Lisp_Object val;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
300 Bytebpos p1, p2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 Bytecount s1, s2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 REGISTER int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 struct re_pattern_buffer *bufp;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
304 struct syntax_cache scache_struct;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
305 struct syntax_cache *scache = &scache_struct;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
306
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 if (running_asynch_code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 save_search_regs ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 CHECK_STRING (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 bufp = compile_pattern (string, &search_regs,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 (!NILP (buf->case_fold_search)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
313 ? XCASE_TABLE_DOWNCASE (buf->case_table) : Qnil),
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
314 wrap_buffer (buf), buf, posix, ERROR_ME);
428
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 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 /* Get pointers and sizes of the two strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 that make up the visible portion of the buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
321 p1 = BYTE_BUF_BEGV (buf);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
322 p2 = BYTE_BUF_CEILING_OF (buf, p1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 s1 = p2 - p1;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
324 s2 = BYTE_BUF_ZV (buf) - p2;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
325
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
326 /* By making the regex object, regex buffer, and syntax cache arguments
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
327 to re_{search,match}{,_2}, we've removed the need to do nasty things
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
328 to deal with regex reentrancy. (See stack trace in signal.c for proof
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
329 that this can happen.)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
330
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
331 #### there is still a potential problem with the regex cache --
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
332 the compiled regex could be overwritten. we'd need 20-fold
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
333 reentrancy, though. Fix this. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
334
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
335 i = re_match_2 (bufp, (char *) BYTE_BUF_BYTE_ADDRESS (buf, p1),
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
336 s1, (char *) BYTE_BUF_BYTE_ADDRESS (buf, p2), s2,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
337 BYTE_BUF_PT (buf) - BYTE_BUF_BEGV (buf), &search_regs,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
338 BYTE_BUF_ZV (buf) - BYTE_BUF_BEGV (buf), wrap_buffer (buf),
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
339 buf, scache);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 if (i == -2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 matcher_overflow ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 val = (0 <= i ? Qt : Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 if (NILP (val))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
346 return Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 int num_regs = search_regs.num_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 for (i = 0; i < num_regs; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 if (search_regs.start[i] >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
352 search_regs.start[i] += BYTE_BUF_BEGV (buf);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
353 search_regs.end[i] += BYTE_BUF_BEGV (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 }
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
356 last_thing_searched = wrap_buffer (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 fixup_search_regs_for_buffer (buf);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
358 return val;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 }
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 DEFUN ("looking-at", Flooking_at, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 Return t if text after point matches regular expression REGEXP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 This function modifies the match data that `match-beginning',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 `match-end' and `match-data' access; save and restore the match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 data if you want to preserve them.
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 Optional argument BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 (regexp, buffer))
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 return looking_at_1 (regexp, decode_buffer (buffer, 0), 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 DEFUN ("posix-looking-at", Fposix_looking_at, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 Return t if text after point matches regular expression REGEXP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 Find the longest match, in accord with Posix regular expression rules.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 This function modifies the match data that `match-beginning',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 `match-end' and `match-data' access; save and restore the match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 data if you want to preserve them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 Optional argument BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 (regexp, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
385 return looking_at_1 (regexp, decode_buffer (buffer, 0), 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 struct buffer *buf, int posix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 Bytecount val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 Charcount s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 struct re_pattern_buffer *bufp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 if (running_asynch_code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 save_search_regs ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 CHECK_STRING (regexp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 CHECK_STRING (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 if (NILP (start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 s = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
406 Charcount len = string_char_length (string);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 CHECK_INT (start);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 s = XINT (start);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 if (s < 0 && -s <= len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 s = len + s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 else if (0 > s || s > len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 args_out_of_range (string, start);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 bufp = compile_pattern (regexp, &search_regs,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 (!NILP (buf->case_fold_search)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
419 ? XCASE_TABLE_DOWNCASE (buf->case_table) : Qnil),
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
420 string, buf, 0, ERROR_ME);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 {
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
423 Bytecount bis = string_index_char_to_byte (string, s);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
424 struct syntax_cache scache_struct;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
425 struct syntax_cache *scache = &scache_struct;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
426
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
427 /* By making the regex object, regex buffer, and syntax cache arguments
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
428 to re_{search,match}{,_2}, we've removed the need to do nasty things
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
429 to deal with regex reentrancy. (See stack trace in signal.c for proof
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
430 that this can happen.)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
431
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
432 #### there is still a potential problem with the regex cache --
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
433 the compiled regex could be overwritten. we'd need 20-fold
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
434 reentrancy, though. Fix this. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
435
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 val = re_search (bufp, (char *) XSTRING_DATA (string),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 XSTRING_LENGTH (string), bis,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 XSTRING_LENGTH (string) - bis,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
439 &search_regs, string, buf, scache);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 if (val == -2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 matcher_overflow ();
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
443 if (val < 0) return Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 last_thing_searched = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 fixup_search_regs_for_string (string);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
446 return make_int (string_index_byte_to_char (string, val));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 DEFUN ("string-match", Fstring_match, 2, 4, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 Return index of start of first match for REGEXP in STRING, or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 If third arg START is non-nil, start search at that index in STRING.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 For index of first char beyond the match, do (match-end 0).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 `match-end' and `match-beginning' also give indices of substrings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 matched by parenthesis constructs in the pattern.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
456 Optional arg BUFFER controls how case folding and syntax and category
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
457 lookup is done (according to the value of `case-fold-search' in that buffer
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
458 and that buffer's case tables, syntax tables, and category table). If nil
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
459 or unspecified, it defaults *NOT* to the current buffer but instead:
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
460
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
461 -- the value of `case-fold-search' in the current buffer is still respected
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
462 because of idioms like
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
463
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
464 (let ((case-fold-search nil))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
465 (string-match "^foo.*bar" string))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
466
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
467 but the case, syntax, and category tables come from the standard tables,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
468 which are accessed through functions `default-{case,syntax,category}-table' and serve as the parents of the
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
469 tables in particular buffer
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
470
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 (regexp, string, start, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
474 /* &&#### implement new interp for buffer arg; check code to see if it
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
475 makes more sense than prev */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 return string_match_1 (regexp, string, start, decode_buffer (buffer, 0), 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 DEFUN ("posix-string-match", Fposix_string_match, 2, 4, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 Return index of start of first match for REGEXP in STRING, or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 Find the longest match, in accord with Posix regular expression rules.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 If third arg START is non-nil, start search at that index in STRING.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 For index of first char beyond the match, do (match-end 0).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 `match-end' and `match-beginning' also give indices of substrings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 matched by parenthesis constructs in the pattern.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 Optional arg BUFFER controls how case folding is done (according to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 the value of `case-fold-search' in that buffer and that buffer's case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 tables) and defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 (regexp, string, start, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 return string_match_1 (regexp, string, start, decode_buffer (buffer, 0), 1);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 /* Match REGEXP against STRING, searching all of STRING,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 and return the index of the match, or negative on failure.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 This does not clobber the match data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 Bytecount
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
501 fast_string_match (Lisp_Object regexp, const Intbyte *nonreloc,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 Lisp_Object reloc, Bytecount offset,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 Bytecount length, int case_fold_search,
578
190b164ddcac [xemacs-hg @ 2001-05-25 11:26:50 by ben]
ben
parents: 563
diff changeset
504 Error_Behavior errb, int no_quit)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 Bytecount val;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
507 Intbyte *newnonreloc = (Intbyte *) nonreloc;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 struct re_pattern_buffer *bufp;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
509 struct syntax_cache scache_struct;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
510 struct syntax_cache *scache = &scache_struct;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 bufp = compile_pattern (regexp, 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 (case_fold_search
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
514 ? XCASE_TABLE_DOWNCASE (Vstandard_case_table)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
515 : Qnil),
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
516 reloc, 0, 0, errb);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 if (!bufp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 return -1; /* will only do this when errb != ERROR_ME */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 if (!no_quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 no_quit_in_re_search = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 fixup_internal_substring (nonreloc, reloc, offset, &length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
526 /* Don't need to protect against GC inside of re_search() due to QUIT;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
527 QUIT is GC-inhibited. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 if (!NILP (reloc))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
529 newnonreloc = XSTRING_DATA (reloc);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
530
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
531 /* By making the regex object, regex buffer, and syntax cache arguments
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
532 to re_{search,match}{,_2}, we've removed the need to do nasty things
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
533 to deal with regex reentrancy. (See stack trace in signal.c for proof
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
534 that this can happen.)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
535
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
536 #### there is still a potential problem with the regex cache --
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
537 the compiled regex could be overwritten. we'd need 20-fold
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
538 reentrancy, though. Fix this. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
539
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 val = re_search (bufp, (char *) newnonreloc + offset, length, 0,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
541 length, 0, reloc, 0, scache);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 no_quit_in_re_search = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 return val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 Bytecount
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 fast_lisp_string_match (Lisp_Object regex, Lisp_Object string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 return fast_string_match (regex, 0, string, 0, -1, 0, ERROR_ME, 0);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 #ifdef REGION_CACHE_NEEDS_WORK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 /* The newline cache: remembering which sections of text have no newlines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 /* If the user has requested newline caching, make sure it's on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 Otherwise, make sure it's off.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 This is our cheezy way of associating an action with the change of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 state of a buffer-local variable. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 newline_cache_on_off (struct buffer *buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 if (NILP (buf->cache_long_line_scans))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 /* It should be off. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 if (buf->newline_cache)
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 free_region_cache (buf->newline_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 buf->newline_cache = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 }
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 /* It should be on. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 if (buf->newline_cache == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 buf->newline_cache = new_region_cache ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 #endif
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 /* Search in BUF for COUNT instances of the character TARGET between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 START and END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 If COUNT is positive, search forwards; END must be >= START.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 If COUNT is negative, search backwards for the -COUNTth instance;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 END must be <= START.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 If COUNT is zero, do anything you please; run rogue, for all I care.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 If END is zero, use BEGV or ZV instead, as appropriate for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 direction indicated by COUNT.
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 If we find COUNT instances, set *SHORTAGE to zero, and return the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 position after the COUNTth match. Note that for reverse motion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 this is not the same as the usual convention for Emacs motion commands.
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 If we don't find COUNT instances before reaching END, set *SHORTAGE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 to the number of TARGETs left unfound, and return END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 If ALLOW_QUIT is non-zero, call QUIT periodically. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
602 static Bytebpos
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
603 byte_scan_buffer (struct buffer *buf, Emchar target, Bytebpos st, Bytebpos en,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 EMACS_INT count, EMACS_INT *shortage, int allow_quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
606 Bytebpos lim = en > 0 ? en :
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
607 ((count > 0) ? BYTE_BUF_ZV (buf) : BYTE_BUF_BEGV (buf));
428
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 /* #### newline cache stuff in this function not yet ported */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 assert (count != 0);
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 if (shortage)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 *shortage = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 if (count > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 #ifdef MULE
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
618 Internal_Format fmt = buf->text->format;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
619 /* Check for char that's unrepresentable in the buffer -- it
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
620 certainly can't be there. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
621 if (!emchar_fits_in_format (target, fmt, wrap_buffer (buf)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
623 *shortage = count;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
624 return lim;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
625 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
626 /* Due to the Mule representation of characters in a buffer, we can
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
627 simply search for characters in the range 0 - 127 directly; for
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
628 8-bit-fixed, we can do this for all characters. In other cases,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
629 we do it the "hard" way. Note that this way works for all
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
630 characters and all formats, but the other way is faster. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
631 else if (! (fmt == FORMAT_8_BIT_FIXED ||
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
632 (fmt == FORMAT_DEFAULT && emchar_ascii_p (target))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
633 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
634 Raw_Emchar raw = emchar_to_raw (target, fmt, wrap_buffer (buf));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 while (st < lim && count > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
637 if (BYTE_BUF_FETCH_CHAR_RAW (buf, st) == raw)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 count--;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
639 INC_BYTEBPOS (buf, st);
428
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
645 Raw_Emchar raw = emchar_to_raw (target, fmt, wrap_buffer (buf));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 while (st < lim && count > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
648 Bytebpos ceil;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
649 Intbyte *bufptr;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
651 ceil = BYTE_BUF_CEILING_OF (buf, st);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 ceil = min (lim, ceil);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
653 bufptr = (Intbyte *) memchr (BYTE_BUF_BYTE_ADDRESS (buf, st),
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
654 raw, ceil - st);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 if (bufptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 count--;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
658 st = BYTE_BUF_PTR_BYTE_POS (buf, bufptr) + 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 st = ceil;
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 if (shortage)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 *shortage = count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 if (allow_quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 return st;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 #ifdef MULE
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
674 Internal_Format fmt = buf->text->format;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
675 /* Check for char that's unrepresentable in the buffer -- it
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
676 certainly can't be there. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
677 if (!emchar_fits_in_format (target, fmt, wrap_buffer (buf)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
679 *shortage = -count;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
680 return lim;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
681 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
682 else if (! (fmt == FORMAT_8_BIT_FIXED ||
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
683 (fmt == FORMAT_DEFAULT && emchar_ascii_p (target))))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
684 {
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
685 Raw_Emchar raw = emchar_to_raw (target, fmt, wrap_buffer (buf));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 while (st > lim && count < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
688 DEC_BYTEBPOS (buf, st);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
689 if (BYTE_BUF_FETCH_CHAR_RAW (buf, st) == raw)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 count++;
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
696 Raw_Emchar raw = emchar_to_raw (target, fmt, wrap_buffer (buf));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 while (st > lim && count < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
699 Bytebpos floor;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
700 Intbyte *bufptr;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
701 Intbyte *floorptr;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
703 floor = BYTE_BUF_FLOOR_OF (buf, st);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 floor = max (lim, floor);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 /* No memrchr() ... */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
706 bufptr = BYTE_BUF_BYTE_ADDRESS_BEFORE (buf, st);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
707 floorptr = BYTE_BUF_BYTE_ADDRESS (buf, floor);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 while (bufptr >= floorptr)
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 st--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 /* At this point, both ST and BUFPTR refer to the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 character. When the loop terminates, ST will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 always point to the last character we tried. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
714 if (*bufptr == (Intbyte) raw)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 count++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 break;
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 bufptr--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 if (shortage)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 *shortage = -count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 if (allow_quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 if (count)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 return st;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 /* We found the character we were looking for; we have to return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 the position *after* it due to the strange way that the return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 value is defined. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
735 INC_BYTEBPOS (buf, st);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 return st;
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
741 Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
742 scan_buffer (struct buffer *buf, Emchar target, Charbpos start, Charbpos end,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 EMACS_INT count, EMACS_INT *shortage, int allow_quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
745 Bytebpos byte_retval;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
746 Bytebpos byte_start, byte_end;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
747
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
748 byte_start = charbpos_to_bytebpos (buf, start);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 if (end)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
750 byte_end = charbpos_to_bytebpos (buf, end);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 else
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
752 byte_end = 0;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
753 byte_retval = byte_scan_buffer (buf, target, byte_start, byte_end, count,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 shortage, allow_quit);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
755 return bytebpos_to_charbpos (buf, byte_retval);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
758 Bytebpos
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
759 byte_find_next_newline_no_quit (struct buffer *buf, Bytebpos from, int count)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
761 return byte_scan_buffer (buf, '\n', from, 0, count, 0, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
764 Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
765 find_next_newline_no_quit (struct buffer *buf, Charbpos from, int count)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 return scan_buffer (buf, '\n', from, 0, count, 0, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
770 Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
771 find_next_newline (struct buffer *buf, Charbpos from, int count)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 return scan_buffer (buf, '\n', from, 0, count, 0, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
776 Bytecount
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
777 byte_find_next_emchar_in_string (Lisp_Object str, Emchar target, Bytecount st,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 EMACS_INT count)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 {
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
780 Bytebpos lim = XSTRING_LENGTH (str) -1;
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
781 Intbyte *s = XSTRING_DATA (str);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 assert (count >= 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 /* Due to the Mule representation of characters in a buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 we can simply search for characters in the range 0 - 127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 directly. For other characters, we do it the "hard" way.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 Note that this way works for all characters but the other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 way is faster. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 if (target >= 0200)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 while (st < lim && count > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
795 if (string_emchar (str, st) == target)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 count--;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
797 INC_BYTECOUNT (s, st);
428
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 while (st < lim && count > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
805 Intbyte *bufptr = (Intbyte *) memchr (charptr_n_addr (s, st),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 (int) target, lim - st);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 if (bufptr)
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 count--;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
810 st = (Bytebpos) (bufptr - s) + 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 st = lim;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 }
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 return st;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 /* Like find_next_newline, but returns position before the newline,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 not after, and only search up to TO. This isn't just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 find_next_newline (...)-1, because you might hit TO. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
822 Charbpos
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
823 find_before_next_newline (struct buffer *buf, Charbpos from, Charbpos to,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
824 int count)
428
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 EMACS_INT shortage;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
827 Charbpos pos = scan_buffer (buf, '\n', from, to, count, &shortage, 1);
428
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 if (shortage == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 pos--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 return pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 skip_chars (struct buffer *buf, int forwardp, int syntaxp,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 Lisp_Object string, Lisp_Object lim)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
839 REGISTER Intbyte *p, *pend;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 REGISTER Emchar c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 /* We store the first 256 chars in an array here and the rest in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 a range table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 unsigned char fastmap[0400];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 int negate = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 REGISTER int i;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
846 Charbpos limit;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
847 struct syntax_cache *scache;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
848
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 if (NILP (lim))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 limit = forwardp ? BUF_ZV (buf) : BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 CHECK_INT_COERCE_MARKER (lim);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 limit = XINT (lim);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 /* In any case, don't allow scan outside bounds of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 if (limit > BUF_ZV (buf)) limit = BUF_ZV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 if (limit < BUF_BEGV (buf)) limit = BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 }
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 CHECK_STRING (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 p = XSTRING_DATA (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 pend = p + XSTRING_LENGTH (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 memset (fastmap, 0, sizeof (fastmap));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 Fclear_range_table (Vskip_chars_range_table);
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 if (p != pend && *p == '^')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 negate = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 }
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 /* Find the characters specified and set their elements of fastmap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 If syntaxp, each character counts as itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 Otherwise, handle backslashes and ranges specially */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 while (p != pend)
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 c = charptr_emchar (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 INC_CHARPTR (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 if (syntaxp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 if (c < 0400 && syntax_spec_code[c] < (unsigned char) Smax)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 fastmap[c] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 else
831
5d09ddada9ae [xemacs-hg @ 2002-05-09 07:15:20 by ben]
ben
parents: 826
diff changeset
887 invalid_argument ("Invalid syntax designator", make_char (c));
428
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 if (c == '\\')
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 (p == pend) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 c = charptr_emchar (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 INC_CHARPTR (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 if (p != pend && *p == '-')
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 Emchar cend;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 if (p == pend) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 cend = charptr_emchar (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 while (c <= cend && c < 0400)
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 fastmap[c] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 c++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 if (c <= cend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 Fput_range_table (make_int (c), make_int (cend), Qt,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 Vskip_chars_range_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 INC_CHARPTR (p);
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 if (c < 0400)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 fastmap[c] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 Fput_range_table (make_int (c), make_int (c), Qt,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 Vskip_chars_range_table);
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 if (syntaxp && fastmap['-'] != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 fastmap[' '] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 /* If ^ was the first character, complement the fastmap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 We don't complement the range table, however; we just use negate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 in the comparisons below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 if (negate)
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 578
diff changeset
933 for (i = 0; i < (int) (sizeof (fastmap)); i++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 fastmap[i] ^= 1;
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 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
937 Charbpos start_point = BUF_PT (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 if (syntaxp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
941 scache = setup_buffer_syntax_cache (buf, BUF_PT (buf),
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
942 forwardp ? 1 : -1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 /* All syntax designators are normal chars so nothing strange
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 to worry about */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 if (forwardp)
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 while (BUF_PT (buf) < limit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 && fastmap[(unsigned char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 syntax_code_spec
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
950 [(int) SYNTAX_FROM_CACHE
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
951 (scache, BUF_FETCH_CHAR (buf, BUF_PT (buf)))]])
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
952 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
953 BUF_SET_PT (buf, BUF_PT (buf) + 1);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
954 UPDATE_SYNTAX_CACHE_FORWARD (scache, BUF_PT (buf));
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
955 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 while (BUF_PT (buf) > limit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 && fastmap[(unsigned char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 syntax_code_spec
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
962 [(int) SYNTAX_FROM_CACHE
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
963 (scache,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
964 BUF_FETCH_CHAR (buf, BUF_PT (buf) - 1))]])
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
965 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
966 BUF_SET_PT (buf, BUF_PT (buf) - 1);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
967 UPDATE_SYNTAX_CACHE_BACKWARD (scache, BUF_PT (buf) - 1);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
968 }
428
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 if (forwardp)
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 while (BUF_PT (buf) < limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 Emchar ch = BUF_FETCH_CHAR (buf, BUF_PT (buf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 if ((ch < 0400) ? fastmap[ch] :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 (NILP (Fget_range_table (make_int (ch),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 Vskip_chars_range_table,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 Qnil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 == negate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 BUF_SET_PT (buf, BUF_PT (buf) + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 else
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 while (BUF_PT (buf) > limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 Emchar ch = BUF_FETCH_CHAR (buf, BUF_PT (buf) - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 if ((ch < 0400) ? fastmap[ch] :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 (NILP (Fget_range_table (make_int (ch),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 Vskip_chars_range_table,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 Qnil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 == negate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 BUF_SET_PT (buf, BUF_PT (buf) - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 else
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 return make_int (BUF_PT (buf) - start_point);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 DEFUN ("skip-chars-forward", Fskip_chars_forward, 1, 3, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1010 Move point forward, stopping before a char not in STRING, or at pos LIMIT.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 STRING is like the inside of a `[...]' in a regular expression
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 except that `]' is never special and `\\' quotes `^', `-' or `\\'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 Thus, with arg "a-zA-Z", this skips letters stopping before first nonletter.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 With arg "^a-zA-Z", skips nonletters stopping before first letter.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 Returns the distance traveled, either zero or positive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 Optional argument BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1019 (string, limit, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1021 return skip_chars (decode_buffer (buffer, 0), 1, 0, string, limit);
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 DEFUN ("skip-chars-backward", Fskip_chars_backward, 1, 3, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1025 Move point backward, stopping after a char not in STRING, or at pos LIMIT.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 See `skip-chars-forward' for details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 Returns the distance traveled, either zero or negative.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 Optional argument BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1031 (string, limit, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1033 return skip_chars (decode_buffer (buffer, 0), 0, 0, string, limit);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 DEFUN ("skip-syntax-forward", Fskip_syntax_forward, 1, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 Move point forward across chars in specified syntax classes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 SYNTAX is a string of syntax code characters.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1040 Stop before a char whose syntax is not in SYNTAX, or at position LIMIT.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 This function returns the distance traveled, either zero or positive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 Optional argument BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1046 (syntax, limit, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1048 return skip_chars (decode_buffer (buffer, 0), 1, 1, syntax, limit);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 DEFUN ("skip-syntax-backward", Fskip_syntax_backward, 1, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 Move point backward across chars in specified syntax classes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 SYNTAX is a string of syntax code characters.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1054 Stop on reaching a char whose syntax is not in SYNTAX, or at position LIMIT.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 This function returns the distance traveled, either zero or negative.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 Optional argument BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1060 (syntax, limit, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1062 return skip_chars (decode_buffer (buffer, 0), 0, 1, syntax, limit);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 /* Subroutines of Lisp buffer search functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 static Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1069 search_command (Lisp_Object string, Lisp_Object limit, Lisp_Object noerror,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 Lisp_Object count, Lisp_Object buffer, int direction,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 int RE, int posix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1073 REGISTER Charbpos np;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1074 Charbpos lim;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 EMACS_INT n = direction;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 struct buffer *buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 if (!NILP (count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 CHECK_INT (count);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 n *= XINT (count);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 }
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 buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 CHECK_STRING (string);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1086 if (NILP (limit))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 lim = n > 0 ? BUF_ZV (buf) : BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1090 CHECK_INT_COERCE_MARKER (limit);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1091 lim = XINT (limit);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 if (n > 0 ? lim < BUF_PT (buf) : lim > BUF_PT (buf))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 507
diff changeset
1093 invalid_argument ("Invalid search limit (wrong side of point)",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 507
diff changeset
1094 Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 if (lim > BUF_ZV (buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 lim = BUF_ZV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 if (lim < BUF_BEGV (buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 lim = BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 np = search_buffer (buf, string, BUF_PT (buf), lim, n, RE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 (!NILP (buf->case_fold_search)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1103 ? XCASE_TABLE_CANON (buf->case_table)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1104 : Qnil),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 (!NILP (buf->case_fold_search)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1106 ? XCASE_TABLE_EQV (buf->case_table)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1107 : Qnil), posix);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 if (np <= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1111 if (NILP (noerror))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 return signal_failure (string);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1113 if (!EQ (noerror, Qt))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 if (lim < BUF_BEGV (buf) || lim > BUF_ZV (buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 BUF_SET_PT (buf, lim);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 #if 0 /* This would be clean, but maybe programs depend on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 a value of nil here. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 np = lim;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 if (np < BUF_BEGV (buf) || np > BUF_ZV (buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 BUF_SET_PT (buf, np);
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 return make_int (np);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 trivial_regexp_p (Lisp_Object regexp)
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 Bytecount len = XSTRING_LENGTH (regexp);
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1140 Intbyte *s = XSTRING_DATA (regexp);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 while (--len >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 switch (*s++)
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 case '.': case '*': case '+': case '?': case '[': case '^': case '$':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 case '\\':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 if (--len < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 switch (*s++)
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 case '|': case '(': case ')': case '`': case '\'': case 'b':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 case 'B': case '<': case '>': case 'w': case 'W': case 's':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 case 'S': case '=':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 /* 97/2/25 jhod Added for category matches */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 case 'c': case 'C':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 case '1': case '2': case '3': case '4': case '5':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 case '6': case '7': case '8': case '9':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 }
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 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 /* Search for the n'th occurrence of STRING in BUF,
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1169 starting at position CHARBPOS and stopping at position BUFLIM,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 treating PAT as a literal string if RE is false or as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 a regular expression if RE is true.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 If N is positive, searching is forward and BUFLIM must be greater
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1174 than CHARBPOS.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 If N is negative, searching is backward and BUFLIM must be less
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1176 than CHARBPOS.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 Returns -x if only N-x occurrences found (x > 0),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 or else the position at the beginning of the Nth occurrence
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 (if searching backward) or the end (if searching forward).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 POSIX is nonzero if we want full backtracking (POSIX style)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 for this pattern. 0 means backtrack only enough to get a valid match. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1184 static Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1185 search_buffer (struct buffer *buf, Lisp_Object string, Charbpos charbpos,
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1186 Charbpos buflim, EMACS_INT n, int RE, Lisp_Object trt,
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1187 Lisp_Object inverse_trt, int posix)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 Bytecount len = XSTRING_LENGTH (string);
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1190 Intbyte *base_pat = XSTRING_DATA (string);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 REGISTER EMACS_INT i, j;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1192 Bytebpos p1, p2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 Bytecount s1, s2;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1194 Bytebpos pos, lim;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 if (running_asynch_code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 save_search_regs ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 /* Null string is found at starting position. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 if (len == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1202 set_search_regs (buf, charbpos, 0);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1203 return charbpos;
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 /* Searching 0 times means don't move. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 if (n == 0)
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1208 return charbpos;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1209
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1210 pos = charbpos_to_bytebpos (buf, charbpos);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1211 lim = charbpos_to_bytebpos (buf, buflim);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 if (RE && !trivial_regexp_p (string))
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 struct re_pattern_buffer *bufp;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1215
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1216 bufp = compile_pattern (string, &search_regs, trt,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1217 wrap_buffer (buf), buf, posix, ERROR_ME);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 /* Get pointers and sizes of the two strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 that make up the visible portion of the buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1222 p1 = BYTE_BUF_BEGV (buf);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1223 p2 = BYTE_BUF_CEILING_OF (buf, p1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 s1 = p2 - p1;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1225 s2 = BYTE_BUF_ZV (buf) - p2;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1226
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1227 while (n != 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 Bytecount val;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1230 struct syntax_cache scache_struct;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1231 struct syntax_cache *scache = &scache_struct;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1232
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 QUIT;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1234 /* By making the regex object, regex buffer, and syntax cache
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1235 arguments to re_{search,match}{,_2}, we've removed the need to
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1236 do nasty things to deal with regex reentrancy. (See stack
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1237 trace in signal.c for proof that this can happen.)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1238
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1239 #### there is still a potential problem with the regex cache --
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1240 the compiled regex could be overwritten. we'd need 20-fold
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1241 reentrancy, though. Fix this. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1242
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 val = re_search_2 (bufp,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1244 (char *) BYTE_BUF_BYTE_ADDRESS (buf, p1), s1,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1245 (char *) BYTE_BUF_BYTE_ADDRESS (buf, p2), s2,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1246 pos - BYTE_BUF_BEGV (buf), lim - pos, &search_regs,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1247 n > 0 ? lim - BYTE_BUF_BEGV (buf) :
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1248 pos - BYTE_BUF_BEGV (buf), wrap_buffer (buf),
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1249 buf, scache);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 if (val == -2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 matcher_overflow ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 if (val >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 int num_regs = search_regs.num_regs;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1258 j = BYTE_BUF_BEGV (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 for (i = 0; i < num_regs; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 if (search_regs.start[i] >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 search_regs.start[i] += j;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 search_regs.end[i] += j;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 }
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
1265 last_thing_searched = wrap_buffer (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 /* Set pos to the new position. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1267 pos = n > 0 ? search_regs.end[0] : search_regs.start[0];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 fixup_search_regs_for_buffer (buf);
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1269 /* And charbpos too. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1270 charbpos = n > 0 ? search_regs.end[0] : search_regs.start[0];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 else
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1273 return (n > 0 ? 0 - n : n);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1274 if (n > 0) n--; else n++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 }
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1276 return charbpos;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 else /* non-RE case */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1280 int charset_base = -1;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1281 int boyer_moore_ok = 1;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1282 Intbyte *pat = 0;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1283 Intbyte *patbuf = alloca_array (Intbyte, len * MAX_EMCHAR_LEN);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1284 pat = patbuf;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1285 #ifdef MULE
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1286 /* &&#### needs some 8-bit work here */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1287 while (len > 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1288 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1289 Intbyte tmp_str[MAX_EMCHAR_LEN];
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1290 Emchar c, translated, inverse;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1291 Bytecount orig_bytelen, new_bytelen, inv_bytelen;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1292
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1293 /* If we got here and the RE flag is set, it's because
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1294 we're dealing with a regexp known to be trivial, so the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1295 backslash just quotes the next character. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1296 if (RE && *base_pat == '\\')
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1297 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1298 len--;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1299 base_pat++;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1300 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1301 c = charptr_emchar (base_pat);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1302 translated = TRANSLATE (trt, c);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1303 inverse = TRANSLATE (inverse_trt, c);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1304
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1305 orig_bytelen = charptr_emchar_len (base_pat);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1306 inv_bytelen = set_charptr_emchar (tmp_str, inverse);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1307 new_bytelen = set_charptr_emchar (tmp_str, translated);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1308
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1309 if (new_bytelen != orig_bytelen || inv_bytelen != orig_bytelen)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1310 boyer_moore_ok = 0;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1311 if (translated != c || inverse != c)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1312 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1313 /* Keep track of which character set row
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1314 contains the characters that need translation. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1315 int charset_base_code = c & ~EMCHAR_FIELD3_MASK;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1316 if (charset_base == -1)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1317 charset_base = charset_base_code;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1318 else if (charset_base != charset_base_code)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1319 /* If two different rows appear, needing translation,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1320 then we cannot use boyer_moore search. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1321 boyer_moore_ok = 0;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1322 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1323 memcpy (pat, tmp_str, new_bytelen);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1324 pat += new_bytelen;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1325 base_pat += orig_bytelen;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1326 len -= orig_bytelen;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1327 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1328 #else /* not MULE */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1329 while (--len >= 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1330 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1331 /* If we got here and the RE flag is set, it's because
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1332 we're dealing with a regexp known to be trivial, so the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1333 backslash just quotes the next character. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1334 if (RE && *base_pat == '\\')
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1335 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1336 len--;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1337 base_pat++;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1338 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1339 *pat++ = TRANSLATE (trt, *base_pat++);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1340 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1341 #endif /* MULE */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1342 len = pat - patbuf;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1343 pat = base_pat = patbuf;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1344 if (boyer_moore_ok)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1345 return boyer_moore (buf, base_pat, len, pos, lim, n,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1346 trt, inverse_trt, charset_base);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1347 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1348 return simple_search (buf, base_pat, len, pos, lim, n, trt);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1349 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1350 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1351
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1352 /* Do a simple string search N times for the string PAT, whose length is
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1353 LEN/LEN_BYTE, from buffer position POS until LIM. TRT is the
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1354 translation table.
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1355
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1356 Return the character position where the match is found.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1357 Otherwise, if M matches remained to be found, return -M.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1358
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1359 This kind of search works regardless of what is in PAT and
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1360 regardless of what is in TRT. It is used in cases where
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1361 boyer_moore cannot work. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1362
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1363 static Charbpos
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1364 simple_search (struct buffer *buf, Intbyte *base_pat, Bytecount len,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1365 Bytebpos pos, Bytebpos lim, EMACS_INT n, Lisp_Object trt)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1366 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1367 int forward = n > 0;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1368 Bytecount buf_len = 0; /* Shut up compiler. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1369
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1370 if (lim > pos)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1371 while (n > 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1373 while (1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1375 Bytecount this_len = len;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1376 Bytebpos this_pos = pos;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1377 Intbyte *p = base_pat;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1378 if (pos >= lim)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1379 goto stop;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1380
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1381 while (this_len > 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1382 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1383 Emchar pat_ch, buf_ch;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1384 Bytecount pat_len;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1385
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1386 pat_ch = charptr_emchar (p);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1387 buf_ch = BYTE_BUF_FETCH_CHAR (buf, this_pos);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1388
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1389 buf_ch = TRANSLATE (trt, buf_ch);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1390
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1391 if (buf_ch != pat_ch)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1392 break;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1393
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1394 pat_len = charptr_emchar_len (p);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1395 p += pat_len;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1396 this_len -= pat_len;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1397 INC_BYTEBPOS (buf, this_pos);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1398 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1399 if (this_len == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1401 buf_len = this_pos - pos;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1402 pos = this_pos;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1403 break;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 }
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1405 INC_BYTEBPOS (buf, pos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1407 n--;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1408 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1409 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1410 while (n < 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1411 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1412 while (1)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1413 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1414 Bytecount this_len = len;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1415 Bytebpos this_pos = pos;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1416 Intbyte *p;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1417 if (pos <= lim)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1418 goto stop;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1419 p = base_pat + len;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1420
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1421 while (this_len > 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1422 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1423 Emchar pat_ch, buf_ch;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1424
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1425 DEC_CHARPTR (p);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1426 DEC_BYTEBPOS (buf, this_pos);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1427 pat_ch = charptr_emchar (p);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1428 buf_ch = BYTE_BUF_FETCH_CHAR (buf, this_pos);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1429
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1430 buf_ch = TRANSLATE (trt, buf_ch);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1431
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1432 if (buf_ch != pat_ch)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1433 break;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1434
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1435 this_len -= charptr_emchar_len (p);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1436 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1437 if (this_len == 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1438 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1439 buf_len = pos - this_pos;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1440 pos = this_pos;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1441 break;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1442 }
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1443 DEC_BYTEBPOS (buf, pos);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1444 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1445 n++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1447 stop:
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1448 if (n == 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1449 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1450 Charbpos beg, end, retval;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1451 if (forward)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1452 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1453 beg = bytebpos_to_charbpos (buf, pos - buf_len);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1454 retval = end = bytebpos_to_charbpos (buf, pos);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1455 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1456 else
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1458 retval = beg = bytebpos_to_charbpos (buf, pos);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1459 end = bytebpos_to_charbpos (buf, pos + buf_len);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1461 set_search_regs (buf, beg, end - beg);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1462
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1463 return retval;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1464 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1465 else if (n > 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1466 return -n;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1467 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1468 return n;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1469 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1470
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1471 /* Do Boyer-Moore search N times for the string PAT,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1472 whose length is LEN/LEN_BYTE,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1473 from buffer position POS/POS_BYTE until LIM/LIM_BYTE.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1474 DIRECTION says which direction we search in.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1475 TRT and INVERSE_TRT are translation tables.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1476
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1477 This kind of search works if all the characters in PAT that have
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1478 nontrivial translation are the same aside from the last byte. This
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1479 makes it possible to translate just the last byte of a character,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1480 and do so after just a simple test of the context.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1481
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1482 If that criterion is not satisfied, do not call this function. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1483
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1484 static Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1485 boyer_moore (struct buffer *buf, Intbyte *base_pat, Bytecount len,
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1486 Bytebpos pos, Bytebpos lim, EMACS_INT n, Lisp_Object trt,
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1487 Lisp_Object inverse_trt, int charset_base)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1488 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1489 /* &&#### needs some 8-bit work here */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1490 /* #### Someone really really really needs to comment the workings
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1491 of this junk somewhat better.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1492
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1493 BTW "BM" stands for Boyer-Moore, which is one of the standard
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1494 string-searching algorithms. It's the best string-searching
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1495 algorithm out there, provided that:
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1496
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1497 a) You're not fazed by algorithm complexity. (Rabin-Karp, which
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1498 uses hashing, is much much easier to code but not as fast.)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1499 b) You can freely move backwards in the string that you're
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1500 searching through.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1501
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1502 As the comment below tries to explain (but garbles in typical
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1503 programmer-ese), the idea is that you don't have to do a
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1504 string match at every successive position in the text. For
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1505 example, let's say the pattern is "a very long string". We
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1506 compare the last character in the string (`g') with the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1507 corresponding character in the text. If it mismatches, and
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1508 it is, say, `z', then we can skip forward by the entire
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1509 length of the pattern because `z' does not occur anywhere
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1510 in the pattern. If the mismatching character does occur
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1511 in the pattern, we can usually still skip forward by more
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1512 than one: e.g. if it is `l', then we can skip forward
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1513 by the length of the substring "ong string" -- i.e. the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1514 largest end section of the pattern that does not contain
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1515 the mismatched character. So what we do is compute, for
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1516 each possible character, the distance we can skip forward
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1517 (the "stride") and use it in the string matching. This
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1518 is what the BM_tab holds. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1519 REGISTER EMACS_INT *BM_tab;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1520 EMACS_INT *BM_tab_base;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1521 REGISTER Bytecount dirlen;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1522 EMACS_INT infinity;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1523 Bytebpos limit;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1524 Bytecount stride_for_teases = 0;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1525 REGISTER EMACS_INT i, j;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1526 Intbyte *pat, *pat_end;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1527 REGISTER Intbyte *cursor, *p_limit, *ptr2;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1528 Intbyte simple_translate[0400];
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1529 REGISTER int direction = ((n > 0) ? 1 : -1);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1530 #ifdef MULE
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1531 Intbyte translate_prev_byte = 0;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1532 Intbyte translate_anteprev_byte = 0;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1533 #endif
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1534 #ifdef C_ALLOCA
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1535 EMACS_INT BM_tab_space[0400];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1536 BM_tab = &BM_tab_space[0];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1537 #else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1538 BM_tab = alloca_array (EMACS_INT, 256);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1539 #endif
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1540
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1541 /* The general approach is that we are going to maintain that we
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1542 know the first (closest to the present position, in whatever
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1543 direction we're searching) character that could possibly be
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1544 the last (furthest from present position) character of a
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1545 valid match. We advance the state of our knowledge by
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1546 looking at that character and seeing whether it indeed
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1547 matches the last character of the pattern. If it does, we
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1548 take a closer look. If it does not, we move our pointer (to
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1549 putative last characters) as far as is logically possible.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1550 This amount of movement, which I call a stride, will be the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1551 length of the pattern if the actual character appears nowhere
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1552 in the pattern, otherwise it will be the distance from the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1553 last occurrence of that character to the end of the pattern.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1554 As a coding trick, an enormous stride is coded into the table
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1555 for characters that match the last character. This allows
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1556 use of only a single test, a test for having gone past the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1557 end of the permissible match region, to test for both
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1558 possible matches (when the stride goes past the end
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1559 immediately) and failure to match (where you get nudged past
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1560 the end one stride at a time).
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1561
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1562 Here we make a "mickey mouse" BM table. The stride of the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1563 search is determined only by the last character of the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1564 putative match. If that character does not match, we will
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1565 stride the proper distance to propose a match that
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1566 superimposes it on the last instance of a character that
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1567 matches it (per trt), or misses it entirely if there is
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1568 none. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1569
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1570 dirlen = len * direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1571 infinity = dirlen - (lim + pos + len + len) * direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1572 /* Record position after the end of the pattern. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1573 pat_end = base_pat + len;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1574 if (direction < 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1575 base_pat = pat_end - 1;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1576 BM_tab_base = BM_tab;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1577 BM_tab += 0400;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1578 j = dirlen; /* to get it in a register */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1579 /* A character that does not appear in the pattern induces a
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1580 stride equal to the pattern length. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1581 while (BM_tab_base != BM_tab)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1582 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1583 *--BM_tab = j;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1584 *--BM_tab = j;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1585 *--BM_tab = j;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1586 *--BM_tab = j;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1587 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1588 /* We use this for translation, instead of TRT itself. We
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1589 fill this in to handle the characters that actually occur
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1590 in the pattern. Others don't matter anyway! */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1591 xzero (simple_translate);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1592 for (i = 0; i < 0400; i++)
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1593 simple_translate[i] = (Intbyte) i;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1594 i = 0;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1595 while (i != infinity)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1596 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1597 Intbyte *ptr = base_pat + i;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1598 i += direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1599 if (i == dirlen)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1600 i = infinity;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1601 if (!NILP (trt))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1603 #ifdef MULE
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1604 Emchar ch, untranslated;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1605 int this_translated = 1;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1606
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1607 /* Is *PTR the last byte of a character? */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1608 if (pat_end - ptr == 1 || intbyte_first_byte_p (ptr[1]))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1610 Intbyte *charstart = ptr;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1611 while (!intbyte_first_byte_p (*charstart))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1612 charstart--;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1613 untranslated = charptr_emchar (charstart);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1614 if (charset_base == (untranslated & ~EMCHAR_FIELD3_MASK))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1615 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1616 ch = TRANSLATE (trt, untranslated);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1617 if (!intbyte_first_byte_p (*ptr))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1618 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1619 translate_prev_byte = ptr[-1];
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1620 if (!intbyte_first_byte_p (translate_prev_byte))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1621 translate_anteprev_byte = ptr[-2];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1622 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1623 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1624 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1625 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1626 this_translated = 0;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1627 ch = *ptr;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1628 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1632 ch = *ptr;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1633 this_translated = 0;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1634 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1635 if (ch > 0400)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1636 j = ((unsigned char) ch | 0200);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1637 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1638 j = (unsigned char) ch;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1639
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1640 if (i == infinity)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1641 stride_for_teases = BM_tab[j];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1642 BM_tab[j] = dirlen - i;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1643 /* A translation table is accompanied by its inverse --
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1644 see comment in casetab.c. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1645 if (this_translated)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1646 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1647 Emchar starting_ch = ch;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1648 EMACS_INT starting_j = j;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1649 while (1)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1650 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1651 ch = TRANSLATE (inverse_trt, ch);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1652 if (ch > 0400)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1653 j = ((unsigned char) ch | 0200);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1654 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1655 j = (unsigned char) ch;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1656
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1657 /* For all the characters that map into CH,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1658 set up simple_translate to map the last byte
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1659 into STARTING_J. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1660 simple_translate[j] = (Intbyte) starting_j;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1661 if (ch == starting_ch)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1662 break;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1663 BM_tab[j] = dirlen - i;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1664 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1665 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1666 #else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1667 EMACS_INT k;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1668 j = *ptr;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1669 k = (j = TRANSLATE (trt, j));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1670 if (i == infinity)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1671 stride_for_teases = BM_tab[j];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1672 BM_tab[j] = dirlen - i;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1673 /* A translation table is accompanied by its inverse --
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1674 see comment in casetab.c. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1675 while ((j = TRANSLATE (inverse_trt, j)) != k)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1676 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1677 simple_translate[j] = (Intbyte) k;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 BM_tab[j] = dirlen - i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1680 #endif
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1681 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1682 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1683 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1684 j = *ptr;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1685
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1686 if (i == infinity)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1687 stride_for_teases = BM_tab[j];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1688 BM_tab[j] = dirlen - i;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1690 /* stride_for_teases tells how much to stride if we get a
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1691 match on the far character but are subsequently
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1692 disappointed, by recording what the stride would have been
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1693 for that character if the last character had been
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1694 different. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1695 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1696 infinity = dirlen - infinity;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1697 pos += dirlen - ((direction > 0) ? direction : 0);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1698 /* loop invariant - pos points at where last char (first char if
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1699 reverse) of pattern would align in a possible match. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1700 while (n != 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1701 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1702 Bytebpos tail_end;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1703 Intbyte *tail_end_ptr;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1704 /* It's been reported that some (broken) compiler thinks
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1705 that Boolean expressions in an arithmetic context are
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1706 unsigned. Using an explicit ?1:0 prevents this. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1707 if ((lim - pos - ((direction > 0) ? 1 : 0)) * direction < 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1708 return n * (0 - direction);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1709 /* First we do the part we can by pointers (maybe
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1710 nothing) */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1711 QUIT;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1712 pat = base_pat;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1713 limit = pos - dirlen + direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1714 /* XEmacs change: definitions of CEILING_OF and FLOOR_OF
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1715 have changed. See buffer.h. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1716 limit = ((direction > 0)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1717 ? BYTE_BUF_CEILING_OF (buf, limit) - 1
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1718 : BYTE_BUF_FLOOR_OF (buf, limit + 1));
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1719 /* LIMIT is now the last (not beyond-last!) value POS can
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1720 take on without hitting edge of buffer or the gap. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1721 limit = ((direction > 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1722 ? min (lim - 1, min (limit, pos + 20000))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1723 : max (lim, max (limit, pos - 20000)));
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1724 tail_end = BYTE_BUF_CEILING_OF (buf, pos);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1725 tail_end_ptr = BYTE_BUF_BYTE_ADDRESS (buf, tail_end);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1726
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1727 if ((limit - pos) * direction > 20)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1729 /* We have to be careful because the code can generate addresses
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1730 that don't point to the beginning of characters. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1731 p_limit = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, limit);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1732 ptr2 = (cursor = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, pos));
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1733 /* In this loop, pos + cursor - ptr2 is the surrogate
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1734 for pos */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1735 while (1) /* use one cursor setting as long as i can */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1736 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1737 if (direction > 0) /* worth duplicating */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1738 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1739 /* Use signed comparison if appropriate to make
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1740 cursor+infinity sure to be > p_limit.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1741 Assuming that the buffer lies in a range of
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1742 addresses that are all "positive" (as ints)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1743 or all "negative", either kind of comparison
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1744 will work as long as we don't step by
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1745 infinity. So pick the kind that works when
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1746 we do step by infinity. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1747 if ((EMACS_INT) (p_limit + infinity) >
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1748 (EMACS_INT) p_limit)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1749 while ((EMACS_INT) cursor <=
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1750 (EMACS_INT) p_limit)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1751 cursor += BM_tab[*cursor];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1752 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1753 while ((EMACS_UINT) cursor <=
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1754 (EMACS_UINT) p_limit)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1755 cursor += BM_tab[*cursor];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1756 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1757 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1758 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1759 if ((EMACS_INT) (p_limit + infinity) <
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1760 (EMACS_INT) p_limit)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1761 while ((EMACS_INT) cursor >=
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1762 (EMACS_INT) p_limit)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1763 cursor += BM_tab[*cursor];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1764 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1765 while ((EMACS_UINT) cursor >=
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1766 (EMACS_UINT) p_limit)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1767 cursor += BM_tab[*cursor];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1768 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1769 /* If you are here, cursor is beyond the end of the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1770 searched region. This can happen if you match on
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1771 the far character of the pattern, because the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1772 "stride" of that character is infinity, a number
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1773 able to throw you well beyond the end of the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1774 search. It can also happen if you fail to match
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1775 within the permitted region and would otherwise
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1776 try a character beyond that region */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1777 if ((cursor - p_limit) * direction <= len)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1778 break; /* a small overrun is genuine */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1779 cursor -= infinity; /* large overrun = hit */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1780 i = dirlen - direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1781 if (!NILP (trt))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1782 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1783 while ((i -= direction) + direction != 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1784 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1785 #ifdef MULE
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1786 Emchar ch;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1787 cursor -= direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1788 /* Translate only the last byte of a character. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1789 if ((cursor == tail_end_ptr
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1790 || intbyte_first_byte_p (cursor[1]))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1791 && (intbyte_first_byte_p (cursor[0])
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1792 || (translate_prev_byte == cursor[-1]
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1793 && (intbyte_first_byte_p (translate_prev_byte)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1794 || translate_anteprev_byte == cursor[-2]))))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1795 ch = simple_translate[*cursor];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1796 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1797 ch = *cursor;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1798 if (pat[i] != ch)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1799 break;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1800 #else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1801 if (pat[i] != TRANSLATE (trt, *(cursor -= direction)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1802 break;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1803 #endif
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1804 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1805 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1806 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1807 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1808 while ((i -= direction) + direction != 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1809 if (pat[i] != *(cursor -= direction))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1810 break;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1811 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1812 cursor += dirlen - i - direction; /* fix cursor */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1813 if (i + direction == 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1814 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1815 cursor -= direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1816
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1817 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1818 Bytebpos bytstart = (pos + cursor - ptr2 +
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1819 ((direction > 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1820 ? 1 - len : 0));
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1821 Charbpos bufstart = bytebpos_to_charbpos (buf, bytstart);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1822 Charbpos bufend = bytebpos_to_charbpos (buf, bytstart + len);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1823
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1824 set_search_regs (buf, bufstart, bufend - bufstart);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1825 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1826
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1827 if ((n -= direction) != 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1828 cursor += dirlen; /* to resume search */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1829 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1830 return ((direction > 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1831 ? search_regs.end[0] : search_regs.start[0]);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1832 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1833 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1834 cursor += stride_for_teases; /* <sigh> we lose - */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1835 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1836 pos += cursor - ptr2;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1837 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1838 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1839 /* Now we'll pick up a clump that has to be done the hard
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1840 way because it covers a discontinuity */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1841 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 /* XEmacs change: definitions of CEILING_OF and FLOOR_OF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843 have changed. See buffer.h. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1844 limit = ((direction > 0)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1845 ? BYTE_BUF_CEILING_OF (buf, pos - dirlen + 1) - 1
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1846 : BYTE_BUF_FLOOR_OF (buf, pos - dirlen));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847 limit = ((direction > 0)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1848 ? min (limit + len, lim - 1)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1849 : max (limit - len, lim));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1850 /* LIMIT is now the last value POS can have
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1851 and still be valid for a possible match. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1852 while (1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1854 /* This loop can be coded for space rather than
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1855 speed because it will usually run only once.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1856 (the reach is at most len + 21, and typically
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1857 does not exceed len) */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1858 while ((limit - pos) * direction >= 0)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1859 /* *not* BYTE_BUF_FETCH_CHAR. We are working here
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1860 with bytes, not characters. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1861 pos += BM_tab[*BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, pos)];
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1862 /* now run the same tests to distinguish going off
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1863 the end, a match or a phony match. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1864 if ((pos - limit) * direction <= len)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1865 break; /* ran off the end */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1866 /* Found what might be a match.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1867 Set POS back to last (first if reverse) char pos. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1868 pos -= infinity;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1869 i = dirlen - direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1870 while ((i -= direction) + direction != 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1872 #ifdef MULE
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1873 Emchar ch;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1874 Intbyte *ptr;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1875 #endif
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1876 pos -= direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1877 #ifdef MULE
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1878 ptr = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, pos);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1879 if ((ptr == tail_end_ptr
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1880 || intbyte_first_byte_p (ptr[1]))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1881 && (intbyte_first_byte_p (ptr[0])
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1882 || (translate_prev_byte == ptr[-1]
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1883 && (intbyte_first_byte_p (translate_prev_byte)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1884 || translate_anteprev_byte == ptr[-2]))))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1885 ch = simple_translate[*ptr];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 else
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1887 ch = *ptr;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1888 if (pat[i] != ch)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1889 break;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1890
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1891 #else
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1892 if (pat[i] !=
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1893 TRANSLATE (trt,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1894 *BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, pos)))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1895 break;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1896 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1898 /* Above loop has moved POS part or all the way back
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1899 to the first char pos (last char pos if reverse).
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1900 Set it once again at the last (first if reverse)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1901 char. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1902 pos += dirlen - i- direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1903 if (i + direction == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1905 pos -= direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1906
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1907 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1908 Bytebpos bytstart = (pos +
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1909 ((direction > 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1910 ? 1 - len : 0));
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1911 Charbpos bufstart = bytebpos_to_charbpos (buf, bytstart);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1912 Charbpos bufend = bytebpos_to_charbpos (buf, bytstart + len);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1913
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1914 set_search_regs (buf, bufstart, bufend - bufstart);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1915 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1916
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1917 if ((n -= direction) != 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1918 pos += dirlen; /* to resume search */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919 else
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1920 return ((direction > 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1921 ? search_regs.end[0] : search_regs.start[0]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1923 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1924 pos += stride_for_teases;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1925 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1927 /* We have done one clump. Can we continue? */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1928 if ((lim - pos) * direction < 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1929 return (0 - n) * direction;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930 }
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1931 return bytebpos_to_charbpos (buf, pos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 /* Record beginning BEG and end BEG + LEN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 for a match just found in the current buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937 static void
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1938 set_search_regs (struct buffer *buf, Charbpos beg, Charcount len)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940 /* Make sure we have registers in which to store
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 the match position. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942 if (search_regs.num_regs == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944 search_regs.start = xnew (regoff_t);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 search_regs.end = xnew (regoff_t);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946 search_regs.num_regs = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949 search_regs.start[0] = beg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 search_regs.end[0] = beg + len;
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
1951 last_thing_searched = wrap_buffer (buf);
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 /* Given a string of words separated by word delimiters,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1956 compute a regexp that matches those exact words
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1957 separated by arbitrary punctuation. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1959 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 wordify (Lisp_Object buffer, Lisp_Object string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 Charcount i, len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 EMACS_INT punct_count = 0, word_count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 struct buffer *buf = decode_buffer (buffer, 0);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1965 Lisp_Object syntax_table = buf->mirror_syntax_table;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 CHECK_STRING (string);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1968 len = string_char_length (string);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 for (i = 0; i < len; i++)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1971 if (!WORD_SYNTAX_P (syntax_table, string_emchar (string, i)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973 punct_count++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1974 if (i > 0 && WORD_SYNTAX_P (syntax_table,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1975 string_emchar (string, i - 1)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 word_count++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 }
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1978 if (WORD_SYNTAX_P (syntax_table, string_emchar (string, len - 1)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 word_count++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 if (!word_count) return build_string ("");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 /* The following value is an upper bound on the amount of storage we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984 need. In non-Mule, it is exact. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1985 Intbyte *storage =
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1986 (Intbyte *) alloca (XSTRING_LENGTH (string) - punct_count +
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987 5 * (word_count - 1) + 4);
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1988 Intbyte *o = storage;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 *o++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991 *o++ = 'b';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1993 for (i = 0; i < len; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1994 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1995 Emchar ch = string_emchar (string, i);
428
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 if (WORD_SYNTAX_P (syntax_table, ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998 o += set_charptr_emchar (o, ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1999 else if (i > 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2000 && WORD_SYNTAX_P (syntax_table,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2001 string_emchar (string, i - 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2002 && --word_count)
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 *o++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005 *o++ = 'W';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2006 *o++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2007 *o++ = 'W';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2008 *o++ = '*';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2009 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2012 *o++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2013 *o++ = 'b';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2014
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2015 return make_string (storage, o - storage);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2016 }
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 DEFUN ("search-backward", Fsearch_backward, 1, 5, "sSearch backward: ", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020 Search backward from point for STRING.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 Set point to the beginning of the occurrence found, and return point.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2022
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2023 Optional second argument LIMIT bounds the search; it is a buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2024 position. The match found must not extend before that position.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2025 The value nil is equivalent to (point-min).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2026
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2027 Optional third argument NOERROR, if t, means just return nil (no
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2028 error) if the search fails. If neither nil nor t, set point to LIMIT
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2029 and return nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2030
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2031 Optional fourth argument COUNT is a repeat count--search for
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2032 successive occurrences.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2033
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2034 Optional fifth argument BUFFER specifies the buffer to search in and
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2035 defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2036
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2037 See also the functions `match-beginning', `match-end' and `replace-match'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2038 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2039 (string, limit, noerror, count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2041 return search_command (string, limit, noerror, count, buffer, -1, 0, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2042 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2043
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2044 DEFUN ("search-forward", Fsearch_forward, 1, 5, "sSearch: ", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045 Search forward from point for STRING.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046 Set point to the end of the occurrence found, and return point.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2047
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2048 Optional second argument LIMIT bounds the search; it is a buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2049 position. The match found must not extend after that position. The
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2050 value nil is equivalent to (point-max).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2051
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2052 Optional third argument NOERROR, if t, means just return nil (no
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2053 error) if the search fails. If neither nil nor t, set point to LIMIT
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2054 and return nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2055
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2056 Optional fourth argument COUNT is a repeat count--search for
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2057 successive occurrences.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2058
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059 Optional fifth argument BUFFER specifies the buffer to search in and
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2060 defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2061
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2062 See also the functions `match-beginning', `match-end' and `replace-match'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2063 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2064 (string, limit, noerror, count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2065 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2066 return search_command (string, limit, noerror, count, buffer, 1, 0, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2067 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2068
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2069 DEFUN ("word-search-backward", Fword_search_backward, 1, 5,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2070 "sWord search backward: ", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2071 Search backward from point for STRING, ignoring differences in punctuation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2072 Set point to the beginning of the occurrence found, and return point.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2073
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2074 Optional second argument LIMIT bounds the search; it is a buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2075 position. The match found must not extend before that position.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2076 The value nil is equivalent to (point-min).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2077
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2078 Optional third argument NOERROR, if t, means just return nil (no
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2079 error) if the search fails. If neither nil nor t, set point to LIMIT
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2080 and return nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2081
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2082 Optional fourth argument COUNT is a repeat count--search for
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2083 successive occurrences.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2084
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2085 Optional fifth argument BUFFER specifies the buffer to search in and
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2086 defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2087
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2088 See also the functions `match-beginning', `match-end' and `replace-match'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2089 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2090 (string, limit, noerror, count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2091 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2092 return search_command (wordify (buffer, string), limit, noerror, count,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2093 buffer, -1, 1, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2094 }
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 DEFUN ("word-search-forward", Fword_search_forward, 1, 5, "sWord search: ", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2097 Search forward from point for STRING, ignoring differences in punctuation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2098 Set point to the end of the occurrence found, and return point.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2099
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2100 Optional second argument LIMIT bounds the search; it is a buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2101 position. The match found must not extend after that position. The
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2102 value nil is equivalent to (point-max).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2103
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2104 Optional third argument NOERROR, if t, means just return nil (no
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2105 error) if the search fails. If neither nil nor t, set point to LIMIT
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2106 and return nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2107
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2108 Optional fourth argument COUNT is a repeat count--search for
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2109 successive occurrences.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2110
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2111 Optional fifth argument BUFFER specifies the buffer to search in and
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2112 defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2113
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2114 See also the functions `match-beginning', `match-end' and `replace-match'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2115 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2116 (string, limit, noerror, count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2117 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2118 return search_command (wordify (buffer, string), limit, noerror, count,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2119 buffer, 1, 1, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2120 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2122 DEFUN ("re-search-backward", Fre_search_backward, 1, 5,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2123 "sRE search backward: ", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2124 Search backward from point for match for regular expression REGEXP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2125 Set point to the beginning of the match, and return point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2126 The match found is the one starting last in the buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2127 and yet ending before the origin of the search.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2128
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2129 Optional second argument LIMIT bounds the search; it is a buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2130 position. The match found must not extend before that position.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2131 The value nil is equivalent to (point-min).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2132
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2133 Optional third argument NOERROR, if t, means just return nil (no
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2134 error) if the search fails. If neither nil nor t, set point to LIMIT
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2135 and return nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2136
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2137 Optional fourth argument COUNT is a repeat count--search for
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2138 successive occurrences.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2139
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2140 Optional fifth argument BUFFER specifies the buffer to search in and
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2141 defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2142
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2143 See also the functions `match-beginning', `match-end' and `replace-match'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2144 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2145 (regexp, limit, noerror, count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2146 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2147 return search_command (regexp, limit, noerror, count, buffer, -1, 1, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2149
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150 DEFUN ("re-search-forward", Fre_search_forward, 1, 5, "sRE search: ", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2151 Search forward from point for regular expression REGEXP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2152 Set point to the end of the occurrence found, and return point.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2153
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2154 Optional second argument LIMIT bounds the search; it is a buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2155 position. The match found must not extend after that position. The
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2156 value nil is equivalent to (point-max).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2157
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2158 Optional third argument NOERROR, if t, means just return nil (no
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2159 error) if the search fails. If neither nil nor t, set point to LIMIT
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2160 and return nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2161
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2162 Optional fourth argument COUNT is a repeat count--search for
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2163 successive occurrences.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2164
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2165 Optional fifth argument BUFFER specifies the buffer to search in and
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2166 defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2167
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2168 See also the functions `match-beginning', `match-end' and `replace-match'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2169 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2170 (regexp, limit, noerror, count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2171 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2172 return search_command (regexp, limit, noerror, count, buffer, 1, 1, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2173 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2175 DEFUN ("posix-search-backward", Fposix_search_backward, 1, 5,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2176 "sPosix search backward: ", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2177 Search backward from point for match for regular expression REGEXP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2178 Find the longest match in accord with Posix regular expression rules.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2179 Set point to the beginning of the match, and return point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2180 The match found is the one starting last in the buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2181 and yet ending before the origin of the search.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2182
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2183 Optional second argument LIMIT bounds the search; it is a buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2184 position. The match found must not extend before that position.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2185 The value nil is equivalent to (point-min).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2186
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2187 Optional third argument NOERROR, if t, means just return nil (no
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2188 error) if the search fails. If neither nil nor t, set point to LIMIT
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2189 and return nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2190
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2191 Optional fourth argument COUNT is a repeat count--search for
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2192 successive occurrences.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2193
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2194 Optional fifth argument BUFFER specifies the buffer to search in and
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2195 defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2196
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197 See also the functions `match-beginning', `match-end' and `replace-match'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2198 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2199 (regexp, limit, noerror, count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2200 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2201 return search_command (regexp, limit, noerror, count, buffer, -1, 1, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2202 }
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 DEFUN ("posix-search-forward", Fposix_search_forward, 1, 5, "sPosix search: ", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 Search forward from point for regular expression REGEXP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2206 Find the longest match in accord with Posix regular expression rules.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2207 Set point to the end of the occurrence found, and return point.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2208
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2209 Optional second argument LIMIT bounds the search; it is a buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2210 position. The match found must not extend after that position. The
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2211 value nil is equivalent to (point-max).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2212
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2213 Optional third argument NOERROR, if t, means just return nil (no
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2214 error) if the search fails. If neither nil nor t, set point to LIMIT
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2215 and return nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2216
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2217 Optional fourth argument COUNT is a repeat count--search for
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2218 successive occurrences.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2219
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2220 Optional fifth argument BUFFER specifies the buffer to search in and
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2221 defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2222
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2223 See also the functions `match-beginning', `match-end' and `replace-match'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2224 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2225 (regexp, limit, noerror, count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2226 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2227 return search_command (regexp, limit, noerror, count, buffer, 1, 1, 1);
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2230
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2231 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2232 free_created_dynarrs (Lisp_Object cons)
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 Dynarr_free (get_opaque_ptr (XCAR (cons)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2235 Dynarr_free (get_opaque_ptr (XCDR (cons)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2236 free_opaque_ptr (XCAR (cons));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2237 free_opaque_ptr (XCDR (cons));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2238 free_cons (XCONS (cons));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2239 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2240 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2242 DEFUN ("replace-match", Freplace_match, 1, 5, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2243 Replace text matched by last search with REPLACEMENT.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2244 If second arg FIXEDCASE is non-nil, do not alter case of replacement text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245 Otherwise maybe capitalize the whole text, or maybe just word initials,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2246 based on the replaced text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2247 If the replaced text has only capital letters
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2248 and has at least one multiletter word, convert REPLACEMENT to all caps.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2249 If the replaced text has at least one word starting with a capital letter,
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2250 then capitalize each word in REPLACEMENT.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2251
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2252 If third arg LITERAL is non-nil, insert REPLACEMENT literally.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2253 Otherwise treat `\\' as special:
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2254 `\\&' in REPLACEMENT means substitute original matched text.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2255 `\\N' means substitute what matched the Nth `\\(...\\)'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2256 If Nth parens didn't match, substitute nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2257 `\\\\' means insert one `\\'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2258 `\\u' means upcase the next character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2259 `\\l' means downcase the next character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2260 `\\U' means begin upcasing all following characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2261 `\\L' means begin downcasing all following characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2262 `\\E' means terminate the effect of any `\\U' or `\\L'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2263 Case changes made with `\\u', `\\l', `\\U', and `\\L' override
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2264 all other case changes that may be made in the replaced text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2265 FIXEDCASE and LITERAL are optional arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2266 Leaves point at end of replacement text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2267
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2268 The optional fourth argument STRING can be a string to modify.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2269 In that case, this function creates and returns a new string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2270 which is made by replacing the part of STRING that was matched.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2271 When fourth argument is a string, fifth argument STRBUFFER specifies
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2272 the buffer to be used for syntax-table and case-table lookup and
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2273 defaults to the current buffer. When fourth argument is not a string,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2274 the buffer that the match occurred in has automatically been remembered
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2275 and you do not need to specify it.
469
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2276
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2277 When fourth argument is nil, STRBUFFER specifies a subexpression of
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2278 the match. It says to replace just that subexpression instead of the
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2279 whole match. This is useful only after a regular expression search or
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2280 match since only regular expressions have distinguished subexpressions.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2281 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2282 (replacement, fixedcase, literal, string, strbuffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2283 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2284 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2285 enum { nochange, all_caps, cap_initial } case_action;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
2286 Charbpos pos, last;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2287 int some_multiletter_word;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2288 int some_lowercase;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2289 int some_uppercase;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2290 int some_nonuppercase_initial;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2291 Emchar c, prevc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2292 Charcount inslen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293 struct buffer *buf;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2294 Lisp_Object syntax_table;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2295 int mc_count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 Lisp_Object buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2297 int_dynarr *ul_action_dynarr = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2298 int_dynarr *ul_pos_dynarr = 0;
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
2299 int sub = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2300 int speccount;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2301
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2302 CHECK_STRING (replacement);
428
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 (! NILP (string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2305 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2306 CHECK_STRING (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2307 if (!EQ (last_thing_searched, Qt))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 507
diff changeset
2308 invalid_argument ("last thing matched was not a string", Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2309 /* If the match data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2310 were abstracted into a special "match data" type instead
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2311 of the typical half-assed "let the implementation be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2312 visible" form it's in, we could extend it to include
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2313 the last string matched and the buffer used for that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2314 matching. But of course we can't change it as it is. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2315 buf = decode_buffer (strbuffer, 0);
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
2316 buffer = wrap_buffer (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2317 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2318 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2319 {
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2320 if (!NILP (strbuffer))
469
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2321 {
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2322 CHECK_INT (strbuffer);
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2323 sub = XINT (strbuffer);
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2324 if (sub < 0 || sub >= (int) search_regs.num_regs)
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2325 args_out_of_range (strbuffer, make_int (search_regs.num_regs));
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2326 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2327 if (!BUFFERP (last_thing_searched))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 507
diff changeset
2328 invalid_argument ("last thing matched was not a buffer", Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2329 buffer = last_thing_searched;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2330 buf = XBUFFER (buffer);
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
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2333 syntax_table = buf->mirror_syntax_table;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2334
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2335 case_action = nochange; /* We tried an initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2336 /* but some C compilers blew it */
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 if (search_regs.num_regs == 0)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2339 signal_error (Qinvalid_operation,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2340 "replace-match called before any match found", Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2341
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2342 if (NILP (string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2343 {
469
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2344 if (search_regs.start[sub] < BUF_BEGV (buf)
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2345 || search_regs.start[sub] > search_regs.end[sub]
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2346 || search_regs.end[sub] > BUF_ZV (buf))
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2347 args_out_of_range (make_int (search_regs.start[sub]),
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2348 make_int (search_regs.end[sub]));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2349 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2350 else
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 if (search_regs.start[0] < 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2353 || search_regs.start[0] > search_regs.end[0]
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2354 || search_regs.end[0] > string_char_length (string))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2355 args_out_of_range (make_int (search_regs.start[0]),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2356 make_int (search_regs.end[0]));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2357 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2358
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2359 if (NILP (fixedcase))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2360 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2361 /* Decide how to casify by examining the matched text. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2362
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2363 last = search_regs.end[sub];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2364 prevc = '\n';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2365 case_action = all_caps;
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 /* some_multiletter_word is set nonzero if any original word
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2368 is more than one letter long. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2369 some_multiletter_word = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2370 some_lowercase = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2371 some_nonuppercase_initial = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2372 some_uppercase = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2373
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2374 for (pos = search_regs.start[sub]; pos < last; pos++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2375 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2376 if (NILP (string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2377 c = BUF_FETCH_CHAR (buf, pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2378 else
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2379 c = string_emchar (string, pos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2381 if (LOWERCASEP (buf, c))
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 /* Cannot be all caps if any original char is lower case */
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 some_lowercase = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2386 if (!WORD_SYNTAX_P (syntax_table, prevc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2387 some_nonuppercase_initial = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2388 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2389 some_multiletter_word = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2390 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2391 else if (!NOCASEP (buf, c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2392 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2393 some_uppercase = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2394 if (!WORD_SYNTAX_P (syntax_table, prevc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2395 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2396 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2397 some_multiletter_word = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2398 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2399 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2400 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2401 /* If the initial is a caseless word constituent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2402 treat that like a lowercase initial. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2403 if (!WORD_SYNTAX_P (syntax_table, prevc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2404 some_nonuppercase_initial = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2405 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2406
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2407 prevc = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2408 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2410 /* Convert to all caps if the old text is all caps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2411 and has at least one multiletter word. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2412 if (! some_lowercase && some_multiletter_word)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2413 case_action = all_caps;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2414 /* Capitalize each word, if the old text has all capitalized words. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2415 else if (!some_nonuppercase_initial && some_multiletter_word)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2416 case_action = cap_initial;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2417 else if (!some_nonuppercase_initial && some_uppercase)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2418 /* Should x -> yz, operating on X, give Yz or YZ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2419 We'll assume the latter. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2420 case_action = all_caps;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2421 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2422 case_action = nochange;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2423 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2424
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2425 /* Do replacement in a string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2426 if (!NILP (string))
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 Lisp_Object before, after;
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 speccount = specpdl_depth ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2431 before = Fsubstring (string, Qzero, make_int (search_regs.start[0]));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2432 after = Fsubstring (string, make_int (search_regs.end[0]), Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2433
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2434 /* Do case substitution into REPLACEMENT if desired. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2435 if (NILP (literal))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2436 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2437 Charcount stlen = string_char_length (replacement);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2438 Charcount strpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2439 /* XEmacs change: rewrote this loop somewhat to make it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2440 cleaner. Also added \U, \E, etc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2441 Charcount literal_start = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2442 /* We build up the substituted string in ACCUM. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2443 Lisp_Object accum;
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 accum = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2446
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2447 /* OK, the basic idea here is that we scan through the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2448 replacement string until we find a backslash, which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2449 represents a substring of the original string to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2450 substituted. We then append onto ACCUM the literal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2451 text before the backslash (LASTPOS marks the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2452 beginning of this) followed by the substring of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2453 original string that needs to be inserted. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2454 for (strpos = 0; strpos < stlen; strpos++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2455 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2456 /* If LITERAL_END is set, we've encountered a backslash
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2457 (the end of literal text to be inserted). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2458 Charcount literal_end = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2459 /* If SUBSTART is set, we need to also insert the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2460 text from SUBSTART to SUBEND in the original string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2461 Charcount substart = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2462 Charcount subend = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2463
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2464 c = string_emchar (replacement, strpos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2465 if (c == '\\' && strpos < stlen - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2466 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2467 c = string_emchar (replacement, ++strpos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2468 if (c == '&')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2469 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2470 literal_end = strpos - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2471 substart = search_regs.start[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2472 subend = search_regs.end[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2473 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2474 else if (c >= '1' && c <= '9' &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2475 c <= search_regs.num_regs + '0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2476 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2477 if (search_regs.start[c - '0'] >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2478 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2479 literal_end = strpos - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2480 substart = search_regs.start[c - '0'];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2481 subend = search_regs.end[c - '0'];
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2484 else if (c == 'U' || c == 'u' || c == 'L' || c == 'l' ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2485 c == 'E')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2486 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2487 /* Keep track of all case changes requested, but don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2488 make them now. Do them later so we override
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2489 everything else. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2490 if (!ul_pos_dynarr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2491 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2492 ul_pos_dynarr = Dynarr_new (int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2493 ul_action_dynarr = Dynarr_new (int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2494 record_unwind_protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2495 (free_created_dynarrs,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2496 noseeum_cons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2497 (make_opaque_ptr (ul_pos_dynarr),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2498 make_opaque_ptr (ul_action_dynarr)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2499 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2500 literal_end = strpos - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2501 Dynarr_add (ul_pos_dynarr,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2502 (!NILP (accum)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2503 ? string_char_length (accum)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2504 : 0) + (literal_end - literal_start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2505 Dynarr_add (ul_action_dynarr, c);
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 else if (c == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2508 /* So we get just one backslash. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2509 literal_end = strpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2510 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2511 if (literal_end >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2512 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2513 Lisp_Object literal_text = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2514 Lisp_Object substring = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2515 if (literal_end != literal_start)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2516 literal_text = Fsubstring (replacement,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2517 make_int (literal_start),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2518 make_int (literal_end));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2519 if (substart >= 0 && subend != substart)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2520 substring = Fsubstring (string,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2521 make_int (substart),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2522 make_int (subend));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2523 if (!NILP (literal_text) || !NILP (substring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2524 accum = concat3 (accum, literal_text, substring);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2525 literal_start = strpos + 1;
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2528
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2529 if (strpos != literal_start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2530 /* some literal text at end to be inserted */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2531 replacement = concat2 (accum, Fsubstring (replacement,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2532 make_int (literal_start),
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2533 make_int (strpos)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2534 else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2535 replacement = accum;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2536 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2537
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2538 /* replacement can be nil. */
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2539 if (NILP (replacement))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2540 replacement = build_string ("");
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2541
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2542 if (case_action == all_caps)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2543 replacement = Fupcase (replacement, buffer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2544 else if (case_action == cap_initial)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2545 replacement = Fupcase_initials (replacement, buffer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2547 /* Now finally, we need to process the \U's, \E's, etc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2548 if (ul_pos_dynarr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2549 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2550 int i = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2551 int cur_action = 'E';
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2552 Charcount stlen = string_char_length (replacement);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2553 Charcount strpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2554
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2555 for (strpos = 0; strpos < stlen; strpos++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2556 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2557 Emchar curchar = string_emchar (replacement, strpos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2558 Emchar newchar = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2559 if (i < Dynarr_length (ul_pos_dynarr) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2560 strpos == Dynarr_at (ul_pos_dynarr, i))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2561 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2562 int new_action = Dynarr_at (ul_action_dynarr, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2563 i++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2564 if (new_action == 'u')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2565 newchar = UPCASE (buf, curchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2566 else if (new_action == 'l')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2567 newchar = DOWNCASE (buf, curchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2568 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2569 cur_action = new_action;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2570 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2571 if (newchar == -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2572 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2573 if (cur_action == 'U')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2574 newchar = UPCASE (buf, curchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2575 else if (cur_action == 'L')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2576 newchar = DOWNCASE (buf, curchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2577 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2578 newchar = curchar;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2579 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2580 if (newchar != curchar)
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
2581 set_string_char (replacement, strpos, newchar);
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2585 /* frees the Dynarrs if necessary. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2586 unbind_to (speccount);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2587 return concat3 (before, replacement, after);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2588 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2589
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2590 mc_count = begin_multiple_change (buf, search_regs.start[sub],
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2591 search_regs.end[sub]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2592
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2593 /* begin_multiple_change() records an unwind-protect, so we need to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2594 record this value now. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2595 speccount = specpdl_depth ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2596
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2597 /* We insert the replacement text before the old text, and then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2598 delete the original text. This means that markers at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2599 beginning or end of the original will float to the corresponding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2600 position in the replacement. */
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2601 BUF_SET_PT (buf, search_regs.start[sub]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2602 if (!NILP (literal))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2603 Finsert (1, &replacement);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2604 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2605 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2606 Charcount stlen = string_char_length (replacement);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2607 Charcount strpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2608 struct gcpro gcpro1;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2609 GCPRO1 (replacement);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2610 for (strpos = 0; strpos < stlen; strpos++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2611 {
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2612 /* on the first iteration assert(offset==0),
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2613 exactly complementing BUF_SET_PT() above.
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2614 During the loop, it keeps track of the amount inserted.
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2615 */
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2616 Charcount offset = BUF_PT (buf) - search_regs.start[sub];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2617
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2618 c = string_emchar (replacement, strpos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2619 if (c == '\\' && strpos < stlen - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2620 {
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2621 /* XXX FIXME: replacing just a substring non-literally
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2622 using backslash refs to the match looks dangerous. But
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2623 <15366.18513.698042.156573@ns.caldera.de> from Torsten Duwe
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2624 <duwe@caldera.de> claims Finsert_buffer_substring already
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2625 handles this correctly.
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2626 */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2627 c = string_emchar (replacement, ++strpos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2628 if (c == '&')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2629 Finsert_buffer_substring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2630 (buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2631 make_int (search_regs.start[0] + offset),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2632 make_int (search_regs.end[0] + offset));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2633 else if (c >= '1' && c <= '9' &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2634 c <= search_regs.num_regs + '0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2635 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2636 if (search_regs.start[c - '0'] >= 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2637 Finsert_buffer_substring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2638 (buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2639 make_int (search_regs.start[c - '0'] + offset),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2640 make_int (search_regs.end[c - '0'] + offset));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2642 else if (c == 'U' || c == 'u' || c == 'L' || c == 'l' ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643 c == 'E')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2644 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2645 /* Keep track of all case changes requested, but don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2646 make them now. Do them later so we override
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2647 everything else. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2648 if (!ul_pos_dynarr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2649 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2650 ul_pos_dynarr = Dynarr_new (int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2651 ul_action_dynarr = Dynarr_new (int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2652 record_unwind_protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2653 (free_created_dynarrs,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2654 Fcons (make_opaque_ptr (ul_pos_dynarr),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2655 make_opaque_ptr (ul_action_dynarr)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2656 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2657 Dynarr_add (ul_pos_dynarr, BUF_PT (buf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2658 Dynarr_add (ul_action_dynarr, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2659 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2660 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2661 buffer_insert_emacs_char (buf, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2662 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2663 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2664 buffer_insert_emacs_char (buf, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2665 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2666 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2667 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2668
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2669 inslen = BUF_PT (buf) - (search_regs.start[sub]);
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2670 buffer_delete_range (buf, search_regs.start[sub] + inslen,
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2671 search_regs.end[sub] + inslen, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2672
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2673 if (case_action == all_caps)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2674 Fupcase_region (make_int (BUF_PT (buf) - inslen),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2675 make_int (BUF_PT (buf)), buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2676 else if (case_action == cap_initial)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2677 Fupcase_initials_region (make_int (BUF_PT (buf) - inslen),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2678 make_int (BUF_PT (buf)), buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2679
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2680 /* Now go through and make all the case changes that were requested
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2681 in the replacement string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2682 if (ul_pos_dynarr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2683 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
2684 Charbpos eend = BUF_PT (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2685 int i = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2686 int cur_action = 'E';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2687
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2688 for (pos = BUF_PT (buf) - inslen; pos < eend; pos++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2689 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2690 Emchar curchar = BUF_FETCH_CHAR (buf, pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2691 Emchar newchar = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2692 if (i < Dynarr_length (ul_pos_dynarr) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2693 pos == Dynarr_at (ul_pos_dynarr, i))
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 int new_action = Dynarr_at (ul_action_dynarr, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2696 i++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2697 if (new_action == 'u')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2698 newchar = UPCASE (buf, curchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2699 else if (new_action == 'l')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2700 newchar = DOWNCASE (buf, curchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2701 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2702 cur_action = new_action;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2703 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2704 if (newchar == -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2705 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2706 if (cur_action == 'U')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2707 newchar = UPCASE (buf, curchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2708 else if (cur_action == 'L')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2709 newchar = DOWNCASE (buf, curchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2710 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2711 newchar = curchar;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2712 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2713 if (newchar != curchar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2714 buffer_replace_char (buf, pos, newchar, 0, 0);
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2717
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2718 /* frees the Dynarrs if necessary. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2719 unbind_to (speccount);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2720 end_multiple_change (buf, mc_count);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2721
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2722 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2723 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2725 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2726 match_limit (Lisp_Object num, int beginningp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2727 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2728 int n;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2729
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2730 CHECK_INT (num);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2731 n = XINT (num);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2732 if (n < 0 || n >= search_regs.num_regs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2733 args_out_of_range (num, make_int (search_regs.num_regs));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2734 if (search_regs.num_regs == 0 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2735 search_regs.start[n] < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2736 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2737 return make_int (beginningp ? search_regs.start[n] : search_regs.end[n]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2738 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2740 DEFUN ("match-beginning", Fmatch_beginning, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2741 Return position of start of text matched by last regexp search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2742 NUM, specifies which parenthesized expression in the last regexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2743 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2744 Zero means the entire text matched by the whole regexp or whole string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2745 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2746 (num))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2747 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2748 return match_limit (num, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2749 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2750
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2751 DEFUN ("match-end", Fmatch_end, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2752 Return position of end of text matched by last regexp search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2753 NUM specifies which parenthesized expression in the last regexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2754 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2755 Zero means the entire text matched by the whole regexp or whole string.
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 (num))
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 return match_limit (num, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2760 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2761
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2762 DEFUN ("match-data", Fmatch_data, 0, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2763 Return a list containing all info on what the last regexp search matched.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2764 Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2765 All the elements are markers or nil (nil if the Nth pair didn't match)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2766 if the last match was on a buffer; integers or nil if a string was matched.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2767 Use `store-match-data' to reinstate the data in this list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2768
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2769 If INTEGERS (the optional first argument) is non-nil, always use integers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2770 \(rather than markers) to represent buffer positions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2771 If REUSE is a list, reuse it as part of the value. If REUSE is long enough
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2772 to hold all the values, and if INTEGERS is non-nil, no consing is done.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2773 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2774 (integers, reuse))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2775 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2776 Lisp_Object tail, prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2777 Lisp_Object *data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2778 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2779 Charcount len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2780
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2781 if (NILP (last_thing_searched))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 507
diff changeset
2782 /*error ("match-data called before any match found", Qunbound);*/
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2783 return Qnil;
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 data = alloca_array (Lisp_Object, 2 * search_regs.num_regs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2786
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2787 len = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2788 for (i = 0; i < search_regs.num_regs; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2789 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
2790 Charbpos start = search_regs.start[i];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2791 if (start >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2792 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2793 if (EQ (last_thing_searched, Qt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2794 || !NILP (integers))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2795 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2796 data[2 * i] = make_int (start);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2797 data[2 * i + 1] = make_int (search_regs.end[i]);
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 else if (BUFFERP (last_thing_searched))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2800 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2801 data[2 * i] = Fmake_marker ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2802 Fset_marker (data[2 * i],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2803 make_int (start),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2804 last_thing_searched);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2805 data[2 * i + 1] = Fmake_marker ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2806 Fset_marker (data[2 * i + 1],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2807 make_int (search_regs.end[i]),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2808 last_thing_searched);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2809 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2810 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2811 /* last_thing_searched must always be Qt, a buffer, or Qnil. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2812 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2813
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2814 len = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2815 }
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 data[2 * i] = data [2 * i + 1] = Qnil;
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 if (!CONSP (reuse))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2820 return Flist (2 * len + 2, data);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2821
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2822 /* If REUSE is a list, store as many value elements as will fit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2823 into the elements of REUSE. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2824 for (prev = Qnil, i = 0, tail = reuse; CONSP (tail); i++, tail = XCDR (tail))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2825 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2826 if (i < 2 * len + 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2827 XCAR (tail) = data[i];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2828 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2829 XCAR (tail) = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2830 prev = tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2831 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2832
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2833 /* If we couldn't fit all value elements into REUSE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2834 cons up the rest of them and add them to the end of REUSE. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2835 if (i < 2 * len + 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2836 XCDR (prev) = Flist (2 * len + 2 - i, data + i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2837
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2838 return reuse;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2839 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2840
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2841
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2842 DEFUN ("store-match-data", Fstore_match_data, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2843 Set internal data on last search match from elements of LIST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2844 LIST should have been created by calling `match-data' previously.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2845 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2846 (list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2847 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2848 REGISTER int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2849 REGISTER Lisp_Object marker;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2850 int num_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2851 int length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2852
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2853 if (running_asynch_code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2854 save_search_regs ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2855
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2856 CONCHECK_LIST (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2857
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2858 /* Unless we find a marker with a buffer in LIST, assume that this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2859 match data came from a string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2860 last_thing_searched = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2861
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2862 /* Allocate registers if they don't already exist. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2863 length = XINT (Flength (list)) / 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2864 num_regs = search_regs.num_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2865
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2866 if (length > num_regs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2867 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2868 if (search_regs.num_regs == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2869 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2870 search_regs.start = xnew_array (regoff_t, length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2871 search_regs.end = xnew_array (regoff_t, length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2872 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2873 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2874 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2875 XREALLOC_ARRAY (search_regs.start, regoff_t, length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2876 XREALLOC_ARRAY (search_regs.end, regoff_t, length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2877 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2879 search_regs.num_regs = length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2880 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2881
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2882 for (i = 0; i < num_regs; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2883 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2884 marker = Fcar (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2885 if (NILP (marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2886 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2887 search_regs.start[i] = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2888 list = Fcdr (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2889 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2890 else
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 if (MARKERP (marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2893 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2894 if (XMARKER (marker)->buffer == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2895 marker = Qzero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2896 else
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
2897 last_thing_searched = wrap_buffer (XMARKER (marker)->buffer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2898 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2899
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2900 CHECK_INT_COERCE_MARKER (marker);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2901 search_regs.start[i] = XINT (marker);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2902 list = Fcdr (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2903
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2904 marker = Fcar (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2905 if (MARKERP (marker) && XMARKER (marker)->buffer == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2906 marker = Qzero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2907
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2908 CHECK_INT_COERCE_MARKER (marker);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2909 search_regs.end[i] = XINT (marker);
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 list = Fcdr (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2912 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2913
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 return Qnil;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2917 /* If non-zero the match data have been saved in saved_search_regs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2918 during the execution of a sentinel or filter. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2919 static int search_regs_saved;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2920 static struct re_registers saved_search_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2921
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2922 /* Called from Flooking_at, Fstring_match, search_buffer, Fstore_match_data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2923 if asynchronous code (filter or sentinel) is running. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2924 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2925 save_search_regs (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2926 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2927 if (!search_regs_saved)
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 saved_search_regs.num_regs = search_regs.num_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2930 saved_search_regs.start = search_regs.start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2931 saved_search_regs.end = search_regs.end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2932 search_regs.num_regs = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2933 search_regs.start = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2934 search_regs.end = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2935
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2936 search_regs_saved = 1;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2940 /* Called upon exit from filters and sentinels. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2941 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2942 restore_match_data (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2943 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2944 if (search_regs_saved)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2945 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2946 if (search_regs.num_regs > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2947 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2948 xfree (search_regs.start);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2949 xfree (search_regs.end);
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 search_regs.num_regs = saved_search_regs.num_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2952 search_regs.start = saved_search_regs.start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2953 search_regs.end = saved_search_regs.end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2954
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2955 search_regs_saved = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2956 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2957 }
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 /* Quote a string to inactivate reg-expr chars */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2960
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2961 DEFUN ("regexp-quote", Fregexp_quote, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2962 Return a regexp string which matches exactly STRING and nothing else.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2963 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2964 (string))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2965 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
2966 REGISTER Intbyte *in, *out, *end;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
2967 REGISTER Intbyte *temp;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2968
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2969 CHECK_STRING (string);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2970
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
2971 temp = (Intbyte *) alloca (XSTRING_LENGTH (string) * 2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2972
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2973 /* Now copy the data into the new string, inserting escapes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2974
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2975 in = XSTRING_DATA (string);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2976 end = in + XSTRING_LENGTH (string);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977 out = temp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2978
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979 while (in < end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2980 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2981 Emchar c = charptr_emchar (in);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2983 if (c == '[' || c == ']'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2984 || c == '*' || c == '.' || c == '\\'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2985 || c == '?' || c == '+'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2986 || c == '^' || c == '$')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2987 *out++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2988 out += set_charptr_emchar (out, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989 INC_CHARPTR (in);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2990 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2991
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2992 return make_string (temp, out - temp);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2995 DEFUN ("set-word-regexp", Fset_word_regexp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2996 Set the regexp to be used to match a word in regular-expression searching.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2997 #### Not yet implemented. Currently does nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2998 #### Do not use this yet. Its calling interface is likely to change.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2999 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3000 (regexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3001 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002 return Qnil;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3005
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3006 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3007 /* initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3008 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3009
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3010 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3011 syms_of_search (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3013
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3014 DEFERROR_STANDARD (Qsearch_failed, Qinvalid_operation);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3015 DEFERROR_STANDARD (Qinvalid_regexp, Qsyntax_error);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 507
diff changeset
3016 Fput (Qinvalid_regexp, Qerror_lacks_explanatory_string, Qt);
428
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 DEFSUBR (Flooking_at);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3019 DEFSUBR (Fposix_looking_at);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3020 DEFSUBR (Fstring_match);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3021 DEFSUBR (Fposix_string_match);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3022 DEFSUBR (Fskip_chars_forward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3023 DEFSUBR (Fskip_chars_backward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3024 DEFSUBR (Fskip_syntax_forward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3025 DEFSUBR (Fskip_syntax_backward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3026 DEFSUBR (Fsearch_forward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3027 DEFSUBR (Fsearch_backward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3028 DEFSUBR (Fword_search_forward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3029 DEFSUBR (Fword_search_backward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3030 DEFSUBR (Fre_search_forward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3031 DEFSUBR (Fre_search_backward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3032 DEFSUBR (Fposix_search_forward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3033 DEFSUBR (Fposix_search_backward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3034 DEFSUBR (Freplace_match);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3035 DEFSUBR (Fmatch_beginning);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3036 DEFSUBR (Fmatch_end);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3037 DEFSUBR (Fmatch_data);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3038 DEFSUBR (Fstore_match_data);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3039 DEFSUBR (Fregexp_quote);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3040 DEFSUBR (Fset_word_regexp);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3043 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3044 reinit_vars_of_search (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3045 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3046 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3047
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3048 last_thing_searched = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3049 staticpro_nodump (&last_thing_searched);
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 for (i = 0; i < REGEXP_CACHE_SIZE; ++i)
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 searchbufs[i].buf.allocated = 100;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3054 searchbufs[i].buf.buffer = (unsigned char *) xmalloc (100);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3055 searchbufs[i].buf.fastmap = searchbufs[i].fastmap;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3056 searchbufs[i].regexp = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3057 staticpro_nodump (&searchbufs[i].regexp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3058 searchbufs[i].next = (i == REGEXP_CACHE_SIZE-1 ? 0 : &searchbufs[i+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 searchbuf_head = &searchbufs[0];
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3063 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3064 vars_of_search (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3065 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3066 reinit_vars_of_search ();
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 DEFVAR_LISP ("forward-word-regexp", &Vforward_word_regexp /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3069 *Regular expression to be used in `forward-word'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3070 #### Not yet implemented.
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 Vforward_word_regexp = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3073
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3074 DEFVAR_LISP ("backward-word-regexp", &Vbackward_word_regexp /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3075 *Regular expression to be used in `backward-word'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3076 #### Not yet implemented.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3077 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3078 Vbackward_word_regexp = Qnil;
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
3079
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
3080 DEFVAR_INT ("warn-about-possibly-incompatible-back-references",
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
3081 &warn_about_possibly_incompatible_back_references /*
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
3082 If true, issue warnings when new-semantics back references occur.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
3083 This is to catch places where old code might inadvertently have changed
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
3084 semantics. This will occur in old code only where more than nine groups
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
3085 occur and a back reference to one of them is directly followed by a digit.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
3086 */ );
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
3087 warn_about_possibly_incompatible_back_references = 1;
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 793
diff changeset
3088
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3089 Vskip_chars_range_table = Fmake_range_table ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3090 staticpro (&Vskip_chars_range_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3091 }